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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Federico Pelloni
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
    dbus.add_signal_receiver("window.created", self.draw_task)
    in the taskbar code. 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)


In the end, I'm sorry if my English is poor, it isn't my mother lang.

Good bye and many thanks, Federico

_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

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

Sean Meiners
Based on my experience with the python bindings (which is quite a bit  
lately) you should be able to achieve 'A' without much fuss.  As for  
how to do it, I just happened to be poking around the python examples  
included in the DBus source tree today (python/examples) and found  
example-signal-emitter.py and example-signal-recipient.py to be quite  
excellent in this regard (thanks again John P).  To try them out make  
sure you have a session bus running and start the emitter first (the  
receiver relies on it).

On Aug 30, 2005, at 8:37 AM, 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
>    dbus.add_signal_receiver("window.created", self.draw_task)
>    in the taskbar code. 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)
>
>
> In the end, I'm sorry if my English is poor, it isn't my mother lang.
>
> Good bye and many thanks, Federico
>
> _______________________________________________
> dbus mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/dbus
>

--
Sean Meiners
[hidden email]

Perl - $Just @when->$you ${thought} s/yn/tax/ &couldn\'t %get $worse;


_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

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

Jakub Piotr Cłapa-2
In reply to this post by Federico Pelloni
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

Isn't this better handled using some X IPC mechanisms? (you will loose
network transparency if you do it over DBus, won't you?)

> 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
>    dbus.add_signal_receiver("window.created", self.draw_task)
>    in the taskbar code. Quick and simple, I don't need much more.

DISCLAIMER: It's not obvious if my work is a GoodThing(TM) (I'm not
totally sure either) so please consider choosing it over the bindings
very carefully.

If you want quick and simple you could give my experimental pure-python
implementation a try (you can find it in the archives). The Python
bindings are quite sophisticated and unfortunately depend on glib (thus
on pygtk) requiring a glib mainloop in your program.

If you have any questions, don't be afraid to ask (I don't have much
documentation for my work right now --- just what's written in the
source + the example dbus_monitor.py).

> 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)

There where some API changes (but I'm afraid I do not remember what it
was changed into).

--
Regards,
Jakub Piotr Cłapa
_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

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

John Palmieri-2
In reply to this post by Federico Pelloni
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 <[hidden email]>

_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

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

Sean Meiners
Shouldn't the decorator be above WindowCreated rather than __init__?

On Wednesday 31 August 2005 07:28 pm, John (J5) Palmieri wrote:
> 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

--
Sean Meiners
[hidden email]


Perl - $Just @when->$you ${thought} s/yn/tax/ &couldn\'t %get $worse;
_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus
Reply | Threaded
Open this post in threaded view
|

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

John Palmieri-2
On Thu, 2005-09-01 at 10:03 -0700, Sean Meiners wrote:
> Shouldn't the decorator be above WindowCreated rather than __init__?

Yep, typo. Sorry about that.

> On Wednesday 31 August 2005 07:28 pm, John (J5) Palmieri wrote:
> > 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


_______________________________________________
dbus mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/dbus