mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move some initialization to the appropriate mixin and clean up the use of the preference
This commit is contained in:
parent
4c523826b7
commit
cc181a9d0b
@ -19,6 +19,7 @@ from calibre.gui2.widgets import Splitter
|
|||||||
from calibre.gui2.tag_view import TagBrowserWidget
|
from calibre.gui2.tag_view import TagBrowserWidget
|
||||||
from calibre.gui2.book_details import BookDetails
|
from calibre.gui2.book_details import BookDetails
|
||||||
from calibre.gui2.notify import get_notifier
|
from calibre.gui2.notify import get_notifier
|
||||||
|
from calibre.utils.config import dynamic
|
||||||
|
|
||||||
_keep_refs = []
|
_keep_refs = []
|
||||||
|
|
||||||
@ -64,6 +65,8 @@ class LibraryViewMixin(object): # {{{
|
|||||||
view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book)
|
view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book)
|
||||||
|
|
||||||
self.build_context_menus()
|
self.build_context_menus()
|
||||||
|
highlight_cbox=dynamic.get('search_highlight_only', False)
|
||||||
|
self.library_view.model().set_highlight_only(highlight_cbox)
|
||||||
|
|
||||||
def build_context_menus(self):
|
def build_context_menus(self):
|
||||||
lm = QMenu(self)
|
lm = QMenu(self)
|
||||||
|
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import QIcon, Qt, QWidget, QToolBar, QSize, QDialogButtonBox, \
|
from PyQt4.Qt import QIcon, Qt, QWidget, QToolBar, QSize, QDialogButtonBox, \
|
||||||
pyqtSignal, QToolButton, QMenu, QCheckBox, QDialog, QGridLayout, \
|
pyqtSignal, QToolButton, QMenu, QCheckBox, QDialog, QGridLayout, QFrame, \
|
||||||
QObject, QVBoxLayout, QSizePolicy, QLabel, QHBoxLayout, QActionGroup
|
QObject, QVBoxLayout, QSizePolicy, QLabel, QHBoxLayout, QActionGroup
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +19,6 @@ from calibre.gui2 import gprefs
|
|||||||
from calibre.gui2.widgets import ComboBoxWithHelp
|
from calibre.gui2.widgets import ComboBoxWithHelp
|
||||||
from calibre.gui2.complete import MultiCompleteLineEdit
|
from calibre.gui2.complete import MultiCompleteLineEdit
|
||||||
from calibre import human_readable
|
from calibre import human_readable
|
||||||
from calibre.utils.config import prefs
|
|
||||||
|
|
||||||
class LocationManager(QObject): # {{{
|
class LocationManager(QObject): # {{{
|
||||||
|
|
||||||
@ -151,8 +150,6 @@ class SearchBar(QWidget): # {{{
|
|||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.parent = parent
|
|
||||||
|
|
||||||
self._layout = l = QHBoxLayout()
|
self._layout = l = QHBoxLayout()
|
||||||
self.setLayout(self._layout)
|
self.setLayout(self._layout)
|
||||||
self._layout.setContentsMargins(0,5,0,0)
|
self._layout.setContentsMargins(0,5,0,0)
|
||||||
@ -162,8 +159,8 @@ class SearchBar(QWidget): # {{{
|
|||||||
x.setObjectName("search_restriction")
|
x.setObjectName("search_restriction")
|
||||||
x.setToolTip(_('Books display will be restricted to those matching the '
|
x.setToolTip(_('Books display will be restricted to those matching the '
|
||||||
'selected saved search'))
|
'selected saved search'))
|
||||||
parent.search_restriction = x
|
|
||||||
l.addWidget(x)
|
l.addWidget(x)
|
||||||
|
parent.search_restriction = x
|
||||||
|
|
||||||
x = QLabel(self)
|
x = QLabel(self)
|
||||||
x.setObjectName("search_count")
|
x.setObjectName("search_count")
|
||||||
@ -237,21 +234,26 @@ class SearchOptions(QDialog):
|
|||||||
def __init__(self, parent, limit_to_fields, limit_field_list,
|
def __init__(self, parent, limit_to_fields, limit_field_list,
|
||||||
limit_cbox, highlight_cbox):
|
limit_cbox, highlight_cbox):
|
||||||
QDialog.__init__(self, parent=parent)
|
QDialog.__init__(self, parent=parent)
|
||||||
# self.search_limit_possible_fields = []
|
|
||||||
# self.search_limit_cbox_value = False
|
|
||||||
# self.search_highlight_cbox_value = False
|
|
||||||
# self.search_limit_list = ''
|
|
||||||
# self = self.search_popup = QDialog(self.parent)
|
|
||||||
self.setWindowTitle(_('Search options'))
|
self.setWindowTitle(_('Search options'))
|
||||||
l = QGridLayout()
|
l = QGridLayout()
|
||||||
self.setLayout(l)
|
self.setLayout(l)
|
||||||
|
|
||||||
x = QLabel(_(' '), parent=self)
|
x = QLabel(_('Use this box to change search options related to how '
|
||||||
x.setBuddy(parent.search_restriction)
|
'results are displayed and which fields are searched. '
|
||||||
l.addWidget(x, 1, 0, 1, 1)
|
'Changes will be remembered across calibre restarts. '
|
||||||
|
'When you press OK, the last search will be redone using '
|
||||||
|
'the new option values.'),
|
||||||
|
parent=self)
|
||||||
|
x.setWordWrap(True)
|
||||||
|
l.addWidget(x, 0, 0, 1, 2)
|
||||||
|
|
||||||
|
line = QFrame(self)
|
||||||
|
line.setFrameShape(QFrame.HLine)
|
||||||
|
line.setFrameShadow(QFrame.Sunken)
|
||||||
|
l.addWidget(line, 1, 0, 1, 2)
|
||||||
|
|
||||||
x = self.search_highlight_only = QCheckBox(self)
|
x = self.search_highlight_only = QCheckBox(self)
|
||||||
x.setToolTip('<p>'+_('When searching, highlight matched books, instead '
|
x.setToolTip('<p>'+_('When searching, highlight matched books instead '
|
||||||
'of restricting the book list to the matches.<p> You can use the '
|
'of restricting the book list to the matches.<p> You can use the '
|
||||||
'N or F3 keys to go to the next match.'))
|
'N or F3 keys to go to the next match.'))
|
||||||
x.setChecked(highlight_cbox)
|
x.setChecked(highlight_cbox)
|
||||||
@ -268,8 +270,8 @@ class SearchOptions(QDialog):
|
|||||||
'Preferences -> Look and Feel -> Limit non-prefixed searches to columns.'))
|
'Preferences -> Look and Feel -> Limit non-prefixed searches to columns.'))
|
||||||
x.setChecked(limit_cbox)
|
x.setChecked(limit_cbox)
|
||||||
l.addWidget(x, 3, 1, 1, 1)
|
l.addWidget(x, 3, 1, 1, 1)
|
||||||
x = QLabel(_('Check this box if you want non-prefixed searches to be '
|
x = QLabel(_('Check this box if you want non-&prefixed searches to be '
|
||||||
'&limited to certain fields/lookup names'), parent=self)
|
'limited to certain fields/lookup names'), parent=self)
|
||||||
x.setBuddy(self.search_limit_checkbox)
|
x.setBuddy(self.search_limit_checkbox)
|
||||||
l.addWidget(x, 3, 0, 1, 1)
|
l.addWidget(x, 3, 0, 1, 1)
|
||||||
|
|
||||||
@ -284,15 +286,15 @@ class SearchOptions(QDialog):
|
|||||||
x.update_items_cache(limit_field_list)
|
x.update_items_cache(limit_field_list)
|
||||||
x.setText(limit_to_fields)
|
x.setText(limit_to_fields)
|
||||||
l.addWidget(x, 4, 1, 1, 1)
|
l.addWidget(x, 4, 1, 1, 1)
|
||||||
x = QLabel(_('Enter the list of fields that non-prefixed searches '
|
x = QLabel(_('Enter the list of &columns that non-prefixed searches '
|
||||||
'are &limited to'), parent=self)
|
'are limited to'), parent=self)
|
||||||
x.setBuddy(self.search_box_limit_to)
|
x.setBuddy(self.search_box_limit_to)
|
||||||
l.addWidget(x, 4, 0, 1, 1)
|
l.addWidget(x, 4, 0, 1, 1)
|
||||||
|
|
||||||
buttons = QDialogButtonBox()
|
buttons = QDialogButtonBox()
|
||||||
buttons.addButton(QDialogButtonBox.Ok)
|
buttons.addButton(QDialogButtonBox.Ok)
|
||||||
buttons.addButton(QDialogButtonBox.Cancel)
|
buttons.addButton(QDialogButtonBox.Cancel)
|
||||||
l.addWidget(buttons, 5, 0, 1, 1)
|
l.addWidget(buttons, 5, 0, 1, 2)
|
||||||
buttons.accepted.connect(self.search_options_accepted)
|
buttons.accepted.connect(self.search_options_accepted)
|
||||||
buttons.rejected.connect(self.search_options_rejected)
|
buttons.rejected.connect(self.search_options_rejected)
|
||||||
|
|
||||||
|
@ -285,13 +285,6 @@ up into sub-categories. If the partition method is set to disable, this value is
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>MultiCompleteLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header>calibre.gui2.complete.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -376,10 +376,7 @@ class SearchBoxMixin(object): # {{{
|
|||||||
unicode(self.search.toolTip())))
|
unicode(self.search.toolTip())))
|
||||||
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
|
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
|
||||||
self.clear_button.setStatusTip(self.clear_button.toolTip())
|
self.clear_button.setStatusTip(self.clear_button.toolTip())
|
||||||
|
|
||||||
self.search_options_button.clicked.connect(self.search_options_button_clicked)
|
self.search_options_button.clicked.connect(self.search_options_button_clicked)
|
||||||
prefs['use_search_box_limit'] = dynamic.get('use_search_box_limit', False)
|
|
||||||
highlight_cbox=dynamic.get('search_highlight_only', False)
|
|
||||||
|
|
||||||
def focus_search_box(self, *args):
|
def focus_search_box(self, *args):
|
||||||
self.search.setFocus(Qt.OtherFocusReason)
|
self.search.setFocus(Qt.OtherFocusReason)
|
||||||
@ -404,53 +401,28 @@ class SearchBoxMixin(object): # {{{
|
|||||||
self.focus_to_library()
|
self.focus_to_library()
|
||||||
|
|
||||||
def search_options_button_clicked(self):
|
def search_options_button_clicked(self):
|
||||||
|
from calibre.gui2.layout import SearchOptions
|
||||||
|
|
||||||
fm = self.library_view.model().db.field_metadata
|
fm = self.library_view.model().db.field_metadata
|
||||||
ll = fm.get_search_terms()
|
ll = fm.get_search_terms()
|
||||||
ll = [l for l in ll if not l.startswith('@') and l not in fm.search_items]
|
ll = [l for l in ll if not l.startswith('@') and l not in fm.search_items]
|
||||||
print ll
|
options_box = SearchOptions(parent=self,
|
||||||
|
limit_to_fields=prefs['search_box_limit_to'],
|
||||||
from calibre.gui2.layout import SearchOptions
|
limit_field_list=ll,
|
||||||
options_box = SearchOptions(self,
|
limit_cbox=prefs['use_search_box_limit'],
|
||||||
limit_to_fields=prefs['search_box_limit_to'],
|
highlight_cbox=dynamic.get('search_highlight_only', False))
|
||||||
limit_field_list=ll,
|
|
||||||
limit_cbox=dynamic.get('use_search_box_limit', False),
|
|
||||||
highlight_cbox=dynamic.get('search_highlight_only', False))
|
|
||||||
r = options_box.exec_()
|
r = options_box.exec_()
|
||||||
if r:
|
if r:
|
||||||
limit_list, limit_cb, highlight_cb = options_box.values()
|
limit_list, limit_cbox, highlight_cbox = options_box.values()
|
||||||
print limit_list, limit_cb, highlight_cb
|
|
||||||
prefs['search_box_limit_to'] = limit_list
|
prefs['search_box_limit_to'] = limit_list
|
||||||
dynamic.set('use_search_box_limit', limit_cb)
|
prefs['use_search_box_limit'] = limit_cbox
|
||||||
prefs['use_search_box_limit'] = limit_cb
|
dynamic.set('search_highlight_only', highlight_cbox)
|
||||||
dynamic.set('search_highlight_only', highlight_cb)
|
self.current_view().model().set_highlight_only(highlight_cbox)
|
||||||
self.current_view().model().set_highlight_only(highlight_cb)
|
|
||||||
self.search.do_search()
|
self.search.do_search()
|
||||||
|
|
||||||
# self.search_highlight_only.stateChanged.connect(self.highlight_only_changed)
|
|
||||||
# self.search_highlight_only.setChecked(
|
|
||||||
# dynamic.get('search_highlight_only', False))
|
|
||||||
# self.search_limit_checkbox.stateChanged.connect(self.search_limit_checkbox_changed)
|
|
||||||
# self.search_limit_checkbox.setVisible(True)
|
|
||||||
# chk = dynamic.get('use_search_box_limit', False)
|
|
||||||
# self.search_limit_checkbox.setChecked(chk)
|
|
||||||
# prefs['use_search_box_limit'] = chk
|
|
||||||
# self.search_limit_checkbox.setEnabled(bool(prefs['search_box_limit_to']))
|
|
||||||
|
|
||||||
|
|
||||||
def focus_to_library(self):
|
def focus_to_library(self):
|
||||||
self.current_view().setFocus(Qt.OtherFocusReason)
|
self.current_view().setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
def highlight_only_changed(self, toWhat):
|
|
||||||
dynamic.set('search_highlight_only', toWhat)
|
|
||||||
self.current_view().model().set_highlight_only(toWhat)
|
|
||||||
self.focus_to_library()
|
|
||||||
|
|
||||||
def search_limit_checkbox_changed(self, toWhat):
|
|
||||||
toWhat = bool(toWhat)
|
|
||||||
dynamic.set('use_search_box_limit', toWhat)
|
|
||||||
prefs['use_search_box_limit'] = toWhat
|
|
||||||
self.search.do_search()
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class SavedSearchBoxMixin(object): # {{{
|
class SavedSearchBoxMixin(object): # {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user