controls/EditorPanel.py
author laurent
Tue, 20 Dec 2011 23:34:19 +0100
changeset 610 430d029beed6
parent 600 7db729686416
child 613 c487c54c1cfe
permissions -rw-r--r--
Fixing bug in enumerated datatype editor. Initial value symbol not updated if changed in the list of values
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     3
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     6
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     8
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    10
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    15
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    19
#General Public License for more details.
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    20
#
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    24
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    25
import wx
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    26
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    27
from VariablePanel import VariablePanel
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    28
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    29
class EditorPanel(wx.SplitterWindow):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    30
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    31
    ID = wx.NewId()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    32
    VARIABLE_PANEL_TYPE = None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    33
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    34
    if wx.VERSION < (2, 6, 0):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    35
        def Bind(self, event, function, id = None):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    36
            if id is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    37
                event(self, id, function)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    38
            else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    39
                event(self, function)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    40
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    41
    def _init_Editor(self, prnt):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    42
        self.Editor = None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    43
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    44
    def _init_ctrls(self, prnt):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    45
        wx.SplitterWindow.__init__(self, id=self.ID, name='MainSplitter', parent=prnt,
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    46
              size=wx.Size(0, 0), style=wx.SUNKEN_BORDER|wx.SP_3D)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    47
        self.SetNeedUpdating(True)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    48
        self.SetMinimumPaneSize(1)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    49
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    50
        self._init_Editor(self)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    51
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    52
        if self.VARIABLE_PANEL_TYPE is not None:
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 586
diff changeset
    53
            self.VariableEditor = VariablePanel(self, self, self.Controler, self.VARIABLE_PANEL_TYPE, self.Debug)
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    54
            self.VariableEditor.SetTagName(self.TagName)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    55
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    56
            if self.Editor is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    57
                self.SplitHorizontally(self.VariableEditor, self.Editor, 200)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    58
            else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    59
                self.Initialize(self.VariableEditor)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    60
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    61
        else:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    62
            self.VariableEditor = None
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    63
            
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    64
            if self.Editor is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    65
                self.Initialize(self.Editor)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    66
        
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 586
diff changeset
    67
    def __init__(self, parent, tagname, window, controler, debug=False):
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    68
        self.ParentWindow = window
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    69
        self.Controler = controler
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    70
        self.TagName = tagname
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    71
        self.Icon = None
600
7db729686416 Making variable panel not editable when showing variables of debugging block
laurent
parents: 586
diff changeset
    72
        self.Debug = debug
586
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    73
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    74
        self._init_ctrls(parent)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    75
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    76
    def SetTagName(self, tagname):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    77
        self.TagName = tagname
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    78
        if self.VARIABLE_PANEL_TYPE is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    79
            self.VariableEditor.SetTagName(tagname)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    80
        
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    81
    def GetTagName(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    82
        return self.TagName
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    83
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    84
    def GetTitle(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    85
        return "-".join(self.TagName.split("::")[1:])
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    86
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    87
    def GetIcon(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    88
        return self.Icon
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    89
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    90
    def SetIcon(self, icon):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    91
        self.Icon = icon
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    92
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    93
    def IsViewing(self, tagname):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    94
        return self.TagName == tagname
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    95
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    96
    def IsDebugging(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    97
        return False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    98
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
    99
    def SetMode(self, mode):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   100
        pass
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   101
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   102
    def ResetBuffer(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   103
        pass
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   104
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   105
    def GetBufferState(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   106
        if self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   107
            return self.Controler.GetBufferState()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   108
        return False, False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   109
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   110
    def Undo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   111
        if self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   112
            self.Controler.LoadPrevious()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   113
            self.RefreshView()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   114
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   115
    def Redo(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   116
        if self.Controler is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   117
            self.Controler.LoadNext()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   118
            self.RefreshView()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   119
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   120
    def HasNoModel(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   121
        return False
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   122
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   123
    def RefreshView(self, variablepanel=True):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   124
        if variablepanel:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   125
            self.RefreshVariablePanel()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   126
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   127
    def RefreshVariablePanel(self):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   128
        if self.VariableEditor is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   129
            self.VariableEditor.RefreshView()
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   130
    
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   131
    def _Refresh(self, *args):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   132
        self.ParentWindow._Refresh(*args)
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   133
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   134
    def RefreshScaling(self, refresh=True):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   135
        pass
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   136
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   137
    def ClearHighlights(self, highlight_type=None):
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   138
        if self.VariableEditor is not None:
9aa96a36cf33 Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
diff changeset
   139
            self.VariableEditor.ClearHighlights(highlight_type)