RessourceEditor.py
author Laurent Bessard
Sun, 02 Sep 2012 01:18:50 +0200
changeset 754 48966b6ceedc
parent 714 131ea7f237b9
permissions -rw-r--r--
Fix bug in ST code generated for in-out variables in Function and FunctionBlock interface
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     3
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     6
#
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     8
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    10
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    15
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
    19
#General Public License for more details.
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    20
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    24
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    25
import wx
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
    26
import wx.lib.buttons
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    27
import wx.grid
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    28
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    29
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 588
diff changeset
    30
from controls import CustomGrid, CustomTable, EditorPanel, DurationCellEditor
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
    31
from utils.BitmapLibrary import GetBitmap
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    32
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    33
#-------------------------------------------------------------------------------
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    34
#                          Configuration Editor class
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    35
#-------------------------------------------------------------------------------
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    36
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    37
[ID_CONFIGURATIONEDITOR, 
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    38
] = [wx.NewId() for _init_ctrls in range(1)]
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
    39
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    40
class ConfigurationEditor(EditorPanel):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    41
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    42
    ID = ID_CONFIGURATIONEDITOR
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    43
    VARIABLE_PANEL_TYPE = "config"
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    44
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    45
    def GetBufferState(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    46
        return self.Controler.GetBufferState()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    47
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    48
    def Undo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    49
        self.Controler.LoadPrevious()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    50
        self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    51
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    52
    def Redo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    53
        self.Controler.LoadNext()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    54
        self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    55
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    56
    def HasNoModel(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    57
        return self.Controler.GetEditedElement(self.TagName) is None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
    58
365
7bfd014652e0 Bug on clear errors fixed
lbessard
parents: 239
diff changeset
    59
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    60
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    61
#                            Resource Editor class
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    62
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    63
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    64
def GetTasksTableColnames():
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    65
    _ = lambda x : x
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
    66
    return [_("Name"), _("Triggering"), _("Single"), _("Interval"), _("Priority")]
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
    67
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
    68
def GetTaskTriggeringOptions():
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
    69
    _ = lambda x : x
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
    70
    return [_("Interrupt"), _("Cyclic")]
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
    71
TASKTRIGGERINGOPTIONS_DICT = dict([(_(option), option) for option in GetTaskTriggeringOptions()])
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    72
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    73
def GetInstancesTableColnames():
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    74
    _ = lambda x : x
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    75
    return [_("Name"), _("Type"), _("Task")]
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
    76
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 588
diff changeset
    77
class ResourceTable(CustomTable):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    78
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    79
    """
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    80
    A custom wx.grid.Grid Table using user supplied data
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    81
    """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    82
    def __init__(self, parent, data, colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    83
        # The base class must be initialized *first*
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 588
diff changeset
    84
        CustomTable.__init__(self, parent, data, colnames)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    85
        self.ColAlignements = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    86
        self.ColSizes = []
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 588
diff changeset
    87
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    88
    def GetColAlignements(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    89
        return self.ColAlignements
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    90
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    91
    def SetColAlignements(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    92
        self.ColAlignements = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    93
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    94
    def GetColSizes(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    95
        return self.ColSizes
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    96
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    97
    def SetColSizes(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    98
        self.ColSizes = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    99
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   100
    def GetValue(self, row, col):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   101
        if row < self.GetNumberRows():
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   102
            colname = self.GetColLabelValue(col, False)
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   103
            value = str(self.data[row].get(colname, ""))
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   104
            if colname == "Triggering":
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   105
                return _(value)
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   106
            return value
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   107
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   108
    def SetValue(self, row, col, value):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   109
        if col < len(self.colnames):
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   110
            colname = self.GetColLabelValue(col, False)
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   111
            if colname == "Triggering":
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   112
                value = TASKTRIGGERINGOPTIONS_DICT[value]
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   113
            self.data[row][colname] = value
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   114
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   115
    def _updateColAttrs(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   116
        """
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   117
        wx.grid.Grid -> update the column attributes to add the
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   118
        appropriate renderer given the column name.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   119
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   120
        Otherwise default to the default renderer.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   121
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   122
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   123
        for col in range(self.GetNumberCols()):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   124
            attr = wx.grid.GridCellAttr()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   125
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   126
            grid.SetColAttr(col, attr)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   127
            grid.SetColSize(col, self.ColSizes[col])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   128
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   129
        for row in range(self.GetNumberRows()):
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   130
            row_highlights = self.Highlights.get(row, {})
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   131
            for col in range(self.GetNumberCols()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   132
                editor = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   133
                renderer = None
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   134
                colname = self.GetColLabelValue(col, False)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   135
                grid.SetReadOnly(row, col, False)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 560
diff changeset
   136
                if colname == "Name":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   137
                    editor = wx.grid.GridCellTextEditor()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   138
                    renderer = wx.grid.GridCellStringRenderer()
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 560
diff changeset
   139
                elif colname == "Interval":
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 560
diff changeset
   140
                    editor = DurationCellEditor(self)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 560
diff changeset
   141
                    renderer = wx.grid.GridCellStringRenderer()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 560
diff changeset
   142
                    if self.GetValueByName(row, "Triggering") != "Cyclic":
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   143
                        grid.SetReadOnly(row, col, True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   144
                elif colname == "Single":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   145
                    editor = wx.grid.GridCellChoiceEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   146
                    editor.SetParameters(self.Parent.VariableList)
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   147
                    if self.GetValueByName(row, "Triggering") != "Interrupt":
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   148
                        grid.SetReadOnly(row, col, True)
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   149
                elif colname == "Triggering":
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   150
                    editor = wx.grid.GridCellChoiceEditor()
578
73138d14d88d Fix bug with internationalization in ResourceEditor
laurent
parents: 577
diff changeset
   151
                    editor.SetParameters(",".join([""] + map(_, GetTaskTriggeringOptions())))
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   152
                elif colname == "Type":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   153
                    editor = wx.grid.GridCellChoiceEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   154
                    editor.SetParameters(self.Parent.TypeList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   155
                elif colname == "Priority":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   156
                    editor = wx.grid.GridCellNumberEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   157
                    editor.SetParameters("0,65535")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   158
                elif colname == "Task":
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   159
                    editor = wx.grid.GridCellChoiceEditor()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   160
                    editor.SetParameters(self.Parent.TaskList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   161
                    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   162
                grid.SetCellEditor(row, col, editor)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   163
                grid.SetCellRenderer(row, col, renderer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   164
                
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   165
                highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   166
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   167
                grid.SetCellTextColour(row, col, highlight_colours[1])
604
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 588
diff changeset
   168
            self.ResizeRow(grid, row)
5b42b4401e6b Adding support for unifying grid table control elements
laurent
parents: 588
diff changeset
   169
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   170
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   171
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   172
#                        Highlights showing functions
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   173
#-------------------------------------------------------------------------------
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   174
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   175
    def AddHighlight(self, infos, highlight_type):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   176
        row_highlights = self.Highlights.setdefault(infos[0], {})
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   177
        col_highlights = row_highlights.setdefault(infos[1], [])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   178
        col_highlights.append(highlight_type)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   179
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   180
    def ClearHighlights(self, highlight_type=None):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   181
        if highlight_type is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   182
            self.Highlights = {}
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   183
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   184
            for row, row_highlights in self.Highlights.iteritems():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   185
                row_items = row_highlights.items()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   186
                for col, col_highlights in row_items:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   187
                    if highlight_type in col_highlights:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   188
                        col_highlights.remove(highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   189
                    if len(col_highlights) == 0:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   190
                        row_highlights.pop(col)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   191
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   192
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   193
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   194
class ResourceEditor(EditorPanel):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   195
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   196
    VARIABLE_PANEL_TYPE = "resource"
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   197
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   198
    def _init_Editor(self, parent):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   199
        self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   200
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   201
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   202
        main_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   203
        main_sizer.AddGrowableRow(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   204
        main_sizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   205
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   206
        tasks_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   207
        tasks_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   208
        tasks_sizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   209
        main_sizer.AddSizer(tasks_sizer, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   210
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   211
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   212
        tasks_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   213
        tasks_buttons_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   214
        tasks_buttons_sizer.AddGrowableRow(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   215
        tasks_sizer.AddSizer(tasks_buttons_sizer, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   216
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   217
        tasks_label = wx.StaticText(self.Editor, label=_(u'Tasks:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   218
        tasks_buttons_sizer.AddWindow(tasks_label, flag=wx.ALIGN_BOTTOM)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   219
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   220
        for name, bitmap, help in [
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   221
                ("AddTaskButton", "add_element", _("Add task")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   222
                ("DeleteTaskButton", "remove_element", _("Remove task")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   223
                ("UpTaskButton", "up", _("Move task up")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   224
                ("DownTaskButton", "down", _("Move task down"))]:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   225
            button = wx.lib.buttons.GenBitmapButton(self.Editor, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   226
                  bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   227
            button.SetToolTipString(help)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   228
            setattr(self, name, button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   229
            tasks_buttons_sizer.AddWindow(button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   230
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   231
        self.TasksGrid = CustomGrid(self.Editor, style=wx.VSCROLL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   232
        self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnTasksGridCellChange)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   233
        tasks_sizer.AddWindow(self.TasksGrid, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   234
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   235
        instances_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   236
        instances_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   237
        instances_sizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   238
        main_sizer.AddSizer(instances_sizer, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   239
              flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   240
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   241
        instances_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   242
        instances_buttons_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   243
        instances_buttons_sizer.AddGrowableRow(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   244
        instances_sizer.AddSizer(instances_buttons_sizer, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   245
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   246
        instances_label = wx.StaticText(self.Editor, label=_(u'Instances:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   247
        instances_buttons_sizer.AddWindow(instances_label, flag=wx.ALIGN_BOTTOM)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   248
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   249
        for name, bitmap, help in [
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   250
                ("AddInstanceButton", "add_element", _("Add instance")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   251
                ("DeleteInstanceButton", "remove_element", _("Remove instance")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   252
                ("UpInstanceButton", "up", _("Move instance up")),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   253
                ("DownInstanceButton", "down", _("Move instance down"))]:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   254
            button = wx.lib.buttons.GenBitmapButton(self.Editor, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   255
                  bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   256
            button.SetToolTipString(help)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   257
            setattr(self, name, button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   258
            instances_buttons_sizer.AddWindow(button)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   259
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   260
        self.InstancesGrid = CustomGrid(self.Editor, style=wx.VSCROLL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   261
        self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   262
              self.OnInstancesGridCellChange)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   263
        instances_sizer.AddWindow(self.InstancesGrid, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   264
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   265
        self.Editor.SetSizer(main_sizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 684
diff changeset
   266
        
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   267
    def __init__(self, parent, tagname, window, controler):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   268
        EditorPanel.__init__(self, parent, tagname, window, controler)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   269
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   270
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   271
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   272
        
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   273
        self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0}
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   274
        self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   275
        self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 560
diff changeset
   276
        self.TasksTable.SetColSizes([200, 100, 100, 150, 100])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   277
        self.TasksGrid.SetTable(self.TasksTable)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   278
        self.TasksGrid.SetButtons({"Add": self.AddTaskButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   279
                                   "Delete": self.DeleteTaskButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   280
                                   "Up": self.UpTaskButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   281
                                   "Down": self.DownTaskButton})
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   282
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   283
        def _AddTask(new_row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   284
            self.TasksTable.InsertRow(new_row, self.TasksDefaultValue.copy())
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   285
            self.RefreshModel()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   286
            self.RefreshView()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   287
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   288
        setattr(self.TasksGrid, "_AddRow", _AddTask)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   289
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   290
        def _DeleteTask(row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   291
            self.TasksTable.RemoveRow(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   292
            self.RefreshModel()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   293
            self.RefreshView()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   294
        setattr(self.TasksGrid, "_DeleteRow", _DeleteTask)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   295
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   296
        def _MoveTask(row, move):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   297
            new_row = self.TasksTable.MoveRow(row, move)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   298
            if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   299
                self.RefreshModel()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   300
                self.RefreshView()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   301
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   302
        setattr(self.TasksGrid, "_MoveRow", _MoveTask)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   303
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   304
        self.TasksGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   305
        self.TasksTable.ResetView(self.TasksGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   306
        self.TasksGrid.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   307
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   308
        self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""}
391
07447ee3538e Adding support for internationalization
laurent
parents: 365
diff changeset
   309
        self.InstancesTable = ResourceTable(self, [], GetInstancesTableColnames())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   310
        self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   311
        self.InstancesTable.SetColSizes([200, 150, 150])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   312
        self.InstancesGrid.SetTable(self.InstancesTable)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   313
        self.InstancesGrid.SetButtons({"Add": self.AddInstanceButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   314
                                       "Delete": self.DeleteInstanceButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   315
                                       "Up": self.UpInstanceButton,
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   316
                                       "Down": self.DownInstanceButton})
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   317
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   318
        def _AddInstance(new_row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   319
            self.InstancesTable.InsertRow(new_row, self.InstancesDefaultValue.copy())
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   320
            self.RefreshModel()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   321
            self.RefreshView()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   322
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   323
        setattr(self.InstancesGrid, "_AddRow", _AddInstance)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   324
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   325
        def _DeleteInstance(row):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   326
            self.InstancesTable.RemoveRow(row)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   327
            self.RefreshModel()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   328
            self.RefreshView()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   329
        setattr(self.InstancesGrid, "_DeleteRow", _DeleteInstance)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   330
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   331
        def _MoveInstance(row, move):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   332
            new_row = max(0, min(row + move, self.InstancesTable.GetNumberRows() - 1))
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   333
            if new_row != row:
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   334
                if self.InstancesTable.GetValueByName(row, "Task") != self.InstancesTable.GetValueByName(new_row, "Task"):
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   335
                    return row 
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   336
                self.InstancesTable.MoveRow(row, move)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   337
                self.RefreshModel()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   338
                self.RefreshView()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   339
            return new_row
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   340
        setattr(self.InstancesGrid, "_MoveRow", _MoveInstance)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   341
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   342
        def _RefreshInstanceButtons():
672
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   343
            if self:
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   344
                rows = self.InstancesTable.GetNumberRows()
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   345
                row = self.InstancesGrid.GetGridCursorRow()
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   346
                self.DeleteInstanceButton.Enable(rows > 0)
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   347
                self.UpInstanceButton.Enable(row > 0 and 
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   348
                    self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row - 1, "Task"))
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   349
                self.DownInstanceButton.Enable(0 <= row < rows - 1 and 
d751b1c609b3 Fix bug when closing project and one editor is opened
laurent
parents: 658
diff changeset
   350
                    self.InstancesTable.GetValueByName(row, "Task") == self.InstancesTable.GetValueByName(row + 1, "Task"))
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   351
        setattr(self.InstancesGrid, "RefreshButtons", _RefreshInstanceButtons)
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   352
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   353
        self.InstancesGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   354
        self.InstancesTable.ResetView(self.InstancesGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   355
        self.InstancesGrid.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   356
        
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   357
        self.TasksGrid.SetFocus()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   358
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   359
    def __del__(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   360
        self.RefreshHighlightsTimer.Stop()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   361
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   362
    def RefreshTypeList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   363
        self.TypeList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   364
        blocktypes = self.Controler.GetBlockResource()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   365
        for blocktype in blocktypes:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   366
            self.TypeList += ",%s"%blocktype
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   367
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   368
    def RefreshTaskList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   369
        self.TaskList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   370
        for row in xrange(self.TasksTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   371
            self.TaskList += ",%s"%self.TasksTable.GetValueByName(row, "Name")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   372
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   373
    def RefreshVariableList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   374
        self.VariableList = ""
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   375
        for variable in self.Controler.GetEditedResourceVariables(self.TagName):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   376
            self.VariableList += ",%s"%variable
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   377
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   378
    def RefreshModel(self):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   379
        self.Controler.SetEditedResourceInfos(self.TagName, self.TasksTable.GetData(), self.InstancesTable.GetData())
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   380
        self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   381
        
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   382
    # Buffer the last model state
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   383
    def RefreshBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 27
diff changeset
   384
        self.Controler.BufferProject()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   385
        self.ParentWindow.RefreshTitle()
494
c91644c2bfa7 Bug on FileMenu not refreshed when modifications fixed
laurent
parents: 407
diff changeset
   386
        self.ParentWindow.RefreshFileMenu()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   387
        self.ParentWindow.RefreshEditMenu()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   388
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   389
    def GetBufferState(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   390
        return self.Controler.GetBufferState()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   391
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   392
    def Undo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   393
        self.Controler.LoadPrevious()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   394
        self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   395
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   396
    def Redo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   397
        self.Controler.LoadNext()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   398
        self.ParentWindow.CloseTabsWithoutModel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   399
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   400
    def HasNoModel(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   401
        return self.Controler.GetEditedElement(self.TagName) is None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   402
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   403
    def RefreshView(self, variablepanel=True):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   404
        EditorPanel.RefreshView(self, variablepanel)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   405
        
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 113
diff changeset
   406
        tasks, instances = self.Controler.GetEditedResourceInfos(self.TagName)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   407
        self.TasksTable.SetData(tasks)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   408
        self.InstancesTable.SetData(instances)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   409
        self.RefreshTypeList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   410
        self.RefreshTaskList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   411
        self.RefreshVariableList()
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   412
        self.TasksTable.ResetView(self.TasksGrid)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   413
        self.InstancesTable.ResetView(self.InstancesGrid)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   414
        self.TasksGrid.RefreshButtons()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   415
        self.InstancesGrid.RefreshButtons()
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   416
        
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   417
    def OnTasksGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   418
        row, col = event.GetRow(), event.GetCol()
588
4876fedbe9df Fixing bug in RessourceEditor. Task reference in instance entries wan't updated after task name modification
laurent
parents: 586
diff changeset
   419
        if self.TasksTable.GetColLabelValue(col) == "Name":
4876fedbe9df Fixing bug in RessourceEditor. Task reference in instance entries wan't updated after task name modification
laurent
parents: 586
diff changeset
   420
            tasklist = [name for name in self.TaskList.split(",") if name != ""]
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   421
            for i in xrange(self.TasksTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   422
                task = self.TasksTable.GetValueByName(i, "Name")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   423
                if task in tasklist:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   424
                    tasklist.remove(task)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   425
            if len(tasklist) > 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   426
                old_name = tasklist[0]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   427
                new_name = self.TasksTable.GetValue(row, col)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   428
                for i in xrange(self.InstancesTable.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   429
                    if self.InstancesTable.GetValueByName(i, "Task") == old_name:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   430
                        self.InstancesTable.SetValueByName(i, "Task", new_name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   431
        self.RefreshModel()
560
3757f0de0d07 Adding column for selecting task triggering in Resource Editor
laurent
parents: 494
diff changeset
   432
        colname = self.TasksTable.GetColLabelValue(col, False)
588
4876fedbe9df Fixing bug in RessourceEditor. Task reference in instance entries wan't updated after task name modification
laurent
parents: 586
diff changeset
   433
        if colname in ["Triggering", "Name"]:
655
435e2d8ee580 Fixing issues regarding control navigation in EditorPanel and CustomGrid
laurent
parents: 654
diff changeset
   434
            wx.CallAfter(self.RefreshView, False)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   435
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   436
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   437
    def OnInstancesGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   438
        self.RefreshModel()
684
f10449b18dbe refactoring
laurent
parents: 672
diff changeset
   439
        self.ParentWindow.RefreshPouInstanceVariablesPanel()
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 573
diff changeset
   440
        self.InstancesGrid.RefreshButtons()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   441
        event.Skip()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   442
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   443
#-------------------------------------------------------------------------------
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   444
#                        Highlights showing functions
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   445
#-------------------------------------------------------------------------------
573
0a6b2e1f8ce3 Fixing bug in RessourceEditor with highlighting
laurent
parents: 566
diff changeset
   446
    
0a6b2e1f8ce3 Fixing bug in RessourceEditor with highlighting
laurent
parents: 566
diff changeset
   447
    def OnRefreshHighlightsTimer(self, event):
0a6b2e1f8ce3 Fixing bug in RessourceEditor with highlighting
laurent
parents: 566
diff changeset
   448
        self.RefreshView()
0a6b2e1f8ce3 Fixing bug in RessourceEditor with highlighting
laurent
parents: 566
diff changeset
   449
        event.Skip()
0a6b2e1f8ce3 Fixing bug in RessourceEditor with highlighting
laurent
parents: 566
diff changeset
   450
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   451
    def AddHighlight(self, infos, start, end, highlight_type):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   452
        if infos[0] == "task":
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   453
            self.TasksTable.AddHighlight(infos[1:], highlight_type)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 145
diff changeset
   454
        elif infos[0] == "instance":
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   455
            self.InstancesTable.AddHighlight(infos[1:], highlight_type)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   456
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   457
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   458
    def ClearHighlights(self, highlight_type=None):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   459
        EditorPanel.ClearHighlights(self, highlight_type)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents: 579
diff changeset
   460
        
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   461
        self.TasksTable.ClearHighlights(highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   462
        self.InstancesTable.ClearHighlights(highlight_type)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   463
        self.TasksTable.ResetView(self.TasksGrid)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 564
diff changeset
   464
        self.InstancesTable.ResetView(self.InstancesGrid)