Comment 12 for bug 540950

Revision history for this message
Eemil Lagerspetz (eemil-lagerspetz) wrote :

I investigated this another way: from near-zero. I tried the sample python applet in the docs of python-gnomeapplet. I also made a very small version of dockbarx, in the hope that it would give insight into why it does not work. Here is a dockbarx factory class that does not cause the error.

#!/usr/bin/python

# Copyright 2008, 2009, 2010 Aleksey Shaferov and Matias Sars
#
# DockBar is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DockBar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dockbar. If not, see <http://www.gnu.org/licenses/>.

import pygtk
pygtk.require('2.0')
import gtk
import gobject
import gnomeapplet
import sys

class DockBar(gobject.GObject):
    __gsignals__ = {
        "db-move": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,()),
    }
    def __init__(self,applet):
        gobject.GObject.__init__(self)
        print "Dockbarx init"
        self.applet = applet

        #--- Applet / Window container
        if self.applet != None:
            self.applet.set_applet_flags(gnomeapplet.HAS_HANDLE|gnomeapplet.EXPAND_MINOR)
            if self.applet.get_orient() == gnomeapplet.ORIENT_DOWN or applet.get_orient() == gnomeapplet.ORIENT_UP:
                self.orient = "h"
                self.container = gtk.HBox()
            else:
                self.orient = "v"
                self.container = gtk.VBox()
            self.applet.connect("change-orient",self.on_change_orient)
            self.applet.connect("delete-event",self.cleanup)
            self.applet.add(self.container)
            self.applet.connect("size-allocate",self.on_applet_size_alloc)
            self.applet.connect("change_background", self.on_change_background)
            self.pp_menu_xml = """
            <popup name="button3">
                <menuitem name="About Item" verb="About" stockid="gtk-about" />
                <menuitem name="Preferences" verb="Pref" stockid="gtk-properties" />
                <menuitem name="Reload" verb="Reload" stockid="gtk-refresh" />
            </popup>
            """

            #self.pp_menu_verbs = [("About", self.on_ppm_about),
                                  #("Pref", self.on_ppm_pref),
                                  #("Reload", self.reload)]
            #self.applet.setup_menu(self.pp_menu_xml, self.pp_menu_verbs,None)
            self.applet_origin_x = -1000 # off screen. there is no 'window' prop
            self.applet_origin_y = -1000 # at this step
            self.applet.set_background_widget(applet) # background bug workaround
            self.applet.show_all()
            #gobject.idle_add(self.idle_init)
        else:
            self.container = gtk.HBox()
            self.orient = "h"
            #self.idle_init()

    def cleanup(self,event):
        del self.applet

class DockBarWindow():
    """DockBarWindow sets up the window if run-in-window is used."""
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_default_size(200,40)
        self.window.show()
        self.window.set_property("skip-taskbar-hint",True)
        self.window.set_keep_above(True)
        self.window.connect ("delete_event",self.delete_event)
        self.window.connect ("destroy",self.destroy)

        self.dockbar = DockBar(None)
        hbox = gtk.HBox()
        button = gtk.Button('Pref')
        #button.connect('clicked', self.dockbar.on_ppm_pref)
        hbox.pack_start(button, False)
        hbox.pack_start(self.dockbar.container, False)
        eb = gtk.EventBox()
## eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#2E2E2E"))
        eb.add(hbox)
        self.window.add(eb)
        eb.show_all()
        ##self.window.add(self.dockbar.container)

    def delete_event (self,widget,event,data=None):
        return False

    def destroy (self,widget,data=None):
        gtk.main_quit()

    def main(self):
        gtk.main()

def dockbar_factory(applet, iid):
    dockbar = DockBar(applet)
    applet.set_background_widget(applet)
    applet.show_all()
    return True

##gc.enable()

if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":
    dockbarwin = DockBarWindow()
    dockbarwin.main()
else:
    gnomeapplet.bonobo_factory("OAFIID:GNOME_DockBarXApplet_Factory",
                                     gnomeapplet.Applet.__gtype__,
                                     "dockbar applet", "0", dockbar_factory)