Newbie question about events and event handling

Patrick J. Anderson pat.j.anderson at gmail.com
Fri Nov 2 15:22:13 PDT 2007


On Fri, 02 Nov 2007 14:51:52 -0700, Robin Dunn wrote:

> Patrick J. Anderson wrote:
>> On Thu, 01 Nov 2007 16:42:13 -0700, Christopher Barker wrote:
>> 
>>> Patrick J. Anderson wrote:
>>>> I'm not sure how DayPlanner instance can catch the event originating
>>>> in from MiniCalendar instance and change the UI to reflect it.
>>> You have two options:
>>>
>>> 1) put a reference to the DayPlanner instance in your MiniCalendar,
>>> then call a method on it in your event handler. That's the easiest
>>> way, though maybe better to use the main frame or App object as an
>>> intermediary.
>>>
>>> 2) Use a way to post an event indicating that the date has changed.
>>> You can either use custom wx event and wx.PostEvent to do that, or,
>>> even better, use a system like wx.lib.pubsub to pass events around
>>> your app. I think that's probably what you want.
>>>
>>> -CHB
>> 
>> I used the reference to DayPlanner (option1) in my MiniCalendar and I
>> call a method setDate() on planner instance, but how do I update the
>> widget, so it reflects the change?
> 
> What kind of widget is it?  How did you give it the initial value?

I want an event originating from an instance of wx.calendar.CalendarCtrl 
(MiniCalendar) affect contents of the instance of wx.Panel(DayPlanner) 
where I'd like to display appointments related to a selected date.

This is not an isolated problem... I'm simply trying to understand how 
events work and how to update the UI based on events. My code lives in 
multiple modules/classes and I haven't plugged any data to it yet, but 
first I'd like to find the simplest way to make events work.

Sorry, I realize that his might be a trivial thing and I don't want to 
take too much of your time with this, but I've been trying to figure it 
out for a while now, and I appreciate any help.

The examples in the wiki are helpful, but most of them don't go beyond a 
single module/class. I've written the UI, and can start the program and 
see all widgets, and now I'm trying to wire it with events.

As I said before my background is in web programming, so it's a bit of a 
switch in mindset.





More information about the wxpython-users mailing list