--- a/VariablePanel.py Fri Sep 30 17:16:02 2011 +0200
+++ b/VariablePanel.py Sun Oct 09 19:51:14 2011 +0200
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
@@ -28,6 +29,7 @@
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
+from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
from dialogs import ArrayTypeDialog
CWD = os.path.split(os.path.realpath(__file__))[0]
@@ -94,7 +96,7 @@
self.data = data
self.old_value = None
self.colnames = colnames
- self.Errors = {}
+ self.Highlights = {}
self.Parent = parent
# XXX
# we need to store the row length and collength to
@@ -200,6 +202,7 @@
for row in range(self.GetNumberRows()):
var_class = self.GetValueByName(row, "Class")
var_type = self.GetValueByName(row, "Type")
+ row_highlights = self.Highlights.get(row, {})
for col in range(self.GetNumberCols()):
editor = None
renderer = None
@@ -254,13 +257,9 @@
grid.SetCellEditor(row, col, editor)
grid.SetCellRenderer(row, col, renderer)
- if row in self.Errors and self.Errors[row][0] == colname.lower():
- grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
- grid.SetCellTextColour(row, col, wx.RED)
- grid.MakeCellVisible(row, col)
- else:
- grid.SetCellTextColour(row, col, wx.BLACK)
- grid.SetCellBackgroundColour(row, col, wx.WHITE)
+ highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
+ grid.SetCellBackgroundColour(row, col, highlight_colours[0])
+ grid.SetCellTextColour(row, col, highlight_colours[1])
if wx.Platform == '__WXMSW__':
grid.SetRowMinimalHeight(row, 20)
else:
@@ -292,11 +291,23 @@
self.data = []
self.editors = []
- def AddError(self, infos):
- self.Errors[infos[0]] = infos[1:]
-
- def ClearErrors(self):
- self.Errors = {}
+ def AddHighlight(self, infos, highlight_type):
+ row_highlights = self.Highlights.setdefault(infos[0], {})
+ col_highlights = row_highlights.setdefault(infos[1], [])
+ col_highlights.append(highlight_type)
+
+ def ClearHighlights(self, highlight_type=None):
+ if highlight_type is None:
+ self.Highlights = {}
+ else:
+ for row, row_highlights in self.Highlights.iteritems():
+ row_items = row_highlights.items()
+ for col, col_highlights in row_items:
+ if highlight_type in col_highlights:
+ col_highlights.remove(highlight_type)
+ if len(col_highlights) == 0:
+ row_highlights.pop(col)
+
class VariableDropTarget(wx.TextDropTarget):
'''
@@ -524,6 +535,9 @@
self.Controler = controler
self.ElementType = element_type
+ self.RefreshHighlightsTimer = wx.Timer(self, -1)
+ self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
+
self.Filter = "All"
self.FilterChoices = []
self.FilterChoiceTransfer = GetFilterChoiceTransfer()
@@ -597,6 +611,9 @@
self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
self.VariablesGrid.AutoSizeColumn(col, False)
+ def __del__(self):
+ self.RefreshHighlightsTimer.Stop()
+
def SetTagName(self, tagname):
self.TagName = tagname
@@ -920,17 +937,27 @@
self.Controler.BufferProject()
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
- def AddVariableError(self, infos):
+#-------------------------------------------------------------------------------
+# Highlights showing functions
+#-------------------------------------------------------------------------------
+
+ def OnRefreshHighlightsTimer(self, event):
+ self.Table.ResetView(self.VariablesGrid)
+ event.Skip()
+
+ def AddVariableHighlight(self, infos, highlight_type):
if isinstance(infos[0], TupleType):
for i in xrange(*infos[0]):
- self.Table.AddError((i,) + infos[1:])
- else:
- self.Table.AddError(infos)
+ self.Table.AddHighlight((i,) + infos[1:], highlight_type)
+ else:
+ self.Table.AddHighlight(infos, highlight_type)
+ self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
+
+ def ClearHighlights(self, highlight_type=None):
+ self.Table.ClearHighlights(highlight_type)
self.Table.ResetView(self.VariablesGrid)
- def ClearErrors(self):
- self.Table.ClearErrors()
- self.Table.ResetView(self.VariablesGrid)
+
class LocationCellControl(wx.PyControl):