Changes

Jump to: navigation, search

Gramplets

983 bytes added, 26 May
Explanation
gramplet = 'init',
gramplet_title=_("Sample Gramplet"),
gramps_target_version="5.01",
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.
</pre>
== GUI Interface ==* [[Gramplets#Widget_Gramplet_example|Widget Gramplet example]]* [[Gramplets#Cairo_Clock_Example|Cairo Clock Example]]
{{stub}}
 
===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:
<pre>
# File: Widget.py
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 ###
self.gui.get_container_widget().remove(self.gui.textview)
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
self.gui.WIDGET.show()
</pre>
 
<pre>
# File: Widget.gpr.py
 
register(GRAMPLET,
id= "Widget Gramplet",
name=_("Widget Gramplet"),
description = _("Widget Gramplet example"),
height=100,
expand=False,
gramplet = 'WidgetGramplet',
gramplet_title=_("Widget"),
version = '0.0.1',
gramps_target_version = "5.1",
fname="Widget.py",
)
</pre>
 
====Gramps 3.x and older====
<pre>
# File: Widget.py
)
</pre>
 
===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: [https://gramps-addonsgithub.svn.sourceforge.net/svnrootcom/gramps-project/addons-source/branchestree/gramps34maintenance/downloadgramps51/ClockGramplet.addon.tgz ClockGramplet.addon.tgz]* or with GTK+3 & Gramps 4.2* Manual Download: [https://github.com/gramps-project/addons/blob/master/gramps50gramps51/download/ClockGramplet.addon.tgz?raw=true ClockGramplet.addon.tgz]
{{-}}
1,983
edits

Navigation menu