From: Kevin A. <ka...@us...> - 2004-05-04 04:40:38
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21905/components Modified Files: calendar.py Log Message: switched to new style event binding and dispatch Index: calendar.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/calendar.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** calendar.py 1 May 2004 18:47:48 -0000 1.17 --- calendar.py 4 May 2004 04:40:20 -0000 1.18 *************** *** 9,21 **** from PythonCard import event, widget class CalendarSpec(widget.WidgetSpec): def __init__(self): ! events = [event.CalendarMouseDoubleClickEvent, ! event.CalendarChangedEvent, ! event.CalendarDayEvent, ! event.CalendarMonthEvent, ! event.CalendarYearEvent, ! event.CalendarWeekDayHeaderEvent] widget.WidgetSpec.__init__(self, 'Calendar', 'Widget', events, {} ) --- 9,66 ---- from PythonCard import event, widget + class CalendarEvent(event.Event): + def decorate(self, aWxEvent, source): + aWxEvent = event.Event.decorate(self, aWxEvent, source) + aWxEvent.date = aWxEvent.GetDate() + return aWxEvent + + class CalendarMouseDoubleClickEvent(CalendarEvent): + name = 'calendarMouseDoubleClick' + binding = calendar.EVT_CALENDAR + id = calendar.wxEVT_CALENDAR_DOUBLECLICKED + + class CalendarChangedEvent(CalendarEvent): + name = 'calendarChanged' + binding = calendar.EVT_CALENDAR_SEL_CHANGED + id = calendar.wxEVT_CALENDAR_SEL_CHANGED + + class CalendarDayEvent(CalendarEvent): + name = 'calendarDay' + binding = calendar.EVT_CALENDAR_DAY + id = calendar.wxEVT_CALENDAR_DAY_CHANGED + + class CalendarMonthEvent(CalendarEvent): + name = 'calendarMonth' + binding = calendar.EVT_CALENDAR_MONTH + id = calendar.wxEVT_CALENDAR_MONTH_CHANGED + + class CalendarYearEvent(CalendarEvent): + name = 'calendarYear' + binding = calendar.EVT_CALENDAR_YEAR + id = calendar.wxEVT_CALENDAR_YEAR_CHANGED + + class CalendarWeekDayHeaderEvent(event.Event): + name = 'calendarWeekDayHeader' + binding = calendar.EVT_CALENDAR_WEEKDAY_CLICKED + id = calendar.wxEVT_CALENDAR_WEEKDAY_CLICKED + + + CalendarEvents = (CalendarMouseDoubleClickEvent, + CalendarChangedEvent, + CalendarDayEvent, + CalendarMonthEvent, + CalendarYearEvent, + CalendarWeekDayHeaderEvent) + class CalendarSpec(widget.WidgetSpec): def __init__(self): ! ## events = [event.CalendarMouseDoubleClickEvent, ! ## event.CalendarChangedEvent, ! ## event.CalendarDayEvent, ! ## event.CalendarMonthEvent, ! ## event.CalendarYearEvent, ! ## event.CalendarWeekDayHeaderEvent] ! events = list(CalendarEvents) widget.WidgetSpec.__init__(self, 'Calendar', 'Widget', events, {} ) *************** *** 46,51 **** self.SetPosition((aResource.position[0], aResource.position[1])) ! adapter = CalendarEventBinding(self) ! adapter.bindEvents() # KEA 2002-07-09 --- 91,95 ---- self.SetPosition((aResource.position[0], aResource.position[1])) ! self._bindEvents(event.WIDGET_EVENTS + CalendarEvents) # KEA 2002-07-09 *************** *** 54,115 **** self.SetDate(wx.DateTime_Now()) - class CalendarEventBinding(event.DefaultEventBinding): - - def __init__(self, aComponent): - event.DefaultEventBinding.__init__(self, aComponent) - - def bindEvent(self, aEventClass): - parent = self._component._parent - id = self._component.GetId() - if aEventClass is event.CalendarMouseDoubleClickEvent: - calendar.EVT_CALENDAR(parent, id, self._dispatch) - elif aEventClass is event.CalendarChangedEvent: - calendar.EVT_CALENDAR_SEL_CHANGED(parent, id, self._dispatch) - elif aEventClass is event.CalendarDayEvent: - calendar.EVT_CALENDAR_DAY(parent, id, self._dispatch) - elif aEventClass is event.CalendarMonthEvent: - calendar.EVT_CALENDAR_MONTH(parent, id, self._dispatch) - elif aEventClass is event.CalendarYearEvent: - calendar.EVT_CALENDAR_YEAR(parent, id, self._dispatch) - elif aEventClass is event.CalendarWeekDayHeaderEvent: - calendar.EVT_CALENDAR_WEEKDAY_CLICKED(parent, id, self._dispatch) - - def _dispatch(self, aWxEvent): - component = self._component - - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch(self, aWxEvent): - return - - evt = None - - eventType = aWxEvent.GetEventType() - if eventType == calendar.wxEVT_CALENDAR_DOUBLECLICKED: - evt = self._createEvent(event.CalendarMouseDoubleClickEvent, aWxEvent) - elif eventType == calendar.wxEVT_CALENDAR_SEL_CHANGED: - evt = self._createEvent(event.CalendarChangedEvent, aWxEvent) - elif eventType == calendar.wxEVT_CALENDAR_DAY_CHANGED: - evt = self._createEvent(event.CalendarDayEvent, aWxEvent) - elif eventType == calendar.wxEVT_CALENDAR_MONTH_CHANGED: - evt = self._createEvent(event.CalendarMonthEvent, aWxEvent) - elif eventType == calendar.wxEVT_CALENDAR_YEAR_CHANGED: - evt = self._createEvent(event.CalendarYearEvent, aWxEvent) - elif eventType == calendar.wxEVT_CALENDAR_WEEKDAY_CLICKED: - evt = self._createEvent(event.CalendarWeekDayHeaderEvent, aWxEvent) - - if evt is not None: - component.notifyEventListeners(evt) - - - - # KEA 2001-12-09 - # the registry could contain a dictionary of the class, its EventBinding, spec, etc. - # some of those references could be class attributes instead - # it seems like the spec for the class should be part of the class itself - # RDS 2001-16-01 - # A new module, registry, contains the Registry class. A Component's - # class now contains it's spec, which contains meta data for it's events - # and attributes. Components register with the ComponentRegistry. import sys --- 98,101 ---- |