dabo Commit
Revision 1400
Date: 2005-10-04 11:14:51 -0700 (Tue, 04 Oct 2005)
Author: paul

Changed:
U   trunk/dabo/common/dObject.py
U   trunk/dabo/common/eventMixin.py
U   trunk/dabo/common/propertyHelperMixin.py
U   trunk/dabo/dEvents.py
U   trunk/dabo/lib/datanav/Form.py

Log:
Modified getPropertyList(), and added getMethodList() and getEventList().
These functions all return a sorted list of available PEMS for the object,
from the point of view of the user. IOW, nothing starting with _ is 
included, and for properties and events, only uppercase first letters 
are included. For methods, only lowercase first letters are included.

TODO: make those methods private (_getPropertyList(), etc.)

Changed getPropertyInfo's "show/editInDesigner" keys to "readable" and
"writable". I have a small change to daboide to fix this change there as
well, and will commit next. Removed the editorInfo key as it is unused.

TODO: remove the getEditorInfo() functions from the various objects that
still have them, if any.

Added getApiDoc() function to dObject, which returns a single-page HTML
documentation of the object. For now, all it does is display a list of
PEM's, with bold-face on the items that are defined in this class, and
normal-face for those items defined in superclasses.

Fixed some typos in dEvents that became exposed during my testing of the 
above.

I'm not sure about the ultimate location for getApiDoc... perhaps it really
doesn't belong directly in dObject but in a separate documentation utility.
But it is a good start. Try it:

import dabo
dabo.ui.loadUI("wx")

testobj = dabo.ui.dGrid

html = testobj.getApiDoc()
f = open("/home/pmcnett/test.html", "w")
f.write(html)
f.close()




Diff:
Modified: trunk/dabo/common/dObject.py
===================================================================
--- trunk/dabo/common/dObject.py        2005-10-03 23:18:08 UTC (rev 1399)
+++ trunk/dabo/common/dObject.py        2005-10-04 18:14:51 UTC (rev 1400)
@@ -1,3 +1,5 @@
+import string
+import types
 import dabo
 from dabo.common import PropertyHelperMixin
 from dabo.common import DoDefaultMixin
@@ -126,19 +128,83 @@
                return '.'.join(names)
 
                
-       def getValidEvents(self):
-               """Returns a list of valid Dabo events for this object.
-               """
-               import dabo.dEvents as e  # imported here to avoid circular 
import 
-               validEvents = []
-               events = [e.__dict__[evt] for evt in dir(e)]
-               for evt in events:
-                       if type(evt) == type and issubclass(evt, e.Event):
-                               if evt.appliesToClass(self.__class__):
-                                       validEvents.append(evt)
-               return validEvents
+       def getMethodList(cls):
+               """Return the list of (Dabo) methods for this class or 
instance."""
+               try:
+                       methodList = cls.__methodList
+               except:
+                       methodList = None
+
+               if isinstance(methodList, list):
+                       ## A prior call has already generated the methodList
+                       return methodList
+
+               methodList = []
+               for c in cls.__mro__:
+                       for item in dir(c):
+                               if item[0] in string.lowercase:
+                                       if c.__dict__.has_key(item):
+                                               if type(c.__dict__[item]) in 
(types.MethodType, types.FunctionType):
+                                                       if 
methodList.count(item) == 0:
+                                                               
methodList.append(item)
+               methodList.sort()
+               cls.__methodList = methodList
+               return methodList
+       getMethodList = classmethod(getMethodList)
+
+
+       def getApiDoc(cls, outputType="html-single"):
+               PEM_COLUMNS = float(3)  ## float simply for round() to work 
right
+
+               className = cls.__name__
+               classDoc = cls.__doc__
+               if classDoc is None:
+                       classDoc = ""
+               classDoc = "<br>".join(classDoc.split("\n"))
+
+               html = """
+<h1>Class %(className)s</h1>
+<p>%(classDoc)s</p>
+<hr>
+""" % locals()
+
+               def getListing(name, items):
+                       html = """
+<h2>%(name)s</h2>
+<table width="100%%" cellpadding="5" cellspacing="0" border="0">
+""" % locals()
+
+                       for idx, item in enumerate(items):
+                               definedHere = (cls.__dict__.has_key(item))
+                               if idx % PEM_COLUMNS == 0:
+                                       if idx > 0:
+                                               html += """     </tr>
+"""
+                                       html += """     <tr>
+"""
+                               if definedHere:
+                                       html += """             <td><b><a 
href="#prop_%(item)s">%(item)s</a></b></td>
+""" % locals()
+                               else:
+                                       html += """             <td><a 
href="#prop_%(item)s">%(item)s</a></td>
+""" % locals()
+
+                       html += """
+       </tr>
+</table>
+<hr>
+"""
+                       return html
                
