DataTypeEditor.py
author laurent
Thu, 21 Apr 2011 11:06:17 +0200
changeset 535 08f32198e932
parent 507 42150e041dbe
child 556 69214983dd03
permissions -rw-r--r--
Adding support for saving frame size while closing and restore it at next launch
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     3
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     6
#
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     8
#
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    10
#
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    15
#
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    19
#General Public License for more details.
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    20
#
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    24
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    25
import wx
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    26
import wx.grid
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    27
import wx.gizmos
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    28
from plcopen.structures import IEC_KEYWORDS, TestIdentifier
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    29
207
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    30
import re
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    31
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    32
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    33
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    34
def AppendMenu(parent, help, id, kind, text):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    35
    if wx.VERSION >= (2, 6, 0):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    36
        parent.Append(help=help, id=id, kind=kind, text=text)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    37
    else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    38
        parent.Append(helpString=help, id=id, kind=kind, item=text)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    39
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    40
#-------------------------------------------------------------------------------
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    41
#                            Structure Elements Table
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    42
#-------------------------------------------------------------------------------
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    43
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    44
def GetElementsTableColnames():
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    45
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    46
    return ["#", _("Name"), _("Type"), _("Initial Value")]
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    47
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    48
class ElementsTable(wx.grid.PyGridTableBase):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    49
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    50
    """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    51
    A custom wx.grid.Grid Table using user supplied data
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    52
    """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    53
    def __init__(self, parent, data, colnames):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    54
        # The base class must be initialized *first*
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    55
        wx.grid.PyGridTableBase.__init__(self)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    56
        self.data = data
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    57
        self.old_value = None
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    58
        self.colnames = colnames
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    59
        self.Errors = {}
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    60
        self.Parent = parent
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    61
        # XXX
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    62
        # we need to store the row length and collength to
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    63
        # see if the table has changed size
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    64
        self._rows = self.GetNumberRows()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    65
        self._cols = self.GetNumberCols()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    66
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    67
    def GetNumberCols(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    68
        return len(self.colnames)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    69
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    70
    def GetNumberRows(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    71
        return len(self.data)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    72
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    73
    def GetColLabelValue(self, col, translate=True):
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    74
        if col < len(self.colnames):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    75
            if translate:
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    76
                return _(self.colnames[col])
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    77
            return self.colnames[col]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    78
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    79
    def GetRowLabelValues(self, row, translate=True):
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    80
        return row
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    81
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    82
    def GetValue(self, row, col):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    83
        if row < self.GetNumberRows():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    84
            if col == 0:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    85
                return row + 1
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    86
            name = str(self.data[row].get(self.GetColLabelValue(col, False), ""))
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    87
            return name
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    88
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    89
    def SetValue(self, row, col, value):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    90
        if col < len(self.colnames):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    91
            colname = self.GetColLabelValue(col, False)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    92
            if colname == "Name":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    93
                self.old_value = self.data[row][colname]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    94
            self.data[row][colname] = value
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    95
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    96
    def GetValueByName(self, row, colname):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    97
        if row < self.GetNumberRows():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    98
            return self.data[row].get(colname)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    99
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   100
    def SetValueByName(self, row, colname, value):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   101
        if row < self.GetNumberRows():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   102
            self.data[row][colname] = value
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   103
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   104
    def GetOldValue(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   105
        return self.old_value
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   106
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   107
    def ResetView(self, grid):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   108
        """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   109
        (wx.grid.Grid) -> Reset the grid view.   Call this to
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   110
        update the grid if rows and columns have been added or deleted
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   111
        """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   112
        grid.BeginBatch()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   113
        for current, new, delmsg, addmsg in [
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   114
            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   115
            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   116
        ]:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   117
            if new < current:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   118
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   119
                grid.ProcessTableMessage(msg)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   120
            elif new > current:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   121
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   122
                grid.ProcessTableMessage(msg)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   123
                self.UpdateValues(grid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   124
        grid.EndBatch()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   125
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   126
        self._rows = self.GetNumberRows()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   127
        self._cols = self.GetNumberCols()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   128
        # update the column rendering scheme
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   129
        self._updateColAttrs(grid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   130
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   131
        # update the scrollbars and the displayed part of the grid
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   132
        grid.AdjustScrollbars()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   133
        grid.ForceRefresh()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   134
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   135
    def UpdateValues(self, grid):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   136
        """Update all displayed values"""
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   137
        # This sends an event to the grid table to update all of the values
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   138
        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   139
        grid.ProcessTableMessage(msg)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   140
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   141
    def _updateColAttrs(self, grid):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   142
        """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   143
        wx.grid.Grid -> update the column attributes to add the
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   144
        appropriate renderer given the column name.
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   145
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   146
        Otherwise default to the default renderer.
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   147
        """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   148
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   149
        for row in range(self.GetNumberRows()):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   150
            for col in range(self.GetNumberCols()):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   151
                editor = None
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   152
                renderer = None
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   153
                colname = self.GetColLabelValue(col, False)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   154
                if col != 0:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   155
                    grid.SetReadOnly(row, col, False)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   156
                    if colname == "Name":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   157
                        editor = wx.grid.GridCellTextEditor()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   158
                        renderer = wx.grid.GridCellStringRenderer()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   159
                    elif colname == "Initial Value":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   160
                        editor = wx.grid.GridCellTextEditor()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   161
                        renderer = wx.grid.GridCellStringRenderer()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   162
                    elif colname == "Type":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   163
                        editor = wx.grid.GridCellTextEditor()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   164
                else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   165
                    grid.SetReadOnly(row, col, True)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   166
                
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   167
                grid.SetCellEditor(row, col, editor)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   168
                grid.SetCellRenderer(row, col, renderer)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   169
                
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 313
diff changeset
   170
                if self.Errors.has_key(row) and self.Errors[row][0] == colname.lower():
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   171
                    grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   172
                    grid.SetCellTextColour(row, col, wx.RED)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   173
                    grid.MakeCellVisible(row, col)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   174
                else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   175
                    grid.SetCellTextColour(row, col, wx.BLACK)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   176
                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   177
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   178
    def SetData(self, data):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   179
        self.data = data
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   180
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   181
    def GetData(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   182
        return self.data
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   183
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   184
    def AppendRow(self, row_content):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   185
        self.data.append(row_content)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   186
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   187
    def RemoveRow(self, row_index):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   188
        self.data.pop(row_index)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   189
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   190
    def MoveRow(self, idx, move):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   191
        new_idx = max(0, min(idx + move, len(self.data) - 1))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   192
        if new_idx != idx:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   193
            self.data.insert(new_idx, self.data.pop(idx))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   194
            return new_idx
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   195
        return None
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   196
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   197
    def GetRow(self, row_index):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   198
        return self.data[row_index]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   199
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   200
    def Empty(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   201
        self.data = []
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   202
        self.editors = []
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   203
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   204
    def AddError(self, infos):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   205
        self.Errors[infos[0]] = infos[1:]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   206
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   207
    def ClearErrors(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   208
        self.Errors = {}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   209
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   210
#-------------------------------------------------------------------------------
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 313
diff changeset
   211
#                          Datatype Editor class
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   212
#-------------------------------------------------------------------------------
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   213
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   214
[ID_DATATYPEEDITOR, ID_DATATYPEEDITORSTATICBOX,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   215
 ID_DATATYPEEDITORDERIVATIONTYPE, ID_DATATYPEEDITORDIRECTLYPANEL,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   216
 ID_DATATYPEEDITORSUBRANGEPANEL, ID_DATATYPEEDITORDIRECTLYBASETYPE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   217
 ID_DATATYPEEDITORSUBRANGEBASETYPE, ID_DATATYPEEDITORSUBRANGEMINIMUM, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   218
 ID_DATATYPEEDITORSUBRANGEMAXIMUM, ID_DATATYPEEDITORDIRECTLYINITIALVALUE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   219
 ID_DATATYPEEDITORSUBRANGEINITIALVALUE, ID_DATATYPEEDITORENUMERATEDPANEL,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   220
 ID_DATATYPEEDITORENUMERATEDVALUES, ID_DATATYPEEDITORENUMERATEDINITIALVALUE,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   221
 ID_DATATYPEEDITORARRAYPANEL, ID_DATATYPEEDITORARRAYBASETYPE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   222
 ID_DATATYPEEDITORARRAYDIMENSIONS, ID_DATATYPEEDITORARRAYINITIALVALUE, 
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   223
 ID_DATATYPEEDITORSTRUCTUREPANEL, ID_DATATYPEEDITORSTRUCTUREELEMENTSGRID,
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   224
 ID_DATATYPEEDITORSTRUCTUREADDBUTTON, ID_DATATYPEEDITORSTRUCTUREDELETEBUTTON,
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   225
 ID_DATATYPEEDITORSTRUCTUREUPBUTTON, ID_DATATYPEEDITORSTRUCTUREDOWNBUTTON,
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   226
 ID_DATATYPEEDITORSTATICTEXT1, ID_DATATYPEEDITORSTATICTEXT2, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   227
 ID_DATATYPEEDITORSTATICTEXT3, ID_DATATYPEEDITORSTATICTEXT4, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   228
 ID_DATATYPEEDITORSTATICTEXT5, ID_DATATYPEEDITORSTATICTEXT6, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   229
 ID_DATATYPEEDITORSTATICTEXT7, ID_DATATYPEEDITORSTATICTEXT8,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   230
 ID_DATATYPEEDITORSTATICTEXT9, ID_DATATYPEEDITORSTATICTEXT10, 
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   231
 ID_DATATYPEEDITORSTATICTEXT11, 
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   232
] = [wx.NewId() for _init_ctrls in range(35)]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   233
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   234
def GetDatatypeTypes():
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   235
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   236
    return [_("Directly"), _("Subrange"), _("Enumerated"), _("Array"), _("Structure")]
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   237
DATATYPE_TYPES_DICT = dict([(_(datatype), datatype) for datatype in GetDatatypeTypes()])
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   238
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   239
class DataTypeEditor(wx.Panel):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   240
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   241
    def _init_coll_MainSizer_Items(self, parent):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   242
        parent.AddSizer(self.TopSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   243
        parent.AddSizer(self.TypeInfosSizer, 0, border=5, flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   244
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   245
    def _init_coll_MainSizer_Growables(self, parent):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   246
        parent.AddGrowableCol(0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   247
        parent.AddGrowableRow(1)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   248
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   249
    def _init_coll_TopSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   250
        parent.AddWindow(self.staticText1, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   251
        parent.AddWindow(self.DerivationType, 0, border=5, flag=wx.GROW|wx.RIGHT)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   252
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   253
    def _init_coll_TypeInfosSizer_Items(self, parent):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   254
        parent.AddWindow(self.DirectlyPanel, 1, border=0, flag=wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   255
        parent.AddWindow(self.SubrangePanel, 1, border=0, flag=wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   256
        parent.AddWindow(self.EnumeratedPanel, 1, border=0, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   257
        parent.AddWindow(self.ArrayPanel, 1, border=0, flag=wx.ALL)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   258
        parent.AddWindow(self.StructurePanel, 1, border=0, flag=wx.GROW|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   259
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   260
    def _init_coll_DirectlyPanelSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   261
        parent.AddWindow(self.staticText2, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   262
        parent.AddWindow(self.DirectlyBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   263
        parent.AddWindow(self.staticText3, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   264
        parent.AddWindow(self.DirectlyInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   265
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   266
    def _init_coll_SubrangePanelSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   267
        parent.AddWindow(self.staticText4, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   268
        parent.AddWindow(self.SubrangeBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   269
        parent.AddWindow(self.staticText5, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   270
        parent.AddWindow(self.SubrangeInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   271
        parent.AddWindow(self.staticText6, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   272
        parent.AddWindow(self.SubrangeMinimum, 1, border=5, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   273
        parent.AddWindow(wx.Size(0, 0), 1, border=5, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   274
        parent.AddWindow(wx.Size(0, 0), 1, border=5, flag=wx.GROW|wx.ALL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   275
        parent.AddWindow(self.staticText7, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   276
        parent.AddWindow(self.SubrangeMaximum, 1, border=5, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   277
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   278
    def _init_coll_EnumeratedPanelSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   279
        parent.AddWindow(self.EnumeratedValues, 1, border=5, flag=wx.GROW|wx.ALL)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   280
        parent.AddSizer(self.EnumeratedPanelRightSizer, 1, border=0, flag=0)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   281
        
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   282
    def _init_coll_EnumeratedPanelRightSizer_Items(self, parent):
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   283
        parent.AddWindow(self.staticText8, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   284
        parent.AddWindow(self.EnumeratedInitialValue, 1, border=5, flag=wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   285
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   286
    def _init_coll_ArrayPanelSizer_Items(self, parent):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   287
        parent.AddSizer(self.ArrayPanelLeftSizer, 0, border=0, flag=wx.GROW)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   288
        parent.AddSizer(self.ArrayPanelRightSizer, 0, border=0, flag=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   289
        parent.AddWindow(self.ArrayDimensions, 0, border=5, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   290
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   291
    def _init_coll_ArrayPanelSizer_Growables(self, parent):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   292
        parent.AddGrowableCol(0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   293
        parent.AddGrowableCol(1)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   294
        parent.AddGrowableRow(1)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   295
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   296
    def _init_coll_ArrayPanelLeftSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   297
        parent.AddWindow(self.staticText9, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   298
        parent.AddWindow(self.ArrayBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   299
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   300
    def _init_coll_ArrayPanelRightSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   301
        parent.AddWindow(self.staticText10, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   302
        parent.AddWindow(self.ArrayInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   303
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   304
    def _init_coll_StructurePanelSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   305
        parent.AddWindow(self.staticText11, 0, border=5, flag=wx.ALL)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   306
        parent.AddWindow(self.StructureElementsGrid, 0, border=0, flag=wx.GROW)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   307
        parent.AddSizer(self.StructurePanelButtonSizer, 0, border=0, flag=wx.ALIGN_RIGHT)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   308
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   309
    def _init_coll_StructurePanelSizer_Growables(self, parent):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   310
        parent.AddGrowableCol(0)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   311
        parent.AddGrowableRow(1)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   312
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   313
    def _init_coll_StructurePanelButtonSizer_Items(self, parent):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   314
        parent.AddWindow(self.StructureAddButton, 0, border=5, flag=wx.ALL)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   315
        parent.AddWindow(self.StructureDeleteButton, 0, border=5, flag=wx.ALL)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   316
        parent.AddWindow(self.StructureUpButton, 0, border=5, flag=wx.ALL)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   317
        parent.AddWindow(self.StructureDownButton, 0, border=5, flag=wx.ALL)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   318
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   319
    def _init_sizers(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   320
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   321
        self.TopSizer = wx.BoxSizer(wx.HORIZONTAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   322
        self.TypeInfosSizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   323
        self.DirectlyPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   324
        self.SubrangePanelSizer = wx.GridSizer(cols=4, hgap=5, rows=3, vgap=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   325
        self.EnumeratedPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   326
        self.EnumeratedPanelRightSizer = wx.BoxSizer(wx.HORIZONTAL)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   327
        self.ArrayPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   328
        self.ArrayPanelLeftSizer = wx.BoxSizer(wx.HORIZONTAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   329
        self.ArrayPanelRightSizer = wx.BoxSizer(wx.HORIZONTAL)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   330
        self.StructurePanelSizer = wx.FlexGridSizer(cols=1, hgap=5, rows=3, vgap=0)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   331
        self.StructurePanelButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   332
        self._init_coll_MainSizer_Items(self.MainSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   333
        self._init_coll_MainSizer_Growables(self.MainSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   334
        self._init_coll_TopSizer_Items(self.TopSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   335
        self._init_coll_TypeInfosSizer_Items(self.TypeInfosSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   336
        self._init_coll_DirectlyPanelSizer_Items(self.DirectlyPanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   337
        self._init_coll_SubrangePanelSizer_Items(self.SubrangePanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   338
        self._init_coll_EnumeratedPanelSizer_Items(self.EnumeratedPanelSizer)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   339
        self._init_coll_EnumeratedPanelRightSizer_Items(self.EnumeratedPanelRightSizer)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   340
        self._init_coll_ArrayPanelSizer_Items(self.ArrayPanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   341
        self._init_coll_ArrayPanelSizer_Growables(self.ArrayPanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   342
        self._init_coll_ArrayPanelLeftSizer_Items(self.ArrayPanelLeftSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   343
        self._init_coll_ArrayPanelRightSizer_Items(self.ArrayPanelRightSizer)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   344
        self._init_coll_StructurePanelSizer_Items(self.StructurePanelSizer)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   345
        self._init_coll_StructurePanelSizer_Growables(self.StructurePanelSizer)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   346
        self._init_coll_StructurePanelButtonSizer_Items(self.StructurePanelButtonSizer)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   347
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   348
        self.SetSizer(self.MainSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   349
        self.DirectlyPanel.SetSizer(self.DirectlyPanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   350
        self.SubrangePanel.SetSizer(self.SubrangePanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   351
        self.EnumeratedPanel.SetSizer(self.EnumeratedPanelSizer)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   352
        self.ArrayPanel.SetSizer(self.ArrayPanelSizer)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   353
        self.StructurePanel.SetSizer(self.StructurePanelSizer)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   354
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   355
    def _init_ctrls(self, prnt):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   356
        wx.Panel.__init__(self, id=ID_DATATYPEEDITOR, name='', parent=prnt,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   357
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   358
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   359
        self.staticbox = wx.StaticBox(id=ID_DATATYPEEDITORSTATICBOX,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   360
              label=_('Type infos:'), name='staticBox1', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   361
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   362
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   363
        self.staticText1 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   364
              label=_('Derivation Type:'), name='staticText1', parent=self,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   365
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   366
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   367
        self.DerivationType = wx.ComboBox(id=ID_DATATYPEEDITORDERIVATIONTYPE,
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   368
              name='DerivationType', parent=self, pos=wx.Point(0, 0),
313
9266d1e6e3d4 Fix size of ComboBoxes
lbessard
parents: 304
diff changeset
   369
              size=wx.Size(200, 28), style=wx.CB_READONLY)
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   370
        self.Bind(wx.EVT_COMBOBOX, self.OnDerivationTypeChanged, id=ID_DATATYPEEDITORDERIVATIONTYPE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   371
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   372
        # Panel for Directly derived data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   373
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   374
        self.DirectlyPanel = wx.Panel(id=ID_DATATYPEEDITORDIRECTLYPANEL,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   375
              name='DirectlyPanel', parent=self, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   376
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   377
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   378
        self.staticText2 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   379
              label=_('Base Type:'), name='staticText2', parent=self.DirectlyPanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   380
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   381
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   382
        self.DirectlyBaseType = wx.ComboBox(id=ID_DATATYPEEDITORDIRECTLYBASETYPE, 
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   383
              name='DirectlyBaseType', parent=self.DirectlyPanel, pos=wx.Point(0, 0),
313
9266d1e6e3d4 Fix size of ComboBoxes
lbessard
parents: 304
diff changeset
   384
              size=wx.Size(0, 28), style=wx.CB_READONLY)
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   385
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORDIRECTLYBASETYPE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   386
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   387
        self.staticText3 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT3,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   388
              label=_('Initial Value:'), name='staticText3', parent=self.DirectlyPanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   389
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   390
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   391
        self.DirectlyInitialValue = wx.TextCtrl(id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   392
              name='DirectlyInitialValue', parent=self.DirectlyPanel, pos=wx.Point(0, 0),
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   393
              size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_RICH)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   394
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   395
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   396
        # Panel for Subrange data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   397
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   398
        self.SubrangePanel = wx.Panel(id=ID_DATATYPEEDITORSUBRANGEPANEL,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   399
              name='SubrangePanel', parent=self, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   400
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   401
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   402
        self.staticText4 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT4,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   403
              label=_('Base Type:'), name='staticText4', parent=self.SubrangePanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   404
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   405
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   406
        self.SubrangeBaseType = wx.ComboBox(id=ID_DATATYPEEDITORSUBRANGEBASETYPE, 
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   407
              name='SubrangeBaseType', parent=self.SubrangePanel, pos=wx.Point(0, 0),
313
9266d1e6e3d4 Fix size of ComboBoxes
lbessard
parents: 304
diff changeset
   408
              size=wx.Size(0, 28), style=wx.CB_READONLY)
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   409
        self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged, id=ID_DATATYPEEDITORSUBRANGEBASETYPE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   410
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   411
        self.staticText5 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT5,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   412
              label=_('Initial Value:'), name='staticText5', parent=self.SubrangePanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   413
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   414
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   415
        self.SubrangeInitialValue = wx.SpinCtrl(id=ID_DATATYPEEDITORSUBRANGEINITIALVALUE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   416
              name='SubrangeInitialValue', parent=self.SubrangePanel, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   417
              size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   418
        self.Bind(wx.EVT_SPINCTRL, self.OnInfosChanged, id=ID_DATATYPEEDITORSUBRANGEINITIALVALUE)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   419
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   420
        self.staticText6 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT6,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   421
              label=_('Minimum:'), name='staticText6', parent=self.SubrangePanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   422
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   423
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   424
        self.SubrangeMinimum = wx.SpinCtrl(id=ID_DATATYPEEDITORSUBRANGEMINIMUM, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   425
              name='SubrangeMinimum', parent=self.SubrangePanel, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   426
              size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   427
        self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMinimumChanged, id=ID_DATATYPEEDITORSUBRANGEMINIMUM)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   428
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   429
        self.staticText7 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT7,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   430
              label=_('Maximum:'), name='staticText7', parent=self.SubrangePanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   431
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   432
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   433
        self.SubrangeMaximum = wx.SpinCtrl(id=ID_DATATYPEEDITORSUBRANGEMAXIMUM, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   434
              name='SubrangeMaximum', parent=self.SubrangePanel, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   435
              size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   436
        self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMaximumChanged, id=ID_DATATYPEEDITORSUBRANGEMAXIMUM)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   437
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   438
        # Panel for Enumerated data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   439
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   440
        self.EnumeratedPanel = wx.Panel(id=ID_DATATYPEEDITORENUMERATEDPANEL,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   441
              name='EnumeratedPanel', parent=self, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   442
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   443
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   444
        self.EnumeratedValues = wx.gizmos.EditableListBox(id=ID_DATATYPEEDITORENUMERATEDVALUES, 
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   445
              name='EnumeratedValues', parent=self.EnumeratedPanel, label=_("Values:"), pos=wx.Point(0, 0),
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   446
              size=wx.Size(0, 0), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   447
        self.EnumeratedValues.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEnumeratedValueEndEdit)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   448
        self.EnumeratedValues.GetEditButton().SetToolTipString(_("Edit item"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   449
        new_button = self.EnumeratedValues.GetNewButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   450
        new_button.SetToolTipString(_("New item"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   451
        new_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   452
        del_button = self.EnumeratedValues.GetDelButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   453
        del_button.SetToolTipString(_("Delete item"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   454
        del_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   455
        up_button = self.EnumeratedValues.GetUpButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   456
        up_button.SetToolTipString(_("Move up"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   457
        up_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   458
        down_button = self.EnumeratedValues.GetDownButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   459
        down_button.SetToolTipString(_("Move down"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   460
        down_button.Bind(wx.EVT_BUTTON, self.OnEnumeratedValuesChanged)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   461
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   462
        self.staticText8 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT8,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   463
              label=_('Initial Value:'), name='staticText8', parent=self.EnumeratedPanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   464
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   465
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   466
        self.EnumeratedInitialValue = wx.ComboBox(id=ID_DATATYPEEDITORENUMERATEDINITIALVALUE, 
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   467
              name='EnumeratedInitialValue', parent=self.EnumeratedPanel, pos=wx.Point(0, 0),
313
9266d1e6e3d4 Fix size of ComboBoxes
lbessard
parents: 304
diff changeset
   468
              size=wx.Size(0, 28), style=wx.CB_READONLY)
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   469
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORENUMERATEDINITIALVALUE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   470
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   471
        # Panel for Array data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   472
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   473
        self.ArrayPanel = wx.Panel(id=ID_DATATYPEEDITORARRAYPANEL,
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   474
              name='ArrayPanel', parent=self, pos=wx.Point(0, 0),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   475
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   476
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   477
        self.staticText9 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT9,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   478
              label=_('Base Type:'), name='staticText9', parent=self.ArrayPanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   479
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   480
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   481
        self.ArrayBaseType = wx.ComboBox(id=ID_DATATYPEEDITORARRAYBASETYPE, 
507
42150e041dbe Adding support for direct array variable declaration in variable panel (still disable cause matiec doesn't support this feature)
laurent
parents: 494
diff changeset
   482
              name='ArrayBaseType', parent=self.ArrayPanel, pos=wx.Point(0, 0),
313
9266d1e6e3d4 Fix size of ComboBoxes
lbessard
parents: 304
diff changeset
   483
              size=wx.Size(0, 28), style=wx.CB_READONLY)
304
2df3d31d8059 Replacing wx.Choice by wx.ComboBox
lbessard
parents: 295
diff changeset
   484
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORARRAYBASETYPE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   485
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   486
        self.ArrayDimensions = wx.gizmos.EditableListBox(id=ID_DATATYPEEDITORARRAYDIMENSIONS, 
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   487
              name='ArrayDimensions', parent=self.ArrayPanel, label=_("Dimensions:"), pos=wx.Point(0, 0),
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   488
              size=wx.Size(0, 24), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   489
        self.ArrayDimensions.GetListCtrl().Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnDimensionsChanged)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   490
        self.ArrayDimensions.GetEditButton().SetToolTipString(_("Edit item"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   491
        new_button = self.ArrayDimensions.GetNewButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   492
        new_button.SetToolTipString(_("New item"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   493
        new_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   494
        del_button = self.ArrayDimensions.GetDelButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   495
        del_button.SetToolTipString(_("Delete item"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   496
        del_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   497
        up_button = self.ArrayDimensions.GetUpButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   498
        up_button.SetToolTipString(_("Move up"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   499
        up_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   500
        down_button = self.ArrayDimensions.GetDownButton()
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   501
        down_button.SetToolTipString(_("Move down"))
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   502
        down_button.Bind(wx.EVT_BUTTON, self.OnDimensionsChanged)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   503
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   504
        self.staticText10 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT10,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   505
              label=_('Initial Value:'), name='staticText10', parent=self.ArrayPanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   506
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   507
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   508
        self.ArrayInitialValue = wx.TextCtrl(id=ID_DATATYPEEDITORARRAYINITIALVALUE, 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   509
              name='ArrayInitialValue', parent=self.ArrayPanel, pos=wx.Point(0, 0),
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   510
              size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_RICH)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   511
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, id=ID_DATATYPEEDITORARRAYINITIALVALUE)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   512
        
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   513
        # Panel for Structure data types
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   514
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   515
        self.StructurePanel = wx.Panel(id=ID_DATATYPEEDITORSTRUCTUREPANEL,
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   516
              name='StructurePanel', parent=self, pos=wx.Point(0, 0),
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   517
              size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   518
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   519
        self.staticText11 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT11,
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   520
              label=_('Elements :'), name='staticText11', parent=self.StructurePanel,
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   521
              pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   522
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   523
        self.StructureElementsGrid = wx.grid.Grid(id=ID_DATATYPEEDITORSTRUCTUREELEMENTSGRID,
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   524
              name='StructureElementsGrid', parent=self.StructurePanel, pos=wx.Point(0, 0), 
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   525
              size=wx.Size(0, 150), style=wx.VSCROLL)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   526
        self.StructureElementsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   527
              'Sans'))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   528
        self.StructureElementsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   529
              False, 'Sans'))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   530
        self.StructureElementsGrid.SetSelectionBackground(wx.WHITE)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   531
        self.StructureElementsGrid.SetSelectionForeground(wx.BLACK)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   532
        if wx.VERSION >= (2, 6, 0):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   533
            self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnStructureElementsGridCellChange)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   534
            self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnStructureElementsGridEditorShown)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   535
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   536
            wx.grid.EVT_GRID_CELL_CHANGE(self.StructureElementsGrid, self.OnStructureElementsGridCellChange)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   537
            wx.grid.EVT_GRID_EDITOR_SHOWN(self.StructureElementsGrid, self.OnStructureElementsGridEditorShown)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   538
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   539
        self.StructureAddButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREADDBUTTON, label=_('Add'),
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   540
              name='StructureAddButton', parent=self.StructurePanel, pos=wx.Point(0, 0),
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   541
              size=wx.DefaultSize, style=0)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   542
        self.Bind(wx.EVT_BUTTON, self.OnStructureAddButton, id=ID_DATATYPEEDITORSTRUCTUREADDBUTTON)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   543
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   544
        self.StructureDeleteButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREDELETEBUTTON, label=_('Delete'),
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   545
              name='StructureDeleteButton', parent=self.StructurePanel, pos=wx.Point(0, 0),
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   546
              size=wx.DefaultSize, style=0)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   547
        self.Bind(wx.EVT_BUTTON, self.OnStructureDeleteButton, id=ID_DATATYPEEDITORSTRUCTUREDELETEBUTTON)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   548
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   549
        self.StructureUpButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREUPBUTTON, label='^',
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   550
              name='StructureUpButton', parent=self.StructurePanel, pos=wx.Point(0, 0),
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   551
              size=wx.Size(32, 32), style=0)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   552
        self.Bind(wx.EVT_BUTTON, self.OnStructureUpButton, id=ID_DATATYPEEDITORSTRUCTUREUPBUTTON)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   553
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   554
        self.StructureDownButton = wx.Button(id=ID_DATATYPEEDITORSTRUCTUREDOWNBUTTON, label='v',
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   555
              name='StructureDownButton', parent=self.StructurePanel, pos=wx.Point(0, 0),
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   556
              size=wx.Size(32, 32), style=0)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   557
        self.Bind(wx.EVT_BUTTON, self.OnStructureDownButton, id=ID_DATATYPEEDITORSTRUCTUREDOWNBUTTON)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   558
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   559
        self._init_sizers()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   560
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   561
    def __init__(self, parent, tagname, window, controler):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   562
        self._init_ctrls(parent)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   563
        
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   564
        self.StructureElementDefaultValue = {"Name" : "", "Type" : "INT", "Initial Value" : ""}
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   565
        self.StructureElementsTable = ElementsTable(self, [], GetElementsTableColnames())
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   566
        self.StructureColSizes = [40, 150, 100, 250]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   567
        self.StructureColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   568
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   569
        self.StructureElementsGrid.SetTable(self.StructureElementsTable)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   570
        self.StructureElementsGrid.SetRowLabelSize(0)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   571
        for col in range(self.StructureElementsTable.GetNumberCols()):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   572
            attr = wx.grid.GridCellAttr()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   573
            attr.SetAlignment(self.StructureColAlignements[col], wx.ALIGN_CENTRE)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   574
            self.StructureElementsGrid.SetColAttr(col, attr)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   575
            self.StructureElementsGrid.SetColMinimalWidth(col, self.StructureColSizes[col])
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   576
            self.StructureElementsGrid.AutoSizeColumn(col, False)
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   577
        
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   578
        for datatype in GetDatatypeTypes():
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   579
            self.DerivationType.Append(_(datatype))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   580
        self.SubrangePanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   581
        self.EnumeratedPanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   582
        self.ArrayPanel.Hide()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   583
        self.StructurePanel.Hide()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   584
        self.CurrentPanel = "Directly"
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   585
        self.Errors = []
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   586
        self.Initializing = False
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   587
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   588
        self.ParentWindow = window
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   589
        self.Controler = controler
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   590
        self.TagName = tagname
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   591
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   592
    def SetTagName(self, tagname):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   593
        self.TagName = tagname
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   594
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   595
    def GetTagName(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   596
        return self.TagName
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   597
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   598
    def IsViewing(self, tagname):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   599
        return self.TagName == tagname
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   600
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   601
    def IsDebugging(self):
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   602
        return False
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 391
diff changeset
   603
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   604
    def SetMode(self, mode):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   605
        pass
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   606
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   607
    def ResetBuffer(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   608
        pass
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   609
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   610
    def RefreshView(self):
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   611
        self.Initializing = True
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   612
        self.DirectlyBaseType.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   613
        self.ArrayBaseType.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   614
        for datatype in self.Controler.GetDataTypes(self.TagName):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   615
            self.DirectlyBaseType.Append(datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   616
            self.ArrayBaseType.Append(datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   617
        self.DirectlyBaseType.SetSelection(0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   618
        self.SubrangeBaseType.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   619
        words = self.TagName.split("::")
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   620
        for base_type in self.Controler.GetSubrangeBaseTypes(words[1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   621
            self.SubrangeBaseType.Append(base_type)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   622
        self.SubrangeBaseType.SetSelection(0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   623
        self.RefreshBoundsRange()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   624
        type_infos = self.Controler.GetDataTypeInfos(self.TagName)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   625
        if type_infos is not None:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   626
            datatype = type_infos["type"]
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   627
            self.DerivationType.SetStringSelection(_(datatype))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   628
            if type_infos["type"] == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   629
                self.DirectlyBaseType.SetStringSelection(type_infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   630
                self.DirectlyInitialValue.SetValue(type_infos["initial"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   631
            elif type_infos["type"] == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   632
                self.SubrangeBaseType.SetStringSelection(type_infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   633
                self.RefreshBoundsRange()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   634
                self.SubrangeMinimum.SetValue(int(type_infos["min"]))
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   635
                self.SubrangeMaximum.SetValue(int(type_infos["max"]))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   636
                self.RefreshSubrangeInitialValueRange()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   637
                if type_infos["initial"] != "":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   638
                    self.SubrangeInitialValue.SetValue(int(type_infos["initial"]))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   639
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   640
                    self.SubrangeInitialValue.SetValue(type_infos["min"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   641
            elif type_infos["type"] == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   642
                self.EnumeratedValues.SetStrings(type_infos["values"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   643
                self.RefreshEnumeratedValues()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   644
                self.EnumeratedInitialValue.SetStringSelection(type_infos["initial"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   645
            elif type_infos["type"] == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   646
                self.ArrayBaseType.SetStringSelection(type_infos["base_type"])
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   647
                self.ArrayDimensions.SetStrings(map(lambda x : "..".join(x), type_infos["dimensions"]))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   648
                self.ArrayInitialValue.SetValue(type_infos["initial"])
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   649
            elif type_infos["type"] == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   650
                self.StructureElementsTable.SetData(type_infos["elements"])
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   651
                self.StructureElementsTable.ResetView(self.StructureElementsGrid)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   652
            self.RefreshDisplayedInfos()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   653
        self.ShowErrors()
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   654
        self.Initializing = False
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   655
205
f12ad5b87f99 Bug with missing RefreshScaling fixed
lbessard
parents: 192
diff changeset
   656
    def RefreshScaling(self, refresh=True):
f12ad5b87f99 Bug with missing RefreshScaling fixed
lbessard
parents: 192
diff changeset
   657
        pass
f12ad5b87f99 Bug with missing RefreshScaling fixed
lbessard
parents: 192
diff changeset
   658
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   659
    def OnDerivationTypeChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   660
        self.RefreshDisplayedInfos()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   661
        self.RefreshTypeInfos()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   662
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   663
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   664
    def OnReturnKeyPressed(self, event):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   665
        self.RefreshTypeInfos()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   666
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   667
    def OnInfosChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   668
        self.RefreshTypeInfos()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   669
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   670
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   671
    def OnSubrangeBaseTypeChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   672
        self.RefreshBoundsRange()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   673
        self.RefreshTypeInfos()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   674
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   675
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   676
    def OnSubrangeMinimumChanged(self, event):
215
dd3381f38a9e Fixed various bugs
etisserant
parents: 207
diff changeset
   677
        if not self.Initializing:
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   678
            wx.CallAfter(self.SubrangeMinimum.SetValue, min(self.SubrangeMaximum.GetValue(), self.SubrangeMinimum.GetValue()))
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   679
            wx.CallAfter(self.RefreshSubrangeInitialValueRange)
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   680
            wx.CallAfter(self.RefreshTypeInfos)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   681
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   682
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   683
    def OnSubrangeMaximumChanged(self, event):
215
dd3381f38a9e Fixed various bugs
etisserant
parents: 207
diff changeset
   684
        if not self.Initializing:
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   685
            wx.CallAfter(self.SubrangeMaximum.SetValue, max(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue()))
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   686
            wx.CallAfter(self.RefreshSubrangeInitialValueRange)
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   687
            wx.CallAfter(self.RefreshTypeInfos)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   688
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   689
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   690
    def OnDimensionsChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   691
        wx.CallAfter(self.RefreshTypeInfos)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   692
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   693
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   694
    def OnEnumeratedValueEndEdit(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   695
        text = event.GetText()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   696
        values = self.EnumeratedValues.GetStrings()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   697
        index = event.GetIndex()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   698
        if index >= len(values) or values[index].upper() != text.upper():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   699
            if text.upper() in [value.upper() for value in values]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   700
                message = wx.MessageDialog(self, _("\"%s\" value already defined!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   701
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   702
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   703
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   704
            elif text.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   705
                message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   706
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   707
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   708
            else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   709
                wx.CallAfter(self.RefreshEnumeratedValues)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   710
                wx.CallAfter(self.RefreshTypeInfos)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   711
                event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   712
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   713
            wx.CallAfter(self.RefreshEnumeratedValues)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   714
            wx.CallAfter(self.RefreshTypeInfos)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   715
            event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   716
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   717
    def OnEnumeratedValuesChanged(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   718
        wx.CallAfter(self.RefreshEnumeratedValues)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   719
        wx.CallAfter(self.RefreshTypeInfos)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   720
        event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   721
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   722
    def OnStructureAddButton(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   723
        new_row = self.StructureElementDefaultValue.copy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   724
        self.StructureElementsTable.AppendRow(new_row)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   725
        self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   726
        self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   727
        event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   728
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   729
    def OnStructureDeleteButton(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   730
        row = self.StructureElementsGrid.GetGridCursorRow()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   731
        self.StructureElementsTable.RemoveRow(row)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   732
        self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   733
        self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   734
        event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   735
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   736
    def OnStructureUpButton(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   737
        row = self.StructureElementsGrid.GetGridCursorRow()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   738
        new_index = self.StructureElementsTable.MoveRow(row, -1)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   739
        if new_index is not None:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   740
            self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   741
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   742
            self.StructureElementsGrid.SetGridCursor(new_index, self.StructureElementsGrid.GetGridCursorCol())
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   743
        event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   744
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   745
    def OnStructureDownButton(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   746
        row = self.StructureElementsGrid.GetGridCursorRow()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   747
        new_index = self.StructureElementsTable.MoveRow(row, 1)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   748
        if new_index is not None:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   749
            self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   750
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   751
            self.StructureElementsGrid.SetGridCursor(new_index, self.StructureElementsGrid.GetGridCursorCol())
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   752
        event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   753
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   754
    def OnStructureElementsGridCellChange(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   755
        row, col = event.GetRow(), event.GetCol()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   756
        colname = self.StructureElementsTable.GetColLabelValue(col)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   757
        value = self.StructureElementsTable.GetValue(row, col)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   758
        if colname == "Name":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   759
            if not TestIdentifier(value):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   760
                message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   761
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   762
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   763
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   764
            elif value.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   765
                message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   766
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   767
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   768
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   769
##            elif value.upper() in self.PouNames:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   770
##                message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wx.OK|wx.ICON_ERROR)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   771
##                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   772
##                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   773
##                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   774
            elif value.upper() in [var["Name"].upper() for idx, var in enumerate(self.StructureElementsTable.GetData()) if idx != row]:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 391
diff changeset
   775
                message = wx.MessageDialog(self, _("An element named \"%s\" already exists in this structure!")%value, _("Error"), wx.OK|wx.ICON_ERROR)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   776
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   777
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   778
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   779
            else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   780
                self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   781
                self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   782
##                old_value = self.Table.GetOldValue()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   783
##                if old_value != "":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   784
##                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   785
##                self.Controler.BufferProject()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   786
                event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   787
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   788
            self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   789
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   790
            event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   791
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   792
    def OnStructureElementsGridEditorShown(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   793
        row, col = event.GetRow(), event.GetCol() 
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   794
        if self.StructureElementsTable.GetColLabelValue(col) == "Type":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   795
            type_menu = wx.Menu(title='')
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   796
            base_menu = wx.Menu(title='')
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   797
            for base_type in self.Controler.GetBaseTypes():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   798
                new_id = wx.NewId()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   799
                AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   800
                self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   801
            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   802
            datatype_menu = wx.Menu(title='')
462
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   803
            for datatype in self.Controler.GetDataTypes(self.TagName, False):
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   804
                new_id = wx.NewId()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   805
                AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   806
                self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   807
            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   808
##            functionblock_menu = wx.Menu(title='')
462
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   809
##            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   810
##            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   811
##            if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]:
462
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   812
##                for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName):
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   813
##                    new_id = wx.NewId()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   814
##                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   815
##                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   816
##                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   817
            rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   818
            self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize())
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   819
            event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   820
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   821
            event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   822
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   823
    def GetElementTypeFunction(self, base_type):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   824
        def ElementTypeFunction(event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   825
            row = self.StructureElementsGrid.GetGridCursorRow()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   826
            self.StructureElementsTable.SetValueByName(row, "Type", base_type)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   827
            self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   828
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   829
        return ElementTypeFunction
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   830
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   831
    def RefreshDisplayedInfos(self):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   832
        selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   833
        if selected != self.CurrentPanel:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   834
            if self.CurrentPanel == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   835
                self.DirectlyPanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   836
            elif self.CurrentPanel == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   837
                self.SubrangePanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   838
            elif self.CurrentPanel == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   839
                self.EnumeratedPanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   840
            elif self.CurrentPanel == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   841
                self.ArrayPanel.Hide()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   842
            elif self.CurrentPanel == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   843
                self.StructurePanel.Hide()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   844
            self.CurrentPanel = selected
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   845
            if selected == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   846
                self.DirectlyPanel.Show()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   847
            elif selected == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   848
                self.SubrangePanel.Show()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   849
            elif selected == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   850
                self.EnumeratedPanel.Show()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   851
            elif selected == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   852
                self.ArrayPanel.Show()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   853
            elif selected == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   854
                self.StructurePanel.Show()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   855
            self.MainSizer.Layout()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   856
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   857
    def RefreshEnumeratedValues(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   858
        selected = self.EnumeratedInitialValue.GetStringSelection()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   859
        self.EnumeratedInitialValue.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   860
        self.EnumeratedInitialValue.Append("")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   861
        for value in self.EnumeratedValues.GetStrings():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   862
            self.EnumeratedInitialValue.Append(value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   863
        self.EnumeratedInitialValue.SetStringSelection(selected)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   864
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   865
    def RefreshBoundsRange(self):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   866
        range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   867
        if range is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   868
            min_value, max_value = range
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   869
            self.SubrangeMinimum.SetRange(min_value, max_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   870
            self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   871
            self.SubrangeMaximum.SetRange(min_value, max_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   872
            self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   873
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   874
    def RefreshSubrangeInitialValueRange(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   875
        self.SubrangeInitialValue.SetRange(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   876
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   877
    def RefreshTypeInfos(self):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   878
        selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   879
        infos = {"type" : selected}
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   880
        if selected == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   881
            infos["base_type"] = self.DirectlyBaseType.GetStringSelection()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   882
            infos["initial"] = self.DirectlyInitialValue.GetValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   883
        elif selected == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   884
            infos["base_type"] = self.SubrangeBaseType.GetStringSelection()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   885
            infos["min"] = str(self.SubrangeMinimum.GetValue())
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   886
            infos["max"] = str(self.SubrangeMaximum.GetValue())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   887
            initial_value = self.SubrangeInitialValue.GetValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   888
            if initial_value == infos["min"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   889
                infos["initial"] = ""
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   890
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   891
                infos["initial"] = str(initial_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   892
        elif selected == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   893
            infos["values"] = self.EnumeratedValues.GetStrings()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   894
            infos["initial"] = self.EnumeratedInitialValue.GetStringSelection()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   895
        elif selected == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   896
            infos["base_type"] = self.ArrayBaseType.GetStringSelection()
207
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   897
            infos["dimensions"] = []
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   898
            for dimensions in self.ArrayDimensions.GetStrings():
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   899
                result = DIMENSION_MODEL.match(dimensions)
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   900
                if result is None:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   901
                    message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR)
207
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   902
                    message.ShowModal()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   903
                    message.Destroy()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   904
                    self.RefreshView()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   905
                    return
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   906
                bounds = result.groups()
460
2ddf7bbd1f74 Bug on array dimensions bound test fixed
laurent
parents: 440
diff changeset
   907
                if int(bounds[0]) >= int(bounds[1]):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   908
                    message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.")%dimensions, _("Error"), wx.OK|wx.ICON_ERROR)
207
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   909
                    message.ShowModal()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   910
                    message.Destroy()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   911
                    self.RefreshView()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   912
                    return
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   913
                infos["dimensions"].append(bounds)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   914
            infos["initial"] = self.ArrayInitialValue.GetValue()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   915
        elif selected == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   916
            infos["elements"] = self.StructureElementsTable.GetData()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   917
            infos["initial"] = ""
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   918
        self.Controler.SetDataTypeInfos(self.TagName, infos)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   919
        self.ParentWindow.RefreshTitle()
494
c91644c2bfa7 Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 462
diff changeset
   920
        self.ParentWindow.RefreshFileMenu()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   921
        self.ParentWindow.RefreshEditMenu()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   922
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   923
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   924
#                        Errors showing functions
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   925
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   926
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   927
    def ClearErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   928
        self.Errors = []
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   929
        self.RefreshView()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   930
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   931
    def AddShownError(self, infos, start, end):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   932
        self.Errors.append((infos, start, end))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   933
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   934
    def ShowErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   935
        type_infos = self.Controler.GetDataTypeInfos(self.TagName)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   936
        for infos, start, end in self.Errors:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   937
            if infos[0] == "base":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   938
                if type_infos["type"] == "Directly":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   939
                    self.DirectlyBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   940
                    self.DirectlyBaseType.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   941
                elif type_infos["type"] == "Subrange":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   942
                    self.SubrangeBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   943
                    self.SubrangeBaseType.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   944
                elif type_infos["type"] == "Array":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   945
                    self.ArrayBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   946
                    self.ArrayBaseType.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   947
            elif infos[0] == "lower":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   948
                self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   949
                self.SubrangeMaximum.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   950
            elif infos[0] == "upper":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   951
                self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   952
                self.SubrangeMaximum.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   953
            elif infos[0] == "value":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   954
                listctrl = self.EnumeratedValues.GetListCtrl()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   955
                listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   956
                listctrl.SetItemTextColour(infos[1], wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   957
                listctrl.Select(listctrl.FocusedItem, False)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   958
            elif infos[0] == "range":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   959
                listctrl = self.EnumeratedValues.GetListCtrl()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   960
                listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   961
                listctrl.SetItemTextColour(infos[1], wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   962
                listctrl.SetStringSelection("")
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   963
            elif infos[0] == "initial":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   964
                if type_infos["type"] == "Directly":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   965
                    text = self.DirectlyInitialValue.GetValue()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   966
                    self.DirectlyInitialValue.SetValue(text[:start[1]])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   967
                    self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0)))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   968
                    self.DirectlyInitialValue.AppendText(text[start[1]:end[1] + 1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   969
                    self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   970
                    self.DirectlyInitialValue.AppendText(text[end[1] + 1:])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   971
                elif type_infos["type"] == "Subrange":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   972
                    self.SubrangeInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   973
                    self.SubrangeInitialValue.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   974
                elif type_infos["type"] == "Enumerated":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   975
                    self.EnumeratedInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   976
                    self.EnumeratedInitialValue.SetForegroundColour(wx.RED)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   977
                elif type_infos["type"] == "Array":
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   978
                    text = self.ArrayInitialValue.GetValue()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   979
                    self.ArrayInitialValue.SetValue(text[:start[1]])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   980
                    self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0)))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   981
                    self.ArrayInitialValue.AppendText(text[start[1]:end[1] + 1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   982
                    self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   983
                    self.ArrayInitialValue.AppendText(text[end[1] + 1:])