Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. Laurent@814: # andrej@1571: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # andrej@1571: # See COPYING file for copyrights details. Laurent@814: # andrej@1571: # This program is free software; you can redistribute it and/or andrej@1571: # modify it under the terms of the GNU General Public License andrej@1571: # as published by the Free Software Foundation; either version 2 andrej@1571: # of the License, or (at your option) any later version. Laurent@814: # andrej@1571: # This program is distributed in the hope that it will be useful, andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1571: # GNU General Public License for more details. Laurent@814: # andrej@1571: # You should have received a copy of the GNU General Public License andrej@1571: # along with this program; if not, write to the Free Software andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Laurent@814: andrej@1881: andrej@1881: from __future__ import absolute_import Laurent@814: import wx Laurent@814: Laurent@814: from controls import VariablePanel Laurent@814: andrej@1736: Laurent@814: class EditorPanel(wx.SplitterWindow): andrej@1735: Laurent@814: VARIABLE_PANEL_TYPE = None andrej@1735: Laurent@814: def _init_Editor(self, prnt): Laurent@814: self.Editor = None andrej@1735: Laurent@814: def _init_MenuItems(self): Laurent@814: self.MenuItems = [] andrej@1735: Laurent@814: def _init_ctrls(self, parent): Laurent@814: self.SetMinimumPaneSize(1) andrej@1735: Laurent@814: self._init_MenuItems() andrej@1735: Laurent@814: if self.VARIABLE_PANEL_TYPE is not None: Laurent@814: self.VariableEditor = VariablePanel(self, self, self.Controler, self.VARIABLE_PANEL_TYPE, self.Debug) Laurent@814: self.VariableEditor.SetTagName(self.TagName) Laurent@814: else: Laurent@814: self.VariableEditor = None andrej@1735: Laurent@814: self._init_Editor(self) andrej@1735: Laurent@814: if self.Editor is not None and self.VariableEditor is not None: Laurent@814: self.SplitHorizontally(self.VariableEditor, self.Editor, 200) Laurent@814: elif self.VariableEditor is not None: Laurent@814: self.Initialize(self.VariableEditor) Laurent@814: elif self.Editor is not None: Laurent@814: self.Initialize(self.Editor) andrej@1735: Laurent@814: def __init__(self, parent, tagname, window, controler, debug=False): andrej@1836: wx.SplitterWindow.__init__(self, parent, andrej@1836: style=wx.SUNKEN_BORDER | wx.SP_3D) andrej@1836: Laurent@814: self.ParentWindow = window Laurent@814: self.Controler = controler Laurent@814: self.TagName = tagname Laurent@814: self.Icon = None Laurent@814: self.Debug = debug andrej@1735: Laurent@814: self._init_ctrls(parent) andrej@1735: Laurent@814: def SetTagName(self, tagname): Laurent@814: self.TagName = tagname Laurent@814: if self.VARIABLE_PANEL_TYPE is not None: Laurent@814: self.VariableEditor.SetTagName(tagname) andrej@1735: Laurent@814: def GetTagName(self): Laurent@814: return self.TagName andrej@1735: Laurent@814: def Select(self): Laurent@814: self.ParentWindow.EditProjectElement(None, self.GetTagName(), True) andrej@1735: Laurent@814: def GetTitle(self): andrej@1615: return ".".join(self.TagName.split("::")[1:]) andrej@1735: Laurent@814: def GetIcon(self): Laurent@814: return self.Icon andrej@1735: Laurent@814: def SetIcon(self, icon): Laurent@814: self.Icon = icon andrej@1735: Laurent@814: def IsViewing(self, tagname): Laurent@814: return self.GetTagName() == tagname Laurent@814: Laurent@814: def IsDebugging(self): Laurent@814: return self.Debug Laurent@814: Laurent@814: def SetMode(self, mode): Laurent@814: pass Laurent@814: Laurent@814: def ResetBuffer(self): Laurent@814: pass andrej@1735: Laurent@814: def IsModified(self): Laurent@814: return False andrej@1735: Laurent@814: def CheckSaveBeforeClosing(self): Laurent@814: return True andrej@1735: Laurent@814: def Save(self): Laurent@814: pass andrej@1735: Laurent@814: def SaveAs(self): Laurent@814: pass andrej@1735: Laurent@814: def GetBufferState(self): Laurent@814: if self.Controler is not None: Laurent@814: return self.Controler.GetBufferState() Laurent@814: return False, False andrej@1735: Laurent@814: def Undo(self): Laurent@814: if self.Controler is not None: Laurent@814: self.Controler.LoadPrevious() Laurent@814: self.RefreshView() andrej@1735: Laurent@814: def Redo(self): Laurent@814: if self.Controler is not None: Laurent@814: self.Controler.LoadNext() Laurent@814: self.RefreshView() andrej@1735: Laurent@814: def Find(self, direction, search_params): Laurent@814: pass andrej@1735: Laurent@814: def HasNoModel(self): Laurent@814: return False andrej@1735: Laurent@814: def RefreshView(self, variablepanel=True): Laurent@814: if variablepanel: Laurent@814: self.RefreshVariablePanel() andrej@1735: Laurent@814: def RefreshVariablePanel(self): Laurent@814: if self.VariableEditor is not None: Laurent@814: self.VariableEditor.RefreshView() andrej@1735: Laurent@814: def GetConfNodeMenuItems(self): Laurent@814: return self.MenuItems andrej@1735: Laurent@814: def RefreshConfNodeMenu(self, confnode_menu): Laurent@814: pass andrej@1735: Laurent@814: def _Refresh(self, *args): Laurent@814: self.ParentWindow._Refresh(*args) Laurent@814: Laurent@814: def RefreshScaling(self, refresh=True): Laurent@814: pass Laurent@814: Laurent@814: def AddHighlight(self, infos, start, end, highlight_type): Laurent@814: if self.VariableEditor is not None and infos[0] in ["var_local", "var_input", "var_output", "var_inout"]: Laurent@814: self.VariableEditor.AddVariableHighlight(infos[1:], highlight_type) Laurent@814: Laurent@814: def RemoveHighlight(self, infos, start, end, highlight_type): Laurent@814: if self.VariableEditor is not None and infos[0] in ["var_local", "var_input", "var_output", "var_inout"]: Laurent@814: self.VariableEditor.RemoveVariableHighlight(infos[1:], highlight_type) andrej@1735: Laurent@814: def ClearHighlights(self, highlight_type=None): Laurent@814: if self.VariableEditor is not None: Laurent@814: self.VariableEditor.ClearHighlights(highlight_type)