12

I am converting a script to use Gtk3 using the migration guide (Porting GTK2 to GTK3). I converted my import pygtk to a from gi.repository import Gtk and so on...

I'm stuck because the glade module was loaded from module gtk:

 import gtk
 import gtk.glade

but there's no way now to do that anymore.

Note that I would only need a replacement for gtk.glade.XML()...

tshepang
  • 12,111
  • 21
  • 91
  • 136
MP0
  • 1,033
  • 2
  • 10
  • 17

2 Answers2

14

Well, the solution is pretty obvious, after calling to Gtk.Builder() one needs to convert the old glade interface with the gtk-builder-convert command to get the interface file in the right version.

 $ gtk-builder-convert myui.glade myui.ui

And then, in the python script:

 from gi.repository import Gtk
 builder = Gtk.Builder()
 builder.add_from_file("myui.ui")

Thanks to Riccardo.

MP0
  • 1,033
  • 2
  • 10
  • 17
4

This should work

from gi.repository import Gtk
builder = Gtk.Builder()
builder.add_from_file("project.xml")
Riccardo Galli
  • 12,419
  • 6
  • 64
  • 62
  • Well, I get called names by Python, because my XML file has a non-valid root element called `glade-interface` :) – MP0 May 13 '11 at 10:11
  • 3
    I get the same issue. We really need some simple tutorials on using Glade and PYGObject, if thas what they want us to use. Too much reliance on PyGTK at the moment. – Schodemeiss May 13 '11 at 10:56
  • did it work? I couldn't test it. In that case I'll change the wording to "This works" – Riccardo Galli May 13 '11 at 11:23
  • nop it didn't, see my first comment. What form does project.xml must have ? Isn't it a glade file ? – MP0 May 13 '11 at 11:51
  • as far I remember, time ago libglade was superseded by gtk.builder to have an official gtk api. The format must have changed. See http://www.micahcarrick.com/gtk-builder-libglade-faq.html – Riccardo Galli May 13 '11 at 14:22