mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove webeninge_demo plugin example as now we can use webengine in the main calibre process
This commit is contained in:
parent
31b1746d88
commit
b56b524a78
@ -255,34 +255,6 @@ HTML/CSS/image files and has convenience methods for doing many useful things.
|
||||
The container object and various useful utility functions that can be reused in
|
||||
your plugin code are documented in :ref:`polish_api`.
|
||||
|
||||
|
||||
Running User Interface plugins in a separate process
|
||||
-----------------------------------------------------------
|
||||
|
||||
If you are writing a user interface plugin that needs to make use
|
||||
of Qt WebEngine, it cannot be run in the main calibre process as it
|
||||
is not possible to use WebEngine there. Instead you can copy the data
|
||||
your plugin needs to a temporary folder and run the plugin with that
|
||||
data in a separate process. A simple example plugin follows that shows how
|
||||
to do this.
|
||||
|
||||
You can download the plugin from
|
||||
:download_file:`webengine_demo_plugin.zip`.
|
||||
|
||||
The important part of the plugin is in two functions:
|
||||
|
||||
.. literalinclude:: plugin_examples/webengine_demo/ui.py
|
||||
:lines: 47-
|
||||
|
||||
.. literalinclude:: plugin_examples/webengine_demo/main.py
|
||||
:lines: 12-
|
||||
|
||||
|
||||
The ``show_demo()`` function asks the user for a URL and then runs
|
||||
the ``main()`` function passing it that URL. The ``main()`` function
|
||||
displays the URL in a ``QWebEngineView``.
|
||||
|
||||
|
||||
Adding translations to your plugin
|
||||
--------------------------------------
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
# The class that all Interface Action plugin wrappers must inherit from
|
||||
from calibre.customize import InterfaceActionBase
|
||||
|
||||
|
||||
class WebEginePluginDemo(InterfaceActionBase):
|
||||
'''
|
||||
This class is a simple wrapper that provides information about the actual
|
||||
plugin class. The actual interface plugin class is called InterfacePlugin
|
||||
and is defined in the ui.py file, as specified in the actual_plugin field
|
||||
below.
|
||||
|
||||
The reason for having two classes is that it allows the command line
|
||||
calibre utilities to run without needing to load the GUI libraries.
|
||||
'''
|
||||
name = 'WebEngine Plugin Demo'
|
||||
description = 'A WebEngine plugin demo'
|
||||
supported_platforms = ['windows', 'osx', 'linux']
|
||||
author = 'Kovid Goyal'
|
||||
version = (1, 0, 0)
|
||||
minimum_calibre_version = (3, 99, 3)
|
||||
|
||||
#: This field defines the GUI plugin class that contains all the code
|
||||
#: that actually does something. Its format is module_path:class_name
|
||||
#: The specified class must be defined in the specified module.
|
||||
actual_plugin = 'calibre_plugins.webengine_demo.ui:InterfacePlugin'
|
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB |
@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from qt.core import QUrl
|
||||
from qt.webengine import QWebEngineView
|
||||
|
||||
from calibre.gui2 import Application
|
||||
|
||||
|
||||
def main(url):
|
||||
# This function is run in a separate process and can do anything it likes,
|
||||
# including use QWebEngine. Here it simply opens the passed in URL
|
||||
# in a QWebEngineView
|
||||
app = Application([])
|
||||
w = QWebEngineView()
|
||||
w.setUrl(QUrl(url))
|
||||
w.show()
|
||||
w.raise_()
|
||||
app.exec()
|
@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
if False:
|
||||
# This is here to keep my python error checker from complaining about
|
||||
# the builtin functions that will be defined by the plugin loading system
|
||||
# You do not need this code in your plugins
|
||||
get_icons = get_resources = None
|
||||
|
||||
# The class that all interface action plugins must inherit from
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
from qt.core import QInputDialog
|
||||
|
||||
|
||||
class InterfacePlugin(InterfaceAction):
|
||||
|
||||
name = 'WebEngine Plugin Demo'
|
||||
|
||||
# Declare the main action associated with this plugin
|
||||
# The keyboard shortcut can be None if you dont want to use a keyboard
|
||||
# shortcut. Remember that currently calibre has no central management for
|
||||
# keyboard shortcuts, so try to use an unusual/unused shortcut.
|
||||
action_spec = ('WebEngine Plugin Demo', None,
|
||||
'Run the WebEngine Plugin Demo', 'Ctrl+Shift+F2')
|
||||
|
||||
def genesis(self):
|
||||
# This method is called once per plugin, do initial setup here
|
||||
|
||||
# Set the icon for this interface action
|
||||
# The get_icons function is a builtin function defined for all your
|
||||
# plugin code. It loads icons from the plugin zip file. It returns
|
||||
# QIcon objects, if you want the actual data, use the analogous
|
||||
# get_resources builtin function.
|
||||
#
|
||||
# Note that if you are loading more than one icon, for performance, you
|
||||
# should pass a list of names to get_icons. In this case, get_icons
|
||||
# will return a dictionary mapping names to QIcons. Names that
|
||||
# are not found in the zip file will result in null QIcons.
|
||||
icon = get_icons('images/icon.png')
|
||||
|
||||
# The qaction is automatically created from the action_spec defined
|
||||
# above
|
||||
self.qaction.setIcon(icon)
|
||||
self.qaction.triggered.connect(self.show_dialog)
|
||||
|
||||
def show_dialog(self):
|
||||
# Ask the user for a URL
|
||||
url, ok = QInputDialog.getText(self.gui, 'Enter a URL', 'Enter a URL to browse below', text='https://calibre-ebook.com')
|
||||
if not ok or not url:
|
||||
return
|
||||
# Launch a separate process to view the URL in WebEngine
|
||||
self.gui.job_manager.launch_gui_app('webengine-dialog', kwargs={
|
||||
'module':'calibre_plugins.webengine_demo.main', 'url':url})
|
Loading…
x
Reference in New Issue
Block a user