Exemplo n.º 1
0
    def OnFileLocate(self, id, code):
        from pywin.mfc import dialog
        import scriptutils
        import os
        global lastLocateFileName  # save the new version away for next time...

        # Loop until a good name, or cancel
        while 1:
            name = dialog.GetSimpleInput('File name', lastLocateFileName,
                                         'Locate Python File')
            if name is None:  # Cancelled.
                break
            lastLocateFileName = name
            # if ".py" supplied, rip it off!
            if string.lower(lastLocateFileName[-3:]) == '.py':
                lastLocateFileName = lastLocateFileName[:-3]
            lastLocateFileName = string.translate(lastLocateFileName,
                                                  string.maketrans(".", "\\"))
            newName = scriptutils.LocatePythonFile(lastLocateFileName)
            if newName is None:
                win32ui.MessageBox("The file '%s' can not be located" %
                                   lastLocateFileName)
            else:
                win32ui.GetApp().OpenDocumentFile(newName)
                break
Exemplo n.º 2
0
	def OnFileLocate( self, id, code ):
		from pywin.mfc import dialog
		import scriptutils
		import os
		global lastLocateFileName # save the new version away for next time...

		name = dialog.GetSimpleInput('File name', lastLocateFileName, 'Locate Python File')
		if name is None: # Cancelled.
			return
		lastLocateFileName = name
		# if ".py" supplied, rip it off!
		# should also check for .pys and .pyw
		if lastLocateFileName[-3:].lower()=='.py':
			lastLocateFileName = lastLocateFileName[:-3]
		lastLocateFileName = lastLocateFileName.replace(".","\\")
		newName = scriptutils.LocatePythonFile(lastLocateFileName)
		if newName is None:
			win32ui.MessageBox("The file '%s' can not be located" % lastLocateFileName)
		else:
			win32ui.GetApp().OpenDocumentFile(newName)
Exemplo n.º 3
0
            # No match - try the previous line
            lineNo = self.LineFromChar()
            if lineNo > 0:
                line = self.GetLine(lineNo - 1)
                matchResult = self.patErrorMessage.match(line)
        if matchResult is not None:
            # we have an error line.
            fileName = matchResult.group(1)
            if fileName[0] == "<":
                win32ui.SetStatusText("Can not load this file")
                return 1  # still was an error message.
            else:
                lineNoString = matchResult.group(2)
                # Attempt to locate the file (in case it is a relative spec)
                fileNameSpec = fileName
                fileName = scriptutils.LocatePythonFile(fileName)
                if fileName is None:
                    # Dont force update, so it replaces the idle prompt.
                    win32ui.SetStatusText(
                        "Cant locate the file '%s'" % (fileNameSpec), 0)
                    return 1

                win32ui.SetStatusText(
                    "Jumping to line " + lineNoString + " of file " + fileName,
                    1)
                if not scriptutils.JumpToDocument(fileName,
                                                  string.atoi(lineNoString)):
                    win32ui.SetStatusText("Could not open %s" % fileName)
                    return 1  # still was an error message.
                return 1
        return 0  # not an error line
Exemplo n.º 4
0
    def HandleSpecialLine(self):
        import scriptutils
        line = self.GetLine()
        matchResult = self.patErrorMessage.match(line)
        if matchResult <= 0:
            # No match - try the next line
            lineNo = self.LineFromChar()
            if lineNo > 0:
                line = self.GetLine(lineNo - 1)
                matchResult = self.patErrorMessage.match(line)
        if matchResult > 0:
            # we have an error line.
            fileName = self.patErrorMessage.group(1)
            if fileName[0] == "<":
                win32ui.SetStatusText("Can not load this file")
                return 1  # still was an error message.
            else:
                #                               if fileName[:2]=='.\\':
                #                                       fileName = fileName[2:]
                lineNoString = self.patErrorMessage.group(2)
                # Attempt to locate the file (in case it is a relative spec)
                fileNameSpec = fileName
                fileName = scriptutils.LocatePythonFile(fileName)
                if fileName is None:
                    # Dont force update, so it replaces the idle prompt.
                    win32ui.SetStatusText(
                        "Cant locate the file '%s'" % (fileNameSpec), 0)
                    return 1

                win32ui.SetStatusText(
                    "Jumping to line " + lineNoString + " of file " + fileName,
                    1)
                doc = win32ui.GetApp().OpenDocumentFile(fileName)
                if doc is None:
                    win32ui.SetStatusText("Could not open %s" % fileName)
                    return 1  # still was an error message.
                view = doc.GetFirstView()
                try:
                    view.GetParent().AutoRestore(
                    )  # hopefully is an editor window
                except AttributeError:
                    pass  # but may not be.
                lineNo = string.atoi(lineNoString)
                view.GetLineCount(
                )  # seems to be needed in RTF to work correctly?
                charNo = view.LineIndex(lineNo - 1)
                view.SetSel(charNo)
                return 1
        if line[:11] == "com_error: ":
            # An OLE Exception - pull apart the exception
            # and try and locate a help file.
            try:
                import win32api, win32con
                det = eval(string.strip(line[string.find(line, ":") + 1:]))
                win32ui.SetStatusText("Opening help file on OLE error...")
                win32api.WinHelp(win32ui.GetMainFrame().GetSafeHwnd(),
                                 det[2][3], win32con.HELP_CONTEXT, det[2][4])
                return 1
            except win32api.error, details:
                try:
                    msg = details[2]
                except:
                    msg = str(details)
                win32ui.SetStatusText(
                    "The help file could not be opened - %s" % msg)
                return 1
            except: