Index: EditorWindow.py =================================================================== --- EditorWindow.py (revision 67444) +++ EditorWindow.py (working copy) @@ -257,11 +257,34 @@ self.wmenu_end = end WindowList.register_callback(self.postwindowsmenu) - # Some abstractions so IDLE extensions are cross-IDE - self.askyesno = tkMessageBox.askyesno - self.askinteger = tkSimpleDialog.askinteger - self.showerror = tkMessageBox.showerror + # Standard dialogs (which also allow making IDLE extensions cross-IDE) + def _tk_dialog_wrapper(base_method): + def new_method(self, *args, **kwargs): + if 'master' not in kwargs and 'parent' not in kwargs: + kwargs['parent'] = self.text + result = base_method(self, *args, **kwargs) + self.text.focus_set() + return result + return new_method + @_tk_dialog_wrapper + def showerror(self, *args, **kwargs): + return tkMessageBox.showerror(*args, **kwargs) + + @_tk_dialog_wrapper + def askokcancel(self, *args, **kwargs): + return tkMessageBox.askokcancel(*args, **kwargs) + + @_tk_dialog_wrapper + def askyesno(self, *args, **kwargs): + return tkMessageBox.askyesno(*args, **kwargs) + + @_tk_dialog_wrapper + def askinteger(self, *args, **kwargs): + return tkSimpleDialog.askinteger(*args, **kwargs) + + del _tk_dialog_wrapper + def _filename_to_unicode(self, filename): """convert filename to unicode in order to display it in Tk""" if isinstance(filename, unicode) or not filename: @@ -509,8 +532,7 @@ def goto_line_event(self, event): text = self.text - lineno = tkSimpleDialog.askinteger("Goto", - "Go to line number:",parent=text) + lineno = self.askinteger("Goto", "Go to line number:") if lineno is None: return "break" if lineno <= 0: @@ -539,11 +561,11 @@ try: (f, file, (suffix, mode, type)) = _find_module(name) except (NameError, ImportError), msg: - tkMessageBox.showerror("Import error", str(msg), parent=self.text) + self.showerror("Import error", str(msg)) return if type != imp.PY_SOURCE: - tkMessageBox.showerror("Unsupported type", - "%s is not a source module" % name, parent=self.text) + self.showerror("Unsupported type", + "%s is not a source module" % name) return if f: f.close() @@ -555,11 +577,8 @@ def open_class_browser(self, event=None): filename = self.io.filename if not filename: - tkMessageBox.showerror( - "No filename", - "This buffer has no associated filename", - master=self.text) - self.text.focus_set() + self.showerror("No filename", + "This buffer has no associated filename") return None head, tail = os.path.split(filename) base, ext = os.path.splitext(tail) @@ -1317,8 +1336,7 @@ "Turn tabs " + ("on", "off")[self.usetabs] + "?\nIndent width " + ("will be", "remains at")[self.usetabs] + " 8." + - "\n Note: a tab is always 8 columns", - parent=self.text): + "\n Note: a tab is always 8 columns"): self.usetabs = not self.usetabs # Try to prevent inconsistent indentation. # User must change indent width manually after using tabs. Index: IOBinding.py =================================================================== --- IOBinding.py (revision 67444) +++ IOBinding.py (working copy) @@ -247,7 +247,7 @@ chars = f.read() f.close() except IOError, msg: - tkMessageBox.showerror("I/O Error", str(msg), master=self.text) + self.editwin.showerror("I/O Error", str(msg)) return False chars = self.decode(chars) @@ -290,11 +290,10 @@ try: enc = coding_spec(chars) except LookupError, name: - tkMessageBox.showerror( + self.editwin.showerror( title="Error loading the file", message="The encoding '%s' is not known to this Python "\ - "installation. The file may not display correctly" % name, - master = self.text) + "installation. The file may not display correctly" % name) enc = None if enc: try: @@ -381,8 +380,7 @@ f.close() return True except IOError, msg: - tkMessageBox.showerror("I/O Error", str(msg), - master=self.text) + self.editwin.showerror("I/O Error", str(msg)) return False def encode(self, chars): @@ -409,10 +407,9 @@ except UnicodeError: failed = "Invalid encoding '%s'" % enc if failed: - tkMessageBox.showerror( + self.editwin.showerror( "I/O Error", - "%s. Saving as UTF-8" % failed, - master = self.text) + "%s. Saving as UTF-8" % failed) # If there was a UTF-8 signature, use that. This should not fail if self.fileencoding == BOM_UTF8 or failed: return BOM_UTF8 + chars.encode("utf-8") @@ -421,11 +418,10 @@ try: return chars.encode(self.fileencoding) except UnicodeError: - tkMessageBox.showerror( + self.editwin.showerror( "I/O Error", "Cannot save this as '%s' anymore. Saving as UTF-8" \ - % self.fileencoding, - master = self.text) + % self.fileencoding) return BOM_UTF8 + chars.encode("utf-8") # Nothing was declared, and we had not determined an encoding # on loading. Recommend an encoding line. @@ -509,7 +505,7 @@ status + output if output: output = "Printing command: %s\n" % repr(command) + output - tkMessageBox.showerror("Print status", output, master=self.text) + self.editwin.showerror("Print status", output) else: #no printing for this platform message="Printing is not enabled for this platform: %s" % platform tkMessageBox.showinfo("Print status", message, master=self.text) Index: OutputWindow.py =================================================================== --- OutputWindow.py (revision 67444) +++ OutputWindow.py (working copy) @@ -84,11 +84,10 @@ "insert -1line lineend") result = self._file_line_helper(line) if not result: - tkMessageBox.showerror( + self.showerror( "No special line", "The line you point at doesn't look like " - "a valid file name followed by a line number.", - master=self.text) + "a valid file name followed by a line number.") return filename, lineno = result edit = self.flist.open(filename) Index: PyShell.py =================================================================== --- PyShell.py (revision 67444) +++ PyShell.py (working copy) @@ -718,11 +718,10 @@ exec code in self.locals except SystemExit: if not self.tkconsole.closing: - if tkMessageBox.askyesno( + if self.tkconsole.askyesno( "Exit?", "Do you want to exit altogether?", - default="yes", - master=self.tkconsole.text): + default=tkMessageBox.YES): raise else: self.showtraceback() @@ -752,7 +751,7 @@ self.tkconsole.stderr.write(s) def display_port_binding_error(self): - tkMessageBox.showerror( + self.tkconsole.showerror( "Port Binding Error", "IDLE can't bind TCP/IP port 8833, which is necessary to " "communicate with its Python execution server. Either " @@ -760,23 +759,20 @@ "process (another IDLE?) is using the port. Run IDLE with the -n " "command line switch to start without a subprocess and refer to " "Help/IDLE Help 'Running without a subprocess' for further " - "details.", - master=self.tkconsole.text) + "details.") def display_no_subprocess_error(self): - tkMessageBox.showerror( + self.tkconsole.showerror( "Subprocess Startup Error", "IDLE's subprocess didn't make connection. Either IDLE can't " "start a subprocess or personal firewall software is blocking " - "the connection.", - master=self.tkconsole.text) + "the connection.") def display_executing_dialog(self): - tkMessageBox.showerror( + self.tkconsole.showerror( "Already executing", "The Python Shell window is already executing a command; " - "please wait until it is finished.", - master=self.tkconsole.text) + "please wait until it is finished.") class PyShell(OutputWindow): @@ -872,9 +868,8 @@ def toggle_debugger(self, event=None): if self.executing: - tkMessageBox.showerror("Don't debug now", - "You can only toggle the debugger when idle", - master=self.text) + self.showerror("Don't debug now", + "You can only toggle the debugger when idle") self.set_debugger_indicator() return "break" else: @@ -930,11 +925,10 @@ def close(self): "Extend EditorWindow.close()" if self.executing: - response = tkMessageBox.askokcancel( + response = self.askokcancel( "Kill?", "The program is still running!\n Do you want to kill it?", - default="ok", - parent=self.text) + default=tkMessageBox.OK) if response is False: return "cancel" if self.reading: @@ -1184,10 +1178,9 @@ try: sys.last_traceback except: - tkMessageBox.showerror("No stack trace", + self.showerror("No stack trace", "There is no stack trace yet.\n" - "(sys.last_traceback is not defined)", - master=self.text) + "(sys.last_traceback is not defined)") return from StackViewer import StackBrowser sv = StackBrowser(self.root, self.flist) Index: ScriptBinding.py =================================================================== --- ScriptBinding.py (revision 67444) +++ ScriptBinding.py (working copy) @@ -69,13 +69,13 @@ except tokenize.TokenError, msg: msgtxt, (lineno, start) = msg self.editwin.gotoline(lineno) - self.errorbox("Tabnanny Tokenizing Error", - "Token Error: %s" % msgtxt) + self.editwin.showerror("Tabnanny Tokenizing Error", + "Token Error: %s" % msgtxt) return False except tabnanny.NannyNag, nag: # The error messages from tabnanny are too confusing... self.editwin.gotoline(nag.get_lineno()) - self.errorbox("Tab/space error", indent_message) + self.editwin.showerror("Tab/space error", indent_message) return False return True @@ -106,8 +106,9 @@ self.colorize_syntax_error(msg, lineno, offset) except: msg = "*** " + str(err) - self.errorbox("Syntax error", - "There's an error in your program:\n" + msg) + self.editwin.showerror( + "Syntax error", + "There's an error in your program:\n" + msg) return False finally: shell.set_warning_stream(saved_stream) @@ -184,9 +185,7 @@ if autosave and filename: self.editwin.io.save(None) else: - reply = self.ask_save_dialog() - self.editwin.text.focus_set() - if reply == "ok": + if self.ask_save_dialog(): self.editwin.io.save(None) filename = self.editwin.io.filename else: @@ -195,15 +194,7 @@ def ask_save_dialog(self): msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?" - mb = tkMessageBox.Message(title="Save Before Run or Check", - message=msg, - icon=tkMessageBox.QUESTION, - type=tkMessageBox.OKCANCEL, - default=tkMessageBox.OK, - master=self.editwin.text) - return mb.show() - - def errorbox(self, title, message): - # XXX This should really be a function of EditorWindow... - tkMessageBox.showerror(title, message, master=self.editwin.text) - self.editwin.text.focus_set() + return self.editwin.askokcancel( + title="Save Before Run or Check", + message=msg, + default=tkMessageBox.OK)