mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add A go to context menu to the ebook viewer. Fixes #1230 (Feature Suggestions:)
This commit is contained in:
parent
cb3609645e
commit
abb608a226
@ -127,6 +127,8 @@ class BookInfoDisplay(QWidget):
|
|||||||
keys.sort(cmp=lambda x, y: cmp(self.WEIGHTS[x], self.WEIGHTS[y]))
|
keys.sort(cmp=lambda x, y: cmp(self.WEIGHTS[x], self.WEIGHTS[y]))
|
||||||
for key in keys:
|
for key in keys:
|
||||||
txt = data[key]
|
txt = data[key]
|
||||||
|
if not txt or not txt.strip() or txt == 'None':
|
||||||
|
continue
|
||||||
if isinstance(key, str):
|
if isinstance(key, str):
|
||||||
key = key.decode(preferred_encoding, 'replace')
|
key = key.decode(preferred_encoding, 'replace')
|
||||||
if isinstance(txt, str):
|
if isinstance(txt, str):
|
||||||
|
@ -7,10 +7,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''
|
'''
|
||||||
import os, math, re, glob, sys
|
import os, math, re, glob, sys
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
from PyQt4.Qt import QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
||||||
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
||||||
QColor, QPoint, QImage, QRegion, QVariant, QIcon, \
|
QColor, QPoint, QImage, QRegion, QVariant, QIcon, \
|
||||||
QFont, pyqtSignature, QAction, QByteArray
|
QFont, pyqtSignature, QAction, QByteArray, QMenu
|
||||||
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||||
|
|
||||||
from calibre.utils.config import Config, StringConfig
|
from calibre.utils.config import Config, StringConfig
|
||||||
@ -449,6 +451,50 @@ class DocumentView(QWebView):
|
|||||||
_('&Lookup in dictionary'), self)
|
_('&Lookup in dictionary'), self)
|
||||||
self.dictionary_action.setShortcut(Qt.CTRL+Qt.Key_L)
|
self.dictionary_action.setShortcut(Qt.CTRL+Qt.Key_L)
|
||||||
self.dictionary_action.triggered.connect(self.lookup)
|
self.dictionary_action.triggered.connect(self.lookup)
|
||||||
|
self.goto_location_action = QAction(_('Go to...'), self)
|
||||||
|
self.goto_location_menu = m = QMenu(self)
|
||||||
|
self.goto_location_actions = a = {
|
||||||
|
'Next Page': self.next_page,
|
||||||
|
'Previous Page': self.previous_page,
|
||||||
|
'Section Top' : partial(self.scroll_to, 0),
|
||||||
|
'Document Top': self.goto_document_start,
|
||||||
|
'Section Bottom':partial(self.scroll_to, 1),
|
||||||
|
'Document Bottom': self.goto_document_end,
|
||||||
|
'Next Section': self.goto_next_section,
|
||||||
|
'Previous Section': self.goto_previous_section,
|
||||||
|
}
|
||||||
|
for name, key in [(_('Next Section'), 'Next Section'),
|
||||||
|
(_('Previous Section'), 'Previous Section'),
|
||||||
|
(None, None),
|
||||||
|
(_('Document Start'), 'Document Top'),
|
||||||
|
(_('Document End'), 'Document Bottom'),
|
||||||
|
(None, None),
|
||||||
|
(_('Section Start'), 'Section Top'),
|
||||||
|
(_('Section End'), 'Section Bottom'),
|
||||||
|
(None, None),
|
||||||
|
(_('Next Page'), 'Next Page'),
|
||||||
|
(_('Previous Page'), 'Previous Page')]:
|
||||||
|
if key is None:
|
||||||
|
m.addSeparator()
|
||||||
|
else:
|
||||||
|
m.addAction(name, a[key], self.shortcuts.get_sequences(key)[0])
|
||||||
|
self.goto_location_action.setMenu(self.goto_location_menu)
|
||||||
|
|
||||||
|
def goto_next_section(self, *args):
|
||||||
|
if self.manager is not None:
|
||||||
|
self.manager.goto_next_section()
|
||||||
|
|
||||||
|
def goto_previous_section(self, *args):
|
||||||
|
if self.manager is not None:
|
||||||
|
self.manager.goto_previous_section()
|
||||||
|
|
||||||
|
def goto_document_start(self, *args):
|
||||||
|
if self.manager is not None:
|
||||||
|
self.manager.goto_start()
|
||||||
|
|
||||||
|
def goto_document_end(self, *args):
|
||||||
|
if self.manager is not None:
|
||||||
|
self.manager.goto_end()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def copy_action(self):
|
def copy_action(self):
|
||||||
@ -488,6 +534,8 @@ class DocumentView(QWebView):
|
|||||||
text = unicode(self.selectedText())
|
text = unicode(self.selectedText())
|
||||||
if text:
|
if text:
|
||||||
menu.insertAction(list(menu.actions())[0], self.dictionary_action)
|
menu.insertAction(list(menu.actions())[0], self.dictionary_action)
|
||||||
|
menu.addSeparator()
|
||||||
|
menu.addAction(self.goto_location_action)
|
||||||
menu.exec_(ev.globalPos())
|
menu.exec_(ev.globalPos())
|
||||||
|
|
||||||
def lookup(self, *args):
|
def lookup(self, *args):
|
||||||
@ -763,20 +811,9 @@ class DocumentView(QWebView):
|
|||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
key = self.shortcuts.get_match(event)
|
key = self.shortcuts.get_match(event)
|
||||||
if key == 'Next Page':
|
func = self.goto_location_actions.get(key, None)
|
||||||
self.next_page()
|
if func is not None:
|
||||||
elif key == 'Previous Page':
|
func()
|
||||||
self.previous_page()
|
|
||||||
elif key == 'Section Top':
|
|
||||||
self.scroll_to(0)
|
|
||||||
elif key == 'Document Top':
|
|
||||||
if self.manager is not None:
|
|
||||||
self.manager.goto_start()
|
|
||||||
elif key == 'Section Bottom':
|
|
||||||
self.scroll_to(1)
|
|
||||||
elif key == 'Document Bottom':
|
|
||||||
if self.manager is not None:
|
|
||||||
self.manager.goto_end()
|
|
||||||
elif key == 'Down':
|
elif key == 'Down':
|
||||||
self.scroll_by(y=15)
|
self.scroll_by(y=15)
|
||||||
elif key == 'Up':
|
elif key == 'Up':
|
||||||
@ -785,12 +822,6 @@ class DocumentView(QWebView):
|
|||||||
self.scroll_by(x=-15)
|
self.scroll_by(x=-15)
|
||||||
elif key == 'Right':
|
elif key == 'Right':
|
||||||
self.scroll_by(x=15)
|
self.scroll_by(x=15)
|
||||||
elif key == 'Next Section':
|
|
||||||
if self.manager is not None:
|
|
||||||
self.manager.goto_next_section()
|
|
||||||
elif key == 'Previous Section':
|
|
||||||
if self.manager is not None:
|
|
||||||
self.manager.goto_previous_section()
|
|
||||||
else:
|
else:
|
||||||
return QWebView.keyPressEvent(self, event)
|
return QWebView.keyPressEvent(self, event)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user