diff options
author | Guido van Rossum <guido@python.org> | 2002-06-10 18:52:02 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-06-10 18:52:02 (GMT) |
commit | 2ca7862e97610c0e16df8b06cbae4c8f537617a4 (patch) | |
tree | 4b71a9c2d4f8a25c168e62e7c68607dec4c5955b | |
parent | eb914881af66a64a4f03545f2a18761ed774ce5f (diff) | |
download | cpython-2ca7862e97610c0e16df8b06cbae4c8f537617a4.zip cpython-2ca7862e97610c0e16df8b06cbae4c8f537617a4.tar.gz cpython-2ca7862e97610c0e16df8b06cbae4c8f537617a4.tar.bz2 |
Add primitive printing support for Unix and Windows.
-rw-r--r-- | Tools/idle/Bindings.py | 2 | ||||
-rw-r--r-- | Tools/idle/IOBinding.py | 32 | ||||
-rw-r--r-- | Tools/idle/config-unix.txt | 1 | ||||
-rw-r--r-- | Tools/idle/config-win.txt | 1 | ||||
-rw-r--r-- | Tools/idle/keydefs.py | 2 |
5 files changed, 38 insertions, 0 deletions
diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py index ede07b8..8bf0e70 100644 --- a/Tools/idle/Bindings.py +++ b/Tools/idle/Bindings.py @@ -23,6 +23,8 @@ menudefs = [ ('Save _As...', '<<save-window-as-file>>'), ('Save Co_py As...', '<<save-copy-of-window-as-file>>'), None, + ('_Print window', '<<print-window>>'), + None, ('_Close', '<<close-window>>'), ('E_xit', '<<close-all-windows>>'), ]), diff --git a/Tools/idle/IOBinding.py b/Tools/idle/IOBinding.py index db9fbd3..925015f 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 <<open-window-from-file>> #$ win <Control-o> @@ -18,6 +20,10 @@ import tkMessageBox #$ win <Alt-Shift-s> #$ unix <Control-x><w> +#$ event <<print-window>> +#$ win <Control-p> +#$ unix <Control-x><Control-p> + class IOBinding: @@ -30,6 +36,7 @@ class IOBinding: self.save_as) self.__id_savecopy = self.text.bind("<<save-copy-of-window-as-file>>", self.save_a_copy) + self.__id_print = self.text.bind("<<print-window>>", self.print_window) def close(self): # Undo command bindings @@ -37,6 +44,7 @@ class IOBinding: self.text.unbind("<<save-window>>", self.__id_save) self.text.unbind("<<save-window-as-file>>",self.__id_saveas) self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy) + self.text.unbind("<<print-window>>", 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 be9fa81..782965f 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 9faa635..aeb6ab9 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 fddf278..9761258 100644 --- a/Tools/idle/keydefs.py +++ b/Tools/idle/keydefs.py @@ -17,6 +17,7 @@ windows_keydefs = \ '<<open-new-window>>': ['<Control-n>'], '<<open-window-from-file>>': ['<Control-o>'], '<<plain-newline-and-indent>>': ['<Control-j>'], + '<<print-window>>': ['<Control-p>'], '<<redo>>': ['<Control-y>'], '<<remove-selection>>': ['<Escape>'], '<<save-copy-of-window-as-file>>': ['<Alt-Shift-s>'], @@ -46,6 +47,7 @@ unix_keydefs = \ '<<open-new-window>>': ['<Control-x><Control-n>'], '<<open-window-from-file>>': ['<Control-x><Control-f>'], '<<plain-newline-and-indent>>': ['<Control-j>'], + '<<print-window>>': ['<Control-x><Control-p>'], '<<redo>>': ['<Alt-z>', '<Meta-z>'], '<<save-copy-of-window-as-file>>': ['<Control-x><w>'], '<<save-window-as-file>>': ['<Control-x><Control-w>'], |