Allow viewer plugins to customize the viewer's UI

This commit is contained in:
Kovid Goyal 2013-11-29 22:46:34 +05:30
parent 87255226c0
commit 43770ce0f2
3 changed files with 20 additions and 0 deletions

View File

@ -726,5 +726,21 @@ class ViewerPlugin(Plugin): # {{{
'''
pass
def customize_ui(self, ui):
'''
This method is called once when the viewer is created. Use it to make
any customizations you want to the viewer's user interface. For
example, you can modify the toolbars via ui.tool_bar and ui.tool_bar2.
'''
pass
def customize_context_menu(self, menu, event, hit_test_result):
'''
This method is called every time the context (right-click) menu is
shown. You can use it to customize the context menu. event is the
context menu event and hit_test_result is the QWebHitTestResult for this
event in the currently loaded document.
'''
pass
# }}}

View File

@ -702,6 +702,8 @@ class DocumentView(QWebView): # {{{
menu.addSeparator()
menu.addAction(self.manager.action_quit)
for plugin in self.document.all_viewer_plugins:
plugin.customize_context_menu(menu, ev, r)
menu.exec_(ev.globalPos())
def inspect(self):

View File

@ -359,6 +359,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
# continue to function even when the toolbars are hidden
self.addAction(action)
for plugin in self.view.document.all_viewer_plugins:
plugin.customize_ui(self)
self.view.document.settings_changed.connect(self.settings_changed)
self.restore_state()