|
From: Kevin A. <ka...@us...> - 2004-10-20 22:15:17
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25457 Modified Files: component.py Log Message: cleanup import and extra spacing around parens and colon Index: component.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/component.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** component.py 5 May 2004 03:51:53 -0000 1.12 --- component.py 20 Oct 2004 22:15:07 -0000 1.13 *************** *** 5,22 **** import event, registry, log ! import inspect ! 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 --- 5,21 ---- import event, registry, log ! import inspect ! 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 *************** *** 27,35 **** it as *not* used. """ ! def execute( self, name, event ) : ! EventLog.getInstance().log( event, '(not handled)', False ) ! class Scriptable( IScriptable ) : """ RDS - 2004-05-02 --- 26,34 ---- it as *not* used. """ ! def execute(self, name, event): ! event.EventLog.getInstance().log(event, '(not handled)', False) ! class Scriptable(IScriptable): """ RDS - 2004-05-02 *************** *** 45,50 **** if a EventHandler can't be found in this object. """ ! def __init__( self, parent=None ) : ! if parent is None : parent = NullScriptable() self._parent = parent --- 44,49 ---- if a EventHandler can't be found in this object. """ ! def __init__(self, parent=None): ! if parent is None: parent = NullScriptable() self._parent = parent *************** *** 52,56 **** self._parseHandlers() ! def _parseHandlers( self ) : """ Find all of the methods in this object that are --- 51,55 ---- self._parseHandlers() ! def _parseHandlers(self): """ Find all of the methods in this object that are *************** *** 58,104 **** """ 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 --- 57,103 ---- """ 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 *************** *** 113,126 **** 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 ) ! class AttributeSpec : def __init__(self, name, properties): --- 112,125 ---- a missing handler as an error. """ ! handler = self._findHandler(name) ! if handler is not None: ! handler.execute(event) ! event.EventLog.getInstance().log(event, handler.getSourceName(), True) ! else: ! self._parent.execute(name, event) ! class AttributeSpec: def __init__(self, name, properties): *************** *** 137,175 **** # PUBLIC METHODS ! def getName( self ) : return self.name ! def isRequired( self ) : return self.presence is 'mandatory' ! def isOptional( self ) : return self.presence is 'optional' ! def getDefaultValue( self ) : return self.default ! def hasDefaultValueList( self ) : return self.values is not None ! def getDefaultValueList( self ) : return self.values ! class BaseSpec : ! def __init__( self, aDictionary ) : self._name = aDictionary[ 'name' ] self._parent = None self._events = aDictionary[ 'info' ][ 'events' ] ! self._attributes = self._parseAttributes( aDictionary[ 'info' ][ 'attributes' ] ) self._requiredAttributes = self._parseRequiredAttributes() self._optionalAttributes = self._parseOptionalAttributes() ! def getName( self ) : return self._name ! def getParent( self ) : return self._parent ! def getEvents( self ) : return self._events --- 136,174 ---- # PUBLIC METHODS ! def getName(self): return self.name ! def isRequired(self): return self.presence is 'mandatory' ! def isOptional(self): return self.presence is 'optional' ! def getDefaultValue(self): return self.default ! def hasDefaultValueList(self): return self.values is not None ! def getDefaultValueList(self): return self.values ! class BaseSpec: ! def __init__(self, aDictionary): self._name = aDictionary[ 'name' ] self._parent = None self._events = aDictionary[ 'info' ][ 'events' ] ! self._attributes = self._parseAttributes(aDictionary[ 'info' ][ 'attributes' ]) self._requiredAttributes = self._parseRequiredAttributes() self._optionalAttributes = self._parseOptionalAttributes() ! def getName(self): return self._name ! def getParent(self): return self._parent ! def getEvents(self): return self._events *************** *** 180,190 **** return eventNames ! def getAttributes( self ) : return self._attributes ! def getRequiredAttributes( self ) : return self._requiredAttributes ! def getOptionalAttributes( self ) : return self._optionalAttributes --- 179,189 ---- return eventNames ! def getAttributes(self): return self._attributes ! def getRequiredAttributes(self): return self._requiredAttributes ! def getOptionalAttributes(self): return self._optionalAttributes *************** *** 213,223 **** return optional ! def __repr__( self ) : ! return str( self.__dict__ ) ! class ComponentSpec( BaseSpec ) : ! def __init__( self, name, parent, events, subclassAttributes ): # RDS - we should be calling BaseSpec.__init__(). # this is pretty messy. --- 212,222 ---- return optional ! def __repr__(self): ! return str(self.__dict__) ! class ComponentSpec(BaseSpec): ! def __init__(self, name, parent, events, subclassAttributes): # RDS - we should be calling BaseSpec.__init__(). # this is pretty messy. *************** *** 226,231 **** self._events = events attributes = { ! 'name' : { 'presence' : 'mandatory' }, ! 'command' : { 'presence' : 'optional', 'default' : None } } attributes.update(subclassAttributes) --- 225,230 ---- self._events = events attributes = { ! 'name': { 'presence': 'mandatory' }, ! 'command': { 'presence': 'optional', 'default': None } } attributes.update(subclassAttributes) *************** *** 235,291 **** ! class Component( event.EventSource ) : """ The superclass of all PythonCard components. ! Components can be visual ( extend Widget ) or ! non-visual ( extend Component ). """ _spec = None ! def getEvents( self ) : """ A convenience method to get the event classes for this component. """ ! return ComponentClassInspector( self.__class__ ).getEvents() ! def __init__( self ) : ! event.EventSource.__init__( self ) ! class ComponentInspector : """ Provides an api for introspection on Component instances. """ ! def __init__( self, component ) : self.componentClass = component.__class__ ! def getAttributes( self ) : return self.componentClass._spec.getAttributes() ! def getEvents( self ) : return self.componentClass._spec.getEvents() ! class ComponentClassInspector : """ Provides an api for introspection on Component classes. """ ! def __init__( self, componentClass ) : self.componentClass = componentClass ! def getAttributes( self ) : return self.componentClass._spec.getAttributes() ! def getEvents( self ) : return self.componentClass._spec.getEvents() ! class ComponentFactory : """ An abstract factory for creating Widgets from a Resource description. """ ! def createComponent( self, aScriptable, aParent, aResource ) : """ Find the class object based on a component's Resource definition. --- 234,290 ---- ! class Component(event.EventSource): """ The superclass of all PythonCard components. ! Components can be visual (extend Widget) or ! non-visual (extend Component). """ _spec = None ! def getEvents(self): """ A convenience method to get the event classes for this component. """ ! return ComponentClassInspector(self.__class__).getEvents() ! def __init__(self): ! event.EventSource.__init__(self) ! class ComponentInspector: """ Provides an api for introspection on Component instances. """ ! def __init__(self, component): self.componentClass = component.__class__ ! def getAttributes(self): return self.componentClass._spec.getAttributes() ! def getEvents(self): return self.componentClass._spec.getEvents() ! class ComponentClassInspector: """ Provides an api for introspection on Component classes. """ ! def __init__(self, componentClass): self.componentClass = componentClass ! def getAttributes(self): return self.componentClass._spec.getAttributes() ! def getEvents(self): return self.componentClass._spec.getEvents() ! class ComponentFactory: """ An abstract factory for creating Widgets from a Resource description. """ ! def createComponent(self, aScriptable, aParent, aResource): """ Find the class object based on a component's Resource definition. *************** *** 296,304 **** reggie = registry.Registry.getInstance() ! clazz = reggie.getComponentClass( aResource.__dict__['type'] ) # Construct a new Component. ! component = clazz( aParent, aResource ) # KEA 2004-04-20 --- 295,303 ---- reggie = registry.Registry.getInstance() ! clazz = reggie.getComponentClass(aResource.__dict__['type']) # Construct a new Component. ! component = clazz(aParent, aResource) # KEA 2004-04-20 |