[PyCrust-cvs] PyCrust editor.py,1.9,1.10
Brought to you by:
pobrien
From: <po...@us...> - 2003-04-02 04:54:41
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv17054 Modified Files: editor.py Log Message: Better namespace updates. Refactored to support multiple documents. Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** editor.py 1 Apr 2003 23:20:33 -0000 1.9 --- editor.py 2 Apr 2003 04:54:36 -0000 1.10 *************** *** 32,35 **** --- 32,36 ---- """Create an EditorFrame instance.""" frame.Frame.__init__(self, parent, id, title, pos, size, style) + single = False self.single = single self.docs = {} *************** *** 39,49 **** self.statusText = title + ' - the tastiest Python editor.' self.SetStatusText(self.statusText) - if self.single: self.notebook = PythonEditorNotebook(parent=self) editor = self.notebook.editor ! shell = self.notebook.shell ! interp = shell.interp self.doc = PythonDocument(editor, interp) wx.EVT_IDLE(self, self.OnIdle) --- 40,56 ---- self.statusText = title + ' - the tastiest Python editor.' self.SetStatusText(self.statusText) if self.single: self.notebook = PythonEditorNotebook(parent=self) editor = self.notebook.editor ! interp = self.notebook.shell.interp ! self.doc = PythonDocument(editor, interp) ! else: ! self.notebook = DocumentNotebook(parent=self) ! notebook = PythonEditorNotebook(parent=self.notebook) ! editor = notebook.editor ! interp = notebook.shell.interp self.doc = PythonDocument(editor, interp) + self.notebook.AddPage(page=notebook, text=self.doc.filename, + select=True) wx.EVT_IDLE(self, self.OnIdle) *************** *** 67,71 **** """Event handler for idle time.""" self.updateStatusBar() ! ## self.updateTitleBar() event.Skip() --- 74,78 ---- """Event handler for idle time.""" self.updateStatusBar() ! self.updateTitleBar() event.Skip() *************** *** 78,93 **** self.statusText = text ! ## def updateTitleBar(self): ! ## title = self.GetTitle() ! ## if self.editor.GetModify(): ! ## if title.startswith('* '): ! ## pass ! ## else: ! ## self.SetTitle('* ' + title) ! ## else: ! ## if title.startswith('* '): ! ## self.SetTitle(title[2:]) ! ## else: ! ## self.SetTitle(self.filename + ' - PyAlaMode') def FileClose(self): --- 85,98 ---- self.statusText = text ! def updateTitleBar(self): ! title = self.GetTitle() ! if self.doc.editor.GetModify(): ! if title.startswith('* '): ! pass ! else: ! self.SetTitle('* ' + title) ! else: ! if title.startswith('* '): ! self.SetTitle(title[2:]) def FileClose(self): *************** *** 155,158 **** --- 160,164 ---- self.fileext = '' self.modulename = '' + self.modules = sys.modules.keys() self.syspath = sys.path[:] while True: *************** *** 179,209 **** self.syspath.insert(0, self.filedir) def updateNamespace(self): """Update the namespace for autocompletion and calltips. Return True if updated, False if there was an error.""" - if self.editor.GetModify(): - self.save() backup = self.interp.locals syspath = sys.path sys.path = self.syspath ! try: ! del sys.modules[self.modulename] ! except KeyError: ! pass ! modfile, path, descr = imp.find_module(self.modulename) try: try: ! module = imp.load_module(self.modulename, modfile, path, descr) except: self.interp.locals = backup return False else: ! self.interp.locals = module.__dict__ return True finally: sys.path = syspath ! if modfile: ! modfile.close() def new(self, filepath): --- 185,240 ---- self.syspath.insert(0, self.filedir) + ## def updateNamespace(self): + ## """Update the namespace for autocompletion and calltips. + + ## Return True if updated, False if there was an error.""" + ## if self.editor.GetModify(): + ## self.save() + ## backup = self.interp.locals + ## syspath = sys.path + ## sys.path = self.syspath + ## try: + ## del sys.modules[self.modulename] + ## except KeyError: + ## pass + ## modfile, path, descr = imp.find_module(self.modulename, [self.filedir]) + ## try: + ## try: + ## module = imp.load_module(self.modulename, modfile, path, descr) + ## except: + ## self.interp.locals = backup + ## return False + ## else: + ## self.interp.locals = module.__dict__ + ## return True + ## finally: + ## sys.path = syspath + ## if modfile: + ## modfile.close() + def updateNamespace(self): """Update the namespace for autocompletion and calltips. Return True if updated, False if there was an error.""" backup = self.interp.locals syspath = sys.path sys.path = self.syspath ! code = self.editor.GetText() ! module = imp.new_module(self.modulename) ! namespace = module.__dict__ try: try: ! exec code in namespace except: self.interp.locals = backup return False else: ! self.interp.locals = namespace.copy() return True finally: sys.path = syspath ! for m in sys.modules.keys(): ! if m not in self.modules: ! del sys.modules[m] def new(self, filepath): *************** *** 414,415 **** --- 445,454 ---- # Set focus to the editor. self.editor.SetFocus() + + + class DocumentNotebook(wx.wxNotebook): + """A notebook containing a Python code editor and shell for each document.""" + + def __init__(self, parent): + """Create a PythonEditorNotebook instance.""" + wx.wxNotebook.__init__(self, parent, id=-1) |