RessourceEditor.py
author laurent
Thu, 21 Apr 2011 15:15:57 +0200
changeset 536 288324dddfb8
parent 494 c91644c2bfa7
child 560 3757f0de0d07
permissions -rw-r--r--
Adding '0' and '1' as possible value to force boolean variables
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
#based on the plcopen standard. 
#
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
#
#See COPYING file for copyrights details.
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#General Public License for more details.
#
#You should have received a copy of the GNU General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import wx
import wx.grid


#-------------------------------------------------------------------------------
#                          Configuration Editor class
#-------------------------------------------------------------------------------

[ID_CONFIGURATIONEDITOR, 
] = [wx.NewId() for _init_ctrls in range(1)]

class ConfigurationEditor(wx.Panel):
    
    def _init_ctrls(self, prnt):
        wx.Panel.__init__(self, id=ID_CONFIGURATIONEDITOR, name='', parent=prnt,
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)

    def __init__(self, parent, tagname, window, controler):
        self._init_ctrls(parent)
        
        self.ParentWindow = window
        self.Controler = controler
        self.TagName = tagname

    def SetTagName(self, tagname):
        self.TagName = tagname
        
    def GetTagName(self):
        return self.TagName
    
    def IsViewing(self, tagname):
        return self.TagName == tagname

    def IsDebugging(self):
        return False

    def SetMode(self, mode):
        pass

    def ResetBuffer(self):
        pass

    def RefreshView(self):
        pass

    def RefreshScaling(self, refresh=True):
        pass

    def ClearErrors(self):
        pass

#-------------------------------------------------------------------------------
#                            Resource Editor class
#-------------------------------------------------------------------------------

def GetTasksTableColnames():
    _ = lambda x : x
    return [_("Name"), _("Single"), _("Interval"), _("Priority")]

def GetInstancesTableColnames():
    _ = lambda x : x
    return [_("Name"), _("Type"), _("Task")]

