Archivo de la etiqueta: catalog

Use GtkSourceView widget in Glade

I’m developing an application that uses syntax highlight with PyGObject (Gtk+ 3.0 dynamic python bindings). If like me you need to use the GtkSourceView widget in Glade you need to follow this steps:

  1. Install gtksourceview development package:
    sudo apt-get install libgtksourceview-3.0-dev
    This will install the Glade catalog in /usr/share/glade/catalogs/gtksourceview.xml and the library in /usr/lib/x86_64-linux-gnu/libgtksourceview-3.0.so.
  2. Link library so Glade can find it:
    Glade will be unabled to find the library to load the catalog because is not in it’s search path with and error:
    (glade:7010): GladeUI-CRITICAL **: Unable to load module 'gtksourceview-3.0' from any search paths
    Solution: sudo ln -s /usr/lib/x86_64-linux-gnu/libgtksourceview-3.0.so /usr/lib/glade/modules/libgtksourceview-3.0.so

That’s it, now you have the new widget in your Glade.

GtkSourceView in Glade 3.12.0

If you’re using your Glade file with PyGObject you will need to register the new GtkSourceView type in GObject like this before calling GtkBuilder’s add_from_file():

from gi.repository import Gtk, GtkSource, GObject
from os.path import abspath, dirname, join

WHERE_AM_I = abspath(dirname(__file__))

class MyApp(object):

    def __init__(self):
        self.builder = Gtk.Builder()
        self.glade_file = join(WHERE_AM_I, 'test.glade')
        GObject.type_register(GtkSource.View)
        self.builder.add_from_file(self.glade_file)

if __name__ == '__main__':
    try:
        gui = MyApp()
        Gtk.main()
    except KeyboardInterrupt:
        pass

I’ve found very scarse documentation about this, and most of it is outdated (gtksourceview 2.0, Glade 2, PyGtk, Gtk+ 2.0, etc). So this apply to:

  • Ubuntu Precise 12.04
  • Glade 3.12.0
  • libgtksourceview 3.0
  • Gtk+ 3.0
  • PyGObject

Kind regards

Etiquetado , ,