Exemplo n.º 1
0
    def __init__(self, message):
        """
		Initialize the dialog

		**Parameters:**

		* message: Error message to display
		"""
        ErrorDialog.REPORTER_ACTIVE = True

        # Get version from the app since the main window may be dead or
        # not even ready yet.
        #version = wx.GetApp().GetVersion()

        BaseDialog.__init__(self, Utilities.GetActiveWindow())

        # Give message to ErrorReporter
        ErrorReporter().AddMessage(message)

        #self.SetIcon(wx.IconFromBitmap(CreateBitmap("GUI2Exe")))
        self.SetTitle(_("Error/Crash Reporter"))

        # Attributes
        self.err_msg = "%s\n\n%s\n%s\n%s" % (Utilities.EnvironmentInfo(), \
                  "---- Traceback Info ----", \
                  ErrorReporter().GetErrorStack(), \
                  "---- End Traceback Info ----")

        self.textCtrl = wx.TextCtrl(self,
                                    value=self.err_msg,
                                    style=wx.TE_MULTILINE | wx.TE_READONLY)
        self.abortButton = wx.Button(self, wx.ID_CANCEL, size=(-1, 26))
        self.sendButton = wx.Button(self,
                                    ID_SEND,
                                    _("Report Error"),
                                    size=(-1, 26))
        self.sendButton.SetDefault()
        self.closeButton = wx.Button(self, wx.ID_CLOSE, size=(-1, 26))

        # Layout
        self.DoLayout()

        # Event Handlers
        self.Bind(wx.EVT_BUTTON, self.OnButton)
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        # Auto show at end of init
        self.CenterOnParent()
        self.ShowModal()
Exemplo n.º 2
0
    def CreateBlock(*argv, **kwargs):
        """ Create Block from python_file and other info coming from wizard.
		"""
        import Core.Components.Container as Container

        python_file = kwargs['python_file']
        canvas = kwargs['canvas'] if 'canvas' in kwargs else None
        x = kwargs['x'] if 'x' in kwargs else None
        y = kwargs['y'] if 'y' in kwargs else None

        # associated python class
        cls = GetClass(python_file)

        if inspect.isclass(cls):
            # adding devs model on good graphical model
            if issubclass(cls, DomainBehavior.DomainBehavior):
                amd = AMDComponent(*argv, **kwargs)
                m = amd.Create()
                ### move AMD model
                if canvas and x and y:
                    ### convert coordinate depending on the canvas
                    x, y = canvas.GetXY(m, x, y)
                    # move model from mouse position
                    m.move(x, y)
                return m
            elif issubclass(cls, DomainStructure.DomainStructure):
                cmd = CMDComponent(*argv, **kwargs)
                m = cmd.Create()
                ### move CMD model
                if canvas and x and y:
                    ### convert coordinate depending on the canvas
                    x, y = canvas.GetXY(m, x, y)
                    # move model from mouse position
                    m.move(x, y)
                return m
            elif 'IPort' in cls.__name__:
                label = kwargs['label']
                iid = kwargs['id'] if 'id' in kwargs else canvas.GetDiagram(
                ).GetiPortCount()
                m = Container.iPort(label="%s %d" % (label, iid))
                m.id = iid
                m.move(x - 70, y - 70)
                return m
            elif 'OPort' in cls.__name__:
                label = kwargs['label']
                oid = kwargs['id'] if 'id' in kwargs else canvas.GetDiagram(
                ).GetoPortCount()
                m = Container.oPort(label="%s %d" % (label, oid))
                m.id = oid
                m.move(x - 70, y - 70)
                return m
            else:
                dial = wx.MessageDialog(
                    None,
                    _('Object not instantiated !\n\n Perhaps there is bad imports.'
                      ), _('Exclamation'), wx.OK | wx.ICON_EXCLAMATION)
                dial.ShowModal()
                return False

        ### inform user of the existance of error and return None
        else:
            MsgBoxError(None, Utilities.GetActiveWindow(), cls)

        return None
