commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/gnuef/src GFParser.py GFTrigger.py


From: Jason Cater
Subject: gnue/gnuef/src GFParser.py GFTrigger.py
Date: Tue, 26 Jun 2001 20:17:58 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/06/26 20:17:58

Modified files:
        gnuef/src      : GFParser.py GFTrigger.py 

Log message:
        Converted parser format from nested tuples to nested dictionaries so 
that in future info can be added to parser definition without breaking other 
code and vise versa; also; added StoreTriggerAsCDATA setting to gnue.conf; if 
true, triggers are surrounded by \<\!\[CDATA[...\]\]\> and are stored as is; if 
false; <.>, & are converted to &lt; &gt; &amp; Note: the only advantage to this 
setting is if you are planning on editing the gfd file in a text editor; CDATA 
may be easier to edit than xml-friendly entities.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/src/GFParser.py.diff?cvsroot=OldCVS&tr1=1.37&tr2=1.38&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/src/GFTrigger.py.diff?cvsroot=OldCVS&tr1=1.34&tr2=1.35&r1=text&r2=text

Patches:
Index: gnue/gnuef/src/GFParser.py
diff -u gnue/gnuef/src/GFParser.py:1.37 gnue/gnuef/src/GFParser.py:1.38
--- gnue/gnuef/src/GFParser.py:1.37     Wed Jun 20 14:55:37 2001
+++ gnue/gnuef/src/GFParser.py  Tue Jun 26 20:17:58 2001
@@ -31,8 +31,22 @@
 
 from gnue.common.GParser import *
 from gnue.common import GDataSource, GParser
+import copy, types
 
 
+
+
+
+
+########
+########  Please keep this file neat !!!
+########
+
+
+
+
+
+
 #######################################################
 # This method loads a form from an XML file and returns 
 # a GFForm object.  If initialize is 1 (default), then 
@@ -46,151 +60,367 @@
 def loadForm(URL, app, initialize=1):
   return GParser.loadXMLObject (URL, xmlFormsHandler, 'GFForm', 'form', 
            initialize, attributes={"_app": app, 
-                               "_connections": app.connections})  
+                               "_connections": app.connections })  
+
+
 xmlElements = None
 
+
 def getXMLelements(): 
 
   global xmlElements
 
     #
     # xmlElements=
-    #   {tagName: (baseClass, attributesHash, normalizeWhitespace?, parents)}
+    # {tagName: (baseClass, attributesHash, normalizeWhitespace?, parents) }
     #      
     # attributesHash=
-    #   {attrName: (required?, uniqueID?, typecast, defaultValue)}
+    # {attrName: (required?, uniqueID?, typecast, defaultValue) }
     #
     # parents=  # Used by designer to generate menus
     #   (canParentsChildrenContainTagAlso?, Tuple of Parent Tags)
     #
   if xmlElements == None:
     from gnue.forms import GFObjects, GFLibrary, GFTrigger, GFForm
