pycrust-cvs Mailing List for PyCrust (Page 2)
Brought to you by:
pobrien
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
(49) |
Apr
(45) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <po...@us...> - 2003-04-04 15:25:25
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv17086 Added Files: PyWrap.py PyShell.py PyFilling.py PyCrust.py MANUAL.txt Log Message: Renamed files. --- NEW FILE: PyWrap.py --- #!/usr/bin/env python """PyWrap is a command line utility that runs a wxPython program with additional runtime-tools, such as PyCrust.""" __author__ = "Patrick K. O'Brien <po...@or...>" __cvsid__ = "$Id: PyWrap.py,v 1.1 2003/04/04 15:25:05 pobrien Exp $" __revision__ = "$Revision: 1.1 $"[11:-2] import os import sys from wxPython import wx from crust import CrustFrame as Frame try: True except NameError: True = 1==1 False = 1==0 def wrap(app): wx.wxInitAllImageHandlers() frame = Frame() frame.SetSize((750, 525)) frame.Show(True) frame.shell.interp.locals['app'] = app app.MainLoop() def main(argv): if len(argv) < 2: print "Please specify a module name." raise SystemExit name = argv[1] if name[-3:] == '.py': name = name[:-3] module = __import__(name) # Find the App class. App = None d = module.__dict__ for item in d.keys(): try: if issubclass(d[item], wx.wxApp): App = d[item] except (NameError, TypeError): pass if App is None: print "No App class found." raise SystemExit app = App() wrap(app) if __name__ == '__main__': sys.path.insert(0, os.curdir) main(sys.argv) --- NEW FILE: MANUAL.txt --- =============== The Py Manual =============== ------------------------- Py - Served Fresh Daily ------------------------- :Author: Patrick K. O'Brien :Contact: po...@or... :Date: $Date: 2003/04/04 15:25:14 $ :Revision: $Revision: 1.1 $ .. contents:: Introduction ============ This document will show you how to make use of the Py programs and library of modules. What is Py? =========== Py is really several things. Py is a set of standalone programs as well as a library of modules that you can use in your own programs. First, Py contains standalone programs that provide code editors and graphical, Python shell interfaces. Second, Py contains a collections of modules that you can use in your own wxPython applications to provide similar services, either for your own use during development, or as an interface for users of your program. Third, Py containss a wrapper utility, providing you with runtime introspection capabilities for your wxPython programs without having to include PyCrust or PyShell in your program, or alter one line of your code. Py standalone programs ====================== There are several standalone applications in the Py package: * PyAlaCarte * PyAlaMode * PyCrust * PyFilling * PyShell * PyWrap Py modules ========== Py was designed to be modular. That means graphical code is kept separate from non-graphical code, and many of the Py modules can be used by other programs. Likewise, other programs can supply some of the modules needed by Py. For example, you could supply a customized interpreter module and plug it in to the PyCrust standalone application. As long as it supports the minimum functionality required, PyCrust will work just as well with your interpreter as with its default interpreter. Py runtime wrapper ================== The Py wrapper utility (``PyWrap.py``) lets you run an existing wxPython program with a PyCrust frame at the same time. Inside the PyCrust shell, the local variable ``app`` is assigned to your application instance. In this way you can introspect your entire application within the PyCrust shell and the PyCrust namespace viewer. And through the use of the PyCrust decorator classes, PyCrust can display wxPython function and method signatures as well as docstrings for the entire wxPython library. |
From: <po...@us...> - 2003-04-04 14:42:05
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv32300 Removed Files: setup.py MANIFEST.in Log Message: Old files. --- setup.py DELETED --- --- MANIFEST.in DELETED --- |
From: <po...@us...> - 2003-04-04 14:37:41
|
Update of /cvsroot/pycrust/PyCrust/Data In directory sc8-pr-cvs1:/tmp/cvs-serv30610/Data Removed Files: PythonTutorial.py PyCrustTutorial.py Log Message: Old files. --- PythonTutorial.py DELETED --- --- PyCrustTutorial.py DELETED --- |
From: <po...@us...> - 2003-04-04 14:37:38
|
Update of /cvsroot/pycrust/PyCrust/Demos In directory sc8-pr-cvs1:/tmp/cvs-serv30610/Demos Removed Files: PyCrustMinimus.py PyCrustAlaMode.py PyCrustAlaCarte.py Log Message: Old files. --- PyCrustMinimus.py DELETED --- --- PyCrustAlaMode.py DELETED --- --- PyCrustAlaCarte.py DELETED --- |
From: <po...@us...> - 2003-04-03 15:57:18
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv2507 Modified Files: CHANGES.txt Log Message: Updated. Index: CHANGES.txt =================================================================== RCS file: /cvsroot/pycrust/PyCrust/CHANGES.txt,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** CHANGES.txt 29 Mar 2003 02:42:04 -0000 1.30 --- CHANGES.txt 3 Apr 2003 15:57:12 -0000 1.31 *************** *** 25,29 **** * examples.txt (in wx/examples) ! Added PyAlaMode.py code editor. Major refactoring to support editor and shell from the same base. --- 25,29 ---- * examples.txt (in wx/examples) ! Added PyAlaMode.py and PyAlaCarte code editors. Major refactoring to support editor and shell from the same base. |
From: <po...@us...> - 2003-04-03 02:35:05
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv16207 Modified Files: editor.py Added Files: document.py buffer.py Log Message: Restructured files. --- NEW FILE: document.py --- """Document class.""" __author__ = "Patrick K. O'Brien <po...@or...>" __cvsid__ = "$Id: document.py,v 1.1 2003/04/03 02:34:48 pobrien Exp $" __revision__ = "$Revision: 1.1 $"[11:-2] import os try: True except NameError: True = 1==1 False = 1==0 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() --- NEW FILE: buffer.py --- """Buffer class.""" __author__ = "Patrick K. O'Brien <po...@or...>" __cvsid__ = "$Id: buffer.py,v 1.1 2003/04/03 02:34:48 pobrien Exp $" __revision__ = "$Revision: 1.1 $"[11:-2] from wxPython import wx import imp import os import sys import document try: True except NameError: True = 1==1 False = 1==0 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 = '' self.editor = editor self.interp = interp self.modules = sys.modules.keys() self.syspath = sys.path[:] while True: try: self.syspath.remove('') except ValueError: break while True: try: self.syspath.remove('.') except ValueError: break self.open(filename) 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 def hasChanged(self): """Return True if text in editor has changed since last save.""" return self.editor.GetModify() def new(self, filepath): """New empty buffer.""" if not filepath: return if os.path.exists(filepath): self.confirmed = self.overwriteConfirm(filepath) else: self.confirmed = True def open(self, filename): """Open file into buffer.""" self.doc = document.Document(filename) self.name = self.doc.filename or ('Untitled:' + str(self.id)) 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): """Confirm overwriting an existing file.""" 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 if not self.confirmed: self.confirmed = self.overwriteConfirm(filepath) if self.confirmed: self.doc.write(self.editor.GetText()) self.editor.SetSavePoint() 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(str(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] Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** editor.py 3 Apr 2003 01:28:52 -0000 1.13 --- editor.py 3 Apr 2003 02:34:48 -0000 1.14 *************** *** 1,3 **** ! """PyAlaMode code editor.""" __author__ = "Patrick K. O'Brien <po...@or...>" --- 1,3 ---- ! """PyAlaMode editor.""" __author__ = "Patrick K. O'Brien <po...@or...>" *************** *** 7,19 **** from wxPython import wx - import imp - import os - import sys - import time - import base import dispatcher import frame ! from shell import Shell try: --- 7,15 ---- from wxPython import wx import base + import buffer import dispatcher import frame ! import shell try: *************** *** 177,182 **** class EditorNotebook(wx.wxNotebook): ! """Combines a code editor with a shell.""" def __init__(self, parent, filename=None): --- 173,196 ---- + 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() + page = self.GetPage(selection) + buffer = page.buffer + dispatcher.send(signal='BufferChange', sender=self, buffer=buffer) + selection = page.GetSelection() + page.focus(selection) + + class EditorNotebook(wx.wxNotebook): ! """A notebook containing an editor page and a shell page.""" def __init__(self, parent, filename=None): *************** *** 190,195 **** shellparent = self editorparent = self ! self.shell = Shell(parent=shellparent, ! style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) self.editor = Editor(interp=self.shell.interp, parent=editorparent, filename=filename) --- 204,209 ---- shellparent = self editorparent = self ! self.shell = shell.Shell(parent=shellparent, ! style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) self.editor = Editor(interp=self.shell.interp, parent=editorparent, filename=filename) *************** *** 241,246 **** wx.EVT_CHAR(self, self.OnChar) wx.EVT_KEY_DOWN(self, self.OnKeyDown) ! self.buffer = Buffer(editor=self, interp=self.interp, ! filename=filename) def OnChar(self, event): --- 255,260 ---- wx.EVT_CHAR(self, self.OnChar) wx.EVT_KEY_DOWN(self, self.OnKeyDown) ! self.buffer = buffer.Buffer(editor=self, interp=self.interp, ! filename=filename) def OnChar(self, event): *************** *** 336,491 **** self.CallTipShow(tippos, tip) self.CallTipSetHighlight(0, size) - - - 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) - wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged) - - def OnPageChanged(self, event): - """Page changed event handler.""" - selection = event.GetSelection() - notebook = self.GetPage(selection) - buffer = notebook.buffer - dispatcher.send(signal='BufferChange', sender=self, buffer=buffer) - selection = notebook.GetSelection() - notebook.focus(selection) - - - 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 = '' - self.editor = editor - self.interp = interp - self.modules = sys.modules.keys() - self.syspath = sys.path[:] - while True: - try: - self.syspath.remove('') - except ValueError: - break - while True: - try: - self.syspath.remove('.') - except ValueError: - break - self.open(filename) - - 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 - - def hasChanged(self): - """Return True if text in editor has changed since last save.""" - return self.editor.GetModify() - - def new(self, filepath): - """New empty buffer.""" - if not filepath: - return - if os.path.exists(filepath): - self.confirmed = self.overwriteConfirm(filepath) - else: - self.confirmed = True - - def open(self, filename): - """Open file into buffer.""" - self.doc = Document(filename) - self.name = self.doc.filename or ('Untitled:' + str(self.id)) - 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): - """Confirm overwriting an existing file.""" - 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 - if not self.confirmed: - self.confirmed = self.overwriteConfirm(filepath) - if self.confirmed: - self.doc.write(self.editor.GetText()) - self.editor.SetSavePoint() - - 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(str(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] - - - 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() --- 350,351 ---- |
From: <po...@us...> - 2003-04-03 01:28:56
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv6300 Modified Files: editor.py Log Message: Changed buffer naming. Removed old version of namespace update. Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** editor.py 2 Apr 2003 23:16:22 -0000 1.12 --- editor.py 3 Apr 2003 01:28:52 -0000 1.13 *************** *** 365,369 **** Buffer.id += 1 self.id = Buffer.id ! self.name = 'Buffer' self.editor = editor self.interp = interp --- 365,369 ---- Buffer.id += 1 self.id = Buffer.id ! self.name = '' self.editor = editor self.interp = interp *************** *** 407,411 **** """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): --- 407,411 ---- """Open file into buffer.""" self.doc = Document(filename) ! self.name = self.doc.filename or ('Untitled:' + str(self.id)) self.modulename = self.doc.filebase if self.doc.filepath and os.path.exists(self.doc.filepath): *************** *** 432,463 **** self.doc.write(self.editor.GetText()) self.editor.SetSavePoint() - - ## 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): --- 432,435 ---- |
From: <po...@us...> - 2003-04-02 23:16:26
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv24343 Modified Files: editor.py Log Message: More changes. Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** editor.py 2 Apr 2003 19:04:58 -0000 1.11 --- editor.py 2 Apr 2003 23:16:22 -0000 1.12 *************** *** 39,57 **** 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): --- 39,52 ---- self._statusText = title + ' - the tastiest Python editor.' self.SetStatusText(self._statusText) wx.EVT_IDLE(self, self.OnIdle) ! if not self._singlefile: ! self._notebook = BufferNotebook(parent=self) ! dispatcher.connect(receiver=self._bufferChange, ! signal='BufferChange', sender=self._notebook) ! self.bufferCreate(filename) ! ! def _bufferChange(self, buffer): ! """Buffer change signal receiver.""" ! self._buffer = buffer def OnAbout(self, event): *************** *** 103,123 **** 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): --- 98,145 ---- self.bufferSuggestSave() + def bufferCreate(self, filename=None): + """Create new buffer.""" + 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: + self._notebook.AddPage(page=notebook, text=self._buffer.name, + select=True) + self._buffers[self._buffer.id] = self._buffer + self._buffer.editor.SetFocus() + + def bufferDestroy(self): + """Destroy the current buffer.""" + if self._singlefile: + self._notebook = None + if self._buffer: + del self._buffers[self._buffer.id] + self._buffer = None + def bufferHasChanged(self): """Return True if buffer has changed since last save.""" ! if self._buffer: ! return self._buffer.hasChanged() ! else: ! return False def bufferNew(self): """Create new buffer.""" ! if self._singlefile and self.bufferHasChanged(): self.bufferSuggestSave() + self.bufferCreate() ! def bufferOpen(self): """Open file in buffer.""" ! if self._singlefile and self.bufferHasChanged(): self.bufferSuggestSave() ! # XXX Prompt for filename. if filename: ! self.bufferCreate(filename) def bufferPrint(self): *************** *** 155,320 **** ! 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[:] ! while True: ! try: ! self.syspath.remove('') ! except ValueError: ! break ! while True: ! try: ! self.syspath.remove('.') ! except ValueError: ! break ! self.open(filename) ! ! ## 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 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. ! ! 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): ! """New empty buffer.""" ! if not filepath: ! return ! if os.path.exists(filepath): ! self.confirmed = self.overwriteConfirm(filepath) else: ! self.confirmed = True ! ! 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): ! """Confirm overwriting an existing file.""" ! 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 ! if not self.confirmed: ! 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() --- 177,226 ---- ! class EditorNotebook(wx.wxNotebook): ! """Combines a code editor with a shell.""" ! def __init__(self, parent, filename=None): ! """Create an EditorNotebook instance.""" ! wx.wxNotebook.__init__(self, parent, id=-1) ! usePanels = True ! if usePanels: ! shellparent = shellpanel = wx.wxPanel(self, -1) ! editorparent = editorpanel = wx.wxPanel(self, -1) else: ! shellparent = self ! editorparent = self ! self.shell = Shell(parent=shellparent, ! style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER) ! self.editor = Editor(interp=self.shell.interp, parent=editorparent, ! filename=filename) ! if usePanels: ! 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.AddPage(page=self.editor, text='File', select=True) ! self.AddPage(page=self.shell, text='Shell') ! self.buffer = self.editor.buffer ! self.editor.SetFocus() ! wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged) ! def OnPageChanged(self, event): ! """Page changed event handler.""" ! selection = event.GetSelection() ! self.focus(selection) ! def focus(self, selection): ! if selection == 0: ! self.editor.SetFocus() ! else: ! self.shell.SetFocus() *************** *** 324,328 **** def __init__(self, interp, parent, id=-1, pos=wx.wxDefaultPosition, size=wx.wxDefaultSize, ! style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER): """Create a Editor instance.""" base.Editor.__init__(self, parent, id, pos, size, style) --- 230,235 ---- def __init__(self, interp, parent, id=-1, pos=wx.wxDefaultPosition, size=wx.wxDefaultSize, ! style=wx.wxCLIP_CHILDREN | wx.wxSUNKEN_BORDER, ! filename=None): """Create a Editor instance.""" base.Editor.__init__(self, parent, id, pos, size, style) *************** *** 334,337 **** --- 241,246 ---- wx.EVT_CHAR(self, self.OnChar) wx.EVT_KEY_DOWN(self, self.OnKeyDown) + self.buffer = Buffer(editor=self, interp=self.interp, + filename=filename) def OnChar(self, event): *************** *** 429,471 **** ! 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 ! 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 = Editor(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 = Editor(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() ! 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) --- 338,519 ---- ! 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) ! wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged) ! ! def OnPageChanged(self, event): ! """Page changed event handler.""" ! selection = event.GetSelection() ! notebook = self.GetPage(selection) ! buffer = notebook.buffer ! dispatcher.send(signal='BufferChange', sender=self, buffer=buffer) ! selection = notebook.GetSelection() ! notebook.focus(selection) ! ! ! 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[:] ! while True: ! try: ! self.syspath.remove('') ! except ValueError: ! break ! while True: ! try: ! self.syspath.remove('.') ! except ValueError: ! break ! self.open(filename) ! ! 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 ! ! def hasChanged(self): ! """Return True if text in editor has changed since last save.""" ! return self.editor.GetModify() ! ! def new(self, filepath): ! """New empty buffer.""" ! if not filepath: ! return ! if os.path.exists(filepath): ! self.confirmed = self.overwriteConfirm(filepath) else: ! self.confirmed = True + 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): ! """Confirm overwriting an existing file.""" ! 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 ! if not self.confirmed: ! self.confirmed = self.overwriteConfirm(filepath) ! if self.confirmed: ! self.doc.write(self.editor.GetText()) ! self.editor.SetSavePoint() ! ! ## 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(str(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] ! ! ! 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() |
From: <po...@us...> - 2003-04-02 20:36:25
|
Update of /cvsroot/pycrust/PyCrust/wxd In directory sc8-pr-cvs1:/tmp/cvs-serv23511 Modified Files: Controls.py Log Message: Fix dup page keyword. Index: Controls.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/wxd/Controls.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Controls.py 2 Apr 2003 20:19:40 -0000 1.4 --- Controls.py 2 Apr 2003 20:36:17 -0000 1.5 *************** *** 1180,1184 **** pass ! def InsertPage(self, page, page, text, select=False, imageId=-1): """""" pass --- 1180,1184 ---- pass ! def InsertPage(self, index, page, text, select=False, imageId=-1): """""" pass |
From: <po...@us...> - 2003-04-02 20:19:47
|
Update of /cvsroot/pycrust/PyCrust/wxd In directory sc8-pr-cvs1:/tmp/cvs-serv15355 Modified Files: Controls.py Log Message: Updated Notebook sigs. Index: Controls.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/wxd/Controls.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Controls.py 17 Mar 2003 03:56:35 -0000 1.3 --- Controls.py 2 Apr 2003 20:19:40 -0000 1.4 *************** *** 1127,1135 **** pass ! def AddPage(self, pPage, strText, bSelect=False, imageId=-1): """""" pass ! def AdvanceSelection(self, bForward=True): """""" pass --- 1127,1135 ---- pass ! def AddPage(self, page, text, select=False, imageId=-1): """""" pass ! def AdvanceSelection(self, forward=True): """""" pass *************** *** 1148,1152 **** pass ! def DeletePage(self, nPage): """""" pass --- 1148,1152 ---- pass ! def DeletePage(self, page): """""" pass *************** *** 1156,1160 **** pass ! def GetPage(self, nPage): """""" pass --- 1156,1160 ---- pass ! def GetPage(self, page): """""" pass *************** *** 1164,1172 **** pass ! def GetPageImage(self, nPage): """""" pass ! def GetPageText(self, nPage): """""" pass --- 1164,1172 ---- pass ! def GetPageImage(self, page): """""" pass ! def GetPageText(self, page): """""" pass *************** *** 1180,1188 **** pass ! def InsertPage(self, nPage, pPage, strText, bSelect=False, imageId=-1): """""" pass ! def RemovePage(self, nPage): """""" pass --- 1180,1188 ---- pass ! def InsertPage(self, page, page, text, select=False, imageId=-1): """""" pass ! def RemovePage(self, page): """""" pass *************** *** 1200,1204 **** pass ! def SetPageImage(self, nPage, nImage): """""" pass --- 1200,1204 ---- pass ! def SetPageImage(self, page, image): """""" pass *************** *** 1208,1216 **** pass ! def SetPageText(self, nPage, strText): """""" pass ! def SetSelection(self, nPage): """""" pass --- 1208,1216 ---- pass ! def SetPageText(self, page, text): """""" pass ! def SetSelection(self, page): """""" pass |
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 ---- |
From: <po...@us...> - 2003-04-02 13:21:35
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv8196 Modified Files: PyAlaMode.py Log Message: Use old wxPython syntax for now. Index: PyAlaMode.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/PyAlaMode.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyAlaMode.py 1 Apr 2003 06:43:05 -0000 1.3 --- PyAlaMode.py 2 Apr 2003 13:21:31 -0000 1.4 *************** *** 7,13 **** __revision__ = "$Revision$"[11:-2] import os import sys - import wx from editor import PythonEditorFrame --- 7,14 ---- __revision__ = "$Revision$"[11:-2] + from wxPython import wx + import os import sys from editor import PythonEditorFrame *************** *** 19,31 **** False = 1==0 ! class App(wx.App): """PyAlaMode standalone application.""" def __init__(self, filename=None): self.filename = filename ! wx.App.__init__(self, redirect=False) def OnInit(self): ! wx.InitAllImageHandlers() self.frame = PythonEditorFrame() self.frame.FileOpen(self.filename) --- 20,32 ---- False = 1==0 ! class App(wx.wxApp): """PyAlaMode standalone application.""" def __init__(self, filename=None): self.filename = filename ! wx.wxApp.__init__(self, redirect=False) def OnInit(self): ! wx.wxInitAllImageHandlers() self.frame = PythonEditorFrame() self.frame.FileOpen(self.filename) |
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) |
From: <po...@us...> - 2003-04-02 04:30:38
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv7386 Modified Files: frame.py Log Message: No longer saving file. Index: frame.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/frame.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** frame.py 1 Apr 2003 20:05:03 -0000 1.4 --- frame.py 2 Apr 2003 04:30:32 -0000 1.5 *************** *** 69,73 **** m.AppendSeparator() m.Append(ID_NAMESPACE, '&Update Namespace \tShift+Ctrl+N', ! 'Save file; update namespace for autocompletion and calltips') m.AppendSeparator() m.Append(wx.wxID_EXIT, 'E&xit', 'Exit Program') --- 69,73 ---- m.AppendSeparator() m.Append(ID_NAMESPACE, '&Update Namespace \tShift+Ctrl+N', ! 'Update namespace for autocompletion and calltips') m.AppendSeparator() m.Append(wx.wxID_EXIT, 'E&xit', 'Exit Program') |
From: <po...@us...> - 2003-04-01 23:20:36
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv21364 Modified Files: editor.py Log Message: Better namespace updating. Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** editor.py 1 Apr 2003 20:05:08 -0000 1.8 --- editor.py 1 Apr 2003 23:20:33 -0000 1.9 *************** *** 156,160 **** self.modulename = '' self.syspath = sys.path[:] - self.sysmodules = sys.modules.copy() while True: try: --- 156,159 ---- *************** *** 183,194 **** """Update the namespace for autocompletion and calltips. ! Return False if there was an error.""" if self.editor.GetModify(): self.save() backup = self.interp.locals ! modfile = None try: try: - modfile, path, descr = imp.find_module(self.modulename) module = imp.load_module(self.modulename, modfile, path, descr) except: --- 182,198 ---- """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: *************** *** 196,208 **** return False else: ! self.interp.locals = module.__dict__.copy() return True finally: if modfile: modfile.close() - try: - del sys.modules[self.modulename] - except KeyError: - pass def new(self, filepath): --- 200,209 ---- return False else: ! self.interp.locals = module.__dict__ return True finally: + sys.path = syspath if modfile: modfile.close() def new(self, filepath): |
From: <po...@us...> - 2003-04-01 20:05:20
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv1763 Modified Files: frame.py editor.py base.py Log Message: Added PythonDocument class. Refactored. Index: frame.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/frame.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** frame.py 1 Apr 2003 15:46:52 -0000 1.3 --- frame.py 1 Apr 2003 20:05:03 -0000 1.4 *************** *** 294,298 **** 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')) --- 294,298 ---- 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')) *************** *** 334,337 **** event.Enable(False) except AttributeError: ! # object with keyboard focus doesn't support this menu option. event.Enable(False) --- 334,337 ---- event.Enable(False) except AttributeError: ! # This menu option is not supported in the current context. event.Enable(False) Index: editor.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/editor.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** editor.py 1 Apr 2003 16:48:24 -0000 1.7 --- editor.py 1 Apr 2003 20:05:08 -0000 1.8 *************** *** 25,42 **** 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) --- 25,49 ---- 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) ! 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 ! shell = self.notebook.shell ! interp = shell.interp ! self.doc = PythonDocument(editor, interp) wx.EVT_IDLE(self, self.OnIdle) *************** *** 52,57 **** def OnCloseWindow(self, event): """Event handler for closing.""" ! if self.editor.GetModify(): ! self.FileSuggestSave() self.Destroy() --- 59,65 ---- def OnCloseWindow(self, event): """Event handler for closing.""" ! for doc in self.docs.values(): ! if doc.editor.GetModify(): ! doc.FileSuggestSave() self.Destroy() *************** *** 59,104 **** """Event handler for idle time.""" 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.filepath, 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.filepath) ! self.SetTitle(self.filename) def FilePrint(self): --- 67,112 ---- """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.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): """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): *************** *** 112,125 **** def FileSave(self): """Save file in editor.""" ! self.editor.FileSave(self.filepath) 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): --- 120,132 ---- 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): *************** *** 129,154 **** self.FileSave() ! 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): ! """Update the namespace for autocompletion and calltips.""" if self.editor.GetModify(): ! self.FileSave() backup = self.interp.locals modfile = None --- 136,189 ---- 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.syspath = sys.path[:] ! self.sysmodules = sys.modules.copy() while True: try: ! self.syspath.remove('') except ValueError: break while True: try: ! self.syspath.remove('.') 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): ! """Update the namespace for autocompletion and calltips. ! ! Return False if there was an error.""" if self.editor.GetModify(): ! self.save() backup = self.interp.locals modfile = None *************** *** 159,166 **** 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: --- 194,201 ---- except: self.interp.locals = backup ! return False else: self.interp.locals = module.__dict__.copy() ! return True finally: if modfile: *************** *** 171,262 **** 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) ! 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() ! ! ! 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. ! self.autoCompleteKeys = self.interp.getAutoCompleteKeys() ! # Assign handlers for keyboard events. ! wx.EVT_CHAR(self, self.OnChar) ! 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()) ! self.EmptyUndoBuffer() finally: f.close() ! def FileSave(self, filepath): ! """Save file.""" if not filepath: return --- 206,243 ---- pass ! def new(self, filepath): ! """New document.""" if not filepath: return if os.path.exists(filepath): ! self.confirmed = self.overwriteConfirm(filepath) else: self.confirmed = True ! 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): """Confirm overwriting an existing file.""" 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 *************** *** 264,280 **** 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() finally: f.close() def OnChar(self, event): """Keypress event handler. --- 245,287 ---- self.confirmed = True if not self.confirmed: ! 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.""" + + 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. + self.autoCompleteKeys = self.interp.getAutoCompleteKeys() + # Assign handlers for keyboard events. + wx.EVT_CHAR(self, self.OnChar) + wx.EVT_KEY_DOWN(self, self.OnKeyDown) + def OnChar(self, event): """Keypress event handler. *************** *** 369,370 **** --- 376,414 ---- self.CallTipShow(tippos, tip) self.CallTipSetHighlight(0, size) + + + 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 + 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() Index: base.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/base.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** base.py 1 Apr 2003 06:43:05 -0000 1.2 --- base.py 1 Apr 2003 20:05:10 -0000 1.3 *************** *** 52,62 **** """Create an Editor instance.""" stc.wxStyledTextCtrl.__init__(self, parent, id, pos, size, style) ! # Assign handlers for wxSTC events. stc.EVT_STC_UPDATEUI(self, id, self.OnUpdateUI) dispatcher.connect(receiver=self._fontsizer, signal='FontIncrease') dispatcher.connect(receiver=self._fontsizer, signal='FontDecrease') dispatcher.connect(receiver=self._fontsizer, signal='FontDefault') - # Configure various defaults and user preferences. - self.__config() def _fontsizer(self, signal): --- 52,60 ---- """Create an Editor instance.""" stc.wxStyledTextCtrl.__init__(self, parent, id, pos, size, style) ! self.__config() stc.EVT_STC_UPDATEUI(self, id, self.OnUpdateUI) dispatcher.connect(receiver=self._fontsizer, signal='FontIncrease') dispatcher.connect(receiver=self._fontsizer, signal='FontDecrease') dispatcher.connect(receiver=self._fontsizer, signal='FontDefault') def _fontsizer(self, signal): *************** *** 154,158 **** """Check for matching braces.""" # If the auto-complete window is up let it do its thing. ! if self.AutoCompActive(): return braceAtCaret = -1 --- 152,156 ---- """Check for matching braces.""" # If the auto-complete window is up let it do its thing. ! if self.AutoCompActive() or self.CallTipActive(): return braceAtCaret = -1 |
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() |
From: <po...@us...> - 2003-04-01 15:46:57
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv14161 Modified Files: frame.py Log Message: Change to a binding not already used by Scintilla. Index: frame.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/frame.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** frame.py 1 Apr 2003 06:43:04 -0000 1.2 --- frame.py 1 Apr 2003 15:46:52 -0000 1.3 *************** *** 68,72 **** 'Print file') m.AppendSeparator() ! m.Append(ID_NAMESPACE, '&Update Namespace \tShift+Ctrl+U', 'Save file; update namespace for autocompletion and calltips') m.AppendSeparator() --- 68,72 ---- 'Print file') m.AppendSeparator() ! m.Append(ID_NAMESPACE, '&Update Namespace \tShift+Ctrl+N', 'Save file; update namespace for autocompletion and calltips') m.AppendSeparator() |
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() |
From: <po...@us...> - 2003-04-01 00:09:10
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv19979 Modified Files: filling.py Log Message: Changed names to allow renaming utility to work. Index: filling.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/filling.py,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** filling.py 29 Mar 2003 02:42:01 -0000 1.55 --- filling.py 1 Apr 2003 00:09:06 -0000 1.56 *************** *** 64,68 **** rootData = wx.wxTreeItemData(rootObject) self.item = self.root = self.AddRoot(rootLabel, -1, -1, rootData) ! self.SetItemHasChildren(self.root, self.hasChildren(rootObject)) wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding) wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed) --- 64,68 ---- rootData = wx.wxTreeItemData(rootObject) self.item = self.root = self.AddRoot(rootLabel, -1, -1, rootData) ! self.SetItemHasChildren(self.root, self.objHasChildren(rootObject)) wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding) wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed) *************** *** 108,119 **** frame.Show() ! def hasChildren(self, obj): """Return true if object has children.""" ! if self.getChildren(obj): return True else: return False ! def getChildren(self, obj): """Return dictionary with attributes or contents of object.""" busy = wx.wxBusyCursor() --- 108,119 ---- frame.Show() ! def objHasChildren(self, obj): """Return true if object has children.""" ! if self.objGetChildren(obj): return True else: return False ! def objGetChildren(self, obj): """Return dictionary with attributes or contents of object.""" busy = wx.wxBusyCursor() *************** *** 141,145 **** self.DeleteChildren(item) obj = self.GetPyData(item) ! children = self.getChildren(obj) if not children: return --- 141,145 ---- self.DeleteChildren(item) obj = self.GetPyData(item) ! children = self.objGetChildren(obj) if not children: return *************** *** 159,163 **** data = wx.wxTreeItemData(child) branch = self.AppendItem(parent=item, text=itemtext, data=data) ! self.SetItemHasChildren(branch, self.hasChildren(child)) def display(self): --- 159,163 ---- data = wx.wxTreeItemData(child) branch = self.AppendItem(parent=item, text=itemtext, data=data) ! self.SetItemHasChildren(branch, self.objHasChildren(child)) def display(self): *************** *** 169,173 **** if obj is None: # Windows bug fix. return ! self.SetItemHasChildren(item, self.hasChildren(obj)) otype = type(obj) text = '' --- 169,173 ---- if obj is None: # Windows bug fix. return ! self.SetItemHasChildren(item, self.objHasChildren(obj)) otype = type(obj) text = '' |
From: <po...@us...> - 2003-03-31 23:47:53
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv12881 Modified Files: shell.py Log Message: In case something else needs to happen OnIdle. Index: shell.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/shell.py,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** shell.py 30 Mar 2003 20:47:25 -0000 1.119 --- shell.py 31 Mar 2003 23:47:49 -0000 1.120 *************** *** 234,237 **** --- 234,238 ---- if self.waiting: time.sleep(0.05) + event.Skip() def showIntro(self, text=''): |
From: <po...@us...> - 2003-03-31 19:23:07
|
Update of /cvsroot/pycrust/wx In directory sc8-pr-cvs1:/tmp/cvs-serv19086 Removed Files: mimetypes_wdr.py joystick_wdr.py Log Message: Shouldn't have been there in the first place. --- mimetypes_wdr.py DELETED --- --- joystick_wdr.py DELETED --- |
From: <po...@us...> - 2003-03-31 15:45:35
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv29104 Modified Files: PyCrustApp.py Log Message: Use boolean. Index: PyCrustApp.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/PyCrustApp.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PyCrustApp.py 18 Mar 2003 03:06:10 -0000 1.12 --- PyCrustApp.py 31 Mar 2003 15:45:03 -0000 1.13 *************** *** 41,45 **** import sys sys.app = self ! return 1 ''' --- 41,45 ---- import sys sys.app = self ! return True ''' |
From: <po...@us...> - 2003-03-31 02:35:20
|
Update of /cvsroot/pycrust/PyCrust/wxd In directory sc8-pr-cvs1:/tmp/cvs-serv4442/wxd Modified Files: Frames.py Tree.py wxPython.html wxPython.txt Log Message: Moved to frame.py Index: Frames.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/wxd/Frames.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Frames.py 18 Mar 2003 04:10:44 -0000 1.3 --- Frames.py 31 Mar 2003 02:35:16 -0000 1.4 *************** *** 38,44 **** """Create a Frame instance. ! parent - The window parent. This may be NULL. If it is ! non-NULL, the frame will always be displayed on top of the ! parent window on Windows. id - The window identifier. It may take a value of -1 to --- 38,44 ---- """Create a Frame instance. ! parent - The window parent. This may be None. If it is not ! None, the frame will always be displayed on top of the parent ! window on Windows. id - The window identifier. It may take a value of -1 to *************** *** 94,99 **** pass ! def CreateToolBar(self, style=wx.NO_BORDER|wx.TB_HORIZONTAL, id=-1, ! name=wx.PyToolBarNameStr): """Create a toolbar at the top or left of frame. --- 94,99 ---- pass ! def CreateToolBar(self, style=wx.NO_BORDER | wx.TB_HORIZONTAL, ! id=-1, name=wx.PyToolBarNameStr): """Create a toolbar at the top or left of frame. *************** *** 142,147 **** def GetStatusBarPane(self): ! """Return status bar pane used to display menu and toolbar ! help.""" pass --- 142,146 ---- def GetStatusBarPane(self): ! """Return status bar pane used to display menu/toolbar help.""" pass *************** *** 238,257 **** class LayoutAlgorithm(Object): ! """""" def __init__(self): ! """""" pass ! def LayoutFrame(self): ! """""" pass ! def LayoutMDIFrame(self): ! """""" pass ! def LayoutWindow(self): ! """""" pass --- 237,336 ---- class LayoutAlgorithm(Object): ! """LayoutAlgorithm implements layout of subwindows in MDI or SDI ! frames. It sends a wx.CalculateLayoutEvent event to children of ! the frame, asking them for information about their size. For MDI ! parent frames, the algorithm allocates the remaining space to the ! MDI client window (which contains the MDI child frames). For SDI ! (normal) frames, a 'main' window is specified as taking up the ! remaining space. ! ! Because the event system is used, this technique can be applied to ! any windows, which are not necessarily 'aware' of the layout ! classes. However, you may wish to use wx.SashLayoutWindow for ! your subwindows since this class provides handlers for the ! required events, and accessors to specify the desired size of the ! window. The sash behaviour in the base class can be used, ! optionally, to make the windows user-resizable. ! ! LayoutAlgorithm is typically used in IDE (integrated development ! environment) applications, where there are several resizable ! windows in addition to the MDI client window, or other primary ! editing window. Resizable windows might include toolbars, a ! project window, and a window for displaying error and warning ! messages. ! ! When a window receives an OnCalculateLayout event, it should call ! SetRect in the given event object, to be the old supplied ! rectangle minus whatever space the window takes up. It should ! also set its own size accordingly. ! SashLayoutWindow.OnCalculateLayout generates an OnQueryLayoutInfo ! event which it sends to itself to determine the orientation, ! alignment and size of the window, which it gets from internal ! member variables set by the application. ! ! The algorithm works by starting off with a rectangle equal to the ! whole frame client area. It iterates through the frame children, ! generating OnCalculateLayout events which subtract the window size ! and return the remaining rectangle for the next window to process. ! It is assumed (by SashLayoutWindow.OnCalculateLayout) that a ! window stretches the full dimension of the frame client, according ! to the orientation it specifies. For example, a horizontal window ! will stretch the full width of the remaining portion of the frame ! client area. In the other orientation, the window will be fixed ! to whatever size was specified by OnQueryLayoutInfo. An alignment ! setting will make the window 'stick' to the left, top, right or ! bottom of the remaining client area. This scheme implies that ! order of window creation is important. Say you wish to have an ! extra toolbar at the top of the frame, a project window to the ! left of the MDI client window, and an output window above the ! status bar. You should therefore create the windows in this ! order: toolbar, output window, project window. This ensures that ! the toolbar and output window take up space at the top and bottom, ! and then the remaining height in-between is used for the project ! window. ! ! LayoutAlgorithm is quite independent of the way in which ! OnCalculateLayout chooses to interpret a window's size and ! alignment. Therefore you could implement a different window class ! with a new OnCalculateLayout event handler, that has a more ! sophisticated way of laying out the windows. It might allow ! specification of whether stretching occurs in the specified ! orientation, for example, rather than always assuming ! stretching. (This could, and probably should, be added to the ! existing implementation). ! ! The algorithm object does not respond to events, but itself ! generates the following events in order to calculate window sizes: ! EVT_QUERY_LAYOUT_INFO(func), EVT_CALCULATE_LAYOUT(func).""" def __init__(self): ! """Create a LayoutAlgorithm instance.""" pass ! def LayoutFrame(self, frame, mainWindow=wx.NULL): ! """Lay out the children of a normal frame. ! ! mainWindow is set to occupy the remaining space. This ! function simply calls LayoutWindow().""" pass ! def LayoutMDIFrame(self, frame, rect=wx.NULL): ! """Lay out the children of an MDI parent frame. ! ! If rect is non-NULL, the given rectangle will be used as a ! starting point instead of the frame's client area. ! ! The MDI client window is set to occupy the remaining space.""" pass ! def LayoutWindow(self, parent, mainWindow=wx.NULL): ! """Lay out the children of a normal frame or other window. ! ! mainWindow is set to occupy the remaining space. If this is ! not specified, then the last window that responds to a ! calculate layout event in query mode will get the remaining ! space (that is, a non-query OnCalculateLayout event will not ! be sent to this window and the window will be set to the ! remaining size).""" pass Index: Tree.py =================================================================== RCS file: /cvsroot/pycrust/PyCrust/wxd/Tree.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Tree.py 7 Mar 2003 04:36:03 -0000 1.2 --- Tree.py 31 Mar 2003 02:35:17 -0000 1.3 *************** *** 19,23 **** class TreeCtrl(Control): ! """""" def AddRoot(self): --- 19,26 ---- class TreeCtrl(Control): ! """A tree control presents information as a hierarchy, with items ! that may be expanded to show further items. Items in a tree ! control are referenced by wx.TreeItemId handles, which may be ! tested for validity by calling TreeItemId.IsOk().""" def AddRoot(self): *************** *** 355,402 **** class TreeItemData(Object): ! """""" ! def GetData(self): ! """""" pass ! def GetId(self): ! """""" pass ! def SetData(self): ! """""" pass ! def SetId(self): ! """""" pass ! def __init__(self): ! """""" pass class TreeItemId: ! """""" ! ! def IsOk(self): ! """""" ! pass ! def Ok(self): ! """""" ! pass ! def __cmp__(self): ! """""" ! pass ! def __del__(self): ! """""" pass ! def __init__(self): ! """""" pass - --- 358,403 ---- class TreeItemData(Object): ! """TreeItemData is some (arbitrary) user class associated with ! some item. The main advantage of having this class is that ! TreeItemData objects are destroyed automatically by the tree and ! the memory and any other resources associated with a tree item ! will be automatically freed when it is deleted.""" ! def __init__(self, obj=wx.NULL): ! """Associate any Python object with tree item using ! wxTreeItemData as container.""" pass ! def GetData(self): ! """Return the Python object.""" pass ! def GetId(self): ! """Return the item associated with this node.""" pass ! def SetData(self, obj): ! """Associate Python object with tree item.""" pass ! def SetId(self, id): ! """Set the item associated with this node.""" pass class TreeItemId: ! """Item in a TreeCtrl.""" ! ## You wouldn't create these directly. ! ## def __init__(self): ! ## """""" ! ## pass ! def IsOk(self): ! """Return True if item is valid.""" pass ! def Ok(self): ! """Synonym for IsOk.""" pass Index: wxPython.html =================================================================== RCS file: /cvsroot/pycrust/PyCrust/wxd/wxPython.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxPython.html 22 Mar 2003 16:06:44 -0000 1.1 --- wxPython.html 31 Mar 2003 02:35:17 -0000 1.2 *************** *** 70,74 **** <li><a class="reference" href="#programming-with-notebooksizer" id="id30" name="id30">Programming with NotebookSizer</a></li> <li><a class="reference" href="#programming-with-staticboxsizer" id="id31" name="id31">Programming with StaticBoxSizer</a></li> ! <li><a class="reference" href="#createbuttonsizer" id="id32" name="id32">CreateButtonSizer</a></li> </ul> </li> --- 70,74 ---- <li><a class="reference" href="#programming-with-notebooksizer" id="id30" name="id30">Programming with NotebookSizer</a></li> <li><a class="reference" href="#programming-with-staticboxsizer" id="id31" name="id31">Programming with StaticBoxSizer</a></li> ! <li><a class="reference" href="#dialog-createbuttonsizer" id="id32" name="id32">Dialog.CreateButtonSizer</a></li> </ul> </li> *************** *** 385,388 **** --- 385,415 ---- <p>Classes: wx.Sizer, wx.GridSizer, wx.FlexGridSizer, wx.BoxSizer, wx.StaticBoxSizer, wx.NotebookSizer, wx.CreateButtonSizer</p> + <table class="table" frame="border" rules="all"> + <colgroup> + <col width="21%" /> + <col width="79%" /> + </colgroup> + <tbody valign="top"> + <tr><td>Sizer</td> + <td>Abstract base class.</td> + </tr> + <tr><td>GridSizer</td> + <td>A sizer for laying out windows in a grid with all + fields having the same size.</td> + </tr> + <tr><td>FlexGridSizer</td> + <td>A sizer for laying out windows in a flexible grid.</td> + </tr> + <tr><td>BoxSizer</td> + <td>A sizer for laying out windows in a row or column.</td> + </tr> + <tr><td>StaticBoxSizer</td> + <td>Same as BoxSizer, but with a surrounding static box.</td> + </tr> + <tr><td>NotebookSizer</td> + <td>Sizer to use with the Notebook control.</td> + </tr> + </tbody> + </table> <p>Sizers, as represented by the wx.Sizer class and its descendants in the wxPython class hierarchy, have become the method of choice to *************** *** 624,647 **** <p>[Show code and graphic here.]</p> </div> ! <div class="section" id="createbuttonsizer"> ! <h2><a class="toc-backref" href="#id32" name="createbuttonsizer">CreateButtonSizer</a></h2> ! <p>As a convenience, wx.CreateButtonSizer(flags) can be used to create a ! standard button sizer in which standard buttons are displayed. The ! following flags can be passed to this function:</p> ! <pre class="literal-block"> ! wxYES_NO // Add Yes/No subpanel ! wxYES // return wxID_YES ! wxNO // return wxID_NO ! wxNO_DEFAULT // make the wxNO button the default, otherwise wxYES or wxOK button will be default ! ! wxOK // return wxID_OK ! wxCANCEL // return wxID_CANCEL ! wxHELP // return wxID_HELP ! ! wxFORWARD // return wxID_FORWARD ! wxBACKWARD // return wxID_BACKWARD ! wxSETUP // return wxID_SETUP ! wxMORE // return wxID_MORE ! </pre> </div> </div> --- 651,702 ---- <p>[Show code and graphic here.]</p> </div> ! <div class="section" id="dialog-createbuttonsizer"> ! <h2><a class="toc-backref" href="#id32" name="dialog-createbuttonsizer">Dialog.CreateButtonSizer</a></h2> ! <p>As a convenience, the Dialog class has a CreateButtonSizer(flags) ! method that can be used to create a standard button sizer in which ! standard buttons are displayed. The following flags can be passed to ! this method:</p> ! <table class="table" frame="border" rules="all"> ! <colgroup> ! <col width="19%" /> ! <col width="81%" /> ! </colgroup> ! <tbody valign="top"> ! <tr><td>wx.YES_NO</td> ! <td>add Yes/No subpanel</td> ! </tr> ! <tr><td>wx.YES</td> ! <td>return wx.ID_YES</td> ! </tr> ! <tr><td>wx.NO</td> ! <td>return wx.ID_NO</td> ! </tr> ! <tr><td>wx.NO_DEFAULT</td> ! <td>make the wx.NO button the default, otherwise wx.YES or ! wx.OK button will be default</td> ! </tr> ! <tr><td>wx.OK</td> ! <td>return wx.ID_OK</td> ! </tr> ! <tr><td>wx.CANCEL</td> ! <td>return wx.ID_CANCEL</td> ! </tr> ! <tr><td>wx.HELP</td> ! <td>return wx.ID_HELP</td> ! </tr> ! <tr><td>wx.FORWARD</td> ! <td>return wx.ID_FORWARD</td> ! </tr> ! <tr><td>wx.BACKWARD</td> ! <td>return wx.ID_BACKWARD</td> ! </tr> ! <tr><td>wx.SETUP</td> ! <td>return wx.ID_SETUP</td> ! </tr> ! <tr><td>wx.MORE</td> ! <td>return wx.ID_MORE</td> ! </tr> ! </tbody> ! </table> </div> </div> Index: wxPython.txt =================================================================== RCS file: /cvsroot/pycrust/PyCrust/wxd/wxPython.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** wxPython.txt 22 Mar 2003 16:03:47 -0000 1.2 --- wxPython.txt 31 Mar 2003 02:35:17 -0000 1.3 *************** *** 364,367 **** --- 364,384 ---- wx.StaticBoxSizer, wx.NotebookSizer, wx.CreateButtonSizer + ============== ====================================================== + + Sizer Abstract base class. + + GridSizer A sizer for laying out windows in a grid with all + fields having the same size. + + FlexGridSizer A sizer for laying out windows in a flexible grid. + + BoxSizer A sizer for laying out windows in a row or column. + + StaticBoxSizer Same as BoxSizer, but with a surrounding static box. + + NotebookSizer Sizer to use with the Notebook control. + + ============== ====================================================== + Sizers, as represented by the wx.Sizer class and its descendants in the wxPython class hierarchy, have become the method of choice to *************** *** 659,682 **** ! CreateButtonSizer ! ----------------- ! As a convenience, wx.CreateButtonSizer(flags) can be used to create a ! standard button sizer in which standard buttons are displayed. The ! following flags can be passed to this function:: ! wxYES_NO // Add Yes/No subpanel ! wxYES // return wxID_YES ! wxNO // return wxID_NO ! wxNO_DEFAULT // make the wxNO button the default, otherwise wxYES or wxOK button will be default ! ! wxOK // return wxID_OK ! wxCANCEL // return wxID_CANCEL ! wxHELP // return wxID_HELP ! ! wxFORWARD // return wxID_FORWARD ! wxBACKWARD // return wxID_BACKWARD ! wxSETUP // return wxID_SETUP ! wxMORE // return wxID_MORE --- 676,701 ---- ! Dialog.CreateButtonSizer ! ------------------------ ! As a convenience, the Dialog class has a CreateButtonSizer(flags) ! method that can be used to create a standard button sizer in which ! standard buttons are displayed. The following flags can be passed to ! this method: ! ============= ======================================================= ! wx.YES_NO add Yes/No subpanel ! wx.YES return wx.ID_YES ! wx.NO return wx.ID_NO ! wx.NO_DEFAULT make the wx.NO button the default, otherwise wx.YES or ! wx.OK button will be default ! wx.OK return wx.ID_OK ! wx.CANCEL return wx.ID_CANCEL ! wx.HELP return wx.ID_HELP ! wx.FORWARD return wx.ID_FORWARD ! wx.BACKWARD return wx.ID_BACKWARD ! wx.SETUP return wx.ID_SETUP ! wx.MORE return wx.ID_MORE ! ============= ======================================================= *************** *** 899,902 **** --- 918,985 ---- Not done yet. + + + ID constants + ============ + + wxPython provides the following predefined ID constants: + + ID_ABORT + ID_ABOUT + ID_ANY + ID_APPLY + ID_BACKWARD + ID_CANCEL + ID_CLEAR + ID_CLOSE + ID_CLOSE_ALL + ID_CONTEXT_HELP + ID_COPY + ID_CUT + ID_DEFAULT + ID_DUPLICATE + ID_EXIT + ID_FILE1 + ID_FILE2 + ID_FILE3 + ID_FILE4 + ID_FILE5 + ID_FILE6 + ID_FILE7 + ID_FILE8 + ID_FILE9 + ID_FILTERLISTCTRL + ID_FIND + ID_FORWARD + ID_HELP + ID_HELP_COMMANDS + ID_HELP_CONTENTS + ID_HELP_CONTEXT + ID_HELP_PROCEDURES + ID_IGNORE + ID_MORE + ID_NEW + ID_NO + ID_NOTOALL + ID_OK + ID_OPEN + ID_PASTE + ID_PREVIEW + ID_PRINT + ID_PRINT_SETUP + ID_REDO + ID_RESET + ID_RETRY + ID_REVERT + ID_SAVE + ID_SAVEAS + ID_SELECTALL + ID_SEPARATOR + ID_SETUP + ID_STATIC + ID_TREECTRL + ID_UNDO + ID_YES + ID_YESTOALL |
From: <po...@us...> - 2003-03-31 02:35:19
|
Update of /cvsroot/pycrust/PyCrust In directory sc8-pr-cvs1:/tmp/cvs-serv4442 Removed Files: shellmenu.py Log Message: Moved to frame.py --- shellmenu.py DELETED --- |