RessourceEditor.py
author laurent
Tue, 05 Apr 2011 19:06:00 +0200
changeset 525 e8d5ab0855d3
parent 494 c91644c2bfa7
child 560 3757f0de0d07
permissions -rw-r--r--
Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
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
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    28
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    29
#-------------------------------------------------------------------------------
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    30
#                          Configuration Editor class
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    31
#-------------------------------------------------------------------------------
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    32
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    33
[ID_CONFIGURATIONEDITOR, 
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    34
] = [wx.NewId() for _init_ctrls in range(1)]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    35
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    36
class ConfigurationEditor(wx.Panel):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    37
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    38
    def _init_ctrls(self, prnt):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    39
        wx.Panel.__init__(self, id=ID_CONFIGURATIONEDITOR, name='', parent=prnt,
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    40
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    41
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    42
    def __init__(self, parent, tagname, window, controler):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    43
        self._init_ctrls(parent)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    44
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    45
        self.ParentWindow = window
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    46
        self.Controler = controler
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    47
        self.TagName = tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    48
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    49
    def SetTagName(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    50
        self.TagName = tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    51
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    52
    def GetTagName(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    53
        return self.TagName
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    54
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    55
    def IsViewing(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    56
        return self.TagName == tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    57
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
    58
    def IsDebugging(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
    59
        return False
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
    60
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    61
    def SetMode(self, mode):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    62
        pass
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    63
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    64
    def ResetBuffer(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    65
        pass
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    66
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    67
    def RefreshView(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    68
        pass
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    69
145
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
    70
    def RefreshScaling(self, refresh=True):
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
    71
        pass
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
    72
365
7bfd014652e0 Bug on clear errors fixed
lbessard
parents: 239
diff changeset
    73
    def ClearErrors(self):
7bfd014652e0 Bug on clear errors fixed
lbessard
parents: 239
diff changeset
    74
        pass
7bfd014652e0 Bug on clear errors fixed
lbessard
parents: 239
diff changeset
    75
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    76
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    77
#                            Resource Editor class
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    78
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    79
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    80
def GetTasksTableColnames():
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    81
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    82
    return [_("Name"), _("Single"), _("Interval"), _("Priority")]
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    83
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    84
def GetInstancesTableColnames():
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    85
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    86
    return [_("Name"), _("Type"), _("Task")]
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    87
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    88
class ResourceTable(wx.grid.PyGridTableBase):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    89
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    90
    """
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    91
    A custom wx.grid.Grid Table using user supplied data
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    92
    """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    93
    def __init__(self, parent, data, colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    94
        # The base class must be initialized *first*
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    95
        wx.grid.PyGridTableBase.__init__(self)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    96
        self.data = data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    97
        self.colnames = colnames
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
    98
        self.Errors = {}
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    99
        self.Parent = parent
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   100
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   101
        self.ColAlignements = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   102
        self.ColSizes = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   103
        # XXX
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   104
        # we need to store the row length and collength to
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   105
        # see if the table has changed size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   106
        self._rows = self.GetNumberRows()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   107
        self._cols = self.GetNumberCols()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   108
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   109
    def GetColAlignements(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   110
        return self.ColAlignements
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   111
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   112
    def SetColAlignements(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   113
        self.ColAlignements = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   114
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   115
    def GetColSizes(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   116
        return self.ColSizes
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   117
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   118
    def SetColSizes(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   119
        self.ColSizes = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   120
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   121
    def GetNumberCols(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   122
        return len(self.colnames)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   123
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   124
    def GetNumberRows(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   125
        return len(self.data)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   126
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   127
    def GetColLabelValue(self, col, translate=True):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   128
        if col < len(self.colnames):
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   129
            if translate:
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   130
                return _(self.colnames[col])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   131
            return self.colnames[col]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   132
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   133
    def GetRowLabelValues(self, row, translate=True):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   134
        return row
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   135
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   136
    def GetValue(self, row, col):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   137
        if row < self.GetNumberRows():
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   138
            name = str(self.data[row].get(self.GetColLabelValue(col, False), ""))
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   139
            return name
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   140
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   141
    def GetValueByName(self, row, colname):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   142
        return self.data[row].get(colname)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   143
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   144
    def SetValue(self, row, col, value):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   145
        if col < len(self.colnames):
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   146
            self.data[row][self.GetColLabelValue(col, False)] = value
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   147
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   148
    def SetValueByName(self, row, colname, value):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   149
        if colname in self.colnames:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   150
            self.data[row][colname] = value
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   151
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   152
    def ResetView(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   153
        """
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   154
        (wx.grid.Grid) -> Reset the grid view.   Call this to
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   155
        update the grid if rows and columns have been added or deleted
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   156
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   157
        grid.BeginBatch()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   158
        for current, new, delmsg, addmsg in [
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   159
            (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
   160
            (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
   161
        ]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   162
            if new < current:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   163
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   164
                grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   165
            elif new > current:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   166
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   167
                grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   168
                self.UpdateValues(grid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   169
        grid.EndBatch()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   170
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   171
        self._rows = self.GetNumberRows()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   172
        self._cols = self.GetNumberCols()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   173
        # update the column rendering scheme
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   174
        self._updateColAttrs(grid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   175
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   176
        # update the scrollbars and the displayed part of the grid
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   177
        grid.AdjustScrollbars()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   178
        grid.ForceRefresh()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   179
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   180
    def UpdateValues(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   181
        """Update all displayed values"""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   182
        # 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
   183
        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   184
        grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   185
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   186
    def _updateColAttrs(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   187
        """
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   188
        wx.grid.Grid -> update the column attributes to add the
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   189
        appropriate renderer given the column name.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   190
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   191
        Otherwise default to the default renderer.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   192
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   193
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   194
        for col in range(self.GetNumberCols()):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   195
            attr = wx.grid.GridCellAttr()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   196
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   197
            grid.SetColAttr(col, attr)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   198
            grid.SetColSize(col, self.ColSizes[col])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   199
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   200
        for row in range(self.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   201
            for col in range(self.GetNumberCols()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   202
                editor = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   203
                renderer = None
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   204
                colname = self.GetColLabelValue(col, False)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   205
                grid.SetReadOnly(row, col, False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   206
                if colname in ["Name","Interval"]:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   207
                    editor = wx.grid.GridCellTextEditor()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   208
                    renderer = wx.grid.GridCellStringRenderer()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   209
                    if colname == "Interval" and self.GetValueByName(row, "Single") != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   210
                        grid.SetReadOnly(row, col, True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   211
                elif colname == "Single":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   212
                    editor = wx.grid.GridCellChoiceEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   213
                    editor.SetParameters(self.Parent.VariableList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   214
                    if self.GetValueByName(row, "Interval") != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   215
                        grid.SetReadOnly(row, col, True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   216
                elif colname == "Type":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   217
                    editor = wx.grid.GridCellChoiceEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   218
                    editor.SetParameters(self.Parent.TypeList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   219
                elif colname == "Priority":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   220
                    editor = wx.grid.GridCellNumberEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   221
                    editor.SetParameters("0,65535")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   222
                elif colname == "Task":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   223
                    editor = wx.grid.GridCellChoiceEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   224
                    editor.SetParameters(self.Parent.TaskList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   225
                    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   226
                grid.SetCellEditor(row, col, editor)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   227
                grid.SetCellRenderer(row, col, renderer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   228
                
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   229
                if row in self.Errors and self.Errors[row][0] == colname.lower():
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   230
                    grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   231
                    grid.SetCellTextColour(row, col, wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   232
                    grid.MakeCellVisible(row, col)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   233
                else:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   234
                    grid.SetCellTextColour(row, col, wx.BLACK)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   235
                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   236
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   237
    def SetData(self, data):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   238
        self.data = data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   239
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   240
    def GetData(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   241
        return self.data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   242
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   243
    def GetCurrentIndex(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   244
        return self.CurrentIndex
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   245
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   246
    def SetCurrentIndex(self, index):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   247
        self.CurrentIndex = index
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   248
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   249
    def AppendRow(self, row_content):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   250
        self.data.append(row_content)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   251
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   252
    def RemoveRow(self, row_index):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   253
        self.data.pop(row_index)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   254
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   255
    def MoveRow(self, row_index, move, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   256
        new_index = max(0, min(row_index + move, len(self.data) - 1))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   257
        if new_index != row_index:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   258
            self.data.insert(new_index, self.data.pop(row_index))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   259
            grid.SetGridCursor(new_index, grid.GetGridCursorCol())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   260
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   261
    def Empty(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   262
        self.data = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   263
        self.editors = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   264
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   265
    def AddError(self, infos):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   266
        self.Errors[infos[0]] = infos[1:]
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   267
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   268
    def ClearErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   269
        self.Errors = {}
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   270
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   271
[ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   272
 ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   273
 ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   274
 ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   275
 ID_RESOURCEEDITORDOWNINSTANCEBUTTON, ID_RESOURCEEDITORADDTASKBUTTON,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   276
 ID_RESOURCEEDITORDELETETASKBUTTON, ID_RESOURCEEDITORUPTASKBUTTON,
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   277
 ID_RESOURCEEDITORDOWNTASKBUTTON,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   278
] = [wx.NewId() for _init_ctrls in range(13)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   279
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   280
class ResourceEditor(wx.Panel):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   281
    
113
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   282
    if wx.VERSION < (2, 6, 0):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   283
        def Bind(self, event, function, id = None):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   284
            if id is not None:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   285
                event(self, id, function)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   286
            else:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   287
                event(self, function)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   288
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   289
    def _init_coll_InstancesSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   290
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   291
        parent.AddGrowableRow(1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   292
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   293
    def _init_coll_InstancesSizer_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   294
        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
   295
        parent.AddWindow(self.InstancesGrid, 0, border=0, flag=wx.GROW)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   296
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   297
    def _init_coll_InstancesButtonsSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   298
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   299
        parent.AddGrowableRow(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   300
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   301
    def _init_coll_InstancesButtonsSizer_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   302
        parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   303
        parent.AddWindow(self.AddInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   304
        parent.AddWindow(self.DeleteInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   305
        parent.AddWindow(self.UpInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   306
        parent.AddWindow(self.DownInstanceButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   307
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   308
    def _init_coll_TasksSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   309
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   310
        parent.AddGrowableRow(1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   311
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   312
    def _init_coll_TasksSizer_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   313
        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
   314
        parent.AddWindow(self.TasksGrid, 0, border=0, flag=wx.GROW)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   315
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   316
    def _init_coll_TasksButtonsSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   317
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   318
        parent.AddGrowableRow(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   319
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   320
    def _init_coll_TasksButtonsSizer_Items(self, parent):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   321
        parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   322
        parent.AddWindow(self.AddTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   323
        parent.AddWindow(self.DeleteTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   324
        parent.AddWindow(self.UpTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   325
        parent.AddWindow(self.DownTaskButton, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   326
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   327
    def _init_coll_MainGridSizer_Items(self, parent):
124
635d0817508c Adding space all around ResourceEditor
lbessard
parents: 121
diff changeset
   328
        parent.AddSizer(self.TasksSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
635d0817508c Adding space all around ResourceEditor
lbessard
parents: 121
diff changeset
   329
        parent.AddSizer(self.InstancesSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   330
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   331
    def _init_coll_MainGridSizer_Growables(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   332
        parent.AddGrowableCol(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   333
        parent.AddGrowableRow(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   334
        parent.AddGrowableRow(1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   335
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   336
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   337
        self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   338
        self.InstancesSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   339
        self.InstancesButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   340
        self.TasksSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   341
        self.TasksButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   342
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   343
        self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   344
        self._init_coll_MainGridSizer_Items(self.MainGridSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   345
        self._init_coll_InstancesSizer_Growables(self.InstancesSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   346
        self._init_coll_InstancesSizer_Items(self.InstancesSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   347
        self._init_coll_InstancesButtonsSizer_Growables(self.InstancesButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   348
        self._init_coll_InstancesButtonsSizer_Items(self.InstancesButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   349
        self._init_coll_TasksSizer_Growables(self.TasksSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   350
        self._init_coll_TasksSizer_Items(self.TasksSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   351
        self._init_coll_TasksButtonsSizer_Growables(self.TasksButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   352
        self._init_coll_TasksButtonsSizer_Items(self.TasksButtonsSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   353
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   354
        self.SetSizer(self.MainGridSizer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   355
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   356
    def _init_ctrls(self, prnt):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   357
        wx.Panel.__init__(self, id=ID_RESOURCEEDITOR, name='', parent=prnt,
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 64
diff changeset
   358
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   359
        
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   360
        self.staticText1 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   361
              label=_(u'Tasks:'), name='staticText2', parent=self, pos=wx.Point(0,
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   362
              0), size=wx.DefaultSize, style=wx.ALIGN_CENTER)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   363
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   364
        self.TasksGrid = wx.grid.Grid(id=ID_RESOURCEEDITORTASKSGRID,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   365
              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
   366
              size=wx.Size(-1, -1), style=wx.VSCROLL)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   367
        self.TasksGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   368
              'Sans'))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   369
        self.TasksGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   370
              False, 'Sans'))
113
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   371
        if wx.VERSION >= (2, 5, 0):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   372
            self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   373
        else:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   374
            wx.grid.EVT_GRID_CELL_CHANGE(self.TasksGrid, self.OnTasksGridCellChange)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   375
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   376
        self.AddTaskButton = wx.Button(id=ID_RESOURCEEDITORADDTASKBUTTON, label=_('Add Task'),
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   377
              name='AddTaskButton', parent=self, pos=wx.Point(0, 0),
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   378
              size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   379
        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
   380
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   381
        self.DeleteTaskButton = wx.Button(id=ID_RESOURCEEDITORDELETETASKBUTTON, label=_('Delete Task'),
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   382
              name='DeleteTaskButton', parent=self, pos=wx.Point(0, 0),
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   383
              size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   384
        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
   385
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   386
        self.UpTaskButton = wx.Button(id=ID_RESOURCEEDITORUPTASKBUTTON, label='^',
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   387
              name='UpTaskButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   388
              size=wx.Size(32, 32), style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   389
        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
   390
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   391
        self.DownTaskButton = wx.Button(id=ID_RESOURCEEDITORDOWNTASKBUTTON, label='v',
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   392
              name='DownTaskButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   393
              size=wx.Size(32, 32), style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   394
        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
   395
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   396
        self.staticText2 = wx.StaticText(id=ID_RESOURCEEDITORSTATICTEXT2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   397
              label=_(u'Instances:'), name='staticText1', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   398
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=wx.ALIGN_CENTER)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   399
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   400
        self.InstancesGrid = wx.grid.Grid(id=ID_RESOURCEEDITORINSTANCESGRID,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   401
              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
   402
              size=wx.Size(-1, -1), style=wx.VSCROLL)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   403
        self.InstancesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   404
              'Sans'))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   405
        self.InstancesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   406
              False, 'Sans'))
113
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   407
        if wx.VERSION >= (2, 5, 0):
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   408
            self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnInstancesGridCellChange)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   409
        else:
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   410
            wx.grid.EVT_GRID_CELL_CHANGE(self.InstancesGrid, self.OnInstancesGridCellChange)
9eeaebd867aa Adding support for wxpython 2.4
lbessard
parents: 107
diff changeset
   411
        
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   412
        self.AddInstanceButton = wx.Button(id=ID_RESOURCEEDITORADDINSTANCEBUTTON, label=_('Add Instance'),
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   413
              name='AddInstanceButton', parent=self, pos=wx.Point(0, 0),
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   414
              size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   415
        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
   416
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   417
        self.DeleteInstanceButton = wx.Button(id=ID_RESOURCEEDITORDELETEINSTANCEBUTTON, label=_('Delete Instance'),
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   418
              name='DeleteInstanceButton', parent=self, pos=wx.Point(0, 0),
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   419
              size=wx.DefaultSize, style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   420
        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
   421
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   422
        self.UpInstanceButton = wx.Button(id=ID_RESOURCEEDITORUPINSTANCEBUTTON, label='^',
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   423
              name='UpInstanceButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   424
              size=wx.Size(32, 32), style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   425
        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
   426
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   427
        self.DownInstanceButton = wx.Button(id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON, label='v',
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   428
              name='DownInstanceButton', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   429
              size=wx.Size(32, 32), style=0)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   430
        self.Bind(wx.EVT_BUTTON, self.OnDownInstanceButton, id=ID_RESOURCEEDITORDOWNINSTANCEBUTTON)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   431
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   432
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   433
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   434
    def __init__(self, parent, tagname, window, controler):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   435
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   436
        
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   437
        self.ParentWindow = window
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   438
        self.Controler = controler
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   439
        self.TagName = tagname
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   440
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   441
        self.TasksDefaultValue = {"Name" : "", "Single" : "", "Interval" : "", "Priority" : 0}
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   442
        self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   443
        self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   444
        self.TasksTable.SetColSizes([200, 100, 100, 100])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   445
        self.TasksGrid.SetTable(self.TasksTable)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   446
        self.TasksGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   447
        self.TasksTable.ResetView(self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   448
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   449
        self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""}
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   450
        self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   451
        self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   452
        self.InstancesTable.SetColSizes([200, 150, 150])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   453
        self.InstancesGrid.SetTable(self.InstancesTable)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   454
        self.InstancesGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   455
        self.InstancesTable.ResetView(self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   456
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   457
    def SetTagName(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   458
        self.TagName = tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   459
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   460
    def GetTagName(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   461
        return self.TagName
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   462
    
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   463
    def IsViewing(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   464
        return self.TagName == tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   465
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   466
    def IsDebugging(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   467
        return False
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   468
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   469
    def SetMode(self, mode):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   470
        pass
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   471
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   472
    def RefreshTypeList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   473
        self.TypeList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   474
        blocktypes = self.Controler.GetBlockResource()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   475
        for blocktype in blocktypes:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   476
            self.TypeList += ",%s"%blocktype
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   477
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   478
    def RefreshTaskList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   479
        self.TaskList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   480
        for row in xrange(self.TasksTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   481
            self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   482
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   483
    def RefreshVariableList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   484
        self.VariableList = ""
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   485
        for variable in self.Controler.GetEditedResourceVariables(self.TagName):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   486
            self.VariableList += ",%s"%variable
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   487
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   488
    def RefreshModel(self):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   489
        self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData())
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   490
        self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   491
        
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   492
    def ResetBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   493
        pass
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   494
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   495
    # Buffer the last model state
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   496
    def RefreshBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   497
        self.Controler.BufferProject()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   498
        self.ParentWindow.RefreshTitle()
494
c91644c2bfa7 Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 407
diff changeset
   499
        self.ParentWindow.RefreshFileMenu()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   500
        self.ParentWindow.RefreshEditMenu()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   501
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   502
    def RefreshView(self):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   503
        tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   504
        self.TasksTable.SetData(tasks)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   505
        self.InstancesTable.SetData(instances)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   506
        self.RefreshTypeList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   507
        self.RefreshTaskList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   508
        self.RefreshVariableList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   509
        self.InstancesTable.ResetView(self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   510
        self.TasksTable.ResetView(self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   511
145
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
   512
    def RefreshScaling(self, refresh=True):
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
   513
        pass
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
   514
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   515
    def OnAddTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   516
        self.TasksTable.AppendRow(self.TasksDefaultValue.copy())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   517
        self.RefreshModel()
145
4fb225afddf4 Adding scaling
lbessard
parents: 124
diff changeset
   518
        self.RefreshView()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   519
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   520
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   521
    def OnDeleteTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   522
        row = self.TasksGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   523
        self.TasksTable.RemoveRow(row)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   524
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   525
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   526
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   527
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   528
    def OnUpTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   529
        row = self.TasksGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   530
        self.TasksTable.MoveRow(row, -1, self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   531
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   532
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   533
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   534
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   535
    def OnDownTaskButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   536
        row = self.TasksGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   537
        self.TasksTable.MoveRow(row, 1, self.TasksGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   538
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   539
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   540
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   541
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   542
    def OnAddInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   543
        self.InstancesTable.AppendRow(self.InstancesDefaultValue.copy())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   544
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   545
        self.RefreshView()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   546
        self.ParentWindow.RefreshInstancesTree()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   547
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   548
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   549
    def OnDeleteInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   550
        row = self.InstancesGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   551
        self.InstancesTable.RemoveRow(row)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   552
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   553
        self.RefreshView()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   554
        self.ParentWindow.RefreshInstancesTree()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   555
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   556
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   557
    def OnUpInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   558
        row = self.InstancesGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   559
        self.InstancesTable.MoveRow(row, -1, self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   560
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   561
        self.RefreshView()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   562
        self.ParentWindow.RefreshInstancesTree()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   563
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   564
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   565
    def OnDownInstanceButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   566
        row = self.InstancesGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   567
        self.InstancesTable.MoveRow(row, 1, self.InstancesGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   568
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   569
        self.RefreshView()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   570
        self.ParentWindow.RefreshInstancesTree()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   571
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   572
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   573
    def OnTasksGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   574
        row, col = event.GetRow(), event.GetCol()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   575
        if self.TasksTable.GetColLabelValue(event.GetCol()) == "Name":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   576
            tasklist = self.TaskList.split(",")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   577
            for i in xrange(self.TasksTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   578
                task = self.TasksTable.GetValueByName(i, "Name")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   579
                if task in tasklist:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   580
                    tasklist.remove(task)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   581
            tasklist.remove("")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   582
            if len(tasklist) > 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   583
                old_name = tasklist[0]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   584
                new_name = self.TasksTable.GetValue(row, col)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   585
                for i in xrange(self.InstancesTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   586
                    if self.InstancesTable.GetValueByName(i, "Task") == old_name:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   587
                        self.InstancesTable.SetValueByName(i, "Task", new_name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   588
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   589
        self.RefreshView()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   590
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   591
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   592
    def OnInstancesGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   593
        self.RefreshModel()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   594
        self.RefreshView()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   595
        self.ParentWindow.RefreshInstancesTree()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   596
        event.Skip()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   597
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   598
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   599
#                        Errors showing functions
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   600
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   601
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   602
    def ClearErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   603
        self.TasksTable.ClearErrors()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   604
        self.InstancesTable.ClearErrors()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   605
        self.TasksTable.ResetView(self.TasksGrid)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   606
        self.InstancesTable.ResetView(self.InstancesGrid)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   607
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   608
    def AddShownError(self, infos, start, end):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   609
        if infos[0] == "task":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   610
            self.TasksTable.AddError(infos[1:])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   611
        elif infos[0] == "instance":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   612
            self.InstancesTable.AddError(infos[1:])
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   613