| 16 | self.vars = {} # For EditorWindow.getrawvar (shared Tcl variables) |
| 17 | |
| 18 | def open(self, filename, action=None): |
| 19 | assert filename |
| 20 | filename = self.canonize(filename) |
| 21 | if os.path.isdir(filename): |
| 22 | # This can happen when bad filename is passed on command line: |
| 23 | messagebox.showerror( |
| 24 | "File Error", |
| 25 | f"{filename!r} is a directory.", |
| 26 | master=self.root) |
| 27 | return None |
| 28 | key = os.path.normcase(filename) |
| 29 | if key in self.dict: |
| 30 | edit = self.dict[key] |
| 31 | edit.top.wakeup() |
| 32 | return edit |
| 33 | if action: |
| 34 | # Don't create window, perform 'action', e.g. open in same window |
| 35 | return action(filename) |
| 36 | else: |
| 37 | edit = self.EditorWindow(self, filename, key) |
| 38 | if edit.good_load: |
| 39 | return edit |
| 40 | else: |
| 41 | edit._close() |
| 42 | return None |
| 43 | |
| 44 | def gotofileline(self, filename, lineno=None): |
| 45 | edit = self.open(filename) |