def __init__(self, parent, ID, uri):
        EditorInterface.__init__(self, parent, False, uri)
        ElementMap.__init__(self, parent, ID)

        self._controller = Controller()
        self._logger     = self._controller.getLogger()
        self._model      = Model()
        self._circtree   = ComponentManager().getComponent("circuit").getCircuitTree()
        self._importer   = edef.Importer()
        self._mainframe  = self._controller.getMainFrame()
        
        self.setTitle(uri)
       
        if not uri == "circ://":
            self._loadCircuit(uri)
            self.redraw()
            self.setModified(False)

        self._target = CircuitDropTarget(self)
        self.SetDropTarget( self._target )
示例#2
0
    def __init__(self, parent, ID, uri):
        ScrolledPanel.__init__(self, parent, ID)
        eDevEditorInterface.__init__(self, parent, False, uri)

        self._controller = Controller()
        self._model      = Model()
        self._mainframe  = self._controller.getMainFrame()
        self._component_manager = ComponentManager()
        self._moduletree = self._component_manager.getComponent("modeditor").getModuleTree()
        self._notebook   = self._controller.getNotebook()


        if uri == "mod://":
            txt = '<?xml version="1.0"?><Module version="1.0"/>'
            title = "unsaved"
        else:
            txt = self._model.openURI(uri)
            title = getModuleName(uri)
        self.setTitle(title)
        
        self._d_doc = xml.dom.minidom.parseString(txt)

        vert_box = wx.BoxSizer(wx.VERTICAL)
        self._d_basic_data = eDevModuleEditorBasic(self, -1, self._d_doc)
        self._d_require = eDevModuleEditorRequire(self, -1, self._d_doc)
        self._d_provide = eDevModuleEditorProvide(self, -1, self._d_doc)

        self.Bind(Events.EVT_MODIFIED, self.OnModified, self._d_basic_data)
        self.Bind(Events.EVT_MODIFIED, self.OnModified, self._d_require)
        self.Bind(Events.EVT_MODIFIED, self.OnModified, self._d_provide)

        vert_box.Add(self._d_basic_data, 0, wx.EXPAND|wx.ALL, 15)
        vert_box.Add(self._d_require, 0, wx.EXPAND|wx.ALL, 15)
        vert_box.Add(self._d_provide, 0, wx.EXPAND|wx.ALL, 15)

        self.SetSizer(vert_box)
        self.SetAutoLayout(1)
        self.SetupScrolling()
