Newbie question about events and event handling

Patrick J. Anderson pat.j.anderson at gmail.com
Thu Nov 1 06:40:11 PDT 2007


I'm not sure how DayPlanner instance can catch the event originating in 
from MiniCalendar instance and change the UI to reflect it.

I think I just need a little theoretical explanation with an example that 
spans multiple classes, to get me started, because at this point I'm not 
sure if I get the whole picture.

I can bind events and do stuff in the handlers if they are members of a 
single instance, but where I get confused a little is in the propagation 
between instances of different classes and where exactly my event 
handlers should be declared and bound  



On Thu, 01 Nov 2007 02:44:02 -0400, C M wrote:

> I don't understand what you still need--your code seems to have the
> basics of how
> to grab the calendar changing event and use GetDate() to get the
> selected date.
> For the function setDate, you'll just want to use that date however you
> want, right?
> (e.g. in a staticTextCtrl or whatever it might be). So what's the
> problem?
> 
> On 10/31/07, Patrick J. Anderson <pat.j.anderson at gmail.com> wrote:
>>
>> Hi, my background is in python web programming and I'm new to desktop
>> programming and wxPython.
>>
>> My question is about events and event handling, which I still don't
>> quite understand, as it seems rather complex.
>>
>> I have a Splitter Window and on the left side I have a CalendarCtrl and
>> the right side I have a day planner.
>>
>> By changing the selected date in the CalendarCtrl I'd like to change
>> the date for the planner on the right.
>>
>> How can I do this? How can I send the date to the instance of
>> DayPlanner and change its view to reflect the new date?
>>
>> Below is a sample code to illustrate my problem:
>>
>>
>> class PlannerPanel(wx.SplitterWindow):
>>     def __init__(self, *args, **kwds):
>>         wx.SplitterWindow.__init__(self, *args, **kwds)
>>
>>         hbox = wx.BoxSizer(wx.HORIZONTAL)
>>
>>         self.left_pane = LeftPane(self, wx.NewId()) self.right_pane =
>>         RightPane(self, wx.NewId())
>>
>>         self.SplitVertically(self.left_pane, self.right_pane)
>>         self.SetMinimumPaneSize(300)
>>
>>         hbox.Add(self, 1, wx.ALL|wx.EXPAND, 0) self.SetSizer(hbox)
>>         self.Layout()
>>
>>
>> class LeftPane(wx.Panel):
>>
>>     def __init__(self, *args, **kwargs):
>>         wx.Panel.__init__(self, *args, **kwargs)
>>
>>         vbox = wx.BoxSizer(wx.VERTICAL)
>>         calendar = MiniCalendar(self, wx.NewId(), wx.DateTime_Now())
>>         vbox.Add(calendar, 0, wx.ALL | wx.GROW, 1)
>>
>>         self.SetSizer(vbox)
>>         self.Layout()
>>
>>
>> class MiniCalendar(cal.CalendarCtrl):
>>
>>     def __init__(self, *args, **kwargs):
>>         cal.CalendarCtrl.__init__(self, *args, **kwargs)
>>
>>         self.Bind(cal.EVT_CALENDAR_SEL_CHANGED,
>>             self.OnCalSelChanged, id = self.GetId())
>>
>>     def OnCalSelChanged(self, event):
>>         cal = event.GetEventObject()
>>         w = wx.FindWindowByName('Day Planner') w.setDate(cal.GetDate())
>>         # print cal.GetDate()
>>
>>
>> class RightPane(wx.Panel):
>>
>>     def __init__(self, *args, **kwargs):
>>         wx.Panel.__init__(self, *args, **kwargs)
>>
>>         hbox = wx.BoxSizer(wx.HORIZONTAL)
>>
>>         nb = wx.Notebook(self, wx.NewId(),
>>                 style = wx.NB_BOTTOM |
>>                 wx.TAB_TRAVERSAL |
>>                 wx.SUNKEN_BORDER)
>>
>>         nb_pane_day         = DayPlanner(nb, wx.NewId())
>>         nb.AddPage(nb_pane_day, 'Day')
>>
>>         hbox.Add(nb, 1, wx.ALL | wx.GROW, 1)
>>
>>         self.SetSizer(hbox)
>>         self.Layout()
>>
>>
>> class DayPlanner(ScrolledPanel):
>>
>>     def __init__(self, *args, **kwargs):
>>         ScrolledPanel.__init__(self, *args, **kwargs)
>>
>>         self.date = datetime.today()
>>
>>         self.SetName('Day Planner')
>>
>>         self.fbox = wx.FlexGridSizer(0, 2, 1, 1)
>>         self.fbox.AddGrowableCol(1)
>>
>>         for i in range(1,24):
>>             self.fbox.AddGrowableRow(i)
>>
>>         self._createHeaders()
>>         self._createRows(h)
>>
>>         self.SetSizer(self.fbox)
>>         self.Layout()
>>         self.SetupScrolling()
>>
>>     ...
>>
>>     def setDate(self, date):
>>         self.date = date
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
>> For additional commands, e-mail:
>> wxPython-users-help at lists.wxwidgets.org





More information about the wxpython-users mailing list