26 |
27 |
27 from types import TupleType |
28 from types import TupleType |
28 |
29 |
29 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS |
30 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS |
30 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
31 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
|
32 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD |
31 from dialogs import ArrayTypeDialog |
33 from dialogs import ArrayTypeDialog |
32 |
34 |
33 CWD = os.path.split(os.path.realpath(__file__))[0] |
35 CWD = os.path.split(os.path.realpath(__file__))[0] |
34 |
36 |
35 # Compatibility function for wx versions < 2.6 |
37 # Compatibility function for wx versions < 2.6 |
92 # The base class must be initialized *first* |
94 # The base class must be initialized *first* |
93 wx.grid.PyGridTableBase.__init__(self) |
95 wx.grid.PyGridTableBase.__init__(self) |
94 self.data = data |
96 self.data = data |
95 self.old_value = None |
97 self.old_value = None |
96 self.colnames = colnames |
98 self.colnames = colnames |
97 self.Errors = {} |
99 self.Highlights = {} |
98 self.Parent = parent |
100 self.Parent = parent |
99 # XXX |
101 # XXX |
100 # we need to store the row length and collength to |
102 # we need to store the row length and collength to |
101 # see if the table has changed size |
103 # see if the table has changed size |
102 self._rows = self.GetNumberRows() |
104 self._rows = self.GetNumberRows() |
198 Otherwise default to the default renderer. |
200 Otherwise default to the default renderer. |
199 """ |
201 """ |
200 for row in range(self.GetNumberRows()): |
202 for row in range(self.GetNumberRows()): |
201 var_class = self.GetValueByName(row, "Class") |
203 var_class = self.GetValueByName(row, "Class") |
202 var_type = self.GetValueByName(row, "Type") |
204 var_type = self.GetValueByName(row, "Type") |
|
205 row_highlights = self.Highlights.get(row, {}) |
203 for col in range(self.GetNumberCols()): |
206 for col in range(self.GetNumberCols()): |
204 editor = None |
207 editor = None |
205 renderer = None |
208 renderer = None |
206 colname = self.GetColLabelValue(col, False) |
209 colname = self.GetColLabelValue(col, False) |
207 if colname == "Option": |
210 if colname == "Option": |
252 grid.SetReadOnly(row, col, True) |
255 grid.SetReadOnly(row, col, True) |
253 |
256 |
254 grid.SetCellEditor(row, col, editor) |
257 grid.SetCellEditor(row, col, editor) |
255 grid.SetCellRenderer(row, col, renderer) |
258 grid.SetCellRenderer(row, col, renderer) |
256 |
259 |
257 if row in self.Errors and self.Errors[row][0] == colname.lower(): |
260 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] |
258 grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0)) |
261 grid.SetCellBackgroundColour(row, col, highlight_colours[0]) |
259 grid.SetCellTextColour(row, col, wx.RED) |
262 grid.SetCellTextColour(row, col, highlight_colours[1]) |
260 grid.MakeCellVisible(row, col) |
|
261 else: |
|
262 grid.SetCellTextColour(row, col, wx.BLACK) |
|
263 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
|
264 if wx.Platform == '__WXMSW__': |
263 if wx.Platform == '__WXMSW__': |
265 grid.SetRowMinimalHeight(row, 20) |
264 grid.SetRowMinimalHeight(row, 20) |
266 else: |
265 else: |
267 grid.SetRowMinimalHeight(row, 28) |
266 grid.SetRowMinimalHeight(row, 28) |
268 grid.AutoSizeRow(row, False) |
267 grid.AutoSizeRow(row, False) |
290 |
289 |
291 def Empty(self): |
290 def Empty(self): |
292 self.data = [] |
291 self.data = [] |
293 self.editors = [] |
292 self.editors = [] |
294 |
293 |
295 def AddError(self, infos): |
294 def AddHighlight(self, infos, highlight_type): |
296 self.Errors[infos[0]] = infos[1:] |
295 row_highlights = self.Highlights.setdefault(infos[0], {}) |
297 |
296 col_highlights = row_highlights.setdefault(infos[1], []) |
298 def ClearErrors(self): |
297 col_highlights.append(highlight_type) |
299 self.Errors = {} |
298 |
|
299 def ClearHighlights(self, highlight_type=None): |
|
300 if highlight_type is None: |
|
301 self.Highlights = {} |
|
302 else: |
|
303 for row, row_highlights in self.Highlights.iteritems(): |
|
304 row_items = row_highlights.items() |
|
305 for col, col_highlights in row_items: |
|
306 if highlight_type in col_highlights: |
|
307 col_highlights.remove(highlight_type) |
|
308 if len(col_highlights) == 0: |
|
309 row_highlights.pop(col) |
|
310 |
300 |
311 |
301 class VariableDropTarget(wx.TextDropTarget): |
312 class VariableDropTarget(wx.TextDropTarget): |
302 ''' |
313 ''' |
303 This allows dragging a variable location from somewhere to the Location |
314 This allows dragging a variable location from somewhere to the Location |
304 column of a variable row. |
315 column of a variable row. |
522 self._init_ctrls(parent) |
533 self._init_ctrls(parent) |
523 self.ParentWindow = window |
534 self.ParentWindow = window |
524 self.Controler = controler |
535 self.Controler = controler |
525 self.ElementType = element_type |
536 self.ElementType = element_type |
526 |
537 |
|
538 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
|
539 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
|
540 |
527 self.Filter = "All" |
541 self.Filter = "All" |
528 self.FilterChoices = [] |
542 self.FilterChoices = [] |
529 self.FilterChoiceTransfer = GetFilterChoiceTransfer() |
543 self.FilterChoiceTransfer = GetFilterChoiceTransfer() |
530 |
544 |
531 self.DefaultValue = { "Name" : "", "Class" : "", "Type" : "INT", "Location" : "", |
545 self.DefaultValue = { "Name" : "", "Class" : "", "Type" : "INT", "Location" : "", |
594 attr = wx.grid.GridCellAttr() |
608 attr = wx.grid.GridCellAttr() |
595 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
609 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
596 self.VariablesGrid.SetColAttr(col, attr) |
610 self.VariablesGrid.SetColAttr(col, attr) |
597 self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
611 self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
598 self.VariablesGrid.AutoSizeColumn(col, False) |
612 self.VariablesGrid.AutoSizeColumn(col, False) |
|
613 |
|
614 def __del__(self): |
|
615 self.RefreshHighlightsTimer.Stop() |
599 |
616 |
600 def SetTagName(self, tagname): |
617 def SetTagName(self, tagname): |
601 self.TagName = tagname |
618 self.TagName = tagname |
602 |
619 |
603 def IsFunctionBlockType(self, name): |
620 def IsFunctionBlockType(self, name): |
918 self.Controler.SetPouInterfaceVars(words[1], self.Values) |
935 self.Controler.SetPouInterfaceVars(words[1], self.Values) |
919 if buffer: |
936 if buffer: |
920 self.Controler.BufferProject() |
937 self.Controler.BufferProject() |
921 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE) |
938 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE) |
922 |
939 |
923 def AddVariableError(self, infos): |
940 #------------------------------------------------------------------------------- |
|
941 # Highlights showing functions |
|
942 #------------------------------------------------------------------------------- |
|
943 |
|
944 def OnRefreshHighlightsTimer(self, event): |
|
945 self.Table.ResetView(self.VariablesGrid) |
|
946 event.Skip() |
|
947 |
|
948 def AddVariableHighlight(self, infos, highlight_type): |
924 if isinstance(infos[0], TupleType): |
949 if isinstance(infos[0], TupleType): |
925 for i in xrange(*infos[0]): |
950 for i in xrange(*infos[0]): |
926 self.Table.AddError((i,) + infos[1:]) |
951 self.Table.AddHighlight((i,) + infos[1:], highlight_type) |
927 else: |
952 else: |
928 self.Table.AddError(infos) |
953 self.Table.AddHighlight(infos, highlight_type) |
|
954 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
955 |
|
956 def ClearHighlights(self, highlight_type=None): |
|
957 self.Table.ClearHighlights(highlight_type) |
929 self.Table.ResetView(self.VariablesGrid) |
958 self.Table.ResetView(self.VariablesGrid) |
930 |
959 |
931 def ClearErrors(self): |
960 |
932 self.Table.ClearErrors() |
|
933 self.Table.ResetView(self.VariablesGrid) |
|
934 |
961 |
935 class LocationCellControl(wx.PyControl): |
962 class LocationCellControl(wx.PyControl): |
936 |
963 |
937 def _init_coll_MainSizer_Items(self, parent): |
964 def _init_coll_MainSizer_Items(self, parent): |
938 parent.AddWindow(self.Location, 0, border=0, flag=wx.GROW) |
965 parent.AddWindow(self.Location, 0, border=0, flag=wx.GROW) |