2009-06-06 63 views

回答

2

爲什麼不使用GUI設計器就像Anjuta或Glade程序,寫出來glade XML並使用libglade的python綁定來使用XML文件......有點像XAML。

編輯,添加了一些鏈接,Glade.xml->蟒蛇

http://glc.sourceforge.net/
http://www.pygtk.org/(可以幫助)

+0

在sourceforge csv中最後一次提交`glc`似乎是在2002年;也有[Glade代碼生成器 - gcgen](http://sourceforge.net/projects/gcgen/files/)與2010年的最後更新,它需要一個額外的XML庫,它打包... – sdaau 2014-06-29 19:04:48

0

似乎在啓動板已經被複制到本商場倉庫:

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

(直接download tarball - 用它進行下面的代碼段)

此外,鏈接到GladeGen作者的文章:

注意,在格萊德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 

好,我很高興我仍然可以使用這個,因爲顯然它是不可能的格萊德生成/導出/創建/另存爲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) 

...也就是說,它只是接口的空地文件(幾乎如在開始教程中),它實際上並沒有創造Python代碼,我預計,在翻譯的代碼,如:

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

...等等...這是一個恥辱,因爲那正是我所尋找的:)

相關問題