diff --git a/src/calibre/gui2/complete.py b/src/calibre/gui2/complete.py index bb9e0cb4c9..8110618bac 100644 --- a/src/calibre/gui2/complete.py +++ b/src/calibre/gui2/complete.py @@ -6,8 +6,8 @@ __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt4.Qt import QLineEdit, QAbstractListModel, Qt, \ - QApplication, QCompleter +from PyQt4.Qt import (QLineEdit, QAbstractListModel, Qt, + QApplication, QCompleter, QMetaObject) from calibre.utils.icu import sort_key, lower from calibre.gui2 import NONE @@ -182,14 +182,22 @@ class MultiCompleteComboBox(EnComboBox): def set_add_separator(self, what): self.lineEdit().set_add_separator(what) - + def show_initial_value(self, what): + what = unicode(what) + le = self.lineEdit() + if not what.strip(): + QMetaObject.invokeMethod(self, 'clearEditText', + Qt.QueuedConnection) + else: + self.setEditText(what) + le.selectAll() if __name__ == '__main__': from PyQt4.Qt import QDialog, QVBoxLayout app = QApplication([]) d = QDialog() d.setLayout(QVBoxLayout()) - le = MultiCompleteLineEdit(d) + le = MultiCompleteComboBox(d) d.layout().addWidget(le) le.all_items = ['one', 'otwo', 'othree', 'ooone', 'ootwo', 'oothree'] d.exec_() diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 81d25c1f5e..60b8e3445d 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -128,8 +128,7 @@ class TextDelegate(QStyledItemDelegate): # {{{ for item in sorted(complete_items, key=sort_key): editor.addItem(item) ct = index.data(Qt.DisplayRole).toString() - editor.setEditText(ct) - editor.lineEdit().selectAll() + editor.show_initial_value(ct) else: editor = EnLineEdit(parent) return editor @@ -170,8 +169,7 @@ class CompleteDelegate(QStyledItemDelegate): # {{{ for item in sorted(all_items, key=sort_key): editor.addItem(item) ct = index.data(Qt.DisplayRole).toString() - editor.setEditText(ct) - editor.lineEdit().selectAll() + editor.show_initial_value(ct) else: editor = EnLineEdit(parent) return editor @@ -190,8 +188,7 @@ class LanguagesDelegate(QStyledItemDelegate): # {{{ editor = LanguagesEdit(parent=parent) editor.init_langs(index.model().db) ct = index.data(Qt.DisplayRole).toString() - editor.setEditText(ct) - editor.lineEdit().selectAll() + editor.show_initial_value(ct) return editor def setModelData(self, editor, model, index):