mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
use the new completer for publisher and series boxes as well
This commit is contained in:
parent
92b313ec7e
commit
1de9e0b94b
@ -64,8 +64,8 @@ class CompleteWindow(QListView): # {{{
|
||||
|
||||
def do_selected(self, idx=None):
|
||||
idx = self.currentIndex() if idx is None else idx
|
||||
if not idx.isValid() and self.model().rowCount() > 0:
|
||||
idx = self.model().index(0)
|
||||
#if not idx.isValid() and self.model().rowCount() > 0:
|
||||
# idx = self.model().index(0)
|
||||
if idx.isValid():
|
||||
data = unicode(self.model().data(idx, Qt.DisplayRole))
|
||||
self.completion_selected.emit(data)
|
||||
@ -175,9 +175,10 @@ class MultiCompleteLineEdit(QLineEdit):
|
||||
|
||||
self._model = CompleteModel(parent=self)
|
||||
self.complete_window = CompleteWindow(self, self._model)
|
||||
self.textChanged.connect(self.text_changed)
|
||||
self.textEdited.connect(self.text_edited)
|
||||
self.cursorPositionChanged.connect(self.cursor_position_changed)
|
||||
self.complete_window.completion_selected.connect(self.completion_selected)
|
||||
self.installEventFilter(self)
|
||||
|
||||
# Interface {{{
|
||||
def update_items_cache(self, complete_items):
|
||||
@ -198,7 +199,7 @@ class MultiCompleteLineEdit(QLineEdit):
|
||||
return QLineEdit.eventFilter(self, o, e)
|
||||
|
||||
|
||||
def text_changed(self, *args):
|
||||
def text_edited(self, *args):
|
||||
self.update_completions()
|
||||
|
||||
def cursor_position_changed(self, *args):
|
||||
@ -206,6 +207,8 @@ class MultiCompleteLineEdit(QLineEdit):
|
||||
|
||||
def update_completions(self):
|
||||
' Update the list of completions '
|
||||
if not self.complete_window.isVisible() and not self.hasFocus():
|
||||
return
|
||||
cpos = self.cursorPosition()
|
||||
text = unicode(self.text())
|
||||
prefix = text[:cpos]
|
||||
@ -223,7 +226,7 @@ class MultiCompleteLineEdit(QLineEdit):
|
||||
text
|
||||
'''
|
||||
if self.sep is None:
|
||||
return text
|
||||
return -1, -1, text
|
||||
else:
|
||||
cursor_pos = self.cursorPosition()
|
||||
before_text = unicode(self.text())[:cursor_pos]
|
||||
@ -334,6 +337,11 @@ class MultiCompleteComboBox(EnComboBox):
|
||||
def __init__(self, *args):
|
||||
EnComboBox.__init__(self, *args)
|
||||
self.setLineEdit(MultiCompleteLineEdit(self))
|
||||
# Needed to allow changing the case of an existing item
|
||||
# otherwise on focus out, the text is changed to the
|
||||
# item that matches case insensitively
|
||||
c = self.lineEdit().completer()
|
||||
c.setCaseSensitivity(Qt.CaseSensitive)
|
||||
|
||||
def update_items_cache(self, complete_items):
|
||||
self.lineEdit().update_items_cache(complete_items)
|
||||
|
@ -12,7 +12,7 @@ from PyQt4.Qt import Qt, QDateEdit, QDate, \
|
||||
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, \
|
||||
QPushButton, QSpinBox, QLineEdit
|
||||
|
||||
from calibre.gui2.widgets import EnLineEdit, EnComboBox, FormatList, ImageView
|
||||
from calibre.gui2.widgets import EnLineEdit, FormatList, ImageView
|
||||
from calibre.gui2.complete import MultiCompleteLineEdit, MultiCompleteComboBox
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.utils.config import tweaks, prefs
|
||||
@ -283,13 +283,14 @@ class AuthorSortEdit(EnLineEdit):
|
||||
# }}}
|
||||
|
||||
# Series {{{
|
||||
class SeriesEdit(EnComboBox):
|
||||
class SeriesEdit(MultiCompleteComboBox):
|
||||
|
||||
TOOLTIP = _('List of known series. You can add new series.')
|
||||
LABEL = _('&Series:')
|
||||
|
||||
def __init__(self, parent):
|
||||
EnComboBox.__init__(self, parent)
|
||||
MultiCompleteComboBox.__init__(self, parent)
|
||||
self.set_separator(None)
|
||||
self.dialog = parent
|
||||
self.setSizeAdjustPolicy(
|
||||
self.AdjustToMinimumContentsLengthWithIcon)
|
||||
@ -314,6 +315,7 @@ class SeriesEdit(EnComboBox):
|
||||
def initialize(self, db, id_):
|
||||
all_series = db.all_series()
|
||||
all_series.sort(key=lambda x : sort_key(x[1]))
|
||||
self.update_items_cache([x[1] for x in all_series])
|
||||
series_id = db.series_id(id_, index_is_id=True)
|
||||
idx, c = None, 0
|
||||
for i in all_series:
|
||||
@ -910,11 +912,12 @@ class ISBNEdit(QLineEdit): # {{{
|
||||
|
||||
# }}}
|
||||
|
||||
class PublisherEdit(EnComboBox): # {{{
|
||||
class PublisherEdit(MultiCompleteComboBox): # {{{
|
||||
LABEL = _('&Publisher:')
|
||||
|
||||
def __init__(self, parent):
|
||||
EnComboBox.__init__(self, parent)
|
||||
MultiCompleteComboBox.__init__(self, parent)
|
||||
self.set_separator(None)
|
||||
self.setSizeAdjustPolicy(
|
||||
self.AdjustToMinimumContentsLengthWithIcon)
|
||||
|
||||
@ -935,6 +938,7 @@ class PublisherEdit(EnComboBox): # {{{
|
||||
def initialize(self, db, id_):
|
||||
all_publishers = db.all_publishers()
|
||||
all_publishers.sort(key=lambda x : sort_key(x[1]))
|
||||
self.update_items_cache([x[1] for x in all_publishers])
|
||||
publisher_id = db.publisher_id(id_, index_is_id=True)
|
||||
idx, c = None, 0
|
||||
for i in all_publishers:
|
||||
|
Loading…
x
Reference in New Issue
Block a user