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.book_details import BookDetails
|
||||
from calibre.gui2.notify import get_notifier
|
||||
from calibre.utils.config import dynamic
|
||||
|
||||
_keep_refs = []
|
||||
|
||||
@ -64,6 +65,8 @@ class LibraryViewMixin(object): # {{{
|
||||
view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book)
|
||||
|
||||
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):
|
||||
lm = QMenu(self)
|
||||
|
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
||||
from functools import partial
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ from calibre.gui2 import gprefs
|
||||
from calibre.gui2.widgets import ComboBoxWithHelp
|
||||
from calibre.gui2.complete import MultiCompleteLineEdit
|
||||
from calibre import human_readable
|
||||
from calibre.utils.config import prefs
|
||||
|
||||
class LocationManager(QObject): # {{{
|
||||
|
||||
@ -151,8 +150,6 @@ class SearchBar(QWidget): # {{{
|
||||
|
||||
def __init__(self, parent):
|
||||
QWidget.__init__(self, parent)
|
||||
self.parent = parent
|
||||
|
||||
self._layout = l = QHBoxLayout()
|
||||
self.setLayout(self._layout)
|
||||
self._layout.setContentsMargins(0,5,0,0)
|
||||
@ -162,8 +159,8 @@ class SearchBar(QWidget): # {{{
|
||||
x.setObjectName("search_restriction")
|
||||
x.setToolTip(_('Books display will be restricted to those matching the '
|
||||
'selected saved search'))
|
||||
parent.search_restriction = x
|
||||
l.addWidget(x)
|
||||
parent.search_restriction = x
|
||||
|
||||
x = QLabel(self)
|
||||
x.setObjectName("search_count")
|
||||
@ -237,21 +234,26 @@ class SearchOptions(QDialog):
|
||||
def __init__(self, parent, limit_to_fields, limit_field_list,
|
||||
limit_cbox, highlight_cbox):
|
||||
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'))
|
||||
l = QGridLayout()
|
||||
self.setLayout(l)
|
||||
|
||||
x = QLabel(_(' '), parent=self)
|
||||
x.setBuddy(parent.search_restriction)
|
||||
l.addWidget(x, 1, 0, 1, 1)
|
||||
x = QLabel(_('Use this box to change search options related to how '
|
||||
'results are displayed and which fields are searched. '
|
||||
'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.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 '
|
||||
'N or F3 keys to go to the next match.'))
|
||||
x.setChecked(highlight_cbox)
|
||||
@ -268,8 +270,8 @@ class SearchOptions(QDialog):
|
||||
'Preferences -> Look and Feel -> Limit non-prefixed searches to columns.'))
|
||||
x.setChecked(limit_cbox)
|
||||
l.addWidget(x, 3, 1, 1, 1)
|
||||
x = QLabel(_('Check this box if you want non-prefixed searches to be '
|
||||
'&limited to certain fields/lookup names'), parent=self)
|
||||
x = QLabel(_('Check this box if you want non-&prefixed searches to be '
|
||||
'limited to certain fields/lookup names'), parent=self)
|
||||
x.setBuddy(self.search_limit_checkbox)
|
||||
l.addWidget(x, 3, 0, 1, 1)
|
||||
|
||||
@ -284,15 +286,15 @@ class SearchOptions(QDialog):
|
||||
x.update_items_cache(limit_field_list)
|
||||
x.setText(limit_to_fields)
|
||||
l.addWidget(x, 4, 1, 1, 1)
|
||||
x = QLabel(_('Enter the list of fields that non-prefixed searches '
|
||||
'are &limited to'), parent=self)
|
||||
x = QLabel(_('Enter the list of &columns that non-prefixed searches '
|
||||
'are limited to'), parent=self)
|
||||
x.setBuddy(self.search_box_limit_to)
|
||||
l.addWidget(x, 4, 0, 1, 1)
|
||||
|
||||
buttons = QDialogButtonBox()
|
||||
buttons.addButton(QDialogButtonBox.Ok)
|
||||
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.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>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MultiCompleteLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>calibre.gui2.complete.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -376,10 +376,7 @@ class SearchBoxMixin(object): # {{{
|
||||
unicode(self.search.toolTip())))
|
||||
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
|
||||
self.clear_button.setStatusTip(self.clear_button.toolTip())
|
||||
|
||||
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):
|
||||
self.search.setFocus(Qt.OtherFocusReason)
|
||||
@ -404,53 +401,28 @@ class SearchBoxMixin(object): # {{{
|
||||
self.focus_to_library()
|
||||
|
||||
def search_options_button_clicked(self):
|
||||
from calibre.gui2.layout import SearchOptions
|
||||
|
||||
fm = self.library_view.model().db.field_metadata
|
||||
ll = fm.get_search_terms()
|
||||
ll = [l for l in ll if not l.startswith('@') and l not in fm.search_items]
|
||||
print ll
|
||||
|
||||
from calibre.gui2.layout import SearchOptions
|
||||
options_box = SearchOptions(self,
|
||||
limit_to_fields=prefs['search_box_limit_to'],
|
||||
limit_field_list=ll,
|
||||
limit_cbox=dynamic.get('use_search_box_limit', False),
|
||||
highlight_cbox=dynamic.get('search_highlight_only', False))
|
||||
options_box = SearchOptions(parent=self,
|
||||
limit_to_fields=prefs['search_box_limit_to'],
|
||||
limit_field_list=ll,
|
||||
limit_cbox=prefs['use_search_box_limit'],
|
||||
highlight_cbox=dynamic.get('search_highlight_only', False))
|
||||
r = options_box.exec_()
|
||||
if r:
|
||||
limit_list, limit_cb, highlight_cb = options_box.values()
|
||||
print limit_list, limit_cb, highlight_cb
|
||||
limit_list, limit_cbox, highlight_cbox = options_box.values()
|
||||
prefs['search_box_limit_to'] = limit_list
|
||||
dynamic.set('use_search_box_limit', limit_cb)
|
||||
prefs['use_search_box_limit'] = limit_cb
|
||||
dynamic.set('search_highlight_only', highlight_cb)
|
||||
self.current_view().model().set_highlight_only(highlight_cb)
|
||||
prefs['use_search_box_limit'] = limit_cbox
|
||||
dynamic.set('search_highlight_only', highlight_cbox)
|
||||
self.current_view().model().set_highlight_only(highlight_cbox)
|
||||
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):
|
||||
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): # {{{
|
||||
|
Loading…
x
Reference in New Issue
Block a user