示例#3
0
class eDevModuleEditor(ScrolledPanel, eDevEditorInterface):
    _d_txt  = None

    def __init__(self, parent, ID, uri):
        ScrolledPanel.__init__(self, parent, ID)
        eDevEditorInterface.__init__(self, parent, False, uri)

        self._controller = Controller()
        self._model      = Model()
        self._mainframe  = self._controller.getMainFrame()
        self._component_manager = ComponentManager()
        self._moduletree = self._component_manager.getComponent("modeditor").getModuleTree()
        self._notebook   = self._controller.getNotebook()


        if uri == "mod://":
            txt = '<?xml version="1.0"?><Module version="1.0"/>'
            title = "unsaved"
        else:
            txt = self._model.openURI(uri)
            title = getModuleName(uri)
        self.setTitle(title)
        
        self._d_doc = xml.dom.minidom.parseString(txt)

        vert_box = wx.BoxSizer(wx.VERTICAL)
        self._d_basic_data = eDevModuleEditorBasic(self, -1, self._d_doc)
        self._d_require = eDevModuleEditorRequire(self, -1, self._d_doc)
        self._d_provide = eDevModuleEditorProvide(self, -1, self._d_doc)

        self.Bind(Events.EVT_MODIFIED, self.OnModified, self._d_basic_data)
        self.Bind(Events.EVT_MODIFIED, self.OnModified, self._d_require)
        self.Bind(Events.EVT_MODIFIED, self.OnModified, self._d_provide)

        vert_box.Add(self._d_basic_data, 0, wx.EXPAND|wx.ALL, 15)
        vert_box.Add(self._d_require, 0, wx.EXPAND|wx.ALL, 15)
        vert_box.Add(self._d_provide, 0, wx.EXPAND|wx.ALL, 15)

        self.SetSizer(vert_box)
        self.SetAutoLayout(1)
        self.SetupScrolling()


    def OnModified(self, evt):
        #print "Something was modified"
        self.setModified()
        event = Events.PageModifiedEvent(Events._event_modified, self.GetId())
        event.SetPage(self)
        self.GetEventHandler().ProcessEvent(event)
        evt.Skip()
        self._updateMainFrame()

    
    def OnSelected(self):
        self._updateMainFrame()

    
    def _updateMainFrame(self):
        self._mainframe.bindCopy()
        self._mainframe.bindCut()
        self._mainframe.bindPaste()
        self._mainframe.bindRedo()
        self._mainframe.bindUndo()

        self._mainframe.bindSaveAs(self.OnSaveAs)
        if self.isModified() and self.getURI() != "mod://":
            self._mainframe.bindSave(self.OnSave)
        else: self._mainframe.bindSave()


    def _toXML(self):
        impl = xml.dom.minidom.getDOMImplementation()
        dom  = impl.createDocument(None, "Module", None)
        dom.documentElement.setAttribute("version","1.0")
        
        node_list = self._d_basic_data.ToXML(dom)
        
        node_list += self._d_require.ToXML(dom)
        
        node_list += self._d_provide.ToXML(dom)
        
        for node in node_list:
            dom.documentElement.appendChild(node)

        return dom.toprettyxml("    ")


    def OnSave(self, evt=None):
        if self.getURI() == "mod://": return
        
        txt = self._toXML()
        self._controller.DocumentSave(self.getURI(),txt)
        self.setModified(False)
        self._updateMainFrame()


    def OnSaveAs(self, evt=None):
        selected = False
        while not selected:
            dlg = Dialogs.eDevSaveModuleAsDialog(self, -1)
            if dlg.ShowModal() != wx.ID_OK:
                return
            uri = "mod://%s"%dlg.getSelection()
            dlg.Destroy()
            if self._model.checkURI(uri):
                # FIXME Override?
                continue
            selected = True
        
        if not self._model.checkURI(uri):
            self._controller.DocumentSave(uri, self._toXML())
            self._moduletree.addURI(uri)
        else:
            self._controller.DocumentSave(uri, self._toXML())
        self.setURI(uri)
        self.setTitle( getModuleName(uri) )
