mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add fromaework for viewer plugins
This commit is contained in:
parent
b880992393
commit
8a5a7a5975
@ -654,3 +654,36 @@ class StoreBase(Plugin): # {{{
|
||||
raise NotImplementedError()
|
||||
|
||||
# }}}
|
||||
|
||||
class ViewerPlugin(Plugin): # {{{
|
||||
|
||||
'''
|
||||
These plugins are used to add functionality to the calibre viewer.
|
||||
'''
|
||||
|
||||
def load_fonts(self):
|
||||
'''
|
||||
This method is called once at viewer starup. It should load any fonts
|
||||
it wants to make available. For example::
|
||||
|
||||
def load_fonts():
|
||||
from PyQt4.Qt import QFontDatabase
|
||||
font_data = get_resources(['myfont1.ttf', 'myfont2.ttf'])
|
||||
for raw in font_data.itervalues():
|
||||
QFontDatabase.addApplicationFontFromData(raw)
|
||||
'''
|
||||
pass
|
||||
|
||||
def load_javascript(self, evaljs):
|
||||
'''
|
||||
This method is called every time a new HTML document is loaded in the
|
||||
viewer. Use it to load javascript libraries into the viewer. For
|
||||
example::
|
||||
|
||||
def load_javascript(self, evaljs):
|
||||
js = get_resources('myjavascript.js')
|
||||
evaljs(js)
|
||||
'''
|
||||
pass
|
||||
# }}}
|
||||
|
||||
|
@ -8,7 +8,7 @@ from calibre.customize import (CatalogPlugin, FileTypePlugin, PluginNotFound,
|
||||
MetadataReaderPlugin, MetadataWriterPlugin,
|
||||
InterfaceActionBase as InterfaceAction,
|
||||
PreferencesPlugin, platform, InvalidPlugin,
|
||||
StoreBase as Store)
|
||||
StoreBase as Store, ViewerPlugin)
|
||||
from calibre.customize.conversion import InputFormatPlugin, OutputFormatPlugin
|
||||
from calibre.customize.zipplugin import loader
|
||||
from calibre.customize.profiles import InputProfile, OutputProfile
|
||||
@ -481,6 +481,13 @@ def all_metadata_plugins():
|
||||
yield plugin
|
||||
# }}}
|
||||
|
||||
# Viewer plugins {{{
|
||||
def all_viewer_plugins():
|
||||
for plugin in _initialized_plugins:
|
||||
if isinstance(plugin, ViewerPlugin):
|
||||
yield plugin
|
||||
# }}}
|
||||
|
||||
# Initialize plugins {{{
|
||||
|
||||
_initialized_plugins = []
|
||||
|
@ -17,6 +17,7 @@ from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||
from calibre.gui2.viewer.flip import SlideFlip
|
||||
from calibre.gui2.shortcuts import Shortcuts
|
||||
from calibre import prints
|
||||
from calibre.customize.ui import all_viewer_plugins
|
||||
from calibre.gui2.viewer.keys import SHORTCUTS
|
||||
from calibre.gui2.viewer.javascript import JavaScriptLoader
|
||||
from calibre.gui2.viewer.position import PagePosition
|
||||
@ -90,6 +91,8 @@ class Document(QWebPage): # {{{
|
||||
|
||||
# Fonts
|
||||
load_builtin_fonts()
|
||||
for pl in all_viewer_plugins():
|
||||
pl.load_fonts()
|
||||
self.set_font_settings()
|
||||
|
||||
# Security
|
||||
@ -169,8 +172,11 @@ class Document(QWebPage): # {{{
|
||||
if self.loaded_javascript:
|
||||
return
|
||||
self.loaded_javascript = True
|
||||
self.loaded_lang = self.js_loader(self.mainFrame().evaluateJavaScript,
|
||||
self.current_language, self.hyphenate_default_lang)
|
||||
evaljs = self.mainFrame().evaluateJavaScript
|
||||
self.loaded_lang = self.js_loader(evaljs, self.current_language,
|
||||
self.hyphenate_default_lang)
|
||||
for pl in all_viewer_plugins():
|
||||
pl.load_javascript(evaljs)
|
||||
|
||||
@pyqtSignature("")
|
||||
def animated_scroll_done(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user