]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/tools/XRCed/xxx.py
Putting draft of wxImplDC and the wxDC using it
[wxWidgets.git] / wxPython / wx / tools / XRCed / xxx.py
index cdbc54c0307f7d8166e83a75beefb7706709fa61..147240efc1335e9c9dae973e42095a27e6e9307c 100644 (file)
@@ -191,7 +191,7 @@ class xxxObject:
     hasName = True                      # has name attribute?
     isSizer = hasChild = False
     isElement = True
-    allParams = None                    # Some nodes have no parameters
+    allParams = []                     # Some nodes have no parameters
     # Style parameters (all optional)
     styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
     # Special parameters
@@ -315,6 +315,16 @@ class xxxObject:
         else: obj = self
         obj.name = name
         obj.node.setAttribute('name', name)
+    # Set normal (text) params
+    def set(self, param, value):
+        try:
+            self.params[param].update(value)
+        except KeyError:
+            elem = g.tree.dom.createElement(param)
+            p = xxxParam(elem)
+            p.update(value)
+            self.params[param] = p
+            self.node.appendChild(elem)
     # Special processing for growablecols-like parameters
     # represented by several nodes
     def special(self, tag, node):
@@ -837,7 +847,8 @@ class xxxChildContainer(xxxObject):
 class xxxSizerItem(xxxChildContainer):
     allParams = ['option', 'flag', 'border', 'minsize', 'ratio']
     paramDict = {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
-    #default = {'cellspan': '1,1'}
+    defaults_panel = {}
+    defaults_control = {}
     def __init__(self, parent, element, refElem=None):
         # For GridBag sizer items, extra parameters added
         if isinstance(parent, xxxGridBagSizer):
@@ -1007,14 +1018,29 @@ def custom(klassName, klass='unknown'):
     g.pullDownMenu.addCustom(klassName)
 
 class xxxParamComment(xxxParam):
+    locals = {}                         # namespace for comment directives
+    allow = None                        # undefined initial state for current file
     def __init__(self, node):
         xxxNode.__init__(self, node)
         self.textNode = node
-        # Parse "pragma" comments
-        if node.data and node.data[0] == '%':
+        # Parse "pragma" comments if enabled
+        if node.data and node.data[0] == '%' and g.conf.allowExec != 'no' and \
+               xxxParamComment.allow is not False:
+            # Show warning
+            if g.conf.allowExec == 'ask' and xxxParamComment.allow is None:
+                flags = wx.ICON_EXCLAMATION | wx.YES_NO | wx.CENTRE
+                dlg = wx.MessageDialog(g.frame, '''
+This file contains executable %comment directives. Allow to execute?''',
+                                       'Warning', flags)
+                say = dlg.ShowModal()
+                dlg.Destroy()
+                if say == wx.ID_YES:
+                    xxxParamComment.allow = True
+                else:
+                    xxxParamComment.allow = False
             try:
                 code = node.data[1:]
-                exec code in globals()
+                exec code in globals(), self.locals
             except:
                 wx.LogError('exec error: "%s"' % code)
                 print traceback.print_exc()
@@ -1174,7 +1200,8 @@ def MakeEmptyDOM(className):
 def MakeEmptyXXX(parent, className):
     # Make corresponding DOM object first
     elem = MakeEmptyDOM(className)
-    # If parent is a sizer, we should create sizeritem object, except for spacers
+    # Special handling, e.g. if parent is a sizer, we should create
+    # sizeritem object, except for spacers, etc.
     if parent:
         if parent.isSizer and className != 'spacer':
             sizerItemElem = MakeEmptyDOM(parent.itemTag)
@@ -1193,7 +1220,16 @@ def MakeEmptyXXX(parent, className):
             pageElem.appendChild(elem)
             elem = pageElem
     # Now just make object
-    return MakeXXXFromDOM(parent, elem)
+    xxx = MakeXXXFromDOM(parent, elem)
+    # Special defaults for new panels and controls
+    if isinstance(xxx, xxxSizerItem):
+        if isinstance(xxx.child, xxxContainer) and not xxx.child.isSizer:
+            for param,v in xxxSizerItem.defaults_panel.items():
+                xxx.set(param, v)
+        elif isinstance(xxx.child, xxxObject):
+            for param,v in xxxSizerItem.defaults_control.items():
+                xxx.set(param, v)
+    return xxx            
 
 # Make empty DOM element for reference
 def MakeEmptyRefDOM(ref):