From: Arlo B. <abe...@us...> - 2004-12-31 20:44:19
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23112 Modified Files: component.py menu.py widget.py Log Message: * Refactored some attributes from Widget up to Component. In particular, Component's spec called for name and command, yet the properties to hold these were specified only at Widget. This made it impossible to inherit directly from Component and still be instantiated via the resources. I also moved the actionBindings up from Widget to Component, as they make more sense there. Component is now clearly "anything that can be manipulated as a resource (and instantiated via a .rsrc.py)", while Widget is "anything with a user interface (a size and a position describing where it can draw)". All Widgets are Components - we want to be able to instantiate any GUI element from the resource file. In the experimentalResourceEditor branch, I fixed a number of bugs that prevented the resource editor from dealing with Components that are not Widgets. The experimentalResourceEditor now fully handles UI-less Components (you can edit their properties via the PropertyEditor, but they don't appear in the ResourceEditor pane). AB Index: widget.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/widget.py,v retrieving revision 1.134 retrieving revision 1.135 diff -C2 -d -r1.134 -r1.135 *** widget.py 24 Oct 2004 19:43:31 -0000 1.134 --- widget.py 31 Dec 2004 20:44:09 -0000 1.135 *************** *** 34,49 **** 'position' : { 'presence' : 'optional', 'default' : [ -1, -1 ] }, 'size' : { 'presence' : 'optional', 'default' : [ -1, -1 ] }, - 'actionBindings' : {'presence':'optional', 'default':None}, 'userdata' : {'presence':'optional', 'default':''} } attributes.update(subclassAttributes) component.ComponentSpec.__init__( self, name, parent, events, attributes ) - - def getMinimalResourceDict(self, name): - """ - Class method that returns the minimal resource dictionary needed to create a component. - The spec will provide the optional attributes when the Resource is created. - """ - return {'type':self.getName(), 'name':name} --- 34,41 ---- *************** *** 60,73 **** def __init__(self, aParent, aResource): ! component.Component.__init__(self) self._parent = aParent self._resource = aResource - self._name = aResource.name self._setUserdata(self._resource.userdata) - if self._resource.actionBindings is None: - self._setActionBindings(dict()) - else: - self._setActionBindings(dict(self._resource.actionBindings.__dict__)) - self._setCommand(self._resource.command) # KEA 2004-04-23 # Controls are enabled and visible by default --- 52,59 ---- def __init__(self, aParent, aResource): ! component.Component.__init__(self, aResource) self._parent = aParent self._resource = aResource self._setUserdata(self._resource.userdata) # KEA 2004-04-23 # Controls are enabled and visible by default *************** *** 107,116 **** def getParent(self): return self.GetParent() - - def _getName(self): - return self._name - - def _setName(self, aString): - raise AttributeError, "name attribute is read-only" def _getToolTip(self): --- 93,96 ---- *************** *** 149,158 **** self.SetFont( aWxFont ) - def _getActionBindings(self): - return self._actionBindings - - def _setActionBindings(self, actionDict): - self._actionBindings = actionDict - def _getUserdata(self): return self._userdata --- 129,132 ---- *************** *** 161,170 **** self._userdata = aString - def _setCommand( self, aString ) : - self._command = aString - - def _getCommand( self ) : - return self._command - def _getDefaultColor( self, aColor ) : if aColor is None : --- 135,138 ---- *************** *** 229,243 **** # set the property as well so the appropriate method gets used backgroundColor = property(_getBackgroundColor, _setBackgroundColor) - command = property(_getCommand, _setCommand) font = property(_getFont, _setFont) foregroundColor = property(_getForegroundColor, _setForegroundColor) enabled = property(_getEnabled, _setEnabled) id = property(_getId, _setId) - name = property(_getName, _setName) #position = property(wx.Window.GetPositionTuple, wx.Window.Move) position = property(_getPosition, _setPosition) size = property(_getSize, _setSize) toolTip = property(_getToolTip, _setToolTip) - actionBindings = property(_getActionBindings, _setActionBindings) userdata = property(_getUserdata, _setUserdata) visible = property(_getVisible, _setVisible) --- 197,208 ---- Index: component.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/component.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** component.py 20 Oct 2004 22:15:07 -0000 1.13 --- component.py 31 Dec 2004 20:44:09 -0000 1.14 *************** *** 226,230 **** attributes = { 'name': { 'presence': 'mandatory' }, ! 'command': { 'presence': 'optional', 'default': None } } attributes.update(subclassAttributes) --- 226,231 ---- attributes = { 'name': { 'presence': 'mandatory' }, ! 'command': { 'presence': 'optional', 'default': None }, ! 'actionBindings' : {'presence':'optional', 'default':None} } attributes.update(subclassAttributes) *************** *** 233,236 **** --- 234,244 ---- self._optionalAttributes = self._parseOptionalAttributes() + def getMinimalResourceDict(self, name): + """ + Class method that returns the minimal resource dictionary needed to create a component. + The spec will provide the optional attributes when the Resource is created. + """ + return {'type':self.getName(), 'name':name} + class Component(event.EventSource): *************** *** 240,244 **** non-visual (extend Component). """ ! _spec = None def getEvents(self): --- 248,252 ---- non-visual (extend Component). """ ! _spec = ComponentSpec def getEvents(self): *************** *** 247,253 **** """ return ComponentClassInspector(self.__class__).getEvents() ! ! def __init__(self): event.EventSource.__init__(self) --- 255,299 ---- """ return ComponentClassInspector(self.__class__).getEvents() ! ! def __init__(self, aResource): event.EventSource.__init__(self) + self._name = aResource.name + self._setCommand(aResource.command) + if getattr(aResource, 'actionBindings', None): + self._setActionBindings(dict(aResource.actionBindings.__dict__)) + else: + self._setActionBindings(dict()) + + def Lower(self): + pass + + def _getName(self): + return self._name + + def _setName(self, aString): + raise AttributeError, "name attribute is read-only" + + def _setCommand( self, aString ) : + self._command = aString + + def _getCommand( self ) : + return self._command + + def _getActionBindings(self): + return self._actionBindings + + def _setActionBindings(self, actionDict): + self._actionBindings = actionDict + + name = property(_getName, _setName) + command = property(_getCommand, _setCommand) + actionBindings = property(_getActionBindings, _setActionBindings) + + + def registerAsComponent(pythonClass, attributes={}): + pythonClass._spec = ComponentSpec(pythonClass.__name__, 'Component', list(), attributes) + import sys + from PythonCard import registry + registry.Registry.getInstance().register(pythonClass) Index: menu.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/menu.py,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** menu.py 14 Sep 2004 23:37:19 -0000 1.39 --- menu.py 31 Dec 2004 20:44:09 -0000 1.40 *************** *** 51,55 **** def __init__(self, aScriptable, aParent, aResource): - self.name = aResource.name self.label = aResource.label self.command = aResource.command --- 51,54 ---- *************** *** 80,84 **** ! component.Component.__init__( self ) self._bindEvents((MenuSelectEvent,), aScriptable, id) --- 79,83 ---- ! component.Component.__init__(self, aResource) self._bindEvents((MenuSelectEvent,), aScriptable, id) |