RessourceEditor.py
author jon
Tue, 04 Sep 2007 17:08:12 +0200
changeset 84 0369ad49e67f
parent 80 c798a68c5560
child 90 2245e8776086
permissions -rw-r--r--
Bug on choice element in xmlclass fixed
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     3
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     8
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    10
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    15
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
    19
#General Public License for more details.
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    20
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    24
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    28
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    29
#                            Resource Editor class
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    30
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    33
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    36
    """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    37
    def __init__(self, parent, data, colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    40
        self.data = data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    41
        self.colnames = colnames
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    42
        self.Parent = parent
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    43
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    44
        self.ColAlignements = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    45
        self.ColSizes = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    46
        # XXX
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    47
        # we need to store the row length and collength to
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    48
        # see if the table has changed size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    49
        self._rows = self.GetNumberRows()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    50
        self._cols = self.GetNumberCols()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    51
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    52
    def GetColAlignements(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    53
        return self.ColAlignements
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    54
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    55
    def SetColAlignements(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    56
        self.ColAlignements = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    57
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    58
    def GetColSizes(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    59
        return self.ColSizes
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    60
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    61
    def SetColSizes(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    62
        self.ColSizes = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    63
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    64
    def GetNumberCols(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    65
        return len(self.colnames)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    66
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    67
    def GetNumberRows(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    68
        return len(self.data)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    69
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    70
    def GetColLabelValue(self, col):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    71
        if col < len(self.colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    72
            return self.colnames[col]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    73
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    74
    def GetRowLabelValues(self, row):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    75
        return row
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    76
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    77
    def GetValue(self, row, col):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    78
        if row < self.GetNumberRows():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    79
            name = str(self.data[row].get(self.GetColLabelValue(col), ""))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    80
            return name
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    81
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    82
    def GetValueByName(self, row, colname):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    83
        return self.data[row].get(colname)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    84
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    85
    def SetValue(self, row, col, value):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    86
        if col < len(self.colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    87
            self.data[row][self.GetColLabelValue(col)] = value
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    88
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    89
    def SetValueByName(self, row, colname, value):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    90
        if colname in self.colnames:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    91
            self.data[row][colname] = value
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    92
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    93
    def ResetView(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    96
        update the grid if rows and columns have been added or deleted
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    97
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    98
        grid.BeginBatch()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   102
        ]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   105
                grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   108
                grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   109
                self.UpdateValues(grid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   110
        grid.EndBatch()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   111
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   112
        self._rows = self.GetNumberRows()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   113
        self._cols = self.GetNumberCols()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   114
        # update the column rendering scheme
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   115
        self._updateColAttrs(grid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   116
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   117
        # update the scrollbars and the displayed part of the grid
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   118
        grid.AdjustScrollbars()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   119
        grid.ForceRefresh()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   120
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   121
    def UpdateValues(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   122
        """Update all displayed values"""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   125
        grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   126
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   127
    def _updateColAttrs(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   130
        appropriate renderer given the column name.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   131
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   132
        Otherwise default to the default renderer.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   133
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   134
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   138
            grid.SetColAttr(col, attr)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   139
            grid.SetColSize(col, self.ColSizes[col])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   140
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   141
        for row in range(self.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   142
            for col in range(self.GetNumberCols()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   143
                editor = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   144
                renderer = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   145
                colname = self.GetColLabelValue(col)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   146
                grid.SetReadOnly(row, col, False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   150
                    if colname == "Interval" and self.GetValueByName(row, "Single") != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   151
                        grid.SetReadOnly(row, col, True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   154
                    editor.SetParameters(self.Parent.VariableList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   155
                    if self.GetValueByName(row, "Interval") != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   156
                        grid.SetReadOnly(row, col, True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   159
                    editor.SetParameters(self.Parent.TypeList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   162
                    editor.SetParameters("0,65535")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   165
                    editor.SetParameters(self.Parent.TaskList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   166
                    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   167
                grid.SetCellEditor(row, col, editor)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   168
                grid.SetCellRenderer(row, col, renderer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   171
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   172
    def SetData(self, data):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   173
        self.data = data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   174
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   175
    def GetData(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   176
        return self.data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   177
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   178
    def GetCurrentIndex(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   179
        return self.CurrentIndex
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   180
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   181
    def SetCurrentIndex(self, index):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   182
        self.CurrentIndex = index
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   183
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   184
    def AppendRow(self, row_content):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   185
        self.data.append(row_content)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   186
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   187
    def RemoveRow(self, row_index):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   188
        self.data.pop(row_index)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   189
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   190
    def MoveRow(self, row_index, move, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   191
        new_index = max(0, min(row_index + move, len(self.data) - 1))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   192
        if new_index != row_index:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   193
            self.data.insert(new_index, self.data.pop(row_index))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   194
            grid.SetGridCursor(new_index, grid.GetGridCursorCol())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   195
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   196
    def Empty(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   197
        self.data = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   198
        self.editors = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   199
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   208
] = [wx.NewId() for _init_ctrls in range(13)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   209
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   210
class ResourceEditor(wx.Panel):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   211
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   212
    def _init_coll_InstancesSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   213
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   214
        parent.AddGrowableRow(1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   215
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   219
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   220
    def _init_coll_InstancesButtonsSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   221
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   222
        parent.AddGrowableRow(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   223
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   226
        parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   227
        parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   228
        parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   229
        parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   230
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   231
    def _init_coll_TasksSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   232
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   233
        parent.AddGrowableRow(1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   234
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   238
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   239
    def _init_coll_TasksButtonsSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   240
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   241
        parent.AddGrowableRow(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   242
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   245
        parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   246
        parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   247
        parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   248
        parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   249
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   253
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   254
    def _init_coll_MainGridSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   255
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   256
        parent.AddGrowableRow(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   257
        parent.AddGrowableRow(1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   258
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   259
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   260
        self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   261
        self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   262
        self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   263
        self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   264
        self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   265
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   266
        self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   267
        self._init_coll_MainGridSizer_Items(self.MainGridSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   268
        self._init_coll_InstancesSizer_Growables(self.InstancesSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   269
        self._init_coll_InstancesSizer_Items(self.InstancesSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   270
        self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   271
        self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   272
        self._init_coll_TasksSizer_Growables(self.TasksSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   273
        self._init_coll_TasksSizer_Items(self.TasksSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   274
        self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   275
        self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   276
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   277
        self.SetSizer(self.MainGridSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   278
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
c798a68c5560 Lots of bugs fixed
lbessard
parents: 64
diff changeset
   281
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   290
        self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   291
              'Sans'))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   292
        self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   297
              name='AddTaskButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   302
              name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   307
              name='UpTaskButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   312
              name='DownTaskButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   323
        self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   324
              'Sans'))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   325
        self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   330
              name='AddInstanceButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   335
              name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   340
              name='UpInstanceButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   345
              name='DownInstanceButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   348
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   349
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   350
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   351
    def __init__(self, parent, window, controler):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   352
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   353
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   354
        self.Parent = window
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   355
        self.Controler = controler
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   356
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   357
        self.TasksDefaultValue = {"Name" : "", "Single" : "", "Interval" : "", "Priority" : 0}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   360
        self.TasksTable.SetColSizes([200, 100, 100, 100])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   361
        self.TasksGrid.SetTable(self.TasksTable)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   362
        self.TasksGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   363
        self.TasksTable.ResetView(self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   364
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   365
        self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   368
        self.InstancesTable.SetColSizes([200, 150, 150])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   369
        self.InstancesGrid.SetTable(self.InstancesTable)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   370
        self.InstancesGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   371
        self.InstancesTable.ResetView(self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   372
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   373
    def SetMode(self, mode):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   374
        pass
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   375
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   376
    def RefreshTypeList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   377
        self.TypeList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   378
        blocktypes = self.Controler.GetBlockResource()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   379
        for blocktype in blocktypes:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   380
            self.TypeList += ",%s"%blocktype
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   381
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   382
    def RefreshTaskList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   383
        self.TaskList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   384
        for row in xrange(self.TasksTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   385
            self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   386
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   387
    def RefreshVariableList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   388
        self.VariableList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   389
        for variable in self.Controler.GetCurrentResourceEditingVariables():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   390
            self.VariableList += ",%s"%variable
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   391
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   392
    def RefreshModel(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   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
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   404
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   405
    def RefreshView(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   406
        tasks, instances = self.Controler.GetCurrentResourceEditingInfos()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   407
        self.TasksTable.SetData(tasks)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   408
        self.InstancesTable.SetData(instances)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   409
        self.RefreshTypeList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   410
        self.RefreshTaskList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   411
        self.RefreshVariableList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   412
        self.InstancesTable.ResetView(self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   413
        self.TasksTable.ResetView(self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   414
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   415
    def OnAddTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   416
        self.TasksTable.AppendRow(self.TasksDefaultValue.copy())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   417
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   418
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   419
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   420
    def OnDeleteTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   421
        row = self.TasksGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   422
        self.TasksTable.RemoveRow(row)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   423
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   424
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   425
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   426
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   427
    def OnUpTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   428
        row = self.TasksGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   429
        self.TasksTable.MoveRow(row, -1, self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   430
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   431
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   432
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   433
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   434
    def OnDownTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   435
        row = self.TasksGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   436
        self.TasksTable.MoveRow(row, 1, self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   437
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   438
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   439
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   440
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   441
    def OnAddInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   442
        self.InstancesTable.AppendRow(self.InstancesDefaultValue.copy())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   443
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   444
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   445
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   446
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   447
    def OnDeleteInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   448
        row = self.InstancesGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   449
        self.InstancesTable.RemoveRow(row)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   450
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   451
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   452
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   453
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   454
    def OnUpInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   455
        row = self.InstancesGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   456
        self.InstancesTable.MoveRow(row, -1, self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   457
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   458
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   459
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   460
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   461
    def OnDownInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   462
        row = self.InstancesGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   463
        self.InstancesTable.MoveRow(row, 1, self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   464
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   465
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   466
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   467
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   468
    def OnTasksGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   469
        row, col = event.GetRow(), event.GetCol()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   470
        if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   471
            tasklist = self.TaskList.split(",")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   472
            for i in xrange(self.TasksTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   473
                task = self.TasksTable.GetValueByName(i, "Name")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   474
                if task in tasklist:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   475
                    tasklist.remove(task)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   476
            tasklist.remove("")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   477
            if len(tasklist) > 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   478
                old_name = tasklist[0]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   479
                new_name = self.TasksTable.GetValue(row, col)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   480
                for i in xrange(self.InstancesTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   481
                    if self.InstancesTable.GetValueByName(i, "Task") == old_name:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   482
                        self.InstancesTable.SetValueByName(i, "Task", new_name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   483
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   484
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   485
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   486
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   487
    def OnInstancesGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   488
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   489
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   490
        event.Skip()