-               
+               # Property, Event, Method Listings:
+               html += getListing("Properties", cls.getPropertyList())
+               html += getListing("Events", cls.getEventList())
+               html += getListing("Methods", cls.getMethodList())
+
+               return html
+       getApiDoc = classmethod(getApiDoc)
+
+
        def _getBaseClass(self):
                # Every Dabo baseclass must set self._baseClass explicitly, to 
itself. For instance:
                #       class dBackend(object)

Modified: trunk/dabo/common/eventMixin.py
===================================================================
--- trunk/dabo/common/eventMixin.py     2005-10-03 23:18:08 UTC (rev 1399)
+++ trunk/dabo/common/eventMixin.py     2005-10-04 18:14:51 UTC (rev 1400)
@@ -1,3 +1,4 @@
+import string
 import types
 import traceback
 import dabo
@@ -3,4 +4,5 @@
 from dabo.dLocalize import _
 
+
 class EventMixin(object):
        """Mix-in class making objects know how to bind and raise Dabo events.
@@ -227,6 +229,38 @@
                                        self.bindEvent(evtObj, funcObj)
 
 
+       def getEventList(cls):
+               """Return a list of valid Dabo event names for this object."""
+               el = cls.getValidEvents()
+               el = [e.__name__ for e in el if e.__name__[0] in 
string.uppercase]
+               el.sort()
+               return el
+       getEventList = classmethod(getEventList)
+
+
+       def getValidEvents(cls):
+               """Returns a list of valid Dabo event classes for this object.
+
+               The cls parameter can actually be either a class or self.
+               """
+               classRef = cls
+               try:
+                       issubclass(cls, object)
+               except TypeError:
+                       # we are an instance, cls is self.
+                       classRef = cls.__class__
+
+               import dabo.dEvents as e  # imported here to avoid circular 
import 
+               validEvents = []
+               events = [e.__dict__[evt] for evt in dir(e)]
+               for evt in events:
+                       if type(evt) == type and issubclass(evt, e.Event):
+                               if evt.appliesToClass(classRef):
+                                       validEvents.append(evt)
+               return validEvents
+       getValidEvents = classmethod(getValidEvents)
+
+
        # Allow for alternate capitalization (deprecated):
        unBindEvent = unbindEvent
        

Modified: trunk/dabo/common/propertyHelperMixin.py
===================================================================
--- trunk/dabo/common/propertyHelperMixin.py    2005-10-03 23:18:08 UTC (rev 
1399)
+++ trunk/dabo/common/propertyHelperMixin.py    2005-10-04 18:14:51 UTC (rev 
1400)
@@ -1,5 +1,7 @@
+import string
 from dabo.dLocalize import _
 
+
 class PropertyHelperMixin(object):
        """ Helper functions for getting information on class properties.
        """
@@ -43,6 +45,7 @@
                                raise ValueError, s
                return value
 
+
        def extractKeywordProperties(self, kwdict, propdict):
                """ Called from __init__: puts any property keyword arguments 
into
                the property dictionary, so that __init__ can pass that dict to 
@@ -196,12 +199,11 @@
                                        raise ValueError, "Could not set 
property '%s' to value: %s" % (prop, val)
                
                        
-       def getPropertyList(classOrInstance):
+       def getPropertyList(cls):
                """ Returns the list of properties for this object (class or 
instance).
                """
-               ## pkm: check out revision 927 if you have problems.
                try:
-                       propList = classOrInstance.__propList
+                       propList = cls.__propList
                except:
                        propList = None
 
@@ -210,60 +212,61 @@
                        return propList
 
                propList = []
-               for c in classOrInstance.__mro__:
+               for c in cls.__mro__:
                        for item in dir(c):
-                               if c.__dict__.has_key(item):
-                                       if type(c.__dict__[item]) == property:
-                                               if propList.count(item) == 0:
-                                                       propList.append(item)
-               classOrInstance.__propList = propList
+                               if item[0] in string.uppercase:
+                                       if c.__dict__.has_key(item):
+                                               if type(c.__dict__[item]) == 
property:
+                                                       if propList.count(item) 
== 0:
+                                                               
propList.append(item)
+               propList.sort()
+               cls.__propList = propList
                return propList
        getPropertyList = classmethod(getPropertyList)
 
 
-       def getPropertyInfo(self, name):
+       def getPropertyInfo(cls, name):
                """ Returns a dictionary of information about the passed 
property name.
                """
