diff --git a/src/calibre/gui2/main.ui b/src/calibre/gui2/main.ui index d89a451cda..0d937527f6 100644 --- a/src/calibre/gui2/main.ui +++ b/src/calibre/gui2/main.ui @@ -123,17 +123,7 @@ 0 - - - &Restrict to: - - - search_restriction - - - - - + 150 @@ -543,6 +533,11 @@ QComboBox
calibre.gui2.search_box
+ + ComboBoxWithHelp + QComboBox +
calibre.gui2.widgets
+
ThrobbingButton QToolButton diff --git a/src/calibre/gui2/search_restriction_mixin.py b/src/calibre/gui2/search_restriction_mixin.py index 3a71fa3de0..6f31f65c13 100644 --- a/src/calibre/gui2/search_restriction_mixin.py +++ b/src/calibre/gui2/search_restriction_mixin.py @@ -7,7 +7,8 @@ Created on 10 Jun 2010 class SearchRestrictionMixin(object): def __init__(self): - self.search_restriction.activated[str].connect(self.apply_search_restriction) + self.search_restriction.initialize(help_text=_('Restrict To')) + self.search_restriction.activated[int].connect(self.apply_search_restriction) self.library_view.model().count_changed_signal.connect(self.restriction_count_changed) self.search_restriction.setSizeAdjustPolicy(self.search_restriction.AdjustToMinimumContentsLengthWithIcon) self.search_restriction.setMinimumContentsLength(10) @@ -27,8 +28,8 @@ class SearchRestrictionMixin(object): if self.restriction_in_effect: self.set_number_of_books_shown() - def apply_search_restriction(self, r): - r = unicode(r) + def apply_search_restriction(self, i): + r = unicode(self.search_restriction.currentText()) if r is not None and r != '': self.restriction_in_effect = True restriction = 'search:"%s"'%(r) diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index d94d8e7292..63be2b19ec 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -731,6 +731,58 @@ class HistoryLineEdit(QComboBox): def text(self): return self.currentText() +class ComboBoxWithHelp(QComboBox): + ''' + A combobox where item 0 is help text. CurrentText will return '' for item 0. + Be sure to always fetch the text with currentText. Don't use the signals + that pass a string, because they will not correct the text. + ''' + def __init__(self, parent=None): + QComboBox.__init__(self, parent) + self.normal_background = 'rgb(255, 255, 255, 0%)' + self.connect(self, SIGNAL('currentIndexChanged(int)'), self.index_changed) + self.help_text = '' + self.state_set = False + + def initialize(self, help_text=_('Search')): + self.help_text = help_text + self.set_state() + + def set_state(self): + if not self.state_set: + if self.currentIndex() == 0: + self.setItemText(0, self.help_text) + self.setStyleSheet( + 'QComboBox { color: gray; background-color: %s; }' % + self.normal_background) + else: + self.setItemText(0, '') + self.setStyleSheet( + 'QComboBox { color: black; background-color: %s; }' % + self.normal_background) + + def index_changed(self, index): + self.state_set = False + self.set_state() + + def currentText(self): + if self.currentIndex() == 0: + return '' + return QComboBox.currentText(self) + + def itemText(self, idx): + if idx == 0: + return '' + return QComboBox.itemText(self, idx) + + def showPopup(self): + self.setItemText(0, '') + QComboBox.showPopup(self) + + def hidePopup(self): + QComboBox.hidePopup(self) + self.set_state() + class PythonHighlighter(QSyntaxHighlighter): Rules = []