etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor etisserant@0: #based on the plcopen standard. etisserant@0: # lbessard@58: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@5: #modify it under the terms of the GNU General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@58: #General Public License for more details. etisserant@0: # etisserant@5: #You should have received a copy of the GNU General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: from time import localtime etisserant@0: from datetime import datetime etisserant@0: import wx lbessard@64: import wx.grid etisserant@0: etisserant@0: from SFCViewer import * etisserant@0: from LDViewer import * etisserant@0: from Viewer import * lbessard@27: from TextViewer import * lbessard@27: from RessourceEditor import * etisserant@0: from PLCControler import * etisserant@0: from plcopen import OpenPDFDoc etisserant@0: etisserant@0: import os, re, platform, sys, time, traceback, getopt etisserant@0: etisserant@0: __version__ = "$Revision$" etisserant@0: etisserant@0: def create(parent): etisserant@0: return PLCOpenEditor(parent) etisserant@0: etisserant@0: def usage(): etisserant@0: print "\nUsage of PLCOpenEditor.py :" etisserant@0: print "\n %s [Filepath]\n"%sys.argv[0] etisserant@0: etisserant@0: try: etisserant@0: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) etisserant@0: except getopt.GetoptError: etisserant@0: # print help information and exit: etisserant@0: usage() etisserant@0: sys.exit(2) etisserant@0: etisserant@0: for o, a in opts: etisserant@0: if o in ("-h", "--help"): etisserant@0: usage() etisserant@0: sys.exit() etisserant@0: etisserant@0: fileOpen = None etisserant@0: if len(args) > 1: etisserant@0: usage() etisserant@0: sys.exit() etisserant@0: elif len(args) == 1: etisserant@0: fileOpen = args[0] lbessard@47: CWD = "" lbessard@47: for path in sys.path: lbessard@47: if os.path.isfile(os.path.join(path, "PLCOpenEditor.py")): lbessard@47: CWD = path etisserant@0: lbessard@64: [ID_PLCOPENEDITOR, ID_PLCOPENEDITORPROJECTTREE, lbessard@64: ID_PLCOPENEDITORSPLITTERWINDOW1, ID_PLCOPENEDITOREDITORPANEL, lbessard@64: ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTOOLBAR, lbessard@64: ID_PLCOPENEDITORDEFAULTTOOLBAR, ID_PLCOPENEDITORSFCTOOLBAR, lbessard@64: ID_PLCOPENEDITORFBDTOOLBAR, ID_PLCOPENEDITORLDTOOLBAR, lbessard@6: ] = [wx.NewId() for _init_ctrls in range(10)] lbessard@6: lbessard@64: [ID_PLCOPENEDITORFILEMENUITEMS0, ID_PLCOPENEDITORFILEMENUITEMS1, lbessard@64: ID_PLCOPENEDITORFILEMENUITEMS2, ID_PLCOPENEDITORFILEMENUITEMS3, lbessard@64: ID_PLCOPENEDITORFILEMENUITEMS5, ID_PLCOPENEDITORFILEMENUITEMS6, lbessard@64: ID_PLCOPENEDITORFILEMENUITEMS7, ID_PLCOPENEDITORFILEMENUITEMS9, lbessard@64: ID_PLCOPENEDITORFILEMENUITEMS11, etisserant@0: ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] etisserant@0: lbessard@64: [ID_PLCOPENEDITORHELPMENUITEMS0, ID_PLCOPENEDITORHELPMENUITEMS1, lbessard@64: ID_PLCOPENEDITORHELPMENUITEMS2, ID_PLCOPENEDITORHELPMENUITEMS3, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] etisserant@0: lbessard@64: [ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, lbessard@64: ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] etisserant@0: lbessard@64: [ID_PLCOPENEDITORCONFIGMENUITEMS0, ID_PLCOPENEDITORCONFIGMENUITEMS1, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] etisserant@0: lbessard@64: [ID_PLCOPENEDITOREDITMENUITEMS0, ID_PLCOPENEDITOREDITMENUITEMS1, lbessard@64: ID_PLCOPENEDITOREDITMENUITEMS11, ID_PLCOPENEDITOREDITMENUITEMS12, lbessard@64: ID_PLCOPENEDITOREDITMENUITEMS2, ID_PLCOPENEDITOREDITMENUITEMS4, lbessard@64: ID_PLCOPENEDITOREDITMENUITEMS5, ID_PLCOPENEDITOREDITMENUITEMS6, lbessard@64: ID_PLCOPENEDITOREDITMENUITEMS8, ID_PLCOPENEDITOREDITMENUITEMS9, etisserant@0: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)] etisserant@0: lbessard@64: [ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, lbessard@64: ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, etisserant@0: ] = [wx.NewId() for _init_coll_SFCMenu_Items in range(4)] etisserant@0: lbessard@64: [ID_PLCOPENEDITORCONFIGMENUITEMS0, ID_PLCOPENEDITORCONFIGMENUITEMS1, etisserant@0: ] = [wx.NewId() for _init_coll_ConfigMenu_Items in range(2)] etisserant@0: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # ToolBars definitions lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: lbessard@64: [ID_PLCOPENEDITORTOOLBARSELECTION, ID_PLCOPENEDITORTOOLBARCOMMENT, lbessard@64: ID_PLCOPENEDITORTOOLBARVARIABLE, ID_PLCOPENEDITORTOOLBARBLOCK, lbessard@64: ID_PLCOPENEDITORTOOLBARCONNECTION, ID_PLCOPENEDITORTOOLBARWIRE, lbessard@64: ID_PLCOPENEDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITORTOOLBARRUNG, lbessard@64: ID_PLCOPENEDITORTOOLBARCOIL, ID_PLCOPENEDITORTOOLBARCONTACT, lbessard@64: ID_PLCOPENEDITORTOOLBARBRANCH, ID_PLCOPENEDITORTOOLBARINITIALSTEP, lbessard@64: ID_PLCOPENEDITORTOOLBARSTEP, ID_PLCOPENEDITORTOOLBARTRANSITION, lbessard@64: ID_PLCOPENEDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITORTOOLBARDIVERGENCE, lbessard@64: ID_PLCOPENEDITORTOOLBARJUMP, lbessard@27: ] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(17)] lbessard@27: lbessard@27: ToolBarItems = { lbessard@64: "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), lbessard@64: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), lbessard@64: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), lbessard@64: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), lbessard@64: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], lbessard@64: "LD" : [(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "Images/powerrail.png", "Create a new power rail"), lbessard@64: (False, DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARRUNG, "OnRungTool", "Images/rung.png", "Create a new rung"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOIL, "OnCoilTool", "Images/coil.png", "Create a new coil"), lbessard@64: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "Images/contact.png", "Create a new contact"), lbessard@64: (False, DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBRANCH, "OnBranchTool", "Images/branch.png", "Create a new branch"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), lbessard@64: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], lbessard@64: "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), lbessard@64: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARINITIALSTEP, "OnInitialStepTool", "Images/initial_step.png", "Create a new initial step"), lbessard@64: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARSTEP, "OnStepTool", "Images/step.png", "Create a new step"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARTRANSITION, "OnTransitionTool", "Images/transition.png", "Create a new transition"), lbessard@64: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", "Images/action.png", "Create a new action block"), lbessard@64: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARDIVERGENCE, "OnDivergenceTool", "Images/divergence.png", "Create a new divergence"), lbessard@64: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARJUMP, "OnJumpTool", "Images/jump.png", "Create a new jump"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "Images/powerrail.png", "Create a new power rail"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "Images/contact.png", "Create a new contact"), lbessard@64: (True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], lbessard@27: "ST" : [], lbessard@27: "IL" : [] lbessard@27: } lbessard@27: etisserant@0: class PLCOpenEditor(wx.Frame): etisserant@0: _custom_classes = {'wx.SashWindow' : ['Viewer']} etisserant@0: etisserant@0: def _init_coll_EditMenu_Items(self, parent): lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') etisserant@0: parent.AppendSeparator() lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V') etisserant@0: parent.AppendSeparator() lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS8, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add POU') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS9, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove POU') etisserant@0: parent.AppendSeparator() lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS11, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Configuration') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS12, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Configuration') etisserant@0: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS0) lbessard@56: self.Bind(wx.EVT_MENU, self.OnUndoMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS1) lbessard@56: self.Bind(wx.EVT_MENU, self.OnRedoMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCutMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCopyMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS5) etisserant@0: self.Bind(wx.EVT_MENU, self.OnPasteMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS6) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPouMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS8) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS9) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS11) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, lbessard@64: id=ID_PLCOPENEDITOREDITMENUITEMS12) etisserant@0: etisserant@0: def _init_coll_menuBar1_Menus(self, parent): lbessard@47: if self.ModeSolo: lbessard@47: parent.Append(menu=self.FileMenu, title=u'File') etisserant@0: parent.Append(menu=self.EditMenu, title=u'Edit') etisserant@0: parent.Append(menu=self.HelpMenu, title=u'Help') etisserant@0: etisserant@0: def _init_coll_ConfigMenu_Items(self, parent): lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Resource') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Resource') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddResourceMenu, lbessard@64: id=ID_PLCOPENEDITORCONFIGMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, lbessard@64: id=ID_PLCOPENEDITORCONFIGMENUITEMS1) etisserant@0: etisserant@0: def _init_coll_HelpMenu_Items(self, parent): lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') lbessard@47: if self.ModeSolo: lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS3, lbessard@47: kind=wx.ITEM_NORMAL, text=u'About') etisserant@0: self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, lbessard@64: id=ID_PLCOPENEDITORHELPMENUITEMS1) etisserant@0: etisserant@0: def _init_coll_FileMenu_Items(self, parent): lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Close Project') etisserant@0: parent.AppendSeparator() lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS7, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G') etisserant@0: parent.AppendSeparator() lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS9, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Properties') etisserant@0: parent.AppendSeparator() lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS11, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') etisserant@0: self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS3) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS5) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS6) etisserant@0: self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS7) lbessard@27: self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS9) etisserant@0: self.Bind(wx.EVT_MENU, self.OnQuitMenu, lbessard@64: id=ID_PLCOPENEDITORFILEMENUITEMS11) etisserant@0: etisserant@0: def _init_coll_SFCMenu_Items(self, parent): lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Transition') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Action') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Transition') lbessard@64: parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Action') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu, lbessard@64: id=ID_PLCOPENEDITORSFCMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPouActionMenu, lbessard@64: id=ID_PLCOPENEDITORSFCMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemovePouTransitionMenu, lbessard@64: id=ID_PLCOPENEDITORSFCMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemovePouActionMenu, lbessard@64: id=ID_PLCOPENEDITORSFCMENUITEMS3) etisserant@0: etisserant@0: def _init_utils(self): etisserant@0: self.menuBar1 = wx.MenuBar() etisserant@0: lbessard@47: if self.ModeSolo: lbessard@47: self.FileMenu = wx.Menu(title=u'') lbessard@47: else: lbessard@47: self.FileMenu = None etisserant@0: self.EditMenu = wx.Menu(title=u'') etisserant@0: self.HelpMenu = wx.Menu(title='') etisserant@0: self.SFCMenu = wx.Menu(title='') etisserant@0: self.ConfigMenu = wx.Menu(title='') etisserant@0: etisserant@0: self._init_coll_menuBar1_Menus(self.menuBar1) lbessard@47: if self.ModeSolo: lbessard@47: self._init_coll_FileMenu_Items(self.FileMenu) etisserant@0: self._init_coll_EditMenu_Items(self.EditMenu) etisserant@0: self._init_coll_HelpMenu_Items(self.HelpMenu) etisserant@0: self._init_coll_SFCMenu_Items(self.SFCMenu) etisserant@0: self._init_coll_ConfigMenu_Items(self.ConfigMenu) etisserant@0: etisserant@0: def _init_coll_MainGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wx.GROW) etisserant@0: lbessard@6: def _init_coll_EditorGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.ToolBar, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.TabsOpened, 0, border=0, flag=wx.GROW) lbessard@6: etisserant@0: def _init_coll_MainGridSizer_Growables(self, parent): etisserant@0: parent.AddGrowableCol(0) etisserant@0: parent.AddGrowableRow(0) etisserant@0: lbessard@6: def _init_coll_EditorGridSizer_Growables(self, parent): lbessard@6: parent.AddGrowableCol(0) lbessard@6: parent.AddGrowableRow(1) lbessard@6: etisserant@0: def _init_sizers(self): etisserant@0: self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) lbessard@6: self.EditorGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@6: etisserant@0: self._init_coll_MainGridSizer_Growables(self.MainGridSizer) etisserant@0: self._init_coll_MainGridSizer_Items(self.MainGridSizer) lbessard@6: self._init_coll_EditorGridSizer_Growables(self.EditorGridSizer) lbessard@6: self._init_coll_EditorGridSizer_Items(self.EditorGridSizer) lbessard@6: etisserant@0: self.SetSizer(self.MainGridSizer) lbessard@6: self.EditorPanel.SetSizer(self.EditorGridSizer) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): lbessard@64: wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name=u'PLCOpenEditor', etisserant@0: parent=prnt, pos=wx.Point(235, 287), size=wx.Size(1000, 600), etisserant@0: style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor') etisserant@0: self._init_utils() etisserant@0: self.SetClientSize(wx.Size(1000, 600)) etisserant@0: self.SetMenuBar(self.menuBar1) lbessard@64: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_PLCOPENEDITOR) lbessard@64: lbessard@64: self.splitterWindow1 = wx.SplitterWindow(id=ID_PLCOPENEDITORSPLITTERWINDOW1, lbessard@7: name='splitterWindow1', parent=self, point=wx.Point(0, 0), lbessard@7: size=wx.Size(-1, -1), style=wx.SP_3D) lbessard@7: self.splitterWindow1.SetNeedUpdating(True) lbessard@7: self.splitterWindow1.SetMinimumPaneSize(1) lbessard@7: lbessard@64: self.EditorPanel = wx.Panel(id=ID_PLCOPENEDITOREDITORPANEL, lbessard@7: name='TabPanel', parent=self.splitterWindow1, pos=wx.Point(0, 0), lbessard@7: size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) lbessard@7: lbessard@64: self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED, lbessard@7: name='TabsOpened', parent=self.EditorPanel, pos=wx.Point(0, lbessard@7: 0), size=wx.Size(-1, -1), style=0) lbessard@7: self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, lbessard@64: self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED) lbessard@64: lbessard@64: self.ToolBar = wx.ToolBar(id=ID_PLCOPENEDITORTOOLBAR, name='ToolBar', lbessard@7: parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40), lbessard@64: style=wx.TB_HORIZONTAL | wx.NO_BORDER) lbessard@64: self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, lbessard@64: wx.Bitmap(os.path.join(CWD, 'Images/select.png')), wx.NullBitmap, "Select an object") lbessard@7: self.Bind(wx.EVT_TOOL, self.OnSelectionTool, lbessard@64: id=ID_PLCOPENEDITORTOOLBARSELECTION) lbessard@64: lbessard@64: self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE, lbessard@7: name='treeCtrl1', parent=self.splitterWindow1, pos=wx.Point(0, 0), lbessard@7: size=wx.Size(-1, -1), lbessard@7: style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) lbessard@27: self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) lbessard@7: self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag, lbessard@64: id=ID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, lbessard@64: id=ID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, lbessard@64: id=ID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, lbessard@64: id=ID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected, lbessard@64: id=ID_PLCOPENEDITORPROJECTTREE) lbessard@6: self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel, etisserant@0: 200) lbessard@47: etisserant@0: self._init_sizers() etisserant@0: lbessard@47: def __init__(self, parent, controler = None): lbessard@47: self.ModeSolo = controler == None etisserant@0: self._init_ctrls(parent) etisserant@0: lbessard@64: self.TreeImageList = wx.ImageList(16, 16) lbessard@9: for language in LANGUAGES: lbessard@64: self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images/%s.png'%language))) lbessard@9: self.ProjectTree.SetImageList(self.TreeImageList) lbessard@9: lbessard@47: if self.ModeSolo: lbessard@47: self.Controler = PLCControler() lbessard@47: else: lbessard@47: self.Controler = controler etisserant@0: lbessard@67: if self.ModeSolo and fileOpen: etisserant@0: self.Controler.OpenXMLFile(fileOpen) etisserant@0: self.RefreshProjectTree() lbessard@3: lbessard@6: self.CurrentToolBar = [] lbessard@27: self.CurrentLanguage = "" lbessard@71: self.DrawingMode = FREEDRAWING_MODE lbessard@71: #self.DrawingMode = DRIVENDRAWING_MODE lbessard@6: etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() lbessard@56: self.RefreshTitle() etisserant@0: self.RefreshToolBar() etisserant@0: lbessard@27: def GetDrawingMode(self): lbessard@27: return self.DrawingMode lbessard@27: lbessard@56: def RefreshTitle(self): lbessard@56: if self.Controler.HasOpenedProject() > 0: lbessard@56: self.SetTitle("PLCOpenEditor - %s"%self.Controler.GetFilename()) lbessard@56: else: lbessard@56: self.SetTitle("PLCOpenEditor") lbessard@56: etisserant@0: def RefreshFileMenu(self): lbessard@9: if self.FileMenu: lbessard@9: if self.Controler.HasOpenedProject(): lbessard@9: if self.TabsOpened.GetPageCount() > 0: lbessard@9: self.FileMenu.FindItemByPosition(2).Enable(True) lbessard@9: else: lbessard@9: self.FileMenu.FindItemByPosition(2).Enable(False) lbessard@9: self.FileMenu.FindItemByPosition(3).Enable(True) lbessard@9: self.FileMenu.FindItemByPosition(5).Enable(True) lbessard@9: self.FileMenu.FindItemByPosition(6).Enable(True) lbessard@9: self.FileMenu.FindItemByPosition(7).Enable(True) lbessard@9: self.FileMenu.FindItemByPosition(9).Enable(True) etisserant@0: else: etisserant@0: self.FileMenu.FindItemByPosition(2).Enable(False) lbessard@9: self.FileMenu.FindItemByPosition(3).Enable(False) lbessard@9: self.FileMenu.FindItemByPosition(5).Enable(False) lbessard@9: self.FileMenu.FindItemByPosition(6).Enable(False) lbessard@9: self.FileMenu.FindItemByPosition(7).Enable(False) lbessard@9: self.FileMenu.FindItemByPosition(9).Enable(False) etisserant@0: etisserant@0: def RefreshEditMenu(self): lbessard@9: if self.EditMenu: lbessard@56: if self.Controler.HasOpenedProject(): lbessard@56: undo, redo = self.Controler.GetBufferState() lbessard@64: self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, undo) lbessard@64: self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, redo) lbessard@56: else: lbessard@64: self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, False) lbessard@64: self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, False) lbessard@9: if self.Controler.HasOpenedProject(): lbessard@9: if self.TabsOpened.GetPageCount() > 0: lbessard@9: self.EditMenu.FindItemByPosition(0).Enable(True) lbessard@9: else: lbessard@9: self.EditMenu.FindItemByPosition(0).Enable(False) lbessard@9: self.EditMenu.FindItemByPosition(8).Enable(True) lbessard@9: self.EditMenu.FindItemByPosition(9).Enable(True) etisserant@0: else: etisserant@0: self.EditMenu.FindItemByPosition(0).Enable(False) lbessard@9: self.EditMenu.FindItemByPosition(8).Enable(False) lbessard@9: self.EditMenu.FindItemByPosition(9).Enable(False) lbessard@9: bodytype = self.Controler.GetCurrentElementEditingBodyType() lbessard@9: if bodytype in ["IL","ST"]: lbessard@9: self.EditMenu.FindItemByPosition(4).Enable(True) lbessard@9: self.EditMenu.FindItemByPosition(5).Enable(True) lbessard@9: self.EditMenu.FindItemByPosition(6).Enable(True) lbessard@9: else: lbessard@9: self.EditMenu.FindItemByPosition(4).Enable(False) lbessard@9: self.EditMenu.FindItemByPosition(5).Enable(False) etisserant@0: self.EditMenu.FindItemByPosition(6).Enable(False) etisserant@0: lbessard@67: def RefreshEditor(self): lbessard@67: selected = self.TabsOpened.GetSelection() lbessard@67: if selected != -1: lbessard@67: self.TabsOpened.GetPage(selected).RefreshView() lbessard@67: lbessard@27: def ShowProperties(self): lbessard@27: old_values = self.Controler.GetProjectProperties() lbessard@27: dialog = ProjectDialog(self) lbessard@27: dialog.SetValues(old_values) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@27: new_values = dialog.GetValues() lbessard@27: projectname = new_values.pop("projectName") lbessard@27: new_values["creationDateTime"] = old_values["creationDateTime"] lbessard@56: self.Controler.SetProjectProperties(projectname, new_values) lbessard@27: self.RefreshProjectTree() lbessard@27: dialog.Destroy() lbessard@27: lbessard@56: def OnCloseFrame(self, event): lbessard@56: if not self.Controler.ProjectIsSaved(): lbessard@64: dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) lbessard@56: answer = dialog.ShowModal() lbessard@56: dialog.Destroy() lbessard@64: if answer == wx.ID_YES: lbessard@56: self.SaveProject() lbessard@56: event.Skip() lbessard@64: elif answer == wx.ID_NO: lbessard@56: event.Skip() lbessard@56: else: lbessard@56: event.Skip() lbessard@56: etisserant@0: def OnNewProjectMenu(self, event): etisserant@0: dialog = ProjectDialog(self) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: values = dialog.GetValues() etisserant@0: projectname = values.pop("projectName") etisserant@0: values["creationDateTime"] = datetime(*localtime()[:6]) etisserant@0: self.Controler.CreateNewProject(projectname) lbessard@56: self.Controler.SetProjectProperties(projectname, values) lbessard@56: self.RefreshTitle() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshProjectTree() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnOpenProjectMenu(self, event): etisserant@0: filepath = self.Controler.GetFilePath() etisserant@0: if filepath != "": etisserant@0: directory = os.path.dirname(filepath) etisserant@0: else: etisserant@0: directory = os.getcwd() lbessard@64: dialog = wx.FileDialog(self, "Choose a file", directory, "", "PLCOpen files (*.xml)|*.xml|All files|*.*", wx.OPEN) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isfile(filepath): etisserant@0: self.Controler.OpenXMLFile(filepath) etisserant@0: self.TabsOpened.DeleteAllPages() etisserant@0: self.RefreshProjectTree() lbessard@56: self.RefreshTitle() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCloseTabMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected >= 0: etisserant@0: self.Controler.CloseElementEditing() etisserant@0: self.TabsOpened.DeletePage(selected) etisserant@0: if self.TabsOpened.GetPageCount() > 0: etisserant@0: self.TabsOpened.SetSelection(min(selected, self.TabsOpened.GetPageCount() - 1)) lbessard@56: self.RefreshTitle() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCloseProjectMenu(self, event): etisserant@0: self.Controler.Reset() etisserant@0: self.TabsOpened.DeleteAllPages() etisserant@0: self.ProjectTree.DeleteAllItems() lbessard@56: self.RefreshTitle() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSaveProjectMenu(self, event): etisserant@0: self.SaveProject() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSaveProjectAsMenu(self, event): etisserant@0: self.SaveProjectAs() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnGenerateProgramMenu(self, event): lbessard@64: dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), self.Controler.GetProgramFilePath(), "ST files (*.st)|*.st|All files|*.*", wx.SAVE|wx.CHANGE_DIR) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@4: filepath = dialog.GetPath() lbessard@4: if os.path.isdir(os.path.dirname(filepath)): lbessard@4: result = self.Controler.GenerateProgram(filepath) lbessard@4: if not result: lbessard@64: message = wx.MessageDialog(self, "Can't generate program to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR) lbessard@4: message.ShowModal() lbessard@4: message.Destroy() lbessard@67: else: lbessard@67: message = wx.MessageDialog(self, "Program was successfully generated!", "Done", wx.OK|wx.ICON_INFORMATION) lbessard@67: message.ShowModal() lbessard@67: message.Destroy() lbessard@4: else: lbessard@64: message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) lbessard@4: message.ShowModal() lbessard@4: message.Destroy() lbessard@4: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def SaveProject(self): etisserant@0: result = self.Controler.SaveXMLFile() etisserant@0: if not result: etisserant@0: self.SaveProjectAs() lbessard@56: else: lbessard@56: self.RefreshTitle() etisserant@0: etisserant@0: def SaveProjectAs(self): etisserant@0: filepath = self.Controler.GetFilePath() etisserant@0: if filepath != "": etisserant@0: directory, filename = os.path.split(filepath) etisserant@0: else: lbessard@56: directory, filename = os.getcwd(), "%(projectName)s.xml"%self.Controler.GetProjectProperties() lbessard@64: dialog = wx.FileDialog(self, "Choose a file", directory, filename, "PLCOpen files (*.xml)|*.xml|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isdir(os.path.dirname(filepath)): etisserant@0: result = self.Controler.SaveXMLFile(filepath) etisserant@0: if not result: lbessard@64: message = wx.MessageDialog(self, "Can't save project to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: lbessard@64: message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@56: self.RefreshTitle() etisserant@0: dialog.Destroy() etisserant@0: lbessard@27: def OnPropertiesMenu(self, event): lbessard@27: self.ShowProperties() lbessard@27: event.Skip() lbessard@27: etisserant@0: def OnQuitMenu(self, event): lbessard@6: self.ToolBar.Reparent(self) lbessard@6: self.Controler.Reset() etisserant@0: self.Close() etisserant@0: event.Skip() etisserant@0: lbessard@3: def ResetCurrentMode(self): lbessard@3: selected = self.TabsOpened.GetSelection() lbessard@3: if selected != -1: lbessard@6: window = self.TabsOpened.GetPage(selected) lbessard@47: window.SetMode(MODE_SELECTION) lbessard@64: self.ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True) lbessard@6: lbessard@6: def ResetToolToggle(self, id): lbessard@6: tool = self.ToolBar.FindById(id) lbessard@6: tool.SetToggle(False) lbessard@3: etisserant@0: def OnSelectionTool(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).SetMode(MODE_SELECTION) etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnCommentTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT) etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT) etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnVariableTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE) etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE) etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnBlockTool(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK) etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnConnectionTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION) etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION) etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnWireTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARWIRE) lbessard@6: selected = self.TabsOpened.GetSelection() lbessard@6: if selected != -1: lbessard@6: self.TabsOpened.GetPage(selected).SetMode(MODE_WIRE) lbessard@6: event.Skip() lbessard@6: lbessard@27: def OnPowerRailTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnRungTool(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddLadderRung() etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnCoilTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOIL) etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_COIL) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnContactTool(self, event): lbessard@27: if self.DrawingMode == FREEDRAWING_MODE: lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONTACT) etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@27: if self.DrawingMode == FREEDRAWING_MODE: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_CONTACT) lbessard@27: else: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddLadderContact() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnBranchTool(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddLadderBranch() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnInitialStepTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnStepTool(self, event): lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARSTEP) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_STEP) lbessard@27: else: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddStep() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnActionBlockTool(self, event): lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_ACTION) lbessard@27: else: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddStepAction() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnTransitionTool(self, event): lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDivergenceTool(self, event): lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_DIVERGENCE) lbessard@27: else: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddDivergence() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnJumpTool(self, event): lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@64: self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARJUMP) lbessard@27: selected = self.TabsOpened.GetSelection() lbessard@27: if selected != -1: lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.TabsOpened.GetPage(selected).SetMode(MODE_JUMP) lbessard@27: else: lbessard@47: self.TabsOpened.GetPage(selected).Viewer.AddJump() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnPouSelectedChanged(self, event): lbessard@56: old_selected = self.TabsOpened.GetSelection() lbessard@56: if old_selected >= 0: lbessard@56: self.TabsOpened.GetPage(old_selected).ResetBuffer() etisserant@0: selected = event.GetSelection() etisserant@0: if selected >= 0: etisserant@0: self.Controler.RefreshCurrentElementEditing(selected) etisserant@0: found = False etisserant@0: name = self.TabsOpened.GetPageText(selected) etisserant@0: root = self.ProjectTree.GetRootItem() etisserant@0: item, root_cookie = self.ProjectTree.GetFirstChild(root) etisserant@0: while item.IsOk() and not found: etisserant@0: if self.ProjectTree.GetItemText(item) == name: etisserant@0: self.ProjectTree.SelectItem(item) etisserant@0: item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) lbessard@47: self.TabsOpened.GetPage(selected).RefreshView() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: event.Skip() etisserant@0: lbessard@7: def OnProjectTreeBeginDrag(self, event): lbessard@7: item = event.GetItem() lbessard@47: if self.ProjectTree.GetPyData(item) == ITEM_POU: lbessard@47: block_name = self.ProjectTree.GetItemText(item) lbessard@47: block_type = self.Controler.GetPouType(block_name) lbessard@53: if block_type != "program": lbessard@64: data = wx.TextDataObject(str((block_name, block_type, ""))) lbessard@64: dragSource = wx.DropSource(self.ProjectTree) lbessard@53: dragSource.SetData(data) lbessard@53: dragSource.DoDragDrop() lbessard@7: etisserant@0: def OnProjectTreeItemEndEdit(self, event): lbessard@6: message = None lbessard@6: abort = False etisserant@0: new_name = event.GetLabel() etisserant@0: if new_name != "": lbessard@6: if not TestIdentifier(new_name): lbessard@6: message = "\"%s\" is not a valid identifier!"%new_name lbessard@6: elif new_name.upper() in IEC_KEYWORDS: lbessard@6: message = "\"%s\" is a keyword. It can't be used!"%new_name lbessard@6: else: etisserant@0: item = event.GetItem() etisserant@0: itemtype = self.ProjectTree.GetPyData(item) etisserant@0: if itemtype == ITEM_PROJECT: lbessard@56: self.Controler.SetProjectProperties(name = new_name) etisserant@0: elif itemtype == ITEM_POU: lbessard@70: if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: lbessard@6: message = "\"%s\" pou already exists!"%new_name lbessard@6: abort = True lbessard@70: elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: lbessard@64: messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) lbessard@64: if messageDialog.ShowModal() == wx.ID_NO: lbessard@6: abort = True lbessard@6: messageDialog.Destroy() lbessard@6: if not abort: lbessard@6: old_name = self.ProjectTree.GetItemText(item) lbessard@6: self.Controler.ChangePouName(old_name, new_name) lbessard@6: self.RefreshTabsOpenedTitles() etisserant@0: elif itemtype == ITEM_TRANSITION: lbessard@6: category = self.ProjectTree.GetItemParent(item) lbessard@6: pou = self.ProjectTree.GetItemParent(category) lbessard@6: pou_name = self.ProjectTree.GetItemText(pou) lbessard@70: if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: lbessard@6: message = "A pou with \"%s\" as name exists!"%new_name lbessard@70: elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name)]: lbessard@6: message = "A variable with \"%s\" as name already exists in this pou!"%new_name lbessard@6: else: lbessard@6: old_name = self.ProjectTree.GetItemText(item) lbessard@6: self.Controler.ChangePouTransitionName(pou_name, old_name, new_name) lbessard@6: self.RefreshTabsOpenedTitles() etisserant@0: elif itemtype == ITEM_ACTION: lbessard@6: category = self.ProjectTree.GetItemParent(item) lbessard@6: pou = self.ProjectTree.GetItemParent(category) lbessard@6: pou_name = self.ProjectTree.GetItemText(pou) lbessard@70: if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: lbessard@6: message = "A pou with \"%s\" as name exists!"%new_name lbessard@70: elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name)]: lbessard@6: message = "A variable with \"%s\" as name already exists in this pou!"%new_name lbessard@6: else: lbessard@6: old_name = self.ProjectTree.GetItemText(item) lbessard@6: self.Controler.ChangePouActionName(pou_name, old_name, new_name) lbessard@6: self.RefreshTabsOpenedTitles() lbessard@6: if message or abort: lbessard@6: if message: lbessard@64: messageDialog = wx.MessageDialog(self, message, "Error", wx.OK|wx.ICON_ERROR) lbessard@6: messageDialog.ShowModal() lbessard@6: messageDialog.Destroy() etisserant@0: item = event.GetItem() lbessard@64: wx.CallAfter(self.ProjectTree.EditLabel, item) etisserant@0: event.Veto() lbessard@6: else: lbessard@64: wx.CallAfter(self.RefreshProjectTree) lbessard@6: event.Skip() etisserant@0: etisserant@0: def OnProjectTreeItemBeginEdit(self, event): etisserant@0: selected = event.GetItem() etisserant@0: if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: etisserant@0: event.Veto() etisserant@0: else: etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnProjectTreeItemActivated(self, event): etisserant@0: selected = event.GetItem() etisserant@0: if self.ProjectTree.IsExpanded(selected): etisserant@0: self.ProjectTree.Collapse(selected) etisserant@0: else: etisserant@0: self.ProjectTree.Expand(selected) etisserant@0: name = self.ProjectTree.GetItemText(selected) etisserant@0: data = self.ProjectTree.GetPyData(selected) etisserant@0: if name == "Properties": lbessard@27: self.ShowProperties() lbessard@47: elif data in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION, ITEM_RESOURCE, ITEM_CONFIGURATION]: lbessard@47: if data == ITEM_CONFIGURATION: lbessard@47: idx = self.Controler.OpenConfigurationEditing(name) lbessard@47: if idx != None: lbessard@47: new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "config", config_name = name) lbessard@47: self.TabsOpened.AddPage(new_window, "") lbessard@47: else: lbessard@47: idx = self.Controler.ChangeConfigurationEditing(name) lbessard@47: elif data == ITEM_RESOURCE: lbessard@47: item = self.ProjectTree.GetItemParent(selected) etisserant@0: item_type = self.ProjectTree.GetPyData(item) lbessard@47: while item_type != ITEM_CONFIGURATION: lbessard@47: item = self.ProjectTree.GetItemParent(item) lbessard@47: item_type = self.ProjectTree.GetPyData(item) lbessard@47: config_name = self.ProjectTree.GetItemText(item) lbessard@47: idx = self.Controler.OpenConfigurationResourceEditing(config_name, name) lbessard@47: if idx != None: lbessard@47: new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "resource", config_name = config_name, resource_name = name) lbessard@47: self.TabsOpened.AddPage(new_window, "") lbessard@47: else: lbessard@47: idx = self.Controler.ChangeConfigurationResourceEditing(config_name, name) lbessard@47: elif data == ITEM_POU: etisserant@0: idx = self.Controler.OpenElementEditing(name) lbessard@47: if idx != None: lbessard@47: new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, self.Controler.GetPouType(name), pou_name = name) lbessard@47: self.TabsOpened.AddPage(new_window, "") lbessard@47: else: lbessard@47: idx = self.Controler.ChangeElementEditing(name) etisserant@0: else: etisserant@0: parent = self.ProjectTree.GetItemParent(selected) etisserant@0: parent_name = self.ProjectTree.GetItemText(parent) etisserant@0: grandparent = self.ProjectTree.GetItemParent(parent) etisserant@0: grandparent_name = self.ProjectTree.GetItemText(grandparent) etisserant@0: if data == ITEM_TRANSITION: etisserant@0: idx = self.Controler.OpenPouTransitionEditing(grandparent_name, name) lbessard@47: if idx != None: lbessard@47: new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "transition", pou_name = grandparent_name, transition_name = name) lbessard@47: self.TabsOpened.AddPage(new_window, "") lbessard@47: else: lbessard@47: idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) etisserant@0: elif data == ITEM_ACTION: etisserant@0: idx = self.Controler.OpenPouActionEditing(grandparent_name, name) lbessard@47: if idx != None: lbessard@47: new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "action", pou_name = grandparent_name, action_name = name) lbessard@47: self.TabsOpened.AddPage(new_window, "") lbessard@47: else: lbessard@47: idx = self.Controler.ChangePouActionEditing(grandparent_name, name) etisserant@0: if idx != None: lbessard@56: old_selected = self.TabsOpened.GetSelection() lbessard@56: if old_selected >= 0: lbessard@56: self.TabsOpened.GetPage(old_selected).ResetBuffer() etisserant@0: self.TabsOpened.SetSelection(idx) lbessard@47: window = self.TabsOpened.GetPage(idx) lbessard@47: window.RefreshView() etisserant@0: self.RefreshTabsOpenedTitles() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: etisserant@0: def OnProjectTreeRightUp(self, event): etisserant@0: selected = self.ProjectTree.GetSelection() etisserant@0: if self.ProjectTree.GetPyData(selected) == ITEM_POU: etisserant@0: name = self.ProjectTree.GetItemText(selected) etisserant@0: if self.Controler.GetPouBodyType(name) == "SFC": etisserant@0: self.PopupMenu(self.SFCMenu) etisserant@0: elif self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: etisserant@0: self.PopupMenu(self.ConfigMenu) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnProjectTreeItemSelected(self, event): etisserant@0: selected = event.GetItem() etisserant@0: name = self.ProjectTree.GetItemText(selected) etisserant@0: if self.ProjectTree.GetItemParent(selected) == self.ProjectTree.GetRootItem() and name != "Properties": etisserant@0: if self.Controler.IsElementEditing(name): etisserant@0: idx = self.Controler.ChangeElementEditing(name) etisserant@0: if idx != None: etisserant@0: self.TabsOpened.SetSelection(idx) etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: else: etisserant@0: name = self.ProjectTree.GetItemText(selected) etisserant@0: parent = self.ProjectTree.GetItemParent(selected) etisserant@0: parent_name = self.ProjectTree.GetItemText(parent) etisserant@0: grandparent = self.ProjectTree.GetItemParent(parent) etisserant@0: grandparent_name = self.ProjectTree.GetItemText(grandparent) etisserant@0: if parent_name == "Transitions": etisserant@0: idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) etisserant@0: if idx != None: etisserant@0: self.TabsOpened.SetSelection(idx) etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: elif parent_name == "Action": etisserant@0: idx = self.Controler.ChangePouActionEditing(grandparent_name, name) etisserant@0: if idx != None: etisserant@0: self.TabsOpened.SetSelection(idx) etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: event.Skip() etisserant@0: etisserant@0: def RefreshProjectTree(self): etisserant@0: infos = self.Controler.GetProjectInfos() etisserant@0: root = self.ProjectTree.GetRootItem() etisserant@0: self.GenerateTreeBranch(root, infos) etisserant@0: self.ProjectTree.Expand(self.ProjectTree.GetRootItem()) etisserant@0: etisserant@0: def GenerateTreeBranch(self, root, infos): etisserant@0: to_delete = [] etisserant@0: if root.IsOk(): etisserant@0: self.ProjectTree.SetItemText(root, infos["name"]) etisserant@0: else: etisserant@0: root = self.ProjectTree.AddRoot(infos["name"]) etisserant@0: self.ProjectTree.SetPyData(root, infos["type"]) lbessard@9: if infos["type"] == ITEM_POU: lbessard@9: self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"]))) etisserant@0: item, root_cookie = self.ProjectTree.GetFirstChild(root) etisserant@0: if len(infos["values"]) > 0: etisserant@0: for values in infos["values"]: etisserant@0: if not item.IsOk(): etisserant@0: item = self.ProjectTree.AppendItem(root, "") etisserant@0: item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) etisserant@0: self.GenerateTreeBranch(item, values) etisserant@0: item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) etisserant@0: while item.IsOk(): etisserant@0: to_delete.append(item) lbessard@27: item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) etisserant@0: for item in to_delete: etisserant@0: self.ProjectTree.Delete(item) lbessard@27: lbessard@6: def ResetToolBar(self): lbessard@6: for item in self.CurrentToolBar: lbessard@27: self.Unbind(wx.EVT_MENU, id=item) lbessard@6: self.ToolBar.DeleteTool(item) lbessard@6: etisserant@0: def RefreshToolBar(self): etisserant@0: language = self.Controler.GetCurrentElementEditingBodyType() lbessard@27: if language and language != self.CurrentLanguage: lbessard@27: self.ResetToolBar() lbessard@27: self.CurrentLanguage = language lbessard@27: self.CurrentToolBar = [] lbessard@27: for radio, modes, id, method, picture, help in ToolBarItems[language]: lbessard@27: if modes & self.DrawingMode: lbessard@27: if radio or self.DrawingMode == FREEDRAWING_MODE: lbessard@64: self.ToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, picture)), wx.NullBitmap, help) lbessard@27: else: lbessard@64: self.ToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, picture)), help) lbessard@27: self.Bind(wx.EVT_TOOL, getattr(self, method), id=id) lbessard@27: self.CurrentToolBar.append(id) lbessard@3: self.ResetCurrentMode() etisserant@0: etisserant@0: def RefreshTabsOpenedTitles(self): etisserant@0: pous = self.Controler.GetElementsOpenedNames() etisserant@0: for i, pou in enumerate(pous): etisserant@0: self.TabsOpened.SetPageText(i, pou) etisserant@0: etisserant@0: def OnRefreshMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@56: self.TabsOpened.GetPage(selected).RefreshView() etisserant@0: self.TabsOpened.GetPage(selected).Refresh() etisserant@0: event.Skip() lbessard@56: lbessard@56: def OnUndoMenu(self, event): lbessard@56: self.Controler.LoadPrevious() lbessard@56: selected = self.TabsOpened.GetSelection() lbessard@56: if selected != -1: lbessard@56: self.TabsOpened.GetPage(selected).RefreshView() lbessard@56: self.TabsOpened.GetPage(selected).Refresh() lbessard@56: self.RefreshTitle() lbessard@56: self.RefreshEditMenu() lbessard@56: event.Skip() lbessard@56: lbessard@56: def OnRedoMenu(self, event): lbessard@56: self.Controler.LoadNext() lbessard@56: selected = self.TabsOpened.GetSelection() lbessard@56: if selected != -1: lbessard@56: self.TabsOpened.GetPage(selected).RefreshView() lbessard@56: self.TabsOpened.GetPage(selected).Refresh() lbessard@56: self.RefreshTitle() lbessard@56: self.RefreshEditMenu() lbessard@56: event.Skip() lbessard@56: etisserant@0: def OnCutMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@51: try: lbessard@51: self.TabsOpened.GetPage(selected).Viewer.Cut() lbessard@51: except: lbessard@51: pass etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCopyMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@51: try: lbessard@51: self.TabsOpened.GetPage(selected).Viewer.Copy() lbessard@51: except: lbessard@51: pass etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnPasteMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: lbessard@51: try: lbessard@51: self.TabsOpened.GetPage(selected).Viewer.Paste() lbessard@51: except: lbessard@51: pass etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPouMenu(self, event): etisserant@0: dialog = PouDialog(self) etisserant@0: dialog.SetPouNames(self.Controler.GetProjectPouNames()) lbessard@70: dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: values = dialog.GetValues() etisserant@0: self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"]) etisserant@0: self.RefreshProjectTree() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemovePouMenu(self, event): etisserant@0: pous = self.Controler.GetProjectPouNames() lbessard@64: dialog = wx.SingleChoiceDialog(self, "Select POU to remove:", "POU Remove", pous, wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: selected = dialog.GetStringSelection() etisserant@0: if not self.Controler.PouIsUsed(selected): etisserant@0: self.Controler.ProjectRemovePou(selected) lbessard@56: deleted = None etisserant@0: for i in xrange(self.TabsOpened.GetPageCount()): etisserant@0: if self.TabsOpened.GetPageText(i) == selected: lbessard@56: deleted = i lbessard@56: if deleted != None: lbessard@56: self.TabsOpened.DeletePage(i) etisserant@0: self.RefreshProjectTree() etisserant@0: self.RefreshToolBar() etisserant@0: else: lbessard@64: message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddConfigurationMenu(self, event): lbessard@64: dialog = wx.TextEntryDialog(self, "Enter configuration name:", "Create new configuration", "", wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: value = dialog.GetValue() etisserant@0: self.Controler.ProjectAddConfiguration(value) etisserant@0: self.RefreshProjectTree() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemoveConfigurationMenu(self, event): etisserant@0: configs = self.Controler.GetProjectConfigNames() lbessard@64: dialog = wx.SingleChoiceDialog(self, "Select Configuration to remove:", "Remove configuration", configs, wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: selected = dialog.GetStringSelection() etisserant@0: self.Controler.ProjectRemoveConfiguration(selected) etisserant@0: self.RefreshProjectTree() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPouTransitionMenu(self, event): lbessard@45: selected = self.ProjectTree.GetSelection() lbessard@45: if self.ProjectTree.GetPyData(selected) == ITEM_POU: lbessard@45: pouname = self.ProjectTree.GetItemText(selected) lbessard@45: if self.Controler.GetPouBodyType(pouname) == "SFC": lbessard@45: dialog = PouTransitionDialog(self) lbessard@70: dialog.SetPouNames(self.Controler.GetProjectPouNames()) lbessard@70: dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname)) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@45: values = dialog.GetValues() lbessard@45: self.Controler.ProjectAddPouTransition(pouname, values["transitionName"], values["language"]) lbessard@45: self.RefreshProjectTree() lbessard@45: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemovePouTransitionMenu(self, event): lbessard@46: selected = self.ProjectTree.GetSelection() lbessard@46: if self.ProjectTree.GetPyData(selected) == ITEM_POU: lbessard@46: pouname = self.ProjectTree.GetItemText(selected) lbessard@46: if self.Controler.GetPouBodyType(pouname) == "SFC": lbessard@46: transitions = self.Controler.GetPouTransitions(pouname) lbessard@64: dialog = wx.SingleChoiceDialog(self, "Select Transition to remove:", "Remove transition", transitions, wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@46: selected = dialog.GetStringSelection() lbessard@46: self.Controler.ProjectRemovePouTransition(pouname, selected) lbessard@46: self.RefreshProjectTree() lbessard@46: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPouActionMenu(self, event): lbessard@45: selected = self.ProjectTree.GetSelection() lbessard@45: if self.ProjectTree.GetPyData(selected) == ITEM_POU: lbessard@45: pouname = self.ProjectTree.GetItemText(selected) lbessard@45: if self.Controler.GetPouBodyType(pouname) == "SFC": lbessard@45: dialog = PouActionDialog(self) lbessard@70: dialog.SetPouNames(self.Controler.GetProjectPouNames()) lbessard@70: dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname)) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@45: values = dialog.GetValues() lbessard@45: self.Controler.ProjectAddPouAction(pouname, values["actionName"], values["language"]) lbessard@45: self.RefreshProjectTree() lbessard@45: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemovePouActionMenu(self, event): lbessard@46: selected = self.ProjectTree.GetSelection() lbessard@46: if self.ProjectTree.GetPyData(selected) == ITEM_POU: lbessard@46: pouname = self.ProjectTree.GetItemText(selected) lbessard@46: if self.Controler.GetPouBodyType(pouname) == "SFC": lbessard@46: actions = self.Controler.GetPouActions(pouname) lbessard@64: dialog = wx.SingleChoiceDialog(self, "Select Action to remove:", "Remove action", actions, wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@46: selected = dialog.GetStringSelection() lbessard@46: self.Controler.ProjectRemovePouAction(pouname, selected) lbessard@46: self.RefreshProjectTree() lbessard@46: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddResourceMenu(self, event): etisserant@0: selected = self.ProjectTree.GetSelection() etisserant@0: if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: etisserant@0: config_name = self.ProjectTree.GetItemText(selected) lbessard@64: dialog = wx.TextEntryDialog(self, "Enter Resource name:", "Create new Resource", "", wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: value = dialog.GetValue() etisserant@0: self.Controler.ProjectAddConfigurationResource(config_name, value) etisserant@0: self.RefreshProjectTree() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemoveResourceMenu(self, event): etisserant@0: selected = self.ProjectTree.GetSelection() etisserant@0: if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: etisserant@0: config_name = self.ProjectTree.GetItemText(selected) etisserant@0: infos = self.Controler.GetProjectInfos() etisserant@0: resources = [] etisserant@0: for config in infos["configs"]: etisserant@0: if config["name"] == config_name: etisserant@0: resources = config["resources"] lbessard@64: dialog = wx.SingleChoiceDialog(self, "Select Resource to remove:", "Remove resource", resources, wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: etisserant@0: resource = dialog.GetStringSelection() etisserant@0: self.Controler.ProjectRemoveConfigurationResource(config_name, resource) etisserant@0: self.RefreshProjectTree() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnPLCOpenMenu(self, event): etisserant@0: result = OpenPDFDoc() etisserant@0: if type(result) == StringType: lbessard@64: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: current_num = 0 etisserant@0: def GetNewNum(): etisserant@0: global current_num etisserant@0: current_num += 1 etisserant@0: return current_num etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create Project Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@64: [ID_PROJECTDIALOG, ID_PROJECTDIALOGPROJECTNAME, lbessard@64: ID_PROJECTDIALOGCOMPANYNAME, ID_PROJECTDIALOGCOMPANYURL, lbessard@64: ID_PROJECTDIALOGPRODUCTNAME, ID_PROJECTDIALOGPRODUCTVERSION, lbessard@64: ID_PROJECTDIALOGPRODUCTRELEASE, ID_PROJECTDIALOGCONTENTDESCRIPTION, lbessard@64: ID_PROJECTDIALOGSTATICTEXT1, ID_PROJECTDIALOGSTATICTEXT2, lbessard@64: ID_PROJECTDIALOGSTATICTEXT3, ID_PROJECTDIALOGSTATICTEXT4, lbessard@64: ID_PROJECTDIALOGSTATICTEXT5, ID_PROJECTDIALOGSTATICTEXT6, lbessard@64: ID_PROJECTDIALOGSTATICTEXT7, lbessard@64: ] = [wx.NewId() for _init_ctrls in range(15)] etisserant@0: etisserant@0: class ProjectDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ProjectName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.CompanyName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.CompanyURL, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ProductName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ProductVersion, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText6, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ProductRelease, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText7, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ContentDescription, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_MainSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(1) lbessard@64: parent.AddGrowableRow(6) lbessard@64: etisserant@0: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=7, vgap=15) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@64: self._init_coll_MainSizer_Growables(self.MainSizer) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): lbessard@64: wx.Dialog.__init__(self, id=ID_PROJECTDIALOG, etisserant@0: name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(550, 450), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Create a new project') etisserant@0: self.SetClientSize(wx.Size(550, 450)) etisserant@0: lbessard@64: self.staticText1 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT1, lbessard@64: label='Project Name (required):', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.ProjectName = wx.TextCtrl(id=ID_PROJECTDIALOGPROJECTNAME, lbessard@64: name='ProjectName', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText2 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT2, lbessard@64: label='Company Name (required):', name='staticText2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.CompanyName = wx.TextCtrl(id=ID_PROJECTDIALOGCOMPANYNAME, lbessard@64: name='CompanyName', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText3 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT3, lbessard@64: label='Company URL (optional):', name='staticText3', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.CompanyURL = wx.TextCtrl(id=ID_PROJECTDIALOGCOMPANYURL, lbessard@64: name='CompanyURL', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText4 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT4, lbessard@64: label='Product Name (required):', name='staticText4', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.ProductName = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTNAME, lbessard@64: name='ProductName', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText5 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT5, lbessard@64: label='Product Version (required):', name='staticText5', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.ProductVersion = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTVERSION, lbessard@64: name='ProductVersion', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText6 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT6, lbessard@64: label='Product Release (optional):', name='staticText6', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.ProductRelease = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTRELEASE, lbessard@64: name='ProductRelease', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText7 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT7, lbessard@64: label='Content Description (optional):', name='staticText7', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) lbessard@64: lbessard@64: self.ContentDescription = wx.TextCtrl(id=ID_PROJECTDIALOGCONTENTDESCRIPTION, lbessard@64: name='ProductRelease', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 120), style=wx.TE_MULTILINE) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@64: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@64: etisserant@0: def OnOK(self, event): etisserant@0: error = [] etisserant@0: if self.ProjectName.GetValue() == "": etisserant@0: error.append("Project Name") etisserant@0: if self.CompanyName.GetValue() == "": etisserant@0: error.append("Company Name") etisserant@0: if self.ProductName.GetValue() == "": etisserant@0: error.append("Product Name") etisserant@0: if self.ProductVersion.GetValue() == "": etisserant@0: error.append("Product Version") etisserant@0: if len(error) > 0: etisserant@0: text = "" etisserant@0: for i, item in enumerate(error): etisserant@0: if i == 0: etisserant@0: text += item etisserant@0: elif i == len(error) - 1: etisserant@0: text += " and %s"%item etisserant@0: else: etisserant@0: text += ", %s"%item lbessard@64: message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: lbessard@64: self.EndModal(wx.ID_OK) etisserant@0: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): etisserant@0: if item == "projectName": etisserant@0: self.ProjectName.SetValue(value) etisserant@0: elif item == "companyName": etisserant@0: self.CompanyName.SetValue(value) etisserant@0: elif item == "companyURL": etisserant@0: self.CompanyURL.SetValue(value) etisserant@0: elif item == "productName": etisserant@0: self.ProductName.SetValue(value) etisserant@0: elif item == "productVersion": etisserant@0: self.ProductVersion.SetValue(value) etisserant@0: elif item == "productRelease": etisserant@0: self.ProductRelease.SetValue(value) etisserant@0: elif item == "contentDescription": etisserant@0: self.ContentDescription.SetValue(value) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: values["projectName"] = self.ProjectName.GetValue() etisserant@0: values["companyName"] = self.CompanyName.GetValue() etisserant@0: if self.CompanyURL.GetValue() != None: etisserant@0: values["companyURL"] = self.CompanyURL.GetValue() etisserant@0: values["productName"] = self.ProductName.GetValue() etisserant@0: values["productVersion"] = self.ProductVersion.GetValue() etisserant@0: if self.ProductRelease.GetValue() != None: etisserant@0: values["productRelease"] = self.ProductRelease.GetValue() etisserant@0: if self.ProductRelease.GetValue() != None: etisserant@0: values["contentDescription"] = self.ContentDescription.GetValue() etisserant@0: return values etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create Pou Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@64: [ID_POUDIALOG, ID_POUDIALOGPOUNAME, lbessard@64: ID_POUDIALOGPOUTYPE, ID_POUDIALOGLANGUAGE, ID_POUDIALOGSTATICTEXT1, lbessard@64: ID_POUDIALOGSTATICTEXT2, ID_POUDIALOGSTATICTEXT3, lbessard@64: ] = [wx.NewId() for _init_ctrls in range(7)] etisserant@0: etisserant@0: class PouDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.PouName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.PouType, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_MainSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(1) lbessard@64: etisserant@0: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=3, vgap=15) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@64: self._init_coll_MainSizer_Growables(self.MainSizer) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) lbessard@64: etisserant@0: def _init_ctrls(self, prnt): lbessard@64: wx.Dialog.__init__(self, id=ID_POUDIALOG, lbessard@16: name='PouDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, lbessard@16: title='Create a new POU') etisserant@0: self.SetClientSize(wx.Size(300, 200)) etisserant@0: lbessard@64: self.staticText1 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT1, lbessard@64: label='POU Name:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) lbessard@64: lbessard@64: self.PouName = wx.TextCtrl(id=ID_POUDIALOGPOUNAME, lbessard@64: name='POUName', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText2 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT2, lbessard@64: label='POU Type:', name='staticText2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) lbessard@64: lbessard@64: self.PouType = wx.Choice(id=ID_POUDIALOGPOUTYPE, lbessard@64: name='POUType', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_CHOICE, self.OnTypeChanged, id=ID_POUDIALOGPOUTYPE) lbessard@64: lbessard@64: self.staticText3 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT3, lbessard@64: label='Language:', name='staticText3', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) lbessard@64: lbessard@64: self.Language = wx.Choice(id=ID_POUDIALOGLANGUAGE, lbessard@64: name='Language', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@64: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: etisserant@0: for option in ["function","functionBlock","program"]: etisserant@0: self.PouType.Append(option) etisserant@0: self.RefreshLanguage() etisserant@0: lbessard@6: self.PouNames = [] lbessard@70: self.PouElementNames = [] lbessard@6: etisserant@0: def OnOK(self, event): etisserant@0: error = [] etisserant@0: pou_name = self.PouName.GetValue() etisserant@0: if pou_name == "": etisserant@0: error.append("POU Name") etisserant@0: if self.PouType.GetStringSelection() == "": etisserant@0: error.append("POU Type") etisserant@0: if self.Language.GetStringSelection() == "": etisserant@0: error.append("Language") etisserant@0: if len(error) > 0: etisserant@0: text = "" etisserant@0: for i, item in enumerate(error): etisserant@0: if i == 0: etisserant@0: text += item etisserant@0: elif i == len(error) - 1: etisserant@0: text += " and %s"%item etisserant@0: else: etisserant@0: text += ", %s"%item lbessard@64: message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: elif not TestIdentifier(pou_name): lbessard@64: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: elif pou_name.upper() in IEC_KEYWORDS: lbessard@64: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: elif pou_name.upper() in self.PouNames: lbessard@64: message = wx.MessageDialog(self, "\"%s\" pou already exists!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@70: elif pou_name.upper() in self.PouElementNames: lbessard@70: message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%pou_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) lbessard@70: result = message.ShowModal() lbessard@70: message.Destroy() lbessard@70: if result == wx.ID_YES: lbessard@70: self.EndModal(wx.ID_OK) etisserant@0: else: lbessard@64: self.EndModal(wx.ID_OK) etisserant@0: etisserant@0: def RefreshLanguage(self): etisserant@0: selection = self.Language.GetStringSelection() etisserant@0: self.Language.Clear() etisserant@0: for option in ["IL","ST","LD","FBD","SFC"]: lbessard@64: if option != "SFC" or self.PouType.GetStringSelection() != "function": etisserant@0: self.Language.Append(option) lbessard@64: if self.Language.FindString(selection) != wx.NOT_FOUND: etisserant@0: self.Language.SetStringSelection(selection) etisserant@0: etisserant@0: def OnTypeChanged(self, event): etisserant@0: self.RefreshLanguage() etisserant@0: event.Skip() etisserant@0: etisserant@0: def SetPouNames(self, pou_names): etisserant@0: self.PouNames = [pou_name.upper() for pou_name in pou_names] etisserant@0: lbessard@70: def SetPouElementNames(self, element_names): lbessard@70: self.PouElementNames = [element_name.upper() for element_name in element_names] lbessard@70: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): etisserant@0: if item == "pouName": etisserant@0: self.PouName.SetValue(value) etisserant@0: elif item == "pouType": etisserant@0: self.PouType.SetStringSelection(value) etisserant@0: elif item == "language": etisserant@0: self.Language.SetStringSelection(value) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: values["pouName"] = self.PouName.GetValue() etisserant@0: values["pouType"] = self.PouType.GetStringSelection() etisserant@0: values["language"] = self.Language.GetStringSelection() etisserant@0: return values etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create Pou Transition Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@64: [ID_POUTRANSITIONDIALOG, ID_POUTRANSITIONDIALOGTRANSITIONNAME, lbessard@64: ID_POUTRANSITIONDIALOGLANGUAGE, ID_POUTRANSITIONDIALOGSTATICTEXT1, lbessard@64: ID_POUTRANSITIONDIALOGSTATICTEXT2, lbessard@64: ] = [wx.NewId() for _init_ctrls in range(5)] etisserant@0: etisserant@0: class PouTransitionDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.TransitionName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_MainSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(1) lbessard@64: etisserant@0: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@64: self._init_coll_MainSizer_Growables(self.MainSizer) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): lbessard@64: wx.Dialog.__init__(self, id=ID_POUTRANSITIONDIALOG, lbessard@45: name='PouTransitionDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE, lbessard@45: title='Create a new transition') lbessard@45: self.SetClientSize(wx.Size(350, 160)) etisserant@0: lbessard@64: self.staticText1 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT1, lbessard@64: label='Transition Name:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(120, 17), style=0) lbessard@64: lbessard@64: self.TransitionName = wx.TextCtrl(id=ID_POUTRANSITIONDIALOGTRANSITIONNAME, lbessard@64: name='TransitionName', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText2 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT2, lbessard@64: label='Language:', name='staticText2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(120, 17), style=0) lbessard@64: lbessard@64: self.Language = wx.Choice(id=ID_POUTRANSITIONDIALOGLANGUAGE, lbessard@64: name='Language', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@64: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@45: etisserant@0: for option in ["IL","ST","LD","FBD"]: etisserant@0: self.Language.Append(option) lbessard@70: lbessard@70: self.PouNames = [] lbessard@70: self.PouElementNames = [] etisserant@0: etisserant@0: def OnOK(self, event): etisserant@0: error = [] lbessard@70: transition_name = self.TransitionName.GetValue() etisserant@0: if self.TransitionName.GetValue() == "": etisserant@0: error.append("Transition Name") etisserant@0: if self.Language.GetStringSelection() == "": etisserant@0: error.append("Language") etisserant@0: if len(error) > 0: etisserant@0: text = "" etisserant@0: for i, item in enumerate(error): etisserant@0: if i == 0: etisserant@0: text += item etisserant@0: elif i == len(error) - 1: etisserant@0: text += " and %s"%item etisserant@0: else: etisserant@0: text += ", %s"%item lbessard@64: message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@70: elif not TestIdentifier(transition_name): lbessard@70: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif transition_name.upper() in IEC_KEYWORDS: lbessard@70: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif transition_name.upper() in self.PouNames: lbessard@70: message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif transition_name.upper() in self.PouElementNames: lbessard@70: message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() etisserant@0: else: lbessard@64: self.EndModal(wx.ID_OK) lbessard@70: lbessard@70: def SetPouNames(self, pou_names): lbessard@70: self.PouNames = [pou_name.upper() for pou_name in pou_names] lbessard@70: lbessard@70: def SetPouElementNames(self, pou_names): lbessard@70: self.PouElementNames = [pou_name.upper() for pou_name in pou_names] lbessard@70: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): lbessard@45: if item == "transitionName": etisserant@0: self.TransitionName.SetValue(value) etisserant@0: elif item == "language": etisserant@0: self.Language.SetStringSelection(value) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: values["transitionName"] = self.TransitionName.GetValue() etisserant@0: values["language"] = self.Language.GetStringSelection() etisserant@0: return values etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create Pou Action Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@64: [ID_POUACTIONDIALOG, ID_POUACTIONDIALOGACTIONNAME, lbessard@64: ID_POUACTIONDIALOGLANGUAGE, ID_POUACTIONDIALOGSTATICTEXT1, lbessard@64: ID_POUACTIONDIALOGSTATICTEXT2, lbessard@64: ] = [wx.NewId() for _init_ctrls in range(5)] etisserant@0: etisserant@0: class PouActionDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ActionName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_MainSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(1) lbessard@64: etisserant@0: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@64: self._init_coll_MainSizer_Growables(self.MainSizer) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): lbessard@64: wx.Dialog.__init__(self, id=ID_POUACTIONDIALOG, lbessard@45: name='PouActionDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@64: size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, lbessard@45: title='Create a new action') lbessard@45: self.SetClientSize(wx.Size(320, 160)) etisserant@0: lbessard@64: self.staticText1 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT1, lbessard@64: label='Action Name:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) lbessard@64: lbessard@64: self.ActionName = wx.TextCtrl(id=ID_POUACTIONDIALOGACTIONNAME, lbessard@64: name='ActionName', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.staticText2 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT2, lbessard@64: label='Language:', name='staticText2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) lbessard@64: lbessard@64: self.Language = wx.Choice(id=ID_POUACTIONDIALOGLANGUAGE, lbessard@64: name='Language', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@64: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@45: etisserant@0: for option in ["IL","ST","LD","FBD"]: etisserant@0: self.Language.Append(option) etisserant@0: lbessard@70: self.PouNames = [] lbessard@70: self.PouElementNames = [] lbessard@70: etisserant@0: def OnOK(self, event): etisserant@0: error = [] lbessard@70: action_name = self.ActionName.GetValue() lbessard@70: if action_name == "": etisserant@0: error.append("Action Name") etisserant@0: if self.Language.GetStringSelection() == "": etisserant@0: error.append("Language") etisserant@0: if len(error) > 0: etisserant@0: text = "" etisserant@0: for i, item in enumerate(error): etisserant@0: if i == 0: etisserant@0: text += item etisserant@0: elif i == len(error) - 1: etisserant@0: text += " and %s"%item etisserant@0: else: etisserant@0: text += ", %s"%item lbessard@64: message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@70: elif not TestIdentifier(action_name): lbessard@70: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%action_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif action_name.upper() in IEC_KEYWORDS: lbessard@70: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%action_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif action_name.upper() in self.PouNames: lbessard@70: message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif action_name.upper() in self.PouElementNames: lbessard@70: message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() etisserant@0: else: lbessard@64: self.EndModal(wx.ID_OK) lbessard@70: lbessard@70: def SetPouNames(self, pou_names): lbessard@70: self.PouNames = [pou_name.upper() for pou_name in pou_names] lbessard@70: lbessard@70: def SetPouElementNames(self, element_names): lbessard@70: self.PouElementNames = [element_name.upper() for element_name in element_names] lbessard@70: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): lbessard@45: if item == "actionName": etisserant@0: self.ActionName.SetValue(value) etisserant@0: elif item == "language": etisserant@0: self.Language.SetStringSelection(value) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: values["actionName"] = self.ActionName.GetValue() etisserant@0: values["language"] = self.Language.GetStringSelection() etisserant@0: return values etisserant@0: etisserant@0: #------------------------------------------------------------------------------- lbessard@68: # Pou Editor Panel etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@64: class VariableTable(wx.grid.PyGridTableBase): etisserant@0: etisserant@0: """ lbessard@64: A custom wx.grid.Grid Table using user supplied data etisserant@0: """ etisserant@0: def __init__(self, parent, data, colnames): etisserant@0: # The base class must be initialized *first* lbessard@64: wx.grid.PyGridTableBase.__init__(self) etisserant@0: self.data = data lbessard@58: self.old_value = None etisserant@0: self.colnames = colnames etisserant@0: self.Parent = parent etisserant@0: # XXX etisserant@0: # we need to store the row length and collength to etisserant@0: # see if the table has changed size etisserant@0: self._rows = self.GetNumberRows() etisserant@0: self._cols = self.GetNumberCols() etisserant@0: etisserant@0: def GetNumberCols(self): etisserant@0: return len(self.colnames) etisserant@0: etisserant@0: def GetNumberRows(self): etisserant@0: return len(self.data) etisserant@0: etisserant@0: def GetColLabelValue(self, col): etisserant@0: if col < len(self.colnames): etisserant@0: return self.colnames[col] etisserant@0: etisserant@0: def GetRowLabelValues(self, row): etisserant@0: return row etisserant@0: etisserant@0: def GetValue(self, row, col): etisserant@0: if row < self.GetNumberRows(): lbessard@47: if col == 0: etisserant@52: return self.Parent.Values.index(self.data[row]) + 1 etisserant@0: name = str(self.data[row].get(self.GetColLabelValue(col), "")) etisserant@0: return name etisserant@0: etisserant@0: def SetValue(self, row, col, value): etisserant@0: if col < len(self.colnames): lbessard@58: colname = self.GetColLabelValue(col) lbessard@58: if colname == "Name": lbessard@58: self.old_value = self.data[row][colname] lbessard@58: self.data[row][colname] = value lbessard@58: lbessard@68: def GetValueByName(self, row, colname): lbessard@68: if row < self.GetNumberRows(): lbessard@68: return self.data[row].get(colname) lbessard@68: lbessard@68: def SetValueByName(self, row, colname, value): lbessard@68: if row < self.GetNumberRows(): lbessard@68: self.data[row][colname] = value lbessard@68: lbessard@58: def GetOldValue(self): lbessard@58: return self.old_value lbessard@58: etisserant@0: def ResetView(self, grid): etisserant@0: """ lbessard@64: (wx.grid.Grid) -> Reset the grid view. Call this to etisserant@0: update the grid if rows and columns have been added or deleted etisserant@0: """ etisserant@0: grid.BeginBatch() etisserant@0: for current, new, delmsg, addmsg in [ lbessard@64: (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), lbessard@64: (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), etisserant@0: ]: etisserant@0: if new < current: lbessard@64: msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: elif new > current: lbessard@64: msg = wx.grid.GridTableMessage(self,addmsg,new-current) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: self.UpdateValues(grid) etisserant@0: grid.EndBatch() etisserant@0: etisserant@0: self._rows = self.GetNumberRows() etisserant@0: self._cols = self.GetNumberCols() etisserant@0: # update the column rendering scheme etisserant@0: self._updateColAttrs(grid) etisserant@0: etisserant@0: # update the scrollbars and the displayed part of the grid etisserant@0: grid.AdjustScrollbars() etisserant@0: grid.ForceRefresh() etisserant@0: etisserant@0: def UpdateValues(self, grid): etisserant@0: """Update all displayed values""" etisserant@0: # This sends an event to the grid table to update all of the values lbessard@64: msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: etisserant@0: def _updateColAttrs(self, grid): etisserant@0: """ lbessard@64: wx.grid.Grid -> update the column attributes to add the etisserant@0: appropriate renderer given the column name. etisserant@0: etisserant@0: Otherwise default to the default renderer. etisserant@0: """ etisserant@0: etisserant@0: for col in range(self.GetNumberCols()): lbessard@64: attr = wx.grid.GridCellAttr() lbessard@64: attr.SetAlignment(self.Parent.ColAlignements[col], wx.ALIGN_CENTRE) etisserant@0: grid.SetColAttr(col, attr) etisserant@0: grid.SetColSize(col, self.Parent.ColSizes[col]) etisserant@0: etisserant@0: typelist = None etisserant@0: accesslist = None etisserant@0: for row in range(self.GetNumberRows()): etisserant@0: for col in range(self.GetNumberCols()): etisserant@0: editor = None etisserant@0: renderer = None etisserant@0: colname = self.GetColLabelValue(col) lbessard@68: if col != 0 and self.GetValueByName(row, "Edit"): lbessard@68: grid.SetReadOnly(row, col, False) lbessard@68: if colname == "Name": lbessard@68: if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: lbessard@68: grid.SetReadOnly(row, col, True) lbessard@68: else: lbessard@68: editor = wx.grid.GridCellTextEditor() lbessard@68: renderer = wx.grid.GridCellStringRenderer() lbessard@68: elif colname in ["Initial Value","Location"]: lbessard@64: editor = wx.grid.GridCellTextEditor() lbessard@64: renderer = wx.grid.GridCellStringRenderer() lbessard@68: elif colname == "Class": lbessard@68: if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: lbessard@68: grid.SetReadOnly(row, col, True) lbessard@68: else: lbessard@68: editor = wx.grid.GridCellChoiceEditor() lbessard@68: excluded = [] lbessard@68: if self.Parent.PouIsUsed: lbessard@68: excluded.extend(["Input","Output","InOut"]) lbessard@68: editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) lbessard@68: elif colname in ["Retain", "Constant"]: lbessard@64: editor = wx.grid.GridCellChoiceEditor() lbessard@68: editor.SetParameters(self.Parent.OptionList) lbessard@68: elif colname == "Type": lbessard@68: editor = wx.grid.GridCellTextEditor() lbessard@68: else: lbessard@68: grid.SetReadOnly(row, col, True) lbessard@68: etisserant@0: grid.SetCellEditor(row, col, editor) etisserant@0: grid.SetCellRenderer(row, col, renderer) etisserant@0: lbessard@64: grid.SetCellBackgroundColour(row, col, wx.WHITE) etisserant@0: etisserant@0: def SetData(self, data): etisserant@0: self.data = data etisserant@0: etisserant@0: def GetData(self): etisserant@0: return self.data etisserant@0: etisserant@0: def GetCurrentIndex(self): etisserant@0: return self.CurrentIndex etisserant@0: etisserant@0: def SetCurrentIndex(self, index): etisserant@0: self.CurrentIndex = index etisserant@0: etisserant@0: def AppendRow(self, row_content): etisserant@0: self.data.append(row_content) etisserant@0: etisserant@0: def RemoveRow(self, row_index): etisserant@0: self.data.pop(row_index) lbessard@12: lbessard@12: def GetRow(self, row_index): lbessard@12: return self.data[row_index] etisserant@0: etisserant@0: def Empty(self): etisserant@0: self.data = [] etisserant@0: self.editors = [] etisserant@0: lbessard@53: class VariableDropTarget(wx.TextDropTarget): lbessard@53: lbessard@53: def __init__(self, parent): lbessard@53: wx.TextDropTarget.__init__(self) lbessard@53: self.Parent = parent lbessard@53: lbessard@53: def OnDropText(self, x, y, data): lbessard@53: col = self.Parent.VariablesGrid.XToCol(x) lbessard@53: row = self.Parent.VariablesGrid.YToRow(y) lbessard@64: if col != wx.NOT_FOUND and row != wx.NOT_FOUND: lbessard@53: if self.Parent.Table.GetColLabelValue(col) != "Location": lbessard@53: return lbessard@53: try: lbessard@53: values = eval(data) lbessard@53: except: lbessard@53: values = None lbessard@53: if values and values[1] == "location": lbessard@64: dialog = wx.SingleChoiceDialog(self.Parent, "Select a variable class:", "Variable class", ["Input", "Output", "Memory"], wx.OK|wx.CANCEL) lbessard@64: if dialog.ShowModal() == wx.ID_OK: lbessard@53: selected = dialog.GetSelection() lbessard@53: if selected == 0: lbessard@53: location = "%I" + values[0] lbessard@53: elif selected == 1: lbessard@53: location = "%Q" + values[0] lbessard@53: else: lbessard@53: location = "%M" + values[0] lbessard@53: self.Parent.Table.SetValue(row - 1, col, location) lbessard@53: self.Parent.Table.ResetView(self.Parent.VariablesGrid) lbessard@53: self.Parent.SaveValues() lbessard@53: dialog.Destroy() lbessard@53: lbessard@64: [ID_POUEDITORPANEL, ID_POUEDITORPANELVIEWER, lbessard@64: ID_POUEDITORPANELVARIABLESGRID, ID_POUEDITORPANELRETURNTYPE, lbessard@64: ID_POUEDITORPANELCLASSFILTER, ID_POUEDITORPANELADDBUTTON, lbessard@64: ID_POUEDITORPANELDELETEBUTTON, ID_POUEDITORPANELUPBUTTON, lbessard@64: ID_POUEDITORPANELDOWNBUTTON, ID_POUEDITORPANELSTATICTEXT1, lbessard@64: ID_POUEDITORPANELSTATICTEXT2, ID_POUEDITORPANELSTATICTEXT3, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(12)] etisserant@0: lbessard@68: class PouEditorPanel(wx.SplitterWindow): lbessard@47: def _init_coll_VariablePanelSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddSizer(self.ControlPanelSizer, 0, border=0, flag=wx.GROW) lbessard@47: lbessard@47: def _init_coll_VariablePanelSizer_Growables(self, parent): lbessard@47: parent.AddGrowableCol(0) lbessard@47: parent.AddGrowableRow(0) lbessard@47: lbessard@47: def _init_coll_ControlPanelSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.ChoicePanelSizer, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddSizer(self.ButtonPanelSizer, 0, border=0, flag=wx.ALIGN_CENTER) lbessard@47: lbessard@47: def _init_coll_ControlPanelSizer_Growables(self, parent): lbessard@47: parent.AddGrowableCol(0) lbessard@47: parent.AddGrowableRow(0) lbessard@47: parent.AddGrowableRow(1) lbessard@47: lbessard@47: def _init_coll_ChoicePanelSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) etisserant@52: parent.AddWindow(self.ReturnType, 0, border=0, flag=0) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) lbessard@47: parent.AddWindow(self.ClassFilter, 0, border=0, flag=0) lbessard@47: lbessard@47: def _init_coll_ButtonPanelSizer_Items(self, parent): etisserant@52: parent.AddWindow(self.UpButton, 0, border=0, flag=0) lbessard@51: parent.AddWindow(self.AddButton, 0, border=0, flag=0) etisserant@52: parent.AddWindow(self.DownButton, 0, border=0, flag=0) lbessard@51: parent.AddWindow(self.DeleteButton, 0, border=0, flag=0) etisserant@52: lbessard@47: def _init_coll_ButtonPanelSizer_Growables(self, parent): lbessard@47: parent.AddGrowableCol(0) lbessard@47: parent.AddGrowableCol(1) lbessard@47: parent.AddGrowableCol(2) lbessard@47: parent.AddGrowableCol(3) lbessard@47: parent.AddGrowableRow(0) etisserant@0: etisserant@0: def _init_sizers(self): lbessard@47: self.VariablePanelSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=0) etisserant@52: self.ControlPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) etisserant@52: self.ChoicePanelSizer = wx.GridSizer(cols=1, hgap=5, rows=4, vgap=5) etisserant@52: self.ButtonPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0) lbessard@47: lbessard@47: self._init_coll_VariablePanelSizer_Items(self.VariablePanelSizer) lbessard@47: self._init_coll_VariablePanelSizer_Growables(self.VariablePanelSizer) lbessard@47: self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer) lbessard@47: self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer) lbessard@47: self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer) lbessard@47: self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer) lbessard@47: self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer) lbessard@47: lbessard@68: self.VariablePanel.SetSizer(self.VariablePanelSizer) lbessard@47: lbessard@47: def _init_ctrls(self, prnt, element_type): lbessard@68: wx.SplitterWindow.__init__(self, id=ID_POUEDITORPANEL, lbessard@47: name='EditVariablePanel', parent=prnt, pos=wx.Point(0, 0), lbessard@68: size=wx.Size(-1, -1), style=wx.SP_3D) lbessard@68: self.SetNeedUpdating(True) lbessard@68: self.SetMinimumPaneSize(1) lbessard@47: lbessard@47: if element_type == "config": lbessard@64: self.Viewer = wx.Panel(id=ID_POUEDITORPANELVIEWER, lbessard@71: name='ConfigPanel', parent=self, pos=wx.Point(0, 0), lbessard@47: size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) lbessard@56: self.Viewer.ResetBuffer = lambda: None lbessard@56: self.Viewer.RefreshView = lambda: None lbessard@47: elif element_type == "resource": lbessard@47: self.Viewer = ResourceEditor(self, self.Parent, self.Controler) lbessard@47: elif element_type == "FBD": lbessard@47: self.Viewer = Viewer(self, self.Parent, self.Controler) lbessard@47: elif element_type == "LD": lbessard@47: self.Viewer = LD_Viewer(self, self.Parent, self.Controler) lbessard@47: elif element_type == "SFC": lbessard@47: self.Viewer = SFC_Viewer(self, self.Parent, self.Controler) lbessard@47: else: lbessard@47: self.Viewer = TextViewer(self, self.Parent, self.Controler) lbessard@47: self.Viewer.SetTextSyntax(element_type) lbessard@47: if element_type == "IL": lbessard@47: self.Viewer.SetKeywords(IL_KEYWORDS) lbessard@47: else: lbessard@47: self.Viewer.SetKeywords(ST_KEYWORDS) lbessard@47: lbessard@68: self.VariablePanel = wx.Panel(id=ID_POUEDITORPANELVIEWER, lbessard@68: name='VariablePanel', parent=self, pos=wx.Point(0, 0), lbessard@68: size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) lbessard@68: lbessard@64: self.staticText1 = wx.StaticText(id=ID_POUEDITORPANELSTATICTEXT1, lbessard@68: label='Return Type:', name='staticText1', parent=self.VariablePanel, lbessard@47: pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) lbessard@47: lbessard@64: self.ReturnType = wx.Choice(id=ID_POUEDITORPANELRETURNTYPE, lbessard@68: name='ReturnType', parent=self.VariablePanel, pos=wx.Point(0, 0), etisserant@52: size=wx.Size(145, 24), style=0) etisserant@0: lbessard@64: self.staticText2 = wx.StaticText(id=ID_POUEDITORPANELSTATICTEXT2, lbessard@68: label='Class Filter:', name='staticText2', parent=self.VariablePanel, lbessard@47: pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) lbessard@47: lbessard@64: self.ClassFilter = wx.Choice(id=ID_POUEDITORPANELCLASSFILTER, lbessard@68: name='ClassFilter', parent=self.VariablePanel, pos=wx.Point(0, 0), etisserant@52: size=wx.Size(145, 24), style=0) lbessard@64: self.Bind(wx.EVT_CHOICE, self.OnClassFilter, id=ID_POUEDITORPANELCLASSFILTER) lbessard@64: lbessard@64: self.VariablesGrid = wx.grid.Grid(id=ID_POUEDITORPANELVARIABLESGRID, lbessard@68: name='VariablesGrid', parent=self.VariablePanel, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 150), style=wx.VSCROLL) etisserant@0: self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, etisserant@0: 'Sans')) etisserant@0: self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, etisserant@0: False, 'Sans')) lbessard@6: self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) lbessard@37: self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell) lbessard@47: self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) lbessard@68: self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) lbessard@53: self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) lbessard@53: lbessard@64: self.AddButton = wx.Button(id=ID_POUEDITORPANELADDBUTTON, label='Add', lbessard@68: name='AddButton', parent=self.VariablePanel, pos=wx.Point(345, 340), etisserant@0: size=wx.Size(72, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_POUEDITORPANELADDBUTTON) lbessard@64: lbessard@64: self.DeleteButton = wx.Button(id=ID_POUEDITORPANELDELETEBUTTON, label='Delete', lbessard@68: name='DeleteButton', parent=self.VariablePanel, pos=wx.Point(425, 340), etisserant@0: size=wx.Size(72, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_POUEDITORPANELDELETEBUTTON) lbessard@64: lbessard@64: self.UpButton = wx.Button(id=ID_POUEDITORPANELUPBUTTON, label='^', lbessard@68: name='UpButton', parent=self.VariablePanel, pos=wx.Point(505, 340), etisserant@0: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_POUEDITORPANELUPBUTTON) lbessard@64: lbessard@64: self.DownButton = wx.Button(id=ID_POUEDITORPANELDOWNBUTTON, label='v', lbessard@68: name='DownButton', parent=self.VariablePanel, pos=wx.Point(545, 340), etisserant@0: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_POUEDITORPANELDOWNBUTTON) etisserant@0: lbessard@68: self.SplitHorizontally(self.Viewer, self.VariablePanel, -200) lbessard@68: etisserant@0: self._init_sizers() etisserant@0: lbessard@47: def __init__(self, parent, window, controler, element_type, pou_name = None, transition_name = None, action_name = None, config_name = None, resource_name = None): lbessard@47: self.Parent = window lbessard@47: self.Controler = controler lbessard@47: self.ElementType = element_type lbessard@47: self.PouName = pou_name lbessard@47: self.TransitionName = transition_name lbessard@47: self.ActionName = action_name lbessard@47: self.ConfigName = config_name lbessard@47: self.ResourceName = resource_name lbessard@47: lbessard@47: if element_type == "config": lbessard@47: self._init_ctrls(parent, "config") lbessard@47: pou_type = "config" lbessard@47: elif element_type == "resource": lbessard@47: self._init_ctrls(parent, "resource") lbessard@47: pou_type = "resource" lbessard@47: else: lbessard@47: if element_type == "transition": lbessard@47: self._init_ctrls(parent, self.Controler.GetTransitionBodyType(pou_name, transition_name)) lbessard@47: elif element_type == "action": lbessard@47: self._init_ctrls(parent, self.Controler.GetActionBodyType(pou_name, action_name)) lbessard@47: else: lbessard@47: self._init_ctrls(parent, self.Controler.GetPouBodyType(pou_name)) lbessard@47: pou_type = self.Controler.GetPouType(pou_name) lbessard@47: lbessard@47: self.Filter = "All" etisserant@0: self.FilterChoices = [] etisserant@0: self.FilterChoiceTransfer = {"All" : "All", "Interface" : "Interface", lbessard@37: " Input" : "Input", " Output" : "Output", " InOut" : "InOut", lbessard@37: " External" : "External", "Variables" : "Variables", " Local" : "Local", lbessard@37: " Temp" : "Temp", "Global" : "Global", "Access" : "Access"} etisserant@0: lbessard@47: if pou_type in ["config", "resource"]: lbessard@47: self.DefaultTypes = {"All" : "Global"} lbessard@68: self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : "True"} lbessard@47: else: lbessard@37: self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} lbessard@68: self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : "True"} lbessard@47: if pou_type in ["config", "resource"] or pou_type == "program": lbessard@70: self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"]) lbessard@47: if pou_type not in ["config", "resource"]: etisserant@0: self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp","Global","Access"] etisserant@0: else: etisserant@0: self.FilterChoices = ["All","Global","Access"] lbessard@70: self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70] lbessard@70: self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER] lbessard@70: else: lbessard@70: self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Initial Value", "Retain", "Constant"]) etisserant@0: self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"] lbessard@70: self.ColSizes = [40, 120, 70, 80, 120, 60, 70] lbessard@70: self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER] etisserant@0: for choice in self.FilterChoices: etisserant@0: self.ClassFilter.Append(choice) lbessard@37: reverse_transfer = {} lbessard@37: for filter, choice in self.FilterChoiceTransfer.items(): lbessard@37: reverse_transfer[choice] = filter lbessard@37: self.ClassFilter.SetStringSelection(reverse_transfer[self.Filter]) etisserant@0: self.RefreshTypeList() etisserant@0: etisserant@0: self.OptionList = "Yes,No" lbessard@68: self.TypeList = [value for value, parent in TypeHierarchy_list if not value.startswith("ANY")] etisserant@0: etisserant@0: if pou_type == "function": lbessard@28: for value, parent in TypeHierarchy_list: etisserant@0: if not value.startswith("ANY"): etisserant@0: self.ReturnType.Append(value) etisserant@0: self.ReturnType.Enable(True) etisserant@0: else: etisserant@0: self.ReturnType.Enable(False) lbessard@47: self.staticText1.Hide() etisserant@0: self.ReturnType.Hide() etisserant@0: etisserant@0: self.VariablesGrid.SetTable(self.Table) etisserant@0: self.VariablesGrid.SetRowLabelSize(0) lbessard@47: lbessard@47: def SetMode(self, mode): lbessard@47: if self.ElementType not in ["resource", "config"]: lbessard@47: if self.ElementType == "transition": lbessard@47: language = self.Controler.GetTransitionBodyType(self.PouName, self.TransitionName) lbessard@47: elif self.ElementType == "action": lbessard@47: language = self.Controler.GetActionBodyType(self.PouName, self.ActionName) lbessard@47: else: lbessard@47: language = self.Controler.GetPouBodyType(self.PouName) lbessard@47: if language not in ["IL", "ST"]: lbessard@47: self.Viewer.SetMode(mode) lbessard@47: lbessard@56: def ResetBuffer(self): lbessard@56: self.Viewer.ResetBuffer() lbessard@56: lbessard@47: def RefreshView(self): lbessard@47: self.PouNames = self.Controler.GetProjectPouNames() lbessard@47: lbessard@47: if self.ElementType == "config": lbessard@47: self.PouIsUsed = False lbessard@47: returnType = None lbessard@47: self.Values = self.Controler.GetConfigurationGlobalVars(self.ConfigName) lbessard@47: elif self.ElementType == "resource": lbessard@47: self.PouIsUsed = False lbessard@47: returnType = None lbessard@47: self.Values = self.Controler.GetConfigurationResourceGlobalVars(self.ConfigName, self.ResourceName) lbessard@47: else: lbessard@47: self.PouIsUsed = self.Controler.PouIsUsed(self.PouName) lbessard@47: returnType = self.Controler.GetCurrentElementEditingInterfaceReturnType() lbessard@47: self.Values = self.Controler.GetCurrentElementEditingInterfaceVars() lbessard@68: lbessard@68: if returnType and self.ReturnType.IsEnabled(): lbessard@68: self.ReturnType.SetStringSelection(returnType) lbessard@68: lbessard@68: self.RefreshValues() lbessard@68: self.RefreshViewerVarList() lbessard@68: self.RefreshButtons() lbessard@68: self.Viewer.RefreshView() lbessard@68: lbessard@68: def RefreshViewerVarList(self): lbessard@71: if self.ElementType not in ["config", "resource"]: lbessard@47: varlist = [var["Name"] for var in self.Values] lbessard@68: if self.ElementType == "transition": lbessard@47: language = self.Controler.GetTransitionBodyType(self.PouName, self.TransitionName) lbessard@68: varlist.append(self.TransitionName) lbessard@47: elif self.ElementType == "action": lbessard@47: language = self.Controler.GetActionBodyType(self.PouName, self.ActionName) lbessard@47: varlist.append(self.ActionName) lbessard@47: else: lbessard@47: language = self.Controler.GetPouBodyType(self.PouName) lbessard@47: varlist.append(self.PouName) lbessard@47: if language in ["IL", "ST"]: lbessard@47: self.Viewer.SetVariables(varlist) lbessard@47: self.Viewer.SetFunctions(self.Controler.GetBlockTypes()) lbessard@67: etisserant@0: def OnClassFilter(self, event): lbessard@37: self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()] etisserant@0: self.RefreshTypeList() etisserant@0: self.RefreshValues() lbessard@37: self.RefreshButtons() etisserant@0: event.Skip() etisserant@0: etisserant@0: def RefreshTypeList(self): etisserant@0: if self.Filter == "All": lbessard@37: self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] etisserant@0: elif self.Filter == "Interface": etisserant@0: self.ClassList = ["Input","Output","InOut","External"] etisserant@0: elif self.Filter == "Variables": etisserant@0: self.ClassList = ["Local","Temp"] etisserant@0: else: etisserant@0: self.ClassList = [self.Filter] etisserant@0: lbessard@37: def RefreshButtons(self): lbessard@56: if self.Table: lbessard@56: table_length = len(self.Table.data) lbessard@56: row_class = None lbessard@56: if table_length and self.PouIsUsed: lbessard@56: row = self.VariablesGrid.GetGridCursorRow() lbessard@56: row_class = self.Table.GetValueByName(row, "Class") lbessard@56: self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]) lbessard@56: self.DeleteButton.Enable(table_length > 0 and row_class not in ["Input", "Output", "InOut"]) lbessard@56: self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) lbessard@56: self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) lbessard@47: etisserant@0: def OnAddButton(self, event): lbessard@11: new_row = self.DefaultValue.copy() lbessard@11: if self.Filter in self.DefaultTypes: lbessard@11: new_row["Class"] = self.DefaultTypes[self.Filter] lbessard@11: else: lbessard@11: new_row["Class"] = self.Filter lbessard@12: self.Values.append(new_row) lbessard@68: self.SaveValues() lbessard@12: self.RefreshValues() lbessard@37: self.RefreshButtons() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnDeleteButton(self, event): lbessard@12: row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow()) lbessard@12: self.Values.remove(row) lbessard@68: self.SaveValues() lbessard@12: self.RefreshValues() lbessard@37: self.RefreshButtons() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnUpButton(self, event): lbessard@12: self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1) lbessard@37: self.RefreshButtons() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnDownButton(self, event): lbessard@12: self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1) lbessard@37: self.RefreshButtons() etisserant@0: event.Skip() etisserant@0: lbessard@6: def OnVariablesGridCellChange(self, event): lbessard@6: row, col = event.GetRow(), event.GetCol() lbessard@6: colname = self.Table.GetColLabelValue(col) lbessard@6: value = self.Table.GetValue(row, col) lbessard@6: if colname == "Name": lbessard@6: if not TestIdentifier(value): lbessard@64: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wx.OK|wx.ICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: elif value.upper() in IEC_KEYWORDS: lbessard@64: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wx.OK|wx.ICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: elif value.upper() in self.PouNames: lbessard@64: message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wx.OK|wx.ICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]: lbessard@64: message = wx.MessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wx.OK|wx.ICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: else: lbessard@58: self.SaveValues(False) lbessard@58: old_value = self.Table.GetOldValue() lbessard@58: if old_value != "": lbessard@58: self.Controler.UpdateCurrentPouEditingUsedVariable(old_value, value) lbessard@58: self.Controler.BufferProject() lbessard@58: self.Parent.RefreshTitle() lbessard@58: self.Parent.RefreshEditMenu() lbessard@68: self.RefreshViewerVarList() lbessard@58: self.Viewer.RefreshView() lbessard@6: event.Skip() lbessard@6: else: lbessard@47: self.SaveValues() lbessard@6: event.Skip() lbessard@6: lbessard@47: def OnVariablesGridCellLeftClick(self, event): lbessard@68: if event.GetCol() == "#": lbessard@68: row = event.GetRow() lbessard@68: var_name = self.Table.GetValueByName(row, "Name") lbessard@68: var_class = self.Table.GetValueByName(row, "Class") lbessard@68: var_type = self.Table.GetValueByName(row, "Type") lbessard@68: data = wx.TextDataObject(str((var_name, var_class, var_type))) lbessard@68: dragSource = wx.DropSource(self.VariablesGrid) lbessard@68: dragSource.SetData(data) lbessard@68: dragSource.DoDragDrop() lbessard@68: event.Skip() lbessard@68: lbessard@68: def OnVariablesGridEditorShown(self, event): lbessard@68: row, col = event.GetRow(), event.GetCol() lbessard@68: if self.Table.GetColLabelValue(col) == "Type": lbessard@68: type_menu = wx.Menu(title='') lbessard@68: base_menu = wx.Menu(title='') lbessard@68: for base_type in self.TypeList: lbessard@68: new_id = wx.NewId() lbessard@68: base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) lbessard@68: self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) lbessard@68: type_menu.AppendMenu(-1, "Base Types", base_menu, '') lbessard@68: functionblock_menu = wx.Menu(title='') lbessard@68: for functionblock_type in self.Controler.GetFunctionBlockTypes(): lbessard@68: new_id = wx.NewId() lbessard@68: functionblock_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) lbessard@68: self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) lbessard@68: type_menu.AppendMenu(-1, "Function Block Types", functionblock_menu, '') lbessard@68: rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) lbessard@68: self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize()) lbessard@68: event.Veto() lbessard@68: else: lbessard@68: event.Skip() lbessard@68: lbessard@68: def GetVariableTypeFunction(self, base_type): lbessard@68: def VariableTypeFunction(event): lbessard@68: row = self.VariablesGrid.GetGridCursorRow() lbessard@68: self.Table.SetValueByName(row, "Type", base_type) lbessard@68: self.SaveValues() lbessard@68: self.Table.ResetView(self.VariablesGrid) lbessard@68: event.Skip() lbessard@68: return VariableTypeFunction lbessard@68: lbessard@68: def OnVariablesGridCellLeftClick(self, event): lbessard@47: if event.GetCol() == 0: lbessard@47: row = event.GetRow() lbessard@47: var_name = self.Table.GetValueByName(row, "Name") lbessard@47: var_class = self.Table.GetValueByName(row, "Class") lbessard@47: var_type = self.Table.GetValueByName(row, "Type") lbessard@64: data = wx.TextDataObject(str((var_name, var_class, var_type))) lbessard@64: dragSource = wx.DropSource(self.VariablesGrid) lbessard@47: dragSource.SetData(data) lbessard@47: dragSource.DoDragDrop() lbessard@47: event.Skip() lbessard@47: lbessard@37: def OnVariablesGridSelectCell(self, event): lbessard@64: wx.CallAfter(self.RefreshButtons) lbessard@37: event.Skip() lbessard@37: lbessard@12: def MoveValue(self, value_index, move): lbessard@12: new_index = max(0, min(value_index + move, len(self.Values) - 1)) lbessard@12: if new_index != value_index: lbessard@12: self.Values.insert(new_index, self.Values.pop(value_index)) lbessard@28: self.RefreshValues() lbessard@12: self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol()) lbessard@28: else: lbessard@28: self.RefreshValues() lbessard@47: self.SaveValues() lbessard@47: etisserant@0: def RefreshValues(self): lbessard@37: if len(self.Table.data) > 0: lbessard@47: self.VariablesGrid.SetGridCursor(0, 1) etisserant@0: data = [] etisserant@0: for variable in self.Values: etisserant@0: if variable["Class"] in self.ClassList: etisserant@0: data.append(variable) etisserant@0: self.Table.SetData(data) etisserant@0: self.Table.ResetView(self.VariablesGrid) lbessard@47: lbessard@58: def SaveValues(self, buffer = True): lbessard@47: if self.ElementType == "config": lbessard@47: self.Controler.SetConfigurationGlobalVars(self.ConfigName, self.Values) lbessard@47: elif self.ElementType == "resource": lbessard@47: self.Controler.SetConfigurationResourceGlobalVars(self.ConfigName, self.ResourceName, self.Values) lbessard@47: else: lbessard@47: if self.ReturnType.IsEnabled(): lbessard@47: self.Controler.SetPouInterfaceReturnType(self.PouName, self.ReturnType.GetStringSelection()) lbessard@47: self.Controler.SetPouInterfaceVars(self.PouName, self.Values) lbessard@58: if buffer: lbessard@58: self.Controler.BufferProject() lbessard@58: self.Parent.RefreshTitle() lbessard@58: self.Parent.RefreshEditMenu() lbessard@47: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Exception Handler etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: Max_Traceback_List_Size = 20 etisserant@0: etisserant@0: def Display_Exception_Dialog(e_type,e_value,e_tb): etisserant@0: trcbck_lst = [] etisserant@0: for i,line in enumerate(traceback.extract_tb(e_tb)): etisserant@0: trcbck = " " + str(i+1) + ". " etisserant@0: if line[0].find(os.getcwd()) == -1: etisserant@0: trcbck += "file : " + str(line[0]) + ", " etisserant@0: else: etisserant@0: trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " etisserant@0: trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) etisserant@0: trcbck_lst.append(trcbck) etisserant@0: etisserant@0: # Allow clicking.... etisserant@0: cap = wx.Window_GetCapture() etisserant@0: if cap: etisserant@0: cap.ReleaseMouse() etisserant@0: etisserant@0: dlg = wx.SingleChoiceDialog(None, etisserant@0: """ etisserant@0: An error happens. etisserant@0: etisserant@0: Click on OK for saving an error report. etisserant@0: etisserant@0: Please contact LOLITech at: etisserant@0: +33 (0)3 29 52 95 67 etisserant@0: bugs_PLCOpenEditor@lolitech.fr etisserant@0: etisserant@0: etisserant@0: Error: etisserant@0: """ + etisserant@0: str(e_type) + " : " + str(e_value), etisserant@0: "Error", etisserant@0: trcbck_lst) etisserant@0: try: etisserant@0: res = (dlg.ShowModal() == wx.ID_OK) etisserant@0: finally: etisserant@0: dlg.Destroy() etisserant@0: etisserant@0: return res etisserant@0: etisserant@0: def Display_Error_Dialog(e_value): lbessard@64: message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: etisserant@0: def get_last_traceback(tb): etisserant@0: while tb.tb_next: etisserant@0: tb = tb.tb_next etisserant@0: return tb etisserant@0: etisserant@0: etisserant@0: def format_namespace(d, indent=' '): etisserant@0: return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) etisserant@0: etisserant@0: etisserant@0: ignored_exceptions = [] # a problem with a line in a module is only reported once per session etisserant@0: lbessard@65: def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): etisserant@0: etisserant@0: def handle_exception(e_type, e_value, e_traceback): etisserant@0: traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func etisserant@0: last_tb = get_last_traceback(e_traceback) etisserant@0: ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) etisserant@0: if str(e_value).startswith("!!!"): etisserant@0: Display_Error_Dialog(e_value) etisserant@0: elif ex not in ignored_exceptions: etisserant@0: result = Display_Exception_Dialog(e_type,e_value,e_traceback) etisserant@0: if result: etisserant@0: ignored_exceptions.append(ex) etisserant@0: info = { etisserant@0: 'app-title' : wx.GetApp().GetAppName(), # app_title etisserant@0: 'app-version' : app_version, etisserant@0: 'wx-version' : wx.VERSION_STRING, etisserant@0: 'wx-platform' : wx.Platform, etisserant@0: 'python-version' : platform.python_version(), #sys.version.split()[0], etisserant@0: 'platform' : platform.platform(), etisserant@0: 'e-type' : e_type, etisserant@0: 'e-value' : e_value, etisserant@0: 'date' : time.ctime(), etisserant@0: 'cwd' : os.getcwd(), etisserant@0: } etisserant@0: if e_traceback: etisserant@0: info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) etisserant@0: last_tb = get_last_traceback(e_traceback) etisserant@0: exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred etisserant@0: info['locals'] = format_namespace(exception_locals) etisserant@0: if 'self' in exception_locals: etisserant@0: info['self'] = format_namespace(exception_locals['self'].__dict__) etisserant@0: etisserant@0: output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') etisserant@0: lst = info.keys() etisserant@0: lst.sort() etisserant@0: for a in lst: etisserant@0: output.write(a+":\n"+str(info[a])+"\n\n") etisserant@0: etisserant@0: #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) etisserant@0: sys.excepthook = handle_exception etisserant@0: etisserant@0: if __name__ == '__main__': lbessard@64: app = wx.PySimpleApp() lbessard@64: wx.InitAllImageHandlers() etisserant@0: etisserant@0: # Install a exception handle for bug reports lbessard@65: AddExceptHook(os.getcwd(),__version__) etisserant@0: etisserant@0: frame = PLCOpenEditor(None) etisserant@0: etisserant@0: frame.Show() etisserant@0: app.MainLoop() etisserant@0: