开发者

Gnomeapplet - Seeing only a white dot where an entry and a button should be

开发者 https://www.devze.com 2023-03-23 21:30 出处:网络
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

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开发者_如何学Go.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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消