mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a new Quick select action to quickly select a virtual library with a few keystrokes. Activated by Ctrl+t or the Virtual library menu
This commit is contained in:
parent
2ef5d143c5
commit
fb1051476c
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
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
|
from calibre.gui2.actions import InterfaceAction
|
||||||
|
|
||||||
@ -24,6 +24,13 @@ class VirtualLibraryAction(InterfaceAction):
|
|||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.menu = m = self.qaction.menu()
|
self.menu = m = self.qaction.menu()
|
||||||
m.aboutToShow.connect(self.about_to_show_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):
|
def about_to_show_menu(self):
|
||||||
self.gui.build_virtual_library_menu(self.menu, add_tabs_action=False)
|
self.gui.build_virtual_library_menu(self.menu, add_tabs_action=False)
|
||||||
|
@ -380,6 +380,8 @@ class SearchRestrictionMixin(object):
|
|||||||
self.build_virtual_library_list(a, self.remove_vl_triggered)
|
self.build_virtual_library_list(a, self.remove_vl_triggered)
|
||||||
m.addMenu(a)
|
m.addMenu(a)
|
||||||
|
|
||||||
|
m.addAction(_('Quick select Virtual library'), self.choose_vl_triggerred)
|
||||||
|
|
||||||
if add_tabs_action:
|
if add_tabs_action:
|
||||||
if gprefs['show_vl_tabs']:
|
if gprefs['show_vl_tabs']:
|
||||||
m.addAction(_('Hide virtual library tabs'), self.vl_tabs.disable_bar)
|
m.addAction(_('Hide virtual library tabs'), self.vl_tabs.disable_bar)
|
||||||
@ -492,6 +494,29 @@ class SearchRestrictionMixin(object):
|
|||||||
return
|
return
|
||||||
self._remove_vl(name, reapply=True)
|
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 = '<pre>{0}S{1}ome {0}B{1}ook {0}C{1}ollection</pre>'.format(
|
||||||
|
'<span style="%s">' % Results.EMPH, '</span>')
|
||||||
|
chars = '<pre style="%s">sbc</pre>' % Results.EMPH
|
||||||
|
help_text = _('''<p>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):
|
def _remove_vl(self, name, reapply=True):
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.prefs.get('virtual_libraries', {})
|
||||||
|
@ -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.tweak_book import tprefs, current_container
|
||||||
from calibre.gui2.widgets2 import Dialog as BaseDialog, HistoryComboBox, to_plain_text, PARAGRAPH_SEPARATOR
|
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.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 calibre.gui2.complete2 import EditWithComplete
|
||||||
from polyglot.builtins import iteritems, unicode_type, zip, getcwd, filter as ignore_me
|
from polyglot.builtins import iteritems, unicode_type, zip, getcwd, filter as ignore_me
|
||||||
|
|
||||||
@ -408,11 +408,12 @@ class Results(QWidget):
|
|||||||
|
|
||||||
class QuickOpen(Dialog):
|
class QuickOpen(Dialog):
|
||||||
|
|
||||||
def __init__(self, items, parent=None):
|
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)
|
self.matcher = Matcher(items, level1=level1, level2=level2, level3=level3)
|
||||||
self.matches = ()
|
self.matches = ()
|
||||||
self.selected_result = None
|
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):
|
def sizeHint(self):
|
||||||
ans = Dialog.sizeHint(self)
|
ans = Dialog.sizeHint(self)
|
||||||
@ -420,6 +421,18 @@ class QuickOpen(Dialog):
|
|||||||
ans.setHeight(max(600, ans.height()))
|
ans.setHeight(max(600, ans.height()))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def default_help_text(self):
|
||||||
|
example = '<pre>{0}i{1}mages/{0}c{1}hapter1/{0}s{1}cene{0}3{1}.jpg</pre>'.format(
|
||||||
|
'<span style="%s">' % Results.EMPH, '</span>')
|
||||||
|
chars = '<pre style="%s">ics3</pre>' % Results.EMPH
|
||||||
|
|
||||||
|
return _('''<p>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):
|
def setup_ui(self):
|
||||||
self.l = l = QVBoxLayout(self)
|
self.l = l = QVBoxLayout(self)
|
||||||
self.setLayout(l)
|
self.setLayout(l)
|
||||||
@ -428,17 +441,7 @@ class QuickOpen(Dialog):
|
|||||||
t.textEdited.connect(self.update_matches)
|
t.textEdited.connect(self.update_matches)
|
||||||
l.addWidget(t, alignment=Qt.AlignTop)
|
l.addWidget(t, alignment=Qt.AlignTop)
|
||||||
|
|
||||||
example = '<pre>{0}i{1}mages/{0}c{1}hapter1/{0}s{1}cene{0}3{1}.jpg</pre>'.format(
|
self.help_label = hl = QLabel(self.help_text)
|
||||||
'<span style="%s">' % Results.EMPH, '</span>')
|
|
||||||
chars = '<pre style="%s">ics3</pre>' % Results.EMPH
|
|
||||||
|
|
||||||
self.help_label = hl = QLabel(_(
|
|
||||||
'''<p>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))
|
|
||||||
hl.setContentsMargins(50, 50, 50, 50), hl.setAlignment(Qt.AlignTop | Qt.AlignHCenter)
|
hl.setContentsMargins(50, 50, 50, 50), hl.setAlignment(Qt.AlignTop | Qt.AlignHCenter)
|
||||||
l.addWidget(hl)
|
l.addWidget(hl)
|
||||||
self.results = Results(self)
|
self.results = Results(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user