Ejemplo n.º 1
0
def OpenHelpFile(fileName, helpCmd = None, helpArg = None):
	"Open a help file, given a full path"
	# default help arg.
	win32ui.DoWaitCursor(1)
	try:
		if helpCmd is None: helpCmd = win32con.HELP_CONTENTS
		ext = string.lower(os.path.splitext(fileName)[1])
		if ext == ".hlp":
			win32api.WinHelp( win32ui.GetMainFrame().GetSafeHwnd(), fileName, helpCmd, helpArg)
		# XXX - using the htmlhelp API wreaks havoc with keyboard shortcuts
		# so we disable it, forcing ShellExecute, which works fine (but
		# doesn't close the help file when Pythonwin is closed.
		# Tom Heller also points out http://www.microsoft.com/mind/0499/faq/faq0499.asp,
		# which may or may not be related.
		elif 0 and ext == ".chm":
			import win32help
			global htmlhelp_handle
			helpCmd = html_help_command_translators.get(helpCmd, helpCmd)
			#frame = win32ui.GetMainFrame().GetSafeHwnd()
			frame = 0 # Dont want it overlapping ours!
			if htmlhelp_handle is None:
				htmlhelp_hwnd, htmlhelp_handle = win32help.HtmlHelp(frame, None, win32help.HH_INITIALIZE)
			win32help.HtmlHelp(frame, fileName, helpCmd, helpArg)
		else:
			# Hope that the extension is registered, and we know what to do!
			win32api.ShellExecute(0, "open", fileName, None, "", win32con.SW_SHOW)
		return fileName
	finally:
		win32ui.DoWaitCursor(-1)
Ejemplo n.º 2
0
 def TakeDefaultAction(self):
     fname, ctx = self.myobject
     if ctx:
         cmd = win32con.HELP_CONTEXT
     else:
         cmd = win32con.HELP_FINDER
     win32api.WinHelp(win32ui.GetMainFrame().GetSafeHwnd(), fname, cmd, ctx)
Ejemplo n.º 3
0
def OpenHelpFile(fileName, helpCmd=None, helpArg=None):
    "Open a help file, given a full path"
    # default help arg.
    win32ui.DoWaitCursor(1)
    try:
        ext = os.path.splitext(fileName)[1]
        if string.lower(ext) == ".hlp":
            if helpCmd is None: helpCmd = win32con.HELP_FINDER
            win32api.WinHelp(win32ui.GetMainFrame().GetSafeHwnd(), fileName,
                             helpCmd, helpArg)
        else:
            # Hope that the extension is registered, and we know what to do!
            win32api.ShellExecute(0, "open", fileName, None, "",
                                  win32con.SW_SHOW)
        return fileName
    finally:
        win32ui.DoWaitCursor(-1)
Ejemplo 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: