]> granicus.if.org Git - python/commitdiff
Add primitive printing support for Unix and Windows.
authorGuido van Rossum <guido@python.org>
Mon, 10 Jun 2002 18:52:02 +0000 (18:52 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 10 Jun 2002 18:52:02 +0000 (18:52 +0000)
Tools/idle/Bindings.py
Tools/idle/IOBinding.py
Tools/idle/config-unix.txt
Tools/idle/config-win.txt
Tools/idle/keydefs.py

index ede07b856624d43ea21d241431a1c9b3647b23ce..8bf0e704c4b58ebaa7302a3658135e00ce4af5b1 100644 (file)
@@ -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>>'),
   ]),
index db9fbd36afa300227854b2c6c175308b79cd9cd8..925015f3ee55ed6091ce0f58ef8766e6abba81c3 100644 (file)
@@ -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"))
index be9fa814ce0251891f459a4dcd43bd1542befe45..782965f7d170c96cbec080ed47042f898bafb349 100644 (file)
@@ -1,3 +1,4 @@
 [EditorWindow]
 font-name= courier
 font-size= 10
+print-command=lpr %s
index 9faa6353035ef0a737432d9d4687ab6732175b01..aeb6ab96c45fc485ef5d49a54fe18be66810acea 100644 (file)
@@ -1,3 +1,4 @@
 [EditorWindow]
 font-name: courier new
 font-size: 10
+print-command=start /min notepad /p %s
index fddf278b68514b91d031dc8b760bfde786a3ccb4..9761258e5f910ed5afdcae6f45a3426787a97ae8 100644 (file)
@@ -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>'],