wxPython + signals

Or, use wx.lib.pubsub, same idea but different way of doing it. In particular, pubsub allows for a hierarchy of message "topics", which I have found to be of great use in making the GUI "dumb".

Oliver

···

-----Original Message-----
From: Jürgen Kareta [mailto:python@kareta.de]
Sent: October 25, 2006 7:52 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] wxPython + signals

Jorgen Bodde schrieb:

> Hi all,
>
> I am searching for something like SigSlot (the C++'s counterpart). The
> main idea is that I want to make a data model that pushes messages /
> signals to my wxPython application. This way the GUI will
>
> Is there something like this in (wx)Python ? I saw that PyQT has it's
> signslot implementation but it should be more generic I guess..
>
> Regards,
> - Jorgen

look up pydispatcher:
*pydispatcher*.sourceforge.net

Regards,
Jürgen

Hi Peter and Oliver,

I would if I could. I am pretty new to (wx)Python so I am not aware of
it's possibilities and built in solutions. sigslot appealed to me
because I strongly believe in data model / GUI seperation. My previous
apps became monsters because the GUI did more with the objects then
plain behavioral code.

My new vision is this:

Controller Objects - Objects that can take actions like "create new project"

Data Objects - The project info itself

GUI - As minimalistic as possible, should only respond to the data
events or initialize new ones. Once I give a new "project" to the
controller like;

__controller.AddProject(new Project('my name'))

It should emit events to the GUI where the "dumb" combobox simply adds
the new project, the status bar shows this project if the
ProjectManager object tells me that the new object added is also the
selected on, etc.

The problem with traditional GUI programming is that too much
dependencies can exist, things can be forgotten to be updated, etc.

This new approach can also allow Undo / Redo much easier as the Add
signal can be replaced by a remove, which will hide the object from
the GUI's again.

To come back to the example, I am not knowledgeable enough to see how
it works, nor can I see if it allows me to specify an argument list
for every signal that I can create.

By the way I tried PyDispatcher but there is almost no example to be
found showing how it works. Anybody have a good example?

- Jorgen

By the way I tried PyDispatcher but there is almost no example to be
found showing how it works. Anybody have a good example?

Try wx.lib.pubsub . It is significantly easier to understand...

topic = 'sample.topic'
data = 'sample data'

def printer(message):

... print message.topic, message.data
...

import wx.lib.pubsub as ps

ps.Publisher.subscribe(printer, topic)
ps.Publisher.sendMessage(topic, data)

('sample', 'topic') sample data

- Josiah

···

"Jorgen Bodde" <jorgen.maillist@gmail.com> wrote:

By the way I tried PyDispatcher but there is almost no example to be
found showing how it works. Anybody have a good example?

Hi Jorgen,

the example and test directory is lost in the current pydispatcher version 2.0.0
(accidently I hope). But the older version 1.0.2 has the example. I attached the
example to this mail for your convinience. I've tested pydispatcher some time
ago with a simple gauge, witch is also attached. It was a quick and dirty try,
that should give you a starting point, but otherwise don't take it too seriously
:wink:

By the way, I prefer pydispatcher over the wx solution, because it is gui
independent and you can pass around every kind of data you can imagine.

Just run frame.py and click the button. Inside frame.py some dispatcher.send
calls are triggered, witch update the gauge in gauge.py. The dispatcher.send
method could of course also be triggered in a normal python script without any
gui modules imported.

Jürgen

frame.py (2.44 KB)

gauge.py (4.84 KB)

simple_sample.py (2.08 KB)

···

-------------------------------------------------
Versandt durch den Webmaildienst der LDC GmbH Bonn