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: # etisserant@0: #Copyright (C): 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 etisserant@0: #Lesser 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 wxPython.wx import * etisserant@0: from wxPython.grid import * etisserant@0: from time import localtime etisserant@0: from datetime import datetime etisserant@0: import wx 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: from plcopen.structures import * 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@6: CWD = sys.path[0] etisserant@0: etisserant@0: [wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, lbessard@6: wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL, lbessard@6: wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR, lbessard@6: wxID_PLCOPENEDITORDEFAULTTOOLBAR, wxID_PLCOPENEDITORSFCTOOLBAR, etisserant@0: wxID_PLCOPENEDITORFBDTOOLBAR, wxID_PLCOPENEDITORLDTOOLBAR, lbessard@6: ] = [wx.NewId() for _init_ctrls in range(10)] lbessard@6: etisserant@0: [wxID_PLCOPENEDITORFILEMENUITEMS0, wxID_PLCOPENEDITORFILEMENUITEMS1, etisserant@0: wxID_PLCOPENEDITORFILEMENUITEMS2, wxID_PLCOPENEDITORFILEMENUITEMS3, etisserant@0: wxID_PLCOPENEDITORFILEMENUITEMS5, wxID_PLCOPENEDITORFILEMENUITEMS6, etisserant@0: wxID_PLCOPENEDITORFILEMENUITEMS7, wxID_PLCOPENEDITORFILEMENUITEMS9, etisserant@0: wxID_PLCOPENEDITORFILEMENUITEMS11, etisserant@0: ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] etisserant@0: etisserant@0: [wxID_PLCOPENEDITORHELPMENUITEMS0, wxID_PLCOPENEDITORHELPMENUITEMS1, etisserant@0: wxID_PLCOPENEDITORHELPMENUITEMS2, wxID_PLCOPENEDITORHELPMENUITEMS3, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] etisserant@0: etisserant@0: [wxID_PLCOPENEDITORSFCMENUITEMS0, wxID_PLCOPENEDITORSFCMENUITEMS1, etisserant@0: wxID_PLCOPENEDITORSFCMENUITEMS2, wxID_PLCOPENEDITORSFCMENUITEMS3, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] etisserant@0: etisserant@0: [wxID_PLCOPENEDITORCONFIGMENUITEMS0, wxID_PLCOPENEDITORCONFIGMENUITEMS1, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] etisserant@0: etisserant@0: [wxID_PLCOPENEDITOREDITMENUITEMS0, wxID_PLCOPENEDITOREDITMENUITEMS1, etisserant@0: wxID_PLCOPENEDITOREDITMENUITEMS11, wxID_PLCOPENEDITOREDITMENUITEMS12, etisserant@0: wxID_PLCOPENEDITOREDITMENUITEMS2, wxID_PLCOPENEDITOREDITMENUITEMS4, etisserant@0: wxID_PLCOPENEDITOREDITMENUITEMS5, wxID_PLCOPENEDITOREDITMENUITEMS6, etisserant@0: wxID_PLCOPENEDITOREDITMENUITEMS8, wxID_PLCOPENEDITOREDITMENUITEMS9, etisserant@0: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)] etisserant@0: etisserant@0: [wxID_PLCOPENEDITORSFCMENUITEMS0, wxID_PLCOPENEDITORSFCMENUITEMS1, etisserant@0: wxID_PLCOPENEDITORSFCMENUITEMS2, wxID_PLCOPENEDITORSFCMENUITEMS3, etisserant@0: ] = [wx.NewId() for _init_coll_SFCMenu_Items in range(4)] etisserant@0: etisserant@0: [wxID_PLCOPENEDITORCONFIGMENUITEMS0, wxID_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@27: [wxID_PLCOPENEDITORTOOLBARSELECTION, wxID_PLCOPENEDITORTOOLBARCOMMENT, lbessard@27: wxID_PLCOPENEDITORTOOLBARVARIABLE, wxID_PLCOPENEDITORTOOLBARBLOCK, lbessard@27: wxID_PLCOPENEDITORTOOLBARCONNECTION, wxID_PLCOPENEDITORTOOLBARWIRE, lbessard@27: wxID_PLCOPENEDITORTOOLBARPOWERRAIL, wxID_PLCOPENEDITORTOOLBARRUNG, lbessard@27: wxID_PLCOPENEDITORTOOLBARCOIL, wxID_PLCOPENEDITORTOOLBARCONTACT, lbessard@27: wxID_PLCOPENEDITORTOOLBARBRANCH, wxID_PLCOPENEDITORTOOLBARINITIALSTEP, lbessard@27: wxID_PLCOPENEDITORTOOLBARSTEP, wxID_PLCOPENEDITORTOOLBARTRANSITION, lbessard@27: wxID_PLCOPENEDITORTOOLBARACTIONBLOCK, wxID_PLCOPENEDITORTOOLBARDIVERGENCE, lbessard@27: wxID_PLCOPENEDITORTOOLBARJUMP, lbessard@27: ] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(17)] lbessard@27: lbessard@27: ToolBarItems = { lbessard@27: "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), lbessard@27: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), lbessard@27: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), lbessard@27: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), lbessard@27: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], lbessard@27: "LD" : [(True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "Images/powerrail.png", "Create a new power rail"), lbessard@27: (False, DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARRUNG, "OnRungTool", "Images/rung.png", "Create a new rung"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOIL, "OnCoilTool", "Images/coil.png", "Create a new coil"), lbessard@27: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "Images/contact.png", "Create a new contact"), lbessard@27: (False, DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBRANCH, "OnBranchTool", "Images/branch.png", "Create a new branch"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), lbessard@27: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "Images/wire.png", "Create a new wire")], lbessard@27: "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "Images/comment.png", "Create a new comment"), lbessard@27: (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARINITIALSTEP, "OnInitialStepTool", "Images/initial_step.png", "Create a new initial step"), lbessard@27: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARSTEP, "OnStepTool", "Images/step.png", "Create a new step"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARTRANSITION, "OnTransitionTool", "Images/transition.png", "Create a new transition"), lbessard@27: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", "Images/action.png", "Create a new action block"), lbessard@27: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARDIVERGENCE, "OnDivergenceTool", "Images/divergence.png", "Create a new divergence"), lbessard@27: (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARJUMP, "OnJumpTool", "Images/jump.png", "Create a new jump"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "Images/variable.png", "Create a new variable"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "Images/block.png", "Create a new block"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "Images/connection.png", "Create a new connection"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "Images/powerrail.png", "Create a new power rail"), lbessard@27: (True, FREEDRAWING_MODE, wxID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "Images/contact.png", "Create a new contact"), lbessard@27: (True, FREEDRAWING_MODE, wxID_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): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS8, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add POU') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS9, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove POU') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS11, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Configuration') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITOREDITMENUITEMS12, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Configuration') etisserant@0: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCutMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCopyMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS5) etisserant@0: self.Bind(wx.EVT_MENU, self.OnPasteMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS6) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPouMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS8) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS9) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS11) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, etisserant@0: id=wxID_PLCOPENEDITOREDITMENUITEMS12) etisserant@0: etisserant@0: def _init_coll_menuBar1_Menus(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: 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): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORCONFIGMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Resource') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORCONFIGMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Resource') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddResourceMenu, etisserant@0: id=wxID_PLCOPENEDITORCONFIGMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, etisserant@0: id=wxID_PLCOPENEDITORCONFIGMENUITEMS1) etisserant@0: etisserant@0: def _init_coll_HelpMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORHELPMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text=u'About') etisserant@0: self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, etisserant@0: id=wxID_PLCOPENEDITORHELPMENUITEMS1) etisserant@0: etisserant@0: def _init_coll_FileMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Close Project') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS7, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS9, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Properties') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORFILEMENUITEMS11, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') etisserant@0: self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS3) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS5) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS6) etisserant@0: self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS7) lbessard@27: self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, lbessard@27: id=wxID_PLCOPENEDITORFILEMENUITEMS9) etisserant@0: self.Bind(wx.EVT_MENU, self.OnQuitMenu, etisserant@0: id=wxID_PLCOPENEDITORFILEMENUITEMS11) etisserant@0: etisserant@0: def _init_coll_SFCMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Transition') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Add Action') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Transition') etisserant@0: parent.Append(help='', id=wxID_PLCOPENEDITORSFCMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text=u'Remove Action') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu, etisserant@0: id=wxID_PLCOPENEDITORSFCMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPouActionMenu, etisserant@0: id=wxID_PLCOPENEDITORSFCMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemovePouTransitionMenu, etisserant@0: id=wxID_PLCOPENEDITORSFCMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRemovePouActionMenu, etisserant@0: id=wxID_PLCOPENEDITORSFCMENUITEMS3) etisserant@0: etisserant@0: def _init_utils(self): etisserant@0: # generated method, don't edit etisserant@0: self.menuBar1 = wx.MenuBar() etisserant@0: etisserant@0: self.FileMenu = wx.Menu(title=u'') etisserant@0: etisserant@0: self.EditMenu = wx.Menu(title=u'') etisserant@0: etisserant@0: self.HelpMenu = wx.Menu(title='') etisserant@0: etisserant@0: self.SFCMenu = wx.Menu(title='') etisserant@0: etisserant@0: self.ConfigMenu = wx.Menu(title='') etisserant@0: etisserant@0: self._init_coll_menuBar1_Menus(self.menuBar1) etisserant@0: 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): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.splitterWindow1, 0, border=0, flag=wxGROW) etisserant@0: lbessard@6: def _init_coll_EditorGridSizer_Items(self, parent): lbessard@6: # generated method, don't edit lbessard@6: lbessard@6: parent.AddWindow(self.ToolBar, 0, border=0, flag=wxGROW) lbessard@6: parent.AddWindow(self.TabsOpened, 0, border=0, flag=wxGROW) lbessard@6: etisserant@0: def _init_coll_MainGridSizer_Growables(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddGrowableCol(0) etisserant@0: parent.AddGrowableRow(0) etisserant@0: lbessard@6: def _init_coll_EditorGridSizer_Growables(self, parent): lbessard@6: # generated method, don't edit lbessard@6: lbessard@6: parent.AddGrowableCol(0) lbessard@6: parent.AddGrowableRow(1) lbessard@6: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) etisserant@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): etisserant@0: # generated method, don't edit etisserant@0: wx.Frame.__init__(self, id=wxID_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@7: lbessard@7: self.splitterWindow1 = wx.SplitterWindow(id=wxID_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@7: self.EditorPanel = wx.Panel(id=wxID_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@7: self.TabsOpened = wx.Notebook(id=wxID_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@7: self.OnPouSelectedChanged, id=wxID_PLCOPENEDITORTABSOPENED) lbessard@7: lbessard@7: self.ToolBar = wxToolBar(id=wxID_PLCOPENEDITORTOOLBAR, name='ToolBar', lbessard@7: parent=self.EditorPanel, pos=wx.Point(0, 0), size=wx.Size(0, 40), lbessard@7: style=wxTB_HORIZONTAL | wxNO_BORDER) lbessard@27: self.ToolBar.AddRadioTool(wxID_PLCOPENEDITORTOOLBARSELECTION, lbessard@7: wxBitmap(os.path.join(CWD, 'Images/select.png')), wxNullBitmap, "Select an object") lbessard@7: self.Bind(wx.EVT_TOOL, self.OnSelectionTool, lbessard@27: id=wxID_PLCOPENEDITORTOOLBARSELECTION) lbessard@7: lbessard@7: self.ProjectTree = wx.TreeCtrl(id=wxID_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@7: id=wxID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, etisserant@0: id=wxID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, etisserant@0: id=wxID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, etisserant@0: id=wxID_PLCOPENEDITORPROJECTTREE) etisserant@0: self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected, etisserant@0: id=wxID_PLCOPENEDITORPROJECTTREE) lbessard@6: self.splitterWindow1.SplitVertically(self.ProjectTree, self.EditorPanel, etisserant@0: 200) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: lbessard@9: self.TreeImageList = wxImageList(16, 16) lbessard@9: for language in LANGUAGES: lbessard@9: self.TreeImageList.Add(wxBitmap(os.path.join(CWD, 'Images/%s.png'%language))) lbessard@9: self.ProjectTree.SetImageList(self.TreeImageList) lbessard@9: etisserant@0: self.Controler = PLCControler() etisserant@0: etisserant@0: if fileOpen: etisserant@0: self.Controler.OpenXMLFile(fileOpen) etisserant@0: self.RefreshProjectTree() lbessard@3: lbessard@6: self.CurrentToolBar = [] lbessard@27: self.CurrentLanguage = "" lbessard@28: self.DrawingMode = FREEDRAWING_MODE lbessard@6: etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: lbessard@27: def GetDrawingMode(self): lbessard@27: return self.DrawingMode lbessard@27: 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@9: self.EditMenu.FindItemByPosition(1).Enable(False) lbessard@9: self.EditMenu.FindItemByPosition(2).Enable(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@27: def ShowProperties(self): lbessard@27: old_values = self.Controler.GetProjectProperties() lbessard@27: old_values["projectName"] = self.Controler.GetProjectName() lbessard@27: dialog = ProjectDialog(self) lbessard@27: dialog.SetValues(old_values) lbessard@27: if dialog.ShowModal() == wxID_OK: lbessard@27: new_values = dialog.GetValues() lbessard@27: projectname = new_values.pop("projectName") lbessard@27: new_values["creationDateTime"] = old_values["creationDateTime"] lbessard@27: self.Controler.SetProjectName(projectname) lbessard@27: self.Controler.SetProjectProperties(new_values) lbessard@27: self.RefreshProjectTree() lbessard@27: dialog.Destroy() lbessard@27: etisserant@0: def OnNewProjectMenu(self, event): etisserant@0: dialog = ProjectDialog(self) etisserant@0: if dialog.ShowModal() == wxID_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) etisserant@0: self.Controler.SetProjectProperties(values) 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() etisserant@0: dialog = wxFileDialog(self, "Choose a file", directory, "", "PLCOpen files (*.xml)|*.xml|All files|*.*", wxOPEN) etisserant@0: if dialog.ShowModal() == wxID_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() 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)) 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() 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@4: dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "", "ST files (*.st)|*.st|All files|*.*", wxSAVE|wxCHANGE_DIR) lbessard@4: if dialog.ShowModal() == wxID_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@4: message = wxMessageDialog(self, "Can't generate program to file %s!"%filepath, "Error", wxOK|wxICON_ERROR) lbessard@4: message.ShowModal() lbessard@4: message.Destroy() lbessard@4: else: lbessard@4: message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_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() 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@27: directory, filename = os.getcwd(), "%s.xml"%self.Controler.GetProjectName() etisserant@0: dialog = wxFileDialog(self, "Choose a file", directory, filename, "PLCOpen files (*.xml)|*.xml|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT) etisserant@0: if dialog.ShowModal() == wxID_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: etisserant@0: message = wxMessageDialog(self, "Can't save project to file %s!"%filepath, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() 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@6: if not isinstance(window, TextViewer): lbessard@6: window.SetMode(MODE_SELECTION) lbessard@27: self.ToolBar.ToggleTool(wxID_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@27: self.ResetToolToggle(wxID_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@27: self.ResetToolToggle(wxID_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): lbessard@27: self.ResetToolToggle(wxID_PLCOPENEDITORTOOLBARBLOCK) 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@27: self.ResetToolToggle(wxID_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@27: self.ResetToolToggle(wxID_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@27: self.ResetToolToggle(wxID_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: etisserant@0: self.TabsOpened.GetPage(selected).AddRung() etisserant@0: event.Skip() etisserant@0: lbessard@27: def OnCoilTool(self, event): lbessard@27: self.ResetToolToggle(wxID_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@27: self.ResetToolToggle(wxID_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@27: self.TabsOpened.GetPage(selected).AddContact() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnBranchTool(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).AddBranch() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnInitialStepTool(self, event): lbessard@27: self.ResetToolToggle(wxID_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@27: self.ResetToolToggle(wxID_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@27: self.TabsOpened.GetPage(selected).AddStep() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnActionBlockTool(self, event): lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.ResetToolToggle(wxID_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@27: self.TabsOpened.GetPage(selected).AddStepAction() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnTransitionTool(self, event): lbessard@27: self.ResetToolToggle(wxID_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@27: self.ResetToolToggle(wxID_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@27: self.TabsOpened.GetPage(selected).AddDivergence() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnJumpTool(self, event): lbessard@27: if self.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.ResetToolToggle(wxID_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@27: self.TabsOpened.GetPage(selected).AddJump() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnPouSelectedChanged(self, event): 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) 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@7: if self.ProjectTree.GetPyData(item) == ITEM_VARIABLE: lbessard@7: data = wxTextDataObject(self.ProjectTree.GetItemText(item)) lbessard@7: dragSource = wxDropSource(self.ProjectTree) lbessard@7: dragSource.SetData(data) lbessard@7: dragSource.DoDragDrop() lbessard@7: event.Skip() 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: etisserant@0: self.Controler.SetProjectName(new_name) etisserant@0: elif itemtype == ITEM_POU: lbessard@6: if new_name.upper() in self.Controler.GetProjectPouNames(): lbessard@6: message = "\"%s\" pou already exists!"%new_name lbessard@6: abort = True lbessard@6: elif new_name.upper() in self.Controler.GetProjectPouVariables(): lbessard@6: messageDialog = wxMessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wxYES_NO|wxICON_QUESTION) lbessard@6: if messageDialog.ShowModal() == wxID_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@6: if new_name.upper() in self.Controler.GetProjectPouNames(): lbessard@6: message = "A pou with \"%s\" as name exists!"%new_name lbessard@6: elif new_name.upper() 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@6: if new_name.upper() in self.Controler.GetProjectPouNames(): lbessard@6: message = "A pou with \"%s\" as name exists!"%new_name lbessard@6: elif new_name.upper() 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: elif itemtype == ITEM_VARIABLE: lbessard@6: category = self.ProjectTree.GetItemParent(item) lbessard@6: if self.ProjectTree.GetItemText(category) != 'Global': lbessard@6: category = self.ProjectTree.GetItemParent(category) lbessard@6: pou = self.ProjectTree.GetItemParent(category) lbessard@6: pou_name = self.ProjectTree.GetItemText(pou) lbessard@6: if new_name.upper() in self.Controler.GetProjectPouNames(): lbessard@6: message = "A pou with \"%s\" as name exists!"%new_name lbessard@6: elif new_name.upper() 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.ChangePouVariableName(pou_name, old_name, new_name) lbessard@6: self.RefreshTabsOpenedTitles() lbessard@6: if message or abort: lbessard@6: if message: lbessard@6: messageDialog = wxMessageDialog(self, message, "Error", wxOK|wxICON_ERROR) lbessard@6: messageDialog.ShowModal() lbessard@6: messageDialog.Destroy() etisserant@0: item = event.GetItem() etisserant@0: wxCallAfter(self.ProjectTree.EditLabel, item) etisserant@0: event.Veto() lbessard@6: else: lbessard@6: wxCallAfter(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() etisserant@0: elif data == ITEM_CLASS: etisserant@0: item = self.ProjectTree.GetItemParent(selected) etisserant@0: item_type = self.ProjectTree.GetPyData(item) lbessard@10: while item_type not in [ITEM_POU, ITEM_RESOURCE, ITEM_CONFIGURATION] and item.IsOk(): etisserant@0: item = self.ProjectTree.GetItemParent(item) etisserant@0: item_type = self.ProjectTree.GetPyData(item) lbessard@10: item_name = self.ProjectTree.GetItemText(item) lbessard@10: if item_type == ITEM_POU: lbessard@37: dialog = EditVariableDialog(self, item_name, self.Controler.GetPouType(item_name), self.Controler.PouIsUsed(item_name), name) lbessard@10: dialog.SetPouNames(self.Controler.GetProjectPouNames()) lbessard@10: values = {} lbessard@10: values["returnType"] = self.Controler.GetPouInterfaceReturnTypeByName(item_name) lbessard@10: values["data"] = self.Controler.GetPouInterfaceVarsByName(item_name) lbessard@10: dialog.SetValues(values) lbessard@10: if dialog.ShowModal() == wxID_OK: lbessard@37: new_values = dialog.GetValues() lbessard@37: if "returnType" in new_values: lbessard@37: self.Controler.SetPouInterfaceReturnType(item_name, new_values["returnType"]) lbessard@37: self.Controler.SetPouInterfaceVars(item_name, new_values["data"]) lbessard@37: pou_names = self.Controler.GetElementsOpenedNames() lbessard@37: if item_name in pou_names: lbessard@37: window = self.TabsOpened.GetPage(pou_names.index(item_name)) lbessard@37: if isinstance(window, TextViewer): lbessard@37: varlist = [] lbessard@37: if "returnType" in new_values: lbessard@37: varlist.append(name) lbessard@37: for var in new_values["data"]: lbessard@37: varlist.append(var["Name"]) lbessard@37: window.SetVariables(varlist) lbessard@10: dialog.Destroy() lbessard@10: self.RefreshProjectTree() lbessard@10: elif item_type == ITEM_CONFIGURATION: lbessard@10: dialog = EditVariableDialog(self, item_name, None, name) lbessard@10: dialog.SetPouNames(self.Controler.GetProjectPouNames()) lbessard@10: values = {"data" : self.Controler.GetConfigurationGlobalVars(item_name)} etisserant@0: dialog.SetValues(values) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: new_values = dialog.GetValues() lbessard@10: self.Controler.SetConfigurationGlobalVars(item_name, new_values["data"]) lbessard@10: dialog.Destroy() lbessard@10: self.RefreshProjectTree() lbessard@10: elif item_type == ITEM_RESOURCE: lbessard@10: config = self.ProjectTree.GetItemParent(item) lbessard@10: config_type = self.ProjectTree.GetPyData(config) lbessard@10: while config_type != ITEM_CONFIGURATION and config.IsOk(): lbessard@10: config = self.ProjectTree.GetItemParent(config) lbessard@10: config_type = self.ProjectTree.GetPyData(config) lbessard@10: if config.IsOk(): lbessard@10: config_name = self.ProjectTree.GetItemText(config) lbessard@10: dialog = EditVariableDialog(self, item_name, None, name) lbessard@10: values = {"data" : self.Controler.GetConfigurationResourceGlobalVars(config_name, item_name)} lbessard@10: dialog.SetValues(values) lbessard@10: if dialog.ShowModal() == wxID_OK: lbessard@10: new_values = dialog.GetValues() lbessard@10: self.Controler.SetConfigurationResourceGlobalVars(config_name, item_name, new_values["data"]) lbessard@10: dialog.Destroy() lbessard@10: self.RefreshProjectTree() etisserant@0: elif data in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: etisserant@0: if data == ITEM_POU: etisserant@0: idx = self.Controler.OpenElementEditing(name) etisserant@0: language = self.Controler.GetPouBodyType(name) etisserant@0: varlist = [] etisserant@0: returnType = self.Controler.GetPouInterfaceReturnTypeByName(name) etisserant@0: if returnType: etisserant@0: varlist.append(name) etisserant@0: vars = self.Controler.GetPouInterfaceVarsByName(name) etisserant@0: if vars: etisserant@0: for var in vars: etisserant@0: varlist.append(var["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) etisserant@0: language = self.Controler.GetTransitionBodyType(grandparent_name, name) etisserant@0: elif data == ITEM_ACTION: etisserant@0: idx = self.Controler.OpenPouActionEditing(grandparent_name, name) etisserant@0: language = self.Controler.GetActionBodyType(grandparent_name, name) etisserant@0: varlist = [name] etisserant@0: vars = self.Controler.GetPouInterfaceVarsByName(grandparent_name) etisserant@0: if vars: etisserant@0: for var in vars: etisserant@0: varlist.append(var["Name"]) etisserant@0: if idx != None: etisserant@0: if language == "FBD": lbessard@27: new_window = Viewer(self.TabsOpened, self, self.Controler) etisserant@0: elif language == "LD": etisserant@0: new_window = LD_Viewer(self.TabsOpened, self, self.Controler) etisserant@0: elif language == "SFC": etisserant@0: new_window = SFC_Viewer(self.TabsOpened, self, self.Controler) etisserant@0: elif language in ["IL", "ST"]: etisserant@0: new_window = TextViewer(self.TabsOpened, self, self.Controler) lbessard@8: new_window.SetTextSyntax(language) etisserant@0: if language == "IL": etisserant@0: new_window.SetKeywords(IL_KEYWORDS) etisserant@0: else: etisserant@0: new_window.SetKeywords(ST_KEYWORDS) etisserant@0: new_window.SetVariables(varlist) etisserant@0: new_window.SetFunctions(self.Controler.GetBlockTypes()) etisserant@0: else: etisserant@0: return etisserant@0: new_window.RefreshView() etisserant@0: self.TabsOpened.AddPage(new_window, "") etisserant@0: self.TabsOpened.SetSelection(idx) etisserant@0: self.RefreshTabsOpenedTitles() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: else: etisserant@0: if data == ITEM_POU: etisserant@0: idx = self.Controler.ChangeElementEditing(name) etisserant@0: elif data == ITEM_TRANSITION: etisserant@0: idx = self.Controler.ChangePouTransitionEditing(grandparent_name, name) etisserant@0: elif data == ITEM_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: elif data == ITEM_RESOURCE: etisserant@0: item = self.ProjectTree.GetItemParent(selected) etisserant@0: item_type = self.ProjectTree.GetPyData(item) etisserant@0: while item_type != ITEM_CONFIGURATION: etisserant@0: item = self.ProjectTree.GetItemParent(item) etisserant@0: item_type = self.ProjectTree.GetPyData(item) etisserant@0: config_name = self.ProjectTree.GetItemText(item) etisserant@0: idx = self.Controler.OpenConfigurationResourceEditing(config_name, name) etisserant@0: if idx != None: etisserant@0: new_window = ResourceEditor(self.TabsOpened, self, self.Controler) etisserant@0: new_window.RefreshView() etisserant@0: self.TabsOpened.AddPage(new_window, "") etisserant@0: self.TabsOpened.SetSelection(idx) etisserant@0: self.RefreshTabsOpenedTitles() etisserant@0: self.RefreshFileMenu() etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshToolBar() etisserant@0: else: etisserant@0: idx = self.Controler.ChangeConfigurationResourceEditing(parent_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: 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@27: self.ToolBar.AddRadioTool(id, wxBitmap(os.path.join(CWD, picture)), wxNullBitmap, help) lbessard@27: else: lbessard@27: self.ToolBar.AddSimpleTool(id, wxBitmap(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: etisserant@0: self.TabsOpened.GetPage(selected).Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCutMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).Cut() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCopyMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).Copy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnPasteMenu(self, event): etisserant@0: selected = self.TabsOpened.GetSelection() etisserant@0: if selected != -1: etisserant@0: self.TabsOpened.GetPage(selected).Paste() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPouMenu(self, event): etisserant@0: dialog = PouDialog(self) etisserant@0: dialog.SetPouNames(self.Controler.GetProjectPouNames()) etisserant@0: if dialog.ShowModal() == wxID_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() etisserant@0: dialog = wxSingleChoiceDialog(self, "Select POU to remove:", "POU Remove", pous, wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: selected = dialog.GetStringSelection() etisserant@0: if not self.Controler.PouIsUsed(selected): etisserant@0: self.Controler.ProjectRemovePou(selected) etisserant@0: for i in xrange(self.TabsOpened.GetPageCount()): etisserant@0: if self.TabsOpened.GetPageText(i) == selected: etisserant@0: self.TabsOpened.DeletePage(i) etisserant@0: self.RefreshProjectTree() etisserant@0: self.RefreshToolBar() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddConfigurationMenu(self, event): etisserant@0: dialog = wxTextEntryDialog(self, "Enter configuration name:", "Create new configuration", "", wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_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() etisserant@0: dialog = wxSingleChoiceDialog(self, "Select Configuration to remove:", "Configuration Remove", configs, wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_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): etisserant@0: dialog = PouTransitionDialog(self) etisserant@0: dialog.SetPous(self.Controler.GetSFCPous()) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: values = dialog.GetValues() etisserant@0: self.Controler.ProjectAddPouTransition(values["pouName"], values["transitionName"], values["language"]) etisserant@0: self.RefreshProjectTree() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemovePouTransitionMenu(self, event): etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPouActionMenu(self, event): etisserant@0: dialog = PouActionDialog(self) etisserant@0: dialog.SetPous(self.Controler.GetSFCPous()) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: values = dialog.GetValues() etisserant@0: self.Controler.ProjectAddPouAction(values["pouName"], values["actionName"], values["language"]) etisserant@0: self.RefreshProjectTree() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRemovePouActionMenu(self, event): 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) etisserant@0: dialog = wxTextEntryDialog(self, "Enter Resource name:", "Create new Resource", "", wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_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"] etisserant@0: dialog = wxSingleChoiceDialog(self, "Select Resource to remove:", "Resource Remove", resources, wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_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: etisserant@0: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_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: etisserant@0: [wxID_PROJECTDIALOG, wxID_PROJECTDIALOGMAINPANEL, etisserant@0: wxID_PROJECTDIALOGPROJECTNAME, wxID_PROJECTDIALOGCOMPANYNAME, etisserant@0: wxID_PROJECTDIALOGCOMPANYURL, wxID_PROJECTDIALOGPRODUCTNAME, etisserant@0: wxID_PROJECTDIALOGPRODUCTVERSION, wxID_PROJECTDIALOGPRODUCTRELEASE, etisserant@0: wxID_PROJECTDIALOGCONTENTDESCRIPTION, wxID_PROJECTDIALOGSTATICTEXT1, etisserant@0: wxID_PROJECTDIALOGSTATICTEXT2, wxID_PROJECTDIALOGSTATICTEXT3, etisserant@0: wxID_PROJECTDIALOGSTATICTEXT4, wxID_PROJECTDIALOGSTATICTEXT5, etisserant@0: wxID_PROJECTDIALOGSTATICTEXT6, wxID_PROJECTDIALOGSTATICTEXT7, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(16)] etisserant@0: etisserant@0: class ProjectDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_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: etisserant@0: self.MainPanel = wx.Panel(id=wxID_PROJECTDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(450, 400), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT1, etisserant@0: label='Project Name (required):', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.ProjectName = wx.TextCtrl(id=wxID_PROJECTDIALOGPROJECTNAME, etisserant@0: name='ProjectName', parent=self.MainPanel, pos=wx.Point(224, 24), etisserant@0: size=wx.Size(295, 24), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT2, etisserant@0: label='Company Name (required):', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 64), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.CompanyName = wx.TextCtrl(id=wxID_PROJECTDIALOGCOMPANYNAME, etisserant@0: name='CompanyName', parent=self.MainPanel, pos=wx.Point(224, 64), etisserant@0: size=wx.Size(295, 24), style=0) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT3, etisserant@0: label='Company URL (optional):', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 104), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.CompanyURL = wx.TextCtrl(id=wxID_PROJECTDIALOGCOMPANYURL, etisserant@0: name='CompanyURL', parent=self.MainPanel, pos=wx.Point(224, 104), etisserant@0: size=wx.Size(295, 24), style=0) etisserant@0: etisserant@0: self.staticText4 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT4, etisserant@0: label='Product Name (required):', name='staticText4', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 144), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.ProductName = wx.TextCtrl(id=wxID_PROJECTDIALOGPRODUCTNAME, etisserant@0: name='ProductName', parent=self.MainPanel, pos=wx.Point(224, 144), etisserant@0: size=wx.Size(295, 24), style=0) etisserant@0: etisserant@0: self.staticText5 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT5, etisserant@0: label='Product Version (required):', name='staticText5', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 184), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.ProductVersion = wx.TextCtrl(id=wxID_PROJECTDIALOGPRODUCTVERSION, etisserant@0: name='ProductVersion', parent=self.MainPanel, pos=wx.Point(224, 184), etisserant@0: size=wx.Size(295, 24), style=0) etisserant@0: etisserant@0: self.staticText6 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT6, etisserant@0: label='Product Release (optional):', name='staticText6', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 224), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.ProductRelease = wx.TextCtrl(id=wxID_PROJECTDIALOGPRODUCTRELEASE, etisserant@0: name='ProductRelease', parent=self.MainPanel, pos=wx.Point(224, 224), etisserant@0: size=wx.Size(295, 24), style=0) etisserant@0: etisserant@0: self.staticText7 = wx.StaticText(id=wxID_PROJECTDIALOGSTATICTEXT7, etisserant@0: label='Content Description (optional):', name='staticText7', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 264), size=wx.Size(215, 17), style=0) etisserant@0: etisserant@0: self.ContentDescription = wx.TextCtrl(id=wxID_PROJECTDIALOGCONTENTDESCRIPTION, etisserant@0: name='ProductRelease', parent=self.MainPanel, pos=wx.Point(224, 264), etisserant@0: size=wx.Size(295, 120), style=wxTE_MULTILINE) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@9: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: etisserant@0: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) etisserant@0: 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 etisserant@0: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: self.EndModal(wxID_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: etisserant@0: [wxID_POUDIALOG, wxID_POUDIALOGMAINPANEL, wxID_POUDIALOGPOUNAME, etisserant@0: wxID_POUDIALOGPOUTYPE, wxID_POUDIALOGLANGUAGE, wxID_POUDIALOGSTATICTEXT1, etisserant@0: wxID_POUDIALOGSTATICTEXT2, wxID_POUDIALOGSTATICTEXT3, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(8)] etisserant@0: etisserant@0: class PouDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_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: etisserant@0: self.MainPanel = wx.Panel(id=wxID_POUDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_POUDIALOGSTATICTEXT1, etisserant@0: label='POU Name:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.PouName = wx.TextCtrl(id=wxID_POUDIALOGPOUNAME, etisserant@0: name='POUName', parent=self.MainPanel, pos=wx.Point(104, 24), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_POUDIALOGSTATICTEXT2, etisserant@0: label='POU Type:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 64), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.PouType = wx.Choice(id=wxID_POUDIALOGPOUTYPE, etisserant@0: name='POUType', parent=self.MainPanel, pos=wx.Point(104, 64), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: EVT_CHOICE(self, wxID_POUDIALOGPOUTYPE, self.OnTypeChanged) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_POUDIALOGSTATICTEXT3, etisserant@0: label='Language:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 104), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.Language = wx.Choice(id=wxID_POUDIALOGLANGUAGE, etisserant@0: name='Language', parent=self.MainPanel, pos=wx.Point(104, 104), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@9: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) 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@6: etisserant@0: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) etisserant@0: 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 etisserant@0: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: elif not TestIdentifier(pou_name): etisserant@0: message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%pou_name, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: elif pou_name.upper() in IEC_KEYWORDS: etisserant@0: message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%pou_name, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: elif pou_name.upper() in self.PouNames: etisserant@0: message = wxMessageDialog(self, "\"%s\" pou already exists!"%pou_name, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: self.EndModal(wxID_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"]: etisserant@0: if option != "SFC" or self.PouType.GetStringSelection() == "program": etisserant@0: self.Language.Append(option) etisserant@0: if self.Language.FindString(selection) != wxNOT_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: 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: etisserant@0: [wxID_POUTRANSITIONDIALOG, wxID_POUTRANSITIONDIALOGMAINPANEL, etisserant@0: wxID_POUTRANSITIONDIALOGPOUNAME, wxID_POUTRANSITIONDIALOGTRANSITIONNAME, etisserant@0: wxID_POUTRANSITIONDIALOGLANGUAGE, wxID_POUTRANSITIONDIALOGSTATICTEXT1, etisserant@0: wxID_POUTRANSITIONDIALOGSTATICTEXT2, wxID_POUTRANSITIONDIALOGSTATICTEXT3, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(8)] etisserant@0: etisserant@0: class PouTransitionDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_POUTRANSITIONDIALOG, etisserant@0: name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Create a new project') etisserant@0: self.SetClientSize(wx.Size(350, 200)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_POUTRANSITIONDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(350, 200), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT1, etisserant@0: label='POU Name:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0) etisserant@0: etisserant@0: self.PouName = wx.Choice(id=wxID_POUTRANSITIONDIALOGPOUNAME, etisserant@0: name='POUName', parent=self.MainPanel, pos=wx.Point(154, 24), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT2, etisserant@0: label='Transition Name:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0) etisserant@0: etisserant@0: self.TransitionName = wx.TextCtrl(id=wxID_POUTRANSITIONDIALOGTRANSITIONNAME, etisserant@0: name='TransitionName', parent=self.MainPanel, pos=wx.Point(154, 64), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_POUTRANSITIONDIALOGSTATICTEXT3, etisserant@0: label='Language:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 104), size=wx.Size(145, 17), style=0) etisserant@0: etisserant@0: self.Language = wx.Choice(id=wxID_POUTRANSITIONDIALOGLANGUAGE, etisserant@0: name='Language', parent=self.MainPanel, pos=wx.Point(154, 104), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@9: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: etisserant@0: for option in ["IL","ST","LD","FBD"]: etisserant@0: self.Language.Append(option) etisserant@0: etisserant@0: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) etisserant@0: etisserant@0: def OnOK(self, event): etisserant@0: error = [] etisserant@0: if self.PouName.GetStringSelection() == "": etisserant@0: error.append("POU Name") 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 etisserant@0: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: self.EndModal(wxID_OK) etisserant@0: etisserant@0: def SetPous(self, pous): etisserant@0: for pou in pous: etisserant@0: self.PouName.Append(pou) etisserant@0: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): etisserant@0: if item == "pouName": etisserant@0: self.PouName.SetStringSelection(value) etisserant@0: elif 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["pouName"] = self.PouName.GetStringSelection() 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: etisserant@0: [wxID_POUACTIONDIALOG, wxID_POUACTIONDIALOGMAINPANEL, etisserant@0: wxID_POUACTIONDIALOGPOUNAME, wxID_POUACTIONDIALOGACTIONNAME, etisserant@0: wxID_POUACTIONDIALOGLANGUAGE, wxID_POUACTIONDIALOGSTATICTEXT1, etisserant@0: wxID_POUACTIONDIALOGSTATICTEXT2, wxID_POUACTIONDIALOGSTATICTEXT3, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(8)] etisserant@0: etisserant@0: class PouActionDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_POUACTIONDIALOG, etisserant@0: name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Create a new project') etisserant@0: self.SetClientSize(wx.Size(320, 200)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_POUACTIONDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(350, 200), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT1, etisserant@0: label='POU Name:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(145, 17), style=0) etisserant@0: etisserant@0: self.PouName = wx.Choice(id=wxID_POUACTIONDIALOGPOUNAME, etisserant@0: name='POUName', parent=self.MainPanel, pos=wx.Point(124, 24), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT2, etisserant@0: label='Action Name:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 64), size=wx.Size(145, 17), style=0) etisserant@0: etisserant@0: self.ActionName = wx.TextCtrl(id=wxID_POUACTIONDIALOGACTIONNAME, etisserant@0: name='ActionName', parent=self.MainPanel, pos=wx.Point(124, 64), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_POUACTIONDIALOGSTATICTEXT3, etisserant@0: label='Language:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 104), size=wx.Size(145, 17), style=0) etisserant@0: etisserant@0: self.Language = wx.Choice(id=wxID_POUACTIONDIALOGLANGUAGE, etisserant@0: name='Language', parent=self.MainPanel, pos=wx.Point(124, 104), etisserant@0: size=wx.Size(150, 24), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) lbessard@9: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: etisserant@0: for option in ["IL","ST","LD","FBD"]: etisserant@0: self.Language.Append(option) etisserant@0: etisserant@0: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) etisserant@0: etisserant@0: def OnOK(self, event): etisserant@0: error = [] etisserant@0: if self.PouName.GetStringSelection() == "": etisserant@0: error.append("POU Name") etisserant@0: if self.ActionName.GetValue() == "": 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 etisserant@0: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: self.EndModal(wxID_OK) etisserant@0: etisserant@0: def SetPous(self, pous): etisserant@0: for pou in pous: etisserant@0: self.PouName.Append(pou) etisserant@0: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): etisserant@0: if item == "pouName": etisserant@0: self.PouName.SetStringSelection(value) etisserant@0: elif 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["pouName"] = self.PouName.GetStringSelection() etisserant@0: values["actionName"] = self.ActionName.GetValue() etisserant@0: values["language"] = self.Language.GetStringSelection() etisserant@0: return values etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Pou Interface Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: class VariableTable(wxPyGridTableBase): etisserant@0: etisserant@0: """ etisserant@0: A custom wxGrid Table using user supplied data etisserant@0: """ etisserant@0: def __init__(self, parent, data, colnames): etisserant@0: # The base class must be initialized *first* etisserant@0: wxPyGridTableBase.__init__(self) etisserant@0: self.data = data 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(): etisserant@0: name = str(self.data[row].get(self.GetColLabelValue(col), "")) etisserant@0: return name etisserant@0: etisserant@0: def GetValueByName(self, row, colname): etisserant@0: return self.data[row].get(colname) etisserant@0: etisserant@0: def SetValue(self, row, col, value): etisserant@0: if col < len(self.colnames): etisserant@0: self.data[row][self.GetColLabelValue(col)] = value etisserant@0: etisserant@0: def ResetView(self, grid): etisserant@0: """ etisserant@0: (wxGrid) -> 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 [ etisserant@0: (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), etisserant@0: (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), etisserant@0: ]: etisserant@0: if new < current: etisserant@0: msg = wxGridTableMessage(self,delmsg,new,current-new) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: elif new > current: etisserant@0: msg = wxGridTableMessage(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 etisserant@0: msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: etisserant@0: def _updateColAttrs(self, grid): etisserant@0: """ etisserant@0: wxGrid -> 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()): etisserant@0: attr = wxGridCellAttr() etisserant@0: attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_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) etisserant@0: grid.SetReadOnly(row, col, False) lbessard@37: if colname == "Name": lbessard@37: if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: etisserant@0: grid.SetReadOnly(row, col, True) etisserant@0: else: lbessard@37: editor = wxGridCellTextEditor() lbessard@37: renderer = wxGridCellStringRenderer() lbessard@37: if colname in ["Initial Value","Location"]: lbessard@37: editor = wxGridCellTextEditor() lbessard@37: renderer = wxGridCellStringRenderer() lbessard@37: elif colname == "Class": lbessard@37: if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: lbessard@37: grid.SetReadOnly(row, col, True) lbessard@37: else: lbessard@37: editor = wxGridCellChoiceEditor() lbessard@37: excluded = [] lbessard@37: if self.Parent.PouIsUsed: lbessard@37: excluded.extend(["Input","Output","InOut"]) lbessard@37: editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) etisserant@0: elif colname == "Type": lbessard@37: if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: lbessard@37: grid.SetReadOnly(row, col, True) lbessard@37: else: lbessard@37: editor = wxGridCellChoiceEditor() lbessard@37: editor.SetParameters(self.Parent.TypeList) etisserant@0: elif colname in ["Retain", "Constant"]: etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.OptionList) etisserant@0: etisserant@0: grid.SetCellEditor(row, col, editor) etisserant@0: grid.SetCellRenderer(row, col, renderer) etisserant@0: etisserant@0: grid.SetCellBackgroundColour(row, col, wxWHITE) 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: etisserant@0: [wxID_EDITVARIABLEDIALOG, wxID_EDITVARIABLEDIALOGMAINPANEL, etisserant@0: wxID_EDITVARIABLEDIALOGVARIABLESGRID, wxID_EDITVARIABLEDIALOGRETURNTYPE, etisserant@0: wxID_EDITVARIABLEDIALOGCLASSFILTER, wxID_EDITVARIABLEDIALOGADDBUTTON, etisserant@0: wxID_EDITVARIABLEDIALOGDELETEBUTTON, wxID_EDITVARIABLEDIALOGUPBUTTON, etisserant@0: wxID_EDITVARIABLEDIALOGDOWNBUTTON, wxID_EDITVARIABLEDIALOGSTATICTEXT1, etisserant@0: wxID_EDITVARIABLEDIALOGSTATICTEXT2, wxID_EDITVARIABLEDIALOGSTATICTEXT3, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(12)] etisserant@0: etisserant@0: class EditVariableDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt, name): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_EDITVARIABLEDIALOG, etisserant@0: name='EditVariableDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(600, 440), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Edit variables of %s'%name) etisserant@0: self.SetClientSize(wx.Size(600, 440)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_EDITVARIABLEDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(600, 440), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT1, etisserant@0: label='Return Type:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 29), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.ReturnType = wx.Choice(id=wxID_EDITVARIABLEDIALOGRETURNTYPE, etisserant@0: name='ReturnType', parent=self.MainPanel, pos=wx.Point(124, 24), etisserant@0: size=wx.Size(145, 24), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT2, etisserant@0: label='Class Filter:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(324, 29), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.ClassFilter = wx.Choice(id=wxID_EDITVARIABLEDIALOGCLASSFILTER, etisserant@0: name='ClassFilter', parent=self.MainPanel, pos=wx.Point(424, 24), etisserant@0: size=wx.Size(145, 24), style=0) etisserant@0: EVT_CHOICE(self, wxID_EDITVARIABLEDIALOGCLASSFILTER, self.OnClassFilter) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_EDITVARIABLEDIALOGSTATICTEXT3, etisserant@0: label='Variables:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 60), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.VariablesGrid = wx.grid.Grid(id=wxID_EDITVARIABLEDIALOGVARIABLESGRID, etisserant@0: name='VariablesGrid', parent=self.MainPanel, pos=wx.Point(24, 80), etisserant@0: size=wx.Size(550, 250), style=wxVSCROLL) 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')) etisserant@0: self.VariablesGrid.DisableDragGridSize() etisserant@0: self.VariablesGrid.EnableScrolling(False, True) 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) etisserant@0: etisserant@0: self.AddButton = wx.Button(id=wxID_EDITVARIABLEDIALOGADDBUTTON, label='Add', etisserant@0: name='AddButton', parent=self.MainPanel, pos=wx.Point(345, 340), etisserant@0: size=wx.Size(72, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGADDBUTTON, self.OnAddButton) etisserant@0: etisserant@0: self.DeleteButton = wx.Button(id=wxID_EDITVARIABLEDIALOGDELETEBUTTON, label='Delete', etisserant@0: name='DeleteButton', parent=self.MainPanel, pos=wx.Point(425, 340), etisserant@0: size=wx.Size(72, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGDELETEBUTTON, self.OnDeleteButton) etisserant@0: etisserant@0: self.UpButton = wx.Button(id=wxID_EDITVARIABLEDIALOGUPBUTTON, label='^', etisserant@0: name='UpButton', parent=self.MainPanel, pos=wx.Point(505, 340), etisserant@0: size=wx.Size(32, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGUPBUTTON, self.OnUpButton) etisserant@0: etisserant@0: self.DownButton = wx.Button(id=wxID_EDITVARIABLEDIALOGDOWNBUTTON, label='v', etisserant@0: name='DownButton', parent=self.MainPanel, pos=wx.Point(545, 340), etisserant@0: size=wx.Size(32, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_EDITVARIABLEDIALOGDOWNBUTTON, self.OnDownButton) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: lbessard@37: def __init__(self, parent, name, pou_type, pou_is_used, filter = "All"): etisserant@0: self._init_ctrls(parent, name) lbessard@9: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: self.Filter = filter lbessard@37: self.PouIsUsed = pou_is_used 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: etisserant@0: if pou_type: lbessard@37: self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} lbessard@11: self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No"} etisserant@0: else: lbessard@11: self.DefaultTypes = {"All" : "Global"} lbessard@11: self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No"} etisserant@0: if not pou_type or pou_type == "program": etisserant@0: self.Table = VariableTable(self, [], ["Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"]) etisserant@0: if pou_type: 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"] etisserant@0: self.ColSizes = [80, 70, 80, 80, 80, 60, 70] etisserant@0: self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_CENTER] etisserant@0: else: etisserant@0: self.Table = VariableTable(self, [], ["Name", "Class", "Type", "Initial Value", "Retain", "Constant"]) etisserant@0: self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"] etisserant@0: self.ColSizes = [120, 70, 80, 120, 60, 70] etisserant@0: self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_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() lbessard@37: self.RefreshButtons() etisserant@0: etisserant@0: self.OptionList = "Yes,No" lbessard@28: self.TypeList = ",".join([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) etisserant@0: self.staticText2.Hide() etisserant@0: self.ReturnType.Hide() etisserant@0: etisserant@0: self.VariablesGrid.SetTable(self.Table) etisserant@0: self.VariablesGrid.SetRowLabelSize(0) etisserant@0: etisserant@0: self.Table.ResetView(self.VariablesGrid) etisserant@0: lbessard@6: self.PouNames = [] lbessard@6: lbessard@37: if self.PouIsUsed: lbessard@37: wxCallAfter(self.WarningMessage, name) lbessard@37: etisserant@0: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) etisserant@0: lbessard@37: def WarningMessage(self, name): lbessard@37: message = wxMessageDialog(self, "\"%s\" is used by one or more POUs. Its interface can't be changed!"%name, "WARNING", wxOK|wxICON_EXCLAMATION) lbessard@37: message.ShowModal() lbessard@37: message.Destroy() lbessard@37: etisserant@0: def OnOK(self, event): etisserant@0: self.VariablesGrid.SetGridCursor(0, 0) etisserant@0: error = [] etisserant@0: if self.ReturnType.IsEnabled() and self.ReturnType.GetStringSelection() == "": etisserant@0: error.append("Return Type") 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 etisserant@0: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: self.EndModal(wxID_OK) etisserant@0: 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@37: table_length = len(self.Table.data) lbessard@37: row_class = None lbessard@37: if table_length and self.PouIsUsed: lbessard@37: row = self.VariablesGrid.GetGridCursorRow() lbessard@37: row_class = self.Table.GetValueByName(row, "Class") lbessard@37: self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]) lbessard@37: self.DeleteButton.Enable(table_length > 0 and row_class not in ["Input", "Output", "InOut"]) lbessard@37: self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) lbessard@37: self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) lbessard@37: 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@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@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@6: message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wxOK|wxICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: elif value.upper() in IEC_KEYWORDS: lbessard@6: message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wxOK|wxICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: elif value.upper() in self.PouNames: lbessard@6: message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wxOK|wxICON_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@6: message = wxMessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wxOK|wxICON_ERROR) lbessard@6: message.ShowModal() lbessard@6: message.Destroy() lbessard@6: event.Veto() lbessard@6: else: lbessard@6: event.Skip() lbessard@6: else: lbessard@6: event.Skip() lbessard@6: lbessard@37: def OnVariablesGridSelectCell(self, event): lbessard@37: wxCallAfter(self.RefreshButtons) lbessard@37: event.Skip() lbessard@37: lbessard@6: def SetPouNames(self, pou_names): lbessard@6: self.PouNames = [pou_name.upper() for pou_name in pou_names] lbessard@6: etisserant@0: def SetValues(self, values): etisserant@0: for item, value in values.items(): etisserant@0: if item == "returnType" and value and self.ReturnType.IsEnabled(): etisserant@0: self.ReturnType.SetStringSelection(value) etisserant@0: if item == "data": etisserant@0: self.Values = value etisserant@0: self.RefreshValues() lbessard@12: 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@12: etisserant@0: def RefreshValues(self): lbessard@37: if len(self.Table.data) > 0: lbessard@37: self.VariablesGrid.SetGridCursor(0, 0) 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) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: if self.ReturnType.IsEnabled(): etisserant@0: values["returnType"] = self.ReturnType.GetStringSelection() lbessard@12: values["data"] = self.Values etisserant@0: return values etisserant@0: 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): etisserant@0: message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_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: etisserant@0: def wxAddExceptHook(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__': etisserant@0: app = wxPySimpleApp() etisserant@0: wxInitAllImageHandlers() etisserant@0: etisserant@0: # Install a exception handle for bug reports etisserant@0: wxAddExceptHook(os.getcwd(),__version__) etisserant@0: etisserant@0: frame = PLCOpenEditor(None) etisserant@0: etisserant@0: frame.Show() etisserant@0: app.MainLoop() etisserant@0: