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.
This commit is contained in:
Kovid Goyal 2017-11-17 20:20:20 +05:30
parent 7d42447b33
commit a19bc736e9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 23 additions and 2 deletions

View File

@ -42,6 +42,17 @@ class EncodeError(ValueError):
pass 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): # {{{ def image_to_data(image): # {{{
ba = QByteArray() ba = QByteArray()
buf = QBuffer(ba) 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)): for r in xrange(self.first_visible_row or 0, self.last_visible_row or (m.count() - 1)):
self.update(m.index(r, 0)) self.update(m.index(r, 0))
def double_clicked(self, index): def start_view_animation(self, index):
d = self.delegate d = self.delegate
if d.animating is None and not config['disable_animations']: if d.animating is None and not config['disable_animations']:
d.animating = index d.animating = index
d.animation.start() d.animation.start()
def double_clicked(self, index):
self.start_view_animation(index)
if tweaks['doubleclick_on_library_view'] == 'open_viewer': if tweaks['doubleclick_on_library_view'] == 'open_viewer':
self.gui.iactions['View'].view_triggered(index) self.gui.iactions['View'].view_triggered(index)
elif tweaks['doubleclick_on_library_view'] in {'edit_metadata', 'edit_cell'}: elif tweaks['doubleclick_on_library_view'] in {'edit_metadata', 'edit_cell'}:
@ -1000,6 +1014,8 @@ class GridView(QListView):
return self._ncols return self._ncols
def keyPressEvent(self, ev): def keyPressEvent(self, ev):
if handle_enter_press(self, ev, self.start_view_animation):
return
k = ev.key() k = ev.key()
if ev.modifiers() & Qt.ShiftModifier and k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down): if ev.modifiers() & Qt.ShiftModifier and k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down):
ci = self.currentIndex() ci = self.currentIndex()

View File

@ -21,7 +21,7 @@ from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate,
CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate, CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate,
CcEnumDelegate, CcNumberDelegate, LanguagesDelegate) CcEnumDelegate, CcNumberDelegate, LanguagesDelegate)
from calibre.gui2.library.models import BooksModel, DeviceBooksModel 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.gui2.gestures import GestureManager
from calibre.utils.config import tweaks, prefs from calibre.utils.config import tweaks, prefs
from calibre.gui2 import error_dialog, gprefs, FunctionDispatcher from calibre.gui2 import error_dialog, gprefs, FunctionDispatcher
@ -985,6 +985,11 @@ class BooksView(QTableView): # {{{
return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows
return super(BooksView, self).selectionCommand(index, event) 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): def ids_to_rows(self, ids):
row_map = OrderedDict() row_map = OrderedDict()
ids = frozenset(ids) ids = frozenset(ids)