mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Change search restriction box to use grey help text. Remove label.
This commit is contained in:
parent
2ac4403254
commit
0a7171d7b7
@ -123,17 +123,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="restriction_label">
|
<widget class="ComboBoxWithHelp" name="search_restriction">
|
||||||
<property name="text">
|
|
||||||
<string>&Restrict to:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>search_restriction</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="search_restriction">
|
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>150</width>
|
<width>150</width>
|
||||||
@ -543,6 +533,11 @@
|
|||||||
<extends>QComboBox</extends>
|
<extends>QComboBox</extends>
|
||||||
<header>calibre.gui2.search_box</header>
|
<header>calibre.gui2.search_box</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>ComboBoxWithHelp</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>calibre.gui2.widgets</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ThrobbingButton</class>
|
<class>ThrobbingButton</class>
|
||||||
<extends>QToolButton</extends>
|
<extends>QToolButton</extends>
|
||||||
|
@ -7,7 +7,8 @@ Created on 10 Jun 2010
|
|||||||
class SearchRestrictionMixin(object):
|
class SearchRestrictionMixin(object):
|
||||||
|
|
||||||
def __init__(self):
|
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.library_view.model().count_changed_signal.connect(self.restriction_count_changed)
|
||||||
self.search_restriction.setSizeAdjustPolicy(self.search_restriction.AdjustToMinimumContentsLengthWithIcon)
|
self.search_restriction.setSizeAdjustPolicy(self.search_restriction.AdjustToMinimumContentsLengthWithIcon)
|
||||||
self.search_restriction.setMinimumContentsLength(10)
|
self.search_restriction.setMinimumContentsLength(10)
|
||||||
@ -27,8 +28,8 @@ class SearchRestrictionMixin(object):
|
|||||||
if self.restriction_in_effect:
|
if self.restriction_in_effect:
|
||||||
self.set_number_of_books_shown()
|
self.set_number_of_books_shown()
|
||||||
|
|
||||||
def apply_search_restriction(self, r):
|
def apply_search_restriction(self, i):
|
||||||
r = unicode(r)
|
r = unicode(self.search_restriction.currentText())
|
||||||
if r is not None and r != '':
|
if r is not None and r != '':
|
||||||
self.restriction_in_effect = True
|
self.restriction_in_effect = True
|
||||||
restriction = 'search:"%s"'%(r)
|
restriction = 'search:"%s"'%(r)
|
||||||
|
@ -731,6 +731,58 @@ class HistoryLineEdit(QComboBox):
|
|||||||
def text(self):
|
def text(self):
|
||||||
return self.currentText()
|
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):
|
class PythonHighlighter(QSyntaxHighlighter):
|
||||||
|
|
||||||
Rules = []
|
Rules = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user