blob: e2077500c1bf76421c9e308e47a82c01c69e6f11 [file] [log] [blame]
David Scherer7aced172000-08-15 01:13:23 +00001# changes by dscherer@cmu.edu
2# - IOBinding.open() replaces the current window with the opened file,
3# if the current window is both unmodified and unnamed
4# - IOBinding.loadfile() interprets Windows, UNIX, and Macintosh
5# end-of-line conventions, instead of relying on the standard library,
6# which will only understand the local convention.
7
8import os
Kurt B. Kaiser01166da2002-09-16 22:03:37 +00009import types
10import sys
11import codecs
Steven M. Gava7981ce52002-06-11 04:45:34 +000012import tempfile
David Scherer7aced172000-08-15 01:13:23 +000013import tkFileDialog
14import tkMessageBox
15import re
Kurt B. Kaisera053f332003-05-10 00:49:56 +000016from Tkinter import *
17from SimpleDialog import SimpleDialog
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +000018
Steven M. Gava7981ce52002-06-11 04:45:34 +000019from configHandler import idleConf
David Scherer7aced172000-08-15 01:13:23 +000020
Kurt B. Kaiser01166da2002-09-16 22:03:37 +000021try:
22 from codecs import BOM_UTF8
23except ImportError:
24 # only available since Python 2.3
25 BOM_UTF8 = '\xef\xbb\xbf'
26
27# Try setting the locale, so that we can find out
28# what encoding to use
29try:
30 import locale
31 locale.setlocale(locale.LC_CTYPE, "")
32except ImportError:
33 pass
34
35encoding = "ascii"
36if sys.platform == 'win32':
37 # On Windows, we could use "mbcs". However, to give the user
38 # a portable encoding name, we need to find the code page
39 try:
40 encoding = locale.getdefaultlocale()[1]
41 codecs.lookup(encoding)
42 except LookupError:
43 pass
44else:
45 try:
46 # Different things can fail here: the locale module may not be
47 # loaded, it may not offer nl_langinfo, or CODESET, or the
48 # resulting codeset may be unknown to Python. We ignore all
49 # these problems, falling back to ASCII
50 encoding = locale.nl_langinfo(locale.CODESET)
Tony Lowndse555fc72002-09-23 01:01:20 +000051 if encoding is None:
52 # situation occurs on Mac OS X
53 encoding = 'ascii'
Kurt B. Kaiser01166da2002-09-16 22:03:37 +000054 codecs.lookup(encoding)
55 except (NameError, AttributeError, LookupError):
56 # Try getdefaultlocale well: it parses environment variables,
57 # which may give a clue. Unfortunately, getdefaultlocale has
58 # bugs that can cause ValueError.
59 try:
60 encoding = locale.getdefaultlocale()[1]
Tony Lowndse555fc72002-09-23 01:01:20 +000061 if encoding is None:
62 # situation occurs on Mac OS X
63 encoding = 'ascii'
Kurt B. Kaiser01166da2002-09-16 22:03:37 +000064 codecs.lookup(encoding)
65 except (ValueError, LookupError):
66 pass
67
68encoding = encoding.lower()
69
70coding_re = re.compile("coding[:=]\s*([-\w_.]+)")
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +000071
Kurt B. Kaisera053f332003-05-10 00:49:56 +000072class EncodingMessage(SimpleDialog):
73 "Inform user that an encoding declaration is needed."
74 def __init__(self, master, enc):
75 self.should_edit = False
Kurt B. Kaiser47674012003-05-18 02:24:32 +000076
Kurt B. Kaisera053f332003-05-10 00:49:56 +000077 self.root = top = Toplevel(master)
78 top.bind("<Return>", self.return_event)
79 top.bind("<Escape>", self.do_ok)
80 top.protocol("WM_DELETE_WINDOW", self.wm_delete_window)
81 top.wm_title("I/O Warning")
82 top.wm_iconname("I/O Warning")
83 self.top = top
84
85 l1 = Label(top,
86 text="Non-ASCII found, yet no encoding declared. Add a line like")
87 l1.pack(side=TOP, anchor=W)
88 l2 = Entry(top, font="courier")
89 l2.insert(0, "# -*- coding: %s -*-" % enc)
90 # For some reason, the text is not selectable anymore if the
91 # widget is disabled.
92 # l2['state'] = DISABLED
93 l2.pack(side=TOP, anchor = W, fill=X)
94 l3 = Label(top, text="to your file\n"
95 "Choose OK to save this file as %s\n"
96 "Edit your general options to silence this warning" % enc)
97 l3.pack(side=TOP, anchor = W)
98
99 buttons = Frame(top)
100 buttons.pack(side=TOP, fill=X)
101 # Both return and cancel mean the same thing: do nothing
102 self.default = self.cancel = 0
103 b1 = Button(buttons, text="Ok", default="active",
104 command=self.do_ok)
105 b1.pack(side=LEFT, fill=BOTH, expand=1)
106 b2 = Button(buttons, text="Edit my file",
107 command=self.do_edit)
108 b2.pack(side=LEFT, fill=BOTH, expand=1)
Kurt B. Kaiser47674012003-05-18 02:24:32 +0000109
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000110 self._set_transient(master)
111
112 def do_ok(self):
113 self.done(0)
114
115 def do_edit(self):
116 self.done(1)
117
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000118def coding_spec(str):
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000119 """Return the encoding declaration according to PEP 263.
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000120
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +0000121 Raise LookupError if the encoding is declared but unknown.
122 """
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000123 # Only consider the first two lines
124 str = str.split("\n")[:2]
125 str = "\n".join(str)
126
127 match = coding_re.search(str)
128 if not match:
129 return None
130 name = match.group(1)
131 # Check whether the encoding is known
132 import codecs
133 try:
134 codecs.lookup(name)
135 except LookupError:
136 # The standard encoding error does not indicate the encoding
137 raise LookupError, "Unknown encoding "+name
138 return name
David Scherer7aced172000-08-15 01:13:23 +0000139
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +0000140
David Scherer7aced172000-08-15 01:13:23 +0000141class IOBinding:
142
143 def __init__(self, editwin):
144 self.editwin = editwin
145 self.text = editwin.text
146 self.__id_open = self.text.bind("<<open-window-from-file>>", self.open)
147 self.__id_save = self.text.bind("<<save-window>>", self.save)
148 self.__id_saveas = self.text.bind("<<save-window-as-file>>",
149 self.save_as)
150 self.__id_savecopy = self.text.bind("<<save-copy-of-window-as-file>>",
151 self.save_a_copy)
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000152 self.fileencoding = None
Steven M. Gava7981ce52002-06-11 04:45:34 +0000153 self.__id_print = self.text.bind("<<print-window>>", self.print_window)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000154
David Scherer7aced172000-08-15 01:13:23 +0000155 def close(self):
156 # Undo command bindings
157 self.text.unbind("<<open-window-from-file>>", self.__id_open)
158 self.text.unbind("<<save-window>>", self.__id_save)
159 self.text.unbind("<<save-window-as-file>>",self.__id_saveas)
160 self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy)
Steven M. Gava7981ce52002-06-11 04:45:34 +0000161 self.text.unbind("<<print-window>>", self.__id_print)
David Scherer7aced172000-08-15 01:13:23 +0000162 # Break cycles
163 self.editwin = None
164 self.text = None
165 self.filename_change_hook = None
166
167 def get_saved(self):
168 return self.editwin.get_saved()
169
170 def set_saved(self, flag):
171 self.editwin.set_saved(flag)
172
173 def reset_undo(self):
174 self.editwin.reset_undo()
175
176 filename_change_hook = None
177
178 def set_filename_change_hook(self, hook):
179 self.filename_change_hook = hook
180
181 filename = None
Kurt B. Kaiserd2f48612003-06-05 02:34:04 +0000182 dirname = None
David Scherer7aced172000-08-15 01:13:23 +0000183
184 def set_filename(self, filename):
Kurt B. Kaiserd2f48612003-06-05 02:34:04 +0000185 if filename and os.path.isdir(filename):
186 self.filename = None
187 self.dirname = filename
188 else:
189 self.filename = filename
190 self.dirname = None
191 self.set_saved(1)
192 if self.filename_change_hook:
193 self.filename_change_hook()
David Scherer7aced172000-08-15 01:13:23 +0000194
Steven M. Gava1d46e402002-03-27 08:40:46 +0000195 def open(self, event=None, editFile=None):
David Scherer7aced172000-08-15 01:13:23 +0000196 if self.editwin.flist:
Steven M. Gava1d46e402002-03-27 08:40:46 +0000197 if not editFile:
198 filename = self.askopenfile()
199 else:
200 filename=editFile
David Scherer7aced172000-08-15 01:13:23 +0000201 if filename:
Kurt B. Kaiser1bf4c2d2002-07-21 01:24:28 +0000202 # If the current window has no filename and hasn't been
203 # modified, we replace its contents (no loss). Otherwise
204 # we open a new window. But we won't replace the
205 # shell window (which has an interp(reter) attribute), which
206 # gets set to "not modified" at every new prompt.
207 try:
208 interp = self.editwin.interp
209 except:
210 interp = None
211 if not self.filename and self.get_saved() and not interp:
David Scherer7aced172000-08-15 01:13:23 +0000212 self.editwin.flist.open(filename, self.loadfile)
213 else:
214 self.editwin.flist.open(filename)
215 else:
216 self.text.focus_set()
David Scherer7aced172000-08-15 01:13:23 +0000217 return "break"
Kurt B. Kaiser1bf4c2d2002-07-21 01:24:28 +0000218 #
David Scherer7aced172000-08-15 01:13:23 +0000219 # Code for use outside IDLE:
220 if self.get_saved():
221 reply = self.maybesave()
222 if reply == "cancel":
223 self.text.focus_set()
224 return "break"
Steven M. Gava1d46e402002-03-27 08:40:46 +0000225 if not editFile:
226 filename = self.askopenfile()
227 else:
228 filename=editFile
David Scherer7aced172000-08-15 01:13:23 +0000229 if filename:
230 self.loadfile(filename)
231 else:
232 self.text.focus_set()
233 return "break"
234
Guido van Rossumc2f77dd2003-04-25 18:36:31 +0000235 eol = r"(\r\n)|\n|\r" # \r\n (Windows), \n (UNIX), or \r (Mac)
236 eol_re = re.compile(eol)
237 eol_convention = os.linesep # Default
238
David Scherer7aced172000-08-15 01:13:23 +0000239 def loadfile(self, filename):
240 try:
241 # open the file in binary mode so that we can handle
242 # end-of-line convention ourselves.
243 f = open(filename,'rb')
244 chars = f.read()
245 f.close()
246 except IOError, msg:
247 tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000248 return False
David Scherer7aced172000-08-15 01:13:23 +0000249
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000250 chars = self.decode(chars)
David Scherer7aced172000-08-15 01:13:23 +0000251 # We now convert all end-of-lines to '\n's
Guido van Rossumc2f77dd2003-04-25 18:36:31 +0000252 firsteol = self.eol_re.search(chars)
253 if firsteol:
254 self.eol_convention = firsteol.group(0)
255 chars = self.eol_re.sub(r"\n", chars)
David Scherer7aced172000-08-15 01:13:23 +0000256
257 self.text.delete("1.0", "end")
258 self.set_filename(None)
259 self.text.insert("1.0", chars)
260 self.reset_undo()
261 self.set_filename(filename)
262 self.text.mark_set("insert", "1.0")
263 self.text.see("insert")
Chui Tey993e81a2002-11-04 03:11:10 +0000264 self.updaterecentfileslist(filename)
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000265 return True
266
267 def decode(self, chars):
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +0000268 """Create a Unicode string
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000269
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +0000270 If that fails, let Tcl try its best
271 """
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000272 # Check presence of a UTF-8 signature first
273 if chars.startswith(BOM_UTF8):
274 try:
275 chars = chars[3:].decode("utf-8")
276 except UnicodeError:
277 # has UTF-8 signature, but fails to decode...
278 return chars
279 else:
280 # Indicates that this file originally had a BOM
281 self.fileencoding = BOM_UTF8
282 return chars
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000283 # Next look for coding specification
284 try:
285 enc = coding_spec(chars)
286 except LookupError, name:
287 tkMessageBox.showerror(
288 title="Error loading the file",
289 message="The encoding '%s' is not known to this Python "\
290 "installation. The file may not display correctly" % name,
291 master = self.text)
292 enc = None
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000293 if enc:
294 try:
295 return unicode(chars, enc)
296 except UnicodeError:
297 pass
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000298 # If it is ASCII, we need not to record anything
299 try:
300 return unicode(chars, 'ascii')
301 except UnicodeError:
302 pass
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000303 # Finally, try the locale's encoding. This is deprecated;
304 # the user should declare a non-ASCII encoding
305 try:
306 chars = unicode(chars, encoding)
307 self.fileencoding = encoding
308 except UnicodeError:
309 pass
310 return chars
David Scherer7aced172000-08-15 01:13:23 +0000311
312 def maybesave(self):
313 if self.get_saved():
314 return "yes"
315 message = "Do you want to save %s before closing?" % (
316 self.filename or "this untitled document")
317 m = tkMessageBox.Message(
318 title="Save On Close",
319 message=message,
320 icon=tkMessageBox.QUESTION,
321 type=tkMessageBox.YESNOCANCEL,
322 master=self.text)
323 reply = m.show()
324 if reply == "yes":
325 self.save(None)
326 if not self.get_saved():
327 reply = "cancel"
328 self.text.focus_set()
329 return reply
330
331 def save(self, event):
332 if not self.filename:
333 self.save_as(event)
334 else:
335 if self.writefile(self.filename):
336 self.set_saved(1)
Kurt B. Kaiserddeaf112003-03-04 04:42:04 +0000337 try:
338 self.editwin.store_file_breaks()
339 except AttributeError: # may be a PyShell
340 pass
David Scherer7aced172000-08-15 01:13:23 +0000341 self.text.focus_set()
342 return "break"
343
344 def save_as(self, event):
345 filename = self.asksavefile()
346 if filename:
347 if self.writefile(filename):
348 self.set_filename(filename)
349 self.set_saved(1)
Kurt B. Kaiserddeaf112003-03-04 04:42:04 +0000350 try:
351 self.editwin.store_file_breaks()
352 except AttributeError:
353 pass
David Scherer7aced172000-08-15 01:13:23 +0000354 self.text.focus_set()
Chui Tey993e81a2002-11-04 03:11:10 +0000355 self.updaterecentfileslist(filename)
David Scherer7aced172000-08-15 01:13:23 +0000356 return "break"
357
358 def save_a_copy(self, event):
359 filename = self.asksavefile()
360 if filename:
361 self.writefile(filename)
362 self.text.focus_set()
Chui Tey993e81a2002-11-04 03:11:10 +0000363 self.updaterecentfileslist(filename)
David Scherer7aced172000-08-15 01:13:23 +0000364 return "break"
365
366 def writefile(self, filename):
367 self.fixlastline()
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000368 chars = self.encode(self.text.get("1.0", "end-1c"))
Guido van Rossumc2f77dd2003-04-25 18:36:31 +0000369 if self.eol_convention != "\n":
370 chars = chars.replace("\n", self.eol_convention)
David Scherer7aced172000-08-15 01:13:23 +0000371 try:
Guido van Rossumc2f77dd2003-04-25 18:36:31 +0000372 f = open(filename, "wb")
David Scherer7aced172000-08-15 01:13:23 +0000373 f.write(chars)
374 f.close()
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000375 return True
David Scherer7aced172000-08-15 01:13:23 +0000376 except IOError, msg:
377 tkMessageBox.showerror("I/O Error", str(msg),
378 master=self.text)
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000379 return False
380
381 def encode(self, chars):
382 if isinstance(chars, types.StringType):
383 # This is either plain ASCII, or Tk was returning mixed-encoding
384 # text to us. Don't try to guess further.
385 return chars
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000386 # See whether there is anything non-ASCII in it.
387 # If not, no need to figure out the encoding.
388 try:
389 return chars.encode('ascii')
390 except UnicodeError:
391 pass
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000392 # If there is an encoding declared, try this first.
393 try:
394 enc = coding_spec(chars)
395 failed = None
396 except LookupError, msg:
397 failed = msg
398 enc = None
399 if enc:
400 try:
401 return chars.encode(enc)
402 except UnicodeError:
403 failed = "Invalid encoding '%s'" % enc
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000404 if failed:
405 tkMessageBox.showerror(
406 "I/O Error",
407 "%s. Saving as UTF-8" % failed,
408 master = self.text)
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000409 # If there was a UTF-8 signature, use that. This should not fail
410 if self.fileencoding == BOM_UTF8 or failed:
411 return BOM_UTF8 + chars.encode("utf-8")
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000412 # Try the original file encoding next, if any
413 if self.fileencoding:
414 try:
415 return chars.encode(self.fileencoding)
416 except UnicodeError:
417 tkMessageBox.showerror(
418 "I/O Error",
419 "Cannot save this as '%s' anymore. Saving as UTF-8" \
420 % self.fileencoding,
421 master = self.text)
422 return BOM_UTF8 + chars.encode("utf-8")
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000423 # Nothing was declared, and we had not determined an encoding
424 # on loading. Recommend an encoding line.
Kurt B. Kaiser47674012003-05-18 02:24:32 +0000425 config_encoding = idleConf.GetOption("main","EditorWindow",
426 "encoding")
427 if config_encoding == 'utf-8':
428 # User has requested that we save files as UTF-8
429 return BOM_UTF8 + chars.encode("utf-8")
430 ask_user = True
431 try:
432 chars = chars.encode(encoding)
433 enc = encoding
434 if config_encoding == 'locale':
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000435 ask_user = False
Kurt B. Kaiser47674012003-05-18 02:24:32 +0000436 except UnicodeError:
437 chars = BOM_UTF8 + chars.encode("utf-8")
438 enc = "utf-8"
439 if not ask_user:
Kurt B. Kaisera053f332003-05-10 00:49:56 +0000440 return chars
Kurt B. Kaiser47674012003-05-18 02:24:32 +0000441 dialog = EncodingMessage(self.editwin.top, enc)
442 dialog.go()
443 if dialog.num == 1:
444 # User asked us to edit the file
445 encline = "# -*- coding: %s -*-\n" % enc
446 firstline = self.text.get("1.0", "2.0")
447 if firstline.startswith("#!"):
448 # Insert encoding after #! line
449 self.text.insert("2.0", encline)
450 else:
451 self.text.insert("1.0", encline)
452 return self.encode(self.text.get("1.0", "end-1c"))
453 return chars
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000454
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000455 def fixlastline(self):
456 c = self.text.get("end-2c")
457 if c != '\n':
458 self.text.insert("end-1c", "\n")
459
Steven M. Gava7981ce52002-06-11 04:45:34 +0000460 def print_window(self, event):
461 tempfilename = None
462 if self.get_saved():
463 filename = self.filename
464 else:
465 filename = tempfilename = tempfile.mktemp()
466 if not self.writefile(filename):
467 os.unlink(tempfilename)
468 return "break"
469 platform=os.name
470 printPlatform=1
471 if platform == 'posix': #posix platform
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000472 command = idleConf.GetOption('main','General',
473 'print-command-posix')
Steven M. Gava7981ce52002-06-11 04:45:34 +0000474 command = command + " 2>&1"
475 elif platform == 'nt': #win32 platform
476 command = idleConf.GetOption('main','General','print-command-win')
477 else: #no printing for this platform
478 printPlatform=0
479 if printPlatform: #we can try to print for this platform
480 command = command % filename
481 pipe = os.popen(command, "r")
482 output = pipe.read().strip()
483 status = pipe.close()
484 if status:
Kurt B. Kaiser01166da2002-09-16 22:03:37 +0000485 output = "Printing failed (exit status 0x%x)\n" % \
486 status + output
Steven M. Gava7981ce52002-06-11 04:45:34 +0000487 if output:
488 output = "Printing command: %s\n" % repr(command) + output
489 tkMessageBox.showerror("Print status", output, master=self.text)
490 else: #no printing for this platform
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000491 message="Printing is not enabled for this platform: %s" % platform
Steven M. Gava7981ce52002-06-11 04:45:34 +0000492 tkMessageBox.showinfo("Print status", message, master=self.text)
493 return "break"
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000494
David Scherer7aced172000-08-15 01:13:23 +0000495 opendialog = None
496 savedialog = None
497
498 filetypes = [
499 ("Python and text files", "*.py *.pyw *.txt", "TEXT"),
500 ("All text files", "*", "TEXT"),
501 ("All files", "*"),
502 ]
503
504 def askopenfile(self):
505 dir, base = self.defaultfilename("open")
506 if not self.opendialog:
507 self.opendialog = tkFileDialog.Open(master=self.text,
508 filetypes=self.filetypes)
509 return self.opendialog.show(initialdir=dir, initialfile=base)
510
511 def defaultfilename(self, mode="open"):
512 if self.filename:
513 return os.path.split(self.filename)
Kurt B. Kaiserd2f48612003-06-05 02:34:04 +0000514 elif self.dirname:
515 return self.dirname, ""
David Scherer7aced172000-08-15 01:13:23 +0000516 else:
517 try:
518 pwd = os.getcwd()
519 except os.error:
520 pwd = ""
521 return pwd, ""
522
523 def asksavefile(self):
524 dir, base = self.defaultfilename("save")
525 if not self.savedialog:
526 self.savedialog = tkFileDialog.SaveAs(master=self.text,
527 filetypes=self.filetypes)
528 return self.savedialog.show(initialdir=dir, initialfile=base)
529
Chui Tey993e81a2002-11-04 03:11:10 +0000530 def updaterecentfileslist(self,filename):
Kurt B. Kaiserbfed3462002-12-14 04:38:51 +0000531 "Update recent file list on all editor windows"
Chui Tey993e81a2002-11-04 03:11:10 +0000532 self.editwin.UpdateRecentFilesList(filename)
533
David Scherer7aced172000-08-15 01:13:23 +0000534def test():
David Scherer7aced172000-08-15 01:13:23 +0000535 root = Tk()
536 class MyEditWin:
537 def __init__(self, text):
538 self.text = text
539 self.flist = None
540 self.text.bind("<Control-o>", self.open)
541 self.text.bind("<Control-s>", self.save)
542 self.text.bind("<Alt-s>", self.save_as)
543 self.text.bind("<Alt-z>", self.save_a_copy)
544 def get_saved(self): return 0
545 def set_saved(self, flag): pass
546 def reset_undo(self): pass
547 def open(self, event):
548 self.text.event_generate("<<open-window-from-file>>")
549 def save(self, event):
550 self.text.event_generate("<<save-window>>")
551 def save_as(self, event):
552 self.text.event_generate("<<save-window-as-file>>")
553 def save_a_copy(self, event):
554 self.text.event_generate("<<save-copy-of-window-as-file>>")
555 text = Text(root)
556 text.pack()
557 text.focus_set()
558 editwin = MyEditWin(text)
559 io = IOBinding(editwin)
560 root.mainloop()
561
562if __name__ == "__main__":
David Scherer7aced172000-08-15 01:13:23 +0000563 test()