Gnomeapplet - 在应该是条目和按钮的地方只看到一个白点
我已经为 gnome-panel 编写了一个 gnomeapplet,以及相应的服务器文件。当我使用“调试模式”时,一切似乎都工作正常,但是当我尝试从面板加载小程序时,它只显示一个小白点。 谁能帮我找到问题所在吗?
我的代码是:
#!/usr/bin/env python
import gnomeapplet
import gobject
import sys
import gtk
class Priberam(gnomeapplet.Applet):
def __init__(self, applet, iid):
hbox = gtk.HBox(False, 0)
image = gtk.Image()
pixbuf = gtk.gdk.pixbuf_new_from_file('1.png')
pixbuf = gtk.gdk.Pixbuf.add_alpha(pixbuf,255,255,255 ,255)
size = applet.get_size()-6
pixbuf = pixbuf.scale_simple(size,size,gtk.gdk.INTERP_BILINEAR)
image.set_from_pixbuf(pixbuf)
button_search = gtk.Button()
button_search.add(image)
entry = gtk.Entry()
hbox.pack_start(button_search, False, False, 0)
hbox.pack_end(entry, False, False, 0)
applet.add(hbox)
applet.show_all()
gobject.type_register(Priberam)
def priberam_factory(applet,iid):
Priberam(applet,iid)
return True
if len(sys.argv) > 1 and sys.argv[1] == '-d': # debugging
mainWindow = gtk.Window()
mainWindow.set_title('Applet window')
mainWindow.connect("destroy", lambda w: gtk.main_quit())
applet = gnomeapplet.Applet()
priberam_factory(applet, None)
applet.reparent(mainWindow)
mainWindow.show_all()
gtk.main()
sys.exit()
if __name__ == '__main__':
gnomeapplet.bonobo_factory('OAFIID:GNOME_Priberam_Factory', gnomeapplet.Applet.__gtype__, 'Priberam Applet', '0.1', priberam_factory)
提前致谢
I have written a gnomeapplet for gnome-panel, and the corresponding server file. Everything seems to work fine when I use the "debug mode", but when I try to load the applet from the panel it shows only a little white dot.
Can anyone help me find the problem?
my code is:
#!/usr/bin/env python
import gnomeapplet
import gobject
import sys
import gtk
class Priberam(gnomeapplet.Applet):
def __init__(self, applet, iid):
hbox = gtk.HBox(False, 0)
image = gtk.Image()
pixbuf = gtk.gdk.pixbuf_new_from_file('1.png')
pixbuf = gtk.gdk.Pixbuf.add_alpha(pixbuf,255,255,255 ,255)
size = applet.get_size()-6
pixbuf = pixbuf.scale_simple(size,size,gtk.gdk.INTERP_BILINEAR)
image.set_from_pixbuf(pixbuf)
button_search = gtk.Button()
button_search.add(image)
entry = gtk.Entry()
hbox.pack_start(button_search, False, False, 0)
hbox.pack_end(entry, False, False, 0)
applet.add(hbox)
applet.show_all()
gobject.type_register(Priberam)
def priberam_factory(applet,iid):
Priberam(applet,iid)
return True
if len(sys.argv) > 1 and sys.argv[1] == '-d': # debugging
mainWindow = gtk.Window()
mainWindow.set_title('Applet window')
mainWindow.connect("destroy", lambda w: gtk.main_quit())
applet = gnomeapplet.Applet()
priberam_factory(applet, None)
applet.reparent(mainWindow)
mainWindow.show_all()
gtk.main()
sys.exit()
if __name__ == '__main__':
gnomeapplet.bonobo_factory('OAFIID:GNOME_Priberam_Factory', gnomeapplet.Applet.__gtype__, 'Priberam Applet', '0.1', priberam_factory)
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了...解决方案是如此简单...我只需将图像文件的路径更改为完整路径...而不是
pixbuf = gtk.gdk.pixbuf_new_from_file('1.png')< /code> 我应该使用例如:
pixbuf = gtk.gdk.pixbuf_new_from_file('/home/username/applet/1.png')
更好:
pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(os.path.dirname(__file__), '1.png'))
,别忘了导入 os
Solved...The solution was so simple...I just have to change the path to the image file to the complete path...instead of
pixbuf = gtk.gdk.pixbuf_new_from_file('1.png')
I should use for example:pixbuf = gtk.gdk.pixbuf_new_from_file('/home/username/applet/1.png')
Better:
pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(os.path.dirname(__file__), '1.png'))
, don't forget toimport os