GEPS 029: GTK3-GObject introspection Conversion
Gramps was written with GTK 2 toolkit. This has been replaced upstream with GTK 3, so Gramps should convert to GTK 3.
We try to convert 1 to 1. If there are problems due to deprecated features, or otherwise, add in the code:
# TODO GTK3: write what problem is due to gtk 3 conversion
Before release, all TODO GTK3 in the code must be cleaned up
Python GTK3 docs: 
Alternative is to look at the base C documentation, and understand from experience how the introspection works. Gnome docs: .
As python works with classes, it looks somewhat like the C++ interface: . To investigate the specific override (how to init Gtk classes):
- python overrides: 
Furthermore, for the other gi libs:
For people on Ubuntu 12.04, you need:
1. add the gnome_shell repo to have the latest version of glib and friends, see how to add the ppa on: gnome_shell pppa Then upgrade your system via the system manager.
Note 1 : If you use Gnome3, also add the gnome3 ppa!
Note 2: this can make gnome shell unstable if the ppa is too bleeding edge!!
2. install version 3.3.2 of pygobject. No ppa for this, I use the git repo on gnome.org, so my git config:
[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = http://git.gnome.org/browse/pygobject
So to install it to folder pygobject, do
git clone git://git.gnome.org/pygobject pygobject
Then checkout tag 3.3.2, so
cd pygobject git checkout 3.3.2
Make sure you have the dependencies installed, you will need:
- libglib2.0-dev package (otherwise you will obtain an error like undefined mqcro: AM_PATH_GLIB_2_0.
- autoconf, automake, libtool, intltool package
- python-dev package
- libcairo2-dev, python-cairo-dev
So, use the line:
sudo apt-get install autoconf automake libtool python-dev libglib2.0-dev libcairo2-dev python-cairo-dev python-gobject-dev libgirepository1.0-dev
Then compile pygobject:
./autogen.sh make sudo make install
Now this installs to /usr/local, so to run the test with that, on ubuntu in your terminal:
PYTHONPATH=/usr/local/lib/python2.7/site-packages/ python gramps.py
If you then get:
$ PYTHONPATH=/usr/local/lib/python2.7/site-packages/ python src/gramps.py Gtk typelib not installed. Install Gnome Introspection, and pygobject version 3.3.2 or later. Gramps will terminate now.
You may need to:
Also, I had to get rid of the older gobject:
sudo rm -rf /usr/lib/python2.7/dist-packages/gobject
As of 25 July 2012, the Debian repositories does not contain sufficiently up-to-date python GObject introspection packages and so need to be installed from the experimental repository, which currently contains version 3.3.4. Perhaps the simplest way to install is just to download the latest packages from the Debian packages web site. The files required can be found for different architectures at:
Install the package files with dpkg. eg
dpkg -i python-gi_3.3.4-1_i386.deb
A GTK3 theme engine is required to make Gramps look visually more appealing. Try gtk3-engines-oxygen.
GTK 3 theme
If Gramps looks ugly in GTK 3, you probably are not using a GTK 3 theme. In that case, GTK falls back to the Raleigh theme.
The solution is to install a theme that comes with a GTK 3 theme. For example the Adwaita theme:
For a good dark theme, consider elementary-dark-theme, installable from 
To set the theme, open gramps, and open System settings -> Application Appearance -> GTK+ Appearance, and select different theme, click on apply. If you see Gramps update completely, you have selected a theme with GTK 3 support. If the theme falls back to something consisting of Raleigh theme components, the theme does not have good GTK 3 support. Even if Gramps updates, not all elements visible will update. Restart Gramps to be sure the theme works as intended. You can install gtk-theme-switch to test themes.
Spell Check Install
For working spell check, we need a patched gtkspell version that supports gobject introspection. A working version is the changes branch at https://github.com/manisandro/gtkspell3/tree/changes. So one needs to install this version of gtkspell. The python-gtkspell code is then no longer needed, and can be removed. Source of this code is a redhat bug entry: 
Gramps supports this version since revision 20130: 
Installation of spell check in Ubuntu 12.04
First we install the git package to obtain the code:
sudo apt-get install git
Obtain the source code, and change to the version with gtk3 and gobject introspection support:
git clone git://github.com/manisandro/gtkspell3.git cd gtkspell3/ git checkout -b changes origin/changes
Now obtain the packages needed to compile this code. In my case I had most code (see above installation introspection for other packages that might be needed). I still needed to install the following:
sudo apt-get install gtk-doc-tools libenchant-dev
Now compile and install the code
./autogen.sh make sudo make install
Gramps now needs to find the gtkspell typelib and introspection lib. The first I achieve by copying the typelib to the correct location:
sudo cp /usr/local/lib/girepository-1.0/Gtkspell-1.0.typelib /usr/lib/girepository-1.0/
The lib can be found by path by setting the LD_LIBRARY_PATH environment variable. Hence, start Gramps as follows:
LD_LIBRARY_PATH=/usr/local/lib python src/gramps.py
If you followed the guide above and compiled your own pygobject module, you need to start Gramps with the command
PYTHONPATH=/usr/local/lib/python2.7/site-packages/ LD_LIBRARY_PATH=/usr/local/lib python src/gramps.py
If anyone files a bug against PyGobject, Gtk or any of the Gtk dependencies (except Cairo, which isn't part of Gnome), please add John (the address bugzilla has is [email protected]) to the CC list at the bottom of the bug report page or post the bug URI to the gramps-devel list.
- there are some drag and drop issues: , . Solved: Use set_target_list functions for drag and drop with a created TargetList.
- we cannot set strings in struct, see GTK bug 
- error in list_families on textview in styledtexteditor: 
- str and unicode no longer seem to work, the encoding must be passed too; Future: deprecate unicode() in the code, as we want to support python 3' - SOLVED FOR NOW: added reload(sys) in gramps.py and set encoding to utf-8. Is there a better way that is userfriendly?
- there is no longer automatic conversion to str utf-8 when using GTK functions, we must convert before passing to GTK.
- glade can no longer work with our catalog. We need to upgrade comboboxentry to combobox with has_entry manually, and hope editors keep working... - SOLVED: converted editevent.glade, all works
- expose is no longer present on gtk.widget. Draw must be used. Unclear how, .
- Gtk.Clipboard seems to work differently
- Pedigreeview is broken and must be converted to new drawing primitives. Same probably for fanchart.
- osmgpsmap is GTK2. There is a GTK3 branch in git, we should try it, and contribute to the conversion.
- menu.popup does not seem to work in some instances. Solved: Make sure the reference to menu survives, so eg, do self.menu= function, then self.menu.popup. Alternatively, passing position function seems to also work as workaround, see grampsbar.py for example
- Many Gtk elements no longer grab certain events. Solved: Add a Gtk.EventBox under them to grab the event.
Related Gramps Bugs
- #5009: Use gobject introspection for GTK 3 dependency
How to investigate a hard crash?
With GTK 3, hard crashes are a lot more likely than before. Very troubling for a python developer, as you do not know where the crash happens. So, to investigate these, do the following:
$ > gdb python (gdb) set env GRAMPSHOME /path/to/gramps/src (gdb) set env PYTHONPATH $PYTHONPATH:$GRAMPSHOME (gdb) r $GRAMPSHOME/gramps.py ...after the crash... (gdb) bt
This works best if you have the debug symbols installed for everything relevant, or are running from a self-built tree.