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