Jump to: navigation, search


983 bytes added, 26 May
gramplet = 'init',
gramplet_title=_("Sample Gramplet"),
help_url="Sample Gramplet"
=== Explanation ===
The main work of a Gramplet is performed in a function, or a class. In this very simple example, a function '''<code>init''' </code> is defined that takes a single argument, <code>gui</code>. The function simply sets the gui's text area to be "Hello World!", and that's it. It does this just once, and never changes.
Before a plugin can be used, it needs to be "registered". You call the register function with a number of named-arguments. There are a number of named-arguments that you can provide, including: name, height, content, title, expand, state, and data. We will explore those in detail, below.
== GUI Interface ==* [[Gramplets#Widget_Gramplet_example|Widget Gramplet example]]* [[Gramplets#Cairo_Clock_Example|Cairo Clock Example]]
===Widget Gramplet example===
Occasionally, you might have to dive down to the graphical objects that compose a Gramplet.
If you wanted to put an arbitrary gtk object into the main area of a Gramplet, then you need to replace the standard textview object with your own. Here is the basic structure:
# File:
from gettext import gettext as _
from gramps.gen.plug import Gramplet
from gi.repository import Gtk
class WidgetGramplet(Gramplet):
def init(self):
self.gui.WIDGET = ### Some Widget Constructor ###
# File:
id= "Widget Gramplet",
name=_("Widget Gramplet"),
description = _("Widget Gramplet example"),
gramplet = 'WidgetGramplet',
version = '0.0.1',
gramps_target_version = "5.1",
====Gramps 3.x and older====
# File:
===Cairo Clock Example===
[[File:ClockGramplet-addon-example-50.png|thumb|400px|right|Clock Gramplet - shown detached (Gramps 5.0.0)]]
In fact, with Python, gtkGTK, and cairo, you can make your own widgets that do pretty much anything and look very nice.
Here is an example adding a Cairo Clock (which really keeps time)
* with With GTK 2 +3 & Gramps 35.41** Github code: [ ClockGramplet.addon.tgz]* or with GTK+3 & Gramps 4.2* Manual Download: [ ClockGramplet.addon.tgz]

Navigation menu