Change search restriction box to use grey help text. Remove label.

This commit is contained in:
Charles Haley 2010-07-10 06:40:53 +01:00
parent 2ac4403254
commit 0a7171d7b7
3 changed files with 62 additions and 14 deletions

View File

@ -123,17 +123,7 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="restriction_label">
<property name="text">
<string>&amp;Restrict to:</string>
</property>
<property name="buddy">
<cstring>search_restriction</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="search_restriction">
<widget class="ComboBoxWithHelp" name="search_restriction">
<property name="maximumSize">
<size>
<width>150</width>
@ -543,6 +533,11 @@
<extends>QComboBox</extends>
<header>calibre.gui2.search_box</header>
</customwidget>
<customwidget>
<class>ComboBoxWithHelp</class>
<extends>QComboBox</extends>
<header>calibre.gui2.widgets</header>
</customwidget>
<customwidget>
<class>ThrobbingButton</class>
<extends>QToolButton</extends>

View File

@ -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)

View File

@ -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 = []