def exportTopicTreeSpecXml(moduleName=None,
                           rootTopic=None,
                           bak='bak',
                           moduleDoc=None):
    '''
    If rootTopic is None, then pub.getDefaultTopicTreeRoot() is assumed.
    '''

    if rootTopic is None:
        from pubsub import pub
        rootTopic = pub.getDefaultTopicTreeRoot()
    elif isinstance(rootTopic, (str, unicode)):
        from pubsub import pub
        rootTopic = pub.getTopic(rootTopic)

    tree = ET.Element('topicdefntree')
    if moduleDoc:
        mod_desc = ET.SubElement(tree, 'description')
        mod_desc.text = ' '.join(moduleDoc.split())

    traverser = pub.TopicTreeTraverser(XmlVisitor(tree))
    traverser.traverse(rootTopic)

    indent(tree)

    if moduleName:

        filename = '%s.xml' % moduleName
        if bak:
            pub._backupIfExists(filename, bak)

        fulltree = ET.ElementTree(tree)
        fulltree.write(filename, "utf-8", True)

    return ET.tostring(tree)
def exportTopicTreeSpecXml(moduleName=None, rootTopic=None, bak='bak', moduleDoc=None):
    '''
    If rootTopic is None, then pub.getDefaultTopicTreeRoot() is assumed.
    '''

    if rootTopic is None:
        from pubsub import pub
        rootTopic = pub.getDefaultTopicTreeRoot()
    elif isinstance(rootTopic, (str, unicode)):
        from pubsub import pub
        rootTopic = pub.getTopic(rootTopic)

    tree = ET.Element('topicdefntree')
    if moduleDoc:
        mod_desc = ET.SubElement(tree, 'description')
        mod_desc.text = ' '.join(moduleDoc.split())

    traverser = pub.TopicTreeTraverser(XmlVisitor(tree))
    traverser.traverse(rootTopic)

    indent(tree)

    if moduleName:

        filename = '%s.xml' % moduleName
        if bak:
            pub._backupIfExists(filename, bak)

        fulltree= ET.ElementTree(tree)
        fulltree.write(filename, "utf-8", True)

    return ET.tostring(tree)
示例#3
0
 def ShowListeners(self, evt):
     tName = self.GetItemText(self.GetSelection())
     tObj = pub.getTopic(str(tName))
     if tObj.hasListeners():
         llist = '\n'.join([repr(l.getCallable()) for l in tObj.getListenersIter()])
     else:
         llist = "No listeners"
     wx.MessageBox(llist, "Topic Listeners", style=wx.OK)
示例#4
0
 def __init__(self):
     self.__dict__ = self.__shared_state
     if not hasattr(self, 'initialized'):
         self.initialized = False
     pub.subscribe(self.Show, 'monitor.show')
     print "Made Monitor Tool"
     tobj= pub.getTopic('monitor.show')
     print tobj
示例#5
0
 def ShowListeners(self, evt):
     tName = self.GetItemText(self.GetSelection())
     tObj = pub.getTopic(str(tName))
     if tObj.hasListeners():
         llist = '\n'.join(
             [repr(l.getCallable()) for l in tObj.getListenersIter()])
     else:
         llist = "No listeners"
     wx.MessageBox(llist, "Topic Listeners", style=wx.OK)
示例#6
0
    def __init__(self, wxTree=None, startTopic=None):
        if wxTree is None:
            raise RunTimeError, "TopicTreeFiller needs a wx.TreeCtrl to work with"

        self.Tree = wxTree
        if startTopic is None:
            self.startTopic = pub.getTopic(pub.ALL_TOPICS)
        self.root = self.Tree.AddRoot(str(self.startTopic.getName()))
        self.lastT = self.root
        self.Topics = [self.root]
示例#7
0
 def __init__(self):
     self.__dict__ = self.__shared_state
     if not hasattr(self, 'initialized'):
         self.initialized = False
     pub.subscribe(self.Show, 'monitor.show')
     print
     "Made Monitor Tool"
     tobj = pub.getTopic('monitor.show')
     print
     tobj
