예제 #1
0
    def OnCheckComplete(self, data):
        """Callback for when compile check"""
        if len(data) != 2:
            util.Log("[PyTools][err] OnCheckComplete Invalid Data %s" %
                     repr(data))
            return

        path = data[0]
        err = data[1]
        if err:
            line = -1

            # Python 3 outputs correct exception to stderr
            pat = re.compile('File "(.+)", line ([0-9]+)')
            matches = pat.findall(err)
            if len(matches) and len(matches[0]) == 2:
                match = matches[0]
                if match[1].isdigit():
                    line = int(matches[0][1])

            # Python 2 py_compile outputs a tuple of args
            if line < 0:
                pat = re.compile("\('.*', ([0-9]+),")
                matchs = pat.findall(err)
                if len(matchs) and matchs[0].isdigit():
                    line = max(0, int(matchs[0]) - 1)

            if line >= 0:
                mw = wx.GetApp().GetActiveWindow()
                buff = PyStudioUtils.GetEditorForFile(mw, path)
                if buff:
                    self._errdata[path] = (line, err)
                    buff.AddMarker(ed_marker.ErrorMarker(), line)
                    buff.GotoLine(line)
예제 #2
0
    def DefineMarkers(self):
        """Defines the folder and bookmark icons for this control
        @postcondition: all margin markers are defined

        """
        # Get the colours for the various markers
        style = self.GetItemByName('foldmargin_style')
        back = style.GetFore()
        rgb = eclib.HexToRGB(back[1:])
        back = wx.Colour(red=rgb[0], green=rgb[1], blue=rgb[2])

        fore = style.GetBack()
        rgb = eclib.HexToRGB(fore[1:])
        fore = wx.Colour(red=rgb[0], green=rgb[1], blue=rgb[2])

        # Buffer background highlight
        caret_line = self.GetItemByName('caret_line').GetBack()
        rgb = eclib.HexToRGB(caret_line[1:])
        clback = wx.Colour(*rgb)

        # Code Folding markers
        folder = ed_marker.FoldMarker()
        folder.Foreground = fore
        folder.Background = back
        folder.RegisterWithStc(self)

        # Bookmarks
        ed_marker.Bookmark().RegisterWithStc(self)

        # Breakpoints
        ed_marker.Breakpoint().RegisterWithStc(self)
        ed_marker.BreakpointDisabled().RegisterWithStc(self)
        step = ed_marker.BreakpointStep()
        step.Background = clback
        step.RegisterWithStc(self)
        ed_marker.StackMarker().RegisterWithStc(self)

        # Other markers
        errmk = ed_marker.ErrorMarker()
        errsty = self.GetItemByName('error_style')
        rgb = eclib.HexToRGB(errsty.GetBack()[1:])
        errmk.Background = wx.Colour(*rgb)
        rgb = eclib.HexToRGB(errsty.GetFore()[1:])
        errmk.Foreground = wx.Colour(*rgb)
        errmk.RegisterWithStc(self)
        # Lint Marker
        ed_marker.LintMarker().RegisterWithStc(self)
        ed_marker.LintMarkerWarning().RegisterWithStc(self)
        ed_marker.LintMarkerError().RegisterWithStc(self)
예제 #3
0
    def OnFileSaved(self, msg):
        """Performs file saved checks"""
        data = msg.GetData()
        if not data[0] or data[1] != synglob.ID_LANG_PYTHON:
            return

        buff = None
        for mw in wx.GetApp().GetMainWindows():
            if mw.Id == msg.Context:
                buff = PyStudioUtils.GetEditorForFile(mw, data[0])
                break

        if not buff:
            return

        buff.RemoveAllMarkers(ed_marker.ErrorMarker())
        if data[0] in self._errdata:
            del self._errdata[data[0]]

        if ToolConfig.GetConfigValue(ToolConfig.TLC_COMPILE_ON_SAVE, True):
            # Run the compilation check
            RunAsyncTask("CompileCheck", self.OnCheckComplete,
                         self.DoCompileCheck, data[0])