summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/IOBinding.py
diff options
context:
space:
mode:
authorSteven M. Gava <elguavas@python.net>2002-06-11 04:45:34 (GMT)
committerSteven M. Gava <elguavas@python.net>2002-06-11 04:45:34 (GMT)
commit7981ce576c719e291dc901a3463e725b6be3c50e (patch)
tree33e87f7df0b4968d626a4dc5a37d6843ca770ee5 /Lib/idlelib/IOBinding.py
parent55ad7f84a4ccf6f540b6bc350fb09f19348a4193 (diff)
downloadcpython-7981ce576c719e291dc901a3463e725b6be3c50e.zip
cpython-7981ce576c719e291dc901a3463e725b6be3c50e.tar.gz
cpython-7981ce576c719e291dc901a3463e725b6be3c50e.tar.bz2
add a version of GvR's q&d python idle printing patch,
slightly tweaked and modified for the idlefork config system
Diffstat (limited to 'Lib/idlelib/IOBinding.py')
-rw-r--r--Lib/idlelib/IOBinding.py45
1 files changed, 43 insertions, 2 deletions
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 <<open-window-from-file>>
#$ win <Control-o>
@@ -22,6 +24,10 @@ import re
#$ win <Alt-s>
#$ unix <Control-x><Control-w>
+#$ event <<print-window>>
+#$ win <Control-p>
+#$ unix <Control-x><Control-p>
+
#$ event <<save-copy-of-window-as-file>>
#$ win <Alt-Shift-s>
#$ unix <Control-x><w>
@@ -38,13 +44,15 @@ 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
self.text.unbind("<<open-window-from-file>>", self.__id_open)
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
@@ -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':