From 1ecaf1c5ff0441b47aa59dd42d59897ee0fe9be9 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Fri, 17 Nov 2017 18:15:15 +0100 Subject: [PATCH] Add tweak to change the (new) behavior of the enter key --- resources/default_tweaks.py | 8 ++++++++ src/calibre/gui2/library/alternate_views.py | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 18274e8d65..a6d022c653 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -559,3 +559,11 @@ cover_drop_exclude = () # new Saved search is shown in the Search bar. If you would like to have the # old Saved searches box with its two buttons back, set this tweak to True. show_saved_search_box = False + +#: Control behavior of Enter key on the books view +# The behaviors: +# 'viewer': open the book in the viewer, +# 'down_arrow': perform a down arrow, +# 'edit_metadata': open the edit metadata (single) dialog, +# 'do_nothing': makes the key do nothing. +enter_key_behavior = 'viewer' diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index bea953f8fc..f21f909bc8 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -19,7 +19,7 @@ from PyQt5.Qt import ( QMimeData, QUrl, QDrag, QPoint, QPainter, QRect, pyqtProperty, QEvent, QPropertyAnimation, QEasingCurve, pyqtSlot, QHelpEvent, QAbstractItemView, QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush, qRed, qGreen, - qBlue, QItemSelectionModel, QIcon, QFont) + qBlue, QItemSelectionModel, QIcon, QFont, QKeyEvent) from calibre import fit_image, prints, prepare_string_for_xml, human_readable from calibre.constants import DEBUG, config_dir, islinux @@ -47,9 +47,22 @@ def handle_enter_press(self, ev, special_action=None): if self.state() != self.EditingState and self.hasFocus() and self.currentIndex().isValid(): from calibre.gui2.ui import get_gui ev.ignore() - if special_action is not None: + tweak = tweaks['enter_key_behavior'] + if tweak != 'down_arrow' and special_action is not None: + # Don't animate (or whatever) if emulating the down arrow + # Could be that this should check == 'do nothing', but the + # animation is nice when opening the viewer. special_action(self.currentIndex()) - get_gui().iactions['View'].view_triggered(self.currentIndex()) + gui = get_gui() + if tweak == 'viewer': + gui.iactions['View'].view_triggered(self.currentIndex()) + elif tweak == 'down_arrow': + nev = QKeyEvent(QEvent.KeyPress, Qt.Key_Down, ev.modifiers(), ev.text()) + self.keyPressEvent(nev) + elif tweak == 'edit_metadata': + gui.iactions['Edit Metadata'].edit_metadata(False) + elif tweak == 'do_nothing': # for completeness + pass return True