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