diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
index af4ca16eac..dc1ca7f2bd 100644
--- a/src/calibre/gui2/__init__.py
+++ b/src/calibre/gui2/__init__.py
@@ -71,6 +71,9 @@ def _config():
help='Show donation button')
c.add_opt('asked_library_thing_password', default=False,
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)
config = _config()
diff --git a/src/calibre/gui2/dialogs/config.py b/src/calibre/gui2/dialogs/config.py
index 1c337788c6..52b2caeaea 100644
--- a/src/calibre/gui2/dialogs/config.py
+++ b/src/calibre/gui2/dialogs/config.py
@@ -437,6 +437,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
self.password.setText(opts.password if opts.password else '')
self.auto_launch.setChecked(config['autolaunch_server'])
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.delete_news.setChecked(config['delete_news_from_library_on_upload'])
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)
config['delete_news_from_library_on_upload'] = self.delete_news.isChecked()
config['upload_news_to_device'] = self.sync_news.isChecked()
+ config['search_as_you_type'] = self.search_as_you_type.isChecked()
fmts = []
for i in range(self.viewer.count()):
if self.viewer.item(i).checkState() == Qt.Checked:
diff --git a/src/calibre/gui2/dialogs/config.ui b/src/calibre/gui2/dialogs/config.ui
index f2cf9b3202..55e5ce0552 100644
--- a/src/calibre/gui2/dialogs/config.ui
+++ b/src/calibre/gui2/dialogs/config.ui
@@ -8,7 +8,7 @@
0
0
800
- 557
+ 583
@@ -426,6 +426,16 @@
+ -
+
+
+ Search as you type
+
+
+ true
+
+
+
-
@@ -591,15 +601,6 @@
- roman_numerals
- groupBox_2
- systray_icon
- sync_news
- delete_news
- separate_cover_flow
- systray_notifications
-
-
diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py
index 3d5a30ec05..266a878440 100644
--- a/src/calibre/gui2/library.py
+++ b/src/calibre/gui2/library.py
@@ -1095,6 +1095,7 @@ class SearchBox(QLineEdit):
QLineEdit.__init__(self, parent)
self.help_text = help_text
self.initial_state = True
+ self.as_you_type = True
self.default_palette = QApplication.palette(self)
self.gray = QPalette(self.default_palette)
self.gray.setBrush(QPalette.Text, QBrush(QColor('gray')))
@@ -1123,6 +1124,9 @@ class SearchBox(QLineEdit):
if self.initial_state:
self.normalize_state()
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)
def mouseReleaseEvent(self, event):
@@ -1132,17 +1136,21 @@ class SearchBox(QLineEdit):
QLineEdit.mouseReleaseEvent(self, event)
def text_edited_slot(self, text):
- text = qstring_to_unicode(text) if isinstance(text, QString) else unicode(text)
- self.prev_text = text
- self.timer = self.startTimer(self.__class__.INTERVAL)
+ if self.as_you_type:
+ text = qstring_to_unicode(text) if isinstance(text, QString) else unicode(text)
+ self.prev_text = text
+ self.timer = self.startTimer(self.__class__.INTERVAL)
def timerEvent(self, event):
self.killTimer(event.timerId())
if event.timerId() == self.timer:
- 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)
+ self.do_search()
+
+ def do_search(self):
+ 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):
ans = u' '.join([u'%s:%s'%x for x in tokens])
@@ -1161,3 +1169,6 @@ class SearchBox(QLineEdit):
self.end(False)
self.initial_state = False
+ def search_as_you_type(self, enabled):
+ self.as_you_type = enabled
+
diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py
index cd1e545a29..4384121418 100644
--- a/src/calibre/gui2/main.py
+++ b/src/calibre/gui2/main.py
@@ -148,6 +148,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.system_tray_icon.hide()
else:
self.system_tray_icon.show()
+ self.search.search_as_you_type(config['search_as_you_type'])
self.system_tray_menu = QMenu(self)
self.restore_action = self.system_tray_menu.addAction(
QIcon(':/images/page.svg'), _('&Restore'))
@@ -1422,6 +1423,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.content_server = d.server
if d.result() == d.Accepted:
self.tool_bar.setIconSize(config['toolbar_icon_size'])
+ self.search.search_as_you_type(config['search_as_you_type'])
self.tool_bar.setToolButtonStyle(
Qt.ToolButtonTextUnderIcon if \
config['show_text_in_toolbar'] else \