[Idle-dev] CVS: idle IOBinding.py,1.5,1.6

Stephen M. Gava elguavas@users.sourceforge.net
Mon, 10 Jun 2002 21:44:00 -0700


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv16988

Modified Files:
	IOBinding.py 
Log Message:
add a version of GvR's q&d python idle printing patch, 
slightly tweaked and modified for the idlefork config system


Index: IOBinding.py
===================================================================
RCS file: /cvsroot/idlefork/idle/IOBinding.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** IOBinding.py	22 Apr 2002 00:42:42 -0000	1.5
--- IOBinding.py	11 Jun 2002 04:43:58 -0000	1.6
***************
*** 7,13 ****
--- 7,15 ----
  
  import os
+ import tempfile
  import tkFileDialog
  import tkMessageBox
  import re
+ from configHandler import idleConf
  
  #$ event <<open-window-from-file>>
***************
*** 23,26 ****
--- 25,32 ----
  #$ 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>
***************
*** 39,43 ****
          self.__id_savecopy = self.text.bind("<<save-copy-of-window-as-file>>",
                                              self.save_a_copy)
! 
      def close(self):
          # Undo command bindings
--- 45,50 ----
          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
***************
*** 46,49 ****
--- 53,57 ----
          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
***************
*** 188,192 ****
                                     master=self.text)
              return 0
! 
      def fixlastline(self):
          c = self.text.get("end-2c")
--- 196,233 ----
                                     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")