def OnNewModel(self, evt): """ New model action has been invoked. """ mainW = wx.GetApp().GetTopWindow() nb2 = mainW.GetDiagramNotebook() canvas = nb2.GetPage(nb2.GetSelection()) gmwiz = Container.ShapeCanvas.OnStartWizard(canvas, evt) ### update the view of the domain if gmwiz: ### save .dat file in the .cmd or .amd m = BlockFactory.CreateBlock(label=gmwiz.label, inputs=gmwiz.inputs, outputs=gmwiz.outputs, python_file=gmwiz.python_path, model_file=gmwiz.model_path) if m: if not m.SaveFile(gmwiz.model_path): dlg = wx.MessageDialog(self, \ _('Error saving file %s\n')%os.path.basename(gmwiz.model_path), \ gmwiz.label, \ wx.OK | wx.ICON_ERROR) dlg.ShowModal() item = self.ItemDico[os.path.dirname(gmwiz.model_path)] self.UpdateDomain(self.GetPyData(item)) ### sort all item self.SortChildren(self.root) # Cleanup if gmwiz: gmwiz.Destroy()
def OnItemDocumentation(self, evt): """ Display the item's documentation on miniFrame. """ item = self.GetSelection() path = self.GetItemPyData(item) name = self.GetItemText(item) module = BlockFactory.GetModule(path) info = Container.CheckClass(path) if isinstance(info, tuple): doc = str(info) elif isinstance(module, tuple): doc = str(module) else: doc = inspect.getdoc(module) if doc: dlg = wx.lib.dialogs.ScrolledMessageDialog( self, doc, name, style=wx.OK | wx.ICON_EXCLAMATION | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) dlg.CenterOnParent(wx.BOTH) dlg.ShowModal() else: wx.MessageBox(_('No documentation'), name, wx.OK | wx.ICON_INFORMATION)
def OnMotion(self, evt): """ Motion engine over item. """ item, flags = self.HitTest(evt.GetPosition()) if (flags & wx.TREE_HITTEST_ONITEMLABEL) and not evt.LeftIsDown(): path = self.GetItemData(item) if os.path.isdir(path): model_list = self.GetModelList(path) domain_list = self.GetDomainList(path) tip = '\n'.join(model_list) if model_list != [] else "" tip += '\n' tip += '\n'.join(domain_list) if domain_list != [] else "" ### is last item else: module = BlockFactory.GetModule(path) info = Container.CheckClass(path) if isinstance(info, tuple): doc = str(info) elif isinstance(module, tuple): doc = str(module) else: doc = inspect.getdoc(module) tip = doc if doc is not None else _( "No documentation for selected model.") ### add maccabe metric info if item in self.MetricDico: mcc = self.MetricDico[item]['mcc'] tip = ''.join([tip, '\n', 'macCabe metric: %d' % mcc]) self.SetToolTip(tip) else: self.SetToolTip(None) ### else the drag and drop dont run evt.Skip()
def OnMotion(self, evt): """ Motion engine over item. """ item, flags = self.HitTest(evt.GetPosition()) if (flags & wx.TREE_HITTEST_ONITEMLABEL) and not evt.LeftIsDown(): path = self.GetItemPyData(item) if os.path.isdir(path): model_list = self.GetModelList(path) domain_list = self.GetDomainList(path) tip = '\n'.join(model_list) if model_list != [] else "" tip += '\n' tip += '\n'.join(domain_list) if domain_list != [] else "" ### is last item else: module = BlockFactory.GetModule(path) info = Container.CheckClass(path) if isinstance(info, tuple): doc = str(info) elif isinstance(module, tuple): doc = str(module) else: doc = inspect.getdoc(module) tip = doc if doc is not None else _( "No documentation for selected model.") try: txt = tip.decode('utf-8', 'ignore') except UnicodeEncodeError: sys.stdout.write("Unicode Error!\n") else: self.SetToolTip(wx.ToolTip(txt)) else: self.SetToolTip(None) ### else the drag and drop dont run evt.Skip()
def OnMiddleClick(self, evt): """ Middle click has been invoked. """ item_selected = evt.GetItem() GetItemPyData = self.GetItemPyData if wx.VERSION_STRING < '4.0' else self.GetItemData if not self.ItemHasChildren(item_selected): path = GetItemPyData(item_selected) mainW = wx.GetApp().GetTopWindow() nb2 = mainW.GetDiagramNotebook() canvas = nb2.GetPage(nb2.GetSelection()) ### define path for Python and model component if path.endswith('.py'): ### create component m = BlockFactory.CreateBlock( canvas=canvas, x=140, y=140, label=self.GetItemText(item_selected), id=0, inputs=1, outputs=1, python_file=path, model_file="") if m: # Adding graphical model to diagram canvas.AddShape(m) sys.stdout.write( _("Adding DEVSimPy model: \n").encode('utf-8')) sys.stdout.write(repr(m)) # focus #canvas.SetFocus() else: sys.stdout.write( _("This option has not been implemented yet. \n"))
def OnItemDocumentation(self, evt): """ Display the item's documentation on miniFrame. """ item = self.GetSelection() path = self.GetItemPyData(item) name = self.GetItemText(item) module = BlockFactory.GetModule(path) info = Container.CheckClass(path) if isinstance(info, tuple): doc = str(info) elif isinstance(module, tuple): doc = str(module) else: doc = inspect.getdoc(module) ### Add maccabe complexity measure doc += "".join( [_("\n\n MacCabe Complexity: %d") % self.MetricDico[item]['mcc']]) if doc: dlg = wx.lib.dialogs.ScrolledMessageDialog( self, doc, _("%s Documentation") % name, style=wx.OK | wx.ICON_EXCLAMATION | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) dlg.CenterOnParent(wx.BOTH) dlg.ShowModal() else: wx.MessageBox( _("No documentation! \n Please define the documentation of the model %s in the header of its python file." ) % name, _("%s Documentation") % name, wx.OK | wx.ICON_INFORMATION)