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