Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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"))