author | laurent |
Mon, 24 Oct 2011 02:00:34 +0200 | |
changeset 580 | ad996deb920e |
parent 579 | bc333e073aa3 |
child 586 | 9aa96a36cf33 |
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 |
|
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
28 |
from dialogs import DurationEditorDialog |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
29 |
from controls import CustomGrid |
121 | 30 |
|
31 |
#------------------------------------------------------------------------------- |
|
32 |
# Configuration Editor class |
|
33 |
#------------------------------------------------------------------------------- |
|
34 |
||
35 |
[ID_CONFIGURATIONEDITOR, |
|
36 |
] = [wx.NewId() for _init_ctrls in range(1)] |
|
37 |
||
38 |
class ConfigurationEditor(wx.Panel): |
|
39 |
||
40 |
def _init_ctrls(self, prnt): |
|
41 |
wx.Panel.__init__(self, id=ID_CONFIGURATIONEDITOR, name='', parent=prnt, |
|
42 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) |
|
43 |
||
44 |
def __init__(self, parent, tagname, window, controler): |
|
45 |
self._init_ctrls(parent) |
|
46 |
||
47 |
self.ParentWindow = window |
|
48 |
self.Controler = controler |
|
49 |
self.TagName = tagname |
|
50 |
||
51 |
def SetTagName(self, tagname): |
|
52 |
self.TagName = tagname |
|
53 |
||
54 |
def GetTagName(self): |
|
55 |
return self.TagName |
|
56 |
||
57 |
def IsViewing(self, tagname): |
|
58 |
return self.TagName == tagname |
|
59 |
||
407
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
60 |
def IsDebugging(self): |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
61 |
return False |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
62 |
|
121 | 63 |
def SetMode(self, mode): |
64 |
pass |
|
65 |
||
66 |
def ResetBuffer(self): |
|
67 |
pass |
|
68 |
||
69 |
def RefreshView(self): |
|
70 |
pass |
|
71 |
||
145 | 72 |
def RefreshScaling(self, refresh=True): |
73 |
pass |
|
74 |
||
579 | 75 |
def ClearHighlights(self, highlight_type=None): |
365 | 76 |
pass |
77 |
||
27 | 78 |
#------------------------------------------------------------------------------- |
79 |
# Resource Editor class |
|
80 |
#------------------------------------------------------------------------------- |
|
81 |
||
391 | 82 |
def GetTasksTableColnames(): |
83 |
_ = lambda x : x |
|
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
84 |
return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")] |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
85 |
|
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
86 |
def GetTaskTriggeringOptions(): |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
87 |
_ = lambda x : x |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
88 |
return [_("Interrupt"), _("Cyclic")] |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
89 |
TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()]) |
391 | 90 |
|
91 |
def GetInstancesTableColnames(): |
|
92 |
_ = lambda x : x |
|
93 |
return [_("Name"), _("Type"), _("Task")] |
|
94 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
95 |
class ResourceTable(wx.grid.PyGridTableBase): |
27 | 96 |
|
97 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
98 |
A custom wx.grid.Grid Table using user supplied data |
27 | 99 |
""" |
100 |
def __init__(self, parent, data, colnames): |
|
101 |
# The base class must be initialized *first* |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
102 |
wx.grid.PyGridTableBase.__init__(self) |
27 | 103 |
self.data = data |
104 |
self.colnames = colnames |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
105 |
self.Highlights = {} |
27 | 106 |
self.Parent = parent |
107 |
||
108 |
self.ColAlignements = [] |
|
109 |
self.ColSizes = [] |
|
110 |
# XXX |
|
111 |
# we need to store the row length and collength to |
|
112 |
# see if the table has changed size |
|
113 |
self._rows = self.GetNumberRows() |
|
114 |
self._cols = self.GetNumberCols() |
|
115 |
||
116 |
def GetColAlignements(self): |
|
117 |
return self.ColAlignements |
|
118 |
||
119 |
def SetColAlignements(self, list): |
|
120 |
self.ColAlignements = list |
|
121 |
||
122 |
def GetColSizes(self): |
|
123 |
return self.ColSizes |
|
124 |
||
125 |
def SetColSizes(self, list): |
|
126 |
self.ColSizes = list |
|
127 |
||
128 |
def GetNumberCols(self): |
|
129 |
return len(self.colnames) |
|
130 |
||
131 |
def GetNumberRows(self): |
|
132 |
return len(self.data) |
|
133 |
||
391 | 134 |
def GetColLabelValue(self, col, translate=True): |
27 | 135 |
if col < len(self.colnames): |
391 | 136 |
if translate: |
137 |
return _(self.colnames[col]) |
|
27 | 138 |
return self.colnames[col] |
139 |
||
391 | 140 |
def GetRowLabelValues(self, row, translate=True): |
27 | 141 |
return row |
142 |
||
143 |
def GetValue(self, row, col): |
|
144 |
if row < self.GetNumberRows(): |
|
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
145 |
colname = self.GetColLabelValue(col, False) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
146 |
value = str(self.data[row].get(colname, "")) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
147 |
if colname == "Triggering": |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
148 |
return _(value) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
149 |
return value |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
150 |
|
27 | 151 |
def GetValueByName(self, row, colname): |
152 |
return self.data[row].get(colname) |
|
153 |
||
154 |
def SetValue(self, row, col, value): |
|
155 |
if col < len(self.colnames): |
|
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
156 |
colname = self.GetColLabelValue(col, False) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
157 |
if colname == "Triggering": |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
158 |
value = TASKTRIGGERINGOPTIONS_DICT[value] |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
159 |
self.data[row][colname] = value |
27 | 160 |
|
161 |
def SetValueByName(self, row, colname, value): |
|
162 |
if colname in self.colnames: |
|
163 |
self.data[row][colname] = value |
|
164 |
||
165 |
def ResetView(self, grid): |
|
166 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
167 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
27 | 168 |
update the grid if rows and columns have been added or deleted |
169 |
""" |
|
170 |
grid.BeginBatch() |
|
171 |
for current, new, delmsg, addmsg in [ |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
172 |
(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
|
173 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
27 | 174 |
]: |
175 |
if new < current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
176 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
27 | 177 |
grid.ProcessTableMessage(msg) |
178 |
elif 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,addmsg,new-current) |
27 | 180 |
grid.ProcessTableMessage(msg) |
181 |
self.UpdateValues(grid) |
|
182 |
grid.EndBatch() |
|
183 |
||
184 |
self._rows = self.GetNumberRows() |
|
185 |
self._cols = self.GetNumberCols() |
|
186 |
# update the column rendering scheme |
|
187 |
self._updateColAttrs(grid) |
|
188 |
||
189 |
# update the scrollbars and the displayed part of the grid |
|
190 |
grid.AdjustScrollbars() |
|
191 |
grid.ForceRefresh() |
|
192 |
||
193 |
def UpdateValues(self, grid): |
|
194 |
"""Update all displayed values""" |
|
195 |
# 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
|
196 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
27 | 197 |
grid.ProcessTableMessage(msg) |
198 |
||
199 |
def _updateColAttrs(self, grid): |
|
200 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
201 |
wx.grid.Grid -> update the column attributes to add the |
27 | 202 |
appropriate renderer given the column name. |
203 |
||
204 |
Otherwise default to the default renderer. |
|
205 |
""" |
|
206 |
||
207 |
for col in range(self.GetNumberCols()): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
208 |
attr = wx.grid.GridCellAttr() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
209 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
27 | 210 |
grid.SetColAttr(col, attr) |
211 |
grid.SetColSize(col, self.ColSizes[col]) |
|
212 |
||
213 |
for row in range(self.GetNumberRows()): |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
214 |
row_highlights = self.Highlights.get(row, {}) |
27 | 215 |
for col in range(self.GetNumberCols()): |
216 |
editor = None |
|
217 |
renderer = None |
|
391 | 218 |
colname = self.GetColLabelValue(col, False) |
27 | 219 |
grid.SetReadOnly(row, col, False) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
220 |
if colname == "Name": |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
221 |
editor = wx.grid.GridCellTextEditor() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
222 |
renderer = wx.grid.GridCellStringRenderer() |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
223 |
elif colname == "Interval": |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
224 |
editor = DurationCellEditor(self) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
225 |
renderer = wx.grid.GridCellStringRenderer() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
226 |
if self.GetValueByName(row, "Triggering") != "Cyclic": |
27 | 227 |
grid.SetReadOnly(row, col, True) |
228 |
elif colname == "Single": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
229 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 230 |
editor.SetParameters(self.Parent.VariableList) |
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
231 |
if self.GetValueByName(row, "Triggering") != "Interrupt": |
27 | 232 |
grid.SetReadOnly(row, col, True) |
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
233 |
elif colname == "Triggering": |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
234 |
editor = wx.grid.GridCellChoiceEditor() |
578
73138d14d88d
Fix bug with internationalization in ResourceEditor
laurent
parents:
577
diff
changeset
|
235 |
editor.SetParameters(",".join([""] + map(_, GetTaskTriggeringOptions()))) |
27 | 236 |
elif colname == "Type": |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
237 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 238 |
editor.SetParameters(self.Parent.TypeList) |
239 |
elif colname == "Priority": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
240 |
editor = wx.grid.GridCellNumberEditor() |
27 | 241 |
editor.SetParameters("0,65535") |
242 |
elif colname == "Task": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
243 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 244 |
editor.SetParameters(self.Parent.TaskList) |
245 |
||
246 |
grid.SetCellEditor(row, col, editor) |
|
247 |
grid.SetCellRenderer(row, col, renderer) |
|
248 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
249 |
highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
250 |
grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
251 |
grid.SetCellTextColour(row, col, highlight_colours[1]) |
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
252 |
if wx.Platform == '__WXMSW__': |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
253 |
grid.SetRowMinimalHeight(row, 20) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
254 |
else: |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
255 |
grid.SetRowMinimalHeight(row, 28) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
256 |
grid.AutoSizeRow(row, False) |
27 | 257 |
|
258 |
def SetData(self, data): |
|
259 |
self.data = data |
|
260 |
||
261 |
def GetData(self): |
|
262 |
return self.data |
|
263 |
||
264 |
def GetCurrentIndex(self): |
|
265 |
return self.CurrentIndex |
|
266 |
||
267 |
def SetCurrentIndex(self, index): |
|
268 |
self.CurrentIndex = index |
|
269 |
||
270 |
def AppendRow(self, row_content): |
|
271 |
self.data.append(row_content) |
|
272 |
||
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
273 |
def InsertRow(self, index, row_content): |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
274 |
self.data.insert(index, row_content) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
275 |
|
27 | 276 |
def RemoveRow(self, row_index): |
277 |
self.data.pop(row_index) |
|
278 |
||
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
279 |
def MoveRow(self, row_index, move): |
27 | 280 |
new_index = max(0, min(row_index + move, len(self.data) - 1)) |
281 |
if new_index != row_index: |
|
282 |
self.data.insert(new_index, self.data.pop(row_index)) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
283 |
return new_index |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
284 |
|
27 | 285 |
def Empty(self): |
286 |
self.data = [] |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
287 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
288 |
#------------------------------------------------------------------------------- |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
289 |
# Highlights showing functions |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
290 |
#------------------------------------------------------------------------------- |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
291 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
292 |
def AddHighlight(self, infos, highlight_type): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
293 |
row_highlights = self.Highlights.setdefault(infos[0], {}) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
294 |
col_highlights = row_highlights.setdefault(infos[1], []) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
295 |
col_highlights.append(highlight_type) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
296 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
297 |
def ClearHighlights(self, highlight_type=None): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
298 |
if highlight_type is None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
299 |
self.Highlights = {} |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
300 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
301 |
for row, row_highlights in self.Highlights.iteritems(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
302 |
row_items = row_highlights.items() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
303 |
for col, col_highlights in row_items: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
304 |
if highlight_type in col_highlights: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
305 |
col_highlights.remove(highlight_type) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
306 |
if len(col_highlights) == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
307 |
row_highlights.pop(col) |
27 | 308 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
309 |
[ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
310 |
ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
311 |
ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
312 |
ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
313 |
ID_RESOURCEEDITORDOWNINSTANCEBUTTON, ID_RESOURCEEDITORADDTASKBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
314 |
ID_RESOURCEEDITORDELETETASKBUTTON, ID_RESOURCEEDITORUPTASKBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
315 |
ID_RESOURCEEDITORDOWNTASKBUTTON, |
27 | 316 |
] = [wx.NewId() for _init_ctrls in range(13)] |
317 |
||
318 |
class ResourceEditor(wx.Panel): |
|
319 |
||
113 | 320 |
if wx.VERSION < (2, 6, 0): |
321 |
def Bind(self, event, function, id = None): |
|
322 |
if id is not None: |
|
323 |
event(self, id, function) |
|
324 |
else: |
|
325 |
event(self, function) |
|
326 |
||
27 | 327 |
def _init_coll_InstancesSizer_Growables(self, parent): |
328 |
parent.AddGrowableCol(0) |
|
329 |
parent.AddGrowableRow(1) |
|
330 |
||
331 |
def _init_coll_InstancesSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
332 |
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
|
333 |
parent.AddWindow(self.InstancesGrid, 0, border=0, flag=wx.GROW) |
27 | 334 |
|
335 |
def _init_coll_InstancesButtonsSizer_Growables(self, parent): |
|
336 |
parent.AddGrowableCol(0) |
|
337 |
parent.AddGrowableRow(0) |
|
338 |
||
339 |
def _init_coll_InstancesButtonsSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
340 |
parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) |
27 | 341 |
parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0) |
342 |
parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0) |
|
343 |
parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0) |
|
344 |
parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0) |
|
345 |
||
346 |
def _init_coll_TasksSizer_Growables(self, parent): |
|
347 |
parent.AddGrowableCol(0) |
|
348 |
parent.AddGrowableRow(1) |
|
349 |
||
350 |
def _init_coll_TasksSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
351 |
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
|
352 |
parent.AddWindow(self.TasksGrid, 0, border=0, flag=wx.GROW) |
27 | 353 |
|
354 |
def _init_coll_TasksButtonsSizer_Growables(self, parent): |
|
355 |
parent.AddGrowableCol(0) |
|
356 |
parent.AddGrowableRow(0) |
|
357 |
||
358 |
def _init_coll_TasksButtonsSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
359 |
parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) |
27 | 360 |
parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0) |
361 |
parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0) |
|
362 |
parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0) |
|
363 |
parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0) |
|
364 |
||
365 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
124 | 366 |
parent.AddSizer(self.TasksSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
367 |
parent.AddSizer(self.InstancesSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
27 | 368 |
|
369 |
def _init_coll_MainGridSizer_Growables(self, parent): |
|
370 |
parent.AddGrowableCol(0) |
|
371 |
parent.AddGrowableRow(0) |
|
372 |
parent.AddGrowableRow(1) |
|
373 |
||
374 |
def _init_sizers(self): |
|
375 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
376 |
self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
377 |
self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
378 |
self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
379 |
self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
380 |
||
381 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
|
382 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
383 |
self._init_coll_InstancesSizer_Growables(self.InstancesSizer) |
|
384 |
self._init_coll_InstancesSizer_Items(self.InstancesSizer) |
|
385 |
self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer) |
|
386 |
self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer) |
|
387 |
self._init_coll_TasksSizer_Growables(self.TasksSizer) |
|
388 |
self._init_coll_TasksSizer_Items(self.TasksSizer) |
|
389 |
self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer) |
|
390 |
self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer) |
|
391 |
||
392 |
self.SetSizer(self.MainGridSizer) |
|
393 |
||
394 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
395 |
wx.Panel.__init__(self, id=ID_RESOURCEEDITOR, name='', parent=prnt, |
80 | 396 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) |
27 | 397 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
398 |
self.staticText1 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT1, |
391 | 399 |
label=_(u'Tasks:'), name='staticText2', parent=self, pos=wx.Point(0, |
400 |
0), size=wx.DefaultSize, style=wx.ALIGN_CENTER) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
401 |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
402 |
self.TasksGrid = CustomGrid(id=ID_RESOURCEEDITORTASKSGRID, |
27 | 403 |
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
|
404 |
size=wx.Size(-1, -1), style=wx.VSCROLL) |
27 | 405 |
self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
406 |
'Sans')) |
|
407 |
self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
408 |
False, 'Sans')) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
409 |
if wx.VERSION >= (2, 6, 0): |
113 | 410 |
self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange) |
411 |
else: |
|
412 |
wx.grid.EVT_GRID_CELL_CHANGE(self.TasksGrid, self.OnTasksGridCellChange) |
|
413 |
||
391 | 414 |
self.AddTaskButton = wx.Button(id=ID_RESOURCEEDITORADDTASKBUTTON, label=_('Add Task'), |
27 | 415 |
name='AddTaskButton', parent=self, pos=wx.Point(0, 0), |
391 | 416 |
size=wx.DefaultSize, style=0) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
417 |
|
391 | 418 |
self.DeleteTaskButton = wx.Button(id=ID_RESOURCEEDITORDELETETASKBUTTON, label=_('Delete Task'), |
27 | 419 |
name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0), |
391 | 420 |
size=wx.DefaultSize, style=0) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
421 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
422 |
self.UpTaskButton = wx.Button(id=ID_RESOURCEEDITORUPTASKBUTTON, label='^', |
27 | 423 |
name='UpTaskButton', parent=self, pos=wx.Point(0, 0), |
424 |
size=wx.Size(32, 32), style=0) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
425 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
426 |
self.DownTaskButton = wx.Button(id=ID_RESOURCEEDITORDOWNTASKBUTTON, label='v', |
27 | 427 |
name='DownTaskButton', parent=self, pos=wx.Point(0, 0), |
428 |
size=wx.Size(32, 32), style=0) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
429 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
430 |
self.staticText2 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT2, |
391 | 431 |
label=_(u'Instances:'), name='staticText1', parent=self, |
432 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=wx.ALIGN_CENTER) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
433 |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
434 |
self.InstancesGrid = CustomGrid(id=ID_RESOURCEEDITORINSTANCESGRID, |
27 | 435 |
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
|
436 |
size=wx.Size(-1, -1), style=wx.VSCROLL) |
27 | 437 |
self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
438 |
'Sans')) |
|
439 |
self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
440 |
False, 'Sans')) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
441 |
if wx.VERSION >= (2, 6, 0): |
113 | 442 |
self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange) |
443 |
else: |
|
444 |
wx.grid.EVT_GRID_CELL_CHANGE(self.InstancesGrid, self.OnInstancesGridCellChange) |
|
445 |
||
391 | 446 |
self.AddInstanceButton = wx.Button(id=ID_RESOURCEEDITORADDINSTANCEBUTTON, label=_('Add Instance'), |
27 | 447 |
name='AddInstanceButton', parent=self, pos=wx.Point(0, 0), |
391 | 448 |
size=wx.DefaultSize, style=0) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
449 |
|
391 | 450 |
self.DeleteInstanceButton = wx.Button(id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON, label=_('Delete Instance'), |
27 | 451 |
name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0), |
391 | 452 |
size=wx.DefaultSize, style=0) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
453 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
454 |
self.UpInstanceButton = wx.Button(id=ID_RESOURCEEDITORUPINSTANCEBUTTON, label='^', |
27 | 455 |
name='UpInstanceButton', parent=self, pos=wx.Point(0, 0), |
456 |
size=wx.Size(32, 32), style=0) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
457 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
458 |
self.DownInstanceButton = wx.Button(id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON, label='v', |
27 | 459 |
name='DownInstanceButton', parent=self, pos=wx.Point(0, 0), |
460 |
size=wx.Size(32, 32), style=0) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
461 |
|
27 | 462 |
self._init_sizers() |
463 |
||
121 | 464 |
def __init__(self, parent, tagname, window, controler): |
27 | 465 |
self._init_ctrls(parent) |
466 |
||
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
467 |
self.ParentWindow = window |
27 | 468 |
self.Controler = controler |
121 | 469 |
self.TagName = tagname |
27 | 470 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
471 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
472 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
473 |
|
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
474 |
self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0} |
391 | 475 |
self.TasksTable = ResourceTable(self, [], GetTasksTableColnames()) |
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
476 |
self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
477 |
self.TasksTable.SetColSizes([200, 100, 100, 150, 100]) |
27 | 478 |
self.TasksGrid.SetTable(self.TasksTable) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
479 |
self.TasksGrid.SetButtons({"Add": self.AddTaskButton, |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
480 |
"Delete": self.DeleteTaskButton, |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
481 |
"Up": self.UpTaskButton, |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
482 |
"Down": self.DownTaskButton}) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
483 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
484 |
def _AddTask(new_row): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
485 |
self.TasksTable.InsertRow(new_row, self.TasksDefaultValue.copy()) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
486 |
self.RefreshModel() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
487 |
self.RefreshView() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
488 |
return new_row |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
489 |
setattr(self.TasksGrid, "_AddRow", _AddTask) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
490 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
491 |
def _DeleteTask(row): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
492 |
self.TasksTable.RemoveRow(row) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
493 |
self.RefreshModel() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
494 |
self.RefreshView() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
495 |
setattr(self.TasksGrid, "_DeleteRow", _DeleteTask) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
496 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
497 |
def _MoveTask(row, move): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
498 |
new_row = self.TasksTable.MoveRow(row, move) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
499 |
if new_row != row: |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
500 |
self.RefreshModel() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
501 |
self.RefreshView() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
502 |
return new_row |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
503 |
setattr(self.TasksGrid, "_MoveRow", _MoveTask) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
504 |
|
27 | 505 |
self.TasksGrid.SetRowLabelSize(0) |
506 |
self.TasksTable.ResetView(self.TasksGrid) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
507 |
self.TasksGrid.RefreshButtons() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
508 |
|
27 | 509 |
self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""} |
391 | 510 |
self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames()) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
511 |
self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
27 | 512 |
self.InstancesTable.SetColSizes([200, 150, 150]) |
513 |
self.InstancesGrid.SetTable(self.InstancesTable) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
514 |
self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton, |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
515 |
"Delete": self.DeleteInstanceButton, |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
516 |
"Up": self.UpInstanceButton, |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
517 |
"Down": self.DownInstanceButton}) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
518 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
519 |
def _AddInstance(new_row): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
520 |
self.InstancesTable.InsertRow(new_row, self.InstancesDefaultValue.copy()) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
521 |
self.RefreshModel() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
522 |
self.RefreshView() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
523 |
return new_row |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
524 |
setattr(self.InstancesGrid, "_AddRow", _AddInstance) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
525 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
526 |
def _DeleteInstance(row): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
527 |
self.InstancesTable.RemoveRow(row) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
528 |
self.RefreshModel() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
529 |
self.RefreshView() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
530 |
setattr(self.InstancesGrid, "_DeleteRow", _DeleteInstance) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
531 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
532 |
def _MoveInstance(row, move): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
533 |
new_row = max(0, min(row + move, self.InstancesTable.GetNumberRows() - 1)) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
534 |
if new_row != row: |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
535 |
if self.InstancesTable.GetValueByName(row, "Task") != self.InstancesTable.GetValueByName(new_row, "Task"): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
536 |
return row |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
537 |
self.InstancesTable.MoveRow(row, move) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
538 |
self.RefreshModel() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
539 |
self.RefreshView() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
540 |
return new_row |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
541 |
setattr(self.InstancesGrid, "_MoveRow", _MoveInstance) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
542 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
543 |
def _RefreshInstanceButtons(): |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
544 |
rows = self.InstancesTable.GetNumberRows() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
545 |
row = self.InstancesGrid.GetGridCursorRow() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
546 |
self.DeleteInstanceButton.Enable(rows > 0) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
547 |
self.UpInstanceButton.Enable(row > 0 and |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
548 |
self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task")) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
549 |
self.DownInstanceButton.Enable(0 <= row < rows - 1 and |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
550 |
self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task")) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
551 |
setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons) |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
552 |
|
27 | 553 |
self.InstancesGrid.SetRowLabelSize(0) |
554 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
555 |
self.InstancesGrid.RefreshButtons() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
556 |
|
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
557 |
self.TasksGrid.SetFocus() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
558 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
559 |
def __del__(self): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
560 |
self.RefreshHighlightsTimer.Stop() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
561 |
|
121 | 562 |
def SetTagName(self, tagname): |
563 |
self.TagName = tagname |
|
564 |
||
565 |
def GetTagName(self): |
|
566 |
return self.TagName |
|
567 |
||
568 |
def IsViewing(self, tagname): |
|
569 |
return self.TagName == tagname |
|
570 |
||
407
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
571 |
def IsDebugging(self): |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
572 |
return False |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
573 |
|
27 | 574 |
def SetMode(self, mode): |
575 |
pass |
|
576 |
||
577 |
def RefreshTypeList(self): |
|
578 |
self.TypeList = "" |
|
579 |
blocktypes = self.Controler.GetBlockResource() |
|
580 |
for blocktype in blocktypes: |
|
581 |
self.TypeList += ",%s"%blocktype |
|
582 |
||
583 |
def RefreshTaskList(self): |
|
584 |
self.TaskList = "" |
|
585 |
for row in xrange(self.TasksTable.GetNumberRows()): |
|
586 |
self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name") |
|
587 |
||
588 |
def RefreshVariableList(self): |
|
589 |
self.VariableList = "" |
|
121 | 590 |
for variable in self.Controler.GetEditedResourceVariables(self.TagName): |
27 | 591 |
self.VariableList += ",%s"%variable |
592 |
||
593 |
def RefreshModel(self): |
|
121 | 594 |
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
|
595 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
596 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
597 |
def ResetBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
598 |
pass |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
599 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
600 |
# Buffer the last model state |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
601 |
def RefreshBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
602 |
self.Controler.BufferProject() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
603 |
self.ParentWindow.RefreshTitle() |
494
c91644c2bfa7
Bug on FileMenu not refreshed when modifications fixed
laurent
parents:
407
diff
changeset
|
604 |
self.ParentWindow.RefreshFileMenu() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
605 |
self.ParentWindow.RefreshEditMenu() |
27 | 606 |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
607 |
def RefreshView(self): |
121 | 608 |
tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName) |
27 | 609 |
self.TasksTable.SetData(tasks) |
610 |
self.InstancesTable.SetData(instances) |
|
611 |
self.RefreshTypeList() |
|
612 |
self.RefreshTaskList() |
|
613 |
self.RefreshVariableList() |
|
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
614 |
self.TasksTable.ResetView(self.TasksGrid) |
27 | 615 |
self.InstancesTable.ResetView(self.InstancesGrid) |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
616 |
self.TasksGrid.RefreshButtons() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
617 |
self.InstancesGrid.RefreshButtons() |
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
618 |
|
145 | 619 |
def RefreshScaling(self, refresh=True): |
620 |
pass |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
621 |
|
27 | 622 |
def OnTasksGridCellChange(self, event): |
623 |
row, col = event.GetRow(), event.GetCol() |
|
624 |
if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name": |
|
625 |
tasklist = self.TaskList.split(",") |
|
626 |
for i in xrange(self.TasksTable.GetNumberRows()): |
|
627 |
task = self.TasksTable.GetValueByName(i, "Name") |
|
628 |
if task in tasklist: |
|
629 |
tasklist.remove(task) |
|
630 |
tasklist.remove("") |
|
631 |
if len(tasklist) > 0: |
|
632 |
old_name = tasklist[0] |
|
633 |
new_name = self.TasksTable.GetValue(row, col) |
|
634 |
for i in xrange(self.InstancesTable.GetNumberRows()): |
|
635 |
if self.InstancesTable.GetValueByName(i, "Task") == old_name: |
|
636 |
self.InstancesTable.SetValueByName(i, "Task", new_name) |
|
637 |
self.RefreshModel() |
|
560
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
638 |
colname = self.TasksTable.GetColLabelValue(col, False) |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
639 |
if colname == "Triggering": |
3757f0de0d07
Adding column for selecting task triggering in Resource Editor
laurent
parents:
494
diff
changeset
|
640 |
wx.CallAfter(self.RefreshView) |
27 | 641 |
event.Skip() |
642 |
||
643 |
def OnInstancesGridCellChange(self, event): |
|
644 |
self.RefreshModel() |
|
239
d12779e971bd
Adding support for function and functionBlock (standard or user) library
lbessard
parents:
235
diff
changeset
|
645 |
self.ParentWindow.RefreshInstancesTree() |
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
573
diff
changeset
|
646 |
self.InstancesGrid.RefreshButtons() |
27 | 647 |
event.Skip() |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
648 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
649 |
#------------------------------------------------------------------------------- |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
650 |
# Highlights showing functions |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
651 |
#------------------------------------------------------------------------------- |
573 | 652 |
|
653 |
def OnRefreshHighlightsTimer(self, event): |
|
654 |
self.RefreshView() |
|
655 |
event.Skip() |
|
656 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
657 |
def AddHighlight(self, infos, start, end, highlight_type): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
658 |
if infos[0] == "task": |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
659 |
self.TasksTable.AddHighlight(infos[1:], highlight_type) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
660 |
elif infos[0] == "instance": |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
661 |
self.InstancesTable.AddHighlight(infos[1:], highlight_type) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
662 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
663 |
def ClearHighlights(self, highlight_type=None): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
664 |
self.TasksTable.ClearHighlights(highlight_type) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
665 |
self.InstancesTable.ClearHighlights(highlight_type) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
666 |
self.TasksTable.ResetView(self.TasksGrid) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
564
diff
changeset
|
667 |
self.InstancesTable.ResetView(self.InstancesGrid) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
668 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
669 |
class DurationCellControl(wx.PyControl): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
670 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
671 |
def _init_coll_MainSizer_Items(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
672 |
parent.AddWindow(self.Duration, 0, border=0, flag=wx.GROW) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
673 |
parent.AddWindow(self.EditButton, 0, border=0, flag=wx.GROW) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
674 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
675 |
def _init_coll_MainSizer_Growables(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
676 |
parent.AddGrowableCol(0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
677 |
parent.AddGrowableRow(0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
678 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
679 |
def _init_sizers(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
680 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
681 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
682 |
self._init_coll_MainSizer_Items(self.MainSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
683 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
684 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
685 |
self.SetSizer(self.MainSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
686 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
687 |
def _init_ctrls(self, prnt): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
688 |
wx.Control.__init__(self, id=-1, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
689 |
name='DurationCellControl', parent=prnt, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
690 |
size=wx.DefaultSize, style=0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
691 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
692 |
# create location text control |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
693 |
self.Duration = wx.TextCtrl(id=-1, name='Duration', parent=self, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
694 |
pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TE_PROCESS_ENTER) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
695 |
self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
696 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
697 |
# create browse button |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
698 |
self.EditButton = wx.Button(id=-1, label='...', |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
699 |
name='EditButton', parent=self, pos=wx.Point(0, 0), |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
700 |
size=wx.Size(30, 0), style=0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
701 |
self.EditButton.Bind(wx.EVT_BUTTON, self.OnEditButtonClick) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
702 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
703 |
self.Bind(wx.EVT_SIZE, self.OnSize) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
704 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
705 |
self._init_sizers() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
706 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
707 |
''' |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
708 |
Custom cell editor control with a text box and a button that launches |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
709 |
the DurationEditorDialog. |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
710 |
''' |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
711 |
def __init__(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
712 |
self._init_ctrls(parent) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
713 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
714 |
def SetValue(self, value): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
715 |
self.Duration.SetValue(value) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
716 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
717 |
def GetValue(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
718 |
return self.Duration.GetValue() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
719 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
720 |
def OnSize(self, event): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
721 |
self.Layout() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
722 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
723 |
def OnEditButtonClick(self, event): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
724 |
# pop up the Duration Editor dialog |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
725 |
dialog = DurationEditorDialog(self) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
726 |
dialog.SetDuration(self.Duration.GetValue()) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
727 |
if dialog.ShowModal() == wx.ID_OK: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
728 |
# set the duration |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
729 |
self.Duration.SetValue(dialog.GetDuration()) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
730 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
731 |
dialog.Destroy() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
732 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
733 |
self.Duration.SetFocus() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
734 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
735 |
def OnDurationChar(self, event): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
736 |
keycode = event.GetKeyCode() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
737 |
if keycode == wx.WXK_RETURN or keycode == wx.WXK_TAB: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
738 |
self.Parent.Parent.ProcessEvent(event) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
739 |
self.Parent.Parent.SetFocus() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
740 |
else: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
741 |
event.Skip() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
742 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
743 |
def SetInsertionPoint(self, i): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
744 |
self.Duration.SetInsertionPoint(i) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
745 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
746 |
def SetFocus(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
747 |
self.Duration.SetFocus() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
748 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
749 |
class DurationCellEditor(wx.grid.PyGridCellEditor): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
750 |
''' |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
751 |
Grid cell editor that uses DurationCellControl to display an edit button. |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
752 |
''' |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
753 |
def __init__(self, table): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
754 |
wx.grid.PyGridCellEditor.__init__(self) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
755 |
self.Table = table |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
756 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
757 |
def __del__(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
758 |
self.CellControl = None |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
759 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
760 |
def Create(self, parent, id, evt_handler): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
761 |
self.CellControl = DurationCellControl(parent) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
762 |
self.SetControl(self.CellControl) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
763 |
if evt_handler: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
764 |
self.CellControl.PushEventHandler(evt_handler) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
765 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
766 |
def BeginEdit(self, row, col, grid): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
767 |
self.CellControl.SetValue(self.Table.GetValueByName(row, 'Interval')) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
768 |
self.CellControl.SetFocus() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
769 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
770 |
def EndEdit(self, row, col, grid): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
771 |
duration = self.CellControl.GetValue() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
772 |
old_duration = self.Table.GetValueByName(row, 'Interval') |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
773 |
if duration != old_duration: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
774 |
self.Table.SetValueByName(row, 'Interval', duration) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
775 |
return True |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
776 |
return False |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
777 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
778 |
def SetSize(self, rect): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
779 |
self.CellControl.SetDimensions(rect.x + 1, rect.y, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
780 |
rect.width, rect.height, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
781 |
wx.SIZE_ALLOW_MINUS_ONE) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
782 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
783 |
def Clone(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
784 |
return DurationCellEditor(self.Table) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
560
diff
changeset
|
785 |