[wxPython] wxPropertyListView and other Property classes

Basically, there are 4 (extraneous) dependencies in the current basicproperty.wx codebase. Eliminating/optionalising those is the next step in the project (probably done Monday or Tuesday):

  mx.DateTime
  objectlist and objectdnd (same page as basicproperty under "wxPython Object DND Mix-ins", just copy to the Python path)

  wxpycolors (which, I've just realised, isn't currently published anywhere, as I took it off my own site and never did a release from SourceForge. Gack, I'm not really able to get that changed before Monday, as I'm needing to be up in 6 hours. For now going to make a version that doesn't need this for demoing...)
  Numeric (used by wxpycolors)

I've just released 0.1.5a, which includes a few small fixes to the various modules to eliminate spurious dependencies. It also includes a script called no_extensions_test, which shouldn't require mx.DateTime or wxpycolors, and should therefor just run on your Python 2.2 + wxPython 2.3.2.1 + objectlist + objectdnd setup (it doesn't use the calendar or colour data types, however).

As for other usage examples, here's something from my current project (the one that I built the system for):

### User.py, the definition of the object to be edited
import Persistence
from mx import DateTime
from wxPython.wx import *
from conflictsolver import properties
from basicproperty import propertied

class User( propertied.Propertied, Persistence.Persistent):
  """A client, a person/group who can lease resources for a period of time"""
  name = properties.StringProperty(
    "name", "Allows you to identify this user in the interface",
    defaultValue="",
  )
  color = properties.RGBColourProperty(
    "color", "The colour identifying this user in the interface",
    defaultValue=(0,0,0),
  )
  textColor = properties.RGBColourProperty(
    "textColor", "The colour for labels for this user in the interface",
    defaultValue=(255,255,255),
  )
  contactInformation = properties.StringProperty(
    "contactInformation", "Information about how to contact the user (contact name, contact phone number, etceteras)",
    defaultValue="",
  )

### userpropertyset.py, the definition of the UI for editing
### a user object...
from basicproperty import *
from basicproperty.wx.propertyset import *
from basicproperty.wx.standard import colour, longtext
from wxPython.wx import *
from conflictsolver.user import User

set = PropertySet( propertyDefinitions = [
  PropertyDefinition(
    name = "User Name",
    property = User.name,
  ),
  PropertyDefinition(
    property = User.color,
    name = "Bar Colour",
    editClass = colour.ColourEditor,
  ),
  PropertyDefinition(
    property = User.textColor,
    name = "Text Colour",
    editClass = colour.ColourEditor,
  ),
  PropertyDefinition(
    name = "Contact Information",
    property = User.contactInformation,
    # need long string editor for this...
    editClass = longtext.LongTextEditor,
  ),
])

PROPERTYSETREGISTRY[ User ] = set

if __name__ == "__main__":
  from conflictsolver import test
  from basicproperty.wx.propertyview import ObjectPropertyView
  class TestApplication (wxPySimpleApp):
    def OnInit(self):
      frame =wxFrame(NULL, -1, "test", size = (600,300))
      test.setupTestingDatabase()
      panel = ObjectPropertyView(frame, -1)
      table = APPLICATION.GetUserTable()._objects
      panel.SetValue(table[table.keys()[0]])
      frame.Show (1)
      self.SetTopWindow(frame)
      return 1
    def OnExit( self ):
      APPLICATION.CloseDatabase()
  
  app = TestApplication ()
  app.MainLoop()

(In that sample, I'm actually getting a user from the database, whereas you'd normally just create an instance of user to pass to panel.SetValue for a test/demo.)

The User class is entirely abstract (that is, no connection with the UI at all). The Property Definitions contain all of the information necessary to bridge between the abstract representation and the UI. The use of the PROPERTYSETREGISTRY is actually something I'm intending to eliminate. At the moment, it's used to retrieve a default property set for a given class. In practice, I am normally creating views for a single object type, and want to be able to specify different property sets most of the time.

Creating new editing classes is demonstrated by the basicproperty.wx.standard package. Those editors are then specified by the Property Definitions for individual objects.

All files needed for updated version (0.1.5a) are at:

  http://members.rogers.com/mcfletch/programming/

HTH,
Mike

Kevin Altis wrote:

Mike,
I finally got around to downloading the file today on my Python 2.2
installation (my main box is still 2.1.1). There weren't any instructions,
but I went ahead and assumed that I should try installing it as a package so
I did a 'setup.py install' and I think that worked. What I don't see are
much in the way of examples showing the GUI stuff. I see a test.py which I
haven't got working yet because apparently mxDateTime is required and I
haven't gone looking for that yet.

Anyway, in order to avoid wasting a lot of time trying to get started, some
pointers and example usage would be appreciated.

Thanks,

ka

...