|
From: Kevin A. <ka...@us...> - 2004-04-27 06:07:56
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12639 Modified Files: model.py Log Message: removed findId, getIDbyName, getObjectByName replaced findLocalHandler with dictionary lookup Index: model.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/model.py,v retrieving revision 1.159 retrieving revision 1.160 diff -C2 -d -r1.159 -r1.160 *** model.py 27 Apr 2004 01:40:29 -0000 1.159 --- model.py 27 Apr 2004 06:07:48 -0000 1.160 *************** *** 250,257 **** # moved colourdb initialization to work with wxPython 2.5 # which requires a wxApp instance to exist before using colourdb - ###colourdb.updateColourDB() # KEA 2001-07-27 wx.InitAllImageHandlers() wx.App.__init__(self, 0) ! colourdb.updateColourDB() # KEA 2001-07-27 --- 250,256 ---- # moved colourdb initialization to work with wxPython 2.5 # which requires a wxApp instance to exist before using colourdb wx.InitAllImageHandlers() wx.App.__init__(self, 0) ! colourdb.updateColourDB() *************** *** 264,268 **** position, size, parentApp=self) - #self.pw.displayComponents(self._iterator.getCurrentBackground().findAllComponents()) self.pw.displayComponents(bg.components) self.pw.Show(self._showProperties) --- 263,266 ---- *************** *** 403,415 **** """ return isinstance(aObject, types.FunctionType) and aObject.__name__.split('_')[0] == 'on' - - # KEA 2001-09-07 - # I don't see much benefit to caching the handler list, it seems - # like it would be much simpler to parse the dictionary each time - # which will have a slight drop in efficiency, but greatly simplifies - # the code, since the handlers dictionary goes away and doesn't need - # to be kept in sync - # I made the change to findLocalHandler below, but left the old _handler - # code in until we know we don't need it def _addHandler(self, aMethod): --- 401,404 ---- *************** *** 443,459 **** either a Handler is found, or None is returned. """ ! handler = self.findLocalHandler( aString ) ! if handler is not None : return handler # We couldn't find a handler, so look in our parent. ! if self._parentScript is not None : handler = self._parentScript.findHandler( aString ) # have we found a Handler yet? ! if handler is not None : return handler --- 432,455 ---- 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 False: ! print "findHandler", aString, self ! handler = self._handlers.get(aString, None) ! if handler: return handler # We couldn't find a handler, so look in our parent. ! if self._parentScript: handler = self._parentScript.findHandler( aString ) # have we found a Handler yet? ! if handler: return handler *************** *** 469,474 **** #else: aString = words[0] + '_' + self.getName() + '_' + words[len(words) - 1] ! temp = self.findLocalHandler( aString ) ! if temp is not None: return temp else: --- 465,470 ---- #else: aString = words[0] + '_' + self.getName() + '_' + words[len(words) - 1] ! temp = self._handlers.get(aString, None) ! if temp: return temp else: *************** *** 476,514 **** # on_mouseClick, on_initialize aString = words[0] + '_' + words[len(words) - 1] ! return self.findLocalHandler( aString ) ! ! def findLocalHandler( self, aString ) : ! """ ! Look for a Handler in our list of Handlers only. ! KEA 2001-09-07 ! This version doesn't use a _handlers dictionary anymore ! it dynamically searches the current dictionary. ! I left the old _handlers initialization above in case ! we need to go back to it. ! """ ! """ ! aClass = self.__class__ ! for key in aClass.__dict__.keys() : ! value = aClass.__dict__[ key ] ! if isinstance(value, types.FunctionType): ! if self._isHandler( value ) : ! if value.__name__ == aString : ! return Handler( value.__name__, value ) ! ! """ - """ - for key in self._handlers.keys() : - handler = self._handlers[ key ] - if handler.getName() == aString : - return handler - return None - """ - # KEA 2001-11-29 this should be equivelant to the above loop - if aString in self._handlers: - return self._handlers[aString] - else: - return None - class Stack( event.Changeable, Scriptable ) : --- 472,477 ---- # on_mouseClick, on_initialize aString = words[0] + '_' + words[len(words) - 1] ! return self._handlers.get(aString, None) class Stack( event.Changeable, Scriptable ) : *************** *** 943,963 **** def _bindWindowEvents( self ) : wx.EVT_WINDOW_DESTROY(self, self.OnDestroy) - - def findId( self, targetPath ) : - # Find the widget that matches the name - # identified in targetPath. - return self.getIDbyName( targetPath ) - - def getIDbyName( self, widgetName ) : - try: - return self.components[ widgetName ].GetId() - except: - return -1 - - def getObjectByName( self, widgetName ) : - try: - return self.components[ widgetName ] - except: - return -1 # def postEvent( self, aEvent ) : --- 906,909 ---- *************** *** 1011,1014 **** --- 957,968 ---- self.close(True) + # KEA 2004-04-26 + # why do we need the methods below?! + # what is the use case for them? + # findComponentsByClass has some value + # but any app that needs it can easily do the method itself + # I blew away the same methods in CustomDialog + # getComponent, getComponents, findAllComponents, findComponentsByClass + # RDS = new API def getComponent( self, path ) : *************** *** 1047,1061 **** # we may want to put this someplace else, but we do need access # to the componenet list ! def findFocus( self ): ! widgetWX = wx.Window_FindFocus() # the wxPython widget that has focus if widgetWX is None: return None else: ! id = widgetWX.GetId() ! components = self.findAllComponents() ! for widget in components: ! if id == widget.GetId(): return widget ! return None # is this even possible? focus in another window maybe? # KEA 2004-03-17 --- 1001,1015 ---- # we may want to put this someplace else, but we do need access # to the componenet list ! def findFocus(self): ! # the wxPython widget that has focus ! widgetWX = wx.Window_FindFocus() if widgetWX is None: return None else: ! for widget in self.components.itervalues(): ! if widgetWX == widget: return widget ! # is this even possible? focus in another window maybe? ! return None # KEA 2004-03-17 *************** *** 1210,1268 **** pass - - def findId( self, targetPath ) : - # Find the widget that matches the name - # identified in targetPath. - return self.getIDbyName( targetPath ) - - - def getIDbyName( self, widgetName ) : - try: - return self.components[ widgetName ].GetId() - except: - return -1 - - def getObjectByName( self, widgetName ) : - try: - return self.components[ widgetName ] - except: - return -1 - - - def findAllComponents( self ) : - """ - Return a copy of the list of Components in this - Background. We're not just returning - self.components.values because we don't want - someone to inadvertently whack the internal list - of Components. - """ - components = [] - for component in self.components.itervalues() : - components.append( component ) - return components - - def findComponentsByClass( self, aComponentClass ) : - """ - Return a list of Component's that are instances - of the specified Component class. - """ - components = [] - for component in self.components.itervalues() : - if isinstance( component, aComponentClass ) : - components.append( component ) - return components - # KEA 2001-07-31 # we may want to put this someplace else, but we do need access # to the componenet list ! def findFocus( self ): ! widgetWX = wx.Window_FindFocus() # the wxPython widget that has focus ! id = widgetWX.GetId() ! components = self.findAllComponents() ! for widget in components: ! if id == widget.GetId(): return widget ! return None # is this even possible? focus in another window maybe? # these shouldn't be necessary --- 1164,1178 ---- pass # KEA 2001-07-31 # we may want to put this someplace else, but we do need access # to the componenet list ! def findFocus(self): ! # the wxPython widget that has focus ! widgetWX = wx.Window_FindFocus() ! for widget in self.components.itervalues(): ! if widgetWx == widget: return widget ! # is this even possible? focus in another window maybe? ! return None # these shouldn't be necessary |