6
我想要使用Glade文件,它有一個GtkSourceView小部件在PyGObject中。我寫了一篇關於如何開始使用新的GtkSourceView 3.0格萊德點指南:http://cjenkins.wordpress.com/2012/05/08/use-gtksourceview-widget-in-glade/從GtkSourceView在PyGObject加載GUI從GtkSourceView
問題是,當我想要加載格萊德從PyGObject:
from gi.repository import Gtk, GtkSource
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')
self.builder.add_from_file(self.glade_file)
if __name__ == '__main__':
try:
gui = MyApp()
Gtk.main()
except KeyboardInterrupt:
pass
當我運行該文件我得到這個錯誤:
Traceback (most recent call last):
File "test.py", line 15, in <module>
gui = MyApp()
File "test.py", line 11, in __init__
self.builder.add_from_file(self.glade_file)
File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
return info.invoke(*args, **kwargs)
gi._glib.GError: Invalid object type `GtkSourceView'
林間空地文件(test.glade)僅僅是一個帶有GtkSourceView窗口小部件在它:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtksourceview 3.0 -->
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkSourceView" id="gtksourceview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_tooltip">True</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
<property name="tab_width">4</property>
<property name="auto_indent">True</property>
<property name="indent_on_tab">False</property>
</object>
</child>
</object>
</interface>
一個如何解決這個問題現在是我的知識。我想我需要在調用add_from_file()之前註冊一些類型,而不是?任何想法是受歡迎的。
我使用:
- Ubuntu的精確12.04
- 格萊德3.12.0
- libgtksourceview 3.0
- GTK + 3.0
親切的問候