Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: IOBinding.py
# changes by dscherer@cmu.edu
[0] Fix | Delete
# - IOBinding.open() replaces the current window with the opened file,
[1] Fix | Delete
# if the current window is both unmodified and unnamed
[2] Fix | Delete
# - IOBinding.loadfile() interprets Windows, UNIX, and Macintosh
[3] Fix | Delete
# end-of-line conventions, instead of relying on the standard library,
[4] Fix | Delete
# which will only understand the local convention.
[5] Fix | Delete
[6] Fix | Delete
import codecs
[7] Fix | Delete
from codecs import BOM_UTF8
[8] Fix | Delete
import os
[9] Fix | Delete
import pipes
[10] Fix | Delete
import re
[11] Fix | Delete
import sys
[12] Fix | Delete
import tempfile
[13] Fix | Delete
[14] Fix | Delete
from Tkinter import *
[15] Fix | Delete
import tkFileDialog
[16] Fix | Delete
import tkMessageBox
[17] Fix | Delete
from SimpleDialog import SimpleDialog
[18] Fix | Delete
[19] Fix | Delete
from idlelib.configHandler import idleConf
[20] Fix | Delete
[21] Fix | Delete
# Try setting the locale, so that we can find out
[22] Fix | Delete
# what encoding to use
[23] Fix | Delete
try:
[24] Fix | Delete
import locale
[25] Fix | Delete
locale.setlocale(locale.LC_CTYPE, "")
[26] Fix | Delete
except (ImportError, locale.Error):
[27] Fix | Delete
pass
[28] Fix | Delete
[29] Fix | Delete
# Encoding for file names
[30] Fix | Delete
filesystemencoding = sys.getfilesystemencoding()
[31] Fix | Delete
[32] Fix | Delete
encoding = "ascii"
[33] Fix | Delete
if sys.platform == 'win32':
[34] Fix | Delete
# On Windows, we could use "mbcs". However, to give the user
[35] Fix | Delete
# a portable encoding name, we need to find the code page
[36] Fix | Delete
try:
[37] Fix | Delete
encoding = locale.getdefaultlocale()[1]
[38] Fix | Delete
codecs.lookup(encoding)
[39] Fix | Delete
except LookupError:
[40] Fix | Delete
pass
[41] Fix | Delete
else:
[42] Fix | Delete
try:
[43] Fix | Delete
# Different things can fail here: the locale module may not be
[44] Fix | Delete
# loaded, it may not offer nl_langinfo, or CODESET, or the
[45] Fix | Delete
# resulting codeset may be unknown to Python. We ignore all
[46] Fix | Delete
# these problems, falling back to ASCII
[47] Fix | Delete
encoding = locale.nl_langinfo(locale.CODESET)
[48] Fix | Delete
if encoding is None or encoding is '':
[49] Fix | Delete
# situation occurs on Mac OS X
[50] Fix | Delete
encoding = 'ascii'
[51] Fix | Delete
codecs.lookup(encoding)
[52] Fix | Delete
except (NameError, AttributeError, LookupError):
[53] Fix | Delete
# Try getdefaultlocale well: it parses environment variables,
[54] Fix | Delete
# which may give a clue. Unfortunately, getdefaultlocale has
[55] Fix | Delete
# bugs that can cause ValueError.
[56] Fix | Delete
try:
[57] Fix | Delete
encoding = locale.getdefaultlocale()[1]
[58] Fix | Delete
if encoding is None or encoding is '':
[59] Fix | Delete
# situation occurs on Mac OS X
[60] Fix | Delete
encoding = 'ascii'
[61] Fix | Delete
codecs.lookup(encoding)
[62] Fix | Delete
except (ValueError, LookupError):
[63] Fix | Delete
pass
[64] Fix | Delete
[65] Fix | Delete
encoding = encoding.lower()
[66] Fix | Delete
[67] Fix | Delete
coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)')
[68] Fix | Delete
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)')
[69] Fix | Delete
[70] Fix | Delete
class EncodingMessage(SimpleDialog):
[71] Fix | Delete
"Inform user that an encoding declaration is needed."
[72] Fix | Delete
def __init__(self, master, enc):
[73] Fix | Delete
self.should_edit = False
[74] Fix | Delete
[75] Fix | Delete
self.root = top = Toplevel(master)
[76] Fix | Delete
top.bind("<Return>", self.return_event)
[77] Fix | Delete
top.bind("<Escape>", self.do_ok)
[78] Fix | Delete
top.protocol("WM_DELETE_WINDOW", self.wm_delete_window)
[79] Fix | Delete
top.wm_title("I/O Warning")
[80] Fix | Delete
top.wm_iconname("I/O Warning")
[81] Fix | Delete
self.top = top
[82] Fix | Delete
[83] Fix | Delete
l1 = Label(top,
[84] Fix | Delete
text="Non-ASCII found, yet no encoding declared. Add a line like")
[85] Fix | Delete
l1.pack(side=TOP, anchor=W)
[86] Fix | Delete
l2 = Entry(top, font="courier")
[87] Fix | Delete
l2.insert(0, "# -*- coding: %s -*-" % enc)
[88] Fix | Delete
# For some reason, the text is not selectable anymore if the
[89] Fix | Delete
# widget is disabled.
[90] Fix | Delete
# l2['state'] = DISABLED
[91] Fix | Delete
l2.pack(side=TOP, anchor = W, fill=X)
[92] Fix | Delete
l3 = Label(top, text="to your file\n"
[93] Fix | Delete
"See Language Reference, 2.1.4 Encoding declarations.\n"
[94] Fix | Delete
"Choose OK to save this file as %s\n"
[95] Fix | Delete
"Edit your general options to silence this warning" % enc)
[96] Fix | Delete
l3.pack(side=TOP, anchor = W)
[97] Fix | Delete
[98] Fix | Delete
buttons = Frame(top)
[99] Fix | Delete
buttons.pack(side=TOP, fill=X)
[100] Fix | Delete
# Both return and cancel mean the same thing: do nothing
[101] Fix | Delete
self.default = self.cancel = 0
[102] Fix | Delete
b1 = Button(buttons, text="Ok", default="active",
[103] Fix | Delete
command=self.do_ok)
[104] Fix | Delete
b1.pack(side=LEFT, fill=BOTH, expand=1)
[105] Fix | Delete
b2 = Button(buttons, text="Edit my file",
[106] Fix | Delete
command=self.do_edit)
[107] Fix | Delete
b2.pack(side=LEFT, fill=BOTH, expand=1)
[108] Fix | Delete
[109] Fix | Delete
self._set_transient(master)
[110] Fix | Delete
[111] Fix | Delete
def do_ok(self):
[112] Fix | Delete
self.done(0)
[113] Fix | Delete
[114] Fix | Delete
def do_edit(self):
[115] Fix | Delete
self.done(1)
[116] Fix | Delete
[117] Fix | Delete
def coding_spec(str):
[118] Fix | Delete
"""Return the encoding declaration according to PEP 263.
[119] Fix | Delete
[120] Fix | Delete
Raise LookupError if the encoding is declared but unknown.
[121] Fix | Delete
"""
[122] Fix | Delete
# Only consider the first two lines
[123] Fix | Delete
lst = str.split("\n", 2)[:2]
[124] Fix | Delete
for line in lst:
[125] Fix | Delete
match = coding_re.match(line)
[126] Fix | Delete
if match is not None:
[127] Fix | Delete
break
[128] Fix | Delete
if not blank_re.match(line):
[129] Fix | Delete
return None
[130] Fix | Delete
else:
[131] Fix | Delete
return None
[132] Fix | Delete
name = match.group(1)
[133] Fix | Delete
# Check whether the encoding is known
[134] Fix | Delete
import codecs
[135] Fix | Delete
try:
[136] Fix | Delete
codecs.lookup(name)
[137] Fix | Delete
except LookupError:
[138] Fix | Delete
# The standard encoding error does not indicate the encoding
[139] Fix | Delete
raise LookupError, "Unknown encoding "+name
[140] Fix | Delete
return name
[141] Fix | Delete
[142] Fix | Delete
class IOBinding:
[143] Fix | Delete
[144] Fix | Delete
def __init__(self, editwin):
[145] Fix | Delete
self.editwin = editwin
[146] Fix | Delete
self.text = editwin.text
[147] Fix | Delete
self.__id_open = self.text.bind("<<open-window-from-file>>", self.open)
[148] Fix | Delete
self.__id_save = self.text.bind("<<save-window>>", self.save)
[149] Fix | Delete
self.__id_saveas = self.text.bind("<<save-window-as-file>>",
[150] Fix | Delete
self.save_as)
[151] Fix | Delete
self.__id_savecopy = self.text.bind("<<save-copy-of-window-as-file>>",
[152] Fix | Delete
self.save_a_copy)
[153] Fix | Delete
self.fileencoding = None
[154] Fix | Delete
self.__id_print = self.text.bind("<<print-window>>", self.print_window)
[155] Fix | Delete
[156] Fix | Delete
def close(self):
[157] Fix | Delete
# Undo command bindings
[158] Fix | Delete
self.text.unbind("<<open-window-from-file>>", self.__id_open)
[159] Fix | Delete
self.text.unbind("<<save-window>>", self.__id_save)
[160] Fix | Delete
self.text.unbind("<<save-window-as-file>>",self.__id_saveas)
[161] Fix | Delete
self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy)
[162] Fix | Delete
self.text.unbind("<<print-window>>", self.__id_print)
[163] Fix | Delete
# Break cycles
[164] Fix | Delete
self.editwin = None
[165] Fix | Delete
self.text = None
[166] Fix | Delete
self.filename_change_hook = None
[167] Fix | Delete
[168] Fix | Delete
def get_saved(self):
[169] Fix | Delete
return self.editwin.get_saved()
[170] Fix | Delete
[171] Fix | Delete
def set_saved(self, flag):
[172] Fix | Delete
self.editwin.set_saved(flag)
[173] Fix | Delete
[174] Fix | Delete
def reset_undo(self):
[175] Fix | Delete
self.editwin.reset_undo()
[176] Fix | Delete
[177] Fix | Delete
filename_change_hook = None
[178] Fix | Delete
[179] Fix | Delete
def set_filename_change_hook(self, hook):
[180] Fix | Delete
self.filename_change_hook = hook
[181] Fix | Delete
[182] Fix | Delete
filename = None
[183] Fix | Delete
dirname = None
[184] Fix | Delete
[185] Fix | Delete
def set_filename(self, filename):
[186] Fix | Delete
if filename and os.path.isdir(filename):
[187] Fix | Delete
self.filename = None
[188] Fix | Delete
self.dirname = filename
[189] Fix | Delete
else:
[190] Fix | Delete
self.filename = filename
[191] Fix | Delete
self.dirname = None
[192] Fix | Delete
self.set_saved(1)
[193] Fix | Delete
if self.filename_change_hook:
[194] Fix | Delete
self.filename_change_hook()
[195] Fix | Delete
[196] Fix | Delete
def open(self, event=None, editFile=None):
[197] Fix | Delete
flist = self.editwin.flist
[198] Fix | Delete
# Save in case parent window is closed (ie, during askopenfile()).
[199] Fix | Delete
if flist:
[200] Fix | Delete
if not editFile:
[201] Fix | Delete
filename = self.askopenfile()
[202] Fix | Delete
else:
[203] Fix | Delete
filename=editFile
[204] Fix | Delete
if filename:
[205] Fix | Delete
# If editFile is valid and already open, flist.open will
[206] Fix | Delete
# shift focus to its existing window.
[207] Fix | Delete
# If the current window exists and is a fresh unnamed,
[208] Fix | Delete
# unmodified editor window (not an interpreter shell),
[209] Fix | Delete
# pass self.loadfile to flist.open so it will load the file
[210] Fix | Delete
# in the current window (if the file is not already open)
[211] Fix | Delete
# instead of a new window.
[212] Fix | Delete
if (self.editwin and
[213] Fix | Delete
not getattr(self.editwin, 'interp', None) and
[214] Fix | Delete
not self.filename and
[215] Fix | Delete
self.get_saved()):
[216] Fix | Delete
flist.open(filename, self.loadfile)
[217] Fix | Delete
else:
[218] Fix | Delete
flist.open(filename)
[219] Fix | Delete
else:
[220] Fix | Delete
if self.text:
[221] Fix | Delete
self.text.focus_set()
[222] Fix | Delete
return "break"
[223] Fix | Delete
[224] Fix | Delete
# Code for use outside IDLE:
[225] Fix | Delete
if self.get_saved():
[226] Fix | Delete
reply = self.maybesave()
[227] Fix | Delete
if reply == "cancel":
[228] Fix | Delete
self.text.focus_set()
[229] Fix | Delete
return "break"
[230] Fix | Delete
if not editFile:
[231] Fix | Delete
filename = self.askopenfile()
[232] Fix | Delete
else:
[233] Fix | Delete
filename=editFile
[234] Fix | Delete
if filename:
[235] Fix | Delete
self.loadfile(filename)
[236] Fix | Delete
else:
[237] Fix | Delete
self.text.focus_set()
[238] Fix | Delete
return "break"
[239] Fix | Delete
[240] Fix | Delete
eol = r"(\r\n)|\n|\r" # \r\n (Windows), \n (UNIX), or \r (Mac)
[241] Fix | Delete
eol_re = re.compile(eol)
[242] Fix | Delete
eol_convention = os.linesep # Default
[243] Fix | Delete
[244] Fix | Delete
def loadfile(self, filename):
[245] Fix | Delete
try:
[246] Fix | Delete
# open the file in binary mode so that we can handle
[247] Fix | Delete
# end-of-line convention ourselves.
[248] Fix | Delete
with open(filename, 'rb') as f:
[249] Fix | Delete
chars = f.read()
[250] Fix | Delete
except IOError as msg:
[251] Fix | Delete
tkMessageBox.showerror("I/O Error", str(msg), parent=self.text)
[252] Fix | Delete
return False
[253] Fix | Delete
[254] Fix | Delete
chars = self.decode(chars)
[255] Fix | Delete
# We now convert all end-of-lines to '\n's
[256] Fix | Delete
firsteol = self.eol_re.search(chars)
[257] Fix | Delete
if firsteol:
[258] Fix | Delete
self.eol_convention = firsteol.group(0)
[259] Fix | Delete
if isinstance(self.eol_convention, unicode):
[260] Fix | Delete
# Make sure it is an ASCII string
[261] Fix | Delete
self.eol_convention = self.eol_convention.encode("ascii")
[262] Fix | Delete
chars = self.eol_re.sub(r"\n", chars)
[263] Fix | Delete
[264] Fix | Delete
self.text.delete("1.0", "end")
[265] Fix | Delete
self.set_filename(None)
[266] Fix | Delete
self.text.insert("1.0", chars)
[267] Fix | Delete
self.reset_undo()
[268] Fix | Delete
self.set_filename(filename)
[269] Fix | Delete
self.text.mark_set("insert", "1.0")
[270] Fix | Delete
self.text.yview("insert")
[271] Fix | Delete
self.updaterecentfileslist(filename)
[272] Fix | Delete
return True
[273] Fix | Delete
[274] Fix | Delete
def decode(self, chars):
[275] Fix | Delete
"""Create a Unicode string
[276] Fix | Delete
[277] Fix | Delete
If that fails, let Tcl try its best
[278] Fix | Delete
"""
[279] Fix | Delete
# Check presence of a UTF-8 signature first
[280] Fix | Delete
if chars.startswith(BOM_UTF8):
[281] Fix | Delete
try:
[282] Fix | Delete
chars = chars[3:].decode("utf-8")
[283] Fix | Delete
except UnicodeError:
[284] Fix | Delete
# has UTF-8 signature, but fails to decode...
[285] Fix | Delete
return chars
[286] Fix | Delete
else:
[287] Fix | Delete
# Indicates that this file originally had a BOM
[288] Fix | Delete
self.fileencoding = BOM_UTF8
[289] Fix | Delete
return chars
[290] Fix | Delete
# Next look for coding specification
[291] Fix | Delete
try:
[292] Fix | Delete
enc = coding_spec(chars)
[293] Fix | Delete
except LookupError as name:
[294] Fix | Delete
tkMessageBox.showerror(
[295] Fix | Delete
title="Error loading the file",
[296] Fix | Delete
message="The encoding '%s' is not known to this Python "\
[297] Fix | Delete
"installation. The file may not display correctly" % name,
[298] Fix | Delete
parent = self.text)
[299] Fix | Delete
enc = None
[300] Fix | Delete
if enc:
[301] Fix | Delete
try:
[302] Fix | Delete
return unicode(chars, enc)
[303] Fix | Delete
except UnicodeError:
[304] Fix | Delete
pass
[305] Fix | Delete
# If it is ASCII, we need not to record anything
[306] Fix | Delete
try:
[307] Fix | Delete
return unicode(chars, 'ascii')
[308] Fix | Delete
except UnicodeError:
[309] Fix | Delete
pass
[310] Fix | Delete
# Finally, try the locale's encoding. This is deprecated;
[311] Fix | Delete
# the user should declare a non-ASCII encoding
[312] Fix | Delete
try:
[313] Fix | Delete
chars = unicode(chars, encoding)
[314] Fix | Delete
self.fileencoding = encoding
[315] Fix | Delete
except UnicodeError:
[316] Fix | Delete
pass
[317] Fix | Delete
return chars
[318] Fix | Delete
[319] Fix | Delete
def maybesave(self):
[320] Fix | Delete
if self.get_saved():
[321] Fix | Delete
return "yes"
[322] Fix | Delete
message = "Do you want to save %s before closing?" % (
[323] Fix | Delete
self.filename or "this untitled document")
[324] Fix | Delete
confirm = tkMessageBox.askyesnocancel(
[325] Fix | Delete
title="Save On Close",
[326] Fix | Delete
message=message,
[327] Fix | Delete
default=tkMessageBox.YES,
[328] Fix | Delete
parent=self.text)
[329] Fix | Delete
if confirm:
[330] Fix | Delete
reply = "yes"
[331] Fix | Delete
self.save(None)
[332] Fix | Delete
if not self.get_saved():
[333] Fix | Delete
reply = "cancel"
[334] Fix | Delete
elif confirm is None:
[335] Fix | Delete
reply = "cancel"
[336] Fix | Delete
else:
[337] Fix | Delete
reply = "no"
[338] Fix | Delete
self.text.focus_set()
[339] Fix | Delete
return reply
[340] Fix | Delete
[341] Fix | Delete
def save(self, event):
[342] Fix | Delete
if not self.filename:
[343] Fix | Delete
self.save_as(event)
[344] Fix | Delete
else:
[345] Fix | Delete
if self.writefile(self.filename):
[346] Fix | Delete
self.set_saved(True)
[347] Fix | Delete
try:
[348] Fix | Delete
self.editwin.store_file_breaks()
[349] Fix | Delete
except AttributeError: # may be a PyShell
[350] Fix | Delete
pass
[351] Fix | Delete
self.text.focus_set()
[352] Fix | Delete
return "break"
[353] Fix | Delete
[354] Fix | Delete
def save_as(self, event):
[355] Fix | Delete
filename = self.asksavefile()
[356] Fix | Delete
if filename:
[357] Fix | Delete
if self.writefile(filename):
[358] Fix | Delete
self.set_filename(filename)
[359] Fix | Delete
self.set_saved(1)
[360] Fix | Delete
try:
[361] Fix | Delete
self.editwin.store_file_breaks()
[362] Fix | Delete
except AttributeError:
[363] Fix | Delete
pass
[364] Fix | Delete
self.text.focus_set()
[365] Fix | Delete
self.updaterecentfileslist(filename)
[366] Fix | Delete
return "break"
[367] Fix | Delete
[368] Fix | Delete
def save_a_copy(self, event):
[369] Fix | Delete
filename = self.asksavefile()
[370] Fix | Delete
if filename:
[371] Fix | Delete
self.writefile(filename)
[372] Fix | Delete
self.text.focus_set()
[373] Fix | Delete
self.updaterecentfileslist(filename)
[374] Fix | Delete
return "break"
[375] Fix | Delete
[376] Fix | Delete
def writefile(self, filename):
[377] Fix | Delete
self.fixlastline()
[378] Fix | Delete
chars = self.encode(self.text.get("1.0", "end-1c"))
[379] Fix | Delete
if self.eol_convention != "\n":
[380] Fix | Delete
chars = chars.replace("\n", self.eol_convention)
[381] Fix | Delete
try:
[382] Fix | Delete
with open(filename, "wb") as f:
[383] Fix | Delete
f.write(chars)
[384] Fix | Delete
f.flush()
[385] Fix | Delete
os.fsync(f.fileno())
[386] Fix | Delete
return True
[387] Fix | Delete
except IOError as msg:
[388] Fix | Delete
tkMessageBox.showerror("I/O Error", str(msg),
[389] Fix | Delete
parent=self.text)
[390] Fix | Delete
return False
[391] Fix | Delete
[392] Fix | Delete
def encode(self, chars):
[393] Fix | Delete
if isinstance(chars, str):
[394] Fix | Delete
# This is either plain ASCII, or Tk was returning mixed-encoding
[395] Fix | Delete
# text to us. Don't try to guess further.
[396] Fix | Delete
return chars
[397] Fix | Delete
# See whether there is anything non-ASCII in it.
[398] Fix | Delete
# If not, no need to figure out the encoding.
[399] Fix | Delete
try:
[400] Fix | Delete
return chars.encode('ascii')
[401] Fix | Delete
except UnicodeError:
[402] Fix | Delete
pass
[403] Fix | Delete
# If there is an encoding declared, try this first.
[404] Fix | Delete
try:
[405] Fix | Delete
enc = coding_spec(chars)
[406] Fix | Delete
failed = None
[407] Fix | Delete
except LookupError as msg:
[408] Fix | Delete
failed = msg
[409] Fix | Delete
enc = None
[410] Fix | Delete
if enc:
[411] Fix | Delete
try:
[412] Fix | Delete
return chars.encode(enc)
[413] Fix | Delete
except UnicodeError:
[414] Fix | Delete
failed = "Invalid encoding '%s'" % enc
[415] Fix | Delete
if failed:
[416] Fix | Delete
tkMessageBox.showerror(
[417] Fix | Delete
"I/O Error",
[418] Fix | Delete
"%s. Saving as UTF-8" % failed,
[419] Fix | Delete
parent = self.text)
[420] Fix | Delete
# If there was a UTF-8 signature, use that. This should not fail
[421] Fix | Delete
if self.fileencoding == BOM_UTF8 or failed:
[422] Fix | Delete
return BOM_UTF8 + chars.encode("utf-8")
[423] Fix | Delete
# Try the original file encoding next, if any
[424] Fix | Delete
if self.fileencoding:
[425] Fix | Delete
try:
[426] Fix | Delete
return chars.encode(self.fileencoding)
[427] Fix | Delete
except UnicodeError:
[428] Fix | Delete
tkMessageBox.showerror(
[429] Fix | Delete
"I/O Error",
[430] Fix | Delete
"Cannot save this as '%s' anymore. Saving as UTF-8" \
[431] Fix | Delete
% self.fileencoding,
[432] Fix | Delete
parent = self.text)
[433] Fix | Delete
return BOM_UTF8 + chars.encode("utf-8")
[434] Fix | Delete
# Nothing was declared, and we had not determined an encoding
[435] Fix | Delete
# on loading. Recommend an encoding line.
[436] Fix | Delete
config_encoding = idleConf.GetOption("main","EditorWindow",
[437] Fix | Delete
"encoding")
[438] Fix | Delete
if config_encoding == 'utf-8':
[439] Fix | Delete
# User has requested that we save files as UTF-8
[440] Fix | Delete
return BOM_UTF8 + chars.encode("utf-8")
[441] Fix | Delete
ask_user = True
[442] Fix | Delete
try:
[443] Fix | Delete
chars = chars.encode(encoding)
[444] Fix | Delete
enc = encoding
[445] Fix | Delete
if config_encoding == 'locale':
[446] Fix | Delete
ask_user = False
[447] Fix | Delete
except UnicodeError:
[448] Fix | Delete
chars = BOM_UTF8 + chars.encode("utf-8")
[449] Fix | Delete
enc = "utf-8"
[450] Fix | Delete
if not ask_user:
[451] Fix | Delete
return chars
[452] Fix | Delete
dialog = EncodingMessage(self.editwin.top, enc)
[453] Fix | Delete
dialog.go()
[454] Fix | Delete
if dialog.num == 1:
[455] Fix | Delete
# User asked us to edit the file
[456] Fix | Delete
encline = "# -*- coding: %s -*-\n" % enc
[457] Fix | Delete
firstline = self.text.get("1.0", "2.0")
[458] Fix | Delete
if firstline.startswith("#!"):
[459] Fix | Delete
# Insert encoding after #! line
[460] Fix | Delete
self.text.insert("2.0", encline)
[461] Fix | Delete
else:
[462] Fix | Delete
self.text.insert("1.0", encline)
[463] Fix | Delete
return self.encode(self.text.get("1.0", "end-1c"))
[464] Fix | Delete
return chars
[465] Fix | Delete
[466] Fix | Delete
def fixlastline(self):
[467] Fix | Delete
c = self.text.get("end-2c")
[468] Fix | Delete
if c != '\n':
[469] Fix | Delete
self.text.insert("end-1c", "\n")
[470] Fix | Delete
[471] Fix | Delete
def print_window(self, event):
[472] Fix | Delete
confirm = tkMessageBox.askokcancel(
[473] Fix | Delete
title="Print",
[474] Fix | Delete
message="Print to Default Printer",
[475] Fix | Delete
default=tkMessageBox.OK,
[476] Fix | Delete
parent=self.text)
[477] Fix | Delete
if not confirm:
[478] Fix | Delete
self.text.focus_set()
[479] Fix | Delete
return "break"
[480] Fix | Delete
tempfilename = None
[481] Fix | Delete
saved = self.get_saved()
[482] Fix | Delete
if saved:
[483] Fix | Delete
filename = self.filename
[484] Fix | Delete
# shell undo is reset after every prompt, looks saved, probably isn't
[485] Fix | Delete
if not saved or filename is None:
[486] Fix | Delete
(tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
[487] Fix | Delete
filename = tempfilename
[488] Fix | Delete
os.close(tfd)
[489] Fix | Delete
if not self.writefile(tempfilename):
[490] Fix | Delete
os.unlink(tempfilename)
[491] Fix | Delete
return "break"
[492] Fix | Delete
platform = os.name
[493] Fix | Delete
printPlatform = True
[494] Fix | Delete
if platform == 'posix': #posix platform
[495] Fix | Delete
command = idleConf.GetOption('main','General',
[496] Fix | Delete
'print-command-posix')
[497] Fix | Delete
command = command + " 2>&1"
[498] Fix | Delete
elif platform == 'nt': #win32 platform
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function