Exemplo n.º 3
0
    def OnEditor(self, event):
        """ Method that edit the python code of associated devs model of the Block
		"""

        python_path = self.python_path
        model_path = os.path.dirname(python_path)
        name = os.path.basename(python_path)

        ### trying to get parent window
        mainW = Utilities.GetActiveWindow(event)

        if isinstance(mainW, ShapeCanvas.ShapeCanvas):
            mainW = mainW.GetParent()

        if __builtin__.__dict__['LOCAL_EDITOR'] and not zipfile.is_zipfile(
                model_path) and not python_path.startswith('http'):
            dial = wx.MessageDialog(
                mainW,
                _('Do you want to use your local programmer software?\n\n If you want always use the DEVSimPy code editor\n change the option in Editor panel preferences.'
                  ), 'Question', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
            val = dial.ShowModal()
        else:
            val = wx.ID_NO

        ### si local editor choisi dans les preferences et pas de zip file et pas de fichier provenant du server ftp
        if val == wx.ID_YES:
            ### open with local editor
            if wx.Platform == '__WXMAC__':
                os.system("open " + python_path)
            elif "wxMSW" in wx.PlatformInfo:
                os.startfile(python_path)
            elif "wxGTK" in wx.PlatformInfo:
                ### on est dans gnome
                if os.system('pidof gnome-session') != 256:
                    try:
                        soft = which('gnome-open')
                    except:
                        sys.stdout.write(
                            _("Local programmer software not found!\n"))
                    else:
                        os.system(soft + " openURL " + python_path)
                ### on est dans kde
                elif os.system('pidof ksmserver') != 256:
                    try:
                        soft = which('kfmclient')
                    except:
                        sys.stdout.write(
                            _("Local programmer software not found!\n"))
                    else:
                        os.system(soft + " openURL " + python_path)
                else:
                    sys.stdout.write(_("Unknown Windows Manager!\n"))

        elif val != wx.ID_CANCEL:
            # chargement du fichier dans la fenetre d'edition (self.text)
            try:

                editorFrame = Editor.GetEditor(mainW,
                                               wx.ID_ANY,
                                               name,
                                               obj=self,
                                               file_type='block')

                # if zipfile.is_zipfile(model_path):
                # 	importer = zipimport.zipimporter(model_path)
                # 	text = importer.get_source(os.path.splitext(name)[0])

                if not zipfile.is_zipfile(model_path):
                    ### if file is localized on the net
                    if python_path.startswith('http'):
                        ### with internet python file, the editorFrame is read only
                        editorFrame.SetReadOnly(True)

                        printOnStatusBar(editorFrame.statusbar,
                                         {0: _('read only')})

                        ### parse url to extract the path(/devsimpy/domain...) and the network location (lcapocchi.free.fr)
                        o = urlparse(python_path)
                        ### open conenction
                        c = httplib.HTTPConnection(o.netloc)
                        ### request with GET mode
                        c.request('GET', o.path)
                        ### get response of request
                        r = c.getresponse()
                        ### convert file into string
                        text = r.read()

                    else:

                        ### if python_path is not found (because have an external origine)
                        if not os.path.exists(python_path):
                            if os.path.basename(
                                    DOMAIN_PATH) in python_path.split(os.sep):
                                python_path = os.path.join(
                                    HOME_PATH, python_path[python_path.index(
                                        os.path.basename(DOMAIN_PATH)):].strip(
                                            '[]'))
                                self.python_path = python_path

                        # ### only with python 2.6
                        # with codecs.open(python_path, 'r', 'utf-8') as f:
                        # 	text = f.read()

                name = os.path.basename(python_path)
                editorFrame.AddEditPage(name, python_path)
                editorFrame.Show()

                printOnStatusBar(editorFrame.statusbar, {1: ''})

                return editorFrame

            except Exception, info:
                dlg = wx.MessageDialog(
                    mainW, _('Editor frame not instanciated: %s\n' % info),
                    _("Error"), wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                return False