[python] How can a noob get a simple implementation?

John (J5) Palmieri johnp at redhat.com
Wed Aug 31 19:28:09 PDT 2005


On Tue, 2005-08-30 at 17:37 +0200, Federico Pelloni wrote:
> Hi everybody :-)
> 
> First of all, a bit of scenery:
> 
> - python window manager (today, a wrapper over Pywm)
> - python taskbar (building it on my own)
> 
> They should communicate between them, and since I want this simple
> DE to be modern (the taskbar uses cairo for rendering) I thought
> the best way is DBus.
> 
> My idea:
> 
> 1 - a window is created
> 2 - the WM should emit a signal (let's say "window.created") over dbus
> with no particular destination (it could be useful also for a pager, one 
> day)
> 3 - the taskbar receives the signal "window.created" sent by "org.fredp.wm"
> 4 - it draws the new task using the infos shipping with the signal 
> window.created
> 
> My questions:
> 
> Either
> A - is it possible to have this done with a few (I mean 2 or 3, not many 
> more)
>     function calls? Maybe a
>     dbus.emit_signal("window.created", (windowobject))
>     in the WM code and a

class WindowManager(dbus.service.Object):
    @dbus.service.signal('org.foo.WindowManagerInterface')
    def __init__(self, bus_name, 
		 object_path='/org/foo/WindowManager'):
        dbus.service.Object.__init__(self, bus_name, object_path)

    def WindowCreated(window_name):
        pass

session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.foo.WindowManager', bus=session_bus)
wm = WindowManager(bus_name)
wm.WindowCreated("Name of the window")

>     dbus.add_signal_receiver("window.created", self.draw_task)
>     in the taskbar code. 

def window_created_callback(window_name):
    print "Window %s created" % window_name

bus = dbus.SessionBus()

bus.add_signal_receiver(window_created_callback,
                        'WindowCreated',
			'org.foo.WindowManagerInterface',
                        'org.foo.WindowManager',
                        '/org/foo/WindowManager')

> Quick and simple, I don't need much more.
> OR
> B - is there an up-to-date clear tutorial showing how to do something 
> similar?
>     Often I find code that doesn't work (even that from the official how-to,
>     I can't import dbus.service)

http://dbus.freedesktop.org/doc/dbus-tutorial.html

I have to get the latest docs online which fix a few things.

You are most likely using an old version of D-Bus.  All distros should
be shipping with 0.3x (most likely 0.36.x or 0.37) soon.  Gnome 2.12 is
going to require it.  I am in the process of stabilizing the bindings
right now so I don't expect much to change other than internals and some
added API.

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list