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

About these ads
Etiquetado , ,

One thought on “Use GtkSourceView widget in Glade

  1. [...] I’m trying to use a Glade file that has a GtkSourceView widget in PyGObject. I’ve wrote a little guide on how to start using the new GtkSourceView 3.0 in Glade: http://cjenkins.wordpress.com/2012/05/08/use-gtksourceview-widget-in-glade/ [...]

Deja un comentario

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

Seguir

Recibe cada nueva publicación en tu buzón de correo electrónico.

A %d blogueros les gusta esto: