| 1 | #!/usr/local/bin/python |
| 2 | |
| 3 | # simple text editor |
| 4 | # |
| 5 | # Copyright 2001 Adam Feuer and Steve Howell |
| 6 | # |
| 7 | # License: Python |
| 8 | |
| 9 | import re |
| 10 | from wxPython.wx import * |
| 11 | from wxPython.lib.editor import wxEditor |
| 12 | |
| 13 | #--------------------------------------------------------------------- |
| 14 | |
| 15 | class FrogEditor(wxEditor): |
| 16 | def __init__(self, parent, id, |
| 17 | pos=wxDefaultPosition, size=wxDefaultSize, style=0, statusBar=None): |
| 18 | self.StatusBar = statusBar |
| 19 | wxEditor.__init__(self, parent, id, pos, size, style) |
| 20 | self.parent = parent |
| 21 | |
| 22 | ##------------------------------------ |
| 23 | |
| 24 | def TouchBuffer(self): |
| 25 | wxEditor.TouchBuffer(self) |
| 26 | self.StatusBar.setDirty(1) |
| 27 | |
| 28 | def UnTouchBuffer(self): |
| 29 | wxEditor.UnTouchBuffer(self) |
| 30 | self.StatusBar.setDirty(0) |
| 31 | |
| 32 | |
| 33 | #--------- utility function ------------- |
| 34 | |
| 35 | # override our base class method |
| 36 | def DrawCursor(self, dc = None): |
| 37 | wxEditor.DrawCursor(self,dc) |
| 38 | self.StatusBar.setRowCol(self.cy,self.cx) |
| 39 | |
| 40 | def lastLine(self): |
| 41 | lastline = self.sy + self.sh - 1 |
| 42 | return min(lastline, self.LinesInFile() - 1) |
| 43 | |
| 44 | def rawLines(self): |
| 45 | return [l.text for l in self.text] |
| 46 | |
| 47 | def save(self): |
| 48 | if self.page: |
| 49 | self.ds.store(self.page,self.rawLines()) |
| 50 | |
| 51 | def SetRawText(self, rawtext=""): |
| 52 | self.rawText= rawtext |
| 53 | self.SetText(self.RenderText()) |
| 54 | |
| 55 | def RenderText(self): |
| 56 | return(self.rawText) |
| 57 | |
| 58 | #---------- logging ------------- |
| 59 | |
| 60 | def SetStatus(self, log): |
| 61 | self.log = log |
| 62 | self.status = [] |
| 63 | |
| 64 | def PrintSeparator(self, event): |
| 65 | self.Print("..........................") |
| 66 | |
| 67 | def Print(self, data): |
| 68 | self.status.append(data) |
| 69 | if data[-1:] == '\n': |
| 70 | data = data[:-1] |
| 71 | wxLogMessage(data) |
| 72 | |
| 73 | #--------- wxEditor keyboard overrides |
| 74 | |
| 75 | def SetControlFuncs(self, action): |
| 76 | wxEditor.SetControlFuncs(self, action) |
| 77 | action['-'] = self.PrintSeparator |
| 78 | |
| 79 | def SetAltFuncs(self, action): |
| 80 | wxEditor.SetAltFuncs(self, action) |
| 81 | action['x'] = self.Exit |
| 82 | |
| 83 | #----------- commands ----------- |
| 84 | |
| 85 | def OnCloseWindow(self, event): |
| 86 | # xxx - We don't fully understand how exit logic works. |
| 87 | # This event is actually called by our parent frame. |
| 88 | pass |
| 89 | |
| 90 | def Exit(self,event): |
| 91 | self.parent.Close(None) |
| 92 | |