[PyCrust-cvs] PyCrust editor.py,1.20,1.21
Brought to you by:
pobrien
|
From: <po...@us...> - 2003-04-05 02:22:45
|
Update of /cvsroot/pycrust/PyCrust
In directory sc8-pr-cvs1:/tmp/cvs-serv22687
Modified Files:
editor.py
Log Message:
More familiar, one editor per tab interface. No shells at all.
Index: editor.py
===================================================================
RCS file: /cvsroot/pycrust/PyCrust/editor.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** editor.py 4 Apr 2003 23:20:25 -0000 1.20
--- editor.py 5 Apr 2003 02:22:41 -0000 1.21
***************
*** 212,215 ****
--- 212,314 ----
class EditorNotebookFrame(EditorFrame):
+ """Frame containing one or more editors in a notebook."""
+
+ def __init__(self, parent=None, id=-1, title='PyAlaMode',
+ pos=wx.wxDefaultPosition, size=(600, 400),
+ style=wx.wxDEFAULT_FRAME_STYLE, filename=None):
+ """Create an EditorNotebookFrame instance."""
+ EditorFrame.__init__(self, parent, id, title, pos,
+ size, style, filename)
+
+ def _setup(self):
+ """Setup prior to first buffer creation.
+
+ Useful for subclasses."""
+ self._notebook = BufferNotebook(parent=self)
+ dispatcher.connect(receiver=self._bufferChange,
+ signal='BufferChange', sender=self._notebook)
+
+ def _bufferChange(self, buffer):
+ """Buffer change signal receiver."""
+ self._buffer = buffer
+
+ 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)
+ dialog.ShowModal()
+ dialog.Destroy()
+
+ def _updateTitle(self):
+ """Show current title information."""
+ title = self.GetTitle()
+ if self.bufferHasChanged():
+ if title.startswith('* '):
+ pass
+ else:
+ self.SetTitle('* ' + title)
+ else:
+ if title.startswith('* '):
+ self.SetTitle(title[2:])
+
+ def bufferCreate(self, filename=None):
+ """Create new buffer."""
+ interp = interpreter.Interpreter(locals={})
+ editor = Editor(interp=interp, parent=self._notebook,
+ filename=filename)
+ self._buffer = editor.buffer
+ self._buffers[self._buffer.id] = self._buffer
+ self._notebook.AddPage(page=editor, text=self._buffer.name,
+ select=True)
+ self._buffer.editor.SetFocus()
+
+ def bufferDestroy(self):
+ """Destroy the current buffer."""
+ if self._buffer:
+ del self._buffers[self._buffer.id]
+ self._buffer = None # Do this before DeletePage().
+ selection = self._notebook.GetSelection()
+ print "Destroy Selection:", selection
+ self._notebook.DeletePage(selection)
+
+ def bufferNew(self):
+ """Create new buffer."""
+ self.bufferCreate()
+ cancel = False
+ return cancel
+
+ def bufferOpen(self):
+ """Open file in buffer."""
+ filedir = ''
+ if self._buffer and self._buffer.doc.filedir:
+ filedir = self._buffer.doc.filedir
+ result = openMultiple(directory=filedir)
+ for path in result.paths:
+ self.bufferCreate(path)
+ cancel = False
+ return cancel
+
+
+ class BufferNotebook(wx.wxNotebook):
+ """A notebook containing a page for each buffer."""
+
+ def __init__(self, parent):
+ """Create a BufferNotebook instance."""
+ wx.wxNotebook.__init__(self, parent, id=-1)
+ wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
+
+ def OnPageChanged(self, event):
+ """Page changed event handler."""
+ selection = event.GetSelection()
+ print "Changed To Selection:", selection
+ page = self.GetPage(selection)
+ buffer = page.buffer
+ buffer.editor.SetFocus()
+ dispatcher.send(signal='BufferChange', sender=self, buffer=buffer)
+
+
+ class BufferEditorShellNotebookFrame(EditorFrame):
"""Frame containing one or more editor notebooks."""
***************
*** 218,222 ****
style=wx.wxDEFAULT_FRAME_STYLE,
filename=None, singlefile=False):
! """Create an EditorNotebookFrame instance."""
self._singlefile = singlefile
EditorFrame.__init__(self, parent, id, title, pos,
--- 317,321 ----
style=wx.wxDEFAULT_FRAME_STYLE,
filename=None, singlefile=False):
! """Create a BufferEditorShellNotebookFrame instance."""
self._singlefile = singlefile
EditorFrame.__init__(self, parent, id, title, pos,
***************
*** 261,269 ****
if self._singlefile:
self.bufferDestroy()
! notebook = self._notebook = EditorNotebook(parent=self,
! filename=filename)
else:
! notebook = EditorNotebook(parent=self._notebook,
! filename=filename)
self._buffer = notebook.buffer
if not self._singlefile:
--- 360,368 ----
if self._singlefile:
self.bufferDestroy()
! notebook = self._notebook = EditorShellNotebook(parent=self,
! filename=filename)
else:
! notebook = EditorShellNotebook(parent=self._notebook,
! filename=filename)
self._buffer = notebook.buffer
if not self._singlefile:
***************
*** 317,325 ****
! class BufferNotebook(wx.wxNotebook):
"""A notebook containing a page for each buffer."""
def __init__(self, parent):
! """Create a BufferNotebook instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
--- 416,424 ----
! class BufferEditorShellNotebook(wx.wxNotebook):
"""A notebook containing a page for each buffer."""
def __init__(self, parent):
! """Create a BufferEditorShellNotebook instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
***************
*** 336,344 ****
! class EditorNotebook(wx.wxNotebook):
"""A notebook containing an editor page and a shell page."""
def __init__(self, parent, filename=None):
! """Create an EditorNotebook instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
usePanels = True
--- 435,443 ----
! class EditorShellNotebook(wx.wxNotebook):
"""A notebook containing an editor page and a shell page."""
def __init__(self, parent, filename=None):
! """Create an EditorShellNotebook instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
usePanels = True
|