+
     xmlElements = { 
-      'form':       ( GFForm.GFForm,
-                      { 'title':       (0, 0, char, None),
-                        'readonly':    (0, 0, bool, 0   ),
-                        'tabbed':      (0, 0, char, "")},
-                      1, (0,None)),
-      'import':     ( GFLibrary.GFImport,
-                      { 'library':     (1, 0, char, None), 
-                        'datasources': (0, 0, char, ""  ), 
-                        'pages':       (0, 0, char, ""  ), 
-                        'triggers':    (0, 0, char, ""  )}, 
-                     1, (0,('form',))),
-      'database':   ( GFObjects.GFDatabase,   
-                      { 'name':        (1, 1, char, None), 
-                        'provider':    (1, 0, char, None), 
-                        'dbname':      (1, 0, char, None), 
-                        'host':        (1, 0, char, None)}, 
-                      1, (0,('form',))),
-      'datasource': ( GFObjects.GFDataSource,  
-                      GDataSource.tagAttributes, 
-                      1, (0,('form',))),
-      'page':       ( GFObjects.GFPage,\
-                      { 'name':        (0, 1, char, None)}, 
-                      1, (0,('form',))),
-      'block':      ( GFObjects.GFBlock,      
-                      { 'name':        (1, 1, char, None), 
-                        'master':      (0, 0, char, None), 
-                        'detail':      (0, 0, char, None), 
-                        'rows':        (0, 0, int,  1), 
-                        'rowSpacer':   (0, 0, int,  None),
-                        'transparentBlock':(0, 0, bool, 0),
-                        'datasource':  (0, 0, char, None)}, 
-                     1, (0,('page',))),
-      'label':      ( GFObjects.GFLabel, 
-                      { 'name':        (0, 1, char, None), 
-                        'text':        (1, 0, char, None), 
-                        'alignment':   (0, 0, char, "left"), 
-                        'width':       (0, 0, int,  None), 
-                        'x':           (1, 0, int,  None), 
-                        'y':           (1, 0, int,  None)}, 
-                      1, (0,('block',))),
-      'entry':     ( GFObjects.GFEntry,
+      'form': { 
+         'BaseClass':    GFForm.GFForm,
+         'Required': 1,
+         'Attributes': { 
+            'title': {
+               'Typecast': char },
+            'readonly': {
+               'Typecast': bool, 
+               'Default':  0 },
+            'tabbed': {
+               'Typecast': char, 
+               'Default':  "" } },
+         'ParentTags':  None },
+
+      'import': { 
+         'BaseClass':    GFLibrary.GFImport,
+         'Attributes': { 
+            'library': {
+               'Required': 1, 
+               'Typecast': char }, 
+            'datasources': {
+               'Typecast': char, 
+               'Default':  "" }, 
+            'pages': {
+               'Typecast': char, 
+               'Default':  ""  }, 
+            'triggers': {
+               'Typecast': char, 
+               'Default':  "" } }, 
+         'ParentTags':  ('form',) },
+
+      'database': { 
+         'BaseClass':    GFObjects.GFDatabase,   
+         'Attributes': { 
+            'name': {
+               'Required': 1, 
+               'Unique':   1, 
+               'Typecast': char }, 
+            'provider': {
+               'Required': 1, 
+               'Typecast': char }, 
+            'dbname': {
+               'Required': 1, 
+               'Typecast': char }, 
+            'host': {
+               'Required': 1, 
+               'Typecast': char } }, 
+         'Deprecated': 1, 
+         'ParentTags':  ('form',) },
+
+      'datasource': { 
+         'BaseClass':    GFObjects.GFDataSource,  
+         'Attributes':   GDataSource.tagAttributes, 
+         'ParentTags':  ('form',) },
+
+      'page': { 
+         'BaseClass':    GFObjects.GFPage,
+         'Required': 1,
+         'Attributes': { 
+            'name': {
+               'Unique':   1, 
+               'Typecast': char } }, 
+         'ParentTags':  ('form',) },
+
+      'block': { 
+         'BaseClass':    GFObjects.GFBlock,      
+         'Attributes': { 
+            'name': {
+               'Required': 1, 
+               'Unique':   1, 
+               'Typecast': char }, 
+            'master': {
+               'Typecast': char }, 
+            'detail': {
+               'Typecast': char }, 
+            'rows': {
+               'Typecast': int,  
+               'Default':  1}, 
+            'rowSpacer': {
+               'Typecast': int },
+        'transparentBlock':{
+               'Typecast': bool, 
+               'Default':  0 },
+            'datasource': {
+               'Typecast': char } }, 
+         'ParentTags':  ('page',) },
+
+      'label': { 
+         'BaseClass':    GFObjects.GFLabel, 
+         'Attributes': { 
+            'name': {
+               'Unique':   1, 
+               'Typecast': char }, 
+            'text': {
+               'Required': 1, 
+               'Typecast': char }, 
+            'alignment': {
+               'Typecast': char, 
+               'Default':  "left"}, 
+            'width': {
+               'Typecast': int }, 
+            'x': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'y': {
+               'Required': 1, 
+               'Typecast': int } }, 
+         'ParentTags':  ('block',) },
+
       # If you implement a new entry "style", add to the entryStyles 
       # structure after this list
-                      { 'name':        (1, 1, char, None), 
-                        'field':       (0, 0, char, None), 
-                        'height':      (0, 0, int,  None), 
-                        'width':       (0, 0, int,  None), 
-                        'max_length':  (0, 0, int,  None), 
-                        'visibleCount':(0, 0, int,  None), 
-                        'readonly':    (0, 0, bool, 0   ), 
-                        'uppercase':   (0, 0, bool, 0   ), 
-                        'lowercase':   (0, 0, bool, 0   ), 
-                        'numeric':     (0, 0, bool, 0   ), 
-                        'hidden':      (0, 0, bool, 0   ), 
-                        'field':       (0, 0, char, None), 
-                        'style':       (0, 0, char, 'default'), 
-                        'value':       (0, 0, char, None), 
-                        'foreign_key': (0, 0, char, None), 
-                        'default':     (0, 0, char, None), 
-                        'queryDefault':(0, 0, char, None), 
-                        'foreign_key_description':  (0, 0, char, None), 
-                        'sloppyQuery': (0, 0, char, None), 
-                        'x':           (1, 0, int,  None), 
-                        'y':           (1, 0, int,  None)}, 
-                     1, (0,('block',))),
-      'scrollbar':  ( GFObjects.GFScrollBar,  
-                      { 'width':       (1, 0, int,  None), 
-                        'height':      (1, 0, int,  None), 
-                        'x':           (1, 0, int,  None), 
-                        'y':           (1, 0, int,  None)}, 
-                      1, (0,('block',))),
-      'box':        ( GFObjects.GFBox,
-                      { 'name':        (0, 1, char, None), 
-                        'label':       (0, 0, char, None), 
-                        'width':       (1, 0, int,  None), 
-                        'height':      (1, 0, int,  None), 
-                        'x':           (1, 0, int,  None), 
-                        'y':           (1, 0, int,  None)}, 
-                      1, (0,('block',))),
-      'button':     ( GFObjects.GFButton,     
-                      { 'name':        (0, 1, char, None), 
-                        'trigger':     (0, 0, char, None), 
-                        'label':       (0, 0, char, None), 
-                        'width':       (1, 0, int,  None), 
-                        'height':      (1, 0, int,  None), 
-                        'x':           (1, 0, int,  None), 
-                        'y':           (1, 0, int,  None)},  
-                      1, (0,('block',))),
-      'trigger':    ( GFTrigger.GFTrigger, 
-                      { 'name':        (0, 1, char, None), 
-                        'id':          (0, 0, char, None),  # DEPRECATED: Use 
name instead
-                        'type':        (0, 0, char, None), 
-                        'src':         (0, 0, char, None), 
-                        'language':    (0, 0, char,'python')}, 
-                      0, (1,('form',))),
-      'options':    ( GFObjects.GFOptions,    
-                      {}, 
-                      1, (1,('form',))),
-      'option':     ( GFObjects.GFOption,
-                      { 'name':        (1, 0, char, None)},
-                      1, (0,('option',))),
-      'title':      ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'title')},
-                      1, (0,None)),
-      'name':       ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'name')},
-                      1, (0,None)),
-      'height':     ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'height')},
-                      1, (0,None)),
-      'width':      ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'width')},
-                      1, (0,None)),
-      'author':     ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'author')},
-                      1, (0,None)),
-      'description':( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'description')},
-                      1, (0,None)),
-      'version':    ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'version')},
-                      1, (0,None)),
-      'tip':        ( GFObjects.GFOption,
-                      { 'name':        (0, 0, char, 'tip')},
-                      1, (0,('options',))), 
+      'entry': { 
+         'BaseClass':    GFObjects.GFEntry,
+         'Attributes': { 
+            'name': {
+               'Required': 1, 
+               'Unique':   1, 
+               'Typecast': char }, 
+            'field': {
+               'Typecast': char }, 
+            'height': {
+               'Typecast': int }, 
+            'width': {
+               'Typecast': int }, 
+            'max_length': {
+               'Typecast': int }, 
+            'visibleCount':{
+               'Typecast': int }, 
+            'readonly': {
+               'Typecast': bool, 
+               'Default':  0   }, 
+            'uppercase': {
+               'Typecast': bool, 
+               'Default':  0   }, 
+            'lowercase': {
+               'Typecast': bool, 
+               'Default':  0   }, 
+            'numeric': {
+               'Typecast': bool, 
+               'Default':  0   }, 
+            'hidden': {
+               'Typecast': bool, 
+               'Default':  0   }, 
+            'field': {
+               'Typecast': char }, 
+            'style': {
+               'Typecast': char, 
+               'Default': 'default'}, 
+            'value': {
+               'Typecast': char }, 
+            'foreign_key': {
+               'Typecast': char }, 
+            'default': {
+               'Typecast': char }, 
+            'queryDefault':{
+               'Typecast': char }, 
+            'foreign_key_description': {
+               'Typecast': char }, 
+            'sloppyQuery': {
+               'Typecast': char }, 
+            'x': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'y': {
+               'Required': 1, 
+               'Typecast': int } }, 
+         'ParentTags':  ('block',) },
+
+      'scrollbar': { 
+         'BaseClass':    GFObjects.GFScrollBar,  
+         'Attributes': { 
+            'width': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'height': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'x': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'y': {
+               'Required': 1, 
+               'Typecast': int } }, 
+         'ParentTags':  ('block',) },
+
+      'box': { 
+         'BaseClass':    GFObjects.GFBox,
+         'Attributes': { 
+            'name': {
+               'Unique':   1, 
+               'Typecast': char }, 
+            'label': {
+               'Typecast': char }, 
+            'width': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'height': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'x': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'y': {
+               'Required': 1, 
+               'Typecast': int } }, 
+         'ParentTags':  ('block',) },
+
+      'button': { 
+         'BaseClass':    GFObjects.GFButton,     
+         'Attributes': { 
+            'name': {
+               'Unique':   1, 
+               'Typecast': char }, 
+            'trigger': {
+               'Typecast': char }, 
+            'label': {
+               'Typecast': char }, 
+            'width': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'height': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'x': {
+               'Required': 1, 
+               'Typecast': int }, 
+            'y': {
+               'Required': 1, 
+               'Typecast': int } },  
+         'ParentTags':  ('block',) },
+
+      'trigger': { 
+         'BaseClass':    GFTrigger.GFTrigger, 
+         'Attributes': { 
+            'name': {
+               'Unique':   1, 
+               'Typecast': char }, 
+            'id': {
+               'Deprecated': 1, 
+               'Typecast': char },  # DEPRECATED: Use name instead
+            'type': {
+               'Typecast': char }, 
+            'src': {
+               'Typecast': char }, 
+            'language': {
+               'Typecast': char,
+               'Default':  'python' } }, 
+         'MixedContent': 1, 
+         'KeepWhitespace': 1, 
+         'UsableBySiblings': 1, 
+         'ParentTags':  ('form',) },
+
+      'options': { 
+         'BaseClass':    GFObjects.GFOptions,    
+         'UsableBySiblings': 1, 
+         'ParentTags':  ('form',) },
+
+      'option': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Required': 1, 
+               'Typecast': char } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'title': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'title' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'name': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'name' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'height': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'height' } },
+         'MixedContent':   1, 
+         'ParentTags':  None },
+
+      'width': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'width' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'author': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'author' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'description':{ 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'description' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'version': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'version' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) },
+
+      'tip': { 
+         'BaseClass':    GFObjects.GFOption,
+         'Attributes': { 
+            'name': {
+               'Typecast': char, 
+               'Default':  'tip' } },
+         'MixedContent':   1, 
+         'ParentTags':  ('options',) }, 
     }
     
       
