mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement bug #810: Search can be as you type or only on Enter/Return.
This commit is contained in:
parent
ccdc693b97
commit
21140bc72b
@ -71,6 +71,9 @@ def _config():
|
|||||||
help='Show donation button')
|
help='Show donation button')
|
||||||
c.add_opt('asked_library_thing_password', default=False,
|
c.add_opt('asked_library_thing_password', default=False,
|
||||||
help='Asked library thing password at least once.')
|
help='Asked library thing password at least once.')
|
||||||
|
c.add_opt('search_as_you_type', default=True,
|
||||||
|
help='Start searching as you type. If this is disabled then seaerch will '
|
||||||
|
'only take place when the Enter or Return key is pressed.')
|
||||||
return ConfigProxy(c)
|
return ConfigProxy(c)
|
||||||
|
|
||||||
config = _config()
|
config = _config()
|
||||||
|
@ -437,6 +437,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.password.setText(opts.password if opts.password else '')
|
self.password.setText(opts.password if opts.password else '')
|
||||||
self.auto_launch.setChecked(config['autolaunch_server'])
|
self.auto_launch.setChecked(config['autolaunch_server'])
|
||||||
self.systray_icon.setChecked(config['systray_icon'])
|
self.systray_icon.setChecked(config['systray_icon'])
|
||||||
|
self.search_as_you_type.setChecked(config['search_as_you_type'])
|
||||||
self.sync_news.setChecked(config['upload_news_to_device'])
|
self.sync_news.setChecked(config['upload_news_to_device'])
|
||||||
self.delete_news.setChecked(config['delete_news_from_library_on_upload'])
|
self.delete_news.setChecked(config['delete_news_from_library_on_upload'])
|
||||||
p = {'normal':0, 'high':1, 'low':2}[prefs['worker_process_priority']]
|
p = {'normal':0, 'high':1, 'low':2}[prefs['worker_process_priority']]
|
||||||
@ -707,6 +708,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
sc.set('max_cover', mcs)
|
sc.set('max_cover', mcs)
|
||||||
config['delete_news_from_library_on_upload'] = self.delete_news.isChecked()
|
config['delete_news_from_library_on_upload'] = self.delete_news.isChecked()
|
||||||
config['upload_news_to_device'] = self.sync_news.isChecked()
|
config['upload_news_to_device'] = self.sync_news.isChecked()
|
||||||
|
config['search_as_you_type'] = self.search_as_you_type.isChecked()
|
||||||
fmts = []
|
fmts = []
|
||||||
for i in range(self.viewer.count()):
|
for i in range(self.viewer.count()):
|
||||||
if self.viewer.item(i).checkState() == Qt.Checked:
|
if self.viewer.item(i).checkState() == Qt.Checked:
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>557</height>
|
<height>583</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -426,6 +426,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="search_as_you_type">
|
||||||
|
<property name="text">
|
||||||
|
<string>Search as you type</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="sync_news">
|
<widget class="QCheckBox" name="sync_news">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -591,15 +601,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
<zorder>roman_numerals</zorder>
|
|
||||||
<zorder>groupBox_2</zorder>
|
|
||||||
<zorder>systray_icon</zorder>
|
|
||||||
<zorder>sync_news</zorder>
|
|
||||||
<zorder>delete_news</zorder>
|
|
||||||
<zorder>separate_cover_flow</zorder>
|
|
||||||
<zorder>systray_notifications</zorder>
|
|
||||||
<zorder></zorder>
|
|
||||||
<zorder></zorder>
|
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_6">
|
<widget class="QWidget" name="page_6">
|
||||||
<layout class="QGridLayout" name="gridLayout_6">
|
<layout class="QGridLayout" name="gridLayout_6">
|
||||||
|
@ -1095,6 +1095,7 @@ class SearchBox(QLineEdit):
|
|||||||
QLineEdit.__init__(self, parent)
|
QLineEdit.__init__(self, parent)
|
||||||
self.help_text = help_text
|
self.help_text = help_text
|
||||||
self.initial_state = True
|
self.initial_state = True
|
||||||
|
self.as_you_type = True
|
||||||
self.default_palette = QApplication.palette(self)
|
self.default_palette = QApplication.palette(self)
|
||||||
self.gray = QPalette(self.default_palette)
|
self.gray = QPalette(self.default_palette)
|
||||||
self.gray.setBrush(QPalette.Text, QBrush(QColor('gray')))
|
self.gray.setBrush(QPalette.Text, QBrush(QColor('gray')))
|
||||||
@ -1123,6 +1124,9 @@ class SearchBox(QLineEdit):
|
|||||||
if self.initial_state:
|
if self.initial_state:
|
||||||
self.normalize_state()
|
self.normalize_state()
|
||||||
self.initial_state = False
|
self.initial_state = False
|
||||||
|
if not self.as_you_type:
|
||||||
|
if event.key() in (Qt.Key_Return, Qt.Key_Enter):
|
||||||
|
self.do_search()
|
||||||
QLineEdit.keyPressEvent(self, event)
|
QLineEdit.keyPressEvent(self, event)
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
@ -1132,17 +1136,21 @@ class SearchBox(QLineEdit):
|
|||||||
QLineEdit.mouseReleaseEvent(self, event)
|
QLineEdit.mouseReleaseEvent(self, event)
|
||||||
|
|
||||||
def text_edited_slot(self, text):
|
def text_edited_slot(self, text):
|
||||||
text = qstring_to_unicode(text) if isinstance(text, QString) else unicode(text)
|
if self.as_you_type:
|
||||||
self.prev_text = text
|
text = qstring_to_unicode(text) if isinstance(text, QString) else unicode(text)
|
||||||
self.timer = self.startTimer(self.__class__.INTERVAL)
|
self.prev_text = text
|
||||||
|
self.timer = self.startTimer(self.__class__.INTERVAL)
|
||||||
|
|
||||||
def timerEvent(self, event):
|
def timerEvent(self, event):
|
||||||
self.killTimer(event.timerId())
|
self.killTimer(event.timerId())
|
||||||
if event.timerId() == self.timer:
|
if event.timerId() == self.timer:
|
||||||
text = qstring_to_unicode(self.text())
|
self.do_search()
|
||||||
refinement = text.startswith(self.prev_search) and ':' not in text
|
|
||||||
self.prev_search = text
|
def do_search(self):
|
||||||
self.emit(SIGNAL('search(PyQt_PyObject, PyQt_PyObject)'), text, refinement)
|
text = qstring_to_unicode(self.text())
|
||||||
|
refinement = text.startswith(self.prev_search) and ':' not in text
|
||||||
|
self.prev_search = text
|
||||||
|
self.emit(SIGNAL('search(PyQt_PyObject, PyQt_PyObject)'), text, refinement)
|
||||||
|
|
||||||
def search_from_tokens(self, tokens, all):
|
def search_from_tokens(self, tokens, all):
|
||||||
ans = u' '.join([u'%s:%s'%x for x in tokens])
|
ans = u' '.join([u'%s:%s'%x for x in tokens])
|
||||||
@ -1161,3 +1169,6 @@ class SearchBox(QLineEdit):
|
|||||||
self.end(False)
|
self.end(False)
|
||||||
self.initial_state = False
|
self.initial_state = False
|
||||||
|
|
||||||
|
def search_as_you_type(self, enabled):
|
||||||
|
self.as_you_type = enabled
|
||||||
|
|
||||||
|
@ -148,6 +148,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
self.system_tray_icon.hide()
|
self.system_tray_icon.hide()
|
||||||
else:
|
else:
|
||||||
self.system_tray_icon.show()
|
self.system_tray_icon.show()
|
||||||
|
self.search.search_as_you_type(config['search_as_you_type'])
|
||||||
self.system_tray_menu = QMenu(self)
|
self.system_tray_menu = QMenu(self)
|
||||||
self.restore_action = self.system_tray_menu.addAction(
|
self.restore_action = self.system_tray_menu.addAction(
|
||||||
QIcon(':/images/page.svg'), _('&Restore'))
|
QIcon(':/images/page.svg'), _('&Restore'))
|
||||||
@ -1422,6 +1423,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
self.content_server = d.server
|
self.content_server = d.server
|
||||||
if d.result() == d.Accepted:
|
if d.result() == d.Accepted:
|
||||||
self.tool_bar.setIconSize(config['toolbar_icon_size'])
|
self.tool_bar.setIconSize(config['toolbar_icon_size'])
|
||||||
|
self.search.search_as_you_type(config['search_as_you_type'])
|
||||||
self.tool_bar.setToolButtonStyle(
|
self.tool_bar.setToolButtonStyle(
|
||||||
Qt.ToolButtonTextUnderIcon if \
|
Qt.ToolButtonTextUnderIcon if \
|
||||||
config['show_text_in_toolbar'] else \
|
config['show_text_in_toolbar'] else \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user