class CircuitEditor(EditorInterface, ElementMap):
    
    def __init__(self, parent, ID, uri):
        EditorInterface.__init__(self, parent, False, uri)
        ElementMap.__init__(self, parent, ID)

        self._controller = Controller()
        self._logger     = self._controller.getLogger()
        self._model      = Model()
        self._circtree   = ComponentManager().getComponent("circuit").getCircuitTree()
        self._importer   = edef.Importer()
        self._mainframe  = self._controller.getMainFrame()
        
        self.setTitle(uri)
       
        if not uri == "circ://":
            self._loadCircuit(uri)
            self.redraw()
            self.setModified(False)

        self._target = CircuitDropTarget(self)
        self.SetDropTarget( self._target )


    def _loadCircuit(self, uri):
        wire_list = []
        mod_table = {}
        self._logger.debug("Load %s"%uri)
        
        xml = self._model.openURI(uri)
        meta = CircuitMeta(xml)
        mods = meta.getModules()
        
        for (ID, (name, label, (x,y), params)) in mods.items():
            self._logger.debug("Load module %s as %s @ %s,%s"%(name, label, x,y))
            moduri = "mod://"+"/".join(name.split("."))
            mod_table[ID] = self.loadModule(moduri, x,y, params)
            mod_table[ID].setLabel(label)
            wire_list += meta.getWires(ID)
            
        for ( frm, to ) in wire_list:
            (frm_id, frm_pin) = frm
            (to_id,  to_pin)  = to
            frm = mod_table[frm_id].getPin(frm_pin)
            to  = mod_table[to_id].getPin(to_pin)
            self.connect(frm,to)
         

    def OnSelected(self, evt=None):
        self._updateMainFrame()


    def _updateMainFrame(self):
        self._mainframe.bindCopy()
        self._mainframe.bindCut()
        self._mainframe.bindPaste()
        self._mainframe.bindRedo()
        self._mainframe.bindUndo()
        
        self._mainframe.bindSaveAs(self.OnSaveAs)
        if self.isModified() and self.getURI() != "circ://":
            self._mainframe.bindSave(self.OnSave)
        else: self._mainframe.bindSave()


    def OnModified(self):
        self.setModified(True)
        self._updateMainFrame()
        

    def OnSave(self, evt):
        self._logger.debug("On save...")
        
        if self.getURI() == "circ://":
            self.OnSaveAs(evt)
            return
                    
        txt = self._to_xml().toprettyxml(" ")
        self._model.saveURI(self.getURI(), txt)
        self.setModified(False)
        self._updateMainFrame()


    def OnSaveAs(self, evt):
        dlg = SaveAsDialog(self, -1)
        if dlg.ShowModal()==wx.ID_CANCEL:
            dlg.Destroy()
            return
        uri = dlg.getSelection()
        dlg.Destroy()

        try:
            txt = self._to_xml().toprettyxml("  ")
            self._model.saveURI(uri, txt)
        except:
            showExceptionDialog(self, -1, "Unable to save file to %s"%uri)

        self.setURI(uri)
        self.setTitle(uri)
        self._circtree.addURI(uri)
        self.setModified(False)
        self._updateMainFrame()


    def _to_xml(self):
        dom_impl = getDOMImplementation()

        doc = dom_impl.createDocument(None, "Circuit", None)
        root = doc.documentElement

        mods = self.getObjects(gModule)
        for idx in range(len(mods)):
            mod = mods[idx]
            mod_node = mod._to_xml(doc, idx)
            cons = self.getConnectionsFrom(mod)
            for con in cons:
                to_pin = con.getTo().getName()
                frm_pin = con.getFrom().getName()
                to_idx = mods.index(con.getTo().getModule())
                wire = doc.createElement("Wire")
                frm = doc.createElement("From")
                frm.setAttribute("id", str(idx))
                frm.setAttribute("pin",frm_pin)
                wire.appendChild(frm)
                to = doc.createElement("To")
                to.setAttribute("id", str(to_idx))
                to.setAttribute("pin", to_pin)
                wire.appendChild(to)
                root.appendChild(wire)
            root.appendChild(mod_node)
        return doc
示例#5
0
    def __init__(self, parent, ID, uri):
        stc.StyledTextCtrl.__init__(self, parent, ID, style=0)

        if uri == "zip://":
            modified = True
            title = "unsaved"
        else:
            modified = False
            (aname, title) = splitPyFile(uri)

        EditorInterface.__init__(self, parent, False, uri)
        self.setTitle(title)

        self._d_config = Config()

        self._d_controller = Controller()
        self._logger = self._d_controller.getLogger()
        self._d_mainframe = self._d_controller.getMainFrame()
        self._d_model = Model()
        self._d_notebook = self._d_controller.getNotebook()
        self._pyedit_component = ComponentManager().getComponent("pyeditor")
        self._archive_tree = self._pyedit_component.getArchiveTree()

        self.SetLexer(stc.STC_LEX_PYTHON)
        self.SetKeyWords(0, " ".join(keyword.kwlist))

        # config:
        font = self._d_config.getEditorFont()
        fsize = self._d_config.getEditorFontSize()
        sdfsize = self._d_config.getEditorSecondFontSize()
        faces = {"times": font, "mono": font, "helv": font, "other": font, "size": fsize, "size2": sdfsize}

        self.SetTabWidth(self._d_config.getEditorTabSpace())
        self.SetUseTabs(not self._d_config.getEditorExpandTab())

        self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
        self.StyleClearAll()  # Reset all to be like the default

        self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")

        self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
        self.SetCaretForeground("BLUE")

        if isPyFileURI(uri):
            text = self._d_model.openURI(uri)
        else:
            text = ""
        self.SetText(text)
        self.EmptyUndoBuffer()
        self.Colourise(0, -1)

        self.Bind(stc.EVT_STC_CHANGE, self.OnModified)
