lbessard@27: #!/usr/bin/env python lbessard@27: # -*- coding: utf-8 -*- lbessard@27: lbessard@27: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor lbessard@27: #based on the plcopen standard. lbessard@27: # lbessard@58: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD lbessard@27: # lbessard@27: #See COPYING file for copyrights details. lbessard@27: # lbessard@27: #This library is free software; you can redistribute it and/or lbessard@27: #modify it under the terms of the GNU General Public lbessard@27: #License as published by the Free Software Foundation; either lbessard@27: #version 2.1 of the License, or (at your option) any later version. lbessard@27: # lbessard@27: #This library is distributed in the hope that it will be useful, lbessard@27: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@27: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@58: #General Public License for more details. lbessard@27: # lbessard@27: #You should have received a copy of the GNU General Public lbessard@27: #License along with this library; if not, write to the Free Software lbessard@27: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lbessard@27: lbessard@27: import wx lbessard@64: import wx.grid lbessard@27: lbessard@121: if wx.VERSION >= (2, 8, 0): lbessard@121: import wx.aui lbessard@121: lbessard@121: class MDIConfigurationEditor(wx.aui.AuiMDIChildFrame): lbessard@121: def __init__(self, parent, tagname, window, controler): lbessard@121: wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "") lbessard@121: lbessard@121: sizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@121: lbessard@121: self.Viewer = ConfigurationEditor(self, tagname, window, controler) lbessard@121: lbessard@121: sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW) lbessard@121: lbessard@121: self.SetSizer(sizer) lbessard@121: lbessard@121: def GetViewer(self): lbessard@121: return self.Viewer lbessard@121: lbessard@121: class MDIResourceEditor(wx.aui.AuiMDIChildFrame): lbessard@121: def __init__(self, parent, tagname, window, controler): lbessard@121: wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "") lbessard@121: lbessard@121: sizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@121: lbessard@121: self.Viewer = ResourceEditor(self, tagname, window, controler) lbessard@121: lbessard@121: sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW) lbessard@121: lbessard@121: self.SetSizer(sizer) lbessard@121: lbessard@121: def GetViewer(self): lbessard@121: return self.Viewer lbessard@121: lbessard@121: #------------------------------------------------------------------------------- lbessard@121: # Configuration Editor class lbessard@121: #------------------------------------------------------------------------------- lbessard@121: lbessard@121: [ID_CONFIGURATIONEDITOR, lbessard@121: ] = [wx.NewId() for _init_ctrls in range(1)] lbessard@121: lbessard@121: class ConfigurationEditor(wx.Panel): lbessard@121: lbessard@121: def _init_ctrls(self, prnt): lbessard@121: wx.Panel.__init__(self, id=ID_CONFIGURATIONEDITOR, name='', parent=prnt, lbessard@121: size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) lbessard@121: lbessard@121: def __init__(self, parent, tagname, window, controler): lbessard@121: self._init_ctrls(parent) lbessard@121: lbessard@121: self.ParentWindow = window lbessard@121: self.Controler = controler lbessard@121: self.TagName = tagname lbessard@121: lbessard@121: def SetTagName(self, tagname): lbessard@121: self.TagName = tagname lbessard@121: lbessard@121: def GetTagName(self): lbessard@121: return self.TagName lbessard@121: lbessard@121: def IsViewing(self, tagname): lbessard@121: return self.TagName == tagname lbessard@121: lbessard@121: def SetMode(self, mode): lbessard@121: pass lbessard@121: lbessard@121: def ResetBuffer(self): lbessard@121: pass lbessard@121: lbessard@121: def RefreshView(self): lbessard@121: pass lbessard@121: lbessard@145: def RefreshScaling(self, refresh=True): lbessard@145: pass lbessard@145: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Resource Editor class lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: class ResourceTable(wx.grid.PyGridTableBase): lbessard@27: lbessard@27: """ lbessard@64: A custom wx.grid.Grid Table using user supplied data lbessard@27: """ lbessard@27: def __init__(self, parent, data, colnames): lbessard@27: # The base class must be initialized *first* lbessard@64: wx.grid.PyGridTableBase.__init__(self) lbessard@27: self.data = data lbessard@27: self.colnames = colnames lbessard@27: self.Parent = parent lbessard@27: lbessard@27: self.ColAlignements = [] lbessard@27: self.ColSizes = [] lbessard@27: # XXX lbessard@27: # we need to store the row length and collength to lbessard@27: # see if the table has changed size lbessard@27: self._rows = self.GetNumberRows() lbessard@27: self._cols = self.GetNumberCols() lbessard@27: lbessard@27: def GetColAlignements(self): lbessard@27: return self.ColAlignements lbessard@27: lbessard@27: def SetColAlignements(self, list): lbessard@27: self.ColAlignements = list lbessard@27: lbessard@27: def GetColSizes(self): lbessard@27: return self.ColSizes lbessard@27: lbessard@27: def SetColSizes(self, list): lbessard@27: self.ColSizes = list lbessard@27: lbessard@27: def GetNumberCols(self): lbessard@27: return len(self.colnames) lbessard@27: lbessard@27: def GetNumberRows(self): lbessard@27: return len(self.data) lbessard@27: lbessard@27: def GetColLabelValue(self, col): lbessard@27: if col < len(self.colnames): lbessard@27: return self.colnames[col] lbessard@27: lbessard@27: def GetRowLabelValues(self, row): lbessard@27: return row lbessard@27: lbessard@27: def GetValue(self, row, col): lbessard@27: if row < self.GetNumberRows(): lbessard@27: name = str(self.data[row].get(self.GetColLabelValue(col), "")) lbessard@27: return name lbessard@27: lbessard@27: def GetValueByName(self, row, colname): lbessard@27: return self.data[row].get(colname) lbessard@27: lbessard@27: def SetValue(self, row, col, value): lbessard@27: if col < len(self.colnames): lbessard@27: self.data[row][self.GetColLabelValue(col)] = value lbessard@27: lbessard@27: def SetValueByName(self, row, colname, value): lbessard@27: if colname in self.colnames: lbessard@27: self.data[row][colname] = value lbessard@27: lbessard@27: def ResetView(self, grid): lbessard@27: """ lbessard@64: (wx.grid.Grid) -> Reset the grid view. Call this to lbessard@27: update the grid if rows and columns have been added or deleted lbessard@27: """ lbessard@27: grid.BeginBatch() lbessard@27: for current, new, delmsg, addmsg in [ lbessard@64: (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), lbessard@64: (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), lbessard@27: ]: lbessard@27: if new < current: lbessard@64: msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: elif new > current: lbessard@64: msg = wx.grid.GridTableMessage(self,addmsg,new-current) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: self.UpdateValues(grid) lbessard@27: grid.EndBatch() lbessard@27: lbessard@27: self._rows = self.GetNumberRows() lbessard@27: self._cols = self.GetNumberCols() lbessard@27: # update the column rendering scheme lbessard@27: self._updateColAttrs(grid) lbessard@27: lbessard@27: # update the scrollbars and the displayed part of the grid lbessard@27: grid.AdjustScrollbars() lbessard@27: grid.ForceRefresh() lbessard@27: lbessard@27: def UpdateValues(self, grid): lbessard@27: """Update all displayed values""" lbessard@27: # This sends an event to the grid table to update all of the values lbessard@64: msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: lbessard@27: def _updateColAttrs(self, grid): lbessard@27: """ lbessard@64: wx.grid.Grid -> update the column attributes to add the lbessard@27: appropriate renderer given the column name. lbessard@27: lbessard@27: Otherwise default to the default renderer. lbessard@27: """ lbessard@27: lbessard@27: for col in range(self.GetNumberCols()): lbessard@64: attr = wx.grid.GridCellAttr() lbessard@64: attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) lbessard@27: grid.SetColAttr(col, attr) lbessard@27: grid.SetColSize(col, self.ColSizes[col]) lbessard@27: lbessard@27: for row in range(self.GetNumberRows()): lbessard@27: for col in range(self.GetNumberCols()): lbessard@27: editor = None lbessard@27: renderer = None lbessard@27: colname = self.GetColLabelValue(col) lbessard@27: grid.SetReadOnly(row, col, False) lbessard@27: if colname in ["Name","Interval"]: lbessard@64: editor = wx.grid.GridCellTextEditor() lbessard@64: renderer = wx.grid.GridCellStringRenderer() lbessard@27: if colname == "Interval" and self.GetValueByName(row, "Single") != "": lbessard@27: grid.SetReadOnly(row, col, True) lbessard@27: elif colname == "Single": lbessard@64: editor = wx.grid.GridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.VariableList) lbessard@27: if self.GetValueByName(row, "Interval") != "": lbessard@27: grid.SetReadOnly(row, col, True) lbessard@27: elif colname == "Type": lbessard@64: editor = wx.grid.GridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.TypeList) lbessard@27: elif colname == "Priority": lbessard@64: editor = wx.grid.GridCellNumberEditor() lbessard@27: editor.SetParameters("0,65535") lbessard@27: elif colname == "Task": lbessard@64: editor = wx.grid.GridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.TaskList) lbessard@27: lbessard@27: grid.SetCellEditor(row, col, editor) lbessard@27: grid.SetCellRenderer(row, col, renderer) lbessard@27: lbessard@64: grid.SetCellBackgroundColour(row, col, wx.WHITE) lbessard@27: lbessard@27: def SetData(self, data): lbessard@27: self.data = data lbessard@27: lbessard@27: def GetData(self): lbessard@27: return self.data lbessard@27: lbessard@27: def GetCurrentIndex(self): lbessard@27: return self.CurrentIndex lbessard@27: lbessard@27: def SetCurrentIndex(self, index): lbessard@27: self.CurrentIndex = index lbessard@27: lbessard@27: def AppendRow(self, row_content): lbessard@27: self.data.append(row_content) lbessard@27: lbessard@27: def RemoveRow(self, row_index): lbessard@27: self.data.pop(row_index) lbessard@27: lbessard@27: def MoveRow(self, row_index, move, grid): lbessard@27: new_index = max(0, min(row_index + move, len(self.data) - 1)) lbessard@27: if new_index != row_index: lbessard@27: self.data.insert(new_index, self.data.pop(row_index)) lbessard@27: grid.SetGridCursor(new_index, grid.GetGridCursorCol()) lbessard@27: lbessard@27: def Empty(self): lbessard@27: self.data = [] lbessard@27: self.editors = [] lbessard@27: lbessard@27: lbessard@64: [ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1, lbessard@64: ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID, lbessard@64: ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON, lbessard@64: ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON, lbessard@64: ID_RESOURCEEDITORDOWNINSTANCEBUTTON, ID_RESOURCEEDITORADDTASKBUTTON, lbessard@64: ID_RESOURCEEDITORDELETETASKBUTTON, ID_RESOURCEEDITORUPTASKBUTTON, lbessard@64: ID_RESOURCEEDITORDOWNTASKBUTTON, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(13)] lbessard@27: lbessard@27: class ResourceEditor(wx.Panel): lbessard@27: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_InstancesSizer_Growables(self, parent): lbessard@27: parent.AddGrowableCol(0) lbessard@27: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_coll_InstancesSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.InstancesButtonsSizer, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.InstancesGrid, 0, border=0, flag=wx.GROW) lbessard@27: lbessard@27: def _init_coll_InstancesButtonsSizer_Growables(self, parent): lbessard@27: parent.AddGrowableCol(0) lbessard@27: parent.AddGrowableRow(0) lbessard@27: lbessard@27: def _init_coll_InstancesButtonsSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) lbessard@27: parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0) lbessard@27: parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0) lbessard@27: parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0) lbessard@27: parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_coll_TasksSizer_Growables(self, parent): lbessard@27: parent.AddGrowableCol(0) lbessard@27: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_coll_TasksSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.TasksButtonsSizer, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.TasksGrid, 0, border=0, flag=wx.GROW) lbessard@27: lbessard@27: def _init_coll_TasksButtonsSizer_Growables(self, parent): lbessard@27: parent.AddGrowableCol(0) lbessard@27: parent.AddGrowableRow(0) lbessard@27: lbessard@27: def _init_coll_TasksButtonsSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) lbessard@27: parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0) lbessard@27: parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0) lbessard@27: parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0) lbessard@27: parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_coll_MainGridSizer_Items(self, parent): lbessard@124: parent.AddSizer(self.TasksSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@124: parent.AddSizer(self.InstancesSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@27: lbessard@27: def _init_coll_MainGridSizer_Growables(self, parent): lbessard@27: parent.AddGrowableCol(0) lbessard@27: parent.AddGrowableRow(0) lbessard@27: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) lbessard@27: self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) lbessard@27: lbessard@27: self._init_coll_MainGridSizer_Growables(self.MainGridSizer) lbessard@27: self._init_coll_MainGridSizer_Items(self.MainGridSizer) lbessard@27: self._init_coll_InstancesSizer_Growables(self.InstancesSizer) lbessard@27: self._init_coll_InstancesSizer_Items(self.InstancesSizer) lbessard@27: self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer) lbessard@27: self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer) lbessard@27: self._init_coll_TasksSizer_Growables(self.TasksSizer) lbessard@27: self._init_coll_TasksSizer_Items(self.TasksSizer) lbessard@27: self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer) lbessard@27: self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer) lbessard@27: lbessard@27: self.SetSizer(self.MainGridSizer) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@64: wx.Panel.__init__(self, id=ID_RESOURCEEDITOR, name='', parent=prnt, lbessard@80: size=wx.Size(0, 0), style=wx.SUNKEN_BORDER) lbessard@27: lbessard@64: self.staticText1 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT1, lbessard@27: label=u'Tasks:', name='staticText2', parent=self, pos=wx.Point(0, lbessard@64: 0), size=wx.Size(60, 17), style=wx.ALIGN_CENTER) lbessard@64: lbessard@64: self.TasksGrid = wx.grid.Grid(id=ID_RESOURCEEDITORTASKSGRID, lbessard@27: name='TasksGrid', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(-1, -1), style=wx.VSCROLL) lbessard@27: self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, lbessard@27: 'Sans')) lbessard@27: self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, lbessard@27: False, 'Sans')) lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange) lbessard@113: else: lbessard@113: wx.grid.EVT_GRID_CELL_CHANGE(self.TasksGrid, self.OnTasksGridCellChange) lbessard@113: lbessard@64: self.AddTaskButton = wx.Button(id=ID_RESOURCEEDITORADDTASKBUTTON, label='Add Task', lbessard@27: name='AddTaskButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(102, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnAddTaskButton, id=ID_RESOURCEEDITORADDTASKBUTTON) lbessard@64: lbessard@64: self.DeleteTaskButton = wx.Button(id=ID_RESOURCEEDITORDELETETASKBUTTON, label='Delete Task', lbessard@27: name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(102, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDeleteTaskButton, id=ID_RESOURCEEDITORDELETETASKBUTTON) lbessard@64: lbessard@64: self.UpTaskButton = wx.Button(id=ID_RESOURCEEDITORUPTASKBUTTON, label='^', lbessard@27: name='UpTaskButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnUpTaskButton, id=ID_RESOURCEEDITORUPTASKBUTTON) lbessard@64: lbessard@64: self.DownTaskButton = wx.Button(id=ID_RESOURCEEDITORDOWNTASKBUTTON, label='v', lbessard@27: name='DownTaskButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDownTaskButton, id=ID_RESOURCEEDITORDOWNTASKBUTTON) lbessard@64: lbessard@64: self.staticText2 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT2, lbessard@27: label=u'Instances:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(85, 17), style=wx.ALIGN_CENTER) lbessard@64: lbessard@64: self.InstancesGrid = wx.grid.Grid(id=ID_RESOURCEEDITORINSTANCESGRID, lbessard@27: name='InstancesGrid', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(-1, -1), style=wx.VSCROLL) lbessard@27: self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, lbessard@27: 'Sans')) lbessard@27: self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, lbessard@27: False, 'Sans')) lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange) lbessard@113: else: lbessard@113: wx.grid.EVT_GRID_CELL_CHANGE(self.InstancesGrid, self.OnInstancesGridCellChange) lbessard@113: lbessard@64: self.AddInstanceButton = wx.Button(id=ID_RESOURCEEDITORADDINSTANCEBUTTON, label='Add Instance', lbessard@27: name='AddInstanceButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(122, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnAddInstanceButton, id=ID_RESOURCEEDITORADDINSTANCEBUTTON) lbessard@64: lbessard@64: self.DeleteInstanceButton = wx.Button(id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON, label='Delete Instance', lbessard@27: name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(122, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDeleteInstanceButton, id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON) lbessard@64: lbessard@64: self.UpInstanceButton = wx.Button(id=ID_RESOURCEEDITORUPINSTANCEBUTTON, label='^', lbessard@27: name='UpInstanceButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnUpInstanceButton, id=ID_RESOURCEEDITORUPINSTANCEBUTTON) lbessard@64: lbessard@64: self.DownInstanceButton = wx.Button(id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON, label='v', lbessard@27: name='DownInstanceButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDownInstanceButton, id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@121: def __init__(self, parent, tagname, window, controler): lbessard@27: self._init_ctrls(parent) lbessard@27: lbessard@90: self.ParentWindow = window lbessard@27: self.Controler = controler lbessard@121: self.TagName = tagname lbessard@27: lbessard@27: self.TasksDefaultValue = {"Name" : "", "Single" : "", "Interval" : "", "Priority" : 0} lbessard@27: self.TasksTable = ResourceTable(self, [], ["Name", "Single", "Interval", "Priority"]) lbessard@64: self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT]) lbessard@27: self.TasksTable.SetColSizes([200, 100, 100, 100]) lbessard@27: self.TasksGrid.SetTable(self.TasksTable) lbessard@27: self.TasksGrid.SetRowLabelSize(0) lbessard@27: self.TasksTable.ResetView(self.TasksGrid) lbessard@27: lbessard@27: self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""} lbessard@27: self.InstancesTable = ResourceTable(self, [], ["Name", "Type", "Task"]) lbessard@64: self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]) lbessard@27: self.InstancesTable.SetColSizes([200, 150, 150]) lbessard@27: self.InstancesGrid.SetTable(self.InstancesTable) lbessard@27: self.InstancesGrid.SetRowLabelSize(0) lbessard@27: self.InstancesTable.ResetView(self.InstancesGrid) lbessard@27: lbessard@121: def SetTagName(self, tagname): lbessard@121: self.TagName = tagname lbessard@121: lbessard@121: def GetTagName(self): lbessard@121: return self.TagName lbessard@121: lbessard@121: def IsViewing(self, tagname): lbessard@121: return self.TagName == tagname lbessard@121: lbessard@27: def SetMode(self, mode): lbessard@27: pass lbessard@27: lbessard@27: def RefreshTypeList(self): lbessard@27: self.TypeList = "" lbessard@27: blocktypes = self.Controler.GetBlockResource() lbessard@27: for blocktype in blocktypes: lbessard@27: self.TypeList += ",%s"%blocktype lbessard@27: lbessard@27: def RefreshTaskList(self): lbessard@27: self.TaskList = "" lbessard@27: for row in xrange(self.TasksTable.GetNumberRows()): lbessard@27: self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name") lbessard@27: lbessard@27: def RefreshVariableList(self): lbessard@27: self.VariableList = "" lbessard@121: for variable in self.Controler.GetEditedResourceVariables(self.TagName): lbessard@27: self.VariableList += ",%s"%variable lbessard@27: lbessard@27: def RefreshModel(self): lbessard@121: self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData()) lbessard@56: self.RefreshBuffer() lbessard@56: lbessard@56: def ResetBuffer(self): lbessard@56: pass lbessard@56: lbessard@56: # Buffer the last model state lbessard@56: def RefreshBuffer(self): lbessard@56: self.Controler.BufferProject() lbessard@90: self.ParentWindow.RefreshTitle() lbessard@90: self.ParentWindow.RefreshEditMenu() lbessard@27: lbessard@27: def RefreshView(self): lbessard@121: tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName) lbessard@27: self.TasksTable.SetData(tasks) lbessard@27: self.InstancesTable.SetData(instances) lbessard@27: self.RefreshTypeList() lbessard@27: self.RefreshTaskList() lbessard@27: self.RefreshVariableList() lbessard@27: self.InstancesTable.ResetView(self.InstancesGrid) lbessard@27: self.TasksTable.ResetView(self.TasksGrid) lbessard@27: lbessard@145: def RefreshScaling(self, refresh=True): lbessard@145: pass lbessard@145: lbessard@27: def OnAddTaskButton(self, event): lbessard@27: self.TasksTable.AppendRow(self.TasksDefaultValue.copy()) lbessard@27: self.RefreshModel() lbessard@145: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDeleteTaskButton(self, event): lbessard@27: row = self.TasksGrid.GetGridCursorRow() lbessard@27: self.TasksTable.RemoveRow(row) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnUpTaskButton(self, event): lbessard@27: row = self.TasksGrid.GetGridCursorRow() lbessard@27: self.TasksTable.MoveRow(row, -1, self.TasksGrid) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDownTaskButton(self, event): lbessard@27: row = self.TasksGrid.GetGridCursorRow() lbessard@27: self.TasksTable.MoveRow(row, 1, self.TasksGrid) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnAddInstanceButton(self, event): lbessard@27: self.InstancesTable.AppendRow(self.InstancesDefaultValue.copy()) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDeleteInstanceButton(self, event): lbessard@27: row = self.InstancesGrid.GetGridCursorRow() lbessard@27: self.InstancesTable.RemoveRow(row) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnUpInstanceButton(self, event): lbessard@27: row = self.InstancesGrid.GetGridCursorRow() lbessard@27: self.InstancesTable.MoveRow(row, -1, self.InstancesGrid) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDownInstanceButton(self, event): lbessard@27: row = self.InstancesGrid.GetGridCursorRow() lbessard@27: self.InstancesTable.MoveRow(row, 1, self.InstancesGrid) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnTasksGridCellChange(self, event): lbessard@27: row, col = event.GetRow(), event.GetCol() lbessard@27: if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name": lbessard@27: tasklist = self.TaskList.split(",") lbessard@27: for i in xrange(self.TasksTable.GetNumberRows()): lbessard@27: task = self.TasksTable.GetValueByName(i, "Name") lbessard@27: if task in tasklist: lbessard@27: tasklist.remove(task) lbessard@27: tasklist.remove("") lbessard@27: if len(tasklist) > 0: lbessard@27: old_name = tasklist[0] lbessard@27: new_name = self.TasksTable.GetValue(row, col) lbessard@27: for i in xrange(self.InstancesTable.GetNumberRows()): lbessard@27: if self.InstancesTable.GetValueByName(i, "Task") == old_name: lbessard@27: self.InstancesTable.SetValueByName(i, "Task", new_name) lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnInstancesGridCellChange(self, event): lbessard@27: self.RefreshModel() lbessard@27: self.RefreshView() lbessard@27: event.Skip()