@@ -204,10 +434,13 @@
     #
     for key in ('datasource','page','block','trigger','button','entry'): 
       name = "import-%s" % key
-      p = {}
-      for k in xmlElements[key][1].keys(): 
-        p[k] = xmlElements[key][1][k][:]
-      p['library'] = (1, 0, char, None)
+      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(xmlElements[key])
+      p['Attributes']['library'] = (1, 0, char, None)
+      p['MixedContent'] = 0
     
       xmlElements[name] = (GFLibrary.GFImportItem, p)
      
@@ -223,7 +456,7 @@
 #
 entryStyles = {'text':       'Text Field', 
                'dropdown':   'Drop Down Box', 
-               'checkbox':   'Check Box'}
+               'checkbox':   'Check Box' }
 
 #######################################################
 #
Index: gnue/gnuef/src/GFTrigger.py
diff -u gnue/gnuef/src/GFTrigger.py:1.34 gnue/gnuef/src/GFTrigger.py:1.35
--- gnue/gnuef/src/GFTrigger.py:1.34    Mon Jun 25 18:31:12 2001
+++ gnue/gnuef/src/GFTrigger.py Tue Jun 26 20:17:58 2001
@@ -33,6 +33,7 @@
 from GFEvent import *
 from GFTriggerError import *
 from gnue.common.GParser import GContent
