[PyCrust-cvs] PyCrust frame.py,1.1,1.2 editor.py,1.5,1.6 base.py,1.1,1.2 PyAlaMode.py,1.2,1.3
Brought to you by:
pobrien
|
From: <po...@us...> - 2003-04-01 06:43:09
|
Update of /cvsroot/pycrust/PyCrust
In directory sc8-pr-cvs1:/tmp/cvs-serv14333
Modified Files:
frame.py editor.py base.py PyAlaMode.py
Log Message:
Not feature complete, but close. Namespace update is working.
Index: frame.py
===================================================================
RCS file: /cvsroot/pycrust/PyCrust/frame.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** frame.py 29 Mar 2003 02:42:01 -0000 1.1
--- frame.py 1 Apr 2003 06:43:04 -0000 1.2
***************
*** 22,25 ****
--- 22,26 ----
ID_CALLTIPS_SHOW = wx.wxNewId()
ID_COPY_PLUS = wx.wxNewId()
+ ID_NAMESPACE = wx.wxNewId()
ID_PASTE_PLUS = wx.wxNewId()
ID_WRAP = wx.wxNewId()
***************
*** 49,52 ****
--- 50,73 ----
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()
+ m.Append(ID_NAMESPACE, '&Update Namespace \tShift+Ctrl+U',
+ 'Save file; update namespace for autocompletion and calltips')
m.AppendSeparator()
m.Append(wx.wxID_EXIT, 'E&xit', 'Exit Program')
***************
*** 62,69 ****
m.Append(wx.wxID_COPY, '&Copy \tCtrl+C',
'Copy the selection')
! m.Append(ID_COPY_PLUS, 'Cop&y Plus \tCtrl+Shift+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 \tCtrl+Shift+V',
'Paste and run commands')
m.AppendSeparator()
--- 83,90 ----
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()
***************
*** 107,110 ****
--- 128,139 ----
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)
***************
*** 130,133 ****
--- 159,170 ----
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)
***************
*** 146,149 ****
--- 183,210 ----
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):
+ self.updateNamespace()
+
+ def OnFilePrint(self, event):
+ self.FilePrint()
+
def OnExit(self, event):
self.Close(True)
***************
*** 224,228 ****
event.Enable(True)
try:
! if id == wx.wxID_UNDO:
event.Enable(win.CanUndo())
elif id == wx.wxID_REDO:
--- 285,305 ----
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.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:
***************
*** 254,257 ****
--- 331,336 ----
elif id == ID_WRAP:
event.Check(win.GetWrapMode())
+ else:
+ event.Enable(False)
except AttributeError:
# object with keyboard focus doesn't support this menu option.
Index: editor.py
===================================================================
RCS file: /cvsroot/pycrust/PyCrust/editor.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** editor.py 29 Mar 2003 02:42:02 -0000 1.5
--- editor.py 1 Apr 2003 06:43:05 -0000 1.6
***************
*** 7,10 ****
--- 7,15 ----
from wxPython import wx
+ import imp
+ import os
+ import sys
+ import time
+
import base
import dispatcher
***************
*** 19,32 ****
! class EditorFrame(frame.Frame):
! """Frame containing the editor component."""
def __init__(self, parent=None, id=-1, title='PyAlaMode',
! pos=wx.wxDefaultPosition, size=(700, 500),
style=wx.wxDEFAULT_FRAME_STYLE):
"""Create an EditorFrame instance."""
frame.Frame.__init__(self, parent, id, title, pos, size, style)
self.SetStatusText(title + ' - the tastiest Python editor.')
! self.python = PythonEditor(parent=self)
def OnAbout(self, event):
--- 24,43 ----
! class PythonEditorFrame(frame.Frame):
! """Frame containing the Python editor notebook component."""
def __init__(self, parent=None, id=-1, title='PyAlaMode',
! pos=wx.wxDefaultPosition, size=(600, 400),
style=wx.wxDEFAULT_FRAME_STYLE):
"""Create an EditorFrame instance."""
frame.Frame.__init__(self, parent, id, title, pos, size, style)
self.SetStatusText(title + ' - the tastiest Python editor.')
! self.notebook = PythonEditorNotebook(parent=self)
! self.shell = self.notebook.shell
! self.editor = self.notebook.editor
! self.interp = self.shell.interp
! self.lastPos = None
! self.lastStatus = ''
! wx.EVT_IDLE(self, self.OnIdle)
def OnAbout(self, event):
***************
*** 41,72 ****
def OnCloseWindow(self, event):
"""Event handler for closing."""
self.Destroy()
! def FileOpen(self, filename):
"""Open file in editor."""
! self.python.editor.FileOpen(filename)
! class PythonEditor(wx.wxNotebook):
! """PythonEditor class combines an editor with a shell."""
def __init__(self, parent):
! """Create a PythonEditor instance."""
wx.wxNotebook.__init__(self, parent, id=-1)
! self.shell = Shell(parent=self)
! self.editor = Editor(interp=self.shell.interp, parent=self)
! self.AddPage(page=self.editor, text='File', select=True)
! self.AddPage(page=self.shell, text='Shell')
# Set focus to the editor.
self.editor.SetFocus()
! class Editor(base.Editor):
"""Editor based on StyledTextCtrl."""
def __init__(self, interp, parent, id=-1, pos=wx.wxDefaultPosition,
! size=wx.wxDefaultSize, style=wx.wxCLIP_CHILDREN):
! """Create an Editor instance."""
base.Editor.__init__(self, parent, id, pos, size, style)
self.interp = interp
# Find out for which keycodes the interpreter will autocomplete.
--- 52,204 ----
def OnCloseWindow(self, event):
"""Event handler for closing."""
+ if self.editor.GetModify():
+ self.FileSuggestSave()
self.Destroy()
! def OnIdle(self, event):
! self.updateStatusBar()
! self.updateTitleBar()
! time.sleep(0.05)
! event.Skip()
!
! def updateStatusBar(self):
! pos = self.editor.GetCurrentPos()
! line = self.editor.LineFromPosition(pos) + 1
! 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)
! self.lastPos = pos
! self.lastStatus = status
!
! def updateTitleBar(self):
! title = self.GetTitle()
! modified = self.editor.GetModify()
! if modified and title[0] != '*':
! self.SetTitle('* ' + title + ' *')
! elif not modified and title[0] == '*':
! self.SetTitle(title[2:-2])
!
! def FileClose(self):
! """Close file in editor."""
! if self.editor.GetModify():
! self.FileSuggestSave()
!
! def FileNew(self):
! """Create new file in editor."""
! if self.editor.GetModify():
! self.FileSuggestSave()
!
! def FileOpen(self, filename=None):
"""Open file in editor."""
! if self.editor.GetModify():
! self.FileSuggestSave()
! if filename is None:
! return # XXX Prompt for filename.
! self._setFileInfo(filename)
! self.editor.FileOpen(self.path)
! self.SetTitle(self.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.editor.FileSave(self.path)
!
! def FileSaveAs(self):
! """Save file in editor with new name."""
! if self.editor.GetModify():
! self.FileSuggestSave()
! # Get new name
! filename = '' # XXX
! self._setFileInfo(filename)
! self.FileSave()
!
! def FileSuggestSave(self):
! """Suggest saving changes."""
! confirm = True
! if confirm:
! self.FileSave()
!
! 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):
! """Update the namespace for autocompletion and calltips."""
! if self.editor.GetModify():
! self.FileSave()
! backup = self.interp.locals
! try:
! try:
! modfile, path, descr = imp.find_module(self.modulename)
! module = imp.load_module(self.modulename, modfile, path, descr)
! except:
! self.interp.locals = backup
! self.SetStatusText('Error importing file, unable to update namespace')
! else:
! self.interp.locals = module.__dict__.copy()
! self.SetStatusText('Namespace updated')
! finally:
! if modfile:
! modfile.close()
! try:
! del sys.modules[self.modulename]
! except KeyError:
! pass
!
!
! 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)
! ## 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()
! class PythonEditor(base.Editor):
"""Editor based on StyledTextCtrl."""
def __init__(self, interp, parent, id=-1, pos=wx.wxDefaultPosition,
! 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
self.interp = interp
# Find out for which keycodes the interpreter will autocomplete.
***************
*** 76,86 ****
wx.EVT_KEY_DOWN(self, self.OnKeyDown)
! def FileOpen(self, filename):
"""Open file."""
! if not filename:
return
! f = file(filename, 'rb')
try:
self.SetText(f.read())
finally:
f.close()
--- 208,260 ----
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())
+ self.EmptyUndoBuffer()
+ finally:
+ 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()
finally:
f.close()
***************
*** 95,108 ****
if key in self.autoCompleteKeys:
# Usually the dot (period) key activates auto completion.
- # Get the command between the prompt and the cursor. Add
- # the autocomplete character to the end of the command.
if self.AutoCompActive():
self.AutoCompCancel()
text, pos = self.GetCurLine()
text = text[:pos]
- command = text + chr(key)
- self.AddText(chr(key))
if self.autoComplete:
! self.autoCompleteShow(command)
elif key == ord('('):
# The left paren activates a call tip and cancels an
--- 269,280 ----
if key in self.autoCompleteKeys:
# Usually the dot (period) key activates auto completion.
if self.AutoCompActive():
self.AutoCompCancel()
+ self.ReplaceSelection('')
+ self.AddText(chr(key))
text, pos = self.GetCurLine()
text = text[:pos]
if self.autoComplete:
! self.autoCompleteShow(text)
elif key == ord('('):
# The left paren activates a call tip and cancels an
***************
*** 110,122 ****
if self.AutoCompActive():
self.AutoCompCancel()
- # Get the command between the prompt and the cursor. Add
- # the '(' to the end of the command.
self.ReplaceSelection('')
text, pos = self.GetCurLine()
text = text[:pos]
! command = text + '('
! self.AddText('(')
! if self.autoCallTip:
! self.autoCallTipShow(command)
else:
# Allow the normal event handling to take place.
--- 282,290 ----
if self.AutoCompActive():
self.AutoCompCancel()
self.ReplaceSelection('')
+ self.AddText('(')
text, pos = self.GetCurLine()
text = text[:pos]
! self.autoCallTipShow(text)
else:
# Allow the normal event handling to take place.
***************
*** 165,168 ****
--- 333,340 ----
self.CallTipCancel()
(name, argspec, tip) = self.interp.getCallTip(command)
+ if tip:
+ dispatcher.send(signal='Shell.calltip', sender=self, calltip=tip)
+ if not self.autoCallTip:
+ return
if argspec:
startpos = self.GetCurrentPos()
***************
*** 172,180 ****
if tip:
curpos = self.GetCurrentPos()
! tippos = curpos - (len(name) + 1)
fallback = curpos - self.GetColumn(curpos)
# In case there isn't enough room, only go back to the
# fallback.
tippos = max(tippos, fallback)
- dispatcher.send(signal='Shell.calltip', sender=self, calltip=tip)
self.CallTipShow(tippos, tip)
--- 344,353 ----
if tip:
curpos = self.GetCurrentPos()
! size = len(name)
! tippos = curpos - (size + 1)
fallback = curpos - self.GetColumn(curpos)
# In case there isn't enough room, only go back to the
# fallback.
tippos = max(tippos, fallback)
self.CallTipShow(tippos, tip)
+ self.CallTipSetHighlight(0, size)
Index: base.py
===================================================================
RCS file: /cvsroot/pycrust/PyCrust/base.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** base.py 29 Mar 2003 02:42:04 -0000 1.1
--- base.py 1 Apr 2003 06:43:05 -0000 1.2
***************
*** 49,53 ****
def __init__(self, parent, id=-1, pos=wx.wxDefaultPosition,
! size=wx.wxDefaultSize, style=wx.wxCLIP_CHILDREN):
"""Create an Editor instance."""
stc.wxStyledTextCtrl.__init__(self, parent, id, pos, size, style)
--- 49,53 ----
def __init__(self, parent, id=-1, pos=wx.wxDefaultPosition,
! size=wx.wxDefaultSize, style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER):
"""Create an Editor instance."""
stc.wxStyledTextCtrl.__init__(self, parent, id, pos, size, style)
***************
*** 196,226 ****
"""Return true if editing should succeed."""
return True
-
- ## def Cut(self):
- ## """Remove selection and place it on the clipboard."""
- ## if self.CanCut() and self.CanCopy():
- ## if self.AutoCompActive():
- ## self.AutoCompCancel()
- ## if self.CallTipActive():
- ## self.CallTipCancel()
- ## self.Copy()
- ## self.ReplaceSelection('')
-
- ## def Copy(self):
- ## """Copy selection and place it on the clipboard."""
- ## if self.CanCopy():
- ## ps1 = str(sys.ps1)
- ## ps2 = str(sys.ps2)
- ## command = self.GetSelectedText()
- ## command = command.replace(os.linesep + ps2, os.linesep)
- ## command = command.replace(os.linesep + ps1, os.linesep)
- ## command = self.lstripPrompt(text=command)
- ## data = wx.wxTextDataObject(command)
- ## self._clip(data)
-
- ## def _clip(self, data):
- ## if wx.wxTheClipboard.Open():
- ## wx.wxTheClipboard.UsePrimarySelection(False)
- ## wx.wxTheClipboard.SetData(data)
- ## wx.wxTheClipboard.Flush()
- ## wx.wxTheClipboard.Close()
--- 196,197 ----
Index: PyAlaMode.py
===================================================================
RCS file: /cvsroot/pycrust/PyCrust/PyAlaMode.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PyAlaMode.py 29 Mar 2003 05:10:12 -0000 1.2
--- PyAlaMode.py 1 Apr 2003 06:43:05 -0000 1.3
***************
*** 11,15 ****
import wx
! from editor import EditorFrame
try:
--- 11,15 ----
import wx
! from editor import PythonEditorFrame
try:
***************
*** 28,32 ****
def OnInit(self):
wx.InitAllImageHandlers()
! self.frame = EditorFrame()
self.frame.FileOpen(self.filename)
self.frame.Show()
--- 28,32 ----
def OnInit(self):
wx.InitAllImageHandlers()
! self.frame = PythonEditorFrame()
self.frame.FileOpen(self.filename)
self.frame.Show()
|