814
|
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 controls import VariablePanel
|
|
28 |
|
|
29 |
class EditorPanel(wx.SplitterWindow):
|
|
30 |
|
|
31 |
VARIABLE_PANEL_TYPE = None
|
|
32 |
|
|
33 |
def _init_Editor(self, prnt):
|
|
34 |
self.Editor = None
|
|
35 |
|
|
36 |
def _init_MenuItems(self):
|
|
37 |
self.MenuItems = []
|
|
38 |
|
|
39 |
def _init_ctrls(self, parent):
|
|
40 |
wx.SplitterWindow.__init__(self, parent,
|
|
41 |
style=wx.SUNKEN_BORDER|wx.SP_3D)
|
|
42 |
self.SetNeedUpdating(True)
|
|
43 |
self.SetMinimumPaneSize(1)
|
|
44 |
|
|
45 |
self._init_MenuItems()
|
|
46 |
|
|
47 |
if self.VARIABLE_PANEL_TYPE is not None:
|
|
48 |
self.VariableEditor = VariablePanel(self, self, self.Controler, self.VARIABLE_PANEL_TYPE, self.Debug)
|
|
49 |
self.VariableEditor.SetTagName(self.TagName)
|
|
50 |
else:
|
|
51 |
self.VariableEditor = None
|
|
52 |
|
|
53 |
self._init_Editor(self)
|
|
54 |
|
|
55 |
if self.Editor is not None and self.VariableEditor is not None:
|
|
56 |
self.SplitHorizontally(self.VariableEditor, self.Editor, 200)
|
|
57 |
elif self.VariableEditor is not None:
|
|
58 |
self.Initialize(self.VariableEditor)
|
|
59 |
elif self.Editor is not None:
|
|
60 |
self.Initialize(self.Editor)
|
|
61 |
|
|
62 |
def __init__(self, parent, tagname, window, controler, debug=False):
|
|
63 |
self.ParentWindow = window
|
|
64 |
self.Controler = controler
|
|
65 |
self.TagName = tagname
|
|
66 |
self.Icon = None
|
|
67 |
self.Debug = debug
|
|
68 |
|
|
69 |
self._init_ctrls(parent)
|
|
70 |
|
|
71 |
def SetTagName(self, tagname):
|
|
72 |
self.TagName = tagname
|
|
73 |
if self.VARIABLE_PANEL_TYPE is not None:
|
|
74 |
self.VariableEditor.SetTagName(tagname)
|
|
75 |
|
|
76 |
def GetTagName(self):
|
|
77 |
return self.TagName
|
|
78 |
|
|
79 |
def Select(self):
|
|
80 |
self.ParentWindow.EditProjectElement(None, self.GetTagName(), True)
|
|
81 |
|
|
82 |
def GetTitle(self):
|
|
83 |
return "-".join(self.TagName.split("::")[1:])
|
|
84 |
|
|
85 |
def GetIcon(self):
|
|
86 |
return self.Icon
|
|
87 |
|
|
88 |
def SetIcon(self, icon):
|
|
89 |
self.Icon = icon
|
|
90 |
|
|
91 |
def GetState(self):
|
|
92 |
return None
|
|
93 |
|
|
94 |
def SetState(self, state):
|
|
95 |
pass
|
|
96 |
|
|
97 |
def IsViewing(self, tagname):
|
|
98 |
return self.GetTagName() == tagname
|
|
99 |
|
|
100 |
def IsDebugging(self):
|
|
101 |
return self.Debug
|
|
102 |
|
|
103 |
def SetMode(self, mode):
|
|
104 |
pass
|
|
105 |
|
|
106 |
def ResetBuffer(self):
|
|
107 |
pass
|
|
108 |
|
|
109 |
def IsModified(self):
|
|
110 |
return False
|
|
111 |
|
|
112 |
def CheckSaveBeforeClosing(self):
|
|
113 |
return True
|
|
114 |
|
|
115 |
def Save(self):
|
|
116 |
pass
|
|
117 |
|
|
118 |
def SaveAs(self):
|
|
119 |
pass
|
|
120 |
|
|
121 |
def GetBufferState(self):
|
|
122 |
if self.Controler is not None:
|
|
123 |
return self.Controler.GetBufferState()
|
|
124 |
return False, False
|
|
125 |
|
|
126 |
def Undo(self):
|
|
127 |
if self.Controler is not None:
|
|
128 |
self.Controler.LoadPrevious()
|
|
129 |
self.RefreshView()
|
|
130 |
|
|
131 |
def Redo(self):
|
|
132 |
if self.Controler is not None:
|
|
133 |
self.Controler.LoadNext()
|
|
134 |
self.RefreshView()
|
|
135 |
|
|
136 |
def Find(self, direction, search_params):
|
|
137 |
pass
|
|
138 |
|
|
139 |
def HasNoModel(self):
|
|
140 |
return False
|
|
141 |
|
|
142 |
def RefreshView(self, variablepanel=True):
|
|
143 |
if variablepanel:
|
|
144 |
self.RefreshVariablePanel()
|
|
145 |
|
|
146 |
def RefreshVariablePanel(self):
|
|
147 |
if self.VariableEditor is not None:
|
|
148 |
self.VariableEditor.RefreshView()
|
|
149 |
|
|
150 |
def GetConfNodeMenuItems(self):
|
|
151 |
return self.MenuItems
|
|
152 |
|
|
153 |
def RefreshConfNodeMenu(self, confnode_menu):
|
|
154 |
pass
|
|
155 |
|
|
156 |
def _Refresh(self, *args):
|
|
157 |
self.ParentWindow._Refresh(*args)
|
|
158 |
|
|
159 |
def RefreshScaling(self, refresh=True):
|
|
160 |
pass
|
|
161 |
|
|
162 |
def AddHighlight(self, infos, start, end, highlight_type):
|
|
163 |
if self.VariableEditor is not None and infos[0] in ["var_local", "var_input", "var_output", "var_inout"]:
|
|
164 |
self.VariableEditor.AddVariableHighlight(infos[1:], highlight_type)
|
|
165 |
|
|
166 |
def RemoveHighlight(self, infos, start, end, highlight_type):
|
|
167 |
if self.VariableEditor is not None and infos[0] in ["var_local", "var_input", "var_output", "var_inout"]:
|
|
168 |
self.VariableEditor.RemoveVariableHighlight(infos[1:], highlight_type)
|
|
169 |
|
|
170 |
def ClearHighlights(self, highlight_type=None):
|
|
171 |
if self.VariableEditor is not None:
|
|
172 |
self.VariableEditor.ClearHighlights(highlight_type)
|