+from xml.sax import saxutils
 
 import string
 
@@ -188,6 +189,52 @@
     else: 
       return VALIDTRIGGERS[self.type]
   
+  def dumpXML(self, lookupDict, treeDump=None, gap=None):
+    escape = not int(GConfig.get('StoreTriggersAsCDATA','0'))
+    xmlEntity = "trigger"
+    xmlString = "%s<%s" % (gap[:-2],xmlEntity)
+
+    for attribute in self.__dict__.keys():
+      # skip keys beginning with _
+      if attribute[0] == "_":
+        continue
+      val = self.__dict__[attribute]
+      if lookupDict[xmlEntity].has_key('Attributes') and \
+         lookupDict[xmlEntity]['Attributes'].has_key(attribute): 
+        if lookupDict[xmlEntity]['Attributes'][attribute].has_key('Default') 
and \
+           ('%s'%lookupDict[xmlEntity]['Attributes'][attribute]['Default']) != 
('%s'%val): 
+          if lookupDict[xmlEntity][1][attribute][2] == bool \
+             and val == 1:
+            xmlString = xmlString + ' %s=""' % (attribute)
+          else: 
+            xmlString = xmlString + ' %s="%s"' % (attribute, 
saxutils.escape('%s' % val))
+        
+    if len(self._children): 
+      hasContent = 0 
+      for child in self._children: 
+        hasContent = hasContent or isinstance(child,GContent)
+      if hasContent: 
+        xmlString = xmlString + ">"
+      else: 
+        xmlString = xmlString + ">\n"
+       
+      if treeDump:
+        if hasContent and escape: 
+          xmlString = xmlString + "<![CDATA["
+        for child in self._children:
+          xmlString = xmlString + child.dumpXML(lookupDict, 1,gap+"  
",escape=escape)
+        if hasContent and escape: 
+          xmlString = xmlString + "]]!>"
+
+      if hasContent: 
+        xmlString = xmlString + "</%s>\n" % (xmlEntity)
+      else: 
+        xmlString = xmlString + "%s</%s>\n" % (gap[:-2], xmlEntity)
+    else: 
+      xmlString = xmlString + "/>\n"      
+    return xmlString
+
+
 #
 # Helper class for building the namespace for python triggers. All access
 # to GFObjects from triggers are through this class. Its function is to



reply via email to

[Prev in Thread] Current Thread [Next in Thread]