Let’s continue the plugin tutorial! The last installement was on how plugins work and how to create the boilerplate for a new plugin. Now let’s look into how to access Liferea UI elements and how to modify them.
Accessing UI elements
Using the plugin boilerplate for a Liferea.ShellActivatable (a plugin that activates once the Liferea shell, which as an object comprises the entire main window UI, has been setup) we get a member variable named shell
shell = GObject.property (type=Liferea.Shell)
which can be used to look up GTK objects by name using
shell.lookup(<some name>)
Some interesting names to look up are:
Name | Description |
---|---|
mainwindow | The main GtkWindow |
leftpane | The vertical pane containing the feed list |
rightpane | The vertical pane containing the rest |
feedlist | The feed list GtkTreeView |
itemlist | The item list GtkTreeView |
browsertabs | The tabs notebook of the item view |
statusbar | The main window status bar |
This list not being exhaustive you can grep the code for more uses
rgrep liferea_shell_lookup src/
in general when you want to modify existing UI elements or add extra elements to the UI above list should be a good start.
Example: Modifying the feed list
Here is a simple example to hide the 2nd column of the feed list GtkTreeView. To do this we use the shell
member to look up the feedlist
GtkTreeView and ask it for the 2nd column which we then hide:
from gi.repository import GObject, Peas, PeasGtk, Gtk, Liferea, Gdk
class NrColumnHidePlugin (GObject.Object, Liferea.ShellActivatable):
__gtype_name__ = 'NrColumnHidePlugin'
object = GObject.property (type=GObject.Object)
shell = GObject.property (type=Liferea.Shell)
def do_activate (self):
treeview = self.shell.lookup ("feedlist")
column = Gtk.TreeView.get_column (treeview, 1)
Gtk.TreeViewColumn.set_visible (column, 0);
def do_deactivate (self):
return
This is all done on activate, nothing needs to be done on deactivation.
Related
Also check out the other plugin tutorial posts
- Plugin Tutorial Part 1 (Plugin Boiler Plate)
- Plugin Tutorial Part 2 (Acessing and modify UI elements)
- Plugin Tutorial Part 3 (Adding menu elements)
- Plugin Tutorial Part 4 (Using GTK inspector)
- Plugin Tutorial Part 5 (Enabling translations for plugins)