[PyCrust-cvs] PyCrust editor.py,1.6,1.7
Brought to you by:
pobrien
|
From: <po...@us...> - 2003-04-01 16:48:29
|
Update of /cvsroot/pycrust/PyCrust
In directory sc8-pr-cvs1:/tmp/cvs-serv11189
Modified Files:
editor.py
Log Message:
Better handling of sys.path for namespace update.
Renamed path to filepath, other renaming.
Index: editor.py
===================================================================
RCS file: /cvsroot/pycrust/PyCrust/editor.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** editor.py 1 Apr 2003 06:43:05 -0000 1.6
--- editor.py 1 Apr 2003 16:48:24 -0000 1.7
***************
*** 1,3 ****
! """Code editor."""
__author__ = "Patrick K. O'Brien <po...@or...>"
--- 1,3 ----
! """PyAlaMode code editor."""
__author__ = "Patrick K. O'Brien <po...@or...>"
***************
*** 57,60 ****
--- 57,61 ----
def OnIdle(self, event):
+ """Event handler for idle time."""
self.updateStatusBar()
self.updateTitleBar()
***************
*** 67,71 ****
col = self.editor.GetColumn(pos) + 1
status = 'PyAlaMode | File: %s | Line: %d | Column: %d' % \
! (self.path, line, col)
if pos != self.lastPos and status != self.lastStatus:
self.SetStatusText(status)
--- 68,72 ----
col = self.editor.GetColumn(pos) + 1
status = 'PyAlaMode | File: %s | Line: %d | Column: %d' % \
! (self.filepath, line, col)
if pos != self.lastPos and status != self.lastStatus:
self.SetStatusText(status)
***************
*** 98,102 ****
return # XXX Prompt for filename.
self._setFileInfo(filename)
! self.editor.FileOpen(self.path)
self.SetTitle(self.filename)
--- 99,103 ----
return # XXX Prompt for filename.
self._setFileInfo(filename)
! self.editor.FileOpen(self.filepath)
self.SetTitle(self.filename)
***************
*** 111,115 ****
def FileSave(self):
"""Save file in editor."""
! self.editor.FileSave(self.path)
def FileSaveAs(self):
--- 112,116 ----
def FileSave(self):
"""Save file in editor."""
! self.editor.FileSave(self.filepath)
def FileSaveAs(self):
***************
*** 130,136 ****
def _setFileInfo(self, filename):
"""Set file information."""
! self.path = os.path.abspath(filename)
! self.dir, self.filename = os.path.split(self.path)
! self.modulename, self.extension = os.path.splitext(self.filename)
def updateNamespace(self):
--- 131,149 ----
def _setFileInfo(self, filename):
"""Set file information."""
! 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 sys.path:
! sys.path.insert(0, self.filedir)
! while True:
! try:
! sys.path.remove('')
! except ValueError:
! break
! while True:
! try:
! sys.path.remove('.')
! except ValueError:
! break
def updateNamespace(self):
***************
*** 139,142 ****
--- 152,156 ----
self.FileSave()
backup = self.interp.locals
+ modfile = None
try:
try:
***************
*** 164,191 ****
"""Create a PythonEditorNotebook instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
! ## 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)
! ## self.AddPage(page=self.shell, text='Shell')
! shellpanel = wx.wxPanel(self, -1)
! editorpanel = wx.wxPanel(self, -1)
! 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')
! # Setup sizers
! shellsizer = wx.wxBoxSizer(wx.wxVERTICAL)
! shellsizer.Add(self.shell, 1, wx.wxEXPAND)
! shellpanel.SetSizer(shellsizer)
! shellpanel.SetAutoLayout(True)
! editorsizer = wx.wxBoxSizer(wx.wxVERTICAL)
! editorsizer.Add(self.editor, 1, wx.wxEXPAND)
! editorpanel.SetSizer(editorsizer)
! editorpanel.SetAutoLayout(True)
# Set focus to the editor.
self.editor.SetFocus()
--- 178,208 ----
"""Create a PythonEditorNotebook instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
! usePanels = True
! if usePanels:
! shellpanel = wx.wxPanel(self, -1)
! editorpanel = wx.wxPanel(self, -1)
! 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')
! # Setup sizers
! shellsizer = wx.wxBoxSizer(wx.wxVERTICAL)
! shellsizer.Add(self.shell, 1, wx.wxEXPAND)
! shellpanel.SetSizer(shellsizer)
! shellpanel.SetAutoLayout(True)
! editorsizer = wx.wxBoxSizer(wx.wxVERTICAL)
! editorsizer.Add(self.editor, 1, wx.wxEXPAND)
! editorpanel.SetSizer(editorsizer)
! editorpanel.SetAutoLayout(True)
! else:
! 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)
! self.AddPage(page=self.shell, text='Shell')
# Set focus to the editor.
self.editor.SetFocus()
***************
*** 208,237 ****
wx.EVT_KEY_DOWN(self, self.OnKeyDown)
! def FileNew(self, path):
"""New file."""
! if not path:
return
! if os.path.exists(path):
! self.confirmed = self.FileOverwriteConfirm(path)
else:
self.confirmed = True
! def FileOpen(self, path):
"""Open file."""
! if not path:
return
! if os.path.exists(path):
! self.FileReadText(path)
self.confirmed = True
else:
! self.FileNew(path)
! def FileOverwriteConfirm(path):
"""Confirm overwriting an existing file."""
return False
! def FileReadText(self, path):
"""Replace text with contents of file."""
! f = file(path, 'rb')
try:
self.SetText(f.read())
--- 225,254 ----
wx.EVT_KEY_DOWN(self, self.OnKeyDown)
! def FileNew(self, filepath):
"""New file."""
! if not filepath:
return
! if os.path.exists(filepath):
! self.confirmed = self.FileOverwriteConfirm(filepath)
else:
self.confirmed = True
! def FileOpen(self, filepath):
"""Open file."""
! if not filepath:
return
! if os.path.exists(filepath):
! self.FileReadText(filepath)
self.confirmed = True
else:
! self.FileNew(filepath)
! def FileOverwriteConfirm(filepath):
"""Confirm overwriting an existing file."""
return False
! def FileReadText(self, filepath):
"""Replace text with contents of file."""
! f = file(filepath, 'rb')
try:
self.SetText(f.read())
***************
*** 240,258 ****
f.close()
! def FileSave(self, path):
"""Save file."""
! if not path:
return
! if not os.path.exists(path):
self.confirmed = True
if not self.confirmed:
! self.confirmed = self.FileOverwriteConfirm(path)
if self.confirmed:
! self.FileWriteText(path)
! def FileWriteText(self, path):
"""Write all text to file."""
try:
! f = file(path, 'w')
f.write(self.GetText())
self.SetSavePoint()
--- 257,275 ----
f.close()
! def FileSave(self, filepath):
"""Save file."""
! if not filepath:
return
! if not os.path.exists(filepath):
self.confirmed = True
if not self.confirmed:
! self.confirmed = self.FileOverwriteConfirm(filepath)
if self.confirmed:
! self.FileWriteText(filepath)
! def FileWriteText(self, filepath):
"""Write all text to file."""
try:
! f = file(filepath, 'w')
f.write(self.GetText())
self.SetSavePoint()
|