Gnomeapplet - 在应该是条目和按钮的地方只看到一个白点

发布于 2024-11-26 21:47:59 字数 1492 浏览 1 评论 0原文

我已经为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独患者 2024-12-03 21:47:59

解决了...解决方案是如此简单...我只需将图像文件的路径更改为完整路径...而不是 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 to import os

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文