class ResourceTable(wx.grid.PyGridTableBase):
    
    """
    A custom wx.grid.Grid Table using user supplied data
    """
    def __init__(self, parent, data, colnames):
        # The base class must be initialized *first*
        wx.grid.PyGridTableBase.__init__(self)
        self.data = data
        self.colnames = colnames
        self.Errors = {}
        self.Parent = parent
        
        self.ColAlignements = []
        self.ColSizes = []
        # XXX
        # we need to store the row length and collength to
        # see if the table has changed size
        self._rows = self.GetNumberRows()
        self._cols = self.GetNumberCols()
    
    def GetColAlignements(self):
        return self.ColAlignements
    
    def SetColAlignements(self, list):
        self.ColAlignements = list

    def GetColSizes(self):
        return self.ColSizes
    
    def SetColSizes(self, list):
        self.ColSizes = list

    def GetNumberCols(self):
        return len(self.colnames)
        
    def GetNumberRows(self):
        return len(self.data)

    def GetColLabelValue(self, col, translate=True):
        if col < len(self.colnames):
            if translate:
                return _(self.colnames[col])
            return self.colnames[col]

    def GetRowLabelValues(self, row, translate=True):
        return row

    def GetValue(self, row, col):
        if row < self.GetNumberRows():
            name = str(self.data[row].get(self.GetColLabelValue(col, False), ""))
            return name
    
    def GetValueByName(self, row, colname):
        return self.data[row].get(colname)

    def SetValue(self, row, col, value):
        if col < len(self.colnames):
            self.data[row][self.GetColLabelValue(col, False)] = value
    
    def SetValueByName(self, row, colname, value):
        if colname in self.colnames:
            self.data[row][colname] = value
    
    def ResetView(self, grid):
        """
        (wx.grid.Grid) -> Reset the grid view.   Call this to
        update the grid if rows and columns have been added or deleted
        """
        grid.BeginBatch()
        for current, new, delmsg, addmsg in [
            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
        ]:
            if new < current:
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
                grid.ProcessTableMessage(msg)
            elif new > current:
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
                grid.ProcessTableMessage(msg)
                self.UpdateValues(grid)
        grid.EndBatch()

        self._rows = self.GetNumberRows()
        self._cols = self.GetNumberCols()
        # update the column rendering scheme
        self._updateColAttrs(grid)

        # update the scrollbars and the displayed part of the grid
        grid.AdjustScrollbars()
        grid.ForceRefresh()

    def UpdateValues(self, grid):
        """Update all displayed values"""
        # This sends an event to the grid table to update all of the values
        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
        grid.ProcessTableMessage(msg)

    def _updateColAttrs(self, grid):
        """
        wx.grid.Grid -> update the column attributes to add the
        appropriate renderer given the column name.

        Otherwise default to the default renderer.
        """
        
        for col in range(self.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
            grid.SetColAttr(col, attr)
            grid.SetColSize(col, self.ColSizes[col])
        
        for row in range(self.GetNumberRows()):
            for col in range(self.GetNumberCols()):
                editor = None
                renderer = None
                colname = self.GetColLabelValue(col, False)
                grid.SetReadOnly(row, col, False)
                if colname in ["Name","Interval"]:
                    editor = wx.grid.GridCellTextEditor()
                    renderer = wx.grid.GridCellStringRenderer()
                    if colname == "Interval" and self.GetValueByName(row, "Single") != "":
                        grid.SetReadOnly(row, col, True)
                elif colname == "Single":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(self.Parent.VariableList)
                    if self.GetValueByName(row, "Interval") != "":
                        grid.SetReadOnly(row, col, True)
                elif colname == "Type":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(self.Parent.TypeList)
                elif colname == "Priority":
                    editor = wx.grid.GridCellNumberEditor()
                    editor.SetParameters("0,65535")
                elif colname == "Task":
                    editor = wx.grid.GridCellChoiceEditor()
                    editor.SetParameters(self.Parent.TaskList)
                    
                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)
    
    def SetData(self, data):
        self.data = data
    
    def GetData(self):
        return self.data
    
    def GetCurrentIndex(self):
        return self.CurrentIndex
    
    def SetCurrentIndex(self, index):
        self.CurrentIndex = index
    
    def AppendRow(self, row_content):
        self.data.append(row_content)

    def RemoveRow(self, row_index):
        self.data.pop(row_index)
        
    def MoveRow(self, row_index, move, grid):
        new_index = max(0, min(row_index + move, len(self.data) - 1))
        if new_index != row_index:
            self.data.insert(new_index, self.data.pop(row_index))
            grid.SetGridCursor(new_index, grid.GetGridCursorCol())

    def Empty(self):
        self.data = []
        self.editors = []

    def AddError(self, infos):
        self.Errors[infos[0]] = infos[1:]

    def ClearErrors(self):
        self.Errors = {}

[ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1,
 ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID,
 ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON,
 ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON,
 ID_RESOURCEEDITORDOWNINSTANCEBUTTON, ID_RESOURCEEDITORADDTASKBUTTON,
 ID_RESOURCEEDITORDELETETASKBUTTON, ID_RESOURCEEDITORUPTASKBUTTON,
 ID_RESOURCEEDITORDOWNTASKBUTTON,
] = [wx.NewId() for _init_ctrls in range(13)]

