Add primitive printing support for Unix and Windows.
This commit is contained in:
parent
eb914881af
commit
2ca7862e97
|
@ -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>>'),
|
||||
]),
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
[EditorWindow]
|
||||
font-name= courier
|
||||
font-size= 10
|
||||
print-command=lpr %s
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
[EditorWindow]
|
||||
font-name: courier new
|
||||
font-size: 10
|
||||
print-command=start /min notepad /p %s
|
||||
|
|
|
@ -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>'],
|
||||
|
|
Loading…
Reference in New Issue