mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Do a bit less work when building completion lists
This commit is contained in:
parent
7e5438a76a
commit
66ae34e2d3
@ -510,7 +510,7 @@ class Cache(object):
|
|||||||
return frozenset(self.fields[field].table.col_book_map)
|
return frozenset(self.fields[field].table.col_book_map)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return frozenset(itervalues(self.fields[field].table.id_map))
|
return frozenset(self.fields[field].table.id_map.values())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise ValueError('%s is not a many-one or many-many field' % field)
|
raise ValueError('%s is not a many-one or many-many field' % field)
|
||||||
|
|
||||||
|
@ -36,8 +36,10 @@ class CompleteModel(QAbstractListModel): # {{{
|
|||||||
self.current_prefix = ''
|
self.current_prefix = ''
|
||||||
|
|
||||||
def set_items(self, items):
|
def set_items(self, items):
|
||||||
items = [unicode_type(x).strip() if self.strip_completion_entries else unicode_type(x) for x in items]
|
if self.strip_completion_entries:
|
||||||
items = [x for x in items if x]
|
items = (str(x).strip() for x in items if x)
|
||||||
|
else:
|
||||||
|
items = (str(x) for x in items if x)
|
||||||
items = tuple(sorted(items, key=self.sort_func))
|
items = tuple(sorted(items, key=self.sort_func))
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.all_items = self.current_items = items
|
self.all_items = self.current_items = items
|
||||||
|
@ -127,22 +127,21 @@ def create_simple_tab(self, db):
|
|||||||
le.set_separator('&')
|
le.set_separator('&')
|
||||||
le.set_space_before_sep(True)
|
le.set_space_before_sep(True)
|
||||||
le.set_add_separator(tweaks['authors_completer_append_separator'])
|
le.set_add_separator(tweaks['authors_completer_append_separator'])
|
||||||
le.update_items_cache(db.all_author_names())
|
le.update_items_cache(db.new_api.all_field_names('authors'))
|
||||||
l.addRow(_('&Author:'), le)
|
l.addRow(_('&Author:'), le)
|
||||||
|
|
||||||
self.series_box = le = EditWithComplete(self)
|
self.series_box = le = EditWithComplete(self)
|
||||||
le.lineEdit().setPlaceholderText(_('The series to search for'))
|
le.lineEdit().setPlaceholderText(_('The series to search for'))
|
||||||
le.setObjectName('series_box')
|
le.setObjectName('series_box')
|
||||||
all_series = sorted((x[1] for x in db.all_series()), key=sort_key)
|
|
||||||
le.set_separator(None)
|
le.set_separator(None)
|
||||||
le.update_items_cache(all_series)
|
le.update_items_cache(db.new_api.all_field_names('series'))
|
||||||
le.show_initial_value('')
|
le.show_initial_value('')
|
||||||
l.addRow(_('&Series:'), le)
|
l.addRow(_('&Series:'), le)
|
||||||
|
|
||||||
self.tags_box = le = EditWithComplete(self)
|
self.tags_box = le = EditWithComplete(self)
|
||||||
le.setObjectName('tags_box')
|
le.setObjectName('tags_box')
|
||||||
le.lineEdit().setPlaceholderText(_('The tags to search for'))
|
le.lineEdit().setPlaceholderText(_('The tags to search for'))
|
||||||
self.tags_box.update_items_cache(db.all_tags())
|
self.tags_box.update_items_cache(db.new_api.all_field_names('tags'))
|
||||||
l.addRow(_('Ta&gs:'), le)
|
l.addRow(_('Ta&gs:'), le)
|
||||||
|
|
||||||
searchables = sorted(db.field_metadata.searchable_fields(),
|
searchables = sorted(db.field_metadata.searchable_fields(),
|
||||||
@ -490,4 +489,5 @@ if __name__ == '__main__':
|
|||||||
app = Application([])
|
app = Application([])
|
||||||
d = SearchDialog(None, db)
|
d = SearchDialog(None, db)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
print(d.search_string())
|
print(d.search_string())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user