我在哪里可以找到GladeGen?

时间:2009-06-06 16:18:06

标签: python gtk glade

我想使用Glade设计一个GUI,并从中生成python代码。问题是,我找不到GladeGen。有谁知道它可以从哪里下载?

4 个答案:

答案 0 :(得分:2)

为什么不使用GUI设计器就像Anjuta或Glade程序,将其写入 glade XML 并使用libglade的python绑定来使用XML文件......有点像XAML

编辑,添加了一些指向Glade.xml-> python

的链接

http://glc.sourceforge.net/
http://www.pygtk.org/(可能有帮助)

答案 1 :(得分:2)

Google是你的朋友。

http://www.linuxjournal.com/article/7558

答案 2 :(得分:0)

我的建议是 - 不要生成代码。 Glade 3.6现在可以保存为GtkBuilder格式(xml),可以在代码中加载。这更容易处理!

http://www.pygtk.org/pygtk2reference/class-gtkbuilder.html

答案 3 :(得分:0)

似乎已在启动板中复制到此Bazaar存储库:

launchpad.net/~wattazoum: gladegen : Code : Python dev tools

(直接download tarball - 将其用于下面的代码段

此外,GladeGen作者的文章链接:

请注意,在Glade 3.8.0中,您可以将文件导出为LibgladeGtkBuilder;我做了一个小测试,显示你应该将文件保存为Libglade; GladeGen可以解析两者:

$ python2.7 GladeGen.py /tmp/test-libglade.glade TestMe TestMe
funcs
main <function main at 0xb72d98b4>
search_file <function search_file at 0xb72d964c>

classes
GladeWindow <class 'GladeWindow.GladeWindow'>
TestMe <class 'TestMe.TestMe'>

methods
('GladeWindow', '__init__')
('GladeWindow', 'hide')
('GladeWindow', 'set_callback_function')
('GladeWindow', 'set_search_path')
('GladeWindow', 'set_top_window')
('GladeWindow', 'show')
('TestMe', '__init__')
('TestMe', 'hide')
('TestMe', 'init')
('TestMe', 'set_callback_function')
('TestMe', 'set_search_path')
('TestMe', 'set_top_window')
('TestMe', 'show')

widgets
('GtkWindow', 'window1')
('GtkHBox', 'hbox1')
('GtkScrolledWindow', 'scrolledwindow1')

handlers

$ python2.7 GladeGen.py /tmp/test-gtkbuilder.glade TestMe2 TestMe2
funcs
main <function main at 0x95778ec>
search_file <function search_file at 0x9577684>

classes
GladeWindow <class 'GladeWindow.GladeWindow'>
TestMe2 <class 'TestMe2.TestMe2'>

methods
('GladeWindow', '__init__')
('GladeWindow', 'hide')
('GladeWindow', 'set_callback_function')
('GladeWindow', 'set_search_path')
('GladeWindow', 'set_top_window')
('GladeWindow', 'show')
('TestMe2', '__init__')
('TestMe2', 'hide')
('TestMe2', 'init')
('TestMe2', 'set_callback_function')
('TestMe2', 'set_search_path')
('TestMe2', 'set_top_window')
('TestMe2', 'show')

widgets

handlers

但是,如果您尝试运行导出的python代码,则只会运行第一个(python TestMe.py);而第二个,gtkbuilder,将失败:

$ python2.7 TestMe2.py

(TestMe2.py:24883): libglade-WARNING **: Expected <glade-interface>.  Got <interface>.

(TestMe2.py:24883): libglade-WARNING **: did not finish in PARSER_FINISH state
Traceback (most recent call last):
  File "TestMe2.py", line 66, in <module>
    main(sys.argv)
  File "TestMe2.py", line 59, in main
    w = TestMe2()
  File "TestMe2.py", line 37, in __init__
    self.init()
  File "TestMe2.py", line 52, in init
    GladeWindow.__init__(self, filename, top_window, widget_list, handlers)
  File "/path/to/src/wattazoum_pydevtools_gladegen/src/GladeWindow.py", line 77, in __init__
    self.xml = gtk.glade.XML(fname)
RuntimeError: could not create GladeXML object

嗯,我很高兴我仍然可以使用它,因为显然Glade不可能生成/ export / create / save-作为Python代码...


...编辑:虽然,应该注意出口只是:

def init(self):
  filename = '/tmp/test-libglade.glade'
  widget_list = [
          'window1',
          'hbox1',
          'scrolledwindow1',
          ]
  handlers = [
          ]
  top_window = 'window1'
  GladeWindow.__init__(self, filename, top_window, widget_list, handlers)

...也就是说,它只是与glade文件接口(就像在起始教程http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm中那样),并且它实际上并没有创建我期望的python代码,就像在翻译的代码中一样,像:

self.window1 = gtk.Window(gtk.WINDOW_TOPLEVEL)

......依旧......这是一种耻辱,因为那是我在寻找的:)