diff --git a/src/calibre/gui2/actions/virtual_library.py b/src/calibre/gui2/actions/virtual_library.py index 596b697528..496836257f 100644 --- a/src/calibre/gui2/actions/virtual_library.py +++ b/src/calibre/gui2/actions/virtual_library.py @@ -4,7 +4,7 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from PyQt5.Qt import QToolButton +from PyQt5.Qt import QToolButton, QAction from calibre.gui2.actions import InterfaceAction @@ -24,6 +24,13 @@ class VirtualLibraryAction(InterfaceAction): def genesis(self): self.menu = m = self.qaction.menu() m.aboutToShow.connect(self.about_to_show_menu) + self.qs_action = QAction(self.gui) + self.gui.addAction(self.qs_action) + self.qs_action.triggered.connect(self.gui.choose_vl_triggerred) + self.gui.keyboard.register_shortcut(self.unique_name + ' - ' + 'quick-select-vl', + _('Quick select Virtual library'), default_keys=('Ctrl+T',), + action=self.qs_action, description=_('Quick select a Virtual library'), + group=self.action_spec[0]) def about_to_show_menu(self): self.gui.build_virtual_library_menu(self.menu, add_tabs_action=False) diff --git a/src/calibre/gui2/search_restriction_mixin.py b/src/calibre/gui2/search_restriction_mixin.py index 23847ded5e..83aa172b90 100644 --- a/src/calibre/gui2/search_restriction_mixin.py +++ b/src/calibre/gui2/search_restriction_mixin.py @@ -380,6 +380,8 @@ class SearchRestrictionMixin(object): self.build_virtual_library_list(a, self.remove_vl_triggered) m.addMenu(a) + m.addAction(_('Quick select Virtual library'), self.choose_vl_triggerred) + if add_tabs_action: if gprefs['show_vl_tabs']: m.addAction(_('Hide virtual library tabs'), self.vl_tabs.disable_bar) @@ -492,6 +494,29 @@ class SearchRestrictionMixin(object): return self._remove_vl(name, reapply=True) + def choose_vl_triggerred(self): + from calibre.gui2.tweak_book.widgets import QuickOpen, Results + db = self.library_view.model().db + virt_libs = db.prefs.get('virtual_libraries', {}) + if not virt_libs: + return error_dialog(self, _('No virtual libraries'), _( + 'No Virtual libraries present, create some first'), show=True) + example = '
{0}S{1}ome {0}B{1}ook {0}C{1}ollection'.format( + '' % Results.EMPH, '') + chars = '
sbc' % Results.EMPH + help_text = _('''
Quickly choose a Virtual library by typing in just a few characters from the file name into the field above. + For example, if want to choose the VL: + {example} + Simply type in the characters: + {chars} + and press Enter.''').format(example=example, chars=chars) + + d = QuickOpen( + sorted(virt_libs.keys(), key=sort_key), parent=self, title=_('Choose Virtual library'), + name='vl-open', level1=' ', help_text=help_text) + if d.exec_() == d.Accepted and d.selected_result: + self.apply_virtual_library(library=d.selected_result) + def _remove_vl(self, name, reapply=True): db = self.library_view.model().db virt_libs = db.prefs.get('virtual_libraries', {}) diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index 1135135fff..ad0bcb2b5f 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -24,7 +24,7 @@ from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dial from calibre.gui2.tweak_book import tprefs, current_container from calibre.gui2.widgets2 import Dialog as BaseDialog, HistoryComboBox, to_plain_text, PARAGRAPH_SEPARATOR from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key -from calibre.utils.matcher import get_char, Matcher +from calibre.utils.matcher import get_char, Matcher, DEFAULT_LEVEL1, DEFAULT_LEVEL2, DEFAULT_LEVEL3 from calibre.gui2.complete2 import EditWithComplete from polyglot.builtins import iteritems, unicode_type, zip, getcwd, filter as ignore_me @@ -408,11 +408,12 @@ class Results(QWidget): class QuickOpen(Dialog): - def __init__(self, items, parent=None): - self.matcher = Matcher(items) + def __init__(self, items, parent=None, title=None, name='quick-open', level1=DEFAULT_LEVEL1, level2=DEFAULT_LEVEL2, level3=DEFAULT_LEVEL3, help_text=None): + self.matcher = Matcher(items, level1=level1, level2=level2, level3=level3) self.matches = () self.selected_result = None - Dialog.__init__(self, _('Choose file to edit'), 'quick-open', parent=parent) + self.help_text = help_text or self.default_help_text() + Dialog.__init__(self, title or _('Choose file to edit'), name, parent=parent) def sizeHint(self): ans = Dialog.sizeHint(self) @@ -420,6 +421,18 @@ class QuickOpen(Dialog): ans.setHeight(max(600, ans.height())) return ans + def default_help_text(self): + example = '
{0}i{1}mages/{0}c{1}hapter1/{0}s{1}cene{0}3{1}.jpg'.format( + '' % Results.EMPH, '') + chars = '
ics3' % Results.EMPH + + return _('''
Quickly choose a file by typing in just a few characters from the file name into the field above. + For example, if want to choose the file: + {example} + Simply type in the characters: + {chars} + and press Enter.''').format(example=example, chars=chars) + def setup_ui(self): self.l = l = QVBoxLayout(self) self.setLayout(l) @@ -428,17 +441,7 @@ class QuickOpen(Dialog): t.textEdited.connect(self.update_matches) l.addWidget(t, alignment=Qt.AlignTop) - example = '
{0}i{1}mages/{0}c{1}hapter1/{0}s{1}cene{0}3{1}.jpg'.format( - '' % Results.EMPH, '') - chars = '
ics3' % Results.EMPH - - self.help_label = hl = QLabel(_( - '''
Quickly choose a file by typing in just a few characters from the file name into the field above. - For example, if want to choose the file: - {example} - Simply type in the characters: - {chars} - and press Enter.''').format(example=example, chars=chars)) + self.help_label = hl = QLabel(self.help_text) hl.setContentsMargins(50, 50, 50, 50), hl.setAlignment(Qt.AlignTop | Qt.AlignHCenter) l.addWidget(hl) self.results = Results(self)