-               propRef = eval("self.__class__.%s" % name)
+               # cls can be either a class or self
+               classRef = cls
+               try:
+                       issubclass(cls, object)
+               except TypeError:
+                       classRef = cls.__class__
+
+               propRef = getattr(classRef, name)
                if type(propRef) == property:
                        if propRef.fget is None:
                                # With no getter, the property's value cannot 
be determined
                                propVal = None
                        else:
-                               propVal = propRef.fget(self)
+                               try:
+                                       propVal = propRef.fget(cls)
+                               except:
+                                       # There are many reasons the propval 
may not be determined for now, 
+                                       # such as not being a live instance.
+                                       propVal = None
        
                        d = {}
                        d["name"] = name
 
                        if propRef.fget:
-                               d["showValueInDesigner"] = True
+                               d["readable"] = True
                        else:
-                               d["showValueInDesigner"] = False
+                               d["readable"] = False
 
                        if propRef.fset:
-                               d["editValueInDesigner"] = True
+                               d["writable"] = True
                        else:
-                               d["editValueInDesigner"] = False
+                               d["writable"] = False
 
                        d["doc"] = propRef.__doc__
 
                        dataType = d["type"] = type(propVal)
 
-                       try:
-                               d["editorInfo"] = 
eval("self._get%sEditorInfo()" % name)
-                       except:
-                               # There isn't an explicit editor setup, so 
let's derive it:
-                               if dataType in (str, unicode):
-                                       d["editorInfo"] = {"editor": "string", 
"len": 256}
-                               elif dataType == bool:
-                                       d["editorInfo"] = {"editor": "boolean"}
-                               elif dataType in (int, long):
-                                       d["editorInfo"] = {"editor": "integer", 
"min": -65535, "max": 65536}
-                               else:
-                                       # punt
-                                       d["editorInfo"] = {"editor": "string"}
                        return d
                else:
                        raise AttributeError, "%s is not a property." % name
-
+       getPropertyInfo = classmethod(getPropertyInfo)
        

Modified: trunk/dabo/dEvents.py
===================================================================
--- trunk/dabo/dEvents.py       2005-10-03 23:18:08 UTC (rev 1399)
+++ trunk/dabo/dEvents.py       2005-10-04 18:14:51 UTC (rev 1400)
@@ -167,7 +167,7 @@
 
 class ListEvent(Event):
        def appliesToClass(eventClass, objectClass):
-               return issubclass(objectClass, dabo.ui.dListControl, 
dabo.ui.dListBox)
+               return issubclass(objectClass, (dabo.ui.dListControl, 
dabo.ui.dListBox))
        appliesToClass = classmethod(appliesToClass)
        
 class Activate(Event):
@@ -236,12 +236,6 @@
                return issubclass(objectClass, dabo.ui.dPemMixin)
        appliesToClass = classmethod(appliesToClass)
        
-class ItemPicked(Event):
-       """Occurs when an item was picked from a picklist."""
-       def appliesToClass(eventClass, objectClass):
-               return issubclass(objectClass, (dabo.ui.dDataNavForm, 
dabo.ui.dFormDataNav))
-       appliesToClass = classmethod(appliesToClass)
-       
 class GotFocus(Event):
        """Occurs when the control gets the focus."""
        def appliesToClass(eventClass, objectClass):
@@ -481,7 +475,7 @@
 class ValueChanged(Event):
        """Occurs when the control's value has changed, whether 
programmatically or interactively."""
        def appliesToClass(eventClass, objectClass):
-               return issubclass(objectClass, 
dabo.ui.dDataControlMixin.dDataControlMixin)
+               return issubclass(objectClass, dabo.ui.dDataControlMixin)
        appliesToClass = classmethod(appliesToClass)
        
 class ValueRefresh(Event):

Modified: trunk/dabo/lib/datanav/Form.py
===================================================================
--- trunk/dabo/lib/datanav/Form.py      2005-10-03 23:18:08 UTC (rev 1399)
+++ trunk/dabo/lib/datanav/Form.py      2005-10-04 18:14:51 UTC (rev 1400)
@@ -10,6 +10,14 @@
 
 dabo.ui.loadUI("wx")
 
+
+class ItemPicked(dEvents.Event):
+       """Occurs when an item was picked from a picklist."""
+       def appliesToClass(eventClass, objectClass):
+               return issubclass(objectClass, Form)
+       appliesToClass = classmethod(appliesToClass)
+       
+
 class Form(dabo.ui.dForm):
        """ This is a dForm but with the following added controls:
                + Navigation Menu




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to