mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Migrate view action
This commit is contained in:
parent
e4b2729e78
commit
d9ac3a0e0a
@ -599,7 +599,11 @@ class ActionDelete(InterfaceActionBase):
|
||||
|
||||
class ActionEditMetadata(InterfaceActionBase):
|
||||
name = 'Edit Metadata'
|
||||
actual_plugin = 'calibre.gui2.actions.delete:EditMetadataAction'
|
||||
actual_plugin = 'calibre.gui2.actions.edit_metadata:EditMetadataAction'
|
||||
|
||||
class ActionView(InterfaceActionBase):
|
||||
name = 'View'
|
||||
actual_plugin = 'calibre.gui2.actions.view:ViewAction'
|
||||
|
||||
plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
|
||||
ActionConvert, ActionDelete, ActionEditMetadata]
|
||||
ActionConvert, ActionDelete, ActionEditMetadata, ActionView]
|
||||
|
@ -6,8 +6,9 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, time
|
||||
from functools import partial
|
||||
|
||||
from PyQt4.Qt import Qt
|
||||
from PyQt4.Qt import Qt, QMenu
|
||||
|
||||
from calibre.constants import isosx
|
||||
from calibre.gui2 import error_dialog, Dispatcher, question_dialog, config, \
|
||||
@ -15,13 +16,24 @@ from calibre.gui2 import error_dialog, Dispatcher, question_dialog, config, \
|
||||
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
|
||||
from calibre.utils.config import prefs
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
|
||||
class ViewAction(object):
|
||||
class ViewAction(InterfaceAction):
|
||||
|
||||
name = 'View'
|
||||
action_spec = (_('View'), 'view.svg', None, _('V'))
|
||||
|
||||
def genesis(self):
|
||||
self.persistent_files = []
|
||||
self.metadata_view_id = None
|
||||
self.qaction.triggered.connect(self.view_book)
|
||||
self.view_menu = QMenu()
|
||||
self.view_menu.addAction(_('View'), partial(self.view_book, False))
|
||||
ac = self.view_menu.addAction(_('View specific format'))
|
||||
ac.setShortcut((Qt.ControlModifier if isosx else Qt.AltModifier)+Qt.Key_V)
|
||||
self.qaction.setMenu(self.view_menu)
|
||||
ac.triggered.connect(self.view_specific_format, type=Qt.QueuedConnection)
|
||||
|
||||
|
||||
def location_selected(self, loc):
|
||||
enabled = loc == 'library'
|
||||
@ -49,12 +61,12 @@ class ViewAction(object):
|
||||
|
||||
def book_downloaded_for_viewing(self, job):
|
||||
if job.failed:
|
||||
self.device_job_exception(job)
|
||||
self.gui.device_job_exception(job)
|
||||
return
|
||||
self._view_file(job.result)
|
||||
|
||||
def _launch_viewer(self, name=None, viewer='ebook-viewer', internal=True):
|
||||
self.setCursor(Qt.BusyCursor)
|
||||
self.gui.setCursor(Qt.BusyCursor)
|
||||
try:
|
||||
if internal:
|
||||
args = [viewer]
|
||||
@ -62,13 +74,13 @@ class ViewAction(object):
|
||||
args.append('--raise-window')
|
||||
if name is not None:
|
||||
args.append(name)
|
||||
self.job_manager.launch_gui_app(viewer,
|
||||
self.gui.job_manager.launch_gui_app(viewer,
|
||||
kwargs=dict(args=args))
|
||||
else:
|
||||
open_local_file(name)
|
||||
time.sleep(2) # User feedback
|
||||
finally:
|
||||
self.unsetCursor()
|
||||
self.gui.unsetCursor()
|
||||
|
||||
def _view_file(self, name):
|
||||
ext = os.path.splitext(name)[1].upper().replace('.', '')
|
||||
@ -85,7 +97,7 @@ class ViewAction(object):
|
||||
|
||||
row = rows[0].row()
|
||||
formats = self.gui.library_view.model().db.formats(row).upper().split(',')
|
||||
d = ChooseFormatDialog(self, _('Choose the format to view'), formats)
|
||||
d = ChooseFormatDialog(self.gui, _('Choose the format to view'), formats)
|
||||
if d.exec_() == d.Accepted:
|
||||
format = d.format()
|
||||
self.view_format(row, format)
|
||||
@ -162,7 +174,7 @@ class ViewAction(object):
|
||||
os.path.splitext(path)[1])
|
||||
self.persistent_files.append(pt)
|
||||
pt.close()
|
||||
self.device_manager.view_book(\
|
||||
self.gui.device_manager.view_book(\
|
||||
Dispatcher(self.book_downloaded_for_viewing),
|
||||
path, pt.name)
|
||||
|
||||
|
@ -122,7 +122,7 @@ class CoverFlowMixin(object):
|
||||
self.sync_cf_to_listview)
|
||||
self.db_images = DatabaseImages(self.library_view.model())
|
||||
self.cover_flow.setImages(self.db_images)
|
||||
self.cover_flow.itemActivated.connect(self.view_specific_book)
|
||||
self.cover_flow.itemActivated.connect(self.iactions['View'].view_specific_book)
|
||||
else:
|
||||
self.cover_flow = QLabel('<p>'+_('Cover browser could not be loaded')
|
||||
+'<br>'+pictureflowerror)
|
||||
|
@ -118,7 +118,7 @@ class LibraryViewMixin(object): # {{{
|
||||
|
||||
for view in ('library', 'memory', 'card_a', 'card_b'):
|
||||
view = getattr(self, view+'_view')
|
||||
view.verticalHeader().sectionDoubleClicked.connect(self.view_specific_book)
|
||||
view.verticalHeader().sectionDoubleClicked.connect(self.iactions['View'].view_specific_book)
|
||||
|
||||
|
||||
|
||||
@ -308,8 +308,8 @@ class LayoutMixin(object): # {{{
|
||||
self.status_bar.initialize(self.system_tray_icon)
|
||||
self.book_details.show_book_info.connect(self.show_book_info)
|
||||
self.book_details.files_dropped.connect(self.iactions['Add Books'].files_dropped_on_book)
|
||||
self.book_details.open_containing_folder.connect(self.view_folder_for_id)
|
||||
self.book_details.view_specific_format.connect(self.view_format_by_id)
|
||||
self.book_details.open_containing_folder.connect(self.iactions['View'].view_folder_for_id)
|
||||
self.book_details.view_specific_format.connect(self.iactions['View'].view_format_by_id)
|
||||
|
||||
m = self.library_view.model()
|
||||
if m.rowCount(None) > 0:
|
||||
|
@ -13,7 +13,7 @@ from PyQt4.Qt import QIcon, Qt, QWidget, QAction, QToolBar, QSize, \
|
||||
QObject, QVBoxLayout, QSizePolicy, QLabel, QHBoxLayout, QActionGroup, \
|
||||
QMenu, QUrl
|
||||
|
||||
from calibre.constants import __appname__, isosx
|
||||
from calibre.constants import __appname__
|
||||
from calibre.gui2.search_box import SearchBox2, SavedSearchBox
|
||||
from calibre.gui2.throbber import ThrobbingButton
|
||||
from calibre.gui2 import config, open_url, gprefs
|
||||
@ -510,18 +510,10 @@ class MainWindowMixin(object):
|
||||
self.save_menu.addMenu(self.save_sub_menu)
|
||||
self.save_sub_menu.save_fmt.connect(self.save_specific_format_disk)
|
||||
|
||||
self.action_view.triggered.connect(self.view_book)
|
||||
self.view_menu = QMenu()
|
||||
self.view_menu.addAction(_('View'), partial(self.view_book, False))
|
||||
ac = self.view_menu.addAction(_('View specific format'))
|
||||
ac.setShortcut((Qt.ControlModifier if isosx else Qt.AltModifier)+Qt.Key_V)
|
||||
self.action_view.setMenu(self.view_menu)
|
||||
ac.triggered.connect(self.view_specific_format, type=Qt.QueuedConnection)
|
||||
|
||||
|
||||
self.action_open_containing_folder.setShortcut(Qt.Key_O)
|
||||
self.addAction(self.action_open_containing_folder)
|
||||
self.action_open_containing_folder.triggered.connect(self.view_folder)
|
||||
self.action_open_containing_folder.triggered.connect(self.iactions['View'].view_folder)
|
||||
self.action_sync.setShortcut(Qt.Key_D)
|
||||
self.action_sync.setEnabled(True)
|
||||
self.create_device_menu()
|
||||
|
@ -149,7 +149,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
|
||||
self.verbose = opts.verbose
|
||||
self.get_metadata = GetMetadata()
|
||||
self.upload_memory = {}
|
||||
self.persistent_files = []
|
||||
self.metadata_dialogs = []
|
||||
self.default_thumbnail = None
|
||||
self.tb_wrapper = textwrap.TextWrapper(width=40)
|
||||
|
Loading…
x
Reference in New Issue
Block a user