author | lbessard |
Tue, 12 Aug 2008 18:16:09 +0200 | |
changeset 231 | fc2d6cbb8b39 |
parent 145 | 4fb225afddf4 |
child 235 | 7b58a3b5b6ec |
permissions | -rw-r--r-- |
27 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
27 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
27 | 20 |
# |
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import wx |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
26 |
import wx.grid |
27 | 27 |
|
121 | 28 |
if wx.VERSION >= (2, 8, 0): |
29 |
import wx.aui |
|
30 |
||
31 |
class MDIConfigurationEditor(wx.aui.AuiMDIChildFrame): |
|
32 |
def __init__(self, parent, tagname, window, controler): |
|
33 |
wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "") |
|
34 |
||
35 |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
36 |
||
37 |
self.Viewer = ConfigurationEditor(self, tagname, window, controler) |
|
38 |
||
39 |
sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW) |
|
40 |
||
41 |
self.SetSizer(sizer) |
|
42 |
||
43 |
def GetViewer(self): |
|
44 |
return self.Viewer |
|
45 |
||
46 |
class MDIResourceEditor(wx.aui.AuiMDIChildFrame): |
|
47 |
def __init__(self, parent, tagname, window, controler): |
|
48 |
wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "") |
|
49 |
||
50 |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
51 |
||
52 |
self.Viewer = ResourceEditor(self, tagname, window, controler) |
|
53 |
||
54 |
sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW) |
|
55 |
||
56 |
self.SetSizer(sizer) |
|
57 |
||
58 |
def GetViewer(self): |
|
59 |
return self.Viewer |
|
60 |
||
61 |
#------------------------------------------------------------------------------- |
|
62 |
# Configuration Editor class |
|
63 |
#------------------------------------------------------------------------------- |
|
64 |
||
65 |
[ID_CONFIGURATIONEDITOR, |
|
66 |
] = [wx.NewId() for _init_ctrls in range(1)] |
|
67 |
||
68 |
class ConfigurationEditor(wx.Panel): |
|
69 |
||
70 |
def _init_ctrls(self, prnt): |
|
71 |
wx.Panel.__init__(self, id=ID_CONFIGURATIONEDITOR, name='', parent=prnt, |
|
72 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) |
|
73 |
||
74 |
def __init__(self, parent, tagname, window, controler): |
|
75 |
self._init_ctrls(parent) |
|
76 |
||
77 |
self.ParentWindow = window |
|
78 |
self.Controler = controler |
|
79 |
self.TagName = tagname |
|
80 |
||
81 |
def SetTagName(self, tagname): |
|
82 |
self.TagName = tagname |
|
83 |
||
84 |
def GetTagName(self): |
|
85 |
return self.TagName |
|
86 |
||
87 |
def IsViewing(self, tagname): |
|
88 |
return self.TagName == tagname |
|
89 |
||
90 |
def SetMode(self, mode): |
|
91 |
pass |
|
92 |
||
93 |
def ResetBuffer(self): |
|
94 |
pass |
|
95 |
||
96 |
def RefreshView(self): |
|
97 |
pass |
|
98 |
||
145 | 99 |
def RefreshScaling(self, refresh=True): |
100 |
pass |
|
101 |
||
27 | 102 |
#------------------------------------------------------------------------------- |
103 |
# Resource Editor class |
|
104 |
#------------------------------------------------------------------------------- |
|
105 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
106 |
class ResourceTable(wx.grid.PyGridTableBase): |
27 | 107 |
|
108 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
109 |
A custom wx.grid.Grid Table using user supplied data |
27 | 110 |
""" |
111 |
def __init__(self, parent, data, colnames): |
|
112 |
# The base class must be initialized *first* |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
113 |
wx.grid.PyGridTableBase.__init__(self) |
27 | 114 |
self.data = data |
115 |
self.colnames = colnames |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
116 |
self.Errors = {} |
27 | 117 |
self.Parent = parent |
118 |
||
119 |
self.ColAlignements = [] |
|
120 |
self.ColSizes = [] |
|
121 |
# XXX |
|
122 |
# we need to store the row length and collength to |
|
123 |
# see if the table has changed size |
|
124 |
self._rows = self.GetNumberRows() |
|
125 |
self._cols = self.GetNumberCols() |
|
126 |
||
127 |
def GetColAlignements(self): |
|
128 |
return self.ColAlignements |
|
129 |
||
130 |
def SetColAlignements(self, list): |
|
131 |
self.ColAlignements = list |
|
132 |
||
133 |
def GetColSizes(self): |
|
134 |
return self.ColSizes |
|
135 |
||
136 |
def SetColSizes(self, list): |
|
137 |
self.ColSizes = list |
|
138 |
||
139 |
def GetNumberCols(self): |
|
140 |
return len(self.colnames) |
|
141 |
||
142 |
def GetNumberRows(self): |
|
143 |
return len(self.data) |
|
144 |
||
145 |
def GetColLabelValue(self, col): |
|
146 |
if col < len(self.colnames): |
|
147 |
return self.colnames[col] |
|
148 |
||
149 |
def GetRowLabelValues(self, row): |
|
150 |
return row |
|
151 |
||
152 |
def GetValue(self, row, col): |
|
153 |
if row < self.GetNumberRows(): |
|
154 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
|
155 |
return name |
|
156 |
||
157 |
def GetValueByName(self, row, colname): |
|
158 |
return self.data[row].get(colname) |
|
159 |
||
160 |
def SetValue(self, row, col, value): |
|
161 |
if col < len(self.colnames): |
|
162 |
self.data[row][self.GetColLabelValue(col)] = value |
|
163 |
||
164 |
def SetValueByName(self, row, colname, value): |
|
165 |
if colname in self.colnames: |
|
166 |
self.data[row][colname] = value |
|
167 |
||
168 |
def ResetView(self, grid): |
|
169 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
170 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
27 | 171 |
update the grid if rows and columns have been added or deleted |
172 |
""" |
|
173 |
grid.BeginBatch() |
|
174 |
for current, new, delmsg, addmsg in [ |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
175 |
(self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
176 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
27 | 177 |
]: |
178 |
if new < current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
179 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
27 | 180 |
grid.ProcessTableMessage(msg) |
181 |
elif new > current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
182 |
msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
27 | 183 |
grid.ProcessTableMessage(msg) |
184 |
self.UpdateValues(grid) |
|
185 |
grid.EndBatch() |
|
186 |
||
187 |
self._rows = self.GetNumberRows() |
|
188 |
self._cols = self.GetNumberCols() |
|
189 |
# update the column rendering scheme |
|
190 |
self._updateColAttrs(grid) |
|
191 |
||
192 |
# update the scrollbars and the displayed part of the grid |
|
193 |
grid.AdjustScrollbars() |
|
194 |
grid.ForceRefresh() |
|
195 |
||
196 |
def UpdateValues(self, grid): |
|
197 |
"""Update all displayed values""" |
|
198 |
# This sends an event to the grid table to update all of the values |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
199 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
27 | 200 |
grid.ProcessTableMessage(msg) |
201 |
||
202 |
def _updateColAttrs(self, grid): |
|
203 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
204 |
wx.grid.Grid -> update the column attributes to add the |
27 | 205 |
appropriate renderer given the column name. |
206 |
||
207 |
Otherwise default to the default renderer. |
|
208 |
""" |
|
209 |
||
210 |
for col in range(self.GetNumberCols()): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
211 |
attr = wx.grid.GridCellAttr() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
212 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
27 | 213 |
grid.SetColAttr(col, attr) |
214 |
grid.SetColSize(col, self.ColSizes[col]) |
|
215 |
||
216 |
for row in range(self.GetNumberRows()): |
|
217 |
for col in range(self.GetNumberCols()): |
|
218 |
editor = None |
|
219 |
renderer = None |
|
220 |
colname = self.GetColLabelValue(col) |
|
221 |
grid.SetReadOnly(row, col, False) |
|
222 |
if colname in ["Name","Interval"]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
223 |
editor = wx.grid.GridCellTextEditor() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
224 |
renderer = wx.grid.GridCellStringRenderer() |
27 | 225 |
if colname == "Interval" and self.GetValueByName(row, "Single") != "": |
226 |
grid.SetReadOnly(row, col, True) |
|
227 |
elif colname == "Single": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
228 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 229 |
editor.SetParameters(self.Parent.VariableList) |
230 |
if self.GetValueByName(row, "Interval") != "": |
|
231 |
grid.SetReadOnly(row, col, True) |
|
232 |
elif colname == "Type": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
233 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 234 |
editor.SetParameters(self.Parent.TypeList) |
235 |
elif colname == "Priority": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
236 |
editor = wx.grid.GridCellNumberEditor() |
27 | 237 |
editor.SetParameters("0,65535") |
238 |
elif colname == "Task": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
239 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 240 |
editor.SetParameters(self.Parent.TaskList) |
241 |
||
242 |
grid.SetCellEditor(row, col, editor) |
|
243 |
grid.SetCellRenderer(row, col, renderer) |
|
244 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
245 |
if row in self.Errors and self.Errors[row][0] == colname.lower(): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
246 |
grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
247 |
grid.SetCellTextColour(row, col, wx.RED) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
248 |
grid.MakeCellVisible(row, col) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
249 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
250 |
grid.SetCellTextColour(row, col, wx.BLACK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
251 |
grid.SetCellBackgroundColour(row, col, wx.WHITE) |
27 | 252 |
|
253 |
def SetData(self, data): |
|
254 |
self.data = data |
|
255 |
||
256 |
def GetData(self): |
|
257 |
return self.data |
|
258 |
||
259 |
def GetCurrentIndex(self): |
|
260 |
return self.CurrentIndex |
|
261 |
||
262 |
def SetCurrentIndex(self, index): |
|
263 |
self.CurrentIndex = index |
|
264 |
||
265 |
def AppendRow(self, row_content): |
|
266 |
self.data.append(row_content) |
|
267 |
||
268 |
def RemoveRow(self, row_index): |
|
269 |
self.data.pop(row_index) |
|
270 |
||
271 |
def MoveRow(self, row_index, move, grid): |
|
272 |
new_index = max(0, min(row_index + move, len(self.data) - 1)) |
|
273 |
if new_index != row_index: |
|
274 |
self.data.insert(new_index, self.data.pop(row_index)) |
|
275 |
grid.SetGridCursor(new_index, grid.GetGridCursorCol()) |
|
276 |
||
277 |
def Empty(self): |
|
278 |
self.data = [] |
|
279 |
self.editors = [] |
|
280 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
281 |
def AddError(self, infos): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
282 |
self.Errors[infos[0]] = infos[1:] |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
283 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
284 |
def ClearErrors(self): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
285 |
self.Errors = {} |
27 | 286 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
287 |
[ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
288 |
ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
289 |
ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
290 |
ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
291 |
ID_RESOURCEEDITORDOWNINSTANCEBUTTON, ID_RESOURCEEDITORADDTASKBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
292 |
ID_RESOURCEEDITORDELETETASKBUTTON, ID_RESOURCEEDITORUPTASKBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
293 |
ID_RESOURCEEDITORDOWNTASKBUTTON, |
27 | 294 |
] = [wx.NewId() for _init_ctrls in range(13)] |
295 |
||
296 |
class ResourceEditor(wx.Panel): |
|
297 |
||
113 | 298 |
if wx.VERSION < (2, 6, 0): |
299 |
def Bind(self, event, function, id = None): |
|
300 |
if id is not None: |
|
301 |
event(self, id, function) |
|
302 |
else: |
|
303 |
event(self, function) |
|
304 |
||
27 | 305 |
def _init_coll_InstancesSizer_Growables(self, parent): |
306 |
parent.AddGrowableCol(0) |
|
307 |
parent.AddGrowableRow(1) |
|
308 |
||
309 |
def _init_coll_InstancesSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
310 |
parent.AddSizer(self.InstancesButtonsSizer, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
311 |
parent.AddWindow(self.InstancesGrid, 0, border=0, flag=wx.GROW) |
27 | 312 |
|
313 |
def _init_coll_InstancesButtonsSizer_Growables(self, parent): |
|
314 |
parent.AddGrowableCol(0) |
|
315 |
parent.AddGrowableRow(0) |
|
316 |
||
317 |
def _init_coll_InstancesButtonsSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
318 |
parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) |
27 | 319 |
parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0) |
320 |
parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0) |
|
321 |
parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0) |
|
322 |
parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0) |
|
323 |
||
324 |
def _init_coll_TasksSizer_Growables(self, parent): |
|
325 |
parent.AddGrowableCol(0) |
|
326 |
parent.AddGrowableRow(1) |
|
327 |
||
328 |
def _init_coll_TasksSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
329 |
parent.AddSizer(self.TasksButtonsSizer, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
330 |
parent.AddWindow(self.TasksGrid, 0, border=0, flag=wx.GROW) |
27 | 331 |
|
332 |
def _init_coll_TasksButtonsSizer_Growables(self, parent): |
|
333 |
parent.AddGrowableCol(0) |
|
334 |
parent.AddGrowableRow(0) |
|
335 |
||
336 |
def _init_coll_TasksButtonsSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
337 |
parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) |
27 | 338 |
parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0) |
339 |
parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0) |
|
340 |
parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0) |
|
341 |
parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0) |
|
342 |
||
343 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
124 | 344 |
parent.AddSizer(self.TasksSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
345 |
parent.AddSizer(self.InstancesSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
27 | 346 |
|
347 |
def _init_coll_MainGridSizer_Growables(self, parent): |
|
348 |
parent.AddGrowableCol(0) |
|
349 |
parent.AddGrowableRow(0) |
|
350 |
parent.AddGrowableRow(1) |
|
351 |
||
352 |
def _init_sizers(self): |
|
353 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
354 |
self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
355 |
self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
356 |
self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
357 |
self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
358 |
||
359 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
|
360 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
361 |
self._init_coll_InstancesSizer_Growables(self.InstancesSizer) |
|
362 |
self._init_coll_InstancesSizer_Items(self.InstancesSizer) |
|
363 |
self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer) |
|
364 |
self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer) |
|
365 |
self._init_coll_TasksSizer_Growables(self.TasksSizer) |
|
366 |
self._init_coll_TasksSizer_Items(self.TasksSizer) |
|
367 |
self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer) |
|
368 |
self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer) |
|
369 |
||
370 |
self.SetSizer(self.MainGridSizer) |
|
371 |
||
372 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
373 |
wx.Panel.__init__(self, id=ID_RESOURCEEDITOR, name='', parent=prnt, |
80 | 374 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) |
27 | 375 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
376 |
self.staticText1 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT1, |
27 | 377 |
label=u'Tasks:', name='staticText2', parent=self, pos=wx.Point(0, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
378 |
0), size=wx.Size(60, 17), style=wx.ALIGN_CENTER) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
379 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
380 |
self.TasksGrid = wx.grid.Grid(id=ID_RESOURCEEDITORTASKSGRID, |
27 | 381 |
name='TasksGrid', parent=self, pos=wx.Point(0, 0), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
382 |
size=wx.Size(-1, -1), style=wx.VSCROLL) |
27 | 383 |
self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
384 |
'Sans')) |
|
385 |
self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
386 |
False, 'Sans')) |
|
113 | 387 |
if wx.VERSION >= (2, 5, 0): |
388 |
self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange) |
|
389 |
else: |
|
390 |
wx.grid.EVT_GRID_CELL_CHANGE(self.TasksGrid, self.OnTasksGridCellChange) |
|
391 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
392 |
self.AddTaskButton = wx.Button(id=ID_RESOURCEEDITORADDTASKBUTTON, label='Add Task', |
27 | 393 |
name='AddTaskButton', parent=self, pos=wx.Point(0, 0), |
394 |
size=wx.Size(102, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
395 |
self.Bind(wx.EVT_BUTTON, self.OnAddTaskButton, id=ID_RESOURCEEDITORADDTASKBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
396 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
397 |
self.DeleteTaskButton = wx.Button(id=ID_RESOURCEEDITORDELETETASKBUTTON, label='Delete Task', |
27 | 398 |
name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0), |
399 |
size=wx.Size(102, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
400 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteTaskButton, id=ID_RESOURCEEDITORDELETETASKBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
401 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
402 |
self.UpTaskButton = wx.Button(id=ID_RESOURCEEDITORUPTASKBUTTON, label='^', |
27 | 403 |
name='UpTaskButton', parent=self, pos=wx.Point(0, 0), |
404 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
405 |
self.Bind(wx.EVT_BUTTON, self.OnUpTaskButton, id=ID_RESOURCEEDITORUPTASKBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
406 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
407 |
self.DownTaskButton = wx.Button(id=ID_RESOURCEEDITORDOWNTASKBUTTON, label='v', |
27 | 408 |
name='DownTaskButton', parent=self, pos=wx.Point(0, 0), |
409 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
410 |
self.Bind(wx.EVT_BUTTON, self.OnDownTaskButton, id=ID_RESOURCEEDITORDOWNTASKBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
411 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
412 |
self.staticText2 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT2, |
27 | 413 |
label=u'Instances:', name='staticText1', parent=self, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
414 |
pos=wx.Point(0, 0), size=wx.Size(85, 17), style=wx.ALIGN_CENTER) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
415 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
416 |
self.InstancesGrid = wx.grid.Grid(id=ID_RESOURCEEDITORINSTANCESGRID, |
27 | 417 |
name='InstancesGrid', parent=self, pos=wx.Point(0, 0), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
418 |
size=wx.Size(-1, -1), style=wx.VSCROLL) |
27 | 419 |
self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
420 |
'Sans')) |
|
421 |
self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
422 |
False, 'Sans')) |
|
113 | 423 |
if wx.VERSION >= (2, 5, 0): |
424 |
self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange) |
|
425 |
else: |
|
426 |
wx.grid.EVT_GRID_CELL_CHANGE(self.InstancesGrid, self.OnInstancesGridCellChange) |
|
427 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
428 |
self.AddInstanceButton = wx.Button(id=ID_RESOURCEEDITORADDINSTANCEBUTTON, label='Add Instance', |
27 | 429 |
name='AddInstanceButton', parent=self, pos=wx.Point(0, 0), |
430 |
size=wx.Size(122, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
431 |
self.Bind(wx.EVT_BUTTON, self.OnAddInstanceButton, id=ID_RESOURCEEDITORADDINSTANCEBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
432 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
433 |
self.DeleteInstanceButton = wx.Button(id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON, label='Delete Instance', |
27 | 434 |
name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0), |
435 |
size=wx.Size(122, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
436 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteInstanceButton, id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
437 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
438 |
self.UpInstanceButton = wx.Button(id=ID_RESOURCEEDITORUPINSTANCEBUTTON, label='^', |
27 | 439 |
name='UpInstanceButton', parent=self, pos=wx.Point(0, 0), |
440 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
441 |
self.Bind(wx.EVT_BUTTON, self.OnUpInstanceButton, id=ID_RESOURCEEDITORUPINSTANCEBUTTON) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
442 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
443 |
self.DownInstanceButton = wx.Button(id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON, label='v', |
27 | 444 |
name='DownInstanceButton', parent=self, pos=wx.Point(0, 0), |
445 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
446 |
self.Bind(wx.EVT_BUTTON, self.OnDownInstanceButton, id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON) |
27 | 447 |
|
448 |
self._init_sizers() |
|
449 |
||
121 | 450 |
def __init__(self, parent, tagname, window, controler): |
27 | 451 |
self._init_ctrls(parent) |
452 |
||
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
453 |
self.ParentWindow = window |
27 | 454 |
self.Controler = controler |
121 | 455 |
self.TagName = tagname |
27 | 456 |
|
457 |
self.TasksDefaultValue = {"Name" : "", "Single" : "", "Interval" : "", "Priority" : 0} |
|
458 |
self.TasksTable = ResourceTable(self, [], ["Name", "Single", "Interval", "Priority"]) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
459 |
self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
27 | 460 |
self.TasksTable.SetColSizes([200, 100, 100, 100]) |
461 |
self.TasksGrid.SetTable(self.TasksTable) |
|
462 |
self.TasksGrid.SetRowLabelSize(0) |
|
463 |
self.TasksTable.ResetView(self.TasksGrid) |
|
464 |
||
465 |
self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""} |
|
466 |
self.InstancesTable = ResourceTable(self, [], ["Name", "Type", "Task"]) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
467 |
self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
27 | 468 |
self.InstancesTable.SetColSizes([200, 150, 150]) |
469 |
self.InstancesGrid.SetTable(self.InstancesTable) |
|
470 |
self.InstancesGrid.SetRowLabelSize(0) |
|
471 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
472 |
||
121 | 473 |
def SetTagName(self, tagname): |
474 |
self.TagName = tagname |
|
475 |
||
476 |
def GetTagName(self): |
|
477 |
return self.TagName |
|
478 |
||
479 |
def IsViewing(self, tagname): |
|
480 |
return self.TagName == tagname |
|
481 |
||
27 | 482 |
def SetMode(self, mode): |
483 |
pass |
|
484 |
||
485 |
def RefreshTypeList(self): |
|
486 |
self.TypeList = "" |
|
487 |
blocktypes = self.Controler.GetBlockResource() |
|
488 |
for blocktype in blocktypes: |
|
489 |
self.TypeList += ",%s"%blocktype |
|
490 |
||
491 |
def RefreshTaskList(self): |
|
492 |
self.TaskList = "" |
|
493 |
for row in xrange(self.TasksTable.GetNumberRows()): |
|
494 |
self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name") |
|
495 |
||
496 |
def RefreshVariableList(self): |
|
497 |
self.VariableList = "" |
|
121 | 498 |
for variable in self.Controler.GetEditedResourceVariables(self.TagName): |
27 | 499 |
self.VariableList += ",%s"%variable |
500 |
||
501 |
def RefreshModel(self): |
|
121 | 502 |
self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData()) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
503 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
504 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
505 |
def ResetBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
506 |
pass |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
507 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
508 |
# Buffer the last model state |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
509 |
def RefreshBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
510 |
self.Controler.BufferProject() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
511 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
512 |
self.ParentWindow.RefreshEditMenu() |
27 | 513 |
|
514 |
def RefreshView(self): |
|
121 | 515 |
tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName) |
27 | 516 |
self.TasksTable.SetData(tasks) |
517 |
self.InstancesTable.SetData(instances) |
|
518 |
self.RefreshTypeList() |
|
519 |
self.RefreshTaskList() |
|
520 |
self.RefreshVariableList() |
|
521 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
522 |
self.TasksTable.ResetView(self.TasksGrid) |
|
523 |
||
145 | 524 |
def RefreshScaling(self, refresh=True): |
525 |
pass |
|
526 |
||
27 | 527 |
def OnAddTaskButton(self, event): |
528 |
self.TasksTable.AppendRow(self.TasksDefaultValue.copy()) |
|
529 |
self.RefreshModel() |
|
145 | 530 |
self.RefreshView() |
27 | 531 |
event.Skip() |
532 |
||
533 |
def OnDeleteTaskButton(self, event): |
|
534 |
row = self.TasksGrid.GetGridCursorRow() |
|
535 |
self.TasksTable.RemoveRow(row) |
|
536 |
self.RefreshModel() |
|
537 |
self.RefreshView() |
|
538 |
event.Skip() |
|
539 |
||
540 |
def OnUpTaskButton(self, event): |
|
541 |
row = self.TasksGrid.GetGridCursorRow() |
|
542 |
self.TasksTable.MoveRow(row, -1, self.TasksGrid) |
|
543 |
self.RefreshModel() |
|
544 |
self.RefreshView() |
|
545 |
event.Skip() |
|
546 |
||
547 |
def OnDownTaskButton(self, event): |
|
548 |
row = self.TasksGrid.GetGridCursorRow() |
|
549 |
self.TasksTable.MoveRow(row, 1, self.TasksGrid) |
|
550 |
self.RefreshModel() |
|
551 |
self.RefreshView() |
|
552 |
event.Skip() |
|
553 |
||
554 |
def OnAddInstanceButton(self, event): |
|
555 |
self.InstancesTable.AppendRow(self.InstancesDefaultValue.copy()) |
|
556 |
self.RefreshModel() |
|
557 |
self.RefreshView() |
|
558 |
event.Skip() |
|
559 |
||
560 |
def OnDeleteInstanceButton(self, event): |
|
561 |
row = self.InstancesGrid.GetGridCursorRow() |
|
562 |
self.InstancesTable.RemoveRow(row) |
|
563 |
self.RefreshModel() |
|
564 |
self.RefreshView() |
|
565 |
event.Skip() |
|
566 |
||
567 |
def OnUpInstanceButton(self, event): |
|
568 |
row = self.InstancesGrid.GetGridCursorRow() |
|
569 |
self.InstancesTable.MoveRow(row, -1, self.InstancesGrid) |
|
570 |
self.RefreshModel() |
|
571 |
self.RefreshView() |
|
572 |
event.Skip() |
|
573 |
||
574 |
def OnDownInstanceButton(self, event): |
|
575 |
row = self.InstancesGrid.GetGridCursorRow() |
|
576 |
self.InstancesTable.MoveRow(row, 1, self.InstancesGrid) |
|
577 |
self.RefreshModel() |
|
578 |
self.RefreshView() |
|
579 |
event.Skip() |
|
580 |
||
581 |
def OnTasksGridCellChange(self, event): |
|
582 |
row, col = event.GetRow(), event.GetCol() |
|
583 |
if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name": |
|
584 |
tasklist = self.TaskList.split(",") |
|
585 |
for i in xrange(self.TasksTable.GetNumberRows()): |
|
586 |
task = self.TasksTable.GetValueByName(i, "Name") |
|
587 |
if task in tasklist: |
|
588 |
tasklist.remove(task) |
|
589 |
tasklist.remove("") |
|
590 |
if len(tasklist) > 0: |
|
591 |
old_name = tasklist[0] |
|
592 |
new_name = self.TasksTable.GetValue(row, col) |
|
593 |
for i in xrange(self.InstancesTable.GetNumberRows()): |
|
594 |
if self.InstancesTable.GetValueByName(i, "Task") == old_name: |
|
595 |
self.InstancesTable.SetValueByName(i, "Task", new_name) |
|
596 |
self.RefreshModel() |
|
597 |
self.RefreshView() |
|
598 |
event.Skip() |
|
599 |
||
600 |
def OnInstancesGridCellChange(self, event): |
|
601 |
self.RefreshModel() |
|
602 |
self.RefreshView() |
|
603 |
event.Skip() |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
604 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
605 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
606 |
# Errors showing functions |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
607 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
608 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
609 |
def ClearErrors(self): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
610 |
self.TasksTable.ClearErrors() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
611 |
self.InstancesTable.ClearErrors() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
612 |
self.TasksTable.ResetView(self.TasksGrid) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
613 |
self.InstancesTable.ResetView(self.InstancesGrid) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
614 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
615 |
def AddShownError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
616 |
if infos[0] == "task": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
617 |
self.TasksTable.AddError(infos[1:]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
618 |
elif infos[0] == "instance": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
619 |
self.InstancesTable.AddError(infos[1:]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
620 |