[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/forms.test gfclient.py manager.py parser.p...
From: |
Michael Maluck |
Subject: |
gnue/forms.test gfclient.py manager.py parser.p... |
Date: |
Tue, 04 Jun 2002 14:49:48 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Michael Maluck <address@hidden> 02/06/04 14:49:48
Modified files:
forms.test : gfclient.py manager.py parser.py
forms.test/common/forms: login.gfd
forms.test/ui/base: driver.py geometry.py widgets.py
forms.test/ui/webware: driver.py
forms.test/ui/wxpython: driver.py
Added files:
forms.test : GTypecast.py
Log message:
integrated work from gparser now
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/GTypecast.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/gfclient.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/manager.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/parser.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/common/forms/login.gfd.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/ui/base/driver.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/ui/base/geometry.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/ui/base/widgets.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/ui/webware/driver.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms.test/ui/wxpython/driver.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: gnue/forms.test/common/forms/login.gfd
diff -c gnue/forms.test/common/forms/login.gfd:1.1
gnue/forms.test/common/forms/login.gfd:1.2
*** gnue/forms.test/common/forms/login.gfd:1.1 Sun Jun 2 04:30:02 2002
--- gnue/forms.test/common/forms/login.gfd Tue Jun 4 14:49:48 2002
***************
*** 6,17 ****
<form>
<boxLayout insets="10;10;10;10" orientation="vertical">
<label alignX="center" text="Login required for"/>
! <label alignX="center" insets="0;0;0;0" id="dbname" text="this database"/>
<gridBagLayout insets="0;10;0;10">
<label fill="none" text="Name:"/>
<entry weightX="1.0" fill="horizontal" gridWidth="remainder"/>
! <label file="none" text="Password:"/>
<entry weightX="1.0" fill="horizontal" gridWidth="remainder"/>
</gridBagLayout>
--- 6,17 ----
<form>
<boxLayout insets="10;10;10;10" orientation="vertical">
<label alignX="center" text="Login required for"/>
! <label alignX="center" insets="0;0;0;0" text="this database"/>
<gridBagLayout insets="0;10;0;10">
<label fill="none" text="Name:"/>
<entry weightX="1.0" fill="horizontal" gridWidth="remainder"/>
! <label fill="none" text="Password:"/>
<entry weightX="1.0" fill="horizontal" gridWidth="remainder"/>
</gridBagLayout>
Index: gnue/forms.test/gfclient.py
diff -c gnue/forms.test/gfclient.py:1.2 gnue/forms.test/gfclient.py:1.3
*** gnue/forms.test/gfclient.py:1.2 Sun Jun 2 04:30:01 2002
--- gnue/forms.test/gfclient.py Tue Jun 4 14:49:48 2002
***************
*** 34,39 ****
--- 34,43 ----
import sys
from os.path import *
+ # Yes, this will change :)
+ import __builtin__
+ __builtin__.__dict__['_'] = lambda string:string
+
if sys.hexversion < 0x02020100:
print "Minimum required python version is 2.2.1"
sys.exit(1)
***************
*** 44,49 ****
--- 48,55 ----
output=1 #wx output
#fileName = "samples/test.gfd"
+ #fileName = "samples/widgets.gfd"
+ #fileName = "samples/tabPage.gfd"
fileName = "common/forms/login.gfd"
# Add dir of gfclient.py to module search path
***************
*** 54,59 ****
--- 60,67 ----
mgr.setUi("ui.webware.driver")
form = mgr.loadForm(fileName)
form.autoLayout()
+ # from ui.base.driver import DumpWidgetTree
+ # DumpWidgetTree(form)
# print form.size
hw = mgr.uiDriver.HtmlWriter()
hw.open("site.html")
Index: gnue/forms.test/manager.py
diff -c gnue/forms.test/manager.py:1.2 gnue/forms.test/manager.py:1.3
*** gnue/forms.test/manager.py:1.2 Sun Jun 2 04:30:01 2002
--- gnue/forms.test/manager.py Tue Jun 4 14:49:48 2002
***************
*** 31,45 ****
#
from parser import *
class Manager:
def __init__(self):
self.uiDriver = None
def setUi(self, UI):
self.uiDriver = __import__(UI, globals(), locals(), UI)
! self.uiBuilder = self.uiDriver.BuilderClass()
! self.uiBuilder.setTagMap(self.uiDriver.tagMap)
def getUi(self):
return self.uiDriver
--- 31,49 ----
#
from parser import *
+ import ui.base.driver
class Manager:
def __init__(self):
self.uiDriver = None
+ self.uiXmlHandler = None
def setUi(self, UI):
self.uiDriver = __import__(UI, globals(), locals(), UI)
! self.uiXmlHandler = XmlHandler()
! self.uiXmlHandler.registerElements(
! ui.base.driver.getXmlElements(self.uiDriver.getXmlElementUpdates()))
! self.uiXmlHandler.registerFactory(self.uiDriver.FactoryClass())
def getUi(self):
return self.uiDriver
***************
*** 52,58 ****
def loadForm(self, fname):
f = open(fname, "r")
! form = loadXMLobject(f, self.uiBuilder)
f.close()
return form
--- 56,62 ----
def loadForm(self, fname):
f = open(fname, "r")
! form = loadXmlObject(f, self.uiXmlHandler, None, "form")
f.close()
return form
Index: gnue/forms.test/parser.py
diff -c gnue/forms.test/parser.py:1.2 gnue/forms.test/parser.py:1.3
*** gnue/forms.test/parser.py:1.2 Sun Jun 2 04:30:01 2002
--- gnue/forms.test/parser.py Tue Jun 4 14:49:48 2002
***************
*** 22,28 ****
# parser.py
#
# DESCRIPTION:
! # Parser for .gfd files that describe the user interface
#
# WARNING:
# !!! This is for testing purposes only !!!
--- 22,28 ----
# parser.py
#
# DESCRIPTION:
! # Basic xml parser
#
# WARNING:
# !!! This is for testing purposes only !!!
***************
*** 30,95 ****
# NOTES:
#
! from xml.sax import saxexts
! from xml.sax import saxlib
! from xml.sax import saxutils
import copy
! # ----------------------------------------------------------------------------
! class BuildContext:
pass
! # ----------------------------------------------------------------------------
! class XmlFormsHandler(saxlib.HandlerBase):
! def __init__(self, uiBuilder):
! self.uiBuilder = uiBuilder
! self.buildContext = BuildContext()
! self.buildContext.parentObject = None
! self.objStack = []
! self.buildStack = []
!
! def startElement(self, tag, saxattrs):
! self.buildContext.tag = tag
! self.buildContext.createdObject = None
! self.buildContext.xmlAttrs = saxattrs
!
! if not tag in self.uiBuilder.tagMap:
! self.buildContext.classType = None
! createMethodName = None
! print "WARNING: Ignoring unknown gfd tag \"%s\". Continue parsing
childs." % tag
else:
! tagInfo = self.uiBuilder.tagMap[tag]
! self.buildContext.classType = tagInfo[0]
! createMethodName = tagInfo[1]
! if createMethodName == None:
! createdObject = None
else:
! if hasattr(self.uiBuilder, createMethodName):
! createdObject = getattr(self.uiBuilder,
createMethodName)(self.buildContext)
else:
! raise NameError, "FATAL ERROR: [form parser] Can't find create method
for tag \"%s\"." % tag
! self.buildContext.objStack = self.objStack
! self.buildContext.createdObject = createdObject
! self.buildStack.insert(0, copy.copy(self.buildContext))
! self.buildContext.parentObject = createdObject
! self.objStack.insert(0, createdObject)
!
! def endElement(self, name):
! self.buildContext = self.buildStack.pop(0)
!
! def characters(self, ch, start, length):
! pass
! #print "char: %s %s %s" % (ch, start, length)
!
! def loadXMLobject(fileHandle, uiBuilder):
! parser = saxexts.make_parser()
! dh = XmlFormsHandler(uiBuilder)
! parser.setDocumentHandler(dh)
! parser.parseFile(fileHandle)
! parser.close()
- return dh.buildContext.createdObject
--- 30,446 ----
# NOTES:
#
! try:
! from xml.sax import saxutils
! import xml.sax
! except ImportError:
! print """
! This GNUe tool requires PyXML to be installed.
! Please download and install PyXML from:
!
! http://pyxml.sourceforge.net/
!
! """
!
import copy
+ import types
+ #from gnue.common import GTypecast
+ import GTypecast
+ from gnue.common import GDebug
+ from gnue.common.GParserHelpers import GContent
! ######
! #
! # Elements that should be supported by all xml parsers
! #
! ######
! # currently not supported
! ##def getXmlElements(updates={}):
! ## xmlElements = {
! ## 'import': {
! ## 'BaseClass': GFLibrary.GFImport,
! ## 'Attributes': {
! ## 'library': {
! ## 'Required': 1,
! ## 'Typecast': GTypecast.name },
! ## 'datasources': {
! ## 'Typecast': GTypecast.name,
! ## 'Default': "" },
! ## 'pages': {
! ## 'Typecast': GTypecast.name,
! ## 'Default': "" },
! ## 'triggers': {
! ## 'Typecast': GTypecast.name,
! ## 'Default': "" } },
! ## 'ParentTags': ('form',) },
! ## }
! def getXmlElements(): pass
!
! #######################################################
! #
! # Error classed raised for markup errors
! #
! class MarkupError(StandardError):
pass
! #######################################################
! #
! # loadXMLObject
! #
! # This method loads an object from an XML file and
! # returns that object. If initialize is 1 (default),
! # then the object is initialized and ready to go.
! # Setting initialize to 0 is useful for a design
! # environment where the object is not actually
! # being used, but simply loaded as a document.
! #
! # "attributes" is a dictionary containing extra
! # attributes that should be attached to this object.
! #
! # e.g., if attributes={myproperty:[0,1,2]}, then
! # before the object is initialized or returned,
! # object.myproperty == [0,1,2].
! #
! #######################################################
! def loadXmlObject(stream, handler, rootType, xmlFileType,
! initialize=1, attributes={}, initParameters={}):
! # Create a parser
! parser = xml.sax.make_parser()
!
! # Set up some namespace-related stuff for the parsers
! parser.setFeature(xml.sax.handler.feature_namespaces, 1)
!
! # Create the handler
! dh = handler
!
! # Tell the parser to use our handler
! parser.setContentHandler(dh)
! parser.parse(stream)
!
! object = dh.getRoot()
!
! #if not object:
! # raise MarkupError, _("Error loading %s: empty definition file") %
(xmlFileType)
! #elif object._type != rootType:
! # raise MarkupError, _("Error loading %s: not a valid %s definition
(expected: %s, got: %s)") % (xmlFileType,
! # xmlFileType, rootType, object._type)
!
! # Set the object's attributes
! #object.__dict__.update(attributes)
!
! #if initialize:
! # GDebug.printMesg(10,"Initializing the object tree starting at %s"
%(object))
! # object.phaseInit(dh._phaseInitCount)
!
! return object
!
! #######################################################
! #
! # normalise_whitespace
! #
! # Remove redundant whitespace from a string ( from xml-howto )
! #
! #######################################################
! def normalise_whitespace(text):
! return string.join( string.split(text), ' ')
!
!
! def default(attrs, key, default):
! try:
! return attrs[key]
! except KeyError:
! return default
!
!
! #######################################################
! #
! # Stores information gathered during parsing
! #
! #######################################################
!
! class NodeInfo:
! def __init__(self, parent, qtag = None, tagNs = None, tagName = None):
! self.parent = parent
! if parent != None:
! self.parentObj = parent.objInstance
else:
! self.parentObj = None
! self.qtag = qtag
! self.tagNs = tagNs
! self.tagName = tagName
! self.objClass = None
! self.objInstance = None
! self.attrs = {}
!
! class BuildContext:
! def __init__(self):
! self.stacks = {}
!
! def push(self, id, obj):
! if not id in self.stacks:
! self.stacks[id] = []
!
! self.stacks[id].insert(0, obj)
!
! def pop(self, id):
! if not id in self.stacks:
! raise IndexError, _("ERROR: [buildContext] Requested object cannot be "
\
! "found. No objects for id \"%s\" have been stacked.") % (id)
!
! return self.stacks[id].pop(0)
!
! def current(self, id):
! if not id in self.stacks:
! raise IndexError, _("ERROR: [buildContext] No current object found for
" \
! "id \"%s\".") % id
!
! return self.stacks[id][0]
!
! def isStacked(self, id):
! return (id in self.stacks)
!
! #######################################################
! #
! # XmlHandler
! #
! # This class is called by the XML parser to
! # process the xml file.
! #
! #######################################################
!
! class XmlHandler(xml.sax.ContentHandler):
! def __init__(self):
! self.buildContext = BuildContext()
!
! self.xmlMasqueradeNamespaceElements = None
! self.xmlElements = self.getDefaultElements()
! if self.xmlElements == None:
! self.xmlElements = {}
!
! self.bootstrapflag = 0
! self.uniqueIDs = {}
!
! self.factories = []
!
! # Overwrite this to use different defaults
! def getDefaultElements(self):
! return getXmlElements()
!
! # Register new elements
! def registerElements(self, elements, importableElements = []):
! for key in elements:
! if key in self.xmlElements:
! print _("WARNING: [xml parser] Tag <%s> already supported by parser.
Overwriting.") % key
!
! self.xmlElements.update(elements)
! self.makeElementsImportable(importableElements)
!
! # Update existing Elements
! def updateElements(self, updates):
! for alteration in updates.keys():
! if alteration not in self.xmlElements:
! raise IndexError, _("ERROR: [xml parser] Can't update tag <%s>. Tag
not found") % key
!
! self.xmlElements[alteration].update(updates[alteration])
!
! def makeElementsImportable(self, elements):
! for key in elements:
! if not key in self.xmlElements:
! raise IndexError, _("ERROR: [xml parser] Can't make tag <%s> " \
! "importable. Tag not found.") % key
! name = "import-%s" % key
! copy._deepcopy_dispatch[types.FunctionType] = copy._deepcopy_atomic
! copy._deepcopy_dispatch[types.ClassType] = copy._deepcopy_atomic
! copy._deepcopy_dispatch[type(int)] = copy._deepcopy_atomic
!
! p = copy.deepcopy(self.xmlElements[key])
! p['BaseClass'] = GFLibrary.GFImportItem
! p['Attributes']['library'] = {
! 'Required': 1,
! 'Typecast': GTypecast.name }
! p['MixedContent'] = 0
! p['Required'] = 0
!
! self.xmlElements[name] = p
!
! def registerFactory(self, factory):
! self.factories.append(factory)
!
! def createObject(self, buildContext):
! ni = buildContext.newNodeInfo
! for factory in self.factories:
! if hasattr(factory, ni.createMethod) and \
! type(getattr(factory, ni.createMethod)) == types.MethodType:
! return getattr(factory, ni.createMethod)(buildContext)
!
! return None
!
! #
! # Called by client code to get the "root" node
! #
! def getRoot(self):
! return self.root
!
! #####
! #
! # Handler methods for sax parser
! #
! #####
!
! #
! # Called by the internal SAX parser whenever
! # a starting XML element/tag is encountered.
! #
! def startElementNS(self, qtag, qname, saxattrs):
! ns, name = qtag
! attrs = {}
! loadedxmlattrs = {}
!
! if self.buildContext.isStacked("__PARSER__NODEINFO"):
! parentNi = self.buildContext.current("__PARSER__NODEINFO")
else:
! parentNi = None
! nodeInfo = NodeInfo(parentNi, qtag, ns, name)
! self.buildContext.elementStart = True
!
! if not ns:
! #
! # No namespace qualifier
! #
! GDebug.printMesg(50, "<%s>" % name)
!
! try:
! baseAttrs = self.xmlElements[name].get('Attributes',{})
! except KeyError:
! raise MarkupError, _('Error processing <%s> tag [I do not know what a
<%s> tag does]') % (name, name)
!
!
! for qattr in saxattrs.keys():
! attrns, attr = qattr
!
!
! # Typecasting, anyone? If attribute should be int, make it an int
! try:
! attrs[attr] = baseAttrs[attr].get('Typecast',
GTypecast.text).toValue(saxattrs[qattr])
! loadedxmlattrs[attr] = attrs[attr]
! except KeyError:
! raise MarkupError, _('Error processing <%s> tag ' \
! '[I do not recognize the "%s" attribute]') %
(name, attr)
! except:
! raise MarkupError, _('Error processing <%s> tag ' \
! '[invalid type for "%s" attribute; value is
"%s"]') % \
! (name, attr, saxattrs[qattr])
!
! # If this attribute must be unique, check for duplicates
! if baseAttrs[attr].get('Unique',0):
! if self.uniqueIDs.has_key('%s' % (saxattrs[qattr])):
! raise MarkupError, _('Error processing <%s> tag ["%s" attribute
should be unique; ' \
! 'duplicate value is "%s"]') % (name, attr,
saxattrs[qattr])
!
! for attr in baseAttrs.keys():
! if not attrs.has_key(attr):
!
! # Pull default values for missing attributes
! if baseAttrs[attr].has_key ('Default'):
! attrs[attr] = baseAttrs[attr].get('Typecast',
GTypecast.text).toValue(baseAttrs[attr]['Default'])
!
! # Check for missing required attributes
! elif baseAttrs[attr].get('Required', 0):
! raise MarkupError, _('Error processing <%s> tag [required
attribute "%s" not present]') % (name, attr)
!
! nodeInfo.loadedXmlAttrs = loadedxmlattrs
! nodeInfo.attrs = attrs
!
! nodeInfo.objClass = self.xmlElements[name]['BaseClass']
! if nodeInfo.objClass == None:
! raise MarkupError, _('Error processing <%s> tag [known tag but no
base class specified') % name
!
! try:
! nodeInfo.createMethod = self.xmlElements[name].get('CreateMethod',
None)
! except KeyError:
! raise MarkupError, _('Error processing <%s> tag [No create method
defined]')
!
! self.buildContext.newNodeInfo = nodeInfo
! if self.bootstrapflag:
! nodeInfo.objInstance = self.createObject(self.buildContext)
else:
! nodeInfo.objInstance = self.createObject(self.buildContext)
!
! self.root = nodeInfo.objInstance
! self.bootstrapflag = 1
!
! nodeInfo.objInstance._xmltag = name
!
! elif self.xmlMasqueradeNamespaceElements:
! #
! # namespace qualifier and we are masquerading
! #
!
! GDebug.printMesg(50, "<%s:%s>" % (ns,name))
!
! for qattr in saxattrs.keys():
! attrns, attr = qattr
!
! attrs[attr] = saxattrs[qattr]
! loadedxmlattrs[attr] = saxattrs[qattr]
!
! nodeInfo.objInstance =
self.xmlMasqueradeNamespaceElements(parentNi.objClass)
! nodeInfo.objInstance._xmltag = name
! nodeInfo.objInstance._xmlnamespace = ns
! nodeInfo.objInstance._listedAttributes = loadedxmlattrs.keys()
! else:
! #
! # namespace qualifier and we are not masquerading
! #
! print _("WARNING: Markup includes namespaces, but the current tool does
not include namespace support!")
! sys.exit()
!
!
! # Save the attributes loaded from XML file
! # (i.e., attributes that were not defaulted)
! nodeInfo.objInstance._loadedxmlattrs = loadedxmlattrs
! #self.xmlStack.insert(0, object)
! #self.nameStack.insert(0, name)
!
! self.buildContext.push("__PARSER__NODEINFO", nodeInfo)
!
! #
! # Called by the internal SAX parser whenever
! # text (not part of a tag) is encountered.
! #
! def characters(self, text):
! if self.buildContext.isStacked('__PARSER__NODEINFO'):
! currentNi = self.buildContext.current('__PARSER__NODEINFO')
!
! # Masqueraging namespace elements, then keep content
! xmlns = self.xmlMasqueradeNamespaceElements and \
! isinstance(currentNi.objInstance,
self.xmlMasqueradeNamespaceElements)
!
! # Should we keep the text?
! if xmlns or self.xmlElements[currentNi.tagName].get('MixedContent',0):
!
! if xmlns or
self.xmlElements[currentNi.tagName].get('KeepWhitespace',0):
! GContent(currentNi.objInstance, text)
! else:
! # Normalize
! if len(string.replace(string.replace(string.replace(text,'
',''),'\n',''),'\t','')):
! text = normalise_whitespace (text)
! else:
! text = ""
! if len(text):
! GContent(currentNi.objInstance, text)
!
! #
! # Called by the internal SAX parser whenever
! # an ending XML tag/element is encountered.
! #
! def endElementNS(self, qtag, qname):
! ns, name = qtag
! self.buildContext.elementStart = False
! self.buildContext.nodeInfo = self.buildContext.pop("__PARSER__NODEINFO")
! self.createObject(self.buildContext)
Index: gnue/forms.test/ui/base/driver.py
diff -c gnue/forms.test/ui/base/driver.py:1.2
gnue/forms.test/ui/base/driver.py:1.3
*** gnue/forms.test/ui/base/driver.py:1.2 Sun Jun 2 04:30:02 2002
--- gnue/forms.test/ui/base/driver.py Tue Jun 4 14:49:48 2002
***************
*** 18,26 ****
#
# Copyright 2000, 2001, 2002 Free Software Foundation
#
- # FILE:
- # UIwxpython.py
- #
# DESCRIPTION:
# Basic funcionality required for a ui driver
#
--- 18,23 ----
***************
*** 31,113 ****
#
from string import *
import copy
MAX_INT=65535
! class Builder:
! def setTagMap(self, tm):
! self.tagMap = tm
!
! def createForm(self, buildContext):
! form = buildContext.classType()
! form.setAttributes(buildContext.xmlAttrs)
! form.createPeer()
! return form
!
! def createLabel(self, buildContext):
! label = buildContext.classType(buildContext.parentObject)
! label.setAttributes(buildContext.xmlAttrs)
! label.createPeer()
! buildContext.parentObject.addChild(label, buildContext.xmlAttrs)
! return label
!
! def createButton(self, buildContext):
! button = buildContext.classType(buildContext.parentObject)
! button.setAttributes(buildContext.xmlAttrs)
! button.createPeer()
! buildContext.parentObject.addChild(button, buildContext.xmlAttrs)
! return button
!
! def createEntry(self, buildContext):
! entry = buildContext.classType(buildContext.parentObject)
! entry.setAttributes(buildContext.xmlAttrs)
! entry.createPeer()
! buildContext.parentObject.addChild(entry, buildContext.xmlAttrs)
! return entry
!
! def createTabPageMgr(self, buildContext):
! tabPageMgr = buildContext.classType(buildContext.parentObject)
! tabPageMgr.setAttributes(buildContext.xmlAttrs)
! tabPageMgr.createPeer()
! buildContext.parentObject.addChild(tabPageMgr, buildContext.xmlAttrs)
! return tabPageMgr
!
! def createTabPage(self, buildContext):
! tabPage = buildContext.classType(buildContext.parentObject)
! tabPage.setAttributes(buildContext.xmlAttrs)
! tabPage.createPeer()
! buildContext.parentObject.addChild(tabPage, buildContext.xmlAttrs)
! return tabPage
!
! def createBox(self, buildContext):
! box = buildContext.classType(buildContext.parentObject)
! box.setAttributes(buildContext.xmlAttrs)
! box.createPeer()
! buildContext.parentObject.addChild(box, buildContext.xmlAttrs)
! return box
!
! def createBoxLayoutMgr(self, buildContext):
! boxLayoutMgr = buildContext.classType(buildContext.parentObject)
! boxLayoutMgr.setAttributes(buildContext.xmlAttrs)
! boxLayoutMgr.createPeer()
! buildContext.parentObject.addChild(boxLayoutMgr, buildContext.xmlAttrs)
! return boxLayoutMgr
!
! def createGridBagLayoutMgr(self, buildContext):
! gridBagLayoutMgr = buildContext.classType(buildContext.parentObject)
! gridBagLayoutMgr.setAttributes(buildContext.xmlAttrs)
! gridBagLayoutMgr.createPeer()
! buildContext.parentObject.addChild(gridBagLayoutMgr,
buildContext.xmlAttrs)
! return gridBagLayoutMgr
!
! def createXyLayoutMgr(self, buildContext):
! xyLayoutMgr = buildContext.classType(buildContext.parentObject)
! xyLayoutMgr.setAttributes(buildContext.xmlAttrs)
! xyLayoutMgr.createPeer()
! buildContext.parentObject.addChild(xyLayoutMgr, buildContext.xmlAttrs)
! return xyLayoutMgr
!
# ============================================================================
# - Code for debugging
# ============================================================================
--- 28,401 ----
#
from string import *
+ #from gnue.common import GTypecast
+ import GTypecast
import copy
+ from ui.base import geometry
+ PRE_CREATE=0
+ POST_CREATE=1
MAX_INT=65535
! ######
! #
! # Used by client parsers to automatically pull supported xml tags
! #
! ######
!
! #
! # Return any XML elements associated with a form
! # Base is a dictionary of tags whose values are update
! # dictionaries.
! #
! # For example:
! # bases={'datasource': {'BaseClass':myDataSource}}
! # sets xmlElements['datasource']['BaseClass'] = myDataSource
! #
! def getXmlElements(updates={}):
!
! xmlElements = {
! 'form': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Required': 1,
! 'SingleInstance': 1,
! 'ParentTags': None },
!
! 'label': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! 'text': {
! 'Typecast': GTypecast.text,
! 'Required': 1 },
!
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'x': {
! 'Typecast': GTypecast.whole },
! 'y': {
! 'Typecast': GTypecast.whole },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('xyLayout', 'boxLayout', 'gridBagLayout', ) },
!
! 'button': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! 'label': {
! 'Typecast': GTypecast.text,
! 'Required': 1 },
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'x': {
! 'Typecast': GTypecast.whole },
! 'y': {
! 'Typecast': GTypecast.whole },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('xyLayout', 'boxLayout', 'gridBagLayout', ) },
!
! 'entry': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'x': {
! 'Typecast': GTypecast.whole },
! 'y': {
! 'Typecast': GTypecast.whole },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('xyLayout', 'boxLayout', 'gridBagLayout', ) },
!
! 'tabPageMgr': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'x': {
! 'Typecast': GTypecast.whole },
! 'y': {
! 'Typecast': GTypecast.whole },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('xyLayout', 'boxLayout', 'gridBagLayout', ) },
!
! 'tabPage': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! 'title': {
! 'Typecast': GTypecast.text,
! 'Default': 'untitled' } },
! 'ParentTags': ('xyLayout', 'boxLayout', 'gridBagLayout', ) },
!
! 'box': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! 'title': {
! 'Typecast': GTypecast.text },
!
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'x': {
! 'Typecast': GTypecast.whole },
! 'y': {
! 'Typecast': GTypecast.whole },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('xyLayout', 'boxLayout', 'gridBagLayout', ) },
!
! 'boxLayout': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! 'orientation': {
! 'Typecast': geometry.orientation,
! 'Required': 1 },
!
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('boxLayout', 'gridBagLayout', 'form', 'tabPage', 'box')
},
!
! 'gridBagLayout': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets },
! 'alignX': {
! 'Typecast': geometry.alignX },
! 'alignY': {
! 'Typecast': geometry.alignY },
! 'fill': {
! 'Typecast': geometry.fill },
!
! # Attributes for GridBagLayoutMgr
! 'gridX': {
! 'Typecast': geometry.gridPosition },
! 'gridY': {
! 'Typecast': geometry.gridPosition },
! 'gridWidth': {
! 'Typecast': geometry.gridDimension },
! 'gridHeight': {
! 'Typecast': geometry.gridDimension },
! 'weightX': {
! 'Typecast': GTypecast.number },
! 'weightY': {
! 'Typecast': GTypecast.number },
! 'anchor': {
! 'Typecast': geometry.anchor },
! 'ipadx': {
! 'Typecast': GTypecast.whole },
! 'ipady': {
! 'Typecast': GTypecast.whole } },
! 'ParentTags': ('boxLayout', 'gridBagLayout', 'form', 'tabPage', 'box')
},
!
! 'xyLayout': {
! 'BaseClass': None,
! 'CreateMethod': 'createUiObject',
! 'Attributes': {
! # Geometry attributes
! 'insets': {
! 'Typecast': geometry.insets } },
! 'ParentTags': ('xyLayout', 'form', 'tabPage', 'box'),
! } }
!
! for alteration in updates.keys():
! xmlElements[alteration].update(updates[alteration])
!
! return xmlElements
!
! #gfdImportableElements =
['datasource','page','block','trigger','button','entry']
!
! class Factory:
! def createUiObject(self, buildContext):
! if buildContext.elementStart:
! if not hasattr(buildContext, "parentUiObj"):
! parentObj = None
! else:
! parentObj = buildContext.current("__UI__PARENT")
!
! ni = buildContext.newNodeInfo
! newObject = ni.objClass(parentObj)
!
! # Set the attributes
! # warning: __dict__.update does not work with
! # python properties!
! for attr in ni.attrs:
! newObject.__setattr__(attr, ni.attrs[attr])
!
! newObject.createPeer()
!
! if parentObj != None:
! parentObj.addChild(newObject, ni.attrs)
!
! buildContext.parentUiObj = newObject
! buildContext.push('__UI__PARENT', newObject)
!
! return newObject
! else:
! buildContext.parentUiObj = buildContext.pop('__UI__PARENT')
!
# ============================================================================
# - Code for debugging
# ============================================================================
Index: gnue/forms.test/ui/base/geometry.py
diff -c gnue/forms.test/ui/base/geometry.py:1.2
gnue/forms.test/ui/base/geometry.py:1.3
*** gnue/forms.test/ui/base/geometry.py:1.2 Sun Jun 2 04:30:02 2002
--- gnue/forms.test/ui/base/geometry.py Tue Jun 4 14:49:48 2002
***************
*** 34,39 ****
--- 34,41 ----
import sys
import string
import copy
+ #from gnue.common import GTypecast
+ import GTypecast
from dataStructures import *
# this is the maximum ui size
***************
*** 111,116 ****
--- 113,129 ----
def __repr__(self):
return "(left:%s,top:%s,righ:%s,bottom:%s)" % (self.left, self.top,
self.right, self.bottom)
+ def toValue(self, xml):
+ a = GTypecast.integers.toValue(xml)
+ if len(a) != 4:
+ raise TypecastError
+ return Insets(a[0], a[1], a[2], a[3])
+
+ def toXml(self, value):
+ return GTypecast.integers.toXml([value.left, value.top, value.right,
value.bottom])
+
+ insets = Insets()
+
# ----------------------------------------------------------------------------
class GeometryObject(Hierarchy):
***************
*** 125,133 ****
FILL_HORIZONTAL = 2
FILL_VERTICAL = 3
- alignXMap = { "left": ALIGN_LEFT,
- "center": ALIGN_CENTER,
- "right": ALIGN_RIGHT }
alignYMap = { "top": ALIGN_TOP,
"center": ALIGN_RIGHT,
--- 138,143 ----
***************
*** 381,383 ****
--- 391,521 ----
if "fill" in attrs:
self._fill = self.fillMap[attrs["fill"]]
+ # ----------------------------------------------------------------------------
+
+ class AlignX(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "left": return GeometryObject.ALIGN_LEFT
+ if rv == "center": return GeometryObject.ALIGN_CENTER
+ if rv == "right": return GeometryObject.ALIGN_RIGHT
+ raise TypecastError
+
+ def toXml(self, value):
+ if value == GeometryObject.ALIGN_LEFT: return "left"
+ if value == GeometryObject.ALIGN_CETNER: return "center"
+ if value == GeometryObject.ALIGN_RIGHT: return "right"
+
+ alignX = AlignX()
+
+ # ----------------------------------------------------------------------------
+
+ class AlignY(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "top": return GeometryObject.ALIGN_TOP
+ if rv == "center": return GeometryObject.ALIGN_CENTER
+ if rv == "bottom": return GeometryObject.ALIGN_BOTTOM
+ raise TypecastError
+
+ def toXml(self, value):
+ if value == GeometryObject.ALIGN_TOP: return "top"
+ if value == GeometryObject.ALIGN_CETNER: return "center"
+ if value == GeometryObject.ALIGN_BOTTOM: return "bottom"
+ raise TypecastError
+
+ alignY = AlignY()
+
+ # ----------------------------------------------------------------------------
+
+ class Anchor(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "north": return 11
+ if rv == "northeast": return 12
+ if rv == "east": return 13
+ if rv == "southeast": return 14
+ if rv == "south": return 15
+ if rv == "southwest": return 16
+ if rv == "west": return 17
+ if rv == "northwest": return 18
+ raise TypecastError
+
+ def toXml(self, value):
+ if value == 11: return "north"
+ if value == 12: return "northeast"
+ if value == 13: return "east"
+ if value == 14: return "southeast"
+ if value == 15: return "south"
+ if value == 16: return "southwest"
+ if value == 17: return "west"
+ if value == 18: return "northwest"
+ raise TypecastError
+
+ anchor = Anchor()
+
+ # ----------------------------------------------------------------------------
+
+ class Orientation(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "horizontal": return 0
+ if rv == "vertical": return 1
+ raise TypecastError
+
+ def toXml(self, value):
+ if value == 0: return "horizontal"
+ if value == 1: return "vertical"
+ raise TypecastError
+
+ orientation = Orientation()
+
+ # ----------------------------------------------------------------------------
+
+ class Fill(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "none": return 0
+ if rv == "both": return 1
+ if rv == "horizontal": return 2
+ if rv == "vertical": return 3
+ raise TypecastError
+
+ def toXml(self, value):
+ if value == 0: return "none"
+ if value == 1: return "both"
+ if value == 2: return "horizontal"
+ if value == 3: return "vertical"
+ raise TypecastError
+
+ fill = Fill()
+
+ # ----------------------------------------------------------------------------
+
+ class GridDimension(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "relative": return -1
+ if rv == "remainder": return 0
+ return integer.toValue(xml)
+
+ def toXml(self, value):
+ if value == 0: return "remainder"
+ if value == -1: return "relative"
+ return integer.toXml(value)
+
+ gridDimension = GridDimension()
+
+ # ----------------------------------------------------------------------------
+
+ class GridPosition(object):
+ def toValue(self, xml):
+ rv = string.lower(string.strip(xml))
+ if rv == "relative": return -1
+ return integer.toValue(xml)
+
+ def toXml(self, value):
+ if value == -1: return "relative"
+ return integer.toXml(xml)
+
+ gridPosition = GridPosition()
Index: gnue/forms.test/ui/base/widgets.py
diff -c gnue/forms.test/ui/base/widgets.py:1.2
gnue/forms.test/ui/base/widgets.py:1.3
*** gnue/forms.test/ui/base/widgets.py:1.2 Sun Jun 2 04:30:02 2002
--- gnue/forms.test/ui/base/widgets.py Tue Jun 4 14:49:48 2002
***************
*** 111,119 ****
"The button's label")
def setAttributes(self, attrs):
if "label" in attrs:
self.label = attrs["label"]
- super(Button, self).setAttributes(attrs)
# ----------------------------------------------------------------------------
--- 111,119 ----
"The button's label")
def setAttributes(self, attrs):
+ super(Button, self).setAttributes(attrs)
if "label" in attrs:
self.label = attrs["label"]
# ----------------------------------------------------------------------------
Index: gnue/forms.test/ui/webware/driver.py
diff -c gnue/forms.test/ui/webware/driver.py:1.2
gnue/forms.test/ui/webware/driver.py:1.3
*** gnue/forms.test/ui/webware/driver.py:1.2 Sun Jun 2 04:30:02 2002
--- gnue/forms.test/ui/webware/driver.py Tue Jun 4 14:49:48 2002
***************
*** 35,54 ****
from widgets import *
import ui.base.driver
! tagMap = {
! 'form': [ HtmlForm, "createForm" ],
! 'label': [ HtmlLabel, "createLabel" ],
! 'button': [ HtmlButton, "createButton" ],
! 'entry': [ HtmlEntry, "createEntry" ],
! 'tabPageMgr': [ HtmlTabPageMgr, "createTabPageMgr" ],
! 'tabPage': [ HtmlTabPage, "createTabPage" ],
! 'box': [ HtmlBox, "createBox" ],
! 'boxLayout': [ HtmlBoxLayoutMgr, "createBoxLayoutMgr" ],
! 'gridBagLayout': [ HtmlGridBagLayoutMgr, "createGridBagLayoutMgr" ],
! 'xyLayout': [ HtmlXyLayoutMgr, "createXyLayoutMgr" ],
! }
def runForm(form):
! pass
! BuilderClass = ui.base.driver.Builder
--- 35,58 ----
from widgets import *
import ui.base.driver
! def getXmlElementUpdates():
! return { 'form': { 'BaseClass': HtmlForm },
! 'label': { 'BaseClass': HtmlLabel },
! 'button': { 'BaseClass': HtmlButton },
! 'entry': { 'BaseClass': HtmlEntry },
! 'tabPageMgr': { 'BaseClass': HtmlTabPageMgr },
! 'tabPage': { 'BaseClass': HtmlTabPage },
! 'box': { 'BaseClass': HtmlBox },
! 'boxLayout': { 'BaseClass': HtmlBoxLayoutMgr },
! 'gridBagLayout': { 'BaseClass': HtmlGridBagLayoutMgr },
! 'xyLayout': { 'BaseClass': HtmlXyLayoutMgr } }
!
! # ----------------------------------------------------------------------------
def runForm(form):
! pass
! # ----------------------------------------------------------------------------
!
! # Just use the basic ui factory
! FactoryClass = ui.base.driver.Factory
Index: gnue/forms.test/ui/wxpython/driver.py
diff -c gnue/forms.test/ui/wxpython/driver.py:1.2
gnue/forms.test/ui/wxpython/driver.py:1.3
*** gnue/forms.test/ui/wxpython/driver.py:1.2 Sun Jun 2 04:30:02 2002
--- gnue/forms.test/ui/wxpython/driver.py Tue Jun 4 14:49:48 2002
***************
*** 33,55 ****
#
from widgets import *
- from ui.base.driver import *
from manager import *
! # ----------------------------------------------------------------------------
!
! tagMap = {
! 'form': [ WxForm, "createForm" ],
! 'label': [ WxLabel, "createLabel" ],
! 'button': [ WxButton, "createButton" ],
! 'entry': [ WxEntry, "createEntry" ],
! 'tabPageMgr': [ WxTabPageMgr, "createTabPageMgr" ],
! 'tabPage': [ WxTabPage, "createTabPage" ],
! 'box': [ WxBox, "createBox" ],
! 'boxLayout': [ WxBoxLayoutMgr, "createBoxLayoutMgr" ],
! 'gridBagLayout': [ WxGridBagLayoutMgr, "createGridBagLayoutMgr" ],
! 'xyLayout': [ WxXyLayoutMgr, "createXyLayoutMgr" ],
! }
# ----------------------------------------------------------------------------
--- 33,52 ----
#
from widgets import *
from manager import *
+ import ui.base.driver
! def getXmlElementUpdates():
! return { 'form': { 'BaseClass': WxForm },
! 'label': { 'BaseClass': WxLabel },
! 'button': { 'BaseClass': WxButton },
! 'entry': { 'BaseClass': WxEntry },
! 'tabPageMgr': { 'BaseClass': WxTabPageMgr },
! 'tabPage': { 'BaseClass': WxTabPage },
! 'box': { 'BaseClass': WxBox },
! 'boxLayout': { 'BaseClass': WxBoxLayoutMgr },
! 'gridBagLayout': { 'BaseClass': WxGridBagLayoutMgr },
! 'xyLayout': { 'BaseClass': WxXyLayoutMgr } }
# ----------------------------------------------------------------------------
***************
*** 63,73 ****
# ----------------------------------------------------------------------------
- class WxBuilder(Builder):
- pass
-
- # ----------------------------------------------------------------------------
-
def runForm(form):
application = FormsApplication()
formPeer = form.peer
--- 60,65 ----
***************
*** 82,85 ****
# ----------------------------------------------------------------------------
! BuilderClass = WxBuilder
--- 74,78 ----
# ----------------------------------------------------------------------------
! # Just use the basic ui factory
! FactoryClass = ui.base.driver.Factory