author | jon |
Tue, 04 Sep 2007 17:08:12 +0200 | |
changeset 84 | 0369ad49e67f |
parent 80 | c798a68c5560 |
child 90 | 2245e8776086 |
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 |
|
28 |
#------------------------------------------------------------------------------- |
|
29 |
# Resource Editor class |
|
30 |
#------------------------------------------------------------------------------- |
|
31 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
32 |
class ResourceTable(wx.grid.PyGridTableBase): |
27 | 33 |
|
34 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
35 |
A custom wx.grid.Grid Table using user supplied data |
27 | 36 |
""" |
37 |
def __init__(self, parent, data, colnames): |
|
38 |
# The base class must be initialized *first* |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
39 |
wx.grid.PyGridTableBase.__init__(self) |
27 | 40 |
self.data = data |
41 |
self.colnames = colnames |
|
42 |
self.Parent = parent |
|
43 |
||
44 |
self.ColAlignements = [] |
|
45 |
self.ColSizes = [] |
|
46 |
# XXX |
|
47 |
# we need to store the row length and collength to |
|
48 |
# see if the table has changed size |
|
49 |
self._rows = self.GetNumberRows() |
|
50 |
self._cols = self.GetNumberCols() |
|
51 |
||
52 |
def GetColAlignements(self): |
|
53 |
return self.ColAlignements |
|
54 |
||
55 |
def SetColAlignements(self, list): |
|
56 |
self.ColAlignements = list |
|
57 |
||
58 |
def GetColSizes(self): |
|
59 |
return self.ColSizes |
|
60 |
||
61 |
def SetColSizes(self, list): |
|
62 |
self.ColSizes = list |
|
63 |
||
64 |
def GetNumberCols(self): |
|
65 |
return len(self.colnames) |
|
66 |
||
67 |
def GetNumberRows(self): |
|
68 |
return len(self.data) |
|
69 |
||
70 |
def GetColLabelValue(self, col): |
|
71 |
if col < len(self.colnames): |
|
72 |
return self.colnames[col] |
|
73 |
||
74 |
def GetRowLabelValues(self, row): |
|
75 |
return row |
|
76 |
||
77 |
def GetValue(self, row, col): |
|
78 |
if row < self.GetNumberRows(): |
|
79 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
|
80 |
return name |
|
81 |
||
82 |
def GetValueByName(self, row, colname): |
|
83 |
return self.data[row].get(colname) |
|
84 |
||
85 |
def SetValue(self, row, col, value): |
|
86 |
if col < len(self.colnames): |
|
87 |
self.data[row][self.GetColLabelValue(col)] = value |
|
88 |
||
89 |
def SetValueByName(self, row, colname, value): |
|
90 |
if colname in self.colnames: |
|
91 |
self.data[row][colname] = value |
|
92 |
||
93 |
def ResetView(self, grid): |
|
94 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
95 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
27 | 96 |
update the grid if rows and columns have been added or deleted |
97 |
""" |
|
98 |
grid.BeginBatch() |
|
99 |
for current, new, delmsg, addmsg in [ |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
100 |
(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
|
101 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
27 | 102 |
]: |
103 |
if new < current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
104 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
27 | 105 |
grid.ProcessTableMessage(msg) |
106 |
elif new > current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
107 |
msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
27 | 108 |
grid.ProcessTableMessage(msg) |
109 |
self.UpdateValues(grid) |
|
110 |
grid.EndBatch() |
|
111 |
||
112 |
self._rows = self.GetNumberRows() |
|
113 |
self._cols = self.GetNumberCols() |
|
114 |
# update the column rendering scheme |
|
115 |
self._updateColAttrs(grid) |
|
116 |
||
117 |
# update the scrollbars and the displayed part of the grid |
|
118 |
grid.AdjustScrollbars() |
|
119 |
grid.ForceRefresh() |
|
120 |
||
121 |
def UpdateValues(self, grid): |
|
122 |
"""Update all displayed values""" |
|
123 |
# 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
|
124 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
27 | 125 |
grid.ProcessTableMessage(msg) |
126 |
||
127 |
def _updateColAttrs(self, grid): |
|
128 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
129 |
wx.grid.Grid -> update the column attributes to add the |
27 | 130 |
appropriate renderer given the column name. |
131 |
||
132 |
Otherwise default to the default renderer. |
|
133 |
""" |
|
134 |
||
135 |
for col in range(self.GetNumberCols()): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
136 |
attr = wx.grid.GridCellAttr() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
137 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
27 | 138 |
grid.SetColAttr(col, attr) |
139 |
grid.SetColSize(col, self.ColSizes[col]) |
|
140 |
||
141 |
for row in range(self.GetNumberRows()): |
|
142 |
for col in range(self.GetNumberCols()): |
|
143 |
editor = None |
|
144 |
renderer = None |
|
145 |
colname = self.GetColLabelValue(col) |
|
146 |
grid.SetReadOnly(row, col, False) |
|
147 |
if colname in ["Name","Interval"]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
148 |
editor = wx.grid.GridCellTextEditor() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
149 |
renderer = wx.grid.GridCellStringRenderer() |
27 | 150 |
if colname == "Interval" and self.GetValueByName(row, "Single") != "": |
151 |
grid.SetReadOnly(row, col, True) |
|
152 |
elif colname == "Single": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
153 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 154 |
editor.SetParameters(self.Parent.VariableList) |
155 |
if self.GetValueByName(row, "Interval") != "": |
|
156 |
grid.SetReadOnly(row, col, True) |
|
157 |
elif colname == "Type": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
158 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 159 |
editor.SetParameters(self.Parent.TypeList) |
160 |
elif colname == "Priority": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
161 |
editor = wx.grid.GridCellNumberEditor() |
27 | 162 |
editor.SetParameters("0,65535") |
163 |
elif colname == "Task": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
164 |
editor = wx.grid.GridCellChoiceEditor() |
27 | 165 |
editor.SetParameters(self.Parent.TaskList) |
166 |
||
167 |
grid.SetCellEditor(row, col, editor) |
|
168 |
grid.SetCellRenderer(row, col, renderer) |
|
169 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
170 |
grid.SetCellBackgroundColour(row, col, wx.WHITE) |
27 | 171 |
|
172 |
def SetData(self, data): |
|
173 |
self.data = data |
|
174 |
||
175 |
def GetData(self): |
|
176 |
return self.data |
|
177 |
||
178 |
def GetCurrentIndex(self): |
|
179 |
return self.CurrentIndex |
|
180 |
||
181 |
def SetCurrentIndex(self, index): |
|
182 |
self.CurrentIndex = index |
|
183 |
||
184 |
def AppendRow(self, row_content): |
|
185 |
self.data.append(row_content) |
|
186 |
||
187 |
def RemoveRow(self, row_index): |
|
188 |
self.data.pop(row_index) |
|
189 |
||
190 |
def MoveRow(self, row_index, move, grid): |
|
191 |
new_index = max(0, min(row_index + move, len(self.data) - 1)) |
|
192 |
if new_index != row_index: |
|
193 |
self.data.insert(new_index, self.data.pop(row_index)) |
|
194 |
grid.SetGridCursor(new_index, grid.GetGridCursorCol()) |
|
195 |
||
196 |
def Empty(self): |
|
197 |
self.data = [] |
|
198 |
self.editors = [] |
|
199 |
||
200 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
201 |
[ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
202 |
ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
203 |
ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
204 |
ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
205 |
ID_RESOURCEEDITORDOWNINSTANCEBUTTON, ID_RESOURCEEDITORADDTASKBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
206 |
ID_RESOURCEEDITORDELETETASKBUTTON, ID_RESOURCEEDITORUPTASKBUTTON, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
207 |
ID_RESOURCEEDITORDOWNTASKBUTTON, |
27 | 208 |
] = [wx.NewId() for _init_ctrls in range(13)] |
209 |
||
210 |
class ResourceEditor(wx.Panel): |
|
211 |
||
212 |
def _init_coll_InstancesSizer_Growables(self, parent): |
|
213 |
parent.AddGrowableCol(0) |
|
214 |
parent.AddGrowableRow(1) |
|
215 |
||
216 |
def _init_coll_InstancesSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
217 |
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
|
218 |
parent.AddWindow(self.InstancesGrid, 0, border=0, flag=wx.GROW) |
27 | 219 |
|
220 |
def _init_coll_InstancesButtonsSizer_Growables(self, parent): |
|
221 |
parent.AddGrowableCol(0) |
|
222 |
parent.AddGrowableRow(0) |
|
223 |
||
224 |
def _init_coll_InstancesButtonsSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
225 |
parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) |
27 | 226 |
parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0) |
227 |
parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0) |
|
228 |
parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0) |
|
229 |
parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0) |
|
230 |
||
231 |
def _init_coll_TasksSizer_Growables(self, parent): |
|
232 |
parent.AddGrowableCol(0) |
|
233 |
parent.AddGrowableRow(1) |
|
234 |
||
235 |
def _init_coll_TasksSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
236 |
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
|
237 |
parent.AddWindow(self.TasksGrid, 0, border=0, flag=wx.GROW) |
27 | 238 |
|
239 |
def _init_coll_TasksButtonsSizer_Growables(self, parent): |
|
240 |
parent.AddGrowableCol(0) |
|
241 |
parent.AddGrowableRow(0) |
|
242 |
||
243 |
def _init_coll_TasksButtonsSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
244 |
parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) |
27 | 245 |
parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0) |
246 |
parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0) |
|
247 |
parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0) |
|
248 |
parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0) |
|
249 |
||
250 |
def _init_coll_MainGridSizer_Items(self, parent): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
251 |
parent.AddSizer(self.TasksSizer, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
252 |
parent.AddSizer(self.InstancesSizer, 0, border=0, flag=wx.GROW) |
27 | 253 |
|
254 |
def _init_coll_MainGridSizer_Growables(self, parent): |
|
255 |
parent.AddGrowableCol(0) |
|
256 |
parent.AddGrowableRow(0) |
|
257 |
parent.AddGrowableRow(1) |
|
258 |
||
259 |
def _init_sizers(self): |
|
260 |
self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
261 |
self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
262 |
self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
263 |
self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
264 |
self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
265 |
||
266 |
self._init_coll_MainGridSizer_Growables(self.MainGridSizer) |
|
267 |
self._init_coll_MainGridSizer_Items(self.MainGridSizer) |
|
268 |
self._init_coll_InstancesSizer_Growables(self.InstancesSizer) |
|
269 |
self._init_coll_InstancesSizer_Items(self.InstancesSizer) |
|
270 |
self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer) |
|
271 |
self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer) |
|
272 |
self._init_coll_TasksSizer_Growables(self.TasksSizer) |
|
273 |
self._init_coll_TasksSizer_Items(self.TasksSizer) |
|
274 |
self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer) |
|
275 |
self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer) |
|
276 |
||
277 |
self.SetSizer(self.MainGridSizer) |
|
278 |
||
279 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
280 |
wx.Panel.__init__(self, id=ID_RESOURCEEDITOR, name='', parent=prnt, |
80 | 281 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) |
27 | 282 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
283 |
self.staticText1 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT1, |
27 | 284 |
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
|
285 |
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
|
286 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
287 |
self.TasksGrid = wx.grid.Grid(id=ID_RESOURCEEDITORTASKSGRID, |
27 | 288 |
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
|
289 |
size=wx.Size(-1, -1), style=wx.VSCROLL) |
27 | 290 |
self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
291 |
'Sans')) |
|
292 |
self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
293 |
False, 'Sans')) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
294 |
self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
295 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
296 |
self.AddTaskButton = wx.Button(id=ID_RESOURCEEDITORADDTASKBUTTON, label='Add Task', |
27 | 297 |
name='AddTaskButton', parent=self, pos=wx.Point(0, 0), |
298 |
size=wx.Size(102, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
299 |
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
|
300 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
301 |
self.DeleteTaskButton = wx.Button(id=ID_RESOURCEEDITORDELETETASKBUTTON, label='Delete Task', |
27 | 302 |
name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0), |
303 |
size=wx.Size(102, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
304 |
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
|
305 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
306 |
self.UpTaskButton = wx.Button(id=ID_RESOURCEEDITORUPTASKBUTTON, label='^', |
27 | 307 |
name='UpTaskButton', parent=self, pos=wx.Point(0, 0), |
308 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
309 |
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
|
310 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
311 |
self.DownTaskButton = wx.Button(id=ID_RESOURCEEDITORDOWNTASKBUTTON, label='v', |
27 | 312 |
name='DownTaskButton', parent=self, pos=wx.Point(0, 0), |
313 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
314 |
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
|
315 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
316 |
self.staticText2 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT2, |
27 | 317 |
label=u'Instances:', name='staticText1', parent=self, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
318 |
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
|
319 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
320 |
self.InstancesGrid = wx.grid.Grid(id=ID_RESOURCEEDITORINSTANCESGRID, |
27 | 321 |
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
|
322 |
size=wx.Size(-1, -1), style=wx.VSCROLL) |
27 | 323 |
self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
324 |
'Sans')) |
|
325 |
self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
326 |
False, 'Sans')) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
327 |
self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
328 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
329 |
self.AddInstanceButton = wx.Button(id=ID_RESOURCEEDITORADDINSTANCEBUTTON, label='Add Instance', |
27 | 330 |
name='AddInstanceButton', parent=self, pos=wx.Point(0, 0), |
331 |
size=wx.Size(122, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
332 |
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
|
333 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
334 |
self.DeleteInstanceButton = wx.Button(id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON, label='Delete Instance', |
27 | 335 |
name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0), |
336 |
size=wx.Size(122, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
337 |
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
|
338 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
339 |
self.UpInstanceButton = wx.Button(id=ID_RESOURCEEDITORUPINSTANCEBUTTON, label='^', |
27 | 340 |
name='UpInstanceButton', parent=self, pos=wx.Point(0, 0), |
341 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
342 |
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
|
343 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
344 |
self.DownInstanceButton = wx.Button(id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON, label='v', |
27 | 345 |
name='DownInstanceButton', parent=self, pos=wx.Point(0, 0), |
346 |
size=wx.Size(32, 32), style=0) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
347 |
self.Bind(wx.EVT_BUTTON, self.OnDownInstanceButton, id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON) |
27 | 348 |
|
349 |
self._init_sizers() |
|
350 |
||
351 |
def __init__(self, parent, window, controler): |
|
352 |
self._init_ctrls(parent) |
|
353 |
||
354 |
self.Parent = window |
|
355 |
self.Controler = controler |
|
356 |
||
357 |
self.TasksDefaultValue = {"Name" : "", "Single" : "", "Interval" : "", "Priority" : 0} |
|
358 |
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
|
359 |
self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) |
27 | 360 |
self.TasksTable.SetColSizes([200, 100, 100, 100]) |
361 |
self.TasksGrid.SetTable(self.TasksTable) |
|
362 |
self.TasksGrid.SetRowLabelSize(0) |
|
363 |
self.TasksTable.ResetView(self.TasksGrid) |
|
364 |
||
365 |
self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""} |
|
366 |
self.InstancesTable = ResourceTable(self, [], ["Name", "Type", "Task"]) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
367 |
self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) |
27 | 368 |
self.InstancesTable.SetColSizes([200, 150, 150]) |
369 |
self.InstancesGrid.SetTable(self.InstancesTable) |
|
370 |
self.InstancesGrid.SetRowLabelSize(0) |
|
371 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
372 |
||
373 |
def SetMode(self, mode): |
|
374 |
pass |
|
375 |
||
376 |
def RefreshTypeList(self): |
|
377 |
self.TypeList = "" |
|
378 |
blocktypes = self.Controler.GetBlockResource() |
|
379 |
for blocktype in blocktypes: |
|
380 |
self.TypeList += ",%s"%blocktype |
|
381 |
||
382 |
def RefreshTaskList(self): |
|
383 |
self.TaskList = "" |
|
384 |
for row in xrange(self.TasksTable.GetNumberRows()): |
|
385 |
self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name") |
|
386 |
||
387 |
def RefreshVariableList(self): |
|
388 |
self.VariableList = "" |
|
389 |
for variable in self.Controler.GetCurrentResourceEditingVariables(): |
|
390 |
self.VariableList += ",%s"%variable |
|
391 |
||
392 |
def RefreshModel(self): |
|
393 |
self.Controler.SetCurrentResourceEditingInfos(self.TasksTable.GetData(), self.InstancesTable.GetData()) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
394 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
395 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
396 |
def ResetBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
397 |
pass |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
398 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
399 |
# Buffer the last model state |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
400 |
def RefreshBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
401 |
self.Controler.BufferProject() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
402 |
self.Parent.RefreshTitle() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
27
diff
changeset
|
403 |
self.Parent.RefreshEditMenu() |
27 | 404 |
|
405 |
def RefreshView(self): |
|
406 |
tasks, instances = self.Controler.GetCurrentResourceEditingInfos() |
|
407 |
self.TasksTable.SetData(tasks) |
|
408 |
self.InstancesTable.SetData(instances) |
|
409 |
self.RefreshTypeList() |
|
410 |
self.RefreshTaskList() |
|
411 |
self.RefreshVariableList() |
|
412 |
self.InstancesTable.ResetView(self.InstancesGrid) |
|
413 |
self.TasksTable.ResetView(self.TasksGrid) |
|
414 |
||
415 |
def OnAddTaskButton(self, event): |
|
416 |
self.TasksTable.AppendRow(self.TasksDefaultValue.copy()) |
|
417 |
self.RefreshModel() |
|
418 |
event.Skip() |
|
419 |
||
420 |
def OnDeleteTaskButton(self, event): |
|
421 |
row = self.TasksGrid.GetGridCursorRow() |
|
422 |
self.TasksTable.RemoveRow(row) |
|
423 |
self.RefreshModel() |
|
424 |
self.RefreshView() |
|
425 |
event.Skip() |
|
426 |
||
427 |
def OnUpTaskButton(self, event): |
|
428 |
row = self.TasksGrid.GetGridCursorRow() |
|
429 |
self.TasksTable.MoveRow(row, -1, self.TasksGrid) |
|
430 |
self.RefreshModel() |
|
431 |
self.RefreshView() |
|
432 |
event.Skip() |
|
433 |
||
434 |
def OnDownTaskButton(self, event): |
|
435 |
row = self.TasksGrid.GetGridCursorRow() |
|
436 |
self.TasksTable.MoveRow(row, 1, self.TasksGrid) |
|
437 |
self.RefreshModel() |
|
438 |
self.RefreshView() |
|
439 |
event.Skip() |
|
440 |
||
441 |
def OnAddInstanceButton(self, event): |
|
442 |
self.InstancesTable.AppendRow(self.InstancesDefaultValue.copy()) |
|
443 |
self.RefreshModel() |
|
444 |
self.RefreshView() |
|
445 |
event.Skip() |
|
446 |
||
447 |
def OnDeleteInstanceButton(self, event): |
|
448 |
row = self.InstancesGrid.GetGridCursorRow() |
|
449 |
self.InstancesTable.RemoveRow(row) |
|
450 |
self.RefreshModel() |
|
451 |
self.RefreshView() |
|
452 |
event.Skip() |
|
453 |
||
454 |
def OnUpInstanceButton(self, event): |
|
455 |
row = self.InstancesGrid.GetGridCursorRow() |
|
456 |
self.InstancesTable.MoveRow(row, -1, self.InstancesGrid) |
|
457 |
self.RefreshModel() |
|
458 |
self.RefreshView() |
|
459 |
event.Skip() |
|
460 |
||
461 |
def OnDownInstanceButton(self, event): |
|
462 |
row = self.InstancesGrid.GetGridCursorRow() |
|
463 |
self.InstancesTable.MoveRow(row, 1, self.InstancesGrid) |
|
464 |
self.RefreshModel() |
|
465 |
self.RefreshView() |
|
466 |
event.Skip() |
|
467 |
||
468 |
def OnTasksGridCellChange(self, event): |
|
469 |
row, col = event.GetRow(), event.GetCol() |
|
470 |
if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name": |
|
471 |
tasklist = self.TaskList.split(",") |
|
472 |
for i in xrange(self.TasksTable.GetNumberRows()): |
|
473 |
task = self.TasksTable.GetValueByName(i, "Name") |
|
474 |
if task in tasklist: |
|
475 |
tasklist.remove(task) |
|
476 |
tasklist.remove("") |
|
477 |
if len(tasklist) > 0: |
|
478 |
old_name = tasklist[0] |
|
479 |
new_name = self.TasksTable.GetValue(row, col) |
|
480 |
for i in xrange(self.InstancesTable.GetNumberRows()): |
|
481 |
if self.InstancesTable.GetValueByName(i, "Task") == old_name: |
|
482 |
self.InstancesTable.SetValueByName(i, "Task", new_name) |
|
483 |
self.RefreshModel() |
|
484 |
self.RefreshView() |
|
485 |
event.Skip() |
|
486 |
||
487 |
def OnInstancesGridCellChange(self, event): |
|
488 |
self.RefreshModel() |
|
489 |
self.RefreshView() |
|
490 |
event.Skip() |