Пример #1
0
 def AddNode(self, parent, node):
     # Append tree item
     try:
         comp = Manager.getNodeComp(node, None)
         className = comp.klass
     except:
         className = node.getAttribute('class')
         # Try to create some generic component on-the-fly
         attributes = []
         isContainer = False
         for n in node.childNodes:
             if is_object(n):
                 isContainer = True
             elif n.nodeType == node.ELEMENT_NODE and not n.tagName in attributes:
                 attributes.append(n.tagName)
         if isContainer:
             comp = Container(className, 'unknown', attributes)
         else:
             comp = Component(className, 'unknown', attributes)
         Manager.register(comp)
         wx.LogWarning(
             'Unknown component class "%s", registered as generic' %
             className)
     item = self.AppendItem(parent,
                            comp.getTreeText(node),
                            image=comp.getTreeImageId(node),
                            data=wx.TreeItemData(node))
     self.SetItemStyle(item, node)
     # Try to find children objects
     if comp.isContainer():
         for n in filter(is_object, node.childNodes):
             self.AddNode(item, comp.getTreeNode(n))
Пример #2
0
 def __init__(self, page_size, LayoutStrategy, canvas):
     '''LayoutStrategy is class name'''
     self.layout = LayoutStrategy
     self.canvas = canvas
     self.page_size = page_size
     self.pages = []
     self.container = Container(self.canvas,
                                self.layout(page_size))
     self.pages.append(self.container)
Пример #3
0
 def addComponent(self, component):
     '''can raise OutofBoundError'''
     try:
         self.container.addChild(component)
     except OutofBoundError:
         self.container = Container(self.canvas,
                                    self.layout(self.page_size))
         self.pages.append(self.container)
         self.container.addChild(component)
Пример #4
0
    def AddNode(self, parent, node):
        # Append tree item
        try:
            comp = Manager.getNodeComp(node, None)
            className = comp.klass
        except:
            className = node.getAttribute('class')
            # Try to create some generic component on-the-fly
            attributes = []
            isContainer = False
            for n in node.childNodes:
                if is_object(n):
                    isContainer = True
                elif n.nodeType == node.ELEMENT_NODE and not n.tagName in attributes:
                    attributes.append(n.tagName)
            if isContainer:
                comp = Container(className, 'unknown', attributes)
            else:
                comp = Component(className, 'unknown', attributes)
            Manager.register(comp)
            wx.LogWarning(
                'Unknown component class "%s", registered as generic' %
                className)
        item = self.AppendItem(parent,
                               comp.getTreeText(node),
                               image=comp.getTreeImageId(node),
                               data=wx.TreeItemData(node))
        self.SetItemStyle(item, node)
        # Try to find children objects
        if comp.isContainer():
            for n in filter(is_object, node.childNodes):
                self.AddNode(item, comp.getTreeNode(n))
        elif node.nodeType == node.COMMENT_NODE:
            if node.data and node.data[0] == '%' and g.conf.allowExec != 'no':
                if g.conf.allowExec == 'ask' and Model.allowExec is None:
                    say = wx.MessageBox(
                        '''This file contains executable comment directives. \
Allow to execute?''', 'Warning', wx.ICON_EXCLAMATION | wx.YES_NO)
                    if say == wx.YES:
                        Model.allowExec = True
                    else:
                        Model.allowExec = False
                if g.conf.allowExec == 'yes' or Model.allowExec:
                    code = node.data[1:]  # skip '%'
                    try:
                        exec code in globals(), self.locals
                    except:
                        wx.LogError('exec error: "%s"' % code)
                        logger.exception("execution of in-line comment failed")