示例#8
0
    def __init__(self, wxTree=None, startTopic=None):
        if wxTree is None:
            raise RunTimeError, "TopicTreeFiller needs a wx.TreeCtrl to work with"

        self.Tree = wxTree
        if startTopic is None:
            self.startTopic = pub.getTopic(pub.ALL_TOPICS)
        self.root = self.Tree.AddRoot(str(self.startTopic.getName()))
        self.lastT = self.root
        self.Topics = [self.root]
def exportTopicTreeSpec(moduleName=None, rootTopic=None, bak="bak", moduleDoc=None):
    """Export the topic tree rooted at rootTopic to module (.py) file. This file 
    will contain a nested class hierarchy representing the topic tree. Returns a
    string representing the contents of the file. Parameters:

        - If moduleName is given, the topic tree is written to moduleName.py in
          os.getcwd() (the file is overwritten). If bak is None, the module file
          is not backed up.
        - If rootTopic is specified, the export only traverses tree from 
          corresponding topic. Otherwise, complete tree, using 
          pub.getDefaultTopicTreeRoot() as starting  point.
        - The moduleDoc is the doc string for the module ie topic tree.
    """

    if rootTopic is None:
        from pubsub import pub

        rootTopic = pub.getDefaultTopicTreeRoot()
    elif isinstance(rootTopic, (str, unicode)):
        from pubsub import pub

        rootTopic = pub.getTopic(rootTopic)

    # create exporter
    if moduleName is None:
        from StringIO import StringIO

        capture = StringIO()
        TopicTreeSpecPrinter(rootTopic, fileObj=capture, treeDoc=moduleDoc)
        return capture.getvalue()

    else:
        filename = "%s.py" % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = file(filename, "w")
        try:
            TopicTreeSpecPrinter(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()
def exportTopicTreeSpec(moduleName = None, rootTopic=None, bak='bak', moduleDoc=None):
    '''Export the topic tree rooted at rootTopic to module (.py) file. This file 
    will contain a nested class hierarchy representing the topic tree. Returns a
    string representing the contents of the file. Parameters:

        - If moduleName is given, the topic tree is written to moduleName.py in
          os.getcwd() (the file is overwritten). If bak is None, the module file
          is not backed up.
        - If rootTopic is specified, the export only traverses tree from 
          corresponding topic. Otherwise, complete tree, using 
          pub.getDefaultTopicTreeRoot() as starting  point.
        - The moduleDoc is the doc string for the module ie topic tree.
    '''

    if rootTopic is None:
        from pubsub import pub
        rootTopic = pub.getDefaultTopicTreeRoot()
    elif isinstance(rootTopic, (str, unicode)):
        from pubsub import pub
        rootTopic = pub.getTopic(rootTopic)

    # create exporter
    if moduleName is None:
        from StringIO import StringIO
        capture = StringIO()
        TopicTreeSpecPrinter(rootTopic, fileObj=capture, treeDoc=moduleDoc)
        return capture.getvalue()

    else:
        filename = '%s.py' % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = file(filename, 'w')
        try:
            TopicTreeSpecPrinter(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()
示例#11
0
 def _load(self, evt=None):
     self.DeleteAllItems()
     trv = TopicTreeFiller(self)
     trv.traverse(pub.getTopic(pub.ALL_TOPICS))
     self.Expand(self.GetRootItem())
示例#12
0
 def OnSelection(self, evt):
     tName = self.GetItemText(self.GetSelection())
     tObj = pub.getTopic(str(tName))
     self.Parent.SetTopicDescription(tObj)
示例#13
0
 def SendPubSubMessage(self, evt):
     tName = self.GetItemText(self.GetSelection())
     tObj = pub.getTopic(str(tName))
     dlg = SendMessageDialog(self, tObj)
     dlg.ShowModal()
示例#14
0
 def _load(self, evt=None):
     self.DeleteAllItems()
     trv = TopicTreeFiller(self)
     trv.traverse(pub.getTopic(pub.ALL_TOPICS))
     self.Expand(self.GetRootItem())
示例#15
0
 def OnSelection(self, evt):
     tName = self.GetItemText(self.GetSelection())
     tObj = pub.getTopic(str(tName))
     self.Parent.SetTopicDescription(tObj)
示例#16
0
 def SendPubSubMessage(self, evt):
     tName = self.GetItemText(self.GetSelection())
     tObj = pub.getTopic(str(tName))
     dlg = SendMessageDialog(self, tObj)
     dlg.ShowModal()