class ResourceEditor(wx.Panel):
    
    if wx.VERSION < (2, 6, 0):
        def Bind(self, event, function, id = None):
            if id is not None:
                event(self, id, function)
            else:
                event(self, function)
    
    def _init_coll_InstancesSizer_Growables(self, parent):
        parent.AddGrowableCol(0)
        parent.AddGrowableRow(1)

    def _init_coll_InstancesSizer_Items(self, parent):
        parent.AddSizer(self.InstancesButtonsSizer, 0, border=0, flag=wx.GROW)
        parent.AddWindow(self.InstancesGrid, 0, border=0, flag=wx.GROW)

    def _init_coll_InstancesButtonsSizer_Growables(self, parent):
        parent.AddGrowableCol(0)
        parent.AddGrowableRow(0)

    def _init_coll_InstancesButtonsSizer_Items(self, parent):
        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM)
        parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0)
        parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0)
        parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0)
        parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0)

    def _init_coll_TasksSizer_Growables(self, parent):
        parent.AddGrowableCol(0)
        parent.AddGrowableRow(1)

    def _init_coll_TasksSizer_Items(self, parent):
        parent.AddSizer(self.TasksButtonsSizer, 0, border=0, flag=wx.GROW)
        parent.AddWindow(self.TasksGrid, 0, border=0, flag=wx.GROW)

    def _init_coll_TasksButtonsSizer_Growables(self, parent):
        parent.AddGrowableCol(0)
        parent.AddGrowableRow(0)

    def _init_coll_TasksButtonsSizer_Items(self, parent):
        parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM)
        parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0)
        parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0)
        parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0)
        parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0)

    def _init_coll_MainGridSizer_Items(self, parent):
        parent.AddSizer(self.TasksSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
        parent.AddSizer(self.InstancesSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)

    def _init_coll_MainGridSizer_Growables(self, parent):
        parent.AddGrowableCol(0)
        parent.AddGrowableRow(0)
        parent.AddGrowableRow(1)

    def _init_sizers(self):
        self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
        self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
        self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
        self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
        self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)

        self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
        self._init_coll_MainGridSizer_Items(self.MainGridSizer)
        self._init_coll_InstancesSizer_Growables(self.InstancesSizer)
        self._init_coll_InstancesSizer_Items(self.InstancesSizer)
        self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer)
        self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer)
        self._init_coll_TasksSizer_Growables(self.TasksSizer)
        self._init_coll_TasksSizer_Items(self.TasksSizer)
        self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer)
        self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer)

        self.SetSizer(self.MainGridSizer)

    def _init_ctrls(self, prnt):
        wx.Panel.__init__(self, id=ID_RESOURCEEDITOR, name='', parent=prnt,
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
        
        self.staticText1 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT1,
              label=_(u'Tasks:'), name='staticText2', parent=self, pos=wx.Point(0,
              0), size=wx.DefaultSize, style=wx.ALIGN_CENTER)

        self.TasksGrid = wx.grid.Grid(id=ID_RESOURCEEDITORTASKSGRID,
              name='TasksGrid', parent=self, pos=wx.Point(0, 0), 
              size=wx.Size(-1, -1), style=wx.VSCROLL)
        self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
              'Sans'))
        self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
              False, 'Sans'))
        if wx.VERSION >= (2, 5, 0):
            self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange)
        else:
            wx.grid.EVT_GRID_CELL_CHANGE(self.TasksGrid, self.OnTasksGridCellChange)
        
        self.AddTaskButton = wx.Button(id=ID_RESOURCEEDITORADDTASKBUTTON, label=_('Add Task'),
              name='AddTaskButton', parent=self, pos=wx.Point(0, 0),
              size=wx.DefaultSize, style=0)
        self.Bind(wx.EVT_BUTTON, self.OnAddTaskButton, id=ID_RESOURCEEDITORADDTASKBUTTON)

        self.DeleteTaskButton = wx.Button(id=ID_RESOURCEEDITORDELETETASKBUTTON, label=_('Delete Task'),
              name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0),
              size=wx.DefaultSize, style=0)
        self.Bind(wx.EVT_BUTTON, self.OnDeleteTaskButton, id=ID_RESOURCEEDITORDELETETASKBUTTON)

        self.UpTaskButton = wx.Button(id=ID_RESOURCEEDITORUPTASKBUTTON, label='^',
              name='UpTaskButton', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(32, 32), style=0)
        self.Bind(wx.EVT_BUTTON, self.OnUpTaskButton, id=ID_RESOURCEEDITORUPTASKBUTTON)

        self.DownTaskButton = wx.Button(id=ID_RESOURCEEDITORDOWNTASKBUTTON, label='v',
              name='DownTaskButton', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(32, 32), style=0)
        self.Bind(wx.EVT_BUTTON, self.OnDownTaskButton, id=ID_RESOURCEEDITORDOWNTASKBUTTON)

        self.staticText2 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT2,
              label=_(u'Instances:'), name='staticText1', parent=self,
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=wx.ALIGN_CENTER)

        self.InstancesGrid = wx.grid.Grid(id=ID_RESOURCEEDITORINSTANCESGRID,
              name='InstancesGrid', parent=self, pos=wx.Point(0, 0), 
              size=wx.Size(-1, -1), style=wx.VSCROLL)
        self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
              'Sans'))
        self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
              False, 'Sans'))
        if wx.VERSION >= (2, 5, 0):
            self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange)
        else:
            wx.grid.EVT_GRID_CELL_CHANGE(self.InstancesGrid, self.OnInstancesGridCellChange)
        
        self.AddInstanceButton = wx.Button(id=ID_RESOURCEEDITORADDINSTANCEBUTTON, label=_('Add Instance'),
              name='AddInstanceButton', parent=self, pos=wx.Point(0, 0),
              size=wx.DefaultSize, style=0)
        self.Bind(wx.EVT_BUTTON, self.OnAddInstanceButton, id=ID_RESOURCEEDITORADDINSTANCEBUTTON)

        self.DeleteInstanceButton = wx.Button(id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON, label=_('Delete Instance'),
              name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0),
              size=wx.DefaultSize, style=0)
        self.Bind(wx.EVT_BUTTON, self.OnDeleteInstanceButton, id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON)

        self.UpInstanceButton = wx.Button(id=ID_RESOURCEEDITORUPINSTANCEBUTTON, label='^',
              name='UpInstanceButton', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(32, 32), style=0)
        self.Bind(wx.EVT_BUTTON, self.OnUpInstanceButton, id=ID_RESOURCEEDITORUPINSTANCEBUTTON)

        self.DownInstanceButton = wx.Button(id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON, label='v',
              name='DownInstanceButton', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(32, 32), style=0)
        self.Bind(wx.EVT_BUTTON, self.OnDownInstanceButton, id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON)

        self._init_sizers()

    def __init__(self, parent, tagname, window, controler):
        self._init_ctrls(parent)
        
        self.ParentWindow = window
        self.Controler = controler
        self.TagName = tagname
        
        self.TasksDefaultValue = {"Name" : "", "Single" : "", "Interval" : "", "Priority" : 0}
        self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
        self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
        self.TasksTable.SetColSizes([200, 100, 100, 100])
        self.TasksGrid.SetTable(self.TasksTable)
        self.TasksGrid.SetRowLabelSize(0)
        self.TasksTable.ResetView(self.TasksGrid)

        self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""}
        self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames())
        self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT])
        self.InstancesTable.SetColSizes([200, 150, 150])
        self.InstancesGrid.SetTable(self.InstancesTable)
        self.InstancesGrid.SetRowLabelSize(0)
        self.InstancesTable.ResetView(self.InstancesGrid)

    def SetTagName(self, tagname):
        self.TagName = tagname
        
    def GetTagName(self):
        return self.TagName
    
    def IsViewing(self, tagname):
        return self.TagName == tagname

    def IsDebugging(self):
        return False

    def SetMode(self, mode):
        pass

    def RefreshTypeList(self):
        self.TypeList = ""
        blocktypes = self.Controler.GetBlockResource()
        for blocktype in blocktypes:
            self.TypeList += ",%s"%blocktype

    def RefreshTaskList(self):
        self.TaskList = ""
        for row in xrange(self.TasksTable.GetNumberRows()):
            self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name")

    def RefreshVariableList(self):
        self.VariableList = ""
        for variable in self.Controler.GetEditedResourceVariables(self.TagName):
            self.VariableList += ",%s"%variable
        
    def RefreshModel(self):
        self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData())
        self.RefreshBuffer()
        
    def ResetBuffer(self):
        pass

    # Buffer the last model state
    def RefreshBuffer(self):
        self.Controler.BufferProject()
        self.ParentWindow.RefreshTitle()
        self.ParentWindow.RefreshFileMenu()
        self.ParentWindow.RefreshEditMenu()

    def RefreshView(self):
        tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName)
        self.TasksTable.SetData(tasks)
        self.InstancesTable.SetData(instances)
        self.RefreshTypeList()
        self.RefreshTaskList()
        self.RefreshVariableList()
        self.InstancesTable.ResetView(self.InstancesGrid)
        self.TasksTable.ResetView(self.TasksGrid)

    def RefreshScaling(self, refresh=True):
        pass

    def OnAddTaskButton(self, event):
        self.TasksTable.AppendRow(self.TasksDefaultValue.copy())
        self.RefreshModel()
        self.RefreshView()
        event.Skip()

    def OnDeleteTaskButton(self, event):
        row = self.TasksGrid.GetGridCursorRow()
        self.TasksTable.RemoveRow(row)
        self.RefreshModel()
        self.RefreshView()
        event.Skip()

    def OnUpTaskButton(self, event):
        row = self.TasksGrid.GetGridCursorRow()
        self.TasksTable.MoveRow(row, -1, self.TasksGrid)
        self.RefreshModel()
        self.RefreshView()
        event.Skip()

    def OnDownTaskButton(self, event):
        row = self.TasksGrid.GetGridCursorRow()
        self.TasksTable.MoveRow(row, 1, self.TasksGrid)
        self.RefreshModel()
        self.RefreshView()
        event.Skip()

    def OnAddInstanceButton(self, event):
        self.InstancesTable.AppendRow(self.InstancesDefaultValue.copy())
        self.RefreshModel()
        self.RefreshView()
        self.ParentWindow.RefreshInstancesTree()
        event.Skip()

    def OnDeleteInstanceButton(self, event):
        row = self.InstancesGrid.GetGridCursorRow()
        self.InstancesTable.RemoveRow(row)
        self.RefreshModel()
        self.RefreshView()
        self.ParentWindow.RefreshInstancesTree()
        event.Skip()

    def OnUpInstanceButton(self, event):
        row = self.InstancesGrid.GetGridCursorRow()
        self.InstancesTable.MoveRow(row, -1, self.InstancesGrid)
        self.RefreshModel()
        self.RefreshView()
        self.ParentWindow.RefreshInstancesTree()
        event.Skip()

    def OnDownInstanceButton(self, event):
        row = self.InstancesGrid.GetGridCursorRow()
        self.InstancesTable.MoveRow(row, 1, self.InstancesGrid)
        self.RefreshModel()
        self.RefreshView()
        self.ParentWindow.RefreshInstancesTree()
        event.Skip()

    def OnTasksGridCellChange(self, event):
        row, col = event.GetRow(), event.GetCol()
        if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name":
            tasklist = self.TaskList.split(",")
            for i in xrange(self.TasksTable.GetNumberRows()):
                task = self.TasksTable.GetValueByName(i, "Name")
                if task in tasklist:
                    tasklist.remove(task)
            tasklist.remove("")
            if len(tasklist) > 0:
                old_name = tasklist[0]
                new_name = self.TasksTable.GetValue(row, col)
                for i in xrange(self.InstancesTable.GetNumberRows()):
                    if self.InstancesTable.GetValueByName(i, "Task") == old_name:
                        self.InstancesTable.SetValueByName(i, "Task", new_name)
        self.RefreshModel()
        self.RefreshView()
        event.Skip()

    def OnInstancesGridCellChange(self, event):
        self.RefreshModel()
        self.RefreshView()
        self.ParentWindow.RefreshInstancesTree()
        event.Skip()

#-------------------------------------------------------------------------------
#                        Errors showing functions
#-------------------------------------------------------------------------------

    def ClearErrors(self):
        self.TasksTable.ClearErrors()
        self.InstancesTable.ClearErrors()
        self.TasksTable.ResetView(self.TasksGrid)
        self.InstancesTable.ResetView(self.InstancesGrid)

    def AddShownError(self, infos, start, end):
        if infos[0] == "task":
            self.TasksTable.AddError(infos[1:])
        elif infos[0] == "instance":
            self.InstancesTable.AddError(infos[1:])