From: Guido van Rossum Date: Mon, 10 Jun 2002 18:52:02 +0000 (+0000) Subject: Add primitive printing support for Unix and Windows. X-Git-Tag: v2.3c1~5396 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ca7862e97610c0e16df8b06cbae4c8f537617a4;p=python Add primitive printing support for Unix and Windows. --- diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py index ede07b8566..8bf0e704c4 100644 --- a/Tools/idle/Bindings.py +++ b/Tools/idle/Bindings.py @@ -23,6 +23,8 @@ menudefs = [ ('Save _As...', '<>'), ('Save Co_py As...', '<>'), None, + ('_Print window', '<>'), + None, ('_Close', '<>'), ('E_xit', '<>'), ]), diff --git a/Tools/idle/IOBinding.py b/Tools/idle/IOBinding.py index db9fbd36af..925015f3ee 100644 --- a/Tools/idle/IOBinding.py +++ b/Tools/idle/IOBinding.py @@ -1,6 +1,8 @@ import os +import tempfile import tkFileDialog import tkMessageBox +from IdleConf import idleconf #$ event <> #$ win @@ -18,6 +20,10 @@ import tkMessageBox #$ win #$ unix +#$ event <> +#$ win +#$ unix + class IOBinding: @@ -30,6 +36,7 @@ class IOBinding: self.save_as) self.__id_savecopy = self.text.bind("<>", self.save_a_copy) + self.__id_print = self.text.bind("<>", self.print_window) def close(self): # Undo command bindings @@ -37,6 +44,7 @@ class IOBinding: self.text.unbind("<>", self.__id_save) self.text.unbind("<>",self.__id_saveas) self.text.unbind("<>", self.__id_savecopy) + self.text.unbind("<>", self.__id_print) # Break cycles self.editwin = None self.text = None @@ -146,6 +154,30 @@ class IOBinding: self.text.focus_set() return "break" + def print_window(self, event): + tempfilename = None + if self.get_saved(): + filename = self.filename + else: + filename = tempfilename = tempfile.mktemp() + if not self.writefile(filename): + os.unlink(tempfilename) + return "break" + edconf = idleconf.getsection('EditorWindow') + command = edconf.get('print-command') + command = command % filename + if os.name == 'posix': + command = command + " 2>&1" + pipe = os.popen(command, "r") + output = pipe.read().strip() + status = pipe.close() + if status: + output = "Printing failed (exit status 0x%x)\n" % status + output + if output: + output = "Printing command: %s\n" % repr(command) + output + tkMessageBox.showerror("Print status", output, master=self.text) + return "break" + def writefile(self, filename): self.fixlastline() chars = str(self.text.get("1.0", "end-1c")) diff --git a/Tools/idle/config-unix.txt b/Tools/idle/config-unix.txt index be9fa814ce..782965f7d1 100644 --- a/Tools/idle/config-unix.txt +++ b/Tools/idle/config-unix.txt @@ -1,3 +1,4 @@ [EditorWindow] font-name= courier font-size= 10 +print-command=lpr %s diff --git a/Tools/idle/config-win.txt b/Tools/idle/config-win.txt index 9faa635303..aeb6ab96c4 100644 --- a/Tools/idle/config-win.txt +++ b/Tools/idle/config-win.txt @@ -1,3 +1,4 @@ [EditorWindow] font-name: courier new font-size: 10 +print-command=start /min notepad /p %s diff --git a/Tools/idle/keydefs.py b/Tools/idle/keydefs.py index fddf278b68..9761258e5f 100644 --- a/Tools/idle/keydefs.py +++ b/Tools/idle/keydefs.py @@ -17,6 +17,7 @@ windows_keydefs = \ '<>': [''], '<>': [''], '<>': [''], + '<>': [''], '<>': [''], '<>': [''], '<>': [''], @@ -46,6 +47,7 @@ unix_keydefs = \ '<>': [''], '<>': [''], '<>': [''], + '<>': [''], '<>': ['', ''], '<>': [''], '<>': [''],