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):
|
def do_selected(self, idx=None):
|
||||||
idx = self.currentIndex() if idx is None else idx
|
idx = self.currentIndex() if idx is None else idx
|
||||||
if not idx.isValid() and self.model().rowCount() > 0:
|
#if not idx.isValid() and self.model().rowCount() > 0:
|
||||||
idx = self.model().index(0)
|
# idx = self.model().index(0)
|
||||||
if idx.isValid():
|
if idx.isValid():
|
||||||
data = unicode(self.model().data(idx, Qt.DisplayRole))
|
data = unicode(self.model().data(idx, Qt.DisplayRole))
|
||||||
self.completion_selected.emit(data)
|
self.completion_selected.emit(data)
|
||||||
@ -175,9 +175,10 @@ class MultiCompleteLineEdit(QLineEdit):
|
|||||||
|
|
||||||
self._model = CompleteModel(parent=self)
|
self._model = CompleteModel(parent=self)
|
||||||
self.complete_window = CompleteWindow(self, self._model)
|
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.cursorPositionChanged.connect(self.cursor_position_changed)
|
||||||
self.complete_window.completion_selected.connect(self.completion_selected)
|
self.complete_window.completion_selected.connect(self.completion_selected)
|
||||||
|
self.installEventFilter(self)
|
||||||
|
|
||||||
# Interface {{{
|
# Interface {{{
|
||||||
def update_items_cache(self, complete_items):
|
def update_items_cache(self, complete_items):
|
||||||
@ -198,7 +199,7 @@ class MultiCompleteLineEdit(QLineEdit):
|
|||||||
return QLineEdit.eventFilter(self, o, e)
|
return QLineEdit.eventFilter(self, o, e)
|
||||||
|
|
||||||
|
|
||||||
def text_changed(self, *args):
|
def text_edited(self, *args):
|
||||||
self.update_completions()
|
self.update_completions()
|
||||||
|
|
||||||
def cursor_position_changed(self, *args):
|
def cursor_position_changed(self, *args):
|
||||||
@ -206,6 +207,8 @@ class MultiCompleteLineEdit(QLineEdit):
|
|||||||
|
|
||||||
def update_completions(self):
|
def update_completions(self):
|
||||||
' Update the list of completions '
|
' Update the list of completions '
|
||||||
|
if not self.complete_window.isVisible() and not self.hasFocus():
|
||||||
|
return
|
||||||
cpos = self.cursorPosition()
|
cpos = self.cursorPosition()
|
||||||
text = unicode(self.text())
|
text = unicode(self.text())
|
||||||
prefix = text[:cpos]
|
prefix = text[:cpos]
|
||||||
@ -223,7 +226,7 @@ class MultiCompleteLineEdit(QLineEdit):
|
|||||||
text
|
text
|
||||||
'''
|
'''
|
||||||
if self.sep is None:
|
if self.sep is None:
|
||||||
return text
|
return -1, -1, text
|
||||||
else:
|
else:
|
||||||
cursor_pos = self.cursorPosition()
|
cursor_pos = self.cursorPosition()
|
||||||
before_text = unicode(self.text())[:cursor_pos]
|
before_text = unicode(self.text())[:cursor_pos]
|
||||||
@ -334,6 +337,11 @@ class MultiCompleteComboBox(EnComboBox):
|
|||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
EnComboBox.__init__(self, *args)
|
EnComboBox.__init__(self, *args)
|
||||||
self.setLineEdit(MultiCompleteLineEdit(self))
|
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):
|
def update_items_cache(self, complete_items):
|
||||||
self.lineEdit().update_items_cache(complete_items)
|
self.lineEdit().update_items_cache(complete_items)
|
||||||
|
@ -12,7 +12,7 @@ from PyQt4.Qt import Qt, QDateEdit, QDate, \
|
|||||||
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, \
|
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, \
|
||||||
QPushButton, QSpinBox, QLineEdit
|
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.gui2.complete import MultiCompleteLineEdit, MultiCompleteComboBox
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.config import tweaks, prefs
|
from calibre.utils.config import tweaks, prefs
|
||||||
@ -283,13 +283,14 @@ class AuthorSortEdit(EnLineEdit):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Series {{{
|
# Series {{{
|
||||||
class SeriesEdit(EnComboBox):
|
class SeriesEdit(MultiCompleteComboBox):
|
||||||
|
|
||||||
TOOLTIP = _('List of known series. You can add new series.')
|
TOOLTIP = _('List of known series. You can add new series.')
|
||||||
LABEL = _('&Series:')
|
LABEL = _('&Series:')
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
EnComboBox.__init__(self, parent)
|
MultiCompleteComboBox.__init__(self, parent)
|
||||||
|
self.set_separator(None)
|
||||||
self.dialog = parent
|
self.dialog = parent
|
||||||
self.setSizeAdjustPolicy(
|
self.setSizeAdjustPolicy(
|
||||||
self.AdjustToMinimumContentsLengthWithIcon)
|
self.AdjustToMinimumContentsLengthWithIcon)
|
||||||
@ -314,6 +315,7 @@ class SeriesEdit(EnComboBox):
|
|||||||
def initialize(self, db, id_):
|
def initialize(self, db, id_):
|
||||||
all_series = db.all_series()
|
all_series = db.all_series()
|
||||||
all_series.sort(key=lambda x : sort_key(x[1]))
|
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)
|
series_id = db.series_id(id_, index_is_id=True)
|
||||||
idx, c = None, 0
|
idx, c = None, 0
|
||||||
for i in all_series:
|
for i in all_series:
|
||||||
@ -910,11 +912,12 @@ class ISBNEdit(QLineEdit): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class PublisherEdit(EnComboBox): # {{{
|
class PublisherEdit(MultiCompleteComboBox): # {{{
|
||||||
LABEL = _('&Publisher:')
|
LABEL = _('&Publisher:')
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
EnComboBox.__init__(self, parent)
|
MultiCompleteComboBox.__init__(self, parent)
|
||||||
|
self.set_separator(None)
|
||||||
self.setSizeAdjustPolicy(
|
self.setSizeAdjustPolicy(
|
||||||
self.AdjustToMinimumContentsLengthWithIcon)
|
self.AdjustToMinimumContentsLengthWithIcon)
|
||||||
|
|
||||||
@ -935,6 +938,7 @@ class PublisherEdit(EnComboBox): # {{{
|
|||||||
def initialize(self, db, id_):
|
def initialize(self, db, id_):
|
||||||
all_publishers = db.all_publishers()
|
all_publishers = db.all_publishers()
|
||||||
all_publishers.sort(key=lambda x : sort_key(x[1]))
|
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)
|
publisher_id = db.publisher_id(id_, index_is_id=True)
|
||||||
idx, c = None, 0
|
idx, c = None, 0
|
||||||
for i in all_publishers:
|
for i in all_publishers:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user