From 7981ce576c719e291dc901a3463e725b6be3c50e Mon Sep 17 00:00:00 2001 From: "Steven M. Gava" Date: Tue, 11 Jun 2002 04:45:34 +0000 Subject: add a version of GvR's q&d python idle printing patch, slightly tweaked and modified for the idlefork config system --- Lib/idlelib/Bindings.py | 2 ++ Lib/idlelib/IOBinding.py | 45 ++++++++++++++++++++++++++++++++++++++++++-- Lib/idlelib/config-keys.def | 4 +++- Lib/idlelib/config-main.def | 2 ++ Lib/idlelib/configHandler.py | 1 + 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Lib/idlelib/Bindings.py b/Lib/idlelib/Bindings.py index aae6106..06e215e 100644 --- a/Lib/idlelib/Bindings.py +++ b/Lib/idlelib/Bindings.py @@ -30,6 +30,8 @@ menudefs = [ ('Save _As...', '<>'), ('Save Co_py As...', '<>'), None, + ('_Print window', '<>'), + None, ('_Close', '<>'), ('E_xit', '<>'), ]), diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py index 729f29b..eb901dc 100644 --- a/Lib/idlelib/IOBinding.py +++ b/Lib/idlelib/IOBinding.py @@ -6,9 +6,11 @@ # which will only understand the local convention. import os +import tempfile import tkFileDialog import tkMessageBox import re +from configHandler import idleConf #$ event <> #$ win @@ -22,6 +24,10 @@ import re #$ win #$ unix +#$ event <> +#$ win +#$ unix + #$ event <> #$ win #$ unix @@ -38,13 +44,15 @@ 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 self.text.unbind("<>", self.__id_open) 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 @@ -187,7 +195,40 @@ class IOBinding: tkMessageBox.showerror("I/O Error", str(msg), master=self.text) return 0 - + + 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" + platform=os.name + printPlatform=1 + if platform == 'posix': #posix platform + command = idleConf.GetOption('main','General','print-command-posix') + command = command + " 2>&1" + elif platform == 'nt': #win32 platform + command = idleConf.GetOption('main','General','print-command-win') + else: #no printing for this platform + printPlatform=0 + if printPlatform: #we can try to print for this platform + command = command % filename + 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) + else: #no printing for this platform + message="Printing is not enabled for this platform: %s" % platform + tkMessageBox.showinfo("Print status", message, master=self.text) + return "break" + def fixlastline(self): c = self.text.get("end-2c") if c != '\n': diff --git a/Lib/idlelib/config-keys.def b/Lib/idlelib/config-keys.def index 8b38827..180d70e 100644 --- a/Lib/idlelib/config-keys.def +++ b/Lib/idlelib/config-keys.def @@ -26,12 +26,13 @@ open-module= open-new-window= open-window-from-file= plain-newline-and-indent= +print-window= redo= remove-selection= save-copy-of-window-as-file= save-window-as-file= save-window= -select-all= +select-all= toggle-auto-coloring= undo= find= @@ -59,6 +60,7 @@ open-module= open-new-window= open-window-from-file= plain-newline-and-indent= +print-window= python-docs= python-context-help= redo= diff --git a/Lib/idlelib/config-main.def b/Lib/idlelib/config-main.def index 01f0662..cd52b21 100644 --- a/Lib/idlelib/config-main.def +++ b/Lib/idlelib/config-main.def @@ -28,6 +28,8 @@ [General] editor-on-startup= 1 +print-command-posix=lpr %s +print-command-win=start /min notepad /p %s [EditorWindow] width= 80 diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index 82bf6d2..1afd19e 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -507,6 +507,7 @@ class IdleConf: '<>': [''], '<>': [''], '<>': [''], + '<>': [''], '<>': [''], '<>': [''], '<>': [''], -- cgit v0.12