You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(45) |
May
(185) |
Jun
|
Jul
(36) |
Aug
(205) |
Sep
(98) |
Oct
(107) |
Nov
(6) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(1) |
Feb
(2) |
Mar
(19) |
Apr
(26) |
May
(18) |
Jun
|
Jul
(12) |
Aug
(16) |
Sep
(22) |
Oct
(7) |
Nov
(11) |
Dec
(74) |
2006 |
Jan
(14) |
Feb
(1) |
Mar
(3) |
Apr
(3) |
May
(14) |
Jun
(5) |
Jul
(20) |
Aug
(10) |
Sep
(1) |
Oct
|
Nov
(4) |
Dec
(1) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(14) |
Aug
|
Sep
|
Oct
(6) |
Nov
(1) |
Dec
|
From: Kevin A. <ka...@us...> - 2004-05-04 20:49:20
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18372/components Modified Files: bitmapcanvas.py iehtmlwindow.py Log Message: switched to new style event binding and dispatch Index: bitmapcanvas.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/bitmapcanvas.py,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** bitmapcanvas.py 2 May 2004 23:20:40 -0000 1.40 --- bitmapcanvas.py 4 May 2004 20:49:11 -0000 1.41 *************** *** 118,123 **** self._setForegroundColor((0,0,0)) # 'black' - #adapter = event.DefaultEventBinding(self) - #adapter.bindEvents() self._bindEvents(event.WIDGET_EVENTS) --- 118,121 ---- Index: iehtmlwindow.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/iehtmlwindow.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** iehtmlwindow.py 1 May 2004 18:47:49 -0000 1.14 --- iehtmlwindow.py 4 May 2004 20:49:11 -0000 1.15 *************** *** 8,12 **** if wx.Platform == '__WXMSW__': ! from wx import iewin else: # need a graceful exit --- 8,12 ---- if wx.Platform == '__WXMSW__': ! from wx.lib import iewin else: # need a graceful exit *************** *** 15,26 **** from PythonCard import event, log, widget class IEHtmlWindowSpec(widget.WidgetSpec): def __init__(self): self.name = 'IEHtmlWindow' self.parent = 'Widget' ! events = [event.IEHtmlTitleChangeEvent, ! event.IEHtmlStatusTextChangeEvent, ! event.IEHtmlDocumentCompleteEvent, ! ] attributes = { 'text' : { 'presence' : 'optional', 'default' : '' }, --- 15,58 ---- from PythonCard import event, log, widget + """ + # Hook up the event handlers for the IE window + self.Bind(iewin.EVT_BeforeNavigate2, self.OnBeforeNavigate2, self.ie) + self.Bind(iewin.EVT_NewWindow2, self.OnNewWindow2, self.ie) + self.Bind(iewin.EVT_DocumentComplete, self.OnDocumentComplete, self.ie) + ##self.Bind(iewin.EVT_ProgressChange, self.OnProgressChange, self.ie) + self.Bind(iewin.EVT_StatusTextChange, self.OnStatusTextChange, self.ie) + self.Bind(iewin.EVT_TitleChange, self.OnTitleChange, self.ie) + """ + + class IEHtmlTitleChangeEvent(event.Event): + name = 'titleChange' + binding = iewin.EVT_TitleChange + id = iewin.wxEVT_TitleChange + + class IEHtmlStatusTextChangeEvent(event.Event): + name = 'statusTextChange' + binding = iewin.EVT_StatusTextChange + id = iewin.wxEVT_StatusTextChange + + class IEHtmlDocumentCompleteEvent(event.Event): + name = 'documentComplete' + binding = iewin.EVT_DocumentComplete + id = iewin.wxEVT_DocumentComplete + + IEHtmlWindowEvents = ( + IEHtmlTitleChangeEvent, + IEHtmlStatusTextChangeEvent, + IEHtmlDocumentCompleteEvent, + ) + class IEHtmlWindowSpec(widget.WidgetSpec): def __init__(self): self.name = 'IEHtmlWindow' self.parent = 'Widget' ! events = list(IEHtmlWindowEvents) ! ## events = [event.IEHtmlTitleChangeEvent, ! ## event.IEHtmlStatusTextChangeEvent, ! ## event.IEHtmlDocumentCompleteEvent, ! ## ] attributes = { 'text' : { 'presence' : 'optional', 'default' : '' }, *************** *** 29,33 **** ! class IEHtmlWindow(widget.Widget, iewin.IEHtmlWin): """ An HTML window using the MS HTML control. --- 61,65 ---- ! class IEHtmlWindow(widget.Widget, iewin.IEHtmlWindow): """ An HTML window using the MS HTML control. *************** *** 37,41 **** def __init__(self, aParent, aResource): ! iewin.IEHtmlWin.__init__( self, aParent, --- 69,73 ---- def __init__(self, aParent, aResource): ! iewin.IEHtmlWindow.__init__( self, aParent, *************** *** 51,63 **** self._setText(aResource.text) ! # KEA 2003-01-03 ! # should this just go away with 2.3.4.2 and above ! # Refresh was renamed to RefreshPage in wxIEHtmlWin ! def Refresh(self, *_args): ! if _args: ! iewin.IEHtmlWin.Refresh(self, _args[0]) ! ! adapter = IEHtmlWindowEventBinding(self) ! adapter.bindEvents() def _getText(self) : --- 83,87 ---- self._setText(aResource.text) ! self._bindEvents(event.WIDGET_EVENTS + IEHtmlWindowEvents) def _getText(self) : *************** *** 74,113 **** text = property(_getText, _setText) ! class IEHtmlWindowEventBinding(event.DefaultEventBinding): ! """ ! Bind the Events supported by event.Button to wxPython. ! """ ! def __init__(self, aComponent): ! event.DefaultEventBinding.__init__(self, aComponent) ! ! def bindEvent(self, aEventClass): ! parent = self._component._parent ! if aEventClass is event.IEHtmlTitleChangeEvent: ! iewin.EVT_MSHTML_TITLECHANGE(parent, self._component.GetId(), self._dispatch) ! elif aEventClass is event.IEHtmlStatusTextChangeEvent: ! iewin.EVT_MSHTML_STATUSTEXTCHANGE(parent, self._component.GetId(), self._dispatch) ! elif aEventClass is event.IEHtmlDocumentCompleteEvent: ! iewin.EVT_MSHTML_DOCUMENTCOMPLETE(parent, self._component.GetId(), 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 ! if aWxEvent.GetEventType() == iewin.wxEVT_COMMAND_MSHTML_TITLECHANGE: ! evt = self._createEvent(event.IEHtmlTitleChangeEvent, aWxEvent) ! elif aWxEvent.GetEventType() == iewin.wxEVT_COMMAND_MSHTML_STATUSTEXTCHANGE: ! evt = self._createEvent(event.IEHtmlStatusTextChangeEvent, aWxEvent) ! elif aWxEvent.GetEventType() == iewin.wxEVT_COMMAND_MSHTML_DOCUMENTCOMPLETE: ! evt = self._createEvent(event.IEHtmlDocumentCompleteEvent, aWxEvent) ! if evt is not None: ! component.notifyEventListeners(evt) --- 98,223 ---- text = property(_getText, _setText) + # KEA 2004-05-02 + # this will probably end up in Scriptable or Component + # it should be completely generic + # the only problem part would be the reference to the parent (background) + # where the events are actually defined which would make this problematic + # for a compound component or events bound to a Panel + # what we really want is a reference to the application instance + # there is probably some method to give us that in wxWidgets + # UPDATE - I think GetTopLevelParent is what I was looking for + def _bindEvents(self, eventList): + # shouldn't components be subclasses of Scriptable? + # components would have their own handlers but when + # looking for a handler match it will search the parents + # for now just grab handlers from the background + + # the references below would be self.findHandler instead of + # background.findHandler + + #background = self.GetParent().GetParent() + background = wx.GetTopLevelParent(self) ! # where should this check go? ! # should we just set a "global" in the app instance such as ! # self.stack.app.bindUnusedEvents ! # this kind of thing isn't going to work for Rowland's compound ! # components ! if wx.GetApp()._showDebugMenu: ! bindUnusedEvents = True ! else: ! bindUnusedEvents = False ! ! # helper variable to simplify test for whether to bind InsteadOfTypeEvents ! # there is a good chance we will need to know ! # which events are bound, if we want to dynamically add or remove ! # events later, so go ahead and keep a reference to the list ! self.boundEvents = {} ! ! self.eventIdToHandler = {} ! self.wxEventIdMap = {} ! if 0: ! print "\nBINDING...", self.name ! for eventClass in eventList: ! #for eventClass in ButtonEvents: ! # need to figure out a way to avoid the need ! # for this id to class mapping which is used in _dispatch below ! self.wxEventIdMap[eventClass.id] = eventClass ! # command handler overrides normal mouseClick or select handler ! # so dispatch will automatically dispatch to the command handler ! # by looking up the handler this way ! # it also means that if there is a command association with this component ! # then the regular mouseClick or select handler will never be bound, just ignored ! if issubclass(eventClass, event.CommandTypeEvent) and self.command: ! handler = background.findHandler('on_' + self.command + '_command') ! if not handler: ! handler = background.findHandler('on_' + self.name + '_' + eventClass.name) ! else: ! handler = background.findHandler('on_' + self.name + '_' + eventClass.name) ! if not handler: ! handler = background.findHandler('on_' + eventClass.name) ! if handler or bindUnusedEvents: ! # only bind events that have an event handler ! # in this scenario unused events are never bound ! # which is more efficient, but the Message Watcher needs ! # to be changed ! # alternatively we can bind everything and then in _dispatch ! # if there isn't a match in eventIdToHandler then we know ! # the event isn't used and we can set used to False ! # the complication would be that we probably have to have to ! # always call Skip() which may or may not be a hassle with components ! ! # this doesn't bind command events ! # they would be of the form on_somename_command ! # or perhaps on_command but I don't think we would want ! # to support that ! # the event binding would be specific to a component ! # since on dispatch command overrides something like mouseClickEvent ! # but the name of the command is not related to the component ! # need to look at whether self.command has a value and then bind ! # with ButtonMouseClickEvent.binding if that isn't already bound ! # then in dispatch have to check again I think ! ! # need to avoid double binding ! # also binding shouldn't be order-specific ! # so how to avoid binding mouseDrag to _dispatch ! # if mouseMove is already bound or if binding mouseMove ! # not rebinding if mouseDrag is already bound ! # perhaps MouseDragEvent keeps a reference to MouseMoveEvent ! # and that is inserted into boundEvents, then we check boundEvents ! # prior to rebinding? ! if not self.boundEvents.get(eventClass.binding, None): ! background.Bind(eventClass.binding, self._dispatch, self) ! self.boundEvents[eventClass.binding] = eventClass.name ! if handler: ! if 0: ! print " binding", self.name, eventClass.name, handler._name, eventClass.id ! # KEA 2004-05-02 ! # change to just using the method directly, Handler class not needed ! # actually the Handler class isn't needed at all ! # so if the initial list built to simplify findHandler ! # just stores a reference to the method that would be fine ! # as long as the whole system uses that ! # the only reason we don't just build the list ourselves ! # in _bindEvents is that every component needs to do findHandler ! # so it is more efficient to do once when the Scriptable object ! # is created than to reparse for each component ! #self.eventIdToHandler[eventClass.id] = handler ! self.eventIdToHandler[eventClass.id] = handler.getFunction() ! if 0: ! print "\n boundEvents:" ! for name in self.boundEvents.values(): ! print " ", name ! print "\n\n" ! print "\n self.eventIdToHandler:" ! for id in self.eventIdToHandler: ! # KEA 2004-05-02 ! # change to just using the method directly, Handler class not needed ! #print " ", id, self.eventIdToHandler[id]._function ! print " ", id, self.eventIdToHandler[id] ! print "\n\n" |
From: Kevin A. <ka...@us...> - 2004-05-04 20:40:48
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16423 Modified Files: debug.py Log Message: message watcher now removes itself as a listener when it is destroyed Index: debug.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/debug.py,v retrieving revision 1.127 retrieving revision 1.128 diff -C2 -d -r1.127 -r1.128 *** debug.py 1 May 2004 18:47:50 -0000 1.127 --- debug.py 4 May 2004 20:40:39 -0000 1.128 *************** *** 78,81 **** --- 78,82 ---- self.parentApp = parentApp wx.EVT_CLOSE(self, self.onCloseMe) + wx.EVT_WINDOW_DESTROY(self, self.onDestroyMe) sizer1 = wx.BoxSizer(wx.VERTICAL) sizer2 = wx.BoxSizer(wx.HORIZONTAL) *************** *** 178,181 **** --- 179,192 ---- self.Hide() + def onDestroyMe(self, evt): + # KEA 2004-05-04 + # if we're in the midst of a shutdown + # then the Message Watcher needs to be removed from the + # event listeners so that we don't end up trying to access + # a dead object + event.EventQueue().removeListener( self ) + event.EventLog.getInstance().removeEventListener( self ) + evt.Skip() + position = property(wx.Frame.GetPositionTuple, wx.Frame.SetPosition) size = property(wx.Frame.GetSizeTuple, wx.Frame.SetSize) |
From: Kevin A. <ka...@us...> - 2004-05-04 17:16:19
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4638 Modified Files: event.py Log Message: switched to new style event binding and dispatch Index: event.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/event.py,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** event.py 3 May 2004 02:56:33 -0000 1.65 --- event.py 4 May 2004 17:15:41 -0000 1.66 *************** *** 480,483 **** --- 480,485 ---- class TextEnterEvent( Event ) : name = 'textEnter' + binding = wx.EVT_TEXT_ENTER + id = wx.wxEVT_COMMAND_TEXT_ENTER |
From: Kevin A. <ka...@us...> - 2004-05-04 17:15:51
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4638/components Modified Files: button.py checkbox.py choice.py combobox.py gauge.py grid.py htmlwindow.py image.py list.py radiogroup.py slider.py spinner.py staticbox.py staticline.py statictext.py Log Message: switched to new style event binding and dispatch Index: spinner.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/spinner.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** spinner.py 1 May 2004 18:47:48 -0000 1.15 --- spinner.py 4 May 2004 17:15:42 -0000 1.16 *************** *** 8,21 **** from PythonCard import event, widget class SpinnerSpec(widget.WidgetSpec): def __init__(self): ! events = [event.KeyPressEvent, ! event.KeyDownEvent, ! event.KeyUpEvent, ! event.TextEnterEvent, ! event.TextUpdateEvent, ! #event.SpinUpEvent, ! #event.SpinDownEvent ! ] attributes = { 'min' : { 'presence' : 'optional', 'default' : 0 }, --- 8,33 ---- from PythonCard import event, widget + # KEA 2004-05-04 + # dropped TextEnterEvent since I'm not sure it is needed + # use keyPress handler instead + SpinnerEvents = ( + event.KeyPressEvent, + event.KeyDownEvent, + event.KeyUpEvent, + #event.TextEnterEvent, + event.TextUpdateEvent, + ) + class SpinnerSpec(widget.WidgetSpec): def __init__(self): ! events = list(SpinnerEvents) ! ## events = [event.KeyPressEvent, ! ## event.KeyDownEvent, ! ## event.KeyUpEvent, ! ## event.TextEnterEvent, ! ## event.TextUpdateEvent, ! ## #event.SpinUpEvent, ! ## #event.SpinDownEvent ! ## ] attributes = { 'min' : { 'presence' : 'optional', 'default' : 0 }, *************** *** 51,79 **** widget.Widget.__init__( self, aParent, aResource ) ! adapter = SpinnerEventBinding(self) ! adapter.bindEvents() def setRange( self, aMin, aMax ) : self.SetRange( aMin, aMax ) - """ - def _getValue( self ) : - return self.GetValue() - - def _setValue( self, aValue ) : - self.SetValue( aValue ) - - def _getMin( self ) : - return self.GetMin() - """ - def _setMin( self, aMin ) : self.SetRange( aMin, self.GetMax() ) - """ - def _getMax( self ) : - return self.GetMax() - """ - def _setMax( self, aMax ) : self.SetRange( self.GetMin(), aMax ) --- 63,74 ---- widget.Widget.__init__( self, aParent, aResource ) ! self._bindEvents(event.WIDGET_EVENTS + SpinnerEvents) def setRange( self, aMin, aMax ) : self.SetRange( aMin, aMax ) def _setMin( self, aMin ) : self.SetRange( aMin, self.GetMax() ) def _setMax( self, aMax ) : self.SetRange( self.GetMin(), aMax ) *************** *** 84,155 **** - class SpinnerEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.Spinner to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - - def bindEvent( self, aEventClass ) : - parent = self._component._parent - - if aEventClass is event.KeyDownEvent : - wx.EVT_KEY_DOWN( self._component, self._dispatch ) - elif aEventClass is event.KeyUpEvent : - wx.EVT_KEY_UP( self._component, self._dispatch ) - elif aEventClass is event.KeyPressEvent : - wx.EVT_CHAR( self._component, self._dispatch ) - elif aEventClass is event.TextUpdateEvent : - #wx.EVT_SPINCTRL( parent, self._component.GetId(), self._dispatch ) - wx.EVT_TEXT( parent, self._component.GetId(), self._dispatch ) - elif aEventClass is event.TextEnterEvent : - wx.EVT_TEXT_ENTER( parent, self._component.GetId(), self._dispatch ) - """ - elif aEventClass is event.SpinUpEvent : - wx.EVT_SPIN_UP(parent, self._component.GetId(), self._dispatch) - elif aEventClass is event.SpinDownEvent : - wx.EVT_SPIN_DOWN(parent, self._component.GetId(), self._dispatch) - """ - - - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_KEY_DOWN : - evt = self._createEvent( event.KeyDownEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_KEY_UP : - evt = self._createEvent( event.KeyUpEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_CHAR : - evt = self._createEvent( event.KeyPressEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TEXT_ENTER : - evt = self._createEvent( event.TextEnterEvent, aWxEvent ) - """ - if aWxEvent.GetEventType() == wx.wxEVT_SCROLL_LINEUP: - evt = self._createEvent(event.SpinUpEvent, aWxEvent) - if aWxEvent.GetEventType() == wx.wxEVT_SCROLL_LINEDOWN: - evt = self._createEvent(event.SpinDownEvent, aWxEvent) - """ - #if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_SPINCTRL_UPDATED: - # evt = self._createEvent( event.TextUpdateEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TEXT_UPDATED: - component = self._component - if component._getCommand() is not None: - evt = event.CommandEvent(component._getCommand(), component) - evt.setNativeEvent(aWxEvent) - else: - evt = self._createEvent(event.TextUpdateEvent, aWxEvent) - - if evt is not None : - self._component.notifyEventListeners(evt) - #if not evt.getUsed(): - # aWxEvent.Skip() - - import sys from PythonCard import registry --- 79,82 ---- Index: grid.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/grid.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** grid.py 20 Apr 2004 20:54:39 -0000 1.8 --- grid.py 4 May 2004 17:15:42 -0000 1.9 *************** *** 50,55 **** widget.Widget.__init__(self, aParent, aResource) ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() --- 50,54 ---- widget.Widget.__init__(self, aParent, aResource) ! self._bindEvents(event.WIDGET_EVENTS) Index: slider.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/slider.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** slider.py 1 May 2004 18:47:48 -0000 1.17 --- slider.py 4 May 2004 17:15:42 -0000 1.18 *************** *** 8,14 **** from PythonCard import event, widget class SliderSpec(widget.WidgetSpec): def __init__(self): ! events = [event.SelectEvent] attributes = { 'layout' : { 'presence' : 'optional', 'default' : 'horizontal', 'values' : [ 'horizontal', 'vertical' ] }, --- 8,21 ---- from PythonCard import event, widget + class SliderSelectEvent(event.SelectEvent): + binding = wx.EVT_SLIDER + id = wx.wxEVT_COMMAND_SLIDER_UPDATED + + SliderEvents = (SliderSelectEvent,) + class SliderSpec(widget.WidgetSpec): def __init__(self): ! events = list(SliderEvents) ! ## events = [event.SelectEvent] attributes = { 'layout' : { 'presence' : 'optional', 'default' : 'horizontal', 'values' : [ 'horizontal', 'vertical' ] }, *************** *** 44,49 **** self._layout = aResource.layout ! adapter = SliderEventBinding(self) ! adapter.bindEvents() def __getLayout( self, aString ) : --- 51,55 ---- self._layout = aResource.layout ! self._bindEvents(event.WIDGET_EVENTS + SliderEvents) def __getLayout( self, aString ) : *************** *** 58,80 **** self.SetRange( aMin, aMax ) - """ - def _getValue( self ) : - return self.GetValue() - - def _setValue( self, aValue ) : - self.SetValue( aValue ) - - def _getMin( self ) : - return self.GetMin() - """ - def _setMin( self, aMin ) : self.SetRange( aMin, self.GetMax() ) - """ - def _getMax( self ) : - return self.GetMax() - """ - def _setMax( self, aMax ) : self.SetRange( self.GetMin(), aMax ) --- 64,70 ---- *************** *** 92,129 **** - class SliderEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.Slider to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - - def bindEvent( self, aEventClass ) : - parent = self._component._parent - - if aEventClass is event.SelectEvent : - wx.EVT_SLIDER( parent, self._component.GetId(), self._dispatch ) - - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - component = self._component - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_SLIDER_UPDATED: - if component._getCommand() is not None: - evt = event.CommandEvent(component._getCommand(), component) - evt.setNativeEvent(aWxEvent) - else: - evt = self._createEvent(event.SelectEvent, aWxEvent) - - if evt is not None : - self._component.notifyEventListeners( evt ) - - import sys from PythonCard import registry --- 82,85 ---- Index: gauge.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/gauge.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** gauge.py 21 Apr 2004 03:45:00 -0000 1.11 --- gauge.py 4 May 2004 17:15:42 -0000 1.12 *************** *** 44,49 **** self._layout = aResource.layout ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() def __getLayout( self, aString ) : --- 44,48 ---- self._layout = aResource.layout ! self._bindEvents(event.WIDGET_EVENTS) def __getLayout( self, aString ) : Index: checkbox.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/checkbox.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** checkbox.py 1 May 2004 18:47:49 -0000 1.17 --- checkbox.py 4 May 2004 17:15:42 -0000 1.18 *************** *** 8,14 **** from PythonCard import event, widget class CheckBoxSpec(widget.WidgetSpec): def __init__(self): ! events = [event.MouseClickEvent ] attributes = { 'label' : { 'presence' : 'mandatory' }, --- 8,21 ---- from PythonCard import event, widget + class CheckBoxMouseClickEvent(event.MouseClickEvent): + binding = wx.EVT_CHECKBOX + id = wx.wxEVT_COMMAND_CHECKBOX_CLICKED + + CheckBoxEvents = (CheckBoxMouseClickEvent,) + class CheckBoxSpec(widget.WidgetSpec): def __init__(self): ! ## events = [event.MouseClickEvent ] ! events = list(CheckBoxEvents) attributes = { 'label' : { 'presence' : 'mandatory' }, *************** *** 16,19 **** --- 23,27 ---- widget.WidgetSpec.__init__(self, 'CheckBox', 'Widget', events, attributes ) + class CheckBox(widget.Widget, wx.CheckBox): """ *************** *** 40,45 **** self.SetValue(True) ! adapter = CheckBoxEventBinding(self) ! adapter.bindEvents() checked = property(wx.CheckBox.GetValue, wx.CheckBox.SetValue) --- 48,52 ---- self.SetValue(True) ! self._bindEvents(event.WIDGET_EVENTS + CheckBoxEvents) checked = property(wx.CheckBox.GetValue, wx.CheckBox.SetValue) *************** *** 47,79 **** - class CheckBoxEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.CheckBox to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - def bindEvent( self, aEventClass ) : - parent = self._component._parent - - if aEventClass is event.MouseClickEvent : - wx.EVT_CHECKBOX( parent, self._component.GetId(), self._dispatch ) - - def _dispatch( self, aWxEvent ) : - - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_CHECKBOX_CLICKED : - evt = self._createEvent( event.MouseClickEvent, aWxEvent ) - - if evt is not None : - self._component.notifyEventListeners( evt ) - - import sys from PythonCard import registry --- 54,57 ---- Index: staticline.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/staticline.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** staticline.py 21 Apr 2004 03:45:00 -0000 1.11 --- staticline.py 4 May 2004 17:15:42 -0000 1.12 *************** *** 41,46 **** self._layout = aResource.layout ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() def __getLayout( self, aString ) : --- 41,45 ---- self._layout = aResource.layout ! self._bindEvents(event.WIDGET_EVENTS) def __getLayout( self, aString ) : *************** *** 52,58 **** raise 'invalid StaticLine.layout value: ', aString - #def _bindEvents( self ) : - # pass - #def _setHelpText( self, aString ) : # pass --- 51,54 ---- Index: radiogroup.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/radiogroup.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** radiogroup.py 1 May 2004 18:47:48 -0000 1.23 --- radiogroup.py 4 May 2004 17:15:42 -0000 1.24 *************** *** 9,15 **** from list import ContainerMixin class RadioGroupSpec(widget.WidgetSpec): def __init__(self): ! events = [event.SelectEvent] attributes = { 'label' : { 'presence' : 'optional', 'default' : '' }, --- 9,22 ---- from list import ContainerMixin + class RadioGroupSelectEvent(event.SelectEvent): + binding = wx.EVT_RADIOBOX + id = wx.wxEVT_COMMAND_RADIOBOX_SELECTED + + RadioGroupEvents = (RadioGroupSelectEvent,) + class RadioGroupSpec(widget.WidgetSpec): def __init__(self): ! events = list(RadioGroupEvents) ! ## events = [event.SelectEvent] attributes = { 'label' : { 'presence' : 'optional', 'default' : '' }, *************** *** 54,59 **** self._setStringSelection(aResource.stringSelection) ! adapter = RadioGroupEventBinding(self) ! adapter.bindEvents() def __getLayout(self, aString): --- 61,65 ---- self._setStringSelection(aResource.stringSelection) ! self._bindEvents(event.WIDGET_EVENTS + RadioGroupEvents) def __getLayout(self, aString): *************** *** 93,124 **** - class RadioGroupEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.RadioGroup to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - def bindEvent( self, aEventClass ) : - parent = self._component._parent - - if aEventClass is event.SelectEvent : - wx.EVT_RADIOBOX( parent, self._component.GetId(), self._dispatch ) - - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_RADIOBOX_SELECTED : - evt = self._createEvent( event.SelectEvent, aWxEvent ) - - if evt is not None : - self._component.notifyEventListeners( evt ) - - import sys from PythonCard import registry --- 99,102 ---- Index: list.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/list.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** list.py 4 May 2004 05:15:17 -0000 1.24 --- list.py 4 May 2004 17:15:42 -0000 1.25 *************** *** 29,45 **** ! class ListEvent(event.Event, event.CommandTypeEvent): ! def decorate(self, aWxEvent, source): ! aWxEvent = event.Event.decorate(self, aWxEvent, source) ! aWxEvent.selection = aWxEvent.GetSelection() ! aWxEvent.stringSelection = aWxEvent.GetString() ! return aWxEvent ! ! class ListSelectEvent(ListEvent): name = 'select' binding = wx.EVT_LISTBOX id = wx.wxEVT_COMMAND_LISTBOX_SELECTED ! class ListMouseDoubleClickEvent(ListEvent): name = 'mouseDoubleClick' binding = wx.EVT_LISTBOX_DCLICK --- 29,39 ---- ! class ListSelectEvent(event.SelectEvent): name = 'select' binding = wx.EVT_LISTBOX id = wx.wxEVT_COMMAND_LISTBOX_SELECTED ! # can only have one CommandTypeEvent per component ! class ListMouseDoubleClickEvent(event.Event): name = 'mouseDoubleClick' binding = wx.EVT_LISTBOX_DCLICK Index: combobox.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/combobox.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** combobox.py 1 May 2004 18:47:48 -0000 1.25 --- combobox.py 4 May 2004 17:15:42 -0000 1.26 *************** *** 11,22 **** from list import ContainerMixin class ComboBoxSpec(widget.WidgetSpec): ! def __init__(self): ! events = [event.SelectEvent, ! event.KeyPressEvent, ! event.KeyDownEvent, ! event.KeyUpEvent, ! event.TextEnterEvent, ! event.TextUpdateEvent] attributes = { 'text' : { 'presence' : 'optional', 'default' : '' }, --- 11,39 ---- from list import ContainerMixin + class ComboBoxSelectEvent(event.SelectEvent): + binding = wx.EVT_COMBOBOX + id = wx.wxEVT_COMMAND_COMBOBOX_SELECTED + + # KEA 2004-05-04 + # dropped TextEnterEvent since I'm not sure it is needed + # use keyPress handler instead + ComboBoxEvents = ( + event.KeyPressEvent, + event.KeyDownEvent, + event.KeyUpEvent, + #event.TextEnterEvent, + event.TextUpdateEvent, + ComboBoxSelectEvent + ) + class ComboBoxSpec(widget.WidgetSpec): ! def __init__(self): ! events = list(ComboBoxEvents) ! ## events = [event.SelectEvent, ! ## event.KeyPressEvent, ! ## event.KeyDownEvent, ! ## event.KeyUpEvent, ! ## event.TextEnterEvent, ! ## event.TextUpdateEvent] attributes = { 'text' : { 'presence' : 'optional', 'default' : '' }, *************** *** 26,29 **** --- 43,47 ---- widget.WidgetSpec.__init__(self, 'ComboBox', 'Widget', events, attributes) + class ComboBox(widget.Widget, wx.ComboBox, ContainerMixin): """ *************** *** 42,46 **** aResource.size, aResource.items, ! style = wx.CB_DROPDOWN | wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_SIBLINGS, name = aResource.name ) --- 60,64 ---- aResource.size, aResource.items, ! style = wx.CB_DROPDOWN | wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_SIBLINGS, name = aResource.name ) *************** *** 55,60 **** self.SetValue(aResource.text) ! adapter = ComboBoxEventBinding(self) ! adapter.bindEvents() def _getItems(self): --- 73,77 ---- self.SetValue(aResource.text) ! self._bindEvents(event.WIDGET_EVENTS + ComboBoxEvents) def _getItems(self): *************** *** 85,138 **** - class ComboBoxEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.ComboBox to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - def bindEvent( self, aEventClass ) : - parent = self._component._parent - - if aEventClass is event.KeyDownEvent : - wx.EVT_KEY_DOWN( self._component, self._dispatch ) - elif aEventClass is event.KeyUpEvent : - wx.EVT_KEY_UP( self._component, self._dispatch ) - elif aEventClass is event.KeyPressEvent : - wx.EVT_CHAR( self._component, self._dispatch ) - elif aEventClass is event.TextEnterEvent : - wx.EVT_TEXT_ENTER( parent, self._component.GetId(), self._dispatch ) - elif aEventClass is event.TextUpdateEvent : - wx.EVT_TEXT( parent, self._component.GetId(), self._dispatch ) - elif aEventClass is event.SelectEvent : - wx.EVT_COMBOBOX( parent, self._component.GetId(), self._dispatch ) - - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_KEY_DOWN : - evt = self._createEvent( event.KeyDownEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_KEY_UP : - evt = self._createEvent( event.KeyUpEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_CHAR : - evt = self._createEvent( event.KeyPressEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TEXT_ENTER : - evt = self._createEvent( event.TextEnterEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TEXT_UPDATED : - evt = self._createEvent( event.TextUpdateEvent, aWxEvent ) - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_COMBOBOX_SELECTED : - evt = self._createEvent( event.SelectEvent, aWxEvent ) - - if evt is not None : - self._component.notifyEventListeners( evt ) - if not evt.getUsed(): - aWxEvent.Skip() - - import sys from PythonCard import registry --- 102,105 ---- Index: htmlwindow.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/htmlwindow.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** htmlwindow.py 21 Apr 2004 03:45:00 -0000 1.15 --- htmlwindow.py 4 May 2004 17:15:42 -0000 1.16 *************** *** 42,47 **** self._setText(aResource.text) ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() def setAddressField(self, field): --- 42,46 ---- self._setText(aResource.text) ! self._bindEvents(event.WIDGET_EVENTS) def setAddressField(self, field): Index: staticbox.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/staticbox.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** staticbox.py 21 Apr 2004 03:45:00 -0000 1.10 --- staticbox.py 4 May 2004 17:15:42 -0000 1.11 *************** *** 39,44 **** widget.Widget.__init__( self, aParent, aResource ) ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() """ --- 39,43 ---- widget.Widget.__init__( self, aParent, aResource ) ! self._bindEvents(event.WIDGET_EVENTS) """ Index: button.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/button.py,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** button.py 2 May 2004 19:49:57 -0000 1.29 --- button.py 4 May 2004 17:15:41 -0000 1.30 *************** *** 53,58 **** self._setDefault(self._resource.default) - #adapter = ButtonEventBinding(self) - #adapter.bindEvents() self._bindEvents(event.WIDGET_EVENTS + ButtonEvents) --- 53,56 ---- *************** *** 84,150 **** default = property(_getDefault, _setDefault) label = property(wx.Button.GetLabel, wx.Button.SetLabel) - - - class ButtonEventBinding(event.DefaultEventBinding): - """ - Bind the Events supported by event.Button to wxPython. - """ - def __init__(self, aComponent): - event.DefaultEventBinding.__init__(self, aComponent) - - def bindEvent(self, aEventClass): - parent = self._component._parent - # KEA 2004-04-26 - # test to use new event classes - if aEventClass is event.ButtonMouseClickEvent: - event.ButtonMouseClickEvent.bindFunction(parent, self._component.GetId(), self._dispatch) - - ## if aEventClass is event.MouseClickEvent: - ## wx.EVT_BUTTON(parent, self._component.GetId(), 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 - - # KEA 2004-04-26 - # test to use new event classes - # this is a generic loop which because there is only - # one event class in ButtonEvents is a little long-winded - # as soon as we find a match we break out of the loop - # if ButtonEvents was called ComponentSpecificEvents - # or something generic then maybe this loop would be the same for - # all components? - # if we had a mapping of ids to event classes - # then you could just use a try/except block and get the class - # directly from the ButtonEvents list - # eventClass = ButtonEvents[indexToClassMapping(eventType)] - eventType = aWxEvent.GetEventType() - for eventClass in ButtonEvents: - if eventType == eventClass.id: - if eventClass.command: - if component._getCommand() is not None: - evt = event.CommandEvent(component._getCommand(), component) - evt.setNativeEvent(aWxEvent) - else: - evt = self._createEvent(eventClass, aWxEvent) - else: - evt = self._createEvent(eventClass, aWxEvent) - break - ## if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_BUTTON_CLICKED: - ## if component._getCommand() is not None: - ## evt = event.CommandEvent(component._getCommand(), component) - ## evt.setNativeEvent(aWxEvent) - ## else: - ## evt = self._createEvent(event.MouseClickEvent, aWxEvent) - - if evt is not None: - component.notifyEventListeners(evt) - --- 82,85 ---- Index: statictext.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/statictext.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** statictext.py 27 Apr 2004 18:14:38 -0000 1.15 --- statictext.py 4 May 2004 17:15:42 -0000 1.16 *************** *** 41,46 **** self._alignment = aResource.alignment ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() def __getAlignment( self, aString ) : --- 41,45 ---- self._alignment = aResource.alignment ! self._bindEvents(event.WIDGET_EVENTS) def __getAlignment( self, aString ) : Index: image.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/image.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** image.py 2 May 2004 23:20:40 -0000 1.19 --- image.py 4 May 2004 17:15:42 -0000 1.20 *************** *** 63,68 **** wx.EVT_WINDOW_DESTROY(self, self._OnDestroy) - #adapter = event.DefaultEventBinding(self) - #adapter.bindEvents() self._bindEvents(event.WIDGET_EVENTS) --- 63,66 ---- Index: choice.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/choice.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** choice.py 1 May 2004 18:47:48 -0000 1.18 --- choice.py 4 May 2004 17:15:42 -0000 1.19 *************** *** 9,15 **** from list import ContainerMixin class ChoiceSpec(widget.WidgetSpec): def __init__(self): ! events = [ event.SelectEvent ] attributes = { 'items' : { 'presence' : 'optional', 'default' : [] }, --- 9,22 ---- from list import ContainerMixin + class ChoiceSelectEvent(event.SelectEvent): + binding = wx.EVT_CHOICE + id = wx.wxEVT_COMMAND_CHOICE_SELECTED + + ChoiceEvents = (ChoiceSelectEvent,) + class ChoiceSpec(widget.WidgetSpec): def __init__(self): ! events = list(ChoiceEvents) ! ## events = [ event.SelectEvent ] attributes = { 'items' : { 'presence' : 'optional', 'default' : [] }, *************** *** 17,20 **** --- 24,28 ---- widget.WidgetSpec.__init__(self, 'Choice', 'Widget', events, attributes ) + class Choice(widget.Widget, wx.Choice, ContainerMixin): """ *************** *** 41,46 **** self._setStringSelection(aResource.stringSelection) ! adapter = ChoiceEventBinding(self) ! adapter.bindEvents() def _getItems(self): --- 49,53 ---- self._setStringSelection(aResource.stringSelection) ! self._bindEvents(event.WIDGET_EVENTS + ChoiceEvents) def _getItems(self): *************** *** 63,93 **** - class ChoiceEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.Choice to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - def bindEvent( self, aEventClass ) : - parent = self._component._parent - - if aEventClass is event.SelectEvent : - wx.EVT_CHOICE( parent, self._component.GetId(), self._dispatch ) - - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_CHOICE_SELECTED : - evt = self._createEvent( event.SelectEvent, aWxEvent ) - - if evt is not None : - self._component.notifyEventListeners( evt ) - import sys from PythonCard import registry --- 70,73 ---- |
From: Kevin A. <ka...@us...> - 2004-05-04 05:15:25
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28623/components Modified Files: list.py Log Message: switched to new style event binding and dispatch Index: list.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/list.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** list.py 1 May 2004 18:47:48 -0000 1.23 --- list.py 4 May 2004 05:15:17 -0000 1.24 *************** *** 29,35 **** class ListSpec(widget.WidgetSpec): def __init__(self): ! events = [event.SelectEvent] attributes = { 'items' : { 'presence' : 'optional', 'default' : [] }, --- 29,59 ---- + class ListEvent(event.Event, event.CommandTypeEvent): + def decorate(self, aWxEvent, source): + aWxEvent = event.Event.decorate(self, aWxEvent, source) + aWxEvent.selection = aWxEvent.GetSelection() + aWxEvent.stringSelection = aWxEvent.GetString() + return aWxEvent + + class ListSelectEvent(ListEvent): + name = 'select' + binding = wx.EVT_LISTBOX + id = wx.wxEVT_COMMAND_LISTBOX_SELECTED + + class ListMouseDoubleClickEvent(ListEvent): + name = 'mouseDoubleClick' + binding = wx.EVT_LISTBOX_DCLICK + id = wx.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED + + ListEvents = (ListSelectEvent, ListMouseDoubleClickEvent) + + class ListSpec(widget.WidgetSpec): def __init__(self): ! ## events = [event.SelectEvent] ! # KEA 2004-05-03 ! # how do we cleanly remove the MouseDoubleClickEvent ! # which the subclass is automatically going to add? ! events = list(ListEvents) attributes = { 'items' : { 'presence' : 'optional', 'default' : [] }, *************** *** 62,68 **** if aResource.stringSelection: self._setStringSelection(aResource.stringSelection) ! ! adapter = ListEventBinding(self) ! adapter.bindEvents() def _getItems(self): --- 86,95 ---- if aResource.stringSelection: self._setStringSelection(aResource.stringSelection) ! ! # need to remove MouseDoubleClickEvent ! # since ListMouseDoubleClickEvent is used instead ! temp = list(event.WIDGET_EVENTS + ListEvents) ! temp.remove(event.MouseDoubleClickEvent) ! self._bindEvents(tuple(temp)) def _getItems(self): *************** *** 123,166 **** - class ListEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.List to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__( self, aComponent ) - - """ - Bind an Event class that is supported by this objects peer Widget. - """ - def bindEvent( self, aEventClass ) : - parent = self._component._parent - id = self._component.GetId() - if aEventClass is event.SelectEvent : - wx.EVT_LISTBOX( parent, id, self._dispatch ) - - if aEventClass is event.MouseDoubleClickEvent : - wx.EVT_LISTBOX_DCLICK( parent, id, self._dispatch ) - """ - Intercept all wxPyton events, convert them to PythonCard events, and - post them to the EventQueue. - """ - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch( self, aWxEvent ) : - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LISTBOX_SELECTED : - evt = self._createEvent( event.SelectEvent, aWxEvent ) - - elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED : - evt = self._createEvent( event.MouseDoubleClickEvent, aWxEvent ) - - if evt is not None : - self._component.notifyEventListeners( evt ) - - import sys from PythonCard import registry --- 150,153 ---- |
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 ---- |
From: Kevin A. <ka...@us...> - 2004-05-04 04:24:17
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19275/components Modified Files: multicolumnlist.py Log Message: switched to new style event binding and dispatch Index: multicolumnlist.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/multicolumnlist.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** multicolumnlist.py 1 May 2004 18:47:48 -0000 1.24 --- multicolumnlist.py 4 May 2004 04:24:09 -0000 1.25 *************** *** 7,26 **** import wx from wx.lib.mixins.listctrl import ColumnSorterMixin, ListCtrlAutoWidthMixin - - # KEA 2003-09-04 - # workaround typo bug in wxPython 2.4.1.2 controls2.py - #from wxPython.wx import controls2c - from types import TupleType, ListType, StringType, NoneType, IntType from PythonCard import event, widget class MultiColumnListSpec(widget.WidgetSpec): def __init__(self): ! events =[event.SelectEvent, ! event.ItemActivatedEvent, ! event.ItemFocusedEvent, ! event.MouseContextClickEvent, ! event.ListColumnClickEvent, ! event.KeyDownEvent] attributes ={ 'items' : { 'presence' : 'optional', 'default' : [] }, --- 7,72 ---- import wx from wx.lib.mixins.listctrl import ColumnSorterMixin, ListCtrlAutoWidthMixin from types import TupleType, ListType, StringType, NoneType, IntType from PythonCard import event, widget + class MultiColumnListEvent(event.Event): + def decorate(self, aWxEvent, source): + aWxEvent = event.Event.decorate(self, aWxEvent, source) + aWxEvent.item = aWxEvent.GetItem() + return aWxEvent + + class MultiColumnListSelectEvent(MultiColumnListEvent, event.CommandTypeEvent): + name = 'select' + binding = wx.EVT_LIST_ITEM_SELECTED + id = wx.wxEVT_COMMAND_LIST_ITEM_SELECTED + + class MultiColumnListItemActivatedEvent(MultiColumnListEvent): + name = 'itemActivated' + binding = wx.EVT_LIST_ITEM_ACTIVATED + id = wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED + + class MultiColumnListItemFocusedEvent(MultiColumnListEvent): + name = 'itemFocused' + binding = wx.EVT_LIST_ITEM_FOCUSED + id = wx.wxEVT_COMMAND_LIST_ITEM_FOCUSED + + class MultiColumnListMouseContextClickEvent(MultiColumnListEvent): + name = 'mouseContextClick' + binding = wx.EVT_LIST_ITEM_RIGHT_CLICK + id = wx.wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK + + class MultiColumnListKeyDownEvent(MultiColumnListEvent): + name = 'keyDown' + binding = wx.EVT_LIST_KEY_DOWN + id = wx.wxEVT_COMMAND_LIST_KEY_DOWN + + def decorate(self, aWxEvent, source): + aWxEvent = MultiColumnListEvent.decorate(self, aWxEvent, source) + + aWxEvent.keyCode = aWxEvent.GetKeyCode() + return aWxEvent + + class MultiColumnListColumnClickEvent(MultiColumnListEvent): + name = 'columnClick' + binding = wx.EVT_LIST_COL_CLICK + id = wx.wxEVT_COMMAND_LIST_COL_CLICK + + + MultiColumnListEvents =(MultiColumnListSelectEvent, + MultiColumnListItemActivatedEvent, + MultiColumnListItemFocusedEvent, + MultiColumnListMouseContextClickEvent, + MultiColumnListKeyDownEvent, + MultiColumnListColumnClickEvent) + class MultiColumnListSpec(widget.WidgetSpec): def __init__(self): ! ## events =[event.SelectEvent, ! ## event.ItemActivatedEvent, ! ## event.ItemFocusedEvent, ! ## event.MouseContextClickEvent, ! ## event.ListColumnClickEvent, ! ## event.KeyDownEvent] ! events = list(MultiColumnListEvents) attributes ={ 'items' : { 'presence' : 'optional', 'default' : [] }, *************** *** 83,89 **** self._setItems(aResource.items) ! # Bind the events. ! adapter = MultiColumnListEventBinding(self) ! adapter.bindEvents() # Emulate some listBox methods --- 129,133 ---- self._setItems(aResource.items) ! self._bindEvents(event.WIDGET_EVENTS + MultiColumnListEvents) # Emulate some listBox methods *************** *** 480,539 **** - class MultiColumnListEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.MultiColumnList to wxPython. - """ - def __init__( self, aComponent ) : - event.DefaultEventBinding.__init__(self, aComponent) - - """ - Bind an Event class that is supported by this objects peer Widget. - """ - def bindEvent(self, aEventClass): - parent = self._component._parent - id = self._component.GetId() - if aEventClass is event.SelectEvent: - wx.EVT_LIST_ITEM_SELECTED(parent, id, self._dispatch) - elif aEventClass is event.ItemActivatedEvent: - wx.EVT_LIST_ITEM_ACTIVATED(parent, id, self._dispatch) - elif aEventClass is event.ItemFocusedEvent: - wx.EVT_LIST_ITEM_FOCUSED(parent, id, self._dispatch) - elif aEventClass is event.MouseContextClickEvent: - wx.EVT_LIST_ITEM_RIGHT_CLICK(parent, id, self._dispatch) - elif aEventClass is event.KeyDownEvent: - wx.EVT_LIST_KEY_DOWN(parent, id, self._dispatch) - elif aEventClass is event.ListColumnClickEvent: - wx.EVT_LIST_COL_CLICK(parent, id, self._dispatch) - - - """ - Intercept all wxPyton events, convert them to PythonCard events, and - post them to the EventQueue. - """ - def _dispatch( self, aWxEvent ) : - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch(self, aWxEvent): - return - - evt = None - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LIST_ITEM_SELECTED: - evt = self._createEvent(event.SelectEvent, aWxEvent) - elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED: - evt = self._createEvent(event.ItemActivatedEvent, aWxEvent) - elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LIST_ITEM_FOCUSED: - evt = self._createEvent(event.ItemFocusedEvent, aWxEvent) - elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK: - evt = self._createEvent(event.MouseContextClickEvent, aWxEvent) - elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LIST_KEY_DOWN: - evt = self._createEvent(event.KeyDownEvent, aWxEvent) - elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_LIST_COL_CLICK: - evt = self._createEvent(event.ListColumnClickEvent, aWxEvent) - - if evt is not None: - self._component.notifyEventListeners(evt) - - import sys from PythonCard import registry --- 524,527 ---- |
From: Kevin A. <ka...@us...> - 2004-05-03 19:28:02
|
Update of /cvsroot/pythoncard/PythonCard/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10468/docs Modified Files: changelog.txt Log Message: added note about codeEditor loadConfig/saveConfig change Index: changelog.txt =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/docs/changelog.txt,v retrieving revision 1.280 retrieving revision 1.281 diff -C2 -d -r1.280 -r1.281 *** changelog.txt 2 May 2004 02:40:43 -0000 1.280 --- changelog.txt 3 May 2004 19:27:22 -0000 1.281 *************** *** 3,6 **** --- 3,7 ---- Release 0.8 2004-05-?? + codeEditor now persists all View menu settings added reversi (Othello) sample made spirographInteractive its own sample |
From: Kevin A. <ka...@us...> - 2004-05-03 16:14:19
|
Update of /cvsroot/pythoncard/PythonCard/samples/minimalTree In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30068/samples/minimalTree Modified Files: minimalTree.py Log Message: switched to mixedCase method names Index: minimalTree.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/minimalTree/minimalTree.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** minimalTree.py 24 Apr 2004 21:09:19 -0000 1.4 --- minimalTree.py 3 May 2004 16:14:08 -0000 1.5 *************** *** 16,35 **** def on_initialize(self, event): tree = self.components.tree ! root = tree.AddRoot("1") ! tree.SetItemHasChildren(root, 1) ! tree.SelectItem(root) def on_tree_itemExpanding(self, event): tree = self.components.tree ! item=event.GetItem() # This event can happen twice in the self.Expand call ! if tree.IsExpanded(item): return ! obj = int(tree.GetItemText(item)) ! if tree.GetChildrenCount(item, 0) == 0: lst = [obj * 2, (obj *2) + 1] for o in lst: ! new_item = tree.AppendItem(item, str(o)) ! tree.SetItemHasChildren(new_item, 1) def on_menuFileExit_select(self, event): --- 16,36 ---- def on_initialize(self, event): tree = self.components.tree ! root = tree.addRoot("1") ! tree.setItemHasChildren(root, 1) ! tree.selectItem(root) def on_tree_itemExpanding(self, event): tree = self.components.tree ! item=event.item # This event can happen twice in the self.Expand call ! if tree.isExpanded(item): return ! obj = int(tree.getItemText(item)) ! if tree.getChildrenCount(item, 0) == 0: lst = [obj * 2, (obj *2) + 1] for o in lst: ! new_item = tree.appendItem(item, str(o)) ! tree.setItemHasChildren(new_item, 1) ! event.skip() def on_menuFileExit_select(self, event): |
From: Kevin A. <ka...@us...> - 2004-05-03 16:13:49
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29430/components Modified Files: tree.py Log Message: switched to new style event binding and dispatch added itemCollapsed and itemCollapsing events added mixedCase aliases for some methods Index: tree.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/tree.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tree.py 1 May 2004 18:47:48 -0000 1.13 --- tree.py 3 May 2004 16:13:41 -0000 1.14 *************** *** 8,21 **** from PythonCard import event, widget class TreeSpec(widget.WidgetSpec): def __init__(self) : ! events = [event.SelectEvent, ! event.ItemActivatedEvent, ! event.ItemExpandedEvent, ! event.ItemExpandingEvent, ! event.SelectionChangedEvent, ! event.SelectionChangingEvent, ! event.KeyDownEvent ! ] attributes = { #'items' : { 'presence' : 'optional', 'default' : [] }, --- 8,106 ---- from PythonCard import event, widget + + class TreeEvent(event.Event): + def decorate(self, aWxEvent, source): + aWxEvent = event.Event.decorate(self, aWxEvent, source) + aWxEvent.item = aWxEvent.GetItem() + return aWxEvent + + class TreeItemActivatedEvent(TreeEvent): + name = 'itemActivated' + binding = wx.EVT_TREE_ITEM_ACTIVATED + id = wx.wxEVT_COMMAND_TREE_ITEM_ACTIVATED + + class TreeItemCollapsedEvent(TreeEvent): + name = 'itemCollapsed' + binding = wx.EVT_TREE_ITEM_COLLAPSED + id = wx.wxEVT_COMMAND_TREE_ITEM_COLLAPSED + + class TreeItemCollapsingEvent(TreeEvent): + name = 'itemCollapsing' + binding = wx.EVT_TREE_ITEM_COLLAPSING + id = wx.wxEVT_COMMAND_TREE_ITEM_COLLAPSING + + class TreeItemExpandedEvent(TreeEvent): + name = 'itemExpanded' + binding = wx.EVT_TREE_ITEM_EXPANDED + id = wx.wxEVT_COMMAND_TREE_ITEM_EXPANDED + + class TreeItemExpandingEvent(TreeEvent): + name = 'itemExpanding' + binding = wx.EVT_TREE_ITEM_EXPANDING + id = wx.wxEVT_COMMAND_TREE_ITEM_EXPANDING + + class TreeSelectionChangedEvent(TreeEvent): + name = 'selectionChanged' + binding = wx.EVT_TREE_SEL_CHANGED + id = wx.wxEVT_COMMAND_TREE_SEL_CHANGED + + def decorate(self, aWxEvent, source): + aWxEvent = TreeEvent.decorate(self, aWxEvent, source) + aWxEvent.oldItem = aWxEvent.GetOldItem() + return aWxEvent + + class TreeSelectionChangingEvent(TreeEvent): + name = 'selectionChanging' + binding = wx.EVT_TREE_SEL_CHANGING + id = wx.wxEVT_COMMAND_TREE_SEL_CHANGING + + def decorate(self, aWxEvent, source): + aWxEvent = TreeEvent.decorate(self, aWxEvent, source) + aWxEvent.oldItem = aWxEvent.GetOldItem() + return aWxEvent + + class TreeKeyDownEvent(TreeEvent): + name = 'keyDown' + binding = wx.EVT_TREE_KEY_DOWN + id = wx.wxEVT_COMMAND_TREE_KEY_DOWN + + def decorate(self, aWxEvent, source): + aWxEvent = TreeEvent.decorate(self, aWxEvent, source) + + aWxEvent.keyCode = aWxEvent.GetKeyCode() + keyEvent = aWxEvent.GetKeyEvent() + aWxEvent.position = tuple(keyEvent.GetPosition()) + aWxEvent.x = keyEvent.GetX() + aWxEvent.y = keyEvent.GetY() + aWxEvent.altDown = keyEvent.AltDown() + aWxEvent.controlDown = keyEvent.ControlDown() + aWxEvent.shiftDown = keyEvent.ShiftDown() + keyEvent = None + return aWxEvent + + + TreeEvents = (#TreeSelectEvent, + TreeItemActivatedEvent, + TreeItemCollapsedEvent, + TreeItemCollapsingEvent, + TreeItemExpandedEvent, + TreeItemExpandingEvent, + TreeSelectionChangedEvent, + TreeSelectionChangingEvent, + TreeKeyDownEvent + ) + + class TreeSpec(widget.WidgetSpec): def __init__(self) : ! ## events = [event.SelectEvent, ! ## event.ItemActivatedEvent, ! ## event.ItemExpandedEvent, ! ## event.ItemExpandingEvent, ! ## event.SelectionChangedEvent, ! ## event.SelectionChangingEvent, ! ## event.KeyDownEvent ! ## ] ! events = list(TreeEvents) attributes = { #'items' : { 'presence' : 'optional', 'default' : [] }, *************** *** 24,27 **** --- 109,113 ---- widget.WidgetSpec.__init__( self, 'Tree', 'Widget', events, attributes ) + class Tree(widget.Widget, wx.TreeCtrl): """ *************** *** 45,106 **** widget.Widget.__init__(self, aParent, aResource) ! adapter = TreeEventBinding(self) ! adapter.bindEvents() ! ! ! class TreeEventBinding(event.DefaultEventBinding) : ! """ ! Bind the Events supported by Tree to wxPython. ! """ ! def __init__(self, aComponent) : ! event.DefaultEventBinding.__init__(self, aComponent) ! ! """ ! Bind an Event class that is supported by this objects peer Widget. ! """ ! def bindEvent(self, aEventClass) : ! parent = self._component._parent ! id = self._component.GetId() ! ! if aEventClass is event.ItemActivatedEvent: ! wx.EVT_TREE_ITEM_ACTIVATED(parent, id, self._dispatch) ! elif aEventClass is event.ItemExpandedEvent: ! wx.EVT_TREE_ITEM_EXPANDED(parent, id, self._dispatch) ! elif aEventClass is event.ItemExpandingEvent: ! wx.EVT_TREE_ITEM_EXPANDING(parent, id, self._dispatch) ! elif aEventClass is event.SelectionChangedEvent: ! wx.EVT_TREE_SEL_CHANGED(parent, id, self._dispatch) ! elif aEventClass is event.SelectionChangingEvent: ! wx.EVT_TREE_SEL_CHANGING(parent, id, self._dispatch) ! elif aEventClass is event.KeyDownEvent: ! wx.EVT_TREE_KEY_DOWN(parent, id, self._dispatch) ! ! """ ! Intercept all wxPyton events, convert them to PythonCard events, and ! post them to the EventQueue. ! """ ! def _dispatch(self, aWxEvent) : ! # Call our superclass to dispatch the standard mouse ! # events that every widget should get. ! if event.DefaultEventBinding._dispatch(self, aWxEvent) : ! return ! ! evt = None ! ! if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TREE_ITEM_ACTIVATED: ! evt = self._createEvent(event.ItemActivatedEvent, aWxEvent) ! elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TREE_ITEM_EXPANDED: ! evt = self._createEvent(event.ItemExpandedEvent, aWxEvent) ! elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TREE_ITEM_EXPANDING: ! evt = self._createEvent(event.ItemExpandingEvent, aWxEvent) ! elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TREE_SEL_CHANGED: ! evt = self._createEvent(event.SelectionChangedEvent, aWxEvent) ! elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TREE_SEL_CHANGING: ! evt = self._createEvent(event.SelectionChangingEvent, aWxEvent) ! elif aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TREE_KEY_DOWN: ! evt = self._createEvent(event.KeyDownEvent, aWxEvent) ! if evt is not None : ! self._component.notifyEventListeners(evt) --- 131,151 ---- widget.Widget.__init__(self, aParent, aResource) ! self._bindEvents(event.WIDGET_EVENTS + TreeEvents) ! # mixedCase aliases ! # probably need to do all the wxTreeCtrl methods ! # this just covers the ones in the minimalTree sample ! addRoot = wx.TreeCtrl.AddRoot ! appendItem = wx.TreeCtrl.AppendItem ! getChildrenCount = wx.TreeCtrl.GetChildrenCount ! getItemText = wx.TreeCtrl.GetItemText ! isExpanded = wx.TreeCtrl.IsExpanded ! selectItem = wx.TreeCtrl.SelectItem ! setItemHasChildren = wx.TreeCtrl.SetItemHasChildren ! ! # if it looks like there is a memory leak with Tree components ! # then Tree should have its own _dispatch method ! # and set aWxEvent.oldItem = None, and aWxEvent.item = None ! # after calling widget.Widget._dispatch |
From: Kevin A. <ka...@us...> - 2004-05-03 16:12:31
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29382/components Modified Files: codeeditor.py Log Message: switched to new style event binding and dispatch Index: codeeditor.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/codeeditor.py,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** codeeditor.py 1 May 2004 18:47:48 -0000 1.34 --- codeeditor.py 3 May 2004 16:12:23 -0000 1.35 *************** *** 123,128 **** self._setEditable(False) ! adapter = CodeEditorEventBinding(self) ! adapter.bindEvents() # POB 2002-05-04 --- 123,129 ---- self._setEditable(False) ! #adapter = CodeEditorEventBinding(self) ! #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS + (event.KeyPressEvent, event.KeyDownEvent, event.KeyUpEvent)) # POB 2002-05-04 *************** *** 369,455 **** - # this is a copy of TextFieldEventBinding - # not all the events below are valid, but key presses do seem to - # be working - class CodeEditorEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.TextField to wxPython. - """ - def __init__( self, aComponent ) : - - event.DefaultEventBinding.__init__( self, aComponent ) - - def bindEvent( self, aEventClass ) : - - parent = self._component._parent - - # KEA 2001-10-05 - # I don't think this event is used in TextField ?! - #if aEventClass is TextEnterEvent : - # EVT_TEXT_ENTER( parent, self._component.GetId(), self._dispatch ) - - if aEventClass is event.KeyDownEvent : - wx.EVT_KEY_DOWN( self._component, self._dispatch ) - - if aEventClass is event.KeyUpEvent : - wx.EVT_KEY_UP( self._component, self._dispatch ) - - if aEventClass is event.KeyPressEvent : - wx.EVT_CHAR( self._component, self._dispatch ) - - def _dispatch(self, aWxEvent): - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch(self, aWxEvent): - return - - evt = None - - if aWxEvent.GetEventType() == event.wxEVT_CLOSE_FIELD: - #print 'handling closeField' - evt = self._createEvent(event.CloseFieldEvent, aWxEvent) - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TEXT_UPDATED : - evt = self._createEvent( event.TextUpdateEvent, aWxEvent ) - - #if aWxEvent.GetEventType() == wxEVT_COMMAND_TEXT_ENTER : - # event = self._createEvent( TextEnterEvent, aWxEvent ) - # this should be associated with losing focus, not textEnter - #self._component.notifyEventListeners( CloseField( self._component ) ) - - if aWxEvent.GetEventType() == wx.wxEVT_KEY_DOWN : - #print '_dispatch wxEVT_KEY_DOWN' - #evt = KeyDownEvent( self._component ) - evt = self._createEvent( event.KeyDownEvent, aWxEvent ) - - if aWxEvent.GetEventType() == wx.wxEVT_KEY_UP : - #print '_dispatch wxEVT_KEY_UP' - #evt = KeyUpEvent( self._component ) - evt = self._createEvent( event.KeyUpEvent, aWxEvent ) - - if aWxEvent.GetEventType() == wx.wxEVT_CHAR : - #print '_dispatch wxEVT_CHAR' - #evt = KeyPressEvent( self._component ) - evt = self._createEvent( event.KeyPressEvent, aWxEvent ) - - if evt is not None : - #print '_dispatch evt is not None' - self._component.notifyEventListeners( evt ) - #print "after notify" - - # KEA 2001-10-05 - # there needs to be an Event.Skip() somewhere if the event was not handled - # by user code - # however, skip should normally only be called if the user code didn't process - # the event, which will allow the user code to "eat" the event, suppressing - # and/or changing the actions of certain keys - # need to make a complete list of which events can be eaten and which can't - if not evt.getUsed(): - aWxEvent.Skip() - # KEA 2001-10-26 - # if textEnter wasn't handled then focus should move to the next - # control in the panel, just like pressing tab - - import sys from PythonCard import registry --- 370,373 ---- |
From: Kevin A. <ka...@us...> - 2004-05-03 02:56:42
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5567 Modified Files: event.py widget.py Log Message: changed to use decorate and translation of event types Index: widget.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/widget.py,v retrieving revision 1.123 retrieving revision 1.124 diff -C2 -d -r1.123 -r1.124 *** widget.py 3 May 2004 00:03:46 -0000 1.123 --- widget.py 3 May 2004 02:56:33 -0000 1.124 *************** *** 349,440 **** def _dispatch(self, aWxEvent): eventType = aWxEvent.GetEventType() ! eventName = None ! if eventType == wx.wxEVT_TIMER: ! aWxEvent.interval = aWxEvent.GetInterval() ! # wxPython 2.5.1.5 workaround ! # for some reason wx.TimerEvent does not contain the event target ! # so we have to set it ourselves ! aWxEvent.target = aWxEvent.eventObject = self else: ! try: ! # all events should have GetEventObject() ! # except of course for wx.TimerEvent above ! # KEA 2004-04-25 ! # should we remove this redundant identifier? ! aWxEvent.target = aWxEvent.eventObject = self ! except: ! pass ! # Each of these could check the event class like ! # wxListEvent and wxTreeEvent above. ! try: ! # mouse and key events ! aWxEvent.position = tuple(aWxEvent.GetPosition()) ! aWxEvent.x = aWxEvent.GetX() ! aWxEvent.y = aWxEvent.GetY() ! aWxEvent.altDown = aWxEvent.AltDown() ! aWxEvent.controlDown = aWxEvent.ControlDown() ! aWxEvent.shiftDown = aWxEvent.ShiftDown() ! except: ! pass ! try: ! # key events ! aWxEvent.keyCode = aWxEvent.GetKeyCode() ! except: ! pass ! if issubclass(self.wxEventIdMap[eventType], event.CommandTypeEvent): ! # could be command, so need to report the name ! # for the handler if it exists ! if self.command: ! eventName = 'command' ! elif eventType == event.MouseMoveEvent.id: ! # check to see if this is a mouseDrag ! if aWxEvent.Dragging(): ! eventType = event.MouseDragEvent.id ! # don't need this if all event types have unique ids ! #eventName = event.MouseDragEvent.name ! ! # the component-specific helper attributes below ! # should be handled in the relevant component _dispatch ! # not the generic one ! """ ! if eventType in [wx.wxEVT_COMMAND_LIST_KEY_DOWN, ! wx.wxEVT_COMMAND_TREE_KEY_DOWN]: ! try: ! # key events are different for wxTreeCtrl and wxListCtrl ! aWxEvent.keyCode = aWxEvent.GetCode() ! except: ! pass ! try: ! # wxListEvent doesn't have GetKeyEvent for some reason ! keyEvent = aWxEvent.GetKeyEvent() ! aWxEvent.altDown = keyEvent.AltDown() ! aWxEvent.controlDown = keyEvent.ControlDown() ! aWxEvent.shiftDown = keyEvent.ShiftDown() ! except: ! pass ! elif eventType in [wx.wxEVT_COMMAND_TREE_BEGIN_DRAG, \ ! wx.wxEVT_COMMAND_TREE_BEGIN_RDRAG, \ ! wx.wxEVT_COMMAND_TREE_END_DRAG, \ ! wx.wxEVT_COMMAND_LIST_BEGIN_DRAG, \ ! wx.wxEVT_COMMAND_LIST_BEGIN_RDRAG, \ ! wx.wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, \ ! wx.wxEVT_COMMAND_LIST_COL_DRAGGING, \ ! wx.wxEVT_COMMAND_LIST_COL_END_DRAG]: ! try: ! # The mouse position during a drag event ! # there doesn't appear to be a way of getting the ! # state of the shift, alt, and control keys ! # during a mouse drag. ! aWxEvent.position = tuple(aWxEvent.GetPoint()) ! aWxEvent.x = aWxEvent.position[0] ! aWxEvent.y = aWxEvent.position[1] ! except: ! pass ! """ ! ! if not eventName: eventName = self.wxEventIdMap[eventType].name # it shouldn't be possible to be in _dispatch for an event --- 349,371 ---- def _dispatch(self, aWxEvent): eventType = aWxEvent.GetEventType() + eventClass = self.wxEventIdMap[eventType] ! eventClassInstance = eventClass(self) ! # decorate will add the relevant event attributes ! aWxEvent = eventClassInstance.decorate(aWxEvent, self) ! if self.command and isinstance(eventClassInstance, event.CommandTypeEvent): ! # need to report the name for the handler if it exists ! eventName = 'command' else: ! if isinstance(eventClassInstance, event.InsteadOfTypeEvent): ! # changes eventType if needed ! # e.g. mouseDrag instead of mouseMove ! eventType = eventClassInstance.translateEventType(aWxEvent) eventName = self.wxEventIdMap[eventType].name + + # cleanup + eventClass = None + eventClassInstance = None # it shouldn't be possible to be in _dispatch for an event Index: event.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/event.py,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** event.py 2 May 2004 22:09:29 -0000 1.64 --- event.py 3 May 2004 02:56:33 -0000 1.65 *************** *** 261,264 **** --- 261,268 ---- def skip( self ) : self.getNativeEvent().Skip() + + def decorate(self, aWxEvent, source): + aWxEvent.target = aWxEvent.eventObject = source + return aWxEvent *************** *** 411,414 **** --- 415,446 ---- pass + class MouseEvent(Event): + def decorate(self, aWxEvent, source): + aWxEvent = Event.decorate(self, aWxEvent, source) + + aWxEvent.position = tuple(aWxEvent.GetPosition()) + aWxEvent.x = aWxEvent.GetX() + aWxEvent.y = aWxEvent.GetY() + aWxEvent.altDown = aWxEvent.AltDown() + aWxEvent.controlDown = aWxEvent.ControlDown() + aWxEvent.shiftDown = aWxEvent.ShiftDown() + return aWxEvent + + class KeyEvent(Event): + def decorate(self, aWxEvent, source): + aWxEvent = Event.decorate(self, aWxEvent, source) + + # this is basically the same block as MouseEvent.decorate + # but it seems wrong to have KeyEvent be a subclass of MouseEvent + aWxEvent.position = tuple(aWxEvent.GetPosition()) + aWxEvent.x = aWxEvent.GetX() + aWxEvent.y = aWxEvent.GetY() + aWxEvent.altDown = aWxEvent.AltDown() + aWxEvent.controlDown = aWxEvent.ControlDown() + aWxEvent.shiftDown = aWxEvent.ShiftDown() + + aWxEvent.keyCode = aWxEvent.GetKeyCode() + return aWxEvent + class GainFocusEvent(Event): *************** *** 424,428 **** ! class KeyPressEvent( Event ) : name = 'keyPress' binding = wx.EVT_CHAR --- 456,460 ---- ! class KeyPressEvent(KeyEvent): name = 'keyPress' binding = wx.EVT_CHAR *************** *** 430,434 **** ! class KeyDownEvent( Event ) : name = 'keyDown' binding = wx.EVT_KEY_DOWN --- 462,466 ---- ! class KeyDownEvent(KeyEvent): name = 'keyDown' binding = wx.EVT_KEY_DOWN *************** *** 436,440 **** ! class KeyUpEvent( Event ) : name = 'keyUp' binding = wx.EVT_KEY_UP --- 468,472 ---- ! class KeyUpEvent(KeyEvent): name = 'keyUp' binding = wx.EVT_KEY_UP *************** *** 511,514 **** --- 543,550 ---- id = wx.wxEVT_TIMER + def decorate(self, aWxEvent, source): + aWxEvent = Event.decorate(self, aWxEvent, source) + aWxEvent.interval = aWxEvent.GetInterval() + return aWxEvent class MouseClickEvent(Event, CommandTypeEvent): *************** *** 523,527 **** command = True ! class MouseDoubleClickEvent(Event): name = 'mouseDoubleClick' binding = wx.EVT_LEFT_DCLICK --- 559,563 ---- command = True ! class MouseDoubleClickEvent(MouseEvent): name = 'mouseDoubleClick' binding = wx.EVT_LEFT_DCLICK *************** *** 529,538 **** ! class MouseDownEvent(Event): name = 'mouseDown' binding = wx.EVT_LEFT_DOWN id = wx.wxEVT_LEFT_DOWN ! class MouseUpEvent(Event): name = 'mouseUp' binding = wx.EVT_LEFT_UP --- 565,574 ---- ! class MouseDownEvent(MouseEvent): name = 'mouseDown' binding = wx.EVT_LEFT_DOWN id = wx.wxEVT_LEFT_DOWN ! class MouseUpEvent(MouseEvent): name = 'mouseUp' binding = wx.EVT_LEFT_UP *************** *** 540,544 **** ! class MouseMiddleDownEvent(Event): name = 'mouseMiddleDown' binding = wx.EVT_MIDDLE_DOWN --- 576,580 ---- ! class MouseMiddleDownEvent(MouseEvent): name = 'mouseMiddleDown' binding = wx.EVT_MIDDLE_DOWN *************** *** 546,550 **** ! class MouseMiddleUpEvent(Event): name = 'mouseMiddleUp' binding = wx.EVT_MIDDLE_UP --- 582,586 ---- ! class MouseMiddleUpEvent(MouseEvent): name = 'mouseMiddleUp' binding = wx.EVT_MIDDLE_UP *************** *** 552,556 **** ! class MouseMiddleDoubleClickEvent(Event): name = 'mouseMiddleDoubleClick' binding = wx.EVT_MIDDLE_DCLICK --- 588,592 ---- ! class MouseMiddleDoubleClickEvent(MouseEvent): name = 'mouseMiddleDoubleClick' binding = wx.EVT_MIDDLE_DCLICK *************** *** 558,562 **** ! class MouseContextDownEvent(Event): name = 'mouseContextDown' binding = wx.EVT_RIGHT_DOWN --- 594,598 ---- ! class MouseContextDownEvent(MouseEvent): name = 'mouseContextDown' binding = wx.EVT_RIGHT_DOWN *************** *** 564,568 **** ! class MouseContextUpEvent(Event): name = 'mouseContextUp' binding = wx.EVT_RIGHT_UP --- 600,604 ---- ! class MouseContextUpEvent(MouseEvent): name = 'mouseContextUp' binding = wx.EVT_RIGHT_UP *************** *** 574,583 **** ! class MouseContextDoubleClickEvent(Event): name = 'mouseContextDoubleClick' binding = wx.EVT_RIGHT_DCLICK id = wx.wxEVT_RIGHT_DCLICK ! class MouseEnterEvent(Event): name = 'mouseEnter' binding = wx.EVT_ENTER_WINDOW --- 610,619 ---- ! class MouseContextDoubleClickEvent(MouseEvent): name = 'mouseContextDoubleClick' binding = wx.EVT_RIGHT_DCLICK id = wx.wxEVT_RIGHT_DCLICK ! class MouseEnterEvent(MouseEvent): name = 'mouseEnter' binding = wx.EVT_ENTER_WINDOW *************** *** 585,589 **** ! class MouseLeaveEvent(Event): name = 'mouseLeave' binding = wx.EVT_LEAVE_WINDOW --- 621,625 ---- ! class MouseLeaveEvent(MouseEvent): name = 'mouseLeave' binding = wx.EVT_LEAVE_WINDOW *************** *** 591,601 **** ! class MouseMoveEvent(Event): name = 'mouseMove' binding = wx.EVT_MOTION id = wx.wxEVT_MOTION ! class MouseDragEvent(Event, InsteadOfTypeEvent): name = 'mouseDrag' binding = wx.EVT_MOTION --- 627,642 ---- ! class MouseMoveEvent(MouseEvent, InsteadOfTypeEvent): name = 'mouseMove' binding = wx.EVT_MOTION id = wx.wxEVT_MOTION + def translateEventType(self, aWxEvent): + if aWxEvent.Dragging(): + return MouseDragEvent.id + else: + return self.id ! class MouseDragEvent(MouseEvent, InsteadOfTypeEvent): name = 'mouseDrag' binding = wx.EVT_MOTION |
From: Kevin A. <ka...@us...> - 2004-05-03 00:03:55
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12004 Modified Files: widget.py Log Message: turned off debug print Index: widget.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/widget.py,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** widget.py 3 May 2004 00:00:20 -0000 1.122 --- widget.py 3 May 2004 00:03:46 -0000 1.123 *************** *** 334,338 **** self.eventIdToHandler[eventClass.id] = handler.getFunction() ! if 1: print "\n boundEvents:" for name in self.boundEvents.values(): --- 334,338 ---- self.eventIdToHandler[eventClass.id] = handler.getFunction() ! if 0: print "\n boundEvents:" for name in self.boundEvents.values(): |
From: Kevin A. <ka...@us...> - 2004-05-03 00:00:30
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11106 Modified Files: widget.py Log Message: Handler class really isn't needed, since we're just looking up the the method to call based on the id of the event passed into _dispatch Index: widget.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/widget.py,v retrieving revision 1.121 retrieving revision 1.122 diff -C2 -d -r1.121 -r1.122 *** widget.py 2 May 2004 19:56:16 -0000 1.121 --- widget.py 3 May 2004 00:00:20 -0000 1.122 *************** *** 321,327 **** if 0: print " binding", self.name, eventClass.name, handler._name, eventClass.id ! self.eventIdToHandler[eventClass.id] = handler ! if 0: print "\n boundEvents:" for name in self.boundEvents.values(): --- 321,338 ---- if 0: print " binding", self.name, eventClass.name, handler._name, eventClass.id ! # KEA 2004-05-02 ! # change to just using the method directly, Handler class not needed ! # actually the Handler class isn't needed at all ! # so if the initial list built to simplify findHandler ! # just stores a reference to the method that would be fine ! # as long as the whole system uses that ! # the only reason we don't just build the list ourselves ! # in _bindEvents is that every component needs to do findHandler ! # so it is more efficient to do once when the Scriptable object ! # is created than to reparse for each component ! #self.eventIdToHandler[eventClass.id] = handler ! self.eventIdToHandler[eventClass.id] = handler.getFunction() ! if 1: print "\n boundEvents:" for name in self.boundEvents.values(): *************** *** 330,334 **** print "\n self.eventIdToHandler:" for id in self.eventIdToHandler: ! print " ", id, self.eventIdToHandler[id]._function print "\n\n" --- 341,348 ---- print "\n self.eventIdToHandler:" for id in self.eventIdToHandler: ! # KEA 2004-05-02 ! # change to just using the method directly, Handler class not needed ! #print " ", id, self.eventIdToHandler[id]._function ! print " ", id, self.eventIdToHandler[id] print "\n\n" *************** *** 426,429 **** --- 440,446 ---- # it shouldn't be possible to be in _dispatch for an event # that wasn't bound above, but just in case... + # KEA 2004-05-02 + # change to just using the method directly, Handler class not needed + #handler = self.eventIdToHandler.get(eventType, None) handler = self.eventIdToHandler.get(eventType, None) if handler: *************** *** 446,450 **** # this is what is in event.py # aHandler.getFunction()( aOwner, self.getSource(), self ) ! handler.getFunction()(background, aWxEvent) # do we have to clean up this alias? --- 463,470 ---- # this is what is in event.py # aHandler.getFunction()( aOwner, self.getSource(), self ) ! # KEA 2004-05-02 ! # change to just using the method directly, Handler class not needed ! #handler.getFunction()(background, aWxEvent) ! handler(background, aWxEvent) # do we have to clean up this alias? |
From: Kevin A. <ka...@us...> - 2004-05-02 23:20:50
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4242/components Modified Files: bitmapcanvas.py image.py imagebutton.py Log Message: switched to new style event bindings, this fixes broken imagebutton events Index: imagebutton.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/imagebutton.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** imagebutton.py 21 Apr 2004 03:45:00 -0000 1.15 --- imagebutton.py 2 May 2004 23:20:40 -0000 1.16 *************** *** 9,15 **** import button, image class ImageButtonSpec( widget.WidgetSpec ): def __init__(self): ! events = [ event.MouseClickEvent ] attributes = { 'file' : { 'presence' : 'mandatory' }, --- 9,19 ---- import button, image + class ImageButtonSpec( widget.WidgetSpec ): def __init__(self): ! # KEA 2004-04-26 ! # test to use new event classes ! events = [button.ButtonMouseClickEvent] ! #events = [ event.MouseClickEvent ] attributes = { 'file' : { 'presence' : 'mandatory' }, *************** *** 87,92 **** wx.EVT_ERASE_BACKGROUND( self, lambda evt: None) ! adapter = button.ButtonEventBinding(self) ! adapter.bindEvents() def _OnDestroy(self, event): --- 91,97 ---- wx.EVT_ERASE_BACKGROUND( self, lambda evt: None) ! #adapter = button.ButtonEventBinding(self) ! #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS + (button.ButtonMouseClickEvent,)) def _OnDestroy(self, event): Index: image.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/image.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** image.py 21 Apr 2004 03:45:00 -0000 1.18 --- image.py 2 May 2004 23:20:40 -0000 1.19 *************** *** 63,68 **** wx.EVT_WINDOW_DESTROY(self, self._OnDestroy) ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() def _OnDestroy(self, event): --- 63,69 ---- wx.EVT_WINDOW_DESTROY(self, self._OnDestroy) ! #adapter = event.DefaultEventBinding(self) ! #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS) def _OnDestroy(self, event): Index: bitmapcanvas.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/bitmapcanvas.py,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** bitmapcanvas.py 1 May 2004 16:26:01 -0000 1.39 --- bitmapcanvas.py 2 May 2004 23:20:40 -0000 1.40 *************** *** 117,122 **** self.clear() self._setForegroundColor((0,0,0)) # 'black' ! adapter = event.DefaultEventBinding(self) ! adapter.bindEvents() def _onDestroy(self, event): --- 117,124 ---- self.clear() self._setForegroundColor((0,0,0)) # 'black' ! ! #adapter = event.DefaultEventBinding(self) ! #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS) def _onDestroy(self, event): |
From: Rowland S. <mon...@us...> - 2004-05-02 22:09:39
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22762 Modified Files: event.py component.py Log Message: Simplified Scriptable. Created IScriptable interface, extended by Scriptable and NullScriptable. NullScriptable gets installed as the parent of a Scriptable if the parent=None. Index: component.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/component.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** component.py 2 May 2004 16:32:23 -0000 1.10 --- component.py 2 May 2004 22:09:29 -0000 1.11 *************** *** 8,12 **** from PythonCard.event import EventLog ! class Scriptable: """ RDS - 2004-05-02 --- 8,35 ---- from PythonCard.event import EventLog ! ! class IScriptable( object ) : ! """ ! RDS - 2004-05-02 ! The public interface for all scriptable objects. ! """ ! def execute( self, name, event ) : ! raise NotImplementedError ! ! ! class NullScriptable( IScriptable ) : ! """ ! RDS - 2004-05-02 ! Installed as the parent of any Scriptable ! object that is instantiated with a ! parent=None. This implementation calls the ! EventLog when an event is executed and logs ! it as *not* used. ! """ ! def execute( self, name, event ) : ! EventLog.getInstance().log( event, '(not handled)', False ) ! ! ! class Scriptable( IScriptable ) : """ RDS - 2004-05-02 *************** *** 15,147 **** execution of it's handlers. ! All classes that may contain PythonCard Handler definitions must implement Scriptable. A Scriptable object may be specified as the parent of ! this object. The parent will be searched for Handlers ! if a Handler can't be found in this object. """ ! ! def __init__(self, aScriptableParent): ! self._parentScript = aScriptableParent self._handlers = {} self._parseHandlers() - if False: - print "Scriptable init", self._handlers.keys() ! def _parseHandlers(self): """ Find all of the methods in this object that are PythonCard handlers, and register them. """ ! # KEA 2004-03-05 ! # an even slicker way of finding event handlers ! # using the inspect module ! pythoncardMethods = [] ! methods = inspect.getmembers(self.__class__, inspect.ismethod) ! for m in methods: ! if m[0].split('_')[0] == 'on': ! pythoncardMethods.append(m[1]) ! print pythoncardMethods ! ! map(self._addHandler, pythoncardMethods) ! ! def _isPythonCardHandler(self, aObject): """ Return true if the object is a PythonCard handler. """ ! print 'found handler', aObject ! return isinstance(aObject, types.FunctionType) and aObject.__name__.split('_')[0] == 'on' ! def _addHandler(self, aMethod): ! # Add the Handler to our Handler list. ! if aMethod.__name__ not in self._handlers: ! log.debug("_addHandler: " + aMethod.__name__) ! self._handlers[aMethod.__name__] = event.Handler(aMethod) ! ! """ ! RDS - Never gets called - Remove. ! ! def addMethod(self, aFunction): ! if isinstance(aFunction, types.FunctionType): ! if self._isPythonCardHandler(aFunction) : ! #aMethod = new.instancemethod(aFunction, self, self.__class__) ! aMethod = new.instancemethod(aFunction, None, self.__class__) ! #print aFunction ! #print self.__class__ ! #print aMethod.__name__ ! #print aMethod ! self.__class__.__dict__[aMethod.__name__] = aMethod ! # now add the method info to our handler lookup dictionary ! # KEA 2001-11-29 simplified _addHandler ! #handler = event.Handler(aMethod.__name__, aMethod) ! #self._addHandler(aMethod.__name__, handler) ! self._addHandler(aMethod) ! """ ! def _findHandler(self, aString): """ ! Look for a Handler that matches aString in our ! list of Handlers. If a Handler is not found, ! ask our parent script to look for the Handler, ! continuing up the Scriptable hierarchy until ! either a Handler is found, or None is returned. """ ! # KEA 2004-04-26 ! # findHandler is actually called for each event dispatch ! # depending on the level of dynamic code we think we're going ! # to have it might be simpler to just statically bind when ! # the component is created ! if True: ! print "findHandler", aString, self ! handler = self._handlers.get(aString, None) ! ! if handler: ! return self, handler ! ! # We couldn't find a handler, so look in our parent. ! if self._parentScript: ! print 'looking for handler in parent', self._parentScript ! script, handler = self._parentScript._findHandler( aString ) ! # have we found a Handler yet? ! if handler: ! return script, handler ! # Change the handler name to target this Scriptable object ! # and look in our list of Handlers. ! ! words = aString.split('_') ! #print words, self._getName() ! #if len(words) == 2: ! # print words ! # aString = words[ 0 ] + '_' + words[ 1 ] ! #else: ! aString = words[0] + '_' + self.getName() + '_' + words[len(words) - 1] ! temp = self._handlers.get(aString, None) ! if temp: ! return ( self, temp ) ! else: ! # search for Background and Stack handlers like ! # on_mouseClick, on_initialize ! aString = words[0] + '_' + words[len(words) - 1] ! return self._handlers.get(aString, None) ! ! def execute( self, handlerName, event ) : """ RDS - 2004-05-02 Find the handler that matches handlerName and execute it. ! Should we throw an exception if the handlerName ! is not found? The caller would be responsible ! for reporting a missing handler as an error. """ ! print 'finding handler', handlerName ! script, handler = self._findHandler( handlerName ) if handler is not None : ! print script, handler ! handler.execute( script, event ) EventLog.getInstance().log( event, handler.getSourceName(), True ) --- 38,123 ---- execution of it's handlers. ! All classes that may contain PythonCard EventHandler definitions must implement Scriptable. A Scriptable object may be specified as the parent of ! this object. The parent will be searched for EventHandlers ! if a EventHandler can't be found in this object. """ ! def __init__( self, parent=None ) : ! if parent is None : ! parent = NullScriptable() ! self._parent = parent self._handlers = {} self._parseHandlers() ! def _parseHandlers( self ) : """ Find all of the methods in this object that are PythonCard handlers, and register them. """ + found = [] + methods = inspect.getmembers( self, inspect.ismethod ) + for m in methods : + if m[ 0 ].split( '_' )[ 0 ] == 'on' : + found.append( m[ 1 ] ) + map( self._addHandler, found ) ! def _isPythonCardHandler( self, aObject ) : """ Return true if the object is a PythonCard handler. """ ! return isinstance( aObject, types.FunctionType ) and aObject.__name__.split('_')[0] == 'on' ! def _addHandler( self, method ) : ! # Add the EventHandlers to our EventHandler list. ! if method.__name__ not in self._handlers : ! log.debug("_addHandler: " + method.__name__) ! self._handlers[ method.__name__ ] = event.EventHandler( method ) ! def _findHandler( self, name ) : """ ! Look for a EventHandlers that matches 'name' in our ! list of EventHandlers. """ ! handler = self._handlers.get( name, None ) ! if handler is None : ! # Change the handler name to target this Scriptable object ! # and look in our list of EventHandlers. ! ! words = name.split('_') ! s = words[ 0 ] + '_' + self.getName() + '_' + words[ len( words ) - 1 ] ! h = self._handlers.get( s, None ) ! if h is not None : ! return ( h ) ! else: ! # search for Background and Stack handlers like ! # on_mouseClick, on_initialize ! s = words[ 0 ] + '_' + words[ len( words ) - 1 ] ! return self._handlers.get( s, None ) ! return handler ! ! def execute( self, name, event ) : """ RDS - 2004-05-02 + Find the handler that matches handlerName and execute it. ! ! Should we throw an exception if the handler name ! is not found? ! ! The caller would be responsible for reporting ! a missing handler as an error. """ ! handler = self._findHandler( name ) ! if handler is not None : ! handler.execute( event ) EventLog.getInstance().log( event, handler.getSourceName(), True ) + else : + self._parent.execute( name, event ) Index: event.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/event.py,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** event.py 2 May 2004 19:49:56 -0000 1.63 --- event.py 2 May 2004 22:09:29 -0000 1.64 *************** *** 10,13 **** --- 10,66 ---- import wx + class EventHandler: + """ + RDS - 2004-05-02 + Future replacement for Handler. + Maps a function name to an instance method. + """ + def __init__( self, method ) : + + # Grab the method object. + self._method = method + # Hold on to the full name. + self._name = method.__name__ + # Parse the function/method name. + parts = self._name.split('_') + # The 'on' prefix, i.e. on_button1_click + self._prefix = parts[ 0 ] + + if len( parts ) == 3 : + # The name of the Widget instance that is the target. + self._sourceName = parts[ 1 ] + # The Event class identifier. + self._eventName = parts[ 2 ] + else: + # KEA 2001-09-06 + # need to pass in the name of the Background subclass instance ? + # RDS 2004-05-02 + # What? + self._sourceName = '' + self._eventName = parts[ 1 ] + + def getName( self ) : + return self._name + + def getSourceName( self ) : + return self._sourceName + + def getEventName( self ) : + return self._eventName + + def execute( self, event ) : + """ + RDS - 2004-05-02 + Added to support new Scriptable design in + component.Scriptable. Ask the Handler to + execute itself instead of getting it's + function and calling it. + """ + self._method( event ) + + def __repr__( self ) : + return str( self.__dict__ ) + + class Handler: |
From: Rowland S. <mon...@us...> - 2004-05-02 22:09:38
|
Update of /cvsroot/pythoncard/PythonCard/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22762/tests Modified Files: ScriptableTest.py Log Message: Simplified Scriptable. Created IScriptable interface, extended by Scriptable and NullScriptable. NullScriptable gets installed as the parent of a Scriptable if the parent=None. Index: ScriptableTest.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/tests/ScriptableTest.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ScriptableTest.py 2 May 2004 16:32:57 -0000 1.1 --- ScriptableTest.py 2 May 2004 22:09:29 -0000 1.2 *************** *** 5,14 **** class TestHandler( component.Scriptable ) : ! def __init__( self, name, scriptableParent ) : ! component.Scriptable.__init__( self, scriptableParent ) self._name = name ! def on_print( self, event ) : ! print self._name, event def getName( self ) : --- 5,15 ---- class TestHandler( component.Scriptable ) : ! def __init__( self, name, parent ) : ! component.Scriptable.__init__( self, parent ) self._name = name ! def on_doIt( self, event ) : ! global handledIn ! handledIn = self._name def getName( self ) : *************** *** 16,23 **** ! class HandlerWithNoOnPrint( component.Scriptable ) : ! def __init__( self, name, scriptableParent ) : ! component.Scriptable.__init__( self, scriptableParent ) self._name = name --- 17,24 ---- ! class HandlerWithMissingMethod( component.Scriptable ) : ! def __init__( self, name, parent ) : ! component.Scriptable.__init__( self, parent ) self._name = name *************** *** 26,41 **** ! class TestScriptable( unittest.TestCase ) : def setUp( self ) : pass def testScriptable( self ) : parent = TestHandler( 'parent', None ) child = TestHandler( 'child', parent ) ! parent.execute( 'on_print', ( 'howdy' ) ) ! child.execute( 'on_print', ( 'howdy' ) ) ! missing = HandlerWithNoOnPrint( 'missing', parent ) ! missing.execute( 'on_print', ( 'howdy' ) ) if __name__ == '__main__': --- 27,54 ---- ! class TestScriptable( unittest.TestCase, event.EventListener ) : + def __init__( self, name ) : + unittest.TestCase.__init__( self, name ) + event.EventLog.getInstance().addEventListener( self ) + + def eventOccurred( self, event ) : + print 'event=', event + def setUp( self ) : pass def testScriptable( self ) : + global handledIn parent = TestHandler( 'parent', None ) + parent.execute( 'on_doIt', ( 'howdy parent' ) ) + self.assertEqual( handledIn, 'parent' ) child = TestHandler( 'child', parent ) ! child.execute( 'on_doIt', ( 'howdy child' ) ) ! self.assertEqual( handledIn, 'child' ) ! missing = HandlerWithMissingMethod( 'missing', parent ) ! missing.execute( 'on_doIt', ( 'howdy missing(parent)' ) ) ! self.assertEqual( handledIn, 'parent' ) ! missing.execute( 'on_wtf', ( 'no dice' ) ) if __name__ == '__main__': |
From: Kevin A. <ka...@us...> - 2004-05-02 22:03:15
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21418/components Modified Files: passwordfield.py Log Message: added event import Index: passwordfield.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/passwordfield.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** passwordfield.py 2 May 2004 19:49:57 -0000 1.20 --- passwordfield.py 2 May 2004 22:03:06 -0000 1.21 *************** *** 6,10 **** import wx ! from PythonCard import widget import textfield --- 6,10 ---- import wx ! from PythonCard import event, widget import textfield |
From: Kevin A. <ka...@us...> - 2004-05-02 19:56:26
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24188 Modified Files: widget.py Log Message: fixed boundEvents reference Index: widget.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/widget.py,v retrieving revision 1.120 retrieving revision 1.121 diff -C2 -d -r1.120 -r1.121 *** widget.py 2 May 2004 19:49:57 -0000 1.120 --- widget.py 2 May 2004 19:56:16 -0000 1.121 *************** *** 256,260 **** # helper variable to simplify test for whether to bind InsteadOfTypeEvents ! boundEvents = {} self.eventIdToHandler = {} --- 256,263 ---- # helper variable to simplify test for whether to bind InsteadOfTypeEvents ! # there is a good chance we will need to know ! # which events are bound, if we want to dynamically add or remove ! # events later, so go ahead and keep a reference to the list ! self.boundEvents = {} self.eventIdToHandler = {} *************** *** 312,318 **** # and that is inserted into boundEvents, then we check boundEvents # prior to rebinding? ! if not boundEvents.get(eventClass.binding, None): self.Bind(eventClass.binding, self._dispatch) ! boundEvents[eventClass.binding] = eventClass.name if handler: if 0: --- 315,321 ---- # and that is inserted into boundEvents, then we check boundEvents # prior to rebinding? ! if not self.boundEvents.get(eventClass.binding, None): self.Bind(eventClass.binding, self._dispatch) ! self.boundEvents[eventClass.binding] = eventClass.name if handler: if 0: *************** *** 322,326 **** if 0: print "\n boundEvents:" ! for name in boundEvents.values(): print " ", name print "\n\n" --- 325,329 ---- if 0: print "\n boundEvents:" ! for name in self.boundEvents.values(): print " ", name print "\n\n" *************** *** 329,336 **** print " ", id, self.eventIdToHandler[id]._function print "\n\n" - # there is a good chance we will need to know - # which events are bound, if we want to dynamically add or remove - # events later, so go ahead and keep a reference to the list - self.boundEvents = boundEvents def _dispatch(self, aWxEvent): --- 332,335 ---- |
From: Kevin A. <ka...@us...> - 2004-05-02 19:56:25
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24188/components Modified Files: textfield.py Log Message: fixed boundEvents reference Index: textfield.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/textfield.py,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** textfield.py 2 May 2004 19:49:57 -0000 1.27 --- textfield.py 2 May 2004 19:56:17 -0000 1.28 *************** *** 289,293 **** if 0: print "\n boundEvents:" ! for name in boundEvents.values(): print " ", name print "\n\n" --- 289,293 ---- if 0: print "\n boundEvents:" ! for name in self.boundEvents.values(): print " ", name print "\n\n" |
From: Kevin A. <ka...@us...> - 2004-05-02 19:50:08
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21950 Modified Files: event.py widget.py Log Message: moved _binding and _dispatch into widget.py added component specific _binding to TextField, TextArea, PasswordField switched to wx.GetApp and wx.GetTopLevelwindow added binding and id attributes to background event classes added TextArea to testevents Index: widget.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/widget.py,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** widget.py 28 Apr 2004 01:24:50 -0000 1.119 --- widget.py 2 May 2004 19:49:57 -0000 1.120 *************** *** 224,227 **** --- 224,465 ---- visible = property(_getVisible, _setVisible) + # KEA 2004-05-02 + # this will probably end up in Scriptable or Component + # it should be completely generic + # the only problem part would be the reference to the parent (background) + # where the events are actually defined which would make this problematic + # for a compound component or events bound to a Panel + # what we really want is a reference to the application instance + # there is probably some method to give us that in wxWidgets + # UPDATE - I think GetTopLevelParent is what I was looking for + def _bindEvents(self, eventList): + # shouldn't components be subclasses of Scriptable? + # components would have their own handlers but when + # looking for a handler match it will search the parents + # for now just grab handlers from the background + + # the references below would be self.findHandler instead of + # background.findHandler + + #background = self.GetParent().GetParent() + background = wx.GetTopLevelParent(self) + + # where should this check go? + # should we just set a "global" in the app instance such as + # self.stack.app.bindUnusedEvents + # this kind of thing isn't going to work for Rowland's compound + # components + if wx.GetApp()._showDebugMenu: + bindUnusedEvents = True + else: + bindUnusedEvents = False + + # helper variable to simplify test for whether to bind InsteadOfTypeEvents + boundEvents = {} + + self.eventIdToHandler = {} + self.wxEventIdMap = {} + + if 0: + print "\nBINDING...", self.name + + for eventClass in eventList: + #for eventClass in ButtonEvents: + # need to figure out a way to avoid the need + # for this id to class mapping which is used in _dispatch below + self.wxEventIdMap[eventClass.id] = eventClass + # command handler overrides normal mouseClick or select handler + # so dispatch will automatically dispatch to the command handler + # by looking up the handler this way + # it also means that if there is a command association with this component + # then the regular mouseClick or select handler will never be bound, just ignored + if issubclass(eventClass, event.CommandTypeEvent) and self.command: + handler = background.findHandler('on_' + self.command + '_command') + if not handler: + handler = background.findHandler('on_' + self.name + '_' + eventClass.name) + else: + handler = background.findHandler('on_' + self.name + '_' + eventClass.name) + if not handler: + handler = background.findHandler('on_' + eventClass.name) + if handler or bindUnusedEvents: + # only bind events that have an event handler + # in this scenario unused events are never bound + # which is more efficient, but the Message Watcher needs + # to be changed + # alternatively we can bind everything and then in _dispatch + # if there isn't a match in eventIdToHandler then we know + # the event isn't used and we can set used to False + # the complication would be that we probably have to have to + # always call Skip() which may or may not be a hassle with components + + # this doesn't bind command events + # they would be of the form on_somename_command + # or perhaps on_command but I don't think we would want + # to support that + # the event binding would be specific to a component + # since on dispatch command overrides something like mouseClickEvent + # but the name of the command is not related to the component + # need to look at whether self.command has a value and then bind + # with ButtonMouseClickEvent.binding if that isn't already bound + # then in dispatch have to check again I think + + # need to avoid double binding + # also binding shouldn't be order-specific + # so how to avoid binding mouseDrag to _dispatch + # if mouseMove is already bound or if binding mouseMove + # not rebinding if mouseDrag is already bound + # perhaps MouseDragEvent keeps a reference to MouseMoveEvent + # and that is inserted into boundEvents, then we check boundEvents + # prior to rebinding? + if not boundEvents.get(eventClass.binding, None): + self.Bind(eventClass.binding, self._dispatch) + boundEvents[eventClass.binding] = eventClass.name + if handler: + if 0: + print " binding", self.name, eventClass.name, handler._name, eventClass.id + self.eventIdToHandler[eventClass.id] = handler + + if 0: + print "\n boundEvents:" + for name in boundEvents.values(): + print " ", name + print "\n\n" + print "\n self.eventIdToHandler:" + for id in self.eventIdToHandler: + print " ", id, self.eventIdToHandler[id]._function + print "\n\n" + # there is a good chance we will need to know + # which events are bound, if we want to dynamically add or remove + # events later, so go ahead and keep a reference to the list + self.boundEvents = boundEvents + + def _dispatch(self, aWxEvent): + eventType = aWxEvent.GetEventType() + + eventName = None + + if eventType == wx.wxEVT_TIMER: + aWxEvent.interval = aWxEvent.GetInterval() + # wxPython 2.5.1.5 workaround + # for some reason wx.TimerEvent does not contain the event target + # so we have to set it ourselves + aWxEvent.target = aWxEvent.eventObject = self + else: + try: + # all events should have GetEventObject() + # except of course for wx.TimerEvent above + # KEA 2004-04-25 + # should we remove this redundant identifier? + aWxEvent.target = aWxEvent.eventObject = self + except: + pass + # Each of these could check the event class like + # wxListEvent and wxTreeEvent above. + try: + # mouse and key events + aWxEvent.position = tuple(aWxEvent.GetPosition()) + aWxEvent.x = aWxEvent.GetX() + aWxEvent.y = aWxEvent.GetY() + aWxEvent.altDown = aWxEvent.AltDown() + aWxEvent.controlDown = aWxEvent.ControlDown() + aWxEvent.shiftDown = aWxEvent.ShiftDown() + except: + pass + try: + # key events + aWxEvent.keyCode = aWxEvent.GetKeyCode() + except: + pass + if issubclass(self.wxEventIdMap[eventType], event.CommandTypeEvent): + # could be command, so need to report the name + # for the handler if it exists + if self.command: + eventName = 'command' + elif eventType == event.MouseMoveEvent.id: + # check to see if this is a mouseDrag + if aWxEvent.Dragging(): + eventType = event.MouseDragEvent.id + # don't need this if all event types have unique ids + #eventName = event.MouseDragEvent.name + + # the component-specific helper attributes below + # should be handled in the relevant component _dispatch + # not the generic one + """ + if eventType in [wx.wxEVT_COMMAND_LIST_KEY_DOWN, + wx.wxEVT_COMMAND_TREE_KEY_DOWN]: + try: + # key events are different for wxTreeCtrl and wxListCtrl + aWxEvent.keyCode = aWxEvent.GetCode() + except: + pass + try: + # wxListEvent doesn't have GetKeyEvent for some reason + keyEvent = aWxEvent.GetKeyEvent() + aWxEvent.altDown = keyEvent.AltDown() + aWxEvent.controlDown = keyEvent.ControlDown() + aWxEvent.shiftDown = keyEvent.ShiftDown() + except: + pass + elif eventType in [wx.wxEVT_COMMAND_TREE_BEGIN_DRAG, \ + wx.wxEVT_COMMAND_TREE_BEGIN_RDRAG, \ + wx.wxEVT_COMMAND_TREE_END_DRAG, \ + wx.wxEVT_COMMAND_LIST_BEGIN_DRAG, \ + wx.wxEVT_COMMAND_LIST_BEGIN_RDRAG, \ + wx.wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, \ + wx.wxEVT_COMMAND_LIST_COL_DRAGGING, \ + wx.wxEVT_COMMAND_LIST_COL_END_DRAG]: + try: + # The mouse position during a drag event + # there doesn't appear to be a way of getting the + # state of the shift, alt, and control keys + # during a mouse drag. + aWxEvent.position = tuple(aWxEvent.GetPoint()) + aWxEvent.x = aWxEvent.position[0] + aWxEvent.y = aWxEvent.position[1] + except: + pass + """ + + if not eventName: + eventName = self.wxEventIdMap[eventType].name + + # it shouldn't be possible to be in _dispatch for an event + # that wasn't bound above, but just in case... + handler = self.eventIdToHandler.get(eventType, None) + if handler: + event.EventLog.getInstance().log(eventName, self.name, True) + if 0: + print "dispatching", handler._name + # make a lowercase alias + aWxEvent.skip = aWxEvent.Skip + + # the event handlers are part of the Background so + # we have to have a reference to call the handler below + + # if Scriptable takes over the dispatch then + # this would need to work differently if the actual + # handler could be somewhere else + + #background = self.GetParent().GetParent() + background = wx.GetTopLevelParent(self) + + # this is what is in event.py + # aHandler.getFunction()( aOwner, self.getSource(), self ) + handler.getFunction()(background, aWxEvent) + + # do we have to clean up this alias? + aWxEvent.skip = None + # how about this local reference to handler? + handler = None + background = None + else: + event.EventLog.getInstance().log(eventName, self.name, False) + # hopefully this is all we need to do for "unused events" + aWxEvent.Skip() + + # cleanup + aWxEvent.target = aWxEvent.eventObject = None + class Panel(wx.Panel): Index: event.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/event.py,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** event.py 2 May 2004 16:31:33 -0000 1.62 --- event.py 2 May 2004 19:49:56 -0000 1.63 *************** *** 403,436 **** class MoveEvent(Event): name = 'move' class SizeEvent(Event): name = 'size' class CloseEvent(Event): name = 'close' class MinimizeEvent(Event): name = 'minimize' ! class RestoreEvent(Event): name = 'restore' class MaximizeEvent(Event): name = 'maximize' class ActivateEvent(Event): name = 'activate' ! class DeactivateEvent(Event): name = 'deactivate' class IdleEvent(Event): name = 'idle' --- 403,454 ---- class MoveEvent(Event): name = 'move' + binding = wx.EVT_MOVE + id = wx.wxEVT_MOVE class SizeEvent(Event): name = 'size' + binding = wx.EVT_SIZE + id = wx.wxEVT_SIZE class CloseEvent(Event): name = 'close' + binding = wx.EVT_CLOSE + id = wx.wxEVT_CLOSE_WINDOW class MinimizeEvent(Event): name = 'minimize' + binding = wx.EVT_ICONIZE + id = wx.wxEVT_ICONIZE ! class RestoreEvent(Event, InsteadOfTypeEvent): name = 'restore' + binding = wx.EVT_ICONIZE + id = wx.NewEventType() class MaximizeEvent(Event): name = 'maximize' + binding = wx.EVT_MAXIMIZE + id = wx.wxEVT_MAXIMIZE class ActivateEvent(Event): name = 'activate' + binding = wx.EVT_ACTIVATE + id = wx.wxEVT_ACTIVATE ! class DeactivateEvent(Event, InsteadOfTypeEvent): name = 'deactivate' + binding = wx.EVT_ACTIVATE + id = wx.NewEventType() class IdleEvent(Event): name = 'idle' + binding = wx.EVT_IDLE + id = wx.wxEVT_IDLE |
From: Kevin A. <ka...@us...> - 2004-05-02 19:50:06
|
Update of /cvsroot/pythoncard/PythonCard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21950/components Modified Files: button.py passwordfield.py textarea.py textfield.py Log Message: moved _binding and _dispatch into widget.py added component specific _binding to TextField, TextArea, PasswordField switched to wx.GetApp and wx.GetTopLevelwindow added binding and id attributes to background event classes added TextArea to testevents Index: textfield.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/textfield.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** textfield.py 1 May 2004 18:47:48 -0000 1.26 --- textfield.py 2 May 2004 19:49:57 -0000 1.27 *************** *** 103,107 **** #adapter = TextFieldEventBinding(self) #adapter.bindEvents() ! self._bindEvents() def _getAlignment(self): --- 103,107 ---- #adapter = TextFieldEventBinding(self) #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS + TextFieldEvents) def _getAlignment(self): *************** *** 271,369 **** ClearAll = wx.TextCtrl.Clear ! def _bindEvents(self): ! # shouldn't components be subclasses of Scriptable? ! # components would have their own handlers but when ! # looking for a handler match it will search the parents ! # for now just grab handlers from the background ! background = self.GetParent().GetParent() ! ! # where should this check go? ! # should we just set a "global" in the app instance such as ! # self.stack.app.bindUnusedEvents ! # this kind of thing isn't going to work for Rowland's compound ! # components ! if background.stack.app._showDebugMenu: ! bindUnusedEvents = True ! else: ! bindUnusedEvents = False ! ! # helper variable to simplify test for whether to bind InsteadOfTypeEvents ! boundEvents = {} ! ! self.eventIdToHandler = {} ! self.wxEventIdMap = {} ! ! if 0: ! print "\nBINDING...", self.name ! #for eventClass in event.WIDGET_EVENTS + ButtonEvents: ! #for eventClass in ButtonEvents: ! for eventClass in event.WIDGET_EVENTS + TextFieldEvents: ! # need to figure out a way to avoid the need ! # for this id to class mapping which is used in _dispatch below ! self.wxEventIdMap[eventClass.id] = eventClass ! # command handler overrides normal mouseClick or select handler ! # so dispatch will automatically dispatch to the command handler ! # by looking up the handler this way ! # it also means that if there is a command association with this component ! # then the regular mouseClick or select handler will never be bound, just ignored ! if issubclass(eventClass, event.CommandTypeEvent) and self.command: ! handler = background.findHandler('on_' + self.command + '_command') ! if not handler: ! handler = background.findHandler('on_' + self.name + '_' + eventClass.name) ! else: ! handler = background.findHandler('on_' + self.name + '_' + eventClass.name) ! if not handler: ! handler = background.findHandler('on_' + eventClass.name) ! if handler or bindUnusedEvents: ! # only bind events that have an event handler ! # in this scenario unused events are never bound ! # which is more efficient, but the Message Watcher needs ! # to be changed ! # alternatively we can bind everything and then in _dispatch ! # if there isn't a match in eventIdToHandler then we know ! # the event isn't used and we can set used to False ! # the complication would be that we probably have to have to ! # always call Skip() which may or may not be a hassle with components ! ! # this doesn't bind command events ! # they would be of the form on_somename_command ! # or perhaps on_command but I don't think we would want ! # to support that ! # the event binding would be specific to a component ! # since on dispatch command overrides something like mouseClickEvent ! # but the name of the command is not related to the component ! # need to look at whether self.command has a value and then bind ! # with ButtonMouseClickEvent.binding if that isn't already bound ! # then in dispatch have to check again I think ! ! # need to avoid double binding ! # also binding shouldn't be order-specific ! # so how to avoid binding mouseDrag to _dispatch ! # if mouseMove is already bound or if binding mouseMove ! # not rebinding if mouseDrag is already bound ! # perhaps MouseDragEvent keeps a reference to MouseMoveEvent ! # and that is inserted into boundEvents, then we check boundEvents ! # prior to rebinding? ! if not boundEvents.get(eventClass.binding, None): ! self.Bind(eventClass.binding, self._dispatch) ! boundEvents[eventClass.binding] = eventClass.name ! if handler: ! if 0: ! print " binding", self.name, eventClass.name, handler._name, eventClass.id ! self.eventIdToHandler[eventClass.id] = handler ! ! # in order for closeField to work properly ! # both gainFocus and loseFocus have to be bound to _dispatch ! # regardless of whether they have handlers or not ! # everything else above is generic except the for statement ! # but that can be generalized once all components are bound ! # the same way ! for eventClass in [event.GainFocusEvent, event.LoseFocusEvent]: ! if not boundEvents.get(eventClass.binding, None): ! self.Bind(eventClass.binding, self._dispatch) ! boundEvents[eventClass.binding] = eventClass.name ! if 0: print "\n boundEvents:" --- 271,290 ---- ClearAll = wx.TextCtrl.Clear ! def _bindEvents(self, eventList): ! widget.Widget._bindEvents(self, eventList) ! # in order for closeField to work properly ! # both gainFocus and loseFocus have to be bound to _dispatch ! # regardless of whether they have handlers or not ! for eventClass in [event.GainFocusEvent, event.LoseFocusEvent]: ! if not self.boundEvents.get(eventClass.binding, None): ! self.Bind(eventClass.binding, self._dispatch) ! self.boundEvents[eventClass.binding] = eventClass.name + # calling widget.Widget._bindEvents after instead of before + # our component specific initialization would mean any log debug + # statements like this could just be in Widget_bindEvents + # however, until we convert all the components I'm not sure + # that changing the order will always work if 0: print "\n boundEvents:" *************** *** 375,510 **** print " ", id, self.eventIdToHandler[id]._function print "\n\n" - boundEvents = None - # this is pretty generic, but Button doesn't have any specific - # handling that is required so I need to do the same kind of code - # for TextField and see what the special handling for gainFocus, - # loseFocus, closeField will look like - # it probably won't need special handling for the key events def _dispatch(self, aWxEvent): eventType = aWxEvent.GetEventType() ! ! eventName = None ! ! if eventType == wx.wxEVT_TIMER: ! aWxEvent.interval = aWxEvent.GetInterval() ! # wxPython 2.5.1.5 workaround ! # for some reason wx.TimerEvent does not contain the event target ! # so we have to set it ourselves ! aWxEvent.target = aWxEvent.eventObject = self ! else: ! try: ! # all events should have GetEventObject() ! # except of course for wx.TimerEvent above ! # KEA 2004-04-25 ! # should we remove this redundant identifier? ! aWxEvent.target = aWxEvent.eventObject = self ! except: ! pass ! # Each of these could check the event class like ! # wxListEvent and wxTreeEvent above. try: ! # mouse and key events ! aWxEvent.position = tuple(aWxEvent.GetPosition()) ! aWxEvent.x = aWxEvent.GetX() ! aWxEvent.y = aWxEvent.GetY() ! aWxEvent.altDown = aWxEvent.AltDown() ! aWxEvent.controlDown = aWxEvent.ControlDown() ! aWxEvent.shiftDown = aWxEvent.ShiftDown() except: pass try: ! # key events ! aWxEvent.keyCode = aWxEvent.GetKeyCode() except: pass - if issubclass(self.wxEventIdMap[eventType], event.CommandTypeEvent): - # could be command, so need to report the name - # for the handler if it exists - if self.command: - eventName = 'command' - elif eventType == event.MouseMoveEvent.id: - # check to see if this is a mouseDrag - if aWxEvent.Dragging(): - eventType = event.MouseDragEvent.id - # don't need this if all event types have unique ids - #eventName = event.MouseDragEvent.name - - # TextField specific stuff - # the question is how we either call the generic stuff above - # due to the try/except blocks this code would probably - # work in the generic event handling but that would be unclean <wink> - if eventType == wx.wxEVT_SET_FOCUS: - try: - aWxEvent.target.DiscardEdits() - except: - pass - elif eventType == wx.wxEVT_KILL_FOCUS: - try: - # only wxTextCtrl and wxRightTextCtrl should have IsModified - # so an exception will be thrown and the event won't be posted - # for other components, but they shouldn't be binding to these - # handlers anyway, so I'm just be overly defensive - # same with DiscardEdits() above - #modified = obj.IsModified() - if aWxEvent.target.IsModified(): - #closeFieldEvent = aWxEvent.Clone() - #closeFieldEvent.SetEventType(event.wxEVT_CLOSE_FIELD) - # should I be using wx.PyEvent() instead? - closeFieldEvent = wx.WindowCreateEvent() - closeFieldEvent.SetEventType(wxEVT_CLOSE_FIELD) - closeFieldEvent.SetEventObject(aWxEvent.target) - closeFieldEvent.SetId(aWxEvent.GetId()) - closeFieldEvent.SetTimestamp(aWxEvent.GetTimestamp()) - # this is what Robin suggested instead, see: - # http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/1103427 - #obj.GetParent().GetEventHandler().ProcessEvent(closeFieldEvent) - # KEA 2004-04-30 - # ProcessEvent will cause closeField to occur before loseFocus and - # gainFocus messages, so should we do a wxCallAfter instead? - # in the case of fields should closeField be an InsteadOfTypeEvent - # and replace the loseFocus event? probably not since they mean - # different things - aWxEvent.target.GetEventHandler().ProcessEvent(closeFieldEvent) - #wx.PostEvent(obj.GetParent(), evt) - #print 'posted closeField' - except: - pass - - - - if not eventName: - eventName = self.wxEventIdMap[eventType].name ! # it shouldn't be possible to be in _dispatch for an event ! # that wasn't bound above, but just in case... ! handler = self.eventIdToHandler.get(eventType, None) ! if handler: ! event.EventLog.getInstance().log(eventName, self.name, True) ! if 0: ! print "dispatching", handler._name ! # make a lowercase alias ! aWxEvent.skip = aWxEvent.Skip ! ! # the event handlers are part of the Background so ! # we have to have a reference to call the handler below ! background = self.GetParent().GetParent() ! ! # this is what is in event.py ! # aHandler.getFunction()( aOwner, self.getSource(), self ) ! handler.getFunction()(background, aWxEvent) ! ! # do we have to clean up this alias? ! aWxEvent.skip = None ! # how about this local reference to handler? ! handler = None ! background = None ! else: ! event.EventLog.getInstance().log(eventName, self.name, False) ! # hopefully this is all we need to do for "unused events" ! aWxEvent.Skip() - # cleanup - aWxEvent.target = aWxEvent.eventObject = None alignment = property(_getAlignment, _setAlignment) --- 296,348 ---- print " ", id, self.eventIdToHandler[id]._function print "\n\n" def _dispatch(self, aWxEvent): eventType = aWxEvent.GetEventType() ! ! # TextField specific stuff ! # the question is how we either call the generic stuff above ! # due to the try/except blocks this code would probably ! # work in the generic event handling but that would be unclean <wink> ! if eventType == wx.wxEVT_SET_FOCUS: try: ! aWxEvent.GetEventObject().DiscardEdits() except: pass + elif eventType == wx.wxEVT_KILL_FOCUS: try: ! aWxEvent.target = aWxEvent.GetEventObject() ! # only wxTextCtrl should have IsModified ! # so an exception will be thrown and the event won't be posted ! # for other components, but they shouldn't be binding to these ! # handlers anyway, so I'm just being overly defensive ! # same with DiscardEdits() above ! #modified = obj.IsModified() ! if aWxEvent.target.IsModified(): ! #closeFieldEvent = aWxEvent.Clone() ! #closeFieldEvent.SetEventType(event.wxEVT_CLOSE_FIELD) ! # should I be using wx.PyEvent() instead? ! closeFieldEvent = wx.WindowCreateEvent() ! closeFieldEvent.SetEventType(wxEVT_CLOSE_FIELD) ! closeFieldEvent.SetEventObject(aWxEvent.target) ! closeFieldEvent.SetId(aWxEvent.GetId()) ! closeFieldEvent.SetTimestamp(aWxEvent.GetTimestamp()) ! # this is what Robin suggested instead, see: ! # http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/1103427 ! #obj.GetParent().GetEventHandler().ProcessEvent(closeFieldEvent) ! # KEA 2004-04-30 ! # ProcessEvent will cause closeField to occur before loseFocus and ! # gainFocus messages, so should we do a wxCallAfter instead? ! # in the case of fields should closeField be an InsteadOfTypeEvent ! # and replace the loseFocus event? probably not since they mean ! # different things ! aWxEvent.target.GetEventHandler().ProcessEvent(closeFieldEvent) ! #wx.PostEvent(obj.GetParent(), evt) ! #print 'posted closeField' except: pass ! # rest of the dispatch is standard ! widget.Widget._dispatch(self, aWxEvent) alignment = property(_getAlignment, _setAlignment) *************** *** 514,635 **** - class TextFieldEventBinding( event.DefaultEventBinding ) : - """ - Bind the Events supported by event.TextField to wxPython. - """ - def __init__( self, aComponent ) : - - event.DefaultEventBinding.__init__( self, aComponent ) - - def bindEvent( self, aEventClass ) : - - parent = self._component._parent - - if aEventClass is event.CloseFieldEvent : - event.EVT_CLOSE_FIELD(parent, self._component.GetId(), self._dispatch) - - if aEventClass is event.TextUpdateEvent : - wx.EVT_TEXT( parent, self._component.GetId(), self._dispatch ) - - # KEA 2001-10-05 - # I don't think this event is used in TextField ?! - #if aEventClass is TextEnterEvent : - # EVT_TEXT_ENTER( parent, self._component.GetId(), self._dispatch ) - - if aEventClass is event.KeyDownEvent : - wx.EVT_KEY_DOWN( self._component, self._dispatch ) - - if aEventClass is event.KeyUpEvent : - wx.EVT_KEY_UP( self._component, self._dispatch ) - - if aEventClass is event.KeyPressEvent : - wx.EVT_CHAR( self._component, self._dispatch ) - - def _dispatch(self, aWxEvent): - # Call our superclass to dispatch the standard mouse - # events that every widget should get. - if event.DefaultEventBinding._dispatch(self, aWxEvent): - if (aWxEvent.GetEventType() == wx.wxEVT_SET_FOCUS): - try: - aWxEvent.GetEventObject().DiscardEdits() - except: - pass - - if (aWxEvent.GetEventType() == wx.wxEVT_KILL_FOCUS): - try: - obj = aWxEvent.GetEventObject() - # only wxTextCtrl and wxRightTextCtrl should have IsModified - # so an exception will be thrown and the event won't be posted - # for other components, but they shouldn't be binding to these - # handlers anyway, so I'm just be overly defensive - # same with DiscardEdits() above - #modified = obj.IsModified() - if obj.IsModified(): - #closeFieldEvent = aWxEvent.Clone() - #closeFieldEvent.SetEventType(event.wxEVT_CLOSE_FIELD) - # should I be using wx.PyEvent() instead? - closeFieldEvent = wx.WindowCreateEvent() - closeFieldEvent.SetEventType(event.wxEVT_CLOSE_FIELD) - closeFieldEvent.SetEventObject(aWxEvent.GetEventObject()) - closeFieldEvent.SetId(aWxEvent.GetId()) - closeFieldEvent.SetTimestamp(aWxEvent.GetTimestamp()) - # this is what Robin suggested instead, see: - # http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/1103427 - #obj.GetParent().GetEventHandler().ProcessEvent(closeFieldEvent) - obj.GetEventHandler().ProcessEvent(closeFieldEvent) - #wx.PostEvent(obj.GetParent(), evt) - #print 'posted closeField' - except: - pass - return - - evt = None - - if aWxEvent.GetEventType() == event.wxEVT_CLOSE_FIELD: - #print 'handling closeField' - evt = self._createEvent(event.CloseFieldEvent, aWxEvent) - - if aWxEvent.GetEventType() == wx.wxEVT_COMMAND_TEXT_UPDATED : - evt = self._createEvent( event.TextUpdateEvent, aWxEvent ) - - #if aWxEvent.GetEventType() == wxEVT_COMMAND_TEXT_ENTER : - # event = self._createEvent( TextEnterEvent, aWxEvent ) - # this should be associated with losing focus, not textEnter - #self._component.notifyEventListeners( CloseField( self._component ) ) - - if aWxEvent.GetEventType() == wx.wxEVT_KEY_DOWN : - #print '_dispatch wxEVT_KEY_DOWN' - #evt = KeyDownEvent( self._component ) - evt = self._createEvent( event.KeyDownEvent, aWxEvent ) - - if aWxEvent.GetEventType() == wx.wxEVT_KEY_UP : - #print '_dispatch wxEVT_KEY_UP' - #evt = KeyUpEvent( self._component ) - evt = self._createEvent( event.KeyUpEvent, aWxEvent ) - - if aWxEvent.GetEventType() == wx.wxEVT_CHAR : - #print '_dispatch wxEVT_CHAR' - #evt = KeyPressEvent( self._component ) - evt = self._createEvent( event.KeyPressEvent, aWxEvent ) - - if evt is not None : - #print '_dispatch evt is not None' - self._component.notifyEventListeners( evt ) - #print "after notify" - - # KEA 2001-10-05 - # there needs to be an Event.Skip() somewhere if the event was not handled - # by user code - # however, skip should normally only be called if the user code didn't process - # the event, which will allow the user code to "eat" the event, suppressing - # and/or changing the actions of certain keys - # need to make a complete list of which events can be eaten and which can't - if not evt.getUsed(): - aWxEvent.Skip() - # KEA 2001-10-26 - # if textEnter wasn't handled then focus should move to the next - # control in the panel, just like pressing tab - - import sys from PythonCard import registry --- 352,355 ---- Index: passwordfield.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/passwordfield.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** passwordfield.py 21 Apr 2004 16:34:31 -0000 1.19 --- passwordfield.py 2 May 2004 19:49:57 -0000 1.20 *************** *** 60,65 **** self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) ! adapter = textfield.TextFieldEventBinding(self) ! adapter.bindEvents() --- 60,66 ---- self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) ! #adapter = textfield.TextFieldEventBinding(self) ! #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS + textfield.TextFieldEvents) Index: button.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/button.py,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** button.py 1 May 2004 18:47:48 -0000 1.28 --- button.py 2 May 2004 19:49:57 -0000 1.29 *************** *** 55,59 **** #adapter = ButtonEventBinding(self) #adapter.bindEvents() ! self._bindEvents() def _getDefault(self): --- 55,59 ---- #adapter = ButtonEventBinding(self) #adapter.bindEvents() ! self._bindEvents(event.WIDGET_EVENTS + ButtonEvents) def _getDefault(self): *************** *** 81,304 **** pass - def _bindEvents(self): - # shouldn't components be subclasses of Scriptable? - # components would have their own handlers but when - # looking for a handler match it will search the parents - # for now just grab handlers from the background - background = self.GetParent().GetParent() - - # where should this check go? - # should we just set a "global" in the app instance such as - # self.stack.app.bindUnusedEvents - # this kind of thing isn't going to work for Rowland's compound - # components - if background.stack.app._showDebugMenu: - bindUnusedEvents = True - else: - bindUnusedEvents = False - - # helper variable to simplify test for whether to bind InsteadOfTypeEvents - boundEvents = {} - - self.eventIdToHandler = {} - self.wxEventIdMap = {} - - if 0: - print "\nBINDING...", self.name - - for eventClass in event.WIDGET_EVENTS + ButtonEvents: - #for eventClass in ButtonEvents: - # need to figure out a way to avoid the need - # for this id to class mapping which is used in _dispatch below - self.wxEventIdMap[eventClass.id] = eventClass - # command handler overrides normal mouseClick or select handler - # so dispatch will automatically dispatch to the command handler - # by looking up the handler this way - # it also means that if there is a command association with this component - # then the regular mouseClick or select handler will never be bound, just ignored - if issubclass(eventClass, event.CommandTypeEvent) and self.command: - handler = background.findHandler('on_' + self.command + '_command') - if not handler: - handler = background.findHandler('on_' + self.name + '_' + eventClass.name) - else: - handler = background.findHandler('on_' + self.name + '_' + eventClass.name) - if not handler: - handler = background.findHandler('on_' + eventClass.name) - if handler or bindUnusedEvents: - # only bind events that have an event handler - # in this scenario unused events are never bound - # which is more efficient, but the Message Watcher needs - # to be changed - # alternatively we can bind everything and then in _dispatch - # if there isn't a match in eventIdToHandler then we know - # the event isn't used and we can set used to False - # the complication would be that we probably have to have to - # always call Skip() which may or may not be a hassle with components - - # this doesn't bind command events - # they would be of the form on_somename_command - # or perhaps on_command but I don't think we would want - # to support that - # the event binding would be specific to a component - # since on dispatch command overrides something like mouseClickEvent - # but the name of the command is not related to the component - # need to look at whether self.command has a value and then bind - # with ButtonMouseClickEvent.binding if that isn't already bound - # then in dispatch have to check again I think - - # need to avoid double binding - # also binding shouldn't be order-specific - # so how to avoid binding mouseDrag to _dispatch - # if mouseMove is already bound or if binding mouseMove - # not rebinding if mouseDrag is already bound - # perhaps MouseDragEvent keeps a reference to MouseMoveEvent - # and that is inserted into boundEvents, then we check boundEvents - # prior to rebinding? - if not boundEvents.get(eventClass.binding, None): - self.Bind(eventClass.binding, self._dispatch) - boundEvents[eventClass.binding] = eventClass.name - if handler: - if 0: - print " binding", self.name, eventClass.name, handler._name, eventClass.id - self.eventIdToHandler[eventClass.id] = handler - - if 0: - print "\n boundEvents:" - for name in boundEvents.values(): - print " ", name - print "\n\n" - print "\n self.eventIdToHandler:" - for id in self.eventIdToHandler: - print " ", id, self.eventIdToHandler[id]._function - print "\n\n" - boundEvents = None - - # this is pretty generic, but Button doesn't have any specific - # handling that is required so I need to do the same kind of code - # for TextField and see what the special handling for gainFocus, - # loseFocus, closeField will look like - # it probably won't need special handling for the key events - def _dispatch(self, aWxEvent): - eventType = aWxEvent.GetEventType() - - eventName = None - - if eventType == wx.wxEVT_TIMER: - aWxEvent.interval = aWxEvent.GetInterval() - # wxPython 2.5.1.5 workaround - # for some reason wx.TimerEvent does not contain the event target - # so we have to set it ourselves - aWxEvent.target = aWxEvent.eventObject = self - else: - try: - # all events should have GetEventObject() - # except of course for wx.TimerEvent above - # KEA 2004-04-25 - # should we remove this redundant identifier? - aWxEvent.target = aWxEvent.eventObject = self - except: - pass - # Each of these could check the event class like - # wxListEvent and wxTreeEvent above. - try: - # mouse and key events - aWxEvent.position = tuple(aWxEvent.GetPosition()) - aWxEvent.x = aWxEvent.GetX() - aWxEvent.y = aWxEvent.GetY() - aWxEvent.altDown = aWxEvent.AltDown() - aWxEvent.controlDown = aWxEvent.ControlDown() - aWxEvent.shiftDown = aWxEvent.ShiftDown() - except: - pass - try: - # key events - aWxEvent.keyCode = aWxEvent.GetKeyCode() - except: - pass - if issubclass(self.wxEventIdMap[eventType], event.CommandTypeEvent): - # could be command, so need to report the name - # for the handler if it exists - if self.command: - eventName = 'command' - elif eventType == event.MouseMoveEvent.id: - # check to see if this is a mouseDrag - if aWxEvent.Dragging(): - eventType = event.MouseDragEvent.id - # don't need this if all event types have unique ids - #eventName = event.MouseDragEvent.name - - # the component-specific helper attributes below - # should be handled in the relevant component _dispatch - # not the generic one - """ - if eventType in [wx.wxEVT_COMMAND_LIST_KEY_DOWN, - wx.wxEVT_COMMAND_TREE_KEY_DOWN]: - try: - # key events are different for wxTreeCtrl and wxListCtrl - aWxEvent.keyCode = aWxEvent.GetCode() - except: - pass - try: - # wxListEvent doesn't have GetKeyEvent for some reason - keyEvent = aWxEvent.GetKeyEvent() - aWxEvent.altDown = keyEvent.AltDown() - aWxEvent.controlDown = keyEvent.ControlDown() - aWxEvent.shiftDown = keyEvent.ShiftDown() - except: - pass - elif eventType in [wx.wxEVT_COMMAND_TREE_BEGIN_DRAG, \ - wx.wxEVT_COMMAND_TREE_BEGIN_RDRAG, \ - wx.wxEVT_COMMAND_TREE_END_DRAG, \ - wx.wxEVT_COMMAND_LIST_BEGIN_DRAG, \ - wx.wxEVT_COMMAND_LIST_BEGIN_RDRAG, \ - wx.wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, \ - wx.wxEVT_COMMAND_LIST_COL_DRAGGING, \ - wx.wxEVT_COMMAND_LIST_COL_END_DRAG]: - try: - # The mouse position during a drag event - # there doesn't appear to be a way of getting the - # state of the shift, alt, and control keys - # during a mouse drag. - aWxEvent.position = tuple(aWxEvent.GetPoint()) - aWxEvent.x = aWxEvent.position[0] - aWxEvent.y = aWxEvent.position[1] - except: - pass - """ - - if not eventName: - eventName = self.wxEventIdMap[eventType].name - - # it shouldn't be possible to be in _dispatch for an event - # that wasn't bound above, but just in case... - handler = self.eventIdToHandler.get(eventType, None) - if handler: - event.EventLog.getInstance().log(eventName, self.name, True) - if 0: - print "dispatching", handler._name - # make a lowercase alias - aWxEvent.skip = aWxEvent.Skip - - # the event handlers are part of the Background so - # we have to have a reference to call the handler below - background = self.GetParent().GetParent() - - # this is what is in event.py - # aHandler.getFunction()( aOwner, self.getSource(), self ) - handler.getFunction()(background, aWxEvent) - - # do we have to clean up this alias? - aWxEvent.skip = None - # how about this local reference to handler? - handler = None - background = None - else: - event.EventLog.getInstance().log(eventName, self.name, False) - # hopefully this is all we need to do for "unused events" - aWxEvent.Skip() - - # cleanup - aWxEvent.target = aWxEvent.eventObject = None - default = property(_getDefault, _setDefault) --- 81,84 ---- Index: textarea.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/components/textarea.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** textarea.py 21 Apr 2004 16:34:31 -0000 1.23 --- textarea.py 2 May 2004 19:49:57 -0000 1.24 *************** *** 57,60 **** --- 57,62 ---- self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) + self._bindEvents(event.WIDGET_EVENTS + textfield.TextFieldEvents) + # KEA 2004-04-20 # wxPython 2.5.1.5 workaround |
From: Kevin A. <ka...@us...> - 2004-05-02 19:50:05
|
Update of /cvsroot/pythoncard/PythonCard/samples/testevents In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21950/samples/testevents Modified Files: testevents.rsrc.py Log Message: moved _binding and _dispatch into widget.py added component specific _binding to TextField, TextArea, PasswordField switched to wx.GetApp and wx.GetTopLevelwindow added binding and id attributes to background event classes added TextArea to testevents Index: testevents.rsrc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/testevents/testevents.rsrc.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** testevents.rsrc.py 30 Apr 2004 23:02:47 -0000 1.3 --- testevents.rsrc.py 2 May 2004 19:49:57 -0000 1.4 *************** *** 1,5 **** { 'stack':{ 'type':'Stack', ! 'name':'Minimal', 'backgrounds': --- 1,5 ---- { 'stack':{ 'type':'Stack', ! 'name':'TestEvents', 'backgrounds': *************** *** 7,12 **** { 'type':'Background', 'name':'bgMin', ! 'title':'Minimal PythonCard Application', ! 'size':( 300, 120 ), 'menubar': --- 7,12 ---- { 'type':'Background', 'name':'bgMin', ! 'title':'Test Events PythonCard Application', ! 'size':( 300, 250 ), 'menubar': *************** *** 32,35 **** --- 32,40 ---- 'position':(0, 0), 'text':'Hello PythonCard' }, + { 'type':'TextArea', + 'name':'fldArea', + 'position':(0, 30), + 'size':(-1, 100), + 'text':'The quick brown fox jumped over the lazy dog.' }, { 'type':'Button', 'name':'btn', |
From: Rowland S. <mon...@us...> - 2004-05-02 16:33:05
|
Update of /cvsroot/pythoncard/PythonCard/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13362/tests Added Files: ScriptableTest.py Log Message: In progress - a unit test for the new Scriptable design. --- NEW FILE: ScriptableTest.py --- from PythonCard import event, log, component import unittest class TestHandler( component.Scriptable ) : def __init__( self, name, scriptableParent ) : component.Scriptable.__init__( self, scriptableParent ) self._name = name def on_print( self, event ) : print self._name, event def getName( self ) : return self._name class HandlerWithNoOnPrint( component.Scriptable ) : def __init__( self, name, scriptableParent ) : component.Scriptable.__init__( self, scriptableParent ) self._name = name def getName( self ) : return self._name class TestScriptable( unittest.TestCase ) : def setUp( self ) : pass def testScriptable( self ) : parent = TestHandler( 'parent', None ) child = TestHandler( 'child', parent ) parent.execute( 'on_print', ( 'howdy' ) ) child.execute( 'on_print', ( 'howdy' ) ) missing = HandlerWithNoOnPrint( 'missing', parent ) missing.execute( 'on_print', ( 'howdy' ) ) if __name__ == '__main__': unittest.main() |
From: Rowland S. <mon...@us...> - 2004-05-02 16:32:32
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13195 Modified Files: component.py Log Message: Copied model.Scriptable to component.Scriptable. Changing design to encapsulate behavior to execute a handler inside the Scriptable class. Index: component.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/component.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** component.py 21 Apr 2004 16:35:03 -0000 1.9 --- component.py 2 May 2004 16:32:23 -0000 1.10 *************** *** 4,9 **** """ ! import event, registry class AttributeSpec : --- 4,149 ---- """ ! import event, registry, log ! import inspect ! from PythonCard.event import EventLog ! ! class Scriptable: ! """ ! RDS - 2004-05-02 ! A new Scriptable that will Component will inherit from. ! In this design, the Scriptable is responsible for ! execution of it's handlers. ! ! All classes that may contain PythonCard Handler definitions ! must implement Scriptable. ! ! A Scriptable object may be specified as the parent of ! this object. The parent will be searched for Handlers ! if a Handler can't be found in this object. ! """ ! ! def __init__(self, aScriptableParent): ! self._parentScript = aScriptableParent ! self._handlers = {} ! self._parseHandlers() ! if False: ! print "Scriptable init", self._handlers.keys() ! ! def _parseHandlers(self): ! """ ! Find all of the methods in this object that are ! PythonCard handlers, and register them. ! """ ! ! # KEA 2004-03-05 ! # an even slicker way of finding event handlers ! # using the inspect module ! pythoncardMethods = [] ! methods = inspect.getmembers(self.__class__, inspect.ismethod) ! for m in methods: ! if m[0].split('_')[0] == 'on': ! pythoncardMethods.append(m[1]) ! print pythoncardMethods ! ! map(self._addHandler, pythoncardMethods) ! ! def _isPythonCardHandler(self, aObject): ! """ ! Return true if the object is a PythonCard handler. ! """ ! print 'found handler', aObject ! return isinstance(aObject, types.FunctionType) and aObject.__name__.split('_')[0] == 'on' ! ! def _addHandler(self, aMethod): ! # Add the Handler to our Handler list. ! if aMethod.__name__ not in self._handlers: ! log.debug("_addHandler: " + aMethod.__name__) ! self._handlers[aMethod.__name__] = event.Handler(aMethod) ! ! """ ! RDS - Never gets called - Remove. ! ! def addMethod(self, aFunction): ! if isinstance(aFunction, types.FunctionType): ! if self._isPythonCardHandler(aFunction) : ! #aMethod = new.instancemethod(aFunction, self, self.__class__) ! aMethod = new.instancemethod(aFunction, None, self.__class__) ! #print aFunction ! #print self.__class__ ! #print aMethod.__name__ ! #print aMethod ! self.__class__.__dict__[aMethod.__name__] = aMethod ! # now add the method info to our handler lookup dictionary ! # KEA 2001-11-29 simplified _addHandler ! #handler = event.Handler(aMethod.__name__, aMethod) ! #self._addHandler(aMethod.__name__, handler) ! self._addHandler(aMethod) ! """ ! ! def _findHandler(self, aString): ! """ ! Look for a Handler that matches aString in our ! list of Handlers. If a Handler is not found, ! ask our parent script to look for the Handler, ! continuing up the Scriptable hierarchy until ! either a Handler is found, or None is returned. ! """ ! # KEA 2004-04-26 ! # findHandler is actually called for each event dispatch ! # depending on the level of dynamic code we think we're going ! # to have it might be simpler to just statically bind when ! # the component is created ! if True: ! print "findHandler", aString, self ! handler = self._handlers.get(aString, None) + if handler: + return self, handler + + # We couldn't find a handler, so look in our parent. + if self._parentScript: + print 'looking for handler in parent', self._parentScript + script, handler = self._parentScript._findHandler( aString ) + + # have we found a Handler yet? + if handler: + return script, handler + + # Change the handler name to target this Scriptable object + # and look in our list of Handlers. + + words = aString.split('_') + #print words, self._getName() + #if len(words) == 2: + # print words + # aString = words[ 0 ] + '_' + words[ 1 ] + #else: + aString = words[0] + '_' + self.getName() + '_' + words[len(words) - 1] + temp = self._handlers.get(aString, None) + if temp: + return ( self, temp ) + else: + # search for Background and Stack handlers like + # on_mouseClick, on_initialize + aString = words[0] + '_' + words[len(words) - 1] + return self._handlers.get(aString, None) + + def execute( self, handlerName, event ) : + """ + RDS - 2004-05-02 + Find the handler that matches handlerName and + execute it. + Should we throw an exception if the handlerName + is not found? The caller would be responsible + for reporting a missing handler as an error. + """ + print 'finding handler', handlerName + script, handler = self._findHandler( handlerName ) + if handler is not None : + print script, handler + handler.execute( script, event ) + EventLog.getInstance().log( event, handler.getSourceName(), True ) + + class AttributeSpec : |