mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-01 05:58:39 +00:00
[Docs] Cleanup updating plugin page
This commit is contained in:
parent
b711cd258a
commit
5b315e90c5
1 changed files with 62 additions and 21 deletions
|
@ -7,17 +7,14 @@ The main changes are with Python 3 support and the new GTK3 user interface with
|
||||||
the dropping of GTK2. However it is still possible for a 1.3 plugin to be made
|
the dropping of GTK2. However it is still possible for a 1.3 plugin to be made
|
||||||
compatible with 2.0 and this guide aims to helps with that process.
|
compatible with 2.0 and this guide aims to helps with that process.
|
||||||
|
|
||||||
Note that the Deluge 2.0 plugins now use namespace packaging which is not
|
|
||||||
compatible with Deluge 1.3.
|
|
||||||
|
|
||||||
## Python
|
## Python
|
||||||
|
|
||||||
### Python version matching
|
### Python version matching
|
||||||
|
|
||||||
Ensure your code is both Python 2.7 and Python >=3.5 compatible.
|
Ensure your code is both Python 2.7 and Python >=3.5 compatible.
|
||||||
|
|
||||||
In `1.3-stable` the plugins that were built with a specfific version of Python
|
In `1.3-stable` the plugins that were built with a specific version of Python
|
||||||
could on be loaded if the system Python also matched.
|
would only be loaded if the system Python also matched.
|
||||||
|
|
||||||
This has change in Deluge 2.0 and it will load any Python version of plugin
|
This has change in Deluge 2.0 and it will load any Python version of plugin
|
||||||
eggs so compatibility is essential for end-users not to encounter issues.
|
eggs so compatibility is essential for end-users not to encounter issues.
|
||||||
|
@ -30,8 +27,10 @@ Use [six] to assist with compatibility.
|
||||||
|
|
||||||
### Unicode literals
|
### Unicode literals
|
||||||
|
|
||||||
Add this to files to ensure strings and bytes separatation so there are no
|
Add the following to files to ensure strings and bytes separatation so there
|
||||||
surprises when running on Python 3.
|
are no surprises when running on Python 3.
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
## GTK 3 addition
|
## GTK 3 addition
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ XML files by default Deluge plugins used libglade but that has been deprecated
|
||||||
and removed in GTK3. So the libglade `.glade` files will need converted to
|
and removed in GTK3. So the libglade `.glade` files will need converted to
|
||||||
GtkBuilder `.ui` files and the Python code updated.
|
GtkBuilder `.ui` files and the Python code updated.
|
||||||
|
|
||||||
https://developer.gnome.org/gtk2/stable/gtk-migrating-GtkBuilder.html
|
See the official [Migrating to GtkBuilder][migrate-gtkbuilder] document for more details.
|
||||||
|
|
||||||
#### gtk-builder-convert
|
#### gtk-builder-convert
|
||||||
|
|
||||||
|
@ -62,9 +61,12 @@ To convert your GTK run it like so:
|
||||||
|
|
||||||
#### Glade UI designer for GTK2
|
#### Glade UI designer for GTK2
|
||||||
|
|
||||||
The above conversion can be done in Glade UI designer (version <=3.8), ensuring
|
The above conversion can also be done in Glade UI designer (version <=3.8).
|
||||||
that the minimum Gtk version is set to 2.24 and any deprecated widgets are
|
|
||||||
fixed. The updated file should be saved with file extension `.ui`.
|
In the preferences select `GtkBuilder` as the project file format. Ensure
|
||||||
|
that the minimum Gtk version is set to 2.24 and fix any deprecated widgets.
|
||||||
|
|
||||||
|
The updated file should be saved with file extension `.ui`.
|
||||||
|
|
||||||
#### Python code changes
|
#### Python code changes
|
||||||
|
|
||||||
|
@ -72,16 +74,25 @@ The code needs to replace `gtk.glade` references with `gtk.Builder` and the
|
||||||
first step is updating how the files are loaded:
|
first step is updating how the files are loaded:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
- self.glade = gtk.glade.XML(get_resource("config.glade"))
|
- glade = gtk.glade.XML(get_resource("config.glade"))
|
||||||
+ self.builder = gtk.Builder()
|
+ builder = Gtk.Builder.new_from_file(get_resource("config.ui"))
|
||||||
+ self.builder.add_from_file(get_resource("config.ui"))
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The next stage is to replace every occurange of these `glade` methods with
|
Replace signals method:
|
||||||
the `builder` equivalents:
|
|
||||||
|
|
||||||
glade.signal_autoconnect -> builder.connect_signals
|
```diff
|
||||||
glade.get_widget -> builder.get_object
|
- glade.signal_autoconnect(self)
|
||||||
|
+ builder.connect_signals(self)
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `get_widget` with `get_object`:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- glade.get_widget
|
||||||
|
+ builder.get_object
|
||||||
|
```
|
||||||
|
|
||||||
|
Check for any remaining `glade` methods and replace with the `builder` equivalents.
|
||||||
|
|
||||||
### Migrate XML files to GTK3
|
### Migrate XML files to GTK3
|
||||||
|
|
||||||
|
@ -89,7 +100,7 @@ If you open and save the file it will update with the new requirement header:
|
||||||
|
|
||||||
<!-- Generated with glade 3.18.3 -->
|
<!-- Generated with glade 3.18.3 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.0"/>
|
<requires lib="gtk+" version="3.10"/>
|
||||||
|
|
||||||
You can fix deprecated widgets but keep the minimum GTK version to <= 3.10 for
|
You can fix deprecated widgets but keep the minimum GTK version to <= 3.10 for
|
||||||
desktop compatiblity.
|
desktop compatiblity.
|
||||||
|
@ -118,9 +129,11 @@ https://pygobject.readthedocs.io/en/latest/guide/porting.html
|
||||||
|
|
||||||
### Deluge GTK3
|
### Deluge GTK3
|
||||||
|
|
||||||
Imports will need updated from `deluge.ui.gtkui` to `deluge.ui.gtk3`.
|
#### Imports
|
||||||
|
|
||||||
### PluginBase
|
Imports will need renamed from `deluge.ui.gtkui` to `deluge.ui.gtk3`.
|
||||||
|
|
||||||
|
There is also a new PluginBase for Gtk3 UI:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
-from deluge.plugins.pluginbase import GtkPluginBase
|
-from deluge.plugins.pluginbase import GtkPluginBase
|
||||||
|
@ -129,4 +142,32 @@ Imports will need updated from `deluge.ui.gtkui` to `deluge.ui.gtk3`.
|
||||||
+class Gtk3UI(Gtk3PluginBase):
|
+class Gtk3UI(Gtk3PluginBase):
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Entry points
|
||||||
|
|
||||||
|
To enable the GTK3 UI to find the plugin the entry points requires updating too.
|
||||||
|
|
||||||
|
In the plugin `__init__.py` file add a new `Gtk3UIPlugin` class:
|
||||||
|
|
||||||
|
```
|
||||||
|
class Gtk3UIPlugin(PluginInitBase):
|
||||||
|
def __init__(self, plugin_name):
|
||||||
|
from .gtk3ui import Gtk3UI as _plugin_cls
|
||||||
|
self._plugin_cls = _plugin_cls
|
||||||
|
super(Gtk3UIPlugin, self).__init__(plugin_name)
|
||||||
|
```
|
||||||
|
|
||||||
|
A new entry for GTK3 UI can then be added to `setup.py`:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
[deluge.plugin.gtkui]
|
||||||
|
%s = %s:GtkUIPlugin
|
||||||
|
+ [deluge.plugin.gtk3ui]
|
||||||
|
+ %s = deluge_%s:Gtk3UIPlugin
|
||||||
|
[deluge.plugin.webui]
|
||||||
|
%s = %s:WebUIPlugin
|
||||||
|
- """ % ((__plugin_name__, __plugin_name__.lower())*3)
|
||||||
|
+ """ % ((__plugin_name__, __plugin_name__.lower())*4)
|
||||||
|
```
|
||||||
|
|
||||||
|
[migrate-gtkbuilder]: https://developer.gnome.org/gtk2/stable/gtk-migrating-GtkBuilder.html
|
||||||
[autoadd gtkbuilder]: https://git.deluge-torrent.org/deluge/commit/?h=develop&id=510a8b50b213cab804d693a5f122f9c0d9dd1fb3
|
[autoadd gtkbuilder]: https://git.deluge-torrent.org/deluge/commit/?h=develop&id=510a8b50b213cab804d693a5f122f9c0d9dd1fb3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue