DataTypeEditor.py
author Laurent Bessard
Sun, 19 Aug 2012 16:07:01 +0200
changeset 742 75096d6c271c
parent 730 2c4914d941fd
permissions -rw-r--r--
Fix bug while generating code with structured_variables as Standard Function inputs (enable to compute function return type in some cases)
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
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    25
import re
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    26
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    27
import wx
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
    28
import wx.grid
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    29
import wx.lib.buttons
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
    30
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    31
from plcopen.structures import IEC_KEYWORDS, TestIdentifier
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
    32
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 598
diff changeset
    33
from controls import CustomEditableListBox, CustomGrid, CustomTable, EditorPanel
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    34
from utils.BitmapLibrary import GetBitmap
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    35
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    36
#-------------------------------------------------------------------------------
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    37
#                                    Helpers
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    38
#-------------------------------------------------------------------------------
207
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    39
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    40
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
    41
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    42
def AppendMenu(parent, help, id, kind, text):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    43
    parent.Append(help=help, id=id, kind=kind, text=text)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    44
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    45
def GetElementsTableColnames():
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    46
    _ = lambda x : x
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    47
    return ["#", _("Name"), _("Type"), _("Initial Value")]
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    48
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    49
def GetDatatypeTypes():
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    50
    _ = lambda x : x
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    51
    return [_("Directly"), _("Subrange"), _("Enumerated"), _("Array"), _("Structure")]
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
    52
DATATYPE_TYPES_DICT = dict([(_(datatype), datatype) for datatype in GetDatatypeTypes()])
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    53
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    54
#-------------------------------------------------------------------------------
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    55
#                            Structure Elements Table
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    56
#-------------------------------------------------------------------------------
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    57
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 598
diff changeset
    58
class ElementsTable(CustomTable):
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    59
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    60
    """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    61
    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
    62
    """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    63
    def __init__(self, parent, data, colnames):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    64
        # The base class must be initialized *first*
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 598
diff changeset
    65
        CustomTable.__init__(self, parent, data, colnames)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    66
        self.old_value = None
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 598
diff changeset
    67
        
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    68
    def GetValue(self, row, col):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    69
        if row < self.GetNumberRows():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    70
            if col == 0:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    71
                return row + 1
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    72
            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
    73
            return name
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    74
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    75
    def SetValue(self, row, col, value):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    76
        if col < len(self.colnames):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    77
            colname = self.GetColLabelValue(col, False)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    78
            if colname == "Name":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    79
                self.old_value = self.data[row][colname]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    80
            self.data[row][colname] = value
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 GetOldValue(self):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    83
        return self.old_value
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    84
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    85
    def _updateColAttrs(self, grid):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    86
        """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    87
        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
    88
        appropriate renderer given the column name.
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    89
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    90
        Otherwise default to the default renderer.
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    91
        """
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    92
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    93
        for row in range(self.GetNumberRows()):
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
    94
            row_highlights = self.Highlights.get(row, {})
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    95
            for col in range(self.GetNumberCols()):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    96
                editor = None
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    97
                renderer = None
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
    98
                colname = self.GetColLabelValue(col, False)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
    99
                if col != 0:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   100
                    grid.SetReadOnly(row, col, False)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   101
                    if colname == "Name":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   102
                        editor = wx.grid.GridCellTextEditor()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   103
                        renderer = wx.grid.GridCellStringRenderer()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   104
                    elif colname == "Initial Value":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   105
                        editor = wx.grid.GridCellTextEditor()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   106
                        renderer = wx.grid.GridCellStringRenderer()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   107
                    elif colname == "Type":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   108
                        editor = wx.grid.GridCellTextEditor()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   109
                else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   110
                    grid.SetReadOnly(row, col, True)
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.SetCellEditor(row, col, editor)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   113
                grid.SetCellRenderer(row, col, renderer)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   114
                
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   115
                highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   116
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   117
                grid.SetCellTextColour(row, col, highlight_colours[1])
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 598
diff changeset
   118
            self.ResizeRow(grid, row)
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 598
diff changeset
   119
    
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   120
    def AddHighlight(self, infos, highlight_type):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   121
        row_highlights = self.Highlights.setdefault(infos[0], {})
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   122
        if infos[1] == "initial":
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   123
            col_highlights = row_highlights.setdefault("initial value", [])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   124
        else:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   125
            col_highlights = row_highlights.setdefault(infos[1], [])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   126
        col_highlights.append(highlight_type)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   127
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   128
#-------------------------------------------------------------------------------
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 313
diff changeset
   129
#                          Datatype Editor class
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   130
#-------------------------------------------------------------------------------
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   131
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   132
class DataTypeEditor(EditorPanel):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   133
    
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   134
    def _init_Editor(self, parent):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   135
        self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   136
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   137
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   138
        self.MainSizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   139
        self.MainSizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   140
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   141
        top_sizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   142
        self.MainSizer.AddSizer(top_sizer, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   143
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   144
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   145
        derivation_type_label = wx.StaticText(self.Editor, label=_('Derivation Type:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   146
        top_sizer.AddWindow(derivation_type_label, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   147
              flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   148
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   149
        self.DerivationType = wx.ComboBox(self.Editor,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   150
              size=wx.Size(200, -1), style=wx.CB_READONLY)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   151
        self.Bind(wx.EVT_COMBOBOX, self.OnDerivationTypeChanged, self.DerivationType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   152
        top_sizer.AddWindow(self.DerivationType, border=5, flag=wx.GROW|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   153
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   154
        typeinfos_staticbox = wx.StaticBox(self.Editor, label=_('Type infos:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   155
        typeinfos_sizer = wx.StaticBoxSizer(typeinfos_staticbox, wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   156
        self.MainSizer.AddSizer(typeinfos_sizer, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   157
              flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   158
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   159
        # Panel for Directly derived data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   160
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   161
        self.DirectlyPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   162
        typeinfos_sizer.AddWindow(self.DirectlyPanel, 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   163
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   164
        directly_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   165
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   166
        directly_basetype_label = wx.StaticText(self.DirectlyPanel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   167
              label=_('Base Type:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   168
        directly_panel_sizer.AddWindow(directly_basetype_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   169
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   170
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   171
        self.DirectlyBaseType = wx.ComboBox(self.DirectlyPanel, style=wx.CB_READONLY)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   172
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.DirectlyPanel)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   173
        directly_panel_sizer.AddWindow(self.DirectlyBaseType, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   174
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   175
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   176
        directly_initialvalue_label = wx.StaticText(self.DirectlyPanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   177
              label=_('Initial Value:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   178
        directly_panel_sizer.AddWindow(directly_initialvalue_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   179
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   180
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   181
        self.DirectlyInitialValue = wx.TextCtrl(self.DirectlyPanel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   182
              style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_RICH)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   183
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.DirectlyInitialValue)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   184
        directly_panel_sizer.AddWindow(self.DirectlyInitialValue, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   185
              flag=wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   186
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   187
        self.DirectlyPanel.SetSizer(directly_panel_sizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   188
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   189
        # Panel for Subrange data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   190
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   191
        self.SubrangePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   192
        typeinfos_sizer.AddWindow(self.SubrangePanel, 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   193
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   194
        subrange_panel_sizer = wx.GridSizer(cols=4, hgap=5, rows=3, vgap=0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   195
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   196
        subrange_basetype_label = wx.StaticText(self.SubrangePanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   197
              label=_('Base Type:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   198
        subrange_panel_sizer.AddWindow(subrange_basetype_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   199
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   200
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   201
        self.SubrangeBaseType = wx.ComboBox(self.SubrangePanel, style=wx.CB_READONLY)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   202
        self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   203
              self.SubrangeBaseType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   204
        subrange_panel_sizer.AddWindow(self.SubrangeBaseType, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   205
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   206
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   207
        subrange_initialvalue_label = wx.StaticText(self.SubrangePanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   208
              label=_('Initial Value:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   209
        subrange_panel_sizer.AddWindow(subrange_initialvalue_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   210
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   211
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   212
        self.SubrangeInitialValue = wx.SpinCtrl(self.SubrangePanel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   213
              style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   214
        self.Bind(wx.EVT_SPINCTRL, self.OnInfosChanged, self.SubrangeInitialValue)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   215
        subrange_panel_sizer.AddWindow(self.SubrangeInitialValue, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   216
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   217
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   218
        subrange_minimum_label = wx.StaticText(self.SubrangePanel, label=_('Minimum:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   219
        subrange_panel_sizer.AddWindow(subrange_minimum_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   220
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   221
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   222
        self.SubrangeMinimum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   223
        self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMinimumChanged, self.SubrangeMinimum)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   224
        subrange_panel_sizer.AddWindow(self.SubrangeMinimum, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   225
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   226
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   227
        for i in xrange(2):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   228
            subrange_panel_sizer.AddWindow(wx.Size(0, 0), 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   229
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   230
        subrange_maximum_label = wx.StaticText(self.SubrangePanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   231
              label=_('Maximum:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   232
        subrange_panel_sizer.AddWindow(subrange_maximum_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   233
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   234
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   235
        self.SubrangeMaximum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   236
        self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMaximumChanged, self.SubrangeMaximum)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   237
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   238
        subrange_panel_sizer.AddWindow(self.SubrangeMaximum, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   239
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   240
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   241
        self.SubrangePanel.SetSizer(subrange_panel_sizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   242
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   243
        # Panel for Enumerated data types
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   244
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   245
        self.EnumeratedPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   246
        typeinfos_sizer.AddWindow(self.EnumeratedPanel, 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   247
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   248
        enumerated_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   249
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   250
        self.EnumeratedValues = CustomEditableListBox(self.EnumeratedPanel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   251
              label=_("Values:"), style=wx.gizmos.EL_ALLOW_NEW| 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   252
                                        wx.gizmos.EL_ALLOW_EDIT| 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   253
                                        wx.gizmos.EL_ALLOW_DELETE)
640
c32c169b8f63 Fixing segmentation fault in CustomEditableListBox on Windows when clicking on an header button while a value is being edited
laurent
parents: 636
diff changeset
   254
        setattr(self.EnumeratedValues, "_OnLabelEndEdit", self.OnEnumeratedValueEndEdit)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   255
        for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   256
            setattr(self.EnumeratedValues, func, self.OnEnumeratedValuesChanged)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   257
        enumerated_panel_sizer.AddWindow(self.EnumeratedValues, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   258
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   259
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   260
        enumerated_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   261
        enumerated_panel_sizer.AddSizer(enumerated_panel_rightsizer, 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   262
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   263
        enumerated_initialvalue_label = wx.StaticText(self.EnumeratedPanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   264
              label=_('Initial Value:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   265
        enumerated_panel_rightsizer.AddWindow(enumerated_initialvalue_label, 1, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   266
              border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   267
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   268
        self.EnumeratedInitialValue = wx.ComboBox(self.EnumeratedPanel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   269
              style=wx.CB_READONLY)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   270
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.EnumeratedInitialValue)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   271
        enumerated_panel_rightsizer.AddWindow(self.EnumeratedInitialValue, 1, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   272
              border=5, flag=wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   273
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   274
        self.EnumeratedPanel.SetSizer(enumerated_panel_sizer)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   275
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   276
        # Panel for Array data types
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   277
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   278
        self.ArrayPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   279
        typeinfos_sizer.AddWindow(self.ArrayPanel, 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   280
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   281
        array_panel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   282
        array_panel_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   283
        array_panel_sizer.AddGrowableCol(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   284
        array_panel_sizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   285
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   286
        array_panel_leftSizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   287
        array_panel_sizer.AddSizer(array_panel_leftSizer, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   288
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   289
        array_basetype_label = wx.StaticText(self.ArrayPanel, label=_('Base Type:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   290
        array_panel_leftSizer.AddWindow(array_basetype_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   291
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   292
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   293
        self.ArrayBaseType = wx.ComboBox(self.ArrayPanel, style=wx.CB_READONLY)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   294
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.ArrayBaseType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   295
        array_panel_leftSizer.AddWindow(self.ArrayBaseType, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   296
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   297
    
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   298
        array_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   299
        array_panel_sizer.AddSizer(array_panel_rightsizer, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   300
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   301
        array_initialvalue_label = wx.StaticText(self.ArrayPanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   302
              label=_('Initial Value:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   303
        array_panel_rightsizer.AddWindow(array_initialvalue_label, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   304
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   305
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   306
        self.ArrayInitialValue = wx.TextCtrl(self.ArrayPanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   307
              style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_RICH)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   308
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.ArrayInitialValue)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   309
        array_panel_rightsizer.AddWindow(self.ArrayInitialValue, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   310
              flag=wx.ALL)        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   311
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   312
        self.ArrayDimensions = CustomEditableListBox(self.ArrayPanel, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   313
              label=_("Dimensions:"), style=wx.gizmos.EL_ALLOW_NEW|
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   314
                                            wx.gizmos.EL_ALLOW_EDIT|
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   315
                                            wx.gizmos.EL_ALLOW_DELETE)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   316
        for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   317
                     "_OnUpButton", "_OnDownButton"]:
730
2c4914d941fd Fix bug in modifying array dimensions in DataTypeEditor
Laurent Bessard
parents: 714
diff changeset
   318
            setattr(self.ArrayDimensions, func, self.OnDimensionsChanged)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   319
        array_panel_sizer.AddWindow(self.ArrayDimensions, 0, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   320
              flag=wx.GROW|wx.ALL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   321
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   322
        self.ArrayPanel.SetSizer(array_panel_sizer)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   323
        
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   324
        # Panel for Structure data types
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   325
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   326
        self.StructurePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   327
        typeinfos_sizer.AddWindow(self.StructurePanel, 1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   328
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   329
        structure_panel_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   330
        structure_panel_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   331
        structure_panel_sizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   332
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   333
        structure_button_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   334
        structure_button_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   335
        structure_button_sizer.AddGrowableRow(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   336
        structure_panel_sizer.AddSizer(structure_button_sizer, 0, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   337
              flag=wx.ALL|wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   338
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   339
        structure_elements_label = wx.StaticText(self.StructurePanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   340
              label=_('Elements :'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   341
        structure_button_sizer.AddWindow(structure_elements_label, flag=wx.ALIGN_BOTTOM)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   342
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   343
        for name, bitmap, help in [
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   344
                ("StructureAddButton", "add_element", _("Add element")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   345
                ("StructureDeleteButton", "remove_element", _("Remove element")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   346
                ("StructureUpButton", "up", _("Move element up")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   347
                ("StructureDownButton", "down", _("Move element down"))]:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   348
            button = wx.lib.buttons.GenBitmapButton(self.StructurePanel,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   349
                  bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   350
            button.SetToolTipString(help)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   351
            setattr(self, name, button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   352
            structure_button_sizer.AddWindow(button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   353
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   354
        self.StructureElementsGrid = CustomGrid(self.StructurePanel, 
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   355
              size=wx.Size(0, 150), style=wx.VSCROLL)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   356
        self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   357
              self.OnStructureElementsGridCellChange)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   358
        self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   359
              self.OnStructureElementsGridEditorShown)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   360
        structure_panel_sizer.AddWindow(self.StructureElementsGrid, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   361
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   362
        self.StructurePanel.SetSizer(structure_panel_sizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   363
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   364
        self.Editor.SetSizer(self.MainSizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 666
diff changeset
   365
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   366
    def __init__(self, parent, tagname, window, controler):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   367
        EditorPanel.__init__(self, parent, tagname, window, controler)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   368
        
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   369
        self.StructureElementDefaultValue = {"Name" : "", "Type" : "INT", "Initial Value" : ""}
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   370
        self.StructureElementsTable = ElementsTable(self, [], GetElementsTableColnames())
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   371
        self.StructureColSizes = [40, 150, 100, 250]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   372
        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
   373
        
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   374
        self.StructureElementsGrid.SetTable(self.StructureElementsTable)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   375
        self.StructureElementsGrid.SetButtons({"Add": self.StructureAddButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   376
                                               "Delete": self.StructureDeleteButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   377
                                               "Up": self.StructureUpButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   378
                                               "Down": self.StructureDownButton})
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   379
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   380
        def _AddStructureElement(new_row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   381
            self.StructureElementsTable.InsertRow(new_row, self.StructureElementDefaultValue.copy())
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   382
            self.RefreshTypeInfos()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   383
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   384
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   385
        setattr(self.StructureElementsGrid, "_AddRow", _AddStructureElement)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   386
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   387
        def _DeleteStructureElement(row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   388
            self.StructureElementsTable.RemoveRow(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   389
            self.RefreshTypeInfos()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   390
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   391
        setattr(self.StructureElementsGrid, "_DeleteRow", _DeleteStructureElement)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   392
            
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   393
        def _MoveStructureElement(row, move):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   394
            new_row = self.StructureElementsTable.MoveRow(row, move)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   395
            if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   396
                self.RefreshTypeInfos()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   397
                self.StructureElementsTable.ResetView(self.StructureElementsGrid)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   398
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   399
        setattr(self.StructureElementsGrid, "_MoveRow", _MoveStructureElement)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   400
        
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   401
        self.StructureElementsGrid.SetRowLabelSize(0)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   402
        for col in range(self.StructureElementsTable.GetNumberCols()):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   403
            attr = wx.grid.GridCellAttr()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   404
            attr.SetAlignment(self.StructureColAlignements[col], wx.ALIGN_CENTRE)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   405
            self.StructureElementsGrid.SetColAttr(col, attr)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   406
            self.StructureElementsGrid.SetColMinimalWidth(col, self.StructureColSizes[col])
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   407
            self.StructureElementsGrid.AutoSizeColumn(col, False)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   408
        self.StructureElementsGrid.RefreshButtons()
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   409
        
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   410
        for datatype in GetDatatypeTypes():
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   411
            self.DerivationType.Append(_(datatype))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   412
        self.SubrangePanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   413
        self.EnumeratedPanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   414
        self.ArrayPanel.Hide()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   415
        self.StructurePanel.Hide()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   416
        self.CurrentPanel = "Directly"
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   417
        self.Highlights = []
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   418
        self.Initializing = False
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   419
        
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   420
        self.HighlightControls = {
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   421
            ("Directly", "base"): self.DirectlyBaseType,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   422
            ("Directly", "initial"): self.DirectlyInitialValue,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   423
            ("Subrange", "base"): self.SubrangeBaseType,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   424
            ("Subrange", "lower"): self.SubrangeMinimum,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   425
            ("Subrange", "upper"): self.SubrangeMaximum,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   426
            ("Subrange", "initial"): self.SubrangeInitialValue,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   427
            ("Enumerated", "value"): self.EnumeratedValues,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   428
            ("Enumerated", "initial"): self.EnumeratedInitialValue,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   429
            ("Array", "initial"): self.ArrayInitialValue,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   430
            ("Array", "base"): self.ArrayBaseType,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   431
            ("Array", "range"): self.ArrayDimensions,
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   432
        }
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   433
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   434
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   435
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   436
        
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   437
    def __del__(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   438
        self.RefreshHighlightsTimer.Stop()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   439
    
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   440
    def GetBufferState(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   441
        return self.Controler.GetBufferState()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   442
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   443
    def Undo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   444
        self.Controler.LoadPrevious()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   445
        self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   446
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   447
    def Redo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   448
        self.Controler.LoadNext()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   449
        self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   450
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   451
    def HasNoModel(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   452
        return self.Controler.GetEditedElement(self.TagName) is None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   453
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   454
    def RefreshView(self):
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   455
        self.Initializing = True
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   456
        self.DirectlyBaseType.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   457
        self.ArrayBaseType.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   458
        for datatype in self.Controler.GetDataTypes(self.TagName):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   459
            self.DirectlyBaseType.Append(datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   460
            self.ArrayBaseType.Append(datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   461
        self.DirectlyBaseType.SetSelection(0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   462
        self.SubrangeBaseType.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   463
        words = self.TagName.split("::")
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   464
        for base_type in self.Controler.GetSubrangeBaseTypes(words[1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   465
            self.SubrangeBaseType.Append(base_type)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   466
        self.SubrangeBaseType.SetSelection(0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   467
        self.RefreshBoundsRange()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   468
        type_infos = self.Controler.GetDataTypeInfos(self.TagName)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   469
        if type_infos is not None:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   470
            datatype = type_infos["type"]
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   471
            self.DerivationType.SetStringSelection(_(datatype))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   472
            if type_infos["type"] == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   473
                self.DirectlyBaseType.SetStringSelection(type_infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   474
                self.DirectlyInitialValue.SetValue(type_infos["initial"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   475
            elif type_infos["type"] == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   476
                self.SubrangeBaseType.SetStringSelection(type_infos["base_type"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   477
                self.RefreshBoundsRange()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   478
                self.SubrangeMinimum.SetValue(int(type_infos["min"]))
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   479
                self.SubrangeMaximum.SetValue(int(type_infos["max"]))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   480
                self.RefreshSubrangeInitialValueRange()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   481
                if type_infos["initial"] != "":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   482
                    self.SubrangeInitialValue.SetValue(int(type_infos["initial"]))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   483
                else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   484
                    self.SubrangeInitialValue.SetValue(type_infos["min"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   485
            elif type_infos["type"] == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   486
                self.EnumeratedValues.SetStrings(type_infos["values"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   487
                self.RefreshEnumeratedValues()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   488
                self.EnumeratedInitialValue.SetStringSelection(type_infos["initial"])
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   489
            elif type_infos["type"] == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   490
                self.ArrayBaseType.SetStringSelection(type_infos["base_type"])
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   491
                self.ArrayDimensions.SetStrings(map(lambda x : "..".join(x), type_infos["dimensions"]))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   492
                self.ArrayInitialValue.SetValue(type_infos["initial"])
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   493
            elif type_infos["type"] == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   494
                self.StructureElementsTable.SetData(type_infos["elements"])
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   495
            self.RefreshDisplayedInfos()
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   496
        self.ShowHighlights()
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   497
        self.StructureElementsTable.ResetView(self.StructureElementsGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   498
        self.StructureElementsGrid.RefreshButtons()
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   499
        self.Initializing = False
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 577
diff changeset
   500
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   501
    def OnDerivationTypeChanged(self, event):
636
44978a2b9703 Fix bug while adding new value to enumerated datatype list of values
laurent
parents: 610
diff changeset
   502
        wx.CallAfter(self.RefreshDisplayedInfos)
44978a2b9703 Fix bug while adding new value to enumerated datatype list of values
laurent
parents: 610
diff changeset
   503
        wx.CallAfter(self.RefreshTypeInfos)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   504
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   505
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   506
    def OnReturnKeyPressed(self, event):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   507
        self.RefreshTypeInfos()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   508
        
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   509
    def OnInfosChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   510
        self.RefreshTypeInfos()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   511
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   512
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   513
    def OnSubrangeBaseTypeChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   514
        self.RefreshBoundsRange()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   515
        self.RefreshTypeInfos()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   516
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   517
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   518
    def OnSubrangeMinimumChanged(self, event):
215
dd3381f38a9e Fixed various bugs
etisserant
parents: 207
diff changeset
   519
        if not self.Initializing:
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   520
            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
   521
            wx.CallAfter(self.RefreshSubrangeInitialValueRange)
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   522
            wx.CallAfter(self.RefreshTypeInfos)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   523
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   524
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   525
    def OnSubrangeMaximumChanged(self, event):
215
dd3381f38a9e Fixed various bugs
etisserant
parents: 207
diff changeset
   526
        if not self.Initializing:
130
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   527
            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
   528
            wx.CallAfter(self.RefreshSubrangeInitialValueRange)
38421cd7c8ff Bug on subrange SpinCtrls with Windows fixed
lbessard
parents: 125
diff changeset
   529
            wx.CallAfter(self.RefreshTypeInfos)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   530
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   531
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   532
    def OnDimensionsChanged(self, event):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   533
        wx.CallAfter(self.RefreshTypeInfos)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   534
        event.Skip()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   535
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   536
    def OnEnumeratedValueEndEdit(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   537
        text = event.GetText()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   538
        values = self.EnumeratedValues.GetStrings()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   539
        index = event.GetIndex()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   540
        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
   541
            if text.upper() in [value.upper() for value in values]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   542
                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
   543
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   544
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   545
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   546
            elif text.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   547
                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
   548
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   549
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   550
            else:
610
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   551
                initial_selected = None
636
44978a2b9703 Fix bug while adding new value to enumerated datatype list of values
laurent
parents: 610
diff changeset
   552
                if index < len(values) and self.EnumeratedInitialValue.GetStringSelection() == values[index]:
610
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   553
                    initial_selected = text
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   554
                wx.CallAfter(self.RefreshEnumeratedValues, initial_selected)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   555
                wx.CallAfter(self.RefreshTypeInfos)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   556
                event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   557
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   558
            event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   559
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   560
    def OnEnumeratedValuesChanged(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   561
        wx.CallAfter(self.RefreshEnumeratedValues)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   562
        wx.CallAfter(self.RefreshTypeInfos)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   563
        event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   564
    
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   565
    def OnStructureElementsGridCellChange(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   566
        row, col = event.GetRow(), event.GetCol()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   567
        colname = self.StructureElementsTable.GetColLabelValue(col)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   568
        value = self.StructureElementsTable.GetValue(row, col)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   569
        if colname == "Name":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   570
            if not TestIdentifier(value):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   571
                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
   572
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   573
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   574
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   575
            elif value.upper() in IEC_KEYWORDS:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   576
                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
   577
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   578
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   579
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   580
##            elif value.upper() in self.PouNames:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   581
##                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
   582
##                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   583
##                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   584
##                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   585
            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
   586
                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
   587
                message.ShowModal()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   588
                message.Destroy()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   589
                event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   590
            else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   591
                self.RefreshTypeInfos()
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   592
                wx.CallAfter(self.StructureElementsTable.ResetView, self.StructureElementsGrid)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   593
##                old_value = self.Table.GetOldValue()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   594
##                if old_value != "":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   595
##                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   596
##                self.Controler.BufferProject()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   597
                event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   598
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   599
            self.RefreshTypeInfos()
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   600
            wx.CallAfter(self.StructureElementsTable.ResetView, self.StructureElementsGrid)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   601
            event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   602
    
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   603
    def OnStructureElementsGridSelectCell(self, event):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   604
        wx.CallAfter(self.RefreshStructureButtons)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   605
        event.Skip()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 576
diff changeset
   606
    
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   607
    def OnStructureElementsGridEditorShown(self, event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   608
        row, col = event.GetRow(), event.GetCol() 
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   609
        if self.StructureElementsTable.GetColLabelValue(col) == "Type":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   610
            type_menu = wx.Menu(title='')
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   611
            base_menu = wx.Menu(title='')
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   612
            for base_type in self.Controler.GetBaseTypes():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   613
                new_id = wx.NewId()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   614
                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
   615
                self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   616
            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
   617
            datatype_menu = wx.Menu(title='')
462
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   618
            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
   619
                new_id = wx.NewId()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   620
                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
   621
                self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   622
            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
   623
##            functionblock_menu = wx.Menu(title='')
462
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   624
##            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
9abbc90c0263 Bug when trying to choose type of struture datatype element fixed
laurent
parents: 460
diff changeset
   625
##            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   626
##            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
   627
##                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
   628
##                    new_id = wx.NewId()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   629
##                    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
   630
##                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   631
##                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
   632
            rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col))
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   633
            self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize())
666
d4bb66691248 Improving contextual menu in Viewer and fixing menu toolbar icons on Windows
laurent
parents: 654
diff changeset
   634
            type_menu.Destroy()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   635
            event.Veto()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   636
        else:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   637
            event.Skip()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   638
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   639
    def GetElementTypeFunction(self, base_type):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   640
        def ElementTypeFunction(event):
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   641
            row = self.StructureElementsGrid.GetGridCursorRow()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   642
            self.StructureElementsTable.SetValueByName(row, "Type", base_type)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   643
            self.RefreshTypeInfos()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   644
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   645
        return ElementTypeFunction
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   646
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   647
    def RefreshDisplayedInfos(self):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   648
        selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   649
        if selected != self.CurrentPanel:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   650
            if self.CurrentPanel == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   651
                self.DirectlyPanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   652
            elif self.CurrentPanel == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   653
                self.SubrangePanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   654
            elif self.CurrentPanel == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   655
                self.EnumeratedPanel.Hide()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   656
            elif self.CurrentPanel == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   657
                self.ArrayPanel.Hide()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   658
            elif self.CurrentPanel == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   659
                self.StructurePanel.Hide()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   660
            self.CurrentPanel = selected
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   661
            if selected == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   662
                self.DirectlyPanel.Show()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   663
            elif selected == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   664
                self.SubrangePanel.Show()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   665
            elif selected == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   666
                self.EnumeratedPanel.Show()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   667
            elif selected == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   668
                self.ArrayPanel.Show()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   669
            elif selected == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   670
                self.StructurePanel.Show()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   671
            self.MainSizer.Layout()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   672
610
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   673
    def RefreshEnumeratedValues(self, initial_selected=None):
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   674
        if initial_selected is None:
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   675
            initial_selected = self.EnumeratedInitialValue.GetStringSelection()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   676
        self.EnumeratedInitialValue.Clear()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   677
        self.EnumeratedInitialValue.Append("")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   678
        for value in self.EnumeratedValues.GetStrings():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   679
            self.EnumeratedInitialValue.Append(value)
610
430d029beed6 Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
laurent
parents: 609
diff changeset
   680
        self.EnumeratedInitialValue.SetStringSelection(initial_selected)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   681
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   682
    def RefreshBoundsRange(self):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   683
        range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   684
        if range is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   685
            min_value, max_value = range
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   686
            self.SubrangeMinimum.SetRange(min_value, max_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   687
            self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   688
            self.SubrangeMaximum.SetRange(min_value, max_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   689
            self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   690
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   691
    def RefreshSubrangeInitialValueRange(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   692
        self.SubrangeInitialValue.SetRange(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   693
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   694
    def RefreshTypeInfos(self):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   695
        selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   696
        infos = {"type" : selected}
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   697
        if selected == "Directly":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   698
            infos["base_type"] = self.DirectlyBaseType.GetStringSelection()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   699
            infos["initial"] = self.DirectlyInitialValue.GetValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   700
        elif selected == "Subrange":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   701
            infos["base_type"] = self.SubrangeBaseType.GetStringSelection()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   702
            infos["min"] = str(self.SubrangeMinimum.GetValue())
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   703
            infos["max"] = str(self.SubrangeMaximum.GetValue())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   704
            initial_value = self.SubrangeInitialValue.GetValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   705
            if initial_value == infos["min"]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   706
                infos["initial"] = ""
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   707
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   708
                infos["initial"] = str(initial_value)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   709
        elif selected == "Enumerated":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   710
            infos["values"] = self.EnumeratedValues.GetStrings()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   711
            infos["initial"] = self.EnumeratedInitialValue.GetStringSelection()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   712
        elif selected == "Array":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   713
            infos["base_type"] = self.ArrayBaseType.GetStringSelection()
207
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   714
            infos["dimensions"] = []
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   715
            for dimensions in self.ArrayDimensions.GetStrings():
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   716
                result = DIMENSION_MODEL.match(dimensions)
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   717
                if result is None:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   718
                    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
   719
                    message.ShowModal()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   720
                    message.Destroy()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   721
                    self.RefreshView()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   722
                    return
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   723
                bounds = result.groups()
460
2ddf7bbd1f74 Bug on array dimensions bound test fixed
laurent
parents: 440
diff changeset
   724
                if int(bounds[0]) >= int(bounds[1]):
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   725
                    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
   726
                    message.ShowModal()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   727
                    message.Destroy()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   728
                    self.RefreshView()
b1144bb36605 Bug with array dimensions edition fixed
lbessard
parents: 205
diff changeset
   729
                    return
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 379
diff changeset
   730
                infos["dimensions"].append(bounds)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   731
            infos["initial"] = self.ArrayInitialValue.GetValue()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   732
        elif selected == "Structure":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   733
            infos["elements"] = self.StructureElementsTable.GetData()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 235
diff changeset
   734
            infos["initial"] = ""
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   735
        self.Controler.SetDataTypeInfos(self.TagName, infos)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   736
        self.ParentWindow.RefreshTitle()
494
c91644c2bfa7 Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 462
diff changeset
   737
        self.ParentWindow.RefreshFileMenu()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   738
        self.ParentWindow.RefreshEditMenu()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents:
diff changeset
   739
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   740
#-------------------------------------------------------------------------------
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   741
#                        Highlights showing functions
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   742
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   743
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   744
    def OnRefreshHighlightsTimer(self, event):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   745
        self.RefreshView()
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   746
        event.Skip()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   747
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   748
    def ClearHighlights(self, highlight_type=None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   749
        if highlight_type is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   750
            self.Highlights = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   751
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   752
            self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type]
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   753
        for control in self.HighlightControls.itervalues():
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   754
            if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   755
                control.SetBackgroundColour(wx.NullColour)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   756
                control.SetForegroundColour(wx.NullColour)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   757
            elif isinstance(control, wx.TextCtrl):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   758
                value = control.GetValue()
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   759
                control.SetStyle(0, len(value), wx.TextAttr(wx.NullColour))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   760
            elif isinstance(control, wx.gizmos.EditableListBox):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   761
                listctrl = control.GetListCtrl()
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   762
                for i in xrange(listctrl.GetItemCount()):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   763
                    listctrl.SetItemBackgroundColour(i, wx.NullColour)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   764
                    listctrl.SetItemTextColour(i, wx.NullColour)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   765
        self.StructureElementsTable.ClearHighlights(highlight_type)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   766
        self.RefreshView()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   767
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   768
    def AddHighlight(self, infos, start, end ,highlight_type):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   769
        self.Highlights.append((infos, start, end, highlight_type))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   770
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   771
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   772
    def ShowHighlights(self):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 215
diff changeset
   773
        type_infos = self.Controler.GetDataTypeInfos(self.TagName)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 556
diff changeset
   774
        for infos, start, end, highlight_type in self.Highlights:
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   775
            if infos[0] == "struct":
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   776
                self.StructureElementsTable.AddHighlight(infos[1:], highlight_type)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   777
            else:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   778
                control = self.HighlightControls.get((type_infos["type"], infos[0]), None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   779
                if control is not None:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   780
                    if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   781
                        control.SetBackgroundColour(highlight_type[0])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   782
                        control.SetForegroundColour(highlight_type[1])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   783
                    elif isinstance(control, wx.TextCtrl):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   784
                        control.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   785
                    elif isinstance(control, wx.gizmos.EditableListBox):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   786
                        listctrl = control.GetListCtrl()
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   787
                        listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   788
                        listctrl.SetItemTextColour(infos[1], highlight_type[1])
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   789
                        listctrl.Select(listctrl.FocusedItem, False)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   790