From a19bc736e99a771cd1c681bc5c0dd9a67eae1bd6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 Nov 2017 20:20:20 +0530 Subject: [PATCH] Book list: Pressing Enter now views the book Note that this is not a normal shortcut and cannot be configured via Preferences->Shortcuts. I could find no good way of having Enter be a global shortcut. --- src/calibre/gui2/library/alternate_views.py | 18 +++++++++++++++++- src/calibre/gui2/library/views.py | 7 ++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 98ab7bf952..bea953f8fc 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -42,6 +42,17 @@ class EncodeError(ValueError): pass +def handle_enter_press(self, ev, special_action=None): + if ev.key() in (Qt.Key_Enter, Qt.Key_Return): + 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: + special_action(self.currentIndex()) + get_gui().iactions['View'].view_triggered(self.currentIndex()) + return True + + def image_to_data(image): # {{{ ba = QByteArray() buf = QBuffer(ba) @@ -714,11 +725,14 @@ class GridView(QListView): for r in xrange(self.first_visible_row or 0, self.last_visible_row or (m.count() - 1)): self.update(m.index(r, 0)) - def double_clicked(self, index): + def start_view_animation(self, index): d = self.delegate if d.animating is None and not config['disable_animations']: d.animating = index d.animation.start() + + def double_clicked(self, index): + self.start_view_animation(index) if tweaks['doubleclick_on_library_view'] == 'open_viewer': self.gui.iactions['View'].view_triggered(index) elif tweaks['doubleclick_on_library_view'] in {'edit_metadata', 'edit_cell'}: @@ -1000,6 +1014,8 @@ class GridView(QListView): return self._ncols def keyPressEvent(self, ev): + if handle_enter_press(self, ev, self.start_view_animation): + return k = ev.key() if ev.modifiers() & Qt.ShiftModifier and k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down): ci = self.currentIndex() diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 30ea53c9c0..bb635a5bdc 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -21,7 +21,7 @@ from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate, CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate, CcEnumDelegate, CcNumberDelegate, LanguagesDelegate) from calibre.gui2.library.models import BooksModel, DeviceBooksModel -from calibre.gui2.library.alternate_views import AlternateViews, setup_dnd_interface +from calibre.gui2.library.alternate_views import AlternateViews, setup_dnd_interface, handle_enter_press from calibre.gui2.gestures import GestureManager from calibre.utils.config import tweaks, prefs from calibre.gui2 import error_dialog, gprefs, FunctionDispatcher @@ -985,6 +985,11 @@ class BooksView(QTableView): # {{{ return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows return super(BooksView, self).selectionCommand(index, event) + def keyPressEvent(self, ev): + if handle_enter_press(self, ev): + return + return QTableView.keyPressEvent(self, ev) + def ids_to_rows(self, ids): row_map = OrderedDict() ids = frozenset(ids)