mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More changes for #1415714. Make Q toggle quickview. Add Shift+Q to focus to quickview. Add Ctrl+Q to focus to the library without changing the selected cell. Trap tabs in quickview to make navigating with the keyboard possible.
This commit is contained in:
parent
f26495354f
commit
ab166f26c1
@ -834,6 +834,16 @@ class ActionQuickview(InterfaceActionBase):
|
|||||||
actual_plugin = 'calibre.gui2.actions.show_quickview:ShowQuickviewAction'
|
actual_plugin = 'calibre.gui2.actions.show_quickview:ShowQuickviewAction'
|
||||||
description = _('Show a list of related books quickly')
|
description = _('Show a list of related books quickly')
|
||||||
|
|
||||||
|
class ActionQuickviewFocusTo(InterfaceActionBase):
|
||||||
|
name = 'Focus To Quickview'
|
||||||
|
actual_plugin = 'calibre.gui2.actions.show_quickview:FocusToQuickviewAction'
|
||||||
|
description = _('Move the focus to the Quickview pane/window')
|
||||||
|
|
||||||
|
class ActionQuickviewFocusFrom(InterfaceActionBase):
|
||||||
|
name = 'Focus From Quickview'
|
||||||
|
actual_plugin = 'calibre.gui2.actions.show_quickview:FocusFromQuickviewAction'
|
||||||
|
description = _('Move the focus to the library pane')
|
||||||
|
|
||||||
class ActionTemplateTester(InterfaceActionBase):
|
class ActionTemplateTester(InterfaceActionBase):
|
||||||
name = 'Template Tester'
|
name = 'Template Tester'
|
||||||
actual_plugin = 'calibre.gui2.actions.show_template_tester:ShowTemplateTesterAction'
|
actual_plugin = 'calibre.gui2.actions.show_template_tester:ShowTemplateTesterAction'
|
||||||
@ -974,7 +984,8 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
|
|||||||
ActionAddToLibrary, ActionEditCollections, ActionMatchBooks, ActionChooseLibrary,
|
ActionAddToLibrary, ActionEditCollections, ActionMatchBooks, ActionChooseLibrary,
|
||||||
ActionCopyToLibrary, ActionTweakEpub, ActionUnpackBook, ActionNextMatch, ActionStore,
|
ActionCopyToLibrary, ActionTweakEpub, ActionUnpackBook, ActionNextMatch, ActionStore,
|
||||||
ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy,
|
ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy,
|
||||||
ActionMarkBooks, ActionEmbed, ActionTemplateTester]
|
ActionMarkBooks, ActionEmbed, ActionTemplateTester, ActionQuickviewFocusTo,
|
||||||
|
ActionQuickviewFocusFrom]
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
from calibre.utils.fonts.sfnt.glyf import ARGS_ARE_XY_VALUES
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
@ -10,10 +11,40 @@ from calibre.gui2.actions import InterfaceAction
|
|||||||
from calibre.gui2.dialogs.quickview import Quickview
|
from calibre.gui2.dialogs.quickview import Quickview
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
|
|
||||||
|
class FocusToQuickviewAction(InterfaceAction):
|
||||||
|
|
||||||
|
name = 'Focus To Quickview'
|
||||||
|
action_spec = (_('Focus To Quickview'), 'search.png', None, ('Shift+Q'))
|
||||||
|
dont_add_to = frozenset(['context-menu-device'])
|
||||||
|
action_type = 'current'
|
||||||
|
|
||||||
|
def genesis(self):
|
||||||
|
self.qaction.triggered.connect(self.focus_quickview)
|
||||||
|
|
||||||
|
def focus_quickview(self, *args):
|
||||||
|
from calibre.customize.ui import find_plugin
|
||||||
|
qv = find_plugin('Show Quickview')
|
||||||
|
if qv:
|
||||||
|
qv.actual_plugin_.focus_quickview()
|
||||||
|
|
||||||
|
|
||||||
|
class FocusFromQuickviewAction(InterfaceAction):
|
||||||
|
|
||||||
|
name = 'Focus From Quickview'
|
||||||
|
action_spec = (_('Focus From Quickview'), 'search.png', None, ('Ctrl+Q'))
|
||||||
|
dont_add_to = frozenset(['context-menu-device'])
|
||||||
|
action_type = 'current'
|
||||||
|
|
||||||
|
def genesis(self):
|
||||||
|
self.qaction.triggered.connect(self.focus_quickview)
|
||||||
|
|
||||||
|
def focus_quickview(self, *args):
|
||||||
|
self.gui.library_view.setFocus()
|
||||||
|
|
||||||
class ShowQuickviewAction(InterfaceAction):
|
class ShowQuickviewAction(InterfaceAction):
|
||||||
|
|
||||||
name = 'Show quickview'
|
name = 'Show Quickview'
|
||||||
action_spec = (_('Show quickview'), 'search.png', None, _('Q'))
|
action_spec = (_('Show Quickview'), 'search.png', None, (_('Q')))
|
||||||
dont_add_to = frozenset(['context-menu-device'])
|
dont_add_to = frozenset(['context-menu-device'])
|
||||||
action_type = 'current'
|
action_type = 'current'
|
||||||
|
|
||||||
@ -25,9 +56,9 @@ class ShowQuickviewAction(InterfaceAction):
|
|||||||
def show_quickview(self, *args):
|
def show_quickview(self, *args):
|
||||||
if self.current_instance:
|
if self.current_instance:
|
||||||
if not self.current_instance.is_closed:
|
if not self.current_instance.is_closed:
|
||||||
self.current_instance.set_focus()
|
self.current_instance.reject()
|
||||||
return
|
|
||||||
self.current_instance = None
|
self.current_instance = None
|
||||||
|
return
|
||||||
if self.gui.current_view() is not self.gui.library_view:
|
if self.gui.current_view() is not self.gui.library_view:
|
||||||
error_dialog(self.gui, _('No quickview available'),
|
error_dialog(self.gui, _('No quickview available'),
|
||||||
_('Quickview is not available for books '
|
_('Quickview is not available for books '
|
||||||
@ -36,8 +67,15 @@ class ShowQuickviewAction(InterfaceAction):
|
|||||||
index = self.gui.library_view.currentIndex()
|
index = self.gui.library_view.currentIndex()
|
||||||
if index.isValid():
|
if index.isValid():
|
||||||
self.current_instance = Quickview(self.gui, index)
|
self.current_instance = Quickview(self.gui, index)
|
||||||
|
self.current_instance.reopen_quickview.connect(self.reopen_quickview)
|
||||||
self.current_instance.show()
|
self.current_instance.show()
|
||||||
|
|
||||||
|
def reopen_quickview(self):
|
||||||
|
if self.current_instance and not self.current_instance.is_closed:
|
||||||
|
self.current_instance.reject()
|
||||||
|
self.current_instance = None
|
||||||
|
self.show_quickview()
|
||||||
|
|
||||||
def change_quickview_column(self, idx):
|
def change_quickview_column(self, idx):
|
||||||
self.show_quickview()
|
self.show_quickview()
|
||||||
if self.current_instance:
|
if self.current_instance:
|
||||||
@ -48,3 +86,8 @@ class ShowQuickviewAction(InterfaceAction):
|
|||||||
def library_changed(self, db):
|
def library_changed(self, db):
|
||||||
if self.current_instance and not self.current_instance.is_closed:
|
if self.current_instance and not self.current_instance.is_closed:
|
||||||
self.current_instance.reject()
|
self.current_instance.reject()
|
||||||
|
|
||||||
|
def focus_quickview(self):
|
||||||
|
if not (self.current_instance and not self.current_instance.is_closed):
|
||||||
|
self.show_quickview()
|
||||||
|
self.current_instance.set_focus()
|
@ -42,7 +42,15 @@ class TableItem(QTableWidgetItem):
|
|||||||
return self.sort_idx < other.sort_idx
|
return self.sort_idx < other.sort_idx
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
class KeyPressFilter(QObject):
|
IN_WIDGET_ITEMS = 0
|
||||||
|
IN_WIDGET_BOOKS = 1
|
||||||
|
IN_WIDGET_LOCK = 2
|
||||||
|
IN_WIDGET_DOCK = 3
|
||||||
|
IN_WIDGET_SEARCH = 4
|
||||||
|
IN_WIDGET_CLOSE = 5
|
||||||
|
IN_WIDGET_LAST = 5
|
||||||
|
|
||||||
|
class BooksKeyPressFilter(QObject):
|
||||||
|
|
||||||
return_pressed_signal = pyqtSignal()
|
return_pressed_signal = pyqtSignal()
|
||||||
|
|
||||||
@ -50,12 +58,30 @@ class KeyPressFilter(QObject):
|
|||||||
if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Return:
|
if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Return:
|
||||||
self.return_pressed_signal.emit()
|
self.return_pressed_signal.emit()
|
||||||
return True;
|
return True;
|
||||||
else:
|
return False
|
||||||
return QObject.eventFilter(self, obj, event);
|
|
||||||
|
class WidgetTabFilter(QObject):
|
||||||
|
|
||||||
|
def __init__(self, attachToClass, which_widget, tab_signal):
|
||||||
|
QObject.__init__(self, attachToClass)
|
||||||
|
self.tab_signal = tab_signal
|
||||||
|
self.which_widget = which_widget
|
||||||
|
|
||||||
|
def eventFilter(self, obj, event):
|
||||||
|
if event.type() == QEvent.KeyPress:
|
||||||
|
if event.key() == Qt.Key_Tab:
|
||||||
|
self.tab_signal.emit(self.which_widget, True)
|
||||||
|
return True
|
||||||
|
if event.key() == Qt.Key_Backtab:
|
||||||
|
self.tab_signal.emit(self.which_widget, False)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class Quickview(QDialog, Ui_Quickview):
|
class Quickview(QDialog, Ui_Quickview):
|
||||||
|
|
||||||
change_quickview_column = pyqtSignal(object)
|
change_quickview_column = pyqtSignal(object)
|
||||||
|
reopen_quickview = pyqtSignal()
|
||||||
|
tab_pressed_signal = pyqtSignal(object, object)
|
||||||
|
|
||||||
def __init__(self, gui, row):
|
def __init__(self, gui, row):
|
||||||
self.is_pane = gprefs.get('quickview_is_pane', False)
|
self.is_pane = gprefs.get('quickview_is_pane', False)
|
||||||
@ -107,10 +133,18 @@ class Quickview(QDialog, Ui_Quickview):
|
|||||||
self.items.setSelectionMode(QAbstractItemView.SingleSelection)
|
self.items.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||||
self.items.currentTextChanged.connect(self.item_selected)
|
self.items.currentTextChanged.connect(self.item_selected)
|
||||||
|
|
||||||
|
self.tab_pressed_signal.connect(self.tab_pressed)
|
||||||
# Set up the books table columns
|
# Set up the books table columns
|
||||||
return_filter = KeyPressFilter(self.books_table)
|
return_filter = BooksKeyPressFilter(self.books_table)
|
||||||
return_filter.return_pressed_signal.connect(self.return_pressed)
|
return_filter.return_pressed_signal.connect(self.return_pressed)
|
||||||
self.books_table.installEventFilter(return_filter)
|
self.books_table.installEventFilter(return_filter)
|
||||||
|
|
||||||
|
self.close_button = self.buttonBox.button(QDialogButtonBox.Close)
|
||||||
|
self.tab_order_widgets = [self.items, self.books_table, self.lock_qv,
|
||||||
|
self.dock_button, self.search_button, self.close_button]
|
||||||
|
for idx,widget in enumerate(self.tab_order_widgets):
|
||||||
|
widget.installEventFilter(WidgetTabFilter(widget, idx, self.tab_pressed_signal))
|
||||||
|
|
||||||
self.books_table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
self.books_table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
self.books_table.setSelectionMode(QAbstractItemView.SingleSelection)
|
self.books_table.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||||
self.books_table.setColumnCount(3)
|
self.books_table.setColumnCount(3)
|
||||||
@ -142,26 +176,39 @@ class Quickview(QDialog, Ui_Quickview):
|
|||||||
self.search_button.clicked.connect(self.do_search)
|
self.search_button.clicked.connect(self.do_search)
|
||||||
self.view.model().new_bookdisplay_data.connect(self.book_was_changed)
|
self.view.model().new_bookdisplay_data.connect(self.book_was_changed)
|
||||||
|
|
||||||
close_button = self.buttonBox.button(QDialogButtonBox.Close)
|
self.close_button.setDefault(False)
|
||||||
close_button.setDefault(False)
|
|
||||||
if self.is_pane:
|
|
||||||
close_button.setText(_('&Close'))
|
|
||||||
|
|
||||||
self.books_table.horizontalHeader().sectionResized.connect(self.section_resized)
|
|
||||||
if self.is_pane:
|
if self.is_pane:
|
||||||
|
self.dock_button.setText(_('Undock'))
|
||||||
|
self.lock_qv.setText(_('Lock Quickview contents'))
|
||||||
|
self.search_button.setText(_('Search'))
|
||||||
self.gui.quickview_splitter.add_quickview_dialog(self)
|
self.gui.quickview_splitter.add_quickview_dialog(self)
|
||||||
self.set_focus()
|
self.set_focus()
|
||||||
|
else:
|
||||||
|
self.lock_qv.setText(_('&Dock'))
|
||||||
|
self.close_button.setText(_('&Close'))
|
||||||
|
|
||||||
self.show_as_pane.setChecked(self.is_pane)
|
self.books_table.horizontalHeader().sectionResized.connect(self.section_resized)
|
||||||
self.show_as_pane.stateChanged.connect(self.show_as_pane_changed)
|
self.dock_button.clicked.connect(self.show_as_pane_changed)
|
||||||
|
|
||||||
|
def tab_pressed(self, inWidget, isForward):
|
||||||
|
if isForward:
|
||||||
|
inWidget += 1
|
||||||
|
if inWidget > IN_WIDGET_LAST:
|
||||||
|
inWidget = 0
|
||||||
|
else:
|
||||||
|
inWidget -= 1
|
||||||
|
if inWidget < 0:
|
||||||
|
inWidget = IN_WIDGET_LAST
|
||||||
|
self.tab_order_widgets[inWidget].setFocus(Qt.TabFocusReason)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
QDialog.show(self)
|
QDialog.show(self)
|
||||||
if self.is_pane:
|
if self.is_pane:
|
||||||
self.gui.quickview_splitter.show_quickview_widget()
|
self.gui.quickview_splitter.show_quickview_widget()
|
||||||
|
|
||||||
def show_as_pane_changed(self, new_state):
|
def show_as_pane_changed(self):
|
||||||
gprefs['quickview_is_pane'] = self.show_as_pane.isChecked()
|
gprefs['quickview_is_pane'] = not gprefs.get('quickview_is_pane', False)
|
||||||
|
self.reopen_quickview.emit()
|
||||||
|
|
||||||
# search button
|
# search button
|
||||||
def do_search(self):
|
def do_search(self):
|
||||||
|
@ -87,15 +87,18 @@
|
|||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="show_as_pane">
|
<widget class="QPushButton" name="dock_button">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Sho&w as pane</string>
|
<string>&Dock</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><p>If checked, the next time Quickview is opened it will be shown
|
<string><p>If checked, the next time Quickview is opened it will be shown
|
||||||
as a pane under the library view. If unchecked it will be shown as a
|
as a pane under the library view. If unchecked it will be shown as a
|
||||||
separate window.</p></string>
|
separate window.</p></string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="autoDefault">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user