From 13b47f4a29935c77b5773f4a1d78e1683a8389ab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 12 Mar 2014 09:59:42 +0530 Subject: [PATCH] Edit book: Allow disabling the completion popups for the search and replace fields. Right click on the search/replace field to enable/disable the completion popup --- src/calibre/gui2/complete2.py | 10 ++++++++++ src/calibre/gui2/tweak_book/__init__.py | 1 + src/calibre/gui2/tweak_book/search.py | 21 +++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index d19e9aaff4..fe794902ea 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -76,6 +76,7 @@ class Completer(QListView): # {{{ def __init__(self, completer_widget, max_visible_items=7): QListView.__init__(self) + self.disable_popup = False self.completer_widget = weakref.ref(completer_widget) self.setWindowFlags(Qt.Popup) self.max_visible_items = max_visible_items @@ -132,6 +133,8 @@ class Completer(QListView): # {{{ self.setCurrentIndex(index) def popup(self, select_first=True): + if self.disable_popup: + return p = self m = p.model() widget = self.completer_widget() @@ -293,6 +296,13 @@ class LineEdit(QLineEdit, LineEditECM): self.mcompleter.model().set_items(items) return property(fget=fget, fset=fset) + @dynamic_property + def disable_popup(self): + def fget(self): + return self.mcompleter.disable_popup + def fset(self, val): + self.mcompleter.disable_popup = bool(val) + return property(fget=fget, fset=fset) # }}} def complete(self, show_all=False, select_first=True): diff --git a/src/calibre/gui2/tweak_book/__init__.py b/src/calibre/gui2/tweak_book/__init__.py index 1f2f5fa1bc..2085568d6c 100644 --- a/src/calibre/gui2/tweak_book/__init__.py +++ b/src/calibre/gui2/tweak_book/__init__.py @@ -40,6 +40,7 @@ d['remove_existing_links_when_linking_sheets'] = True d['charmap_favorites'] = list(map(ord, '\xa0\u2002\u2003\u2009\xad' '‘’“”‹›«»‚„' '—–§¶†‡©®™' '→⇒•·°±−×÷¼½½¾' '…µ¢£€¿¡¨´¸ˆ˜' 'ÀÁÂÃÄÅÆÇÈÉÊË' 'ÌÍÎÏÐÑÒÓÔÕÖØ' 'ŒŠÙÚÛÜÝŸÞßàá' 'âãäåæçèéêëìí' 'îïðñòóôõöøœš' 'ùúûüýÿþªºαΩ∞')) # noqa d['folders_for_types'] = {'style':'styles', 'image':'images', 'font':'fonts', 'audio':'audio', 'video':'video'} d['pretty_print_on_open'] = False +d['disable_completion_popup_for_search'] = False del d diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index ce2446d7b3..6988aa5912 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -25,6 +25,23 @@ class PushButton(QPushButton): QPushButton.__init__(self, text, parent) self.clicked.connect(lambda : parent.search_triggered.emit(action)) +class HistoryLineEdit(HistoryLineEdit2): + + def __init__(self, parent): + HistoryLineEdit2.__init__(self, parent) + self.disable_popup = tprefs['disable_completion_popup_for_search'] + + def contextMenuEvent(self, event): + menu = self.createStandardContextMenu() + menu.addSeparator() + menu.addAction((_('Show completion based on search history') if self.disable_popup else _( + 'Hide completion based on search history')), self.toggle_popups) + menu.exec_(event.globalPos()) + + def toggle_popups(self): + self.disable_popup = not bool(self.disable_popup) + tprefs['disable_completion_popup_for_search'] = self.disable_popup + class SearchWidget(QWidget): DEFAULT_STATE = { @@ -46,7 +63,7 @@ class SearchWidget(QWidget): self.fl = fl = QLabel(_('&Find:')) fl.setAlignment(Qt.AlignRight | Qt.AlignCenter) - self.find_text = ft = HistoryLineEdit2(self) + self.find_text = ft = HistoryLineEdit(self) ft.initialize('tweak_book_find_edit') ft.returnPressed.connect(lambda : self.search_triggered.emit('find')) fl.setBuddy(ft) @@ -55,7 +72,7 @@ class SearchWidget(QWidget): self.rl = rl = QLabel(_('&Replace:')) rl.setAlignment(Qt.AlignRight | Qt.AlignCenter) - self.replace_text = rt = HistoryLineEdit2(self) + self.replace_text = rt = HistoryLineEdit(self) rt.initialize('tweak_book_replace_edit') rl.setBuddy(rt) l.addWidget(rl, 1, 0)