29 import wx.stc |
29 import wx.stc |
30 |
30 |
31 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
31 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
32 from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS, LOCATIONDATATYPES |
32 from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS, LOCATIONDATATYPES |
33 from EditorPanel import EditorPanel |
33 from EditorPanel import EditorPanel |
|
34 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos |
34 |
35 |
35 #------------------------------------------------------------------------------- |
36 #------------------------------------------------------------------------------- |
36 # Textual programs Viewer class |
37 # Textual programs Viewer class |
37 #------------------------------------------------------------------------------- |
38 #------------------------------------------------------------------------------- |
38 |
39 |
50 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8) |
51 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8) |
51 |
52 |
52 [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
53 [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
53 ] = [wx.NewId() for _init_ctrls in range(2)] |
54 ] = [wx.NewId() for _init_ctrls in range(2)] |
54 |
55 |
55 if wx.Platform == '__WXMSW__': |
|
56 faces = { 'times': 'Times New Roman', |
|
57 'mono' : 'Courier New', |
|
58 'helv' : 'Arial', |
|
59 'other': 'Comic Sans MS', |
|
60 'size' : 10, |
|
61 } |
|
62 else: |
|
63 faces = { 'times': 'Times', |
|
64 'mono' : 'Courier', |
|
65 'helv' : 'Helvetica', |
|
66 'other': 'new century schoolbook', |
|
67 'size' : 12, |
|
68 } |
|
69 re_texts = {} |
56 re_texts = {} |
70 re_texts["letter"] = "[A-Za-z]" |
57 re_texts["letter"] = "[A-Za-z]" |
71 re_texts["digit"] = "[0-9]" |
58 re_texts["digit"] = "[0-9]" |
72 re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts |
59 re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts |
73 IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) |
60 IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) |
77 HIGHLIGHT_TYPES = { |
64 HIGHLIGHT_TYPES = { |
78 ERROR_HIGHLIGHT: STC_PLC_ERROR, |
65 ERROR_HIGHLIGHT: STC_PLC_ERROR, |
79 SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
66 SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
80 } |
67 } |
81 |
68 |
82 def GetCursorPos(old, new): |
|
83 if old == "": |
|
84 return 0 |
|
85 old_length = len(old) |
|
86 new_length = len(new) |
|
87 common_length = min(old_length, new_length) |
|
88 i = 0 |
|
89 for i in xrange(common_length): |
|
90 if old[i] != new[i]: |
|
91 break |
|
92 if old_length < new_length: |
|
93 if common_length > 0 and old[i] != new[i]: |
|
94 return i + new_length - old_length |
|
95 else: |
|
96 return i + new_length - old_length + 1 |
|
97 elif old_length > new_length or i < min(old_length, new_length) - 1: |
|
98 if common_length > 0 and old[i] != new[i]: |
|
99 return i |
|
100 else: |
|
101 return i + 1 |
|
102 else: |
|
103 return None |
|
104 |
|
105 def LineStartswith(line, symbols): |
69 def LineStartswith(line, symbols): |
106 return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False) |
70 return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False) |
107 |
71 |
108 class TextViewer(EditorPanel): |
72 class TextViewer(EditorPanel): |
109 |
73 |
115 event(self, id, function) |
79 event(self, id, function) |
116 else: |
80 else: |
117 event(self, function) |
81 event(self, function) |
118 |
82 |
119 def _init_Editor(self, prnt): |
83 def _init_Editor(self, prnt): |
120 self.Editor = wx.stc.StyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, |
84 self.Editor = CustomStyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, |
121 parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
85 parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
122 self.Editor.ParentWindow = self |
86 self.Editor.ParentWindow = self |
123 |
87 |
124 self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
88 self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
125 self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
89 self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |