<s> import os <EOL> from tkinter import * <EOL> import tkinter . messagebox as tkMessageBox <EOL> class FileList : <EOL> from . EditorWindow import EditorWindow <EOL> def __init__ ( self , root ) : <EOL> self . root = root <EOL> self . dict = { } <EOL> self . inversedict = { } <EOL> self . vars = { } <EOL> def open ( self , filename , action = None ) : <EOL> assert filename <EOL> filename = self . canonize ( filename ) <EOL> if os . path . isdir ( filename ) : <EOL> tkMessageBox . showerror ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( filename , ) , <EOL> master = self . root ) <EOL> return None <EOL> key = os . path . normcase ( filename ) <EOL> if key in self . dict : <EOL> edit = self . dict [ key ] <EOL> edit . top . wakeup ( ) <EOL> return edit <EOL> if action : <EOL> return action ( filename ) <EOL> else : <EOL> edit = self . EditorWindow ( self , filename , key ) <EOL> if edit . good_load : <EOL> return edit <EOL> else : <EOL> edit . _close ( ) <EOL> return None <EOL> def gotofileline ( self , filename , lineno = None ) : <EOL> edit = self . open ( filename ) <EOL> if edit is not None and lineno is not None : <EOL> edit . gotoline ( lineno ) <EOL> def new ( self , filename = None ) : <EOL> return self . EditorWindow ( self , filename ) <EOL> def close_all_callback ( self , * args , ** kwds ) : <EOL> for edit in list ( self . inversedict ) : <EOL> reply = edit . close ( ) <EOL> if reply == "<STR_LIT>" : <EOL> break <EOL> return "<STR_LIT>" <EOL> def unregister_maybe_terminate ( self , edit ) : <EOL> try : <EOL> key = self . inversedict [ edit ] <EOL> except KeyError : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> if key : <EOL> del self . dict [ key ] <EOL> del self . inversedict [ edit ] <EOL> if not self . inversedict : <EOL> self . root . quit ( ) <EOL> def filename_changed_edit ( self , edit ) : <EOL> edit . saved_change_hook ( ) <EOL> try : <EOL> key = self . inversedict [ edit ] <EOL> except KeyError : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> filename = edit . io . filename <EOL> if not filename : <EOL> if key : <EOL> del self . dict [ key ] <EOL> self . inversedict [ edit ] = None <EOL> return <EOL> filename = self . canonize ( filename ) <EOL> newkey = os . path . normcase ( filename ) <EOL> if newkey == key : <EOL> return <EOL> if newkey in self . dict : <EOL> conflict = self . dict [ newkey ] <EOL> self . inversedict [ conflict ] = None <EOL> tkMessageBox . showerror ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" % ( filename , ) , <EOL> master = self . root ) <EOL> self . dict [ newkey ] = edit <EOL> self . inversedict [ edit ] = newkey <EOL> if key : <EOL> try : <EOL> del self . dict [ key ] <EOL> except KeyError : <EOL> pass <EOL> def canonize ( self , filename ) : <EOL> if not os . path . isabs ( filename ) : <EOL> try : <EOL> pwd = os . getcwd ( ) <EOL> except os . error : <EOL> pass <EOL> else : <EOL> filename = os . path . join ( pwd , filename ) <EOL> return os . path . normpath ( filename ) <EOL> def _test ( ) : <EOL> from . EditorWindow import fixwordbreaks <EOL> import sys <EOL> root = Tk ( ) <EOL> fixwordbreaks ( root ) <EOL> root . withdraw ( ) <EOL> flist = FileList ( root ) <EOL> if sys . argv [ <NUM_LIT:1> : ] : <EOL> for filename in sys . argv [ <NUM_LIT:1> : ] : <EOL> flist . open ( filename ) <EOL> else : <EOL> flist . new ( ) <EOL> if flist . inversedict : <EOL> root . mainloop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> _test ( ) </s>
