[PyCrust-cvs] PyCrust frame.py,1.5,1.6 editor.py,1.10,1.11 PyAlaMode.py,1.4,1.5
Brought to you by:
pobrien
From: <po...@us...> - 2003-04-02 19:05:08
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv6504a Modified Files: frame.py editor.py PyAlaMode.py Log Message: Big refactoring. Index: frame.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/frame.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** frame.py 2 Apr 2003 04:30:32 -0000 1.5 --- frame.py 2 Apr 2003 19:04:57 -0000 1.6 *************** *** 14,22 **** False = 1==0 ID_AUTOCOMP = wx.wxNewId() ID_AUTOCOMP_SHOW = wx.wxNewId() ! ID_AUTOCOMP_INCLUDE_MAGIC = wx.wxNewId() ! ID_AUTOCOMP_INCLUDE_SINGLE = wx.wxNewId() ! ID_AUTOCOMP_INCLUDE_DOUBLE = wx.wxNewId() ID_CALLTIPS = wx.wxNewId() ID_CALLTIPS_SHOW = wx.wxNewId() --- 14,38 ---- False = 1==0 + ID_NEW = wx.wxID_NEW + ID_OPEN = wx.wxID_OPEN + ID_REVERT = wx.wxID_REVERT + ID_CLOSE = wx.wxID_CLOSE + ID_SAVE = wx.wxID_SAVE + ID_SAVEAS = wx.wxID_SAVEAS + ID_PRINT = wx.wxID_PRINT + ID_EXIT = wx.wxID_EXIT + ID_UNDO = wx.wxID_UNDO + ID_REDO = wx.wxID_REDO + ID_CUT = wx.wxID_CUT + ID_COPY = wx.wxID_COPY + ID_PASTE = wx.wxID_PASTE + ID_CLEAR = wx.wxID_CLEAR + ID_SELECTALL = wx.wxID_SELECTALL + ID_ABOUT = wx.wxID_ABOUT ID_AUTOCOMP = wx.wxNewId() ID_AUTOCOMP_SHOW = wx.wxNewId() ! ID_AUTOCOMP_MAGIC = wx.wxNewId() ! ID_AUTOCOMP_SINGLE = wx.wxNewId() ! ID_AUTOCOMP_DOUBLE = wx.wxNewId() ID_CALLTIPS = wx.wxNewId() ID_CALLTIPS_SHOW = wx.wxNewId() *************** *** 50,69 **** def __createMenus(self): m = self.fileMenu = wx.wxMenu() ! m.Append(wx.wxID_NEW, '&New \tCtrl+N', 'New file') ! m.Append(wx.wxID_OPEN, '&Open... \tCtrl+O', 'Open file') m.AppendSeparator() ! m.Append(wx.wxID_REVERT, '&Revert \tCtrl+R', 'Revert to last saved version') ! m.Append(wx.wxID_CLOSE, '&Close \tCtrl+W', 'Close file') m.AppendSeparator() ! m.Append(wx.wxID_SAVE, '&Save... \tCtrl+S', 'Save file') ! m.Append(wx.wxID_SAVEAS, 'Save &As \tShift+Ctrl+S', 'Save file with new name') m.AppendSeparator() ! m.Append(wx.wxID_PRINT, '&Print... \tCtrl+P', 'Print file') m.AppendSeparator() --- 66,85 ---- def __createMenus(self): m = self.fileMenu = wx.wxMenu() ! m.Append(ID_NEW, '&New \tCtrl+N', 'New file') ! m.Append(ID_OPEN, '&Open... \tCtrl+O', 'Open file') m.AppendSeparator() ! m.Append(ID_REVERT, '&Revert \tCtrl+R', 'Revert to last saved version') ! m.Append(ID_CLOSE, '&Close \tCtrl+W', 'Close file') m.AppendSeparator() ! m.Append(ID_SAVE, '&Save... \tCtrl+S', 'Save file') ! m.Append(ID_SAVEAS, 'Save &As \tShift+Ctrl+S', 'Save file with new name') m.AppendSeparator() ! m.Append(ID_PRINT, '&Print... \tCtrl+P', 'Print file') m.AppendSeparator() *************** *** 71,95 **** 'Update namespace for autocompletion and calltips') m.AppendSeparator() ! m.Append(wx.wxID_EXIT, 'E&xit', 'Exit Program') m = self.editMenu = wx.wxMenu() ! m.Append(wx.wxID_UNDO, '&Undo \tCtrl+Z', 'Undo the last action') ! m.Append(wx.wxID_REDO, '&Redo \tCtrl+Y', 'Redo the last undone action') m.AppendSeparator() ! m.Append(wx.wxID_CUT, 'Cu&t \tCtrl+X', 'Cut the selection') ! m.Append(wx.wxID_COPY, '&Copy \tCtrl+C', 'Copy the selection') m.Append(ID_COPY_PLUS, 'Cop&y Plus \tShift+Ctrl+C', 'Copy the selection - retaining prompts') ! m.Append(wx.wxID_PASTE, '&Paste \tCtrl+V', 'Paste from clipboard') m.Append(ID_PASTE_PLUS, 'Past&e Plus \tShift+Ctrl+V', 'Paste and run commands') m.AppendSeparator() ! m.Append(wx.wxID_CLEAR, 'Cle&ar', 'Delete the selection') ! m.Append(wx.wxID_SELECTALL, 'Select A&ll \tCtrl+A', 'Select all text') --- 87,111 ---- 'Update namespace for autocompletion and calltips') m.AppendSeparator() ! m.Append(ID_EXIT, 'E&xit', 'Exit Program') m = self.editMenu = wx.wxMenu() ! m.Append(ID_UNDO, '&Undo \tCtrl+Z', 'Undo the last action') ! m.Append(ID_REDO, '&Redo \tCtrl+Y', 'Redo the last undone action') m.AppendSeparator() ! m.Append(ID_CUT, 'Cu&t \tCtrl+X', 'Cut the selection') ! m.Append(ID_COPY, '&Copy \tCtrl+C', 'Copy the selection') m.Append(ID_COPY_PLUS, 'Cop&y Plus \tShift+Ctrl+C', 'Copy the selection - retaining prompts') ! m.Append(ID_PASTE, '&Paste \tCtrl+V', 'Paste from clipboard') m.Append(ID_PASTE_PLUS, 'Past&e Plus \tShift+Ctrl+V', 'Paste and run commands') m.AppendSeparator() ! m.Append(ID_CLEAR, 'Cle&ar', 'Delete the selection') ! m.Append(ID_SELECTALL, 'Select A&ll \tCtrl+A', 'Select all text') *************** *** 97,106 **** m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion', 'Show auto completion list', 1) ! m.Append(ID_AUTOCOMP_INCLUDE_MAGIC, 'Include Magic Attributes', 'Include attributes visible to __getattr__ and __setattr__', 1) ! m.Append(ID_AUTOCOMP_INCLUDE_SINGLE, 'Include Single Underscores', 'Include attibutes prefixed by a single underscore', 1) ! m.Append(ID_AUTOCOMP_INCLUDE_DOUBLE, 'Include Double Underscores', 'Include attibutes prefixed by a double underscore', 1) --- 113,122 ---- m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion', 'Show auto completion list', 1) ! m.Append(ID_AUTOCOMP_MAGIC, 'Include Magic Attributes', 'Include attributes visible to __getattr__ and __setattr__', 1) ! m.Append(ID_AUTOCOMP_SINGLE, 'Include Single Underscores', 'Include attibutes prefixed by a single underscore', 1) ! m.Append(ID_AUTOCOMP_DOUBLE, 'Include Double Underscores', 'Include attibutes prefixed by a double underscore', 1) *************** *** 119,123 **** m = self.helpMenu = wx.wxMenu() m.AppendSeparator() ! m.Append(wx.wxID_ABOUT, '&About...', 'About this program') b = self.menuBar = wx.wxMenuBar() --- 135,139 ---- m = self.helpMenu = wx.wxMenu() m.AppendSeparator() ! m.Append(ID_ABOUT, '&About...', 'About this program') b = self.menuBar = wx.wxMenuBar() *************** *** 128,203 **** self.SetMenuBar(b) ! wx.EVT_MENU(self, wx.wxID_NEW, self.OnFileNew) ! wx.EVT_MENU(self, wx.wxID_OPEN, self.OnFileOpen) ! wx.EVT_MENU(self, wx.wxID_REVERT, self.OnFileRevert) ! wx.EVT_MENU(self, wx.wxID_CLOSE, self.OnFileClose) ! wx.EVT_MENU(self, wx.wxID_SAVE, self.OnFileSave) ! wx.EVT_MENU(self, wx.wxID_SAVEAS, self.OnFileSaveAs) wx.EVT_MENU(self, ID_NAMESPACE, self.OnFileUpdateNamespace) ! wx.EVT_MENU(self, wx.wxID_PRINT, self.OnFilePrint) ! wx.EVT_MENU(self, wx.wxID_EXIT, self.OnExit) ! wx.EVT_MENU(self, wx.wxID_UNDO, self.OnUndo) ! wx.EVT_MENU(self, wx.wxID_REDO, self.OnRedo) ! wx.EVT_MENU(self, wx.wxID_CUT, self.OnCut) ! wx.EVT_MENU(self, wx.wxID_COPY, self.OnCopy) wx.EVT_MENU(self, ID_COPY_PLUS, self.OnCopyPlus) ! wx.EVT_MENU(self, wx.wxID_PASTE, self.OnPaste) wx.EVT_MENU(self, ID_PASTE_PLUS, self.OnPastePlus) ! wx.EVT_MENU(self, wx.wxID_CLEAR, self.OnClear) ! wx.EVT_MENU(self, wx.wxID_SELECTALL, self.OnSelectAll) ! wx.EVT_MENU(self, wx.wxID_ABOUT, self.OnAbout) ! wx.EVT_MENU(self, ID_AUTOCOMP_SHOW, ! self.OnAutoCompleteShow) ! wx.EVT_MENU(self, ID_AUTOCOMP_INCLUDE_MAGIC, ! self.OnAutoCompleteIncludeMagic) ! wx.EVT_MENU(self, ID_AUTOCOMP_INCLUDE_SINGLE, ! self.OnAutoCompleteIncludeSingle) ! wx.EVT_MENU(self, ID_AUTOCOMP_INCLUDE_DOUBLE, ! self.OnAutoCompleteIncludeDouble) ! wx.EVT_MENU(self, ID_CALLTIPS_SHOW, ! self.OnCallTipsShow) wx.EVT_MENU(self, ID_WRAP, self.OnWrap) ! wx.EVT_UPDATE_UI(self, wx.wxID_NEW, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_OPEN, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_REVERT, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_CLOSE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_SAVE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_SAVEAS, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_NAMESPACE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_PRINT, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_UNDO, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_REDO, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_CUT, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_COPY, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_COPY_PLUS, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_PASTE, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_PASTE_PLUS, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_CLEAR, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, wx.wxID_SELECTALL, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_SHOW, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_INCLUDE_MAGIC, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_INCLUDE_SINGLE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_INCLUDE_DOUBLE, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_CALLTIPS_SHOW, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_WRAP, self.OnUpdateMenu) def OnFileNew(self, event): ! self.FileNew() def OnFileOpen(self, event): ! self.FileOpen() def OnFileRevert(self, event): ! self.FileRevert() def OnFileClose(self, event): ! self.FileClose() def OnFileSave(self, event): ! self.FileSave() def OnFileSaveAs(self, event): ! self.FileSaveAs() def OnFileUpdateNamespace(self, event): --- 144,214 ---- self.SetMenuBar(b) ! wx.EVT_MENU(self, ID_NEW, self.OnFileNew) ! wx.EVT_MENU(self, ID_OPEN, self.OnFileOpen) ! wx.EVT_MENU(self, ID_REVERT, self.OnFileRevert) ! wx.EVT_MENU(self, ID_CLOSE, self.OnFileClose) ! wx.EVT_MENU(self, ID_SAVE, self.OnFileSave) ! wx.EVT_MENU(self, ID_SAVEAS, self.OnFileSaveAs) wx.EVT_MENU(self, ID_NAMESPACE, self.OnFileUpdateNamespace) ! wx.EVT_MENU(self, ID_PRINT, self.OnFilePrint) ! wx.EVT_MENU(self, ID_EXIT, self.OnExit) ! wx.EVT_MENU(self, ID_UNDO, self.OnUndo) ! wx.EVT_MENU(self, ID_REDO, self.OnRedo) ! wx.EVT_MENU(self, ID_CUT, self.OnCut) ! wx.EVT_MENU(self, ID_COPY, self.OnCopy) wx.EVT_MENU(self, ID_COPY_PLUS, self.OnCopyPlus) ! wx.EVT_MENU(self, ID_PASTE, self.OnPaste) wx.EVT_MENU(self, ID_PASTE_PLUS, self.OnPastePlus) ! wx.EVT_MENU(self, ID_CLEAR, self.OnClear) ! wx.EVT_MENU(self, ID_SELECTALL, self.OnSelectAll) ! wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) ! wx.EVT_MENU(self, ID_AUTOCOMP_SHOW, self.OnAutoCompleteShow) ! wx.EVT_MENU(self, ID_AUTOCOMP_MAGIC, self.OnAutoCompleteMagic) ! wx.EVT_MENU(self, ID_AUTOCOMP_SINGLE, self.OnAutoCompleteSingle) ! wx.EVT_MENU(self, ID_AUTOCOMP_DOUBLE, self.OnAutoCompleteDouble) ! wx.EVT_MENU(self, ID_CALLTIPS_SHOW, self.OnCallTipsShow) wx.EVT_MENU(self, ID_WRAP, self.OnWrap) ! wx.EVT_UPDATE_UI(self, ID_NEW, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_OPEN, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_REVERT, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_CLOSE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_SAVE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_SAVEAS, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_NAMESPACE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_PRINT, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_UNDO, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_REDO, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_CUT, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_COPY, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_COPY_PLUS, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_PASTE, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_PASTE_PLUS, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_CLEAR, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_SELECTALL, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_SHOW, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_MAGIC, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_SINGLE, self.OnUpdateMenu) ! wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_DOUBLE, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_CALLTIPS_SHOW, self.OnUpdateMenu) wx.EVT_UPDATE_UI(self, ID_WRAP, self.OnUpdateMenu) def OnFileNew(self, event): ! self.bufferNew() def OnFileOpen(self, event): ! self.bufferOpen() def OnFileRevert(self, event): ! self.bufferRevert() def OnFileClose(self, event): ! self.bufferClose() def OnFileSave(self, event): ! self.bufferSave() def OnFileSaveAs(self, event): ! self.bufferSaveAs() def OnFileUpdateNamespace(self, event): *************** *** 205,209 **** def OnFilePrint(self, event): ! self.FilePrint() def OnExit(self, event): --- 216,220 ---- def OnFilePrint(self, event): ! self.bufferPrint() def OnExit(self, event): *************** *** 259,271 **** win.autoComplete = event.IsChecked() ! def OnAutoCompleteIncludeMagic(self, event): win = wx.wxWindow_FindFocus() win.autoCompleteIncludeMagic = event.IsChecked() ! def OnAutoCompleteIncludeSingle(self, event): win = wx.wxWindow_FindFocus() win.autoCompleteIncludeSingle = event.IsChecked() ! def OnAutoCompleteIncludeDouble(self, event): win = wx.wxWindow_FindFocus() win.autoCompleteIncludeDouble = event.IsChecked() --- 270,282 ---- win.autoComplete = event.IsChecked() ! def OnAutoCompleteMagic(self, event): win = wx.wxWindow_FindFocus() win.autoCompleteIncludeMagic = event.IsChecked() ! def OnAutoCompleteSingle(self, event): win = wx.wxWindow_FindFocus() win.autoCompleteIncludeSingle = event.IsChecked() ! def OnAutoCompleteDouble(self, event): win = wx.wxWindow_FindFocus() win.autoCompleteIncludeDouble = event.IsChecked() *************** *** 280,329 **** def OnUpdateMenu(self, event): ! """Update menu items based on current status.""" win = wx.wxWindow_FindFocus() id = event.GetId() event.Enable(True) try: ! if id == wx.wxID_NEW: ! event.Enable(hasattr(self, 'FileNew')) ! elif id == wx.wxID_OPEN: ! event.Enable(hasattr(self, 'FileOpen')) ! elif id == wx.wxID_REVERT: ! event.Enable(hasattr(self, 'FileRevert')) ! elif id == wx.wxID_CLOSE: ! event.Enable(hasattr(self, 'FileClose')) ! elif id == wx.wxID_SAVE: ! event.Enable(hasattr(self, 'FileSave') and self.doc.editor.GetModify()) ! elif id == wx.wxID_SAVEAS: ! event.Enable(hasattr(self, 'FileSaveAs')) elif id == ID_NAMESPACE: event.Enable(hasattr(self, 'updateNamespace')) ! elif id == wx.wxID_PRINT: ! event.Enable(hasattr(self, 'FilePrint')) ! elif id == wx.wxID_UNDO: event.Enable(win.CanUndo()) ! elif id == wx.wxID_REDO: event.Enable(win.CanRedo()) ! elif id == wx.wxID_CUT: event.Enable(win.CanCut()) ! elif id == wx.wxID_COPY: event.Enable(win.CanCopy()) elif id == ID_COPY_PLUS: event.Enable(win.CanCopy() and hasattr(win, 'CopyWithPrompts')) ! elif id == wx.wxID_PASTE: event.Enable(win.CanPaste()) elif id == ID_PASTE_PLUS: event.Enable(win.CanPaste() and hasattr(win, 'PasteAndRun')) ! elif id == wx.wxID_CLEAR: event.Enable(win.CanCut()) ! elif id == wx.wxID_SELECTALL: event.Enable(hasattr(win, 'SelectAll')) elif id == ID_AUTOCOMP_SHOW: event.Check(win.autoComplete) ! elif id == ID_AUTOCOMP_INCLUDE_MAGIC: event.Check(win.autoCompleteIncludeMagic) ! elif id == ID_AUTOCOMP_INCLUDE_SINGLE: event.Check(win.autoCompleteIncludeSingle) ! elif id == ID_AUTOCOMP_INCLUDE_DOUBLE: event.Check(win.autoCompleteIncludeDouble) elif id == ID_CALLTIPS_SHOW: --- 291,340 ---- def OnUpdateMenu(self, event): ! """Update menu items based on current status and context.""" win = wx.wxWindow_FindFocus() id = event.GetId() event.Enable(True) try: ! if id == ID_NEW: ! event.Enable(hasattr(self, 'bufferNew')) ! elif id == ID_OPEN: ! event.Enable(hasattr(self, 'bufferOpen')) ! elif id == ID_REVERT: ! event.Enable(hasattr(self, 'bufferRevert')) ! elif id == ID_CLOSE: ! event.Enable(hasattr(self, 'bufferClose')) ! elif id == ID_SAVE: ! event.Enable(hasattr(self, 'bufferSave') and self.bufferHasChanged()) ! elif id == ID_SAVEAS: ! event.Enable(hasattr(self, 'bufferSaveAs')) elif id == ID_NAMESPACE: event.Enable(hasattr(self, 'updateNamespace')) ! elif id == ID_PRINT: ! event.Enable(hasattr(self, 'bufferPrint')) ! elif id == ID_UNDO: event.Enable(win.CanUndo()) ! elif id == ID_REDO: event.Enable(win.CanRedo()) ! elif id == ID_CUT: event.Enable(win.CanCut()) ! elif id == ID_COPY: event.Enable(win.CanCopy()) elif id == ID_COPY_PLUS: event.Enable(win.CanCopy() and hasattr(win, 'CopyWithPrompts')) ! elif id == ID_PASTE: event.Enable(win.CanPaste()) elif id == ID_PASTE_PLUS: event.Enable(win.CanPaste() and hasattr(win, 'PasteAndRun')) ! elif id == ID_CLEAR: event.Enable(win.CanCut()) ! elif id == ID_SELECTALL: event.Enable(hasattr(win, 'SelectAll')) elif id == ID_AUTOCOMP_SHOW: event.Check(win.autoComplete) ! elif id == ID_AUTOCOMP_MAGIC: event.Check(win.autoCompleteIncludeMagic) ! elif id == ID_AUTOCOMP_SINGLE: event.Check(win.autoCompleteIncludeSingle) ! elif id == ID_AUTOCOMP_DOUBLE: event.Check(win.autoCompleteIncludeDouble) elif id == ID_CALLTIPS_SHOW: Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** editor.py 2 Apr 2003 04:54:36 -0000 1.10 --- editor.py 2 Apr 2003 19:04:58 -0000 1.11 *************** *** 24,62 **** ! class PythonEditorFrame(frame.Frame): ! """Frame containing one or more Python editor notebooks.""" def __init__(self, parent=None, id=-1, title='PyAlaMode', pos=wx.wxDefaultPosition, size=(600, 400), ! style=wx.wxDEFAULT_FRAME_STYLE, single=True): """Create an EditorFrame instance.""" frame.Frame.__init__(self, parent, id, title, pos, size, style) ! single = False ! self.single = single ! self.docs = {} ! self.doc = None # Current document. ! self.editor = None # Current document editor. self.SetTitle('PyAlaMode') ! 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) def OnAbout(self, event): """Display an About window.""" title = 'About PyAlaMode' ! text = 'Another fine, flaky product.' dialog = wx.wxMessageDialog(self, text, title, wx.wxOK | wx.wxICON_INFORMATION) --- 24,62 ---- ! class EditorFrame(frame.Frame): ! """Frame containing one or more editor notebooks.""" def __init__(self, parent=None, id=-1, title='PyAlaMode', pos=wx.wxDefaultPosition, size=(600, 400), ! style=wx.wxDEFAULT_FRAME_STYLE, ! filename=None, singlefile=False): """Create an EditorFrame instance.""" frame.Frame.__init__(self, parent, id, title, pos, size, style) ! self._singlefile = singlefile ! self._buffers = {} ! self._buffer = None # Current buffer. self.SetTitle('PyAlaMode') ! self._statusText = title + ' - the tastiest Python editor.' ! self.SetStatusText(self._statusText) ! if self._singlefile: ! self._notebook = EditorNotebook(parent=self) ! editor = self._notebook.editor ! interp = self._notebook.shell.interp else: ! self._notebook = BufferNotebook(parent=self) ! notebook = EditorNotebook(parent=self._notebook) editor = notebook.editor interp = notebook.shell.interp ! self._buffer = Buffer(editor, interp, filename) ! if not self._singlefile: ! self._notebook.AddPage(page=notebook, text=self._buffer.name) ! self._buffers[self._buffer.id] = self._buffer wx.EVT_IDLE(self, self.OnIdle) + self._buffer.editor.SetFocus() def OnAbout(self, event): """Display an About window.""" title = 'About PyAlaMode' ! text = 'Another fine, flaky program.' dialog = wx.wxMessageDialog(self, text, title, wx.wxOK | wx.wxICON_INFORMATION) *************** *** 66,91 **** def OnCloseWindow(self, event): """Event handler for closing.""" ! for doc in self.docs.values(): ! if doc.editor.GetModify(): ! doc.FileSuggestSave() self.Destroy() def OnIdle(self, event): """Event handler for idle time.""" ! self.updateStatusBar() ! self.updateTitleBar() event.Skip() ! def updateStatusBar(self): ! if self.doc: ! status = self.doc.getStatus() text = 'File: %s | Line: %d | Column: %d' % status ! if text != self.statusText: self.SetStatusText(text) ! self.statusText = text ! def updateTitleBar(self): title = self.GetTitle() ! if self.doc.editor.GetModify(): if title.startswith('* '): pass --- 66,93 ---- def OnCloseWindow(self, event): """Event handler for closing.""" ! for buffer in self._buffers.values(): ! if buffer.hasChanged(): ! self.bufferSuggestSave() self.Destroy() def OnIdle(self, event): """Event handler for idle time.""" ! self._updateStatusBar() ! self._updateTitleBar() event.Skip() ! def _updateStatusBar(self): ! """Update the status bar text.""" ! if self._buffer: ! status = self._buffer.getStatus() text = 'File: %s | Line: %d | Column: %d' % status ! if text != self._statusText: self.SetStatusText(text) ! self._statusText = text ! def _updateTitleBar(self): ! """Update the title bar text.""" title = self.GetTitle() ! if self.bufferHasChanged(): if title.startswith('* '): pass *************** *** 96,163 **** self.SetTitle(title[2:]) ! def FileClose(self): ! """Close file in editor.""" ! if self.doc.editor.GetModify(): ! self.FileSuggestSave() ! def FileNew(self): ! """Create new file in editor.""" ! if self.doc.editor.GetModify(): ! self.FileSuggestSave() ! def FileOpen(self, filename=None): ! """Open file in editor.""" ! if self.doc and self.doc.editor.GetModify(): ! self.FileSuggestSave() if filename is None: return # XXX Prompt for filename. if filename: ! self.doc.open(filename) ! def FilePrint(self): ! """Print file in editor.""" pass ! def FileRevert(self): ! """Revert file in editor.""" pass ! def FileSave(self): ! """Save file in editor.""" ! self.doc.save() ! def FileSaveAs(self): ! """Save file in editor with new name.""" ! if self.doc.editor.GetModify(): ! self.FileSuggestSave() # Get new name filename = '' # XXX ! ## self.doc.saveAs(filename) ! def FileSuggestSave(self): """Suggest saving changes.""" ! confirm = True if confirm: ! self.FileSave() def updateNamespace(self): ! if self.doc.updateNamespace(): self.SetStatusText('Namespace updated') else: ! self.SetStatusText('Error importing file, unable to update namespace') ! class PythonDocument: ! """Python Document class.""" def __init__(self, editor, interp, filename=None): ! """Create a PythonDocument instance.""" self.editor = editor self.interp = interp - self.filename = 'Untitled' - self.filepath = '' - self.filedir = '' - self.fileext = '' - self.modulename = '' self.modules = sys.modules.keys() self.syspath = sys.path[:] --- 98,170 ---- self.SetTitle(title[2:]) ! def bufferClose(self): ! """Close buffer.""" ! if self.bufferHasChanged(): ! self.bufferSuggestSave() ! def bufferHasChanged(self): ! """Return True if buffer has changed since last save.""" ! return self._buffer.hasChanged() ! def bufferNew(self): ! """Create new buffer.""" ! if self.bufferHasChanged(): ! self.bufferSuggestSave() ! ! def bufferOpen(self, filename=None): ! """Open file in buffer.""" ! if self._buffer and self.bufferHasChanged(): ! self.bufferSuggestSave() if filename is None: return # XXX Prompt for filename. if filename: ! self._buffer.open(filename) ! def bufferPrint(self): ! """Print buffer.""" pass ! def bufferRevert(self): ! """Revert buffer to version of file on disk.""" pass ! def bufferSave(self): ! """Save buffer to its file.""" ! self._buffer.save() ! def bufferSaveAs(self): ! """Save buffer to a new filename.""" ! if self.bufferHasChanged(): ! self.bufferSuggestSave() # Get new name filename = '' # XXX ! ## self._buffer.saveAs(filename) ! def bufferSuggestSave(self): """Suggest saving changes.""" ! confirm = False if confirm: ! self.bufferSave() def updateNamespace(self): ! """Update the buffer namespace for autocompletion and calltips.""" ! if self._buffer.updateNamespace(): self.SetStatusText('Namespace updated') else: ! self.SetStatusText('Error executing, unable to update namespace') ! class Buffer: ! """Buffer class.""" ! ! id = 0 def __init__(self, editor, interp, filename=None): ! """Create a Buffer instance.""" ! Buffer.id += 1 ! self.id = Buffer.id ! self.name = 'Buffer' self.editor = editor self.interp = interp self.modules = sys.modules.keys() self.syspath = sys.path[:] *************** *** 172,187 **** except ValueError: break ! if filename: ! self._setFileInfo(filename) ! ! def _setFileInfo(self, filename): ! """Set file information.""" ! if not filename: ! raise AttributeError ! self.filepath = os.path.abspath(filename) ! self.filedir, self.filename = os.path.split(self.filepath) ! self.modulename, self.fileext = os.path.splitext(self.filename) ! if self.filedir not in self.syspath: ! self.syspath.insert(0, self.filedir) ## def updateNamespace(self): --- 179,183 ---- except ValueError: break ! self.open(filename) ## def updateNamespace(self): *************** *** 213,216 **** --- 209,216 ---- ## modfile.close() + def hasChanged(self): + """Return True if text in editor has changed since last save.""" + return self.editor.GetModify() + def updateNamespace(self): """Update the namespace for autocompletion and calltips. *************** *** 239,243 **** def new(self, filepath): ! """New document.""" if not filepath: return --- 239,243 ---- def new(self, filepath): ! """New empty buffer.""" if not filepath: return *************** *** 248,258 **** def open(self, filename): ! """Open file.""" ! self._setFileInfo(filename) ! if os.path.exists(self.filepath): ! self.read(self.filepath) self.confirmed = True ! else: ! self.new(self.filepath) def overwriteConfirm(filepath): --- 248,261 ---- def open(self, filename): ! """Open file into buffer.""" ! self.doc = Document(filename) ! self.name = self.doc.filename or 'Untitled' ! self.modulename = self.doc.filebase ! if self.doc.filepath and os.path.exists(self.doc.filepath): ! self.editor.SetText(self.doc.read()) ! self.editor.EmptyUndoBuffer() self.confirmed = True ! if self.doc.filedir and self.doc.filedir not in self.syspath: ! self.syspath.insert(0, self.doc.filedir) def overwriteConfirm(filepath): *************** *** 260,277 **** return False - def read(self, filepath): - """Replace editor text with contents of file.""" - f = file(filepath, 'rb') - try: - self.editor.SetText(f.read()) - self.editor.EmptyUndoBuffer() - finally: - f.close() - def save(self): ! """Save document.""" ! filepath = self.filepath if not filepath: ! return if not os.path.exists(filepath): self.confirmed = True --- 263,271 ---- return False def save(self): ! """Save buffer.""" ! filepath = self.doc.filepath if not filepath: ! return # XXX Get filename if not os.path.exists(filepath): self.confirmed = True *************** *** 279,304 **** self.confirmed = self.overwriteConfirm(filepath) if self.confirmed: ! self.write(filepath) ! ! def write(self, filepath): ! """Write all editor text to file.""" ! try: ! f = file(filepath, 'w') ! f.write(self.editor.GetText()) self.editor.SetSavePoint() - finally: - f.close() def getStatus(self): ! """Return (filepath, line, column) tuple.""" editor = self.editor pos = editor.GetCurrentPos() line = editor.LineFromPosition(pos) + 1 col = editor.GetColumn(pos) + 1 ! status = (self.filepath, line, col) return status ! class PythonEditor(base.Editor): """Editor based on StyledTextCtrl.""" --- 273,323 ---- self.confirmed = self.overwriteConfirm(filepath) if self.confirmed: ! self.doc.write(self.editor.GetText()) self.editor.SetSavePoint() def getStatus(self): ! """Return (filepath, line, column) status tuple.""" editor = self.editor pos = editor.GetCurrentPos() line = editor.LineFromPosition(pos) + 1 col = editor.GetColumn(pos) + 1 ! status = (self.doc.filepath or self.name, line, col) return status ! class Document: ! """Document class.""" ! ! def __init__(self, filename=None): ! """Create a Document instance.""" ! self.filename = filename ! self.filepath = None ! self.filedir = None ! self.filebase = None ! self.fileext = None ! if self.filename: ! self.filepath = os.path.abspath(self.filename) ! self.filedir, self.filename = os.path.split(self.filepath) ! self.filebase, self.fileext = os.path.splitext(self.filename) ! ! def read(self): ! """Return contents of file.""" ! f = file(self.filepath, 'rb') ! try: ! return f.read() ! finally: ! f.close() ! ! def write(self, text): ! """Write text to file.""" ! try: ! f = file(self.filepath, 'w') ! f.write(text) ! finally: ! if f: ! f.close() ! ! ! class Editor(base.Editor): """Editor based on StyledTextCtrl.""" *************** *** 306,310 **** size=wx.wxDefaultSize, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER): ! """Create a PythonEditor instance.""" base.Editor.__init__(self, parent, id, pos, size, style) self.confirmed = False --- 325,329 ---- size=wx.wxDefaultSize, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER): ! """Create a Editor instance.""" base.Editor.__init__(self, parent, id, pos, size, style) self.confirmed = False *************** *** 410,418 **** ! class PythonEditorNotebook(wx.wxNotebook): ! """Combines a Python code editor with a shell.""" def __init__(self, parent): ! """Create a PythonEditorNotebook instance.""" wx.wxNotebook.__init__(self, parent, id=-1) usePanels = True --- 429,437 ---- ! class EditorNotebook(wx.wxNotebook): ! """Combines a code editor with a shell.""" def __init__(self, parent): ! """Create an EditorNotebook instance.""" wx.wxNotebook.__init__(self, parent, id=-1) usePanels = True *************** *** 422,427 **** self.shell = Shell(parent=shellpanel, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) ! self.editor = PythonEditor(interp=self.shell.interp, ! parent=editorpanel) self.AddPage(page=editorpanel, text='File', select=True) self.AddPage(page=shellpanel, text='Shell') --- 441,445 ---- self.shell = Shell(parent=shellpanel, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) ! self.editor = Editor(interp=self.shell.interp, parent=editorpanel) self.AddPage(page=editorpanel, text='File', select=True) self.AddPage(page=shellpanel, text='Shell') *************** *** 438,443 **** self.shell = Shell(parent=self, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) ! self.editor = PythonEditor(interp=self.shell.interp, ! parent=self) self.shell.interp.locals['editor'] = self.editor self.AddPage(page=self.editor, text='File', select=True) --- 456,460 ---- self.shell = Shell(parent=self, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) ! self.editor = Editor(interp=self.shell.interp, parent=self) self.shell.interp.locals['editor'] = self.editor self.AddPage(page=self.editor, text='File', select=True) *************** *** 447,454 **** ! 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) --- 464,471 ---- ! class BufferNotebook(wx.wxNotebook): ! """A notebook containing a code editor and shell for each buffer.""" def __init__(self, parent): ! """Create a BufferNotebook instance.""" wx.wxNotebook.__init__(self, parent, id=-1) Index: PyAlaMode.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/PyAlaMode.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyAlaMode.py 2 Apr 2003 13:21:31 -0000 1.4 --- PyAlaMode.py 2 Apr 2003 19:04:58 -0000 1.5 *************** *** 12,16 **** import sys ! from editor import PythonEditorFrame try: --- 12,16 ---- import sys ! import editor try: *************** *** 29,34 **** def OnInit(self): wx.wxInitAllImageHandlers() ! self.frame = PythonEditorFrame() ! self.frame.FileOpen(self.filename) self.frame.Show() self.SetTopWindow(self.frame) --- 29,33 ---- def OnInit(self): wx.wxInitAllImageHandlers() ! self.frame = editor.EditorFrame(filename=self.filename) self.frame.Show() self.SetTopWindow(self.frame) *************** *** 40,44 **** if __name__ == '__main__': - sys.path.insert(0, os.curdir) filename = None if len(sys.argv) > 1: --- 39,42 ---- |