示例#6
0
class PythonEditor(stc.StyledTextCtrl, EditorInterface):
    def __init__(self, parent, ID, uri):
        stc.StyledTextCtrl.__init__(self, parent, ID, style=0)

        if uri == "zip://":
            modified = True
            title = "unsaved"
        else:
            modified = False
            (aname, title) = splitPyFile(uri)

        EditorInterface.__init__(self, parent, False, uri)
        self.setTitle(title)

        self._d_config = Config()

        self._d_controller = Controller()
        self._logger = self._d_controller.getLogger()
        self._d_mainframe = self._d_controller.getMainFrame()
        self._d_model = Model()
        self._d_notebook = self._d_controller.getNotebook()
        self._pyedit_component = ComponentManager().getComponent("pyeditor")
        self._archive_tree = self._pyedit_component.getArchiveTree()

        self.SetLexer(stc.STC_LEX_PYTHON)
        self.SetKeyWords(0, " ".join(keyword.kwlist))

        # config:
        font = self._d_config.getEditorFont()
        fsize = self._d_config.getEditorFontSize()
        sdfsize = self._d_config.getEditorSecondFontSize()
        faces = {"times": font, "mono": font, "helv": font, "other": font, "size": fsize, "size2": sdfsize}

        self.SetTabWidth(self._d_config.getEditorTabSpace())
        self.SetUseTabs(not self._d_config.getEditorExpandTab())

        self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
        self.StyleClearAll()  # Reset all to be like the default

        self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
        self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
        self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
        self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")

        self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
        self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
        self.SetCaretForeground("BLUE")

        if isPyFileURI(uri):
            text = self._d_model.openURI(uri)
        else:
            text = ""
        self.SetText(text)
        self.EmptyUndoBuffer()
        self.Colourise(0, -1)

        self.Bind(stc.EVT_STC_CHANGE, self.OnModified)

    def OnModified(self, evt):
        if self.isModified():
            return
        self.setModified()
        event = Events.PageModifiedEvent(Events._event_page_modified, self.GetId())
        event.SetPage(self)
        self.GetEventHandler().ProcessEvent(event)
        self._updateMainFrame()
        # evt.Skip()

    def OnSelected(self, evt=None):
        self._updateMainFrame()

    def _updateMainFrame(self):
        self._d_mainframe.bindRedo()
        self._d_mainframe.bindUndo()
        self._d_mainframe.bindSave()
        self._d_mainframe.bindSaveAs()
        self._d_mainframe.bindCopy()
        self._d_mainframe.bindCut()
        self._d_mainframe.bindPaste()

        if self.CanRedo():
            self._d_mainframe.bindRedo(self.OnRedo)
        if self.CanUndo():
            self._d_mainframe.bindUndo(self.OnUndo)
        self._d_mainframe.bindCopy(self.OnCopy)
        self._d_mainframe.bindCut(self.OnCut)
        if self.CanPaste():
            self._d_mainframe.bindPaste(self.OnPaste)

        self._d_mainframe.bindSaveAs(self.OnSaveAs)
        if self.isModified() and self.getURI() != "zip://":
            self._d_mainframe.bindSave(self.OnSave)

    def OnSaveAs(self, evt=None):
        selected = False
        while not selected:
            dlg = Dialogs.eDevSaveAsDialog(self, -1)
            if dlg.ShowModal() != wx.ID_OK:
                return
            uri = "zip://%s/%s" % dlg.getSelection()
            dlg.Destroy()
            if self._d_model.checkURI(uri):
                # FIXME Override?
                continue
            selected = True

        if not self._d_model.checkURI(uri):
            self._d_controller.DocumentSave(uri, self.GetText())
            self._archive_tree.addURI(uri)
        else:
            self._d_controller.DocumentSave(uri, self.GetText())
        self.setURI(uri)
        self._logger.debug("rename to " + uri)
        self._d_notebook.setPageTitleByURI(uri, getPyFile(uri))

    def OnSave(self, evt=None):
        txt = self.GetText()
        try:
            self._d_controller.DocumentSave(self.getURI(), txt)
            self.setModified(False)
        finally:
            self._updateMainFrame()

    def OnCopy(self, evt=None):
        self.Copy()
        self._updateMainFrame()

    def OnCut(self, evt=None):
        self.Cut()
        self._updateMainFrame()

    def OnPaste(self, evt=None):
        self.Paste()
        self._updateMainFrame()

    def OnRedo(self, evt=None):
        self.Redo()
        self._updateMainFrame()

    def OnUndo(self, evt=None):
        self.Undo()
        self._updateMainFrame()