def CreateConnection(self, event, from_component, from_port, to_component, to_port): try: conn = self.cm.create_connection(from_port, to_port) except: MsgBox("create_connection() failed.") self.LogException() return from_shape = self.component2shape[from_component] to_shape = self.component2shape[to_component] line = wxLineShape() line.SetCanvas(self) line.SetPen(wxBLACK_PEN) line.SetBrush(wxBLACK_BRUSH) line.AddArrow(ARROW_ARROW) line.MakeLineControlPoints(2) from_shape.AddLine(line, to_shape) self.diagram.AddShape(line) line.Show(true) self.line2connection[line] = conn self.connection2line[conn] = line dc = wxClientDC(self) self.PrepareDC(dc) # for some reason, the shapes have to be moved for the line to show up... from_shape.Move(dc, from_shape.GetX(), from_shape.GetY())
def RunOne(self, event, component): try: self.cm.reset_component(component) self.cm.run_one(component) except: MsgBox("run_one() failed.") self.LogException()
def ViewPort(self, event, port): parent = self.parent title = self.cm.get_port_description(port) obj = self.cm.get_port_object(port) if hasattr(obj, 'view'): obj.view(parent, title) else: MsgBox(str(obj))
def RemoveConnection(self, event, connection): try: self.cm.remove_connection(connection) pass except: MsgBox("remove_connection() failed.") self.LogException() return line = self.connection2line[connection] self.RemoveShape(line) line.Unlink() del self.connection2line[connection] del self.line2connection[line] # for some reason... self.Hide() self.Show()
def create_component(self, plugin): """create a component using a plugin, return None if user cancelled the operation""" used_names = [c.name for c in self.components] while 1: name = util.GetInput(caption="Create Component", question="Name of the component:", default=plugin.name) if not name: return None if name in used_names: MsgBox("The name is already used.") else: break obj = plugin.mod.create(self.callback) c = component(obj, name) self.components.append(c) return c
def CreateComponent(self, event, plugin): try: c = self.cm.create_component(plugin) if c is None: return # cancel except: MsgBox("create_component() failed.") self.LogException() return s = wxRectangleShape(100, 50) s.AddText(c.name) s.SetX(self.current_x) s.SetY(self.current_y) s.SetPen(wxBLACK_PEN) s.SetBrush(wxBrush(wxColour(219, 219, 255), wxSOLID)) s.SetCanvas(self) self.AddShape(s) s.Show(True) self.shape2component[s] = c self.component2shape[c] = s
def load_plugins(self): import sys import glob import os.path dirs = glob.glob(os.path.join('plugin', '*')) dirs.sort() for dir in dirs: if not os.path.isdir(dir): continue sys.path.append(dir) files = glob.glob(os.path.join(dir, '*_plugin.py')) files.sort() category = os.path.split(dir)[1] for f in files: try: p = plugin(category, __import__(os.path.split(f)[-1][:-3])) if (p.category, p.name) in [(q.category, q.name) for q in self.plugins]: raise Exception, "Duplicate plugin name: %s/%s" % ( p.category, p.name) self.plugins.append(p) except: MsgBox("Cannot load %s -- \n%s" % (f, util.get_traceback()))
def RunAll(self): try: self.cm.run_all() except: MsgBox("run_all() failed.") self.LogException()