author | lbessard |
Tue, 27 Nov 2007 12:57:39 +0100 | |
changeset 123 | 62f93b8df816 |
parent 122 | e6faee0c271b |
child 125 | 394d9f168258 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
5 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
0 | 20 |
# |
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
from time import localtime |
|
26 |
from datetime import datetime |
|
120 | 27 |
import wx, wx.grid |
28 |
||
29 |
if wx.VERSION >= (2, 8, 0): |
|
30 |
import wx.aui |
|
0 | 31 |
|
32 |
from SFCViewer import * |
|
33 |
from LDViewer import * |
|
34 |
from Viewer import * |
|
27 | 35 |
from TextViewer import * |
36 |
from RessourceEditor import * |
|
0 | 37 |
from PLCControler import * |
38 |
from plcopen import OpenPDFDoc |
|
107 | 39 |
from plcopen.structures import LOCATIONDATATYPES |
0 | 40 |
|
41 |
import os, re, platform, sys, time, traceback, getopt |
|
42 |
||
43 |
__version__ = "$Revision$" |
|
44 |
||
80 | 45 |
CWD = os.path.split(__file__)[0] |
0 | 46 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
47 |
[ID_PLCOPENEDITOR, ID_PLCOPENEDITORPROJECTTREE, |
121 | 48 |
ID_PLCOPENEDITORMAINSPLITTER, ID_PLCOPENEDITORSECONDSPLITTER, |
49 |
ID_PLCOPENEDITOREDITORPANEL, ID_PLCOPENEDITORTABSOPENED, |
|
50 |
ID_PLCOPENEDITORTOOLBAR, ID_PLCOPENEDITORDEFAULTTOOLBAR, |
|
51 |
ID_PLCOPENEDITORSFCTOOLBAR, ID_PLCOPENEDITORFBDTOOLBAR, |
|
52 |
ID_PLCOPENEDITORLDTOOLBAR, |
|
53 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
6 | 54 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
55 |
[ID_PLCOPENEDITORFILEMENUITEMS0, ID_PLCOPENEDITORFILEMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
56 |
ID_PLCOPENEDITORFILEMENUITEMS2, ID_PLCOPENEDITORFILEMENUITEMS3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
57 |
ID_PLCOPENEDITORFILEMENUITEMS5, ID_PLCOPENEDITORFILEMENUITEMS6, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
58 |
ID_PLCOPENEDITORFILEMENUITEMS7, ID_PLCOPENEDITORFILEMENUITEMS9, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
59 |
ID_PLCOPENEDITORFILEMENUITEMS11, |
0 | 60 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
61 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
62 |
[ID_PLCOPENEDITORHELPMENUITEMS0, ID_PLCOPENEDITORHELPMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
63 |
ID_PLCOPENEDITORHELPMENUITEMS2, ID_PLCOPENEDITORHELPMENUITEMS3, |
0 | 64 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
65 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
66 |
[ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
67 |
ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, |
0 | 68 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(4)] |
69 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
70 |
[ID_PLCOPENEDITORCONFIGMENUITEMS0, ID_PLCOPENEDITORCONFIGMENUITEMS1, |
0 | 71 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(2)] |
72 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
73 |
[ID_PLCOPENEDITOREDITMENUITEMS0, ID_PLCOPENEDITOREDITMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
74 |
ID_PLCOPENEDITOREDITMENUITEMS11, ID_PLCOPENEDITOREDITMENUITEMS12, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
75 |
ID_PLCOPENEDITOREDITMENUITEMS2, ID_PLCOPENEDITOREDITMENUITEMS4, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
76 |
ID_PLCOPENEDITOREDITMENUITEMS5, ID_PLCOPENEDITOREDITMENUITEMS6, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
77 |
ID_PLCOPENEDITOREDITMENUITEMS8, ID_PLCOPENEDITOREDITMENUITEMS9, |
0 | 78 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(10)] |
79 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
80 |
[ID_PLCOPENEDITORSFCMENUITEMS0, ID_PLCOPENEDITORSFCMENUITEMS1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
81 |
ID_PLCOPENEDITORSFCMENUITEMS2, ID_PLCOPENEDITORSFCMENUITEMS3, |
0 | 82 |
] = [wx.NewId() for _init_coll_SFCMenu_Items in range(4)] |
83 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
84 |
[ID_PLCOPENEDITORCONFIGMENUITEMS0, ID_PLCOPENEDITORCONFIGMENUITEMS1, |
0 | 85 |
] = [wx.NewId() for _init_coll_ConfigMenu_Items in range(2)] |
86 |
||
27 | 87 |
|
88 |
#------------------------------------------------------------------------------- |
|
89 |
# ToolBars definitions |
|
90 |
#------------------------------------------------------------------------------- |
|
91 |
||
92 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
93 |
[ID_PLCOPENEDITORTOOLBARSELECTION, ID_PLCOPENEDITORTOOLBARCOMMENT, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
94 |
ID_PLCOPENEDITORTOOLBARVARIABLE, ID_PLCOPENEDITORTOOLBARBLOCK, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
95 |
ID_PLCOPENEDITORTOOLBARCONNECTION, ID_PLCOPENEDITORTOOLBARWIRE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
96 |
ID_PLCOPENEDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITORTOOLBARRUNG, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
97 |
ID_PLCOPENEDITORTOOLBARCOIL, ID_PLCOPENEDITORTOOLBARCONTACT, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
98 |
ID_PLCOPENEDITORTOOLBARBRANCH, ID_PLCOPENEDITORTOOLBARINITIALSTEP, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
99 |
ID_PLCOPENEDITORTOOLBARSTEP, ID_PLCOPENEDITORTOOLBARTRANSITION, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
100 |
ID_PLCOPENEDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITORTOOLBARDIVERGENCE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
101 |
ID_PLCOPENEDITORTOOLBARJUMP, |
27 | 102 |
] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(17)] |
103 |
||
104 |
ToolBarItems = { |
|
95 | 105 |
"FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "comment.png", "Create a new comment"), |
106 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "variable.png", "Create a new variable"), |
|
107 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "block.png", "Create a new block"), |
|
108 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "connection.png", "Create a new connection"), |
|
109 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "wire.png", "Create a new wire")], |
|
110 |
"LD" : [(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "comment.png", "Create a new comment"), |
|
111 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "powerrail.png", "Create a new power rail"), |
|
112 |
(False, DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARRUNG, "OnRungTool", "rung.png", "Create a new rung"), |
|
113 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOIL, "OnCoilTool", "coil.png", "Create a new coil"), |
|
114 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "contact.png", "Create a new contact"), |
|
115 |
(False, DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBRANCH, "OnBranchTool", "branch.png", "Create a new branch"), |
|
116 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "variable.png", "Create a new variable"), |
|
117 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "block.png", "Create a new block"), |
|
118 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "connection.png", "Create a new connection"), |
|
119 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "wire.png", "Create a new wire")], |
|
120 |
"SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", "comment.png", "Create a new comment"), |
|
121 |
(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARINITIALSTEP, "OnInitialStepTool", "initial_step.png", "Create a new initial step"), |
|
122 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARSTEP, "OnStepTool", "step.png", "Create a new step"), |
|
123 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARTRANSITION, "OnTransitionTool", "transition.png", "Create a new transition"), |
|
124 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", "action.png", "Create a new action block"), |
|
125 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARDIVERGENCE, "OnDivergenceTool", "divergence.png", "Create a new divergence"), |
|
126 |
(False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, ID_PLCOPENEDITORTOOLBARJUMP, "OnJumpTool", "jump.png", "Create a new jump"), |
|
127 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", "variable.png", "Create a new variable"), |
|
128 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", "block.png", "Create a new block"), |
|
129 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", "connection.png", "Create a new connection"), |
|
130 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", "powerrail.png", "Create a new power rail"), |
|
131 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", "contact.png", "Create a new contact"), |
|
132 |
(True, FREEDRAWING_MODE, ID_PLCOPENEDITORTOOLBARWIRE, "OnWireTool", "wire.png", "Create a new wire")], |
|
82 | 133 |
"ST" : [], |
134 |
"IL" : [] |
|
27 | 135 |
} |
136 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
137 |
def AppendMenu(parent, help, id, kind, text): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
138 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
139 |
parent.Append(help=help, id=id, kind=kind, text=text) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
140 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
141 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
142 |
|
121 | 143 |
if wx.VERSION >= (2, 8, 0): |
144 |
base_class = wx.aui.AuiMDIParentFrame |
|
145 |
else: |
|
146 |
base_class = wx.Frame |
|
147 |
||
148 |
class PLCOpenEditor(base_class): |
|
0 | 149 |
_custom_classes = {'wx.SashWindow' : ['Viewer']} |
150 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
151 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
152 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
153 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
154 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
155 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
156 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
157 |
|
0 | 158 |
def _init_coll_EditMenu_Items(self, parent): |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
159 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS0, |
0 | 160 |
kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
161 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS1, |
0 | 162 |
kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
163 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS2, |
0 | 164 |
kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y') |
165 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
166 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS4, |
0 | 167 |
kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
168 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS5, |
0 | 169 |
kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
170 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS6, |
0 | 171 |
kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V') |
172 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
173 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS8, |
0 | 174 |
kind=wx.ITEM_NORMAL, text=u'Add POU') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
175 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS9, |
0 | 176 |
kind=wx.ITEM_NORMAL, text=u'Remove POU') |
177 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
178 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS11, |
0 | 179 |
kind=wx.ITEM_NORMAL, text=u'Add Configuration') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
180 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS12, |
0 | 181 |
kind=wx.ITEM_NORMAL, text=u'Remove Configuration') |
182 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
183 |
id=ID_PLCOPENEDITOREDITMENUITEMS0) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
184 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
185 |
id=ID_PLCOPENEDITOREDITMENUITEMS1) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
186 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
187 |
id=ID_PLCOPENEDITOREDITMENUITEMS2) |
0 | 188 |
self.Bind(wx.EVT_MENU, self.OnCutMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
189 |
id=ID_PLCOPENEDITOREDITMENUITEMS4) |
0 | 190 |
self.Bind(wx.EVT_MENU, self.OnCopyMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
191 |
id=ID_PLCOPENEDITOREDITMENUITEMS5) |
0 | 192 |
self.Bind(wx.EVT_MENU, self.OnPasteMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
193 |
id=ID_PLCOPENEDITOREDITMENUITEMS6) |
0 | 194 |
self.Bind(wx.EVT_MENU, self.OnAddPouMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
195 |
id=ID_PLCOPENEDITOREDITMENUITEMS8) |
0 | 196 |
self.Bind(wx.EVT_MENU, self.OnRemovePouMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
197 |
id=ID_PLCOPENEDITOREDITMENUITEMS9) |
0 | 198 |
self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
199 |
id=ID_PLCOPENEDITOREDITMENUITEMS11) |
0 | 200 |
self.Bind(wx.EVT_MENU, self.OnRemoveConfigurationMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
201 |
id=ID_PLCOPENEDITOREDITMENUITEMS12) |
0 | 202 |
|
203 |
def _init_coll_menuBar1_Menus(self, parent): |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
204 |
if self.ModeSolo: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
205 |
parent.Append(menu=self.FileMenu, title=u'File') |
0 | 206 |
parent.Append(menu=self.EditMenu, title=u'Edit') |
207 |
parent.Append(menu=self.HelpMenu, title=u'Help') |
|
208 |
||
209 |
def _init_coll_ConfigMenu_Items(self, parent): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
210 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS0, |
0 | 211 |
kind=wx.ITEM_NORMAL, text=u'Add Resource') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
212 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS1, |
0 | 213 |
kind=wx.ITEM_NORMAL, text=u'Remove Resource') |
214 |
self.Bind(wx.EVT_MENU, self.OnAddResourceMenu, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
215 |
id=ID_PLCOPENEDITORCONFIGMENUITEMS0) |
0 | 216 |
self.Bind(wx.EVT_MENU, self.OnRemoveResourceMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
217 |
id=ID_PLCOPENEDITORCONFIGMENUITEMS1) |
0 | 218 |
|
219 |
def _init_coll_HelpMenu_Items(self, parent): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
220 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS0, |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
221 |
kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1') |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
222 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS1, |
0 | 223 |
kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
224 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS2, |
0 | 225 |
kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
226 |
if self.ModeSolo: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
227 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS3, |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
228 |
kind=wx.ITEM_NORMAL, text=u'About') |
0 | 229 |
self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
230 |
id=ID_PLCOPENEDITORHELPMENUITEMS1) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
231 |
|
0 | 232 |
def _init_coll_FileMenu_Items(self, parent): |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
233 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS0, |
0 | 234 |
kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
235 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS1, |
0 | 236 |
kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
237 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS2, |
0 | 238 |
kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
239 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS3, |
0 | 240 |
kind=wx.ITEM_NORMAL, text=u'Close Project') |
241 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
242 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS5, |
0 | 243 |
kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
244 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS6, |
0 | 245 |
kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
246 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS7, |
0 | 247 |
kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G') |
248 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
249 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS9, |
0 | 250 |
kind=wx.ITEM_NORMAL, text=u'Properties') |
251 |
parent.AppendSeparator() |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
252 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS11, |
0 | 253 |
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') |
254 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
255 |
id=ID_PLCOPENEDITORFILEMENUITEMS0) |
0 | 256 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
257 |
id=ID_PLCOPENEDITORFILEMENUITEMS1) |
0 | 258 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
259 |
id=ID_PLCOPENEDITORFILEMENUITEMS2) |
0 | 260 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
261 |
id=ID_PLCOPENEDITORFILEMENUITEMS3) |
0 | 262 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
263 |
id=ID_PLCOPENEDITORFILEMENUITEMS5) |
0 | 264 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
265 |
id=ID_PLCOPENEDITORFILEMENUITEMS6) |
0 | 266 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
267 |
id=ID_PLCOPENEDITORFILEMENUITEMS7) |
27 | 268 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
269 |
id=ID_PLCOPENEDITORFILEMENUITEMS9) |
0 | 270 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
271 |
id=ID_PLCOPENEDITORFILEMENUITEMS11) |
0 | 272 |
|
273 |
def _init_coll_SFCMenu_Items(self, parent): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
274 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS0, |
0 | 275 |
kind=wx.ITEM_NORMAL, text=u'Add Transition') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
276 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS1, |
0 | 277 |
kind=wx.ITEM_NORMAL, text=u'Add Action') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
278 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS2, |
0 | 279 |
kind=wx.ITEM_NORMAL, text=u'Remove Transition') |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
280 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS3, |
0 | 281 |
kind=wx.ITEM_NORMAL, text=u'Remove Action') |
282 |
self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu, |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
283 |
id=ID_PLCOPENEDITORSFCMENUITEMS0) |
0 | 284 |
self.Bind(wx.EVT_MENU, self.OnAddPouActionMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
285 |
id=ID_PLCOPENEDITORSFCMENUITEMS1) |
0 | 286 |
self.Bind(wx.EVT_MENU, self.OnRemovePouTransitionMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
287 |
id=ID_PLCOPENEDITORSFCMENUITEMS2) |
0 | 288 |
self.Bind(wx.EVT_MENU, self.OnRemovePouActionMenu, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
289 |
id=ID_PLCOPENEDITORSFCMENUITEMS3) |
0 | 290 |
|
291 |
def _init_utils(self): |
|
292 |
self.menuBar1 = wx.MenuBar() |
|
293 |
||
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
294 |
if self.ModeSolo: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
295 |
self.FileMenu = wx.Menu(title='') |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
296 |
else: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
297 |
self.FileMenu = None |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
298 |
self.EditMenu = wx.Menu(title='') |
0 | 299 |
self.HelpMenu = wx.Menu(title='') |
300 |
self.SFCMenu = wx.Menu(title='') |
|
301 |
self.ConfigMenu = wx.Menu(title='') |
|
302 |
||
303 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
304 |
if self.ModeSolo: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
305 |
self._init_coll_FileMenu_Items(self.FileMenu) |
0 | 306 |
self._init_coll_EditMenu_Items(self.EditMenu) |
307 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
308 |
self._init_coll_SFCMenu_Items(self.SFCMenu) |
|
309 |
self._init_coll_ConfigMenu_Items(self.ConfigMenu) |
|
310 |
||
311 |
def _init_ctrls(self, prnt): |
|
121 | 312 |
if wx.VERSION >= (2, 8, 0): |
313 |
wx.aui.AuiMDIParentFrame.__init__(self, winid=ID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
|
314 |
parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600), |
|
315 |
style=wx.DEFAULT_FRAME_STYLE|wx.SUNKEN_BORDER|wx.CLIP_CHILDREN, title=u'PLCOpenEditor') |
|
316 |
else: |
|
317 |
wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name=u'PLCOpenEditor', |
|
318 |
parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600), |
|
319 |
style=wx.DEFAULT_FRAME_STYLE, title=u'PLCOpenEditor') |
|
0 | 320 |
self._init_utils() |
321 |
self.SetClientSize(wx.Size(1000, 600)) |
|
322 |
self.SetMenuBar(self.menuBar1) |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
323 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
324 |
if not self.ModeSolo: |
121 | 325 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=ID_PLCOPENEDITORFILEMENUITEMS2) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
326 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=ID_PLCOPENEDITORFILEMENUITEMS5) |
121 | 327 |
accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 119, ID_PLCOPENEDITORFILEMENUITEMS2), |
328 |
wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, ID_PLCOPENEDITORFILEMENUITEMS5)]) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
329 |
self.SetAcceleratorTable(accel) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
330 |
|
120 | 331 |
if wx.VERSION >= (2, 8, 0): |
332 |
self.AUIManager = wx.aui.AuiManager(self) |
|
121 | 333 |
self.AUIManager.SetDockSizeConstraint(0.5, 0.5) |
120 | 334 |
self.Panes = {} |
335 |
||
336 |
if wx.VERSION < (2, 8, 0): |
|
337 |
self.MainSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORMAINSPLITTER, |
|
338 |
name='MainSplitter', parent=self, point=wx.Point(0, 0), |
|
339 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
340 |
self.MainSplitter.SetNeedUpdating(True) |
|
341 |
self.MainSplitter.SetMinimumPaneSize(1) |
|
342 |
||
343 |
self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE, |
|
344 |
name='treeCtrl1', parent=self.MainSplitter, pos=wx.Point(0, 0), |
|
345 |
size=wx.Size(-1, -1), |
|
346 |
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
347 |
else: |
|
348 |
self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE, |
|
349 |
name='treeCtrl1', parent=self, pos=wx.Point(0, 0), |
|
350 |
size=wx.Size(200, -1), |
|
351 |
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
|
121 | 352 |
self.AUIManager.AddPane(self.ProjectTree, wx.aui.AuiPaneInfo().Caption("Project Tree").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False)) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
353 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
354 |
self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
355 |
self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
356 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
357 |
wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
358 |
wx.EVT_LEFT_UP(self.ProjectTree, self.OnProjectTreeLeftUp) |
7 | 359 |
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
360 |
id=ID_PLCOPENEDITORPROJECTTREE) |
0 | 361 |
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
362 |
id=ID_PLCOPENEDITORPROJECTTREE) |
0 | 363 |
self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnProjectTreeItemEndEdit, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
364 |
id=ID_PLCOPENEDITORPROJECTTREE) |
0 | 365 |
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
366 |
id=ID_PLCOPENEDITORPROJECTTREE) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
367 |
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging, |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
368 |
id=ID_PLCOPENEDITORPROJECTTREE) |
95 | 369 |
|
120 | 370 |
if wx.VERSION < (2, 8, 0): |
371 |
self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, |
|
372 |
ID_PLCOPENEDITORTOOLBAR, 'ToolBar') |
|
373 |
self.ToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
374 |
self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, |
|
375 |
wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object") |
|
376 |
self.ToolBar.Realize() |
|
377 |
else: |
|
378 |
ToolBar = wx.ToolBar(self, ID_PLCOPENEDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize, |
|
379 |
wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER) |
|
380 |
ToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
|
381 |
ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, |
|
382 |
wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object") |
|
383 |
ToolBar.Realize() |
|
384 |
self.Panes["ToolBar"] = ToolBar |
|
385 |
self.AUIManager.AddPane(ToolBar, wx.aui.AuiPaneInfo(). |
|
386 |
Name("ToolBar").Caption("Toolbar"). |
|
387 |
ToolbarPane().Top(). |
|
388 |
LeftDockable(False).RightDockable(False)) |
|
389 |
||
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
390 |
self.Bind(wx.EVT_TOOL, self.OnSelectionTool, |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
391 |
id=ID_PLCOPENEDITORTOOLBARSELECTION) |
120 | 392 |
|
393 |
if wx.VERSION < (2, 8, 0): |
|
121 | 394 |
self.SecondSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORSECONDSPLITTER, |
395 |
name='SecondSplitter', parent=self.MainSplitter, point=wx.Point(0, 0), |
|
396 |
size=wx.Size(0, 0), style=wx.SP_3D) |
|
397 |
self.SecondSplitter.SetMinimumPaneSize(1) |
|
398 |
||
399 |
self.MainSplitter.SplitVertically(self.ProjectTree, self.SecondSplitter, 200) |
|
400 |
||
120 | 401 |
self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED, |
121 | 402 |
name='TabsOpened', parent=self.SecondSplitter, pos=wx.Point(0, |
120 | 403 |
0), size=wx.Size(0, 0), style=0) |
121 | 404 |
if wx.VERSION >= (2, 6, 0): |
405 |
self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
406 |
self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED) |
|
407 |
else: |
|
408 |
wx.EVT_NOTEBOOK_PAGE_CHANGED(self.TabsOpened, ID_PLCOPENEDITORTABSOPENED, |
|
409 |
self.OnPouSelectedChanged) |
|
410 |
||
411 |
if wx.VERSION < (2, 8, 0): |
|
412 |
self.VariablePanelIndexer = VariablePanelIndexer(self.SecondSplitter, self.Controler) |
|
413 |
||
414 |
self.SecondSplitter.SplitHorizontally(self.TabsOpened, self.VariablePanelIndexer, -200) |
|
415 |
else: |
|
416 |
self.VariablePanelIndexer = VariablePanelIndexer(self, self.Controler) |
|
417 |
self.AUIManager.AddPane(self.VariablePanelIndexer, wx.aui.AuiPaneInfo().Caption("Variable Panel").Bottom().Layer(0).BestSize(wx.Size(800, 200)).CloseButton(False)) |
|
418 |
||
120 | 419 |
self.AUIManager.Update(); |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
420 |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
421 |
def __init__(self, parent, controler = None, fileOpen = None): |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
422 |
self.ModeSolo = controler == None |
121 | 423 |
if self.ModeSolo: |
424 |
self.Controler = PLCControler() |
|
425 |
if fileOpen is not None: |
|
426 |
self.Controler.OpenXMLFile(fileOpen) |
|
427 |
else: |
|
428 |
self.Controler = controler |
|
429 |
||
0 | 430 |
self._init_ctrls(parent) |
431 |
||
95 | 432 |
if wx.Platform != '__WXMSW__': |
433 |
self.TreeImageList = wx.ImageList(16, 16) |
|
434 |
for language in LANGUAGES: |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
435 |
self.TreeImageList.Add(wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%language))) |
95 | 436 |
self.ProjectTree.AssignImageList(self.TreeImageList) |
9 | 437 |
|
6 | 438 |
self.CurrentToolBar = [] |
27 | 439 |
self.CurrentLanguage = "" |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
440 |
self.SelectedItem = None |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
441 |
self.CopyBuffer = None |
71 | 442 |
self.DrawingMode = FREEDRAWING_MODE |
443 |
#self.DrawingMode = DRIVENDRAWING_MODE |
|
6 | 444 |
|
121 | 445 |
if not self.ModeSolo or fileOpen is not None: |
446 |
self.RefreshProjectTree() |
|
447 |
||
0 | 448 |
self.RefreshFileMenu() |
449 |
self.RefreshEditMenu() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
450 |
self.RefreshTitle() |
0 | 451 |
self.RefreshToolBar() |
452 |
||
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
453 |
def ResetSelectedItem(self): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
454 |
self.SelectedItem = None |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
455 |
|
121 | 456 |
def GetPageCount(self): |
457 |
if wx.VERSION >= (2, 8, 0): |
|
458 |
notebook = self.GetNotebook() |
|
459 |
if notebook is not None: |
|
460 |
return notebook.GetPageCount() |
|
461 |
else: |
|
462 |
return 0 |
|
463 |
else: |
|
464 |
return self.TabsOpened.GetPageCount() |
|
465 |
||
466 |
def GetPage(self, idx): |
|
467 |
if wx.VERSION >= (2, 8, 0): |
|
468 |
notebook = self.GetNotebook() |
|
469 |
if notebook is not None: |
|
470 |
return notebook.GetPage(idx).GetViewer() |
|
471 |
else: |
|
472 |
return None |
|
473 |
else: |
|
474 |
return self.TabsOpened.GetPage(idx) |
|
475 |
||
476 |
def GetPageSelection(self): |
|
477 |
if wx.VERSION >= (2, 8, 0): |
|
478 |
notebook = self.GetNotebook() |
|
479 |
if notebook is not None: |
|
480 |
return notebook.GetSelection() |
|
481 |
else: |
|
482 |
return -1 |
|
483 |
else: |
|
484 |
return self.TabsOpened.GetSelection() |
|
485 |
||
486 |
def SetPageSelection(self, idx): |
|
487 |
if wx.VERSION >= (2, 8, 0): |
|
488 |
notebook = self.GetNotebook() |
|
489 |
if notebook is not None: |
|
490 |
notebook.SetSelection(idx) |
|
491 |
else: |
|
492 |
self.TabsOpened.SetSelection(idx) |
|
493 |
||
494 |
def DeletePage(self, idx): |
|
495 |
if wx.VERSION >= (2, 8, 0): |
|
496 |
notebook = self.GetNotebook() |
|
497 |
if notebook is not None: |
|
498 |
notebook.DeletePage(idx) |
|
499 |
else: |
|
500 |
self.TabsOpened.DeletePage(idx) |
|
501 |
||
502 |
def DeleteAllPages(self): |
|
503 |
if wx.VERSION >= (2, 8, 0): |
|
504 |
notebook = self.GetNotebook() |
|
505 |
if notebook is not None: |
|
506 |
for idx in xrange(notebook.GetPageCount()): |
|
507 |
notebook.DeletePage(idx) |
|
508 |
else: |
|
509 |
self.TabsOpened.DeleteAllPages() |
|
510 |
||
511 |
def SetPageText(self, idx, text): |
|
512 |
if wx.VERSION >= (2, 8, 0): |
|
513 |
notebook = self.GetNotebook() |
|
514 |
if notebook is not None: |
|
515 |
return notebook.SetPageText(idx, text) |
|
516 |
else: |
|
517 |
return self.TabsOpened.SetPageText(idx, text) |
|
518 |
||
519 |
def GetPageText(self, idx): |
|
520 |
if wx.VERSION >= (2, 8, 0): |
|
521 |
notebook = self.GetNotebook() |
|
522 |
if notebook is not None: |
|
523 |
return notebook.GetPageText(idx) |
|
524 |
else: |
|
525 |
return "" |
|
526 |
else: |
|
527 |
return self.TabsOpened.GetPageText(idx) |
|
528 |
||
529 |
def OnPageClose(self, event): |
|
530 |
selected = self.GetPageSelection() |
|
531 |
if selected >= 0: |
|
532 |
tagname = self.GetPage(selected).GetTagName() |
|
533 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
534 |
if self.GetPageCount() > 0: |
|
535 |
new_index = min(selected, self.GetPageCount() - 1) |
|
536 |
tagname = self.GetPage(new_index).GetTagName() |
|
537 |
self.SetPageSelection(new_index) |
|
538 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
539 |
self.RefreshTitle() |
|
540 |
self.RefreshFileMenu() |
|
541 |
self.RefreshEditMenu() |
|
542 |
self.RefreshToolBar() |
|
543 |
event.Skip() |
|
544 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
545 |
def GetCopyBuffer(self): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
546 |
return self.CopyBuffer |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
547 |
|
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
548 |
def SetCopyBuffer(self, element): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
549 |
self.CopyBuffer = element |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
550 |
self.RefreshEditMenu() |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
551 |
|
27 | 552 |
def GetDrawingMode(self): |
553 |
return self.DrawingMode |
|
554 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
555 |
def RefreshTitle(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
556 |
if self.Controler.HasOpenedProject() > 0: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
557 |
self.SetTitle("PLCOpenEditor - %s"%self.Controler.GetFilename()) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
558 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
559 |
self.SetTitle("PLCOpenEditor") |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
560 |
|
0 | 561 |
def RefreshFileMenu(self): |
9 | 562 |
if self.FileMenu: |
563 |
if self.Controler.HasOpenedProject(): |
|
121 | 564 |
if self.GetPageCount() > 0: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
565 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, True) |
9 | 566 |
else: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
567 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
568 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
569 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
570 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
571 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
572 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
573 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
574 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
575 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
576 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
577 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
578 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
579 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, False) |
0 | 580 |
|
581 |
def RefreshEditMenu(self): |
|
9 | 582 |
if self.EditMenu: |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
583 |
if self.Controler.HasOpenedProject(): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
584 |
undo, redo = self.Controler.GetBufferState() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
585 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, undo) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
586 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, redo) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
587 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
588 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS1, False) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
589 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, False) |
9 | 590 |
if self.Controler.HasOpenedProject(): |
121 | 591 |
if self.GetPageCount() > 0: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
592 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, True) |
9 | 593 |
else: |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
594 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
595 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
596 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS9, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
597 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
598 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
599 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
600 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS9, False) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
601 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS4, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
602 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS5, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
603 |
if self.CopyBuffer is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
604 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, True) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
605 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
606 |
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, False) |
0 | 607 |
|
121 | 608 |
def RefreshEditor(self, variablepanel = True): |
609 |
selected = self.GetPageSelection() |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
610 |
if selected != -1: |
121 | 611 |
window = self.GetPage(selected) |
612 |
window.RefreshView() |
|
613 |
if variablepanel: |
|
614 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
615 |
|
27 | 616 |
def ShowProperties(self): |
617 |
old_values = self.Controler.GetProjectProperties() |
|
618 |
dialog = ProjectDialog(self) |
|
619 |
dialog.SetValues(old_values) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
620 |
if dialog.ShowModal() == wx.ID_OK: |
27 | 621 |
new_values = dialog.GetValues() |
622 |
projectname = new_values.pop("projectName") |
|
623 |
new_values["creationDateTime"] = old_values["creationDateTime"] |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
624 |
self.Controler.SetProjectProperties(projectname, new_values) |
27 | 625 |
self.RefreshProjectTree() |
626 |
dialog.Destroy() |
|
627 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
628 |
def OnCloseFrame(self, event): |
107 | 629 |
if not self.ModeSolo and getattr(self, "_onclose", None) is not None: |
121 | 630 |
self.AUIManager.UnInit() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
631 |
self._onclose() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
632 |
event.Skip() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
633 |
elif not self.Controler.ProjectIsSaved(): |
80 | 634 |
dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
635 |
answer = dialog.ShowModal() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
636 |
dialog.Destroy() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
637 |
if answer == wx.ID_YES: |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
638 |
self.SaveProject() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
639 |
event.Skip() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
640 |
elif answer == wx.ID_NO: |
80 | 641 |
self.Controler.Reset() |
121 | 642 |
self.AUIManager.UnInit() |
80 | 643 |
wx.CallAfter(self.Close) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
644 |
event.Skip() |
80 | 645 |
else: |
646 |
event.Veto() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
647 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
648 |
event.Skip() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
649 |
|
0 | 650 |
def OnNewProjectMenu(self, event): |
651 |
dialog = ProjectDialog(self) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
652 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 653 |
values = dialog.GetValues() |
654 |
projectname = values.pop("projectName") |
|
655 |
values["creationDateTime"] = datetime(*localtime()[:6]) |
|
656 |
self.Controler.CreateNewProject(projectname) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
657 |
self.Controler.SetProjectProperties(projectname, values) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
658 |
self.RefreshTitle() |
0 | 659 |
self.RefreshFileMenu() |
660 |
self.RefreshEditMenu() |
|
661 |
self.RefreshProjectTree() |
|
662 |
event.Skip() |
|
663 |
||
664 |
def OnOpenProjectMenu(self, event): |
|
665 |
filepath = self.Controler.GetFilePath() |
|
666 |
if filepath != "": |
|
667 |
directory = os.path.dirname(filepath) |
|
668 |
else: |
|
669 |
directory = os.getcwd() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
670 |
dialog = wx.FileDialog(self, "Choose a file", directory, "", "PLCOpen files (*.xml)|*.xml|All files|*.*", wx.OPEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
671 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 672 |
filepath = dialog.GetPath() |
673 |
if os.path.isfile(filepath): |
|
674 |
self.Controler.OpenXMLFile(filepath) |
|
121 | 675 |
self.DeleteAllPages() |
0 | 676 |
self.RefreshProjectTree() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
677 |
self.RefreshTitle() |
0 | 678 |
self.RefreshFileMenu() |
679 |
self.RefreshEditMenu() |
|
680 |
self.RefreshToolBar() |
|
681 |
dialog.Destroy() |
|
682 |
event.Skip() |
|
683 |
||
684 |
def OnCloseTabMenu(self, event): |
|
121 | 685 |
selected = self.GetPageSelection() |
0 | 686 |
if selected >= 0: |
121 | 687 |
tagname = self.GetPage(selected).GetTagName() |
688 |
self.DeletePage(selected) |
|
689 |
self.VariablePanelIndexer.RemoveVariablePanel(tagname) |
|
690 |
if self.GetPageCount() > 0: |
|
691 |
new_index = min(selected, self.GetPageCount() - 1) |
|
692 |
tagname = self.GetPage(new_index).GetTagName() |
|
693 |
self.SetPageSelection(new_index) |
|
694 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
695 |
self.RefreshTitle() |
0 | 696 |
self.RefreshFileMenu() |
697 |
self.RefreshEditMenu() |
|
698 |
self.RefreshToolBar() |
|
699 |
event.Skip() |
|
700 |
||
701 |
def OnCloseProjectMenu(self, event): |
|
121 | 702 |
self.DeleteAllPages() |
703 |
self.VariablePanelIndexer.RemoveAllPanels() |
|
0 | 704 |
self.ProjectTree.DeleteAllItems() |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
705 |
self.Controler.Reset() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
706 |
self.RefreshTitle() |
0 | 707 |
self.RefreshFileMenu() |
708 |
self.RefreshEditMenu() |
|
709 |
self.RefreshToolBar() |
|
710 |
event.Skip() |
|
711 |
||
712 |
def OnSaveProjectMenu(self, event): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
713 |
if not self.ModeSolo and getattr(self, "_onsave", None) != None: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
714 |
self._onsave() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
715 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
716 |
self.SaveProject() |
0 | 717 |
event.Skip() |
718 |
||
719 |
def OnSaveProjectAsMenu(self, event): |
|
720 |
self.SaveProjectAs() |
|
721 |
event.Skip() |
|
722 |
||
723 |
def OnGenerateProgramMenu(self, event): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
724 |
dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), self.Controler.GetProgramFilePath(), "ST files (*.st)|*.st|All files|*.*", wx.SAVE|wx.CHANGE_DIR) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
725 |
if dialog.ShowModal() == wx.ID_OK: |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
726 |
filepath = dialog.GetPath() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
727 |
if os.path.isdir(os.path.dirname(filepath)): |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
728 |
result = self.Controler.GenerateProgram(filepath) |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
729 |
if not result: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
730 |
message = wx.MessageDialog(self, "Can't generate program to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR) |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
731 |
message.ShowModal() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
732 |
message.Destroy() |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
733 |
else: |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
734 |
message = wx.MessageDialog(self, "Program was successfully generated!", "Done", wx.OK|wx.ICON_INFORMATION) |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
735 |
message.ShowModal() |
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
736 |
message.Destroy() |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
737 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
738 |
message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
4
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
739 |
message.ShowModal() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
740 |
message.Destroy() |
2de7fd952fdd
Adding File Dialog for choosing path to generated program
lbessard
parents:
3
diff
changeset
|
741 |
dialog.Destroy() |
0 | 742 |
event.Skip() |
743 |
||
744 |
def SaveProject(self): |
|
745 |
result = self.Controler.SaveXMLFile() |
|
746 |
if not result: |
|
747 |
self.SaveProjectAs() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
748 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
749 |
self.RefreshTitle() |
0 | 750 |
|
751 |
def SaveProjectAs(self): |
|
752 |
filepath = self.Controler.GetFilePath() |
|
753 |
if filepath != "": |
|
754 |
directory, filename = os.path.split(filepath) |
|
755 |
else: |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
756 |
directory, filename = os.getcwd(), "%(projectName)s.xml"%self.Controler.GetProjectProperties() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
757 |
dialog = wx.FileDialog(self, "Choose a file", directory, filename, "PLCOpen files (*.xml)|*.xml|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
758 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 759 |
filepath = dialog.GetPath() |
760 |
if os.path.isdir(os.path.dirname(filepath)): |
|
761 |
result = self.Controler.SaveXMLFile(filepath) |
|
762 |
if not result: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
763 |
message = wx.MessageDialog(self, "Can't save project to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR) |
0 | 764 |
message.ShowModal() |
765 |
message.Destroy() |
|
766 |
else: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
767 |
message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
0 | 768 |
message.ShowModal() |
769 |
message.Destroy() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
770 |
self.RefreshTitle() |
0 | 771 |
dialog.Destroy() |
772 |
||
27 | 773 |
def OnPropertiesMenu(self, event): |
774 |
self.ShowProperties() |
|
775 |
event.Skip() |
|
776 |
||
0 | 777 |
def OnQuitMenu(self, event): |
778 |
self.Close() |
|
779 |
event.Skip() |
|
780 |
||
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
781 |
def ResetCurrentMode(self): |
121 | 782 |
selected = self.GetPageSelection() |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
783 |
if selected != -1: |
121 | 784 |
window = self.GetPage(selected) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
785 |
window.SetMode(MODE_SELECTION) |
120 | 786 |
if wx.VERSION < (2, 8, 0): |
121 | 787 |
ToolBar = self.ToolBar |
788 |
else: |
|
789 |
ToolBar = self.Panes["ToolBar"] |
|
790 |
if ToolBar: |
|
791 |
ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True) |
|
792 |
||
6 | 793 |
def ResetToolToggle(self, id): |
120 | 794 |
if wx.VERSION < (2, 8, 0): |
795 |
tool = self.ToolBar.FindById(id) |
|
796 |
else: |
|
797 |
tool = self.Panes["ToolBar"].FindById(id) |
|
6 | 798 |
tool.SetToggle(False) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
799 |
|
0 | 800 |
def OnSelectionTool(self, event): |
121 | 801 |
self.GetPageSelection() |
0 | 802 |
if selected != -1: |
121 | 803 |
self.GetPage(selected).SetMode(MODE_SELECTION) |
0 | 804 |
event.Skip() |
805 |
||
27 | 806 |
def OnCommentTool(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
807 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT) |
121 | 808 |
selected = self.GetPageSelection() |
0 | 809 |
if selected != -1: |
121 | 810 |
self.GetPage(selected).SetMode(MODE_COMMENT) |
0 | 811 |
event.Skip() |
812 |
||
27 | 813 |
def OnVariableTool(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
814 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE) |
121 | 815 |
selected = self.GetPageSelection() |
0 | 816 |
if selected != -1: |
121 | 817 |
self.GetPage(selected).SetMode(MODE_VARIABLE) |
0 | 818 |
event.Skip() |
819 |
||
27 | 820 |
def OnBlockTool(self, event): |
121 | 821 |
selected = self.GetPageSelection() |
0 | 822 |
if selected != -1: |
121 | 823 |
self.GetPage(selected).SetMode(MODE_BLOCK) |
0 | 824 |
event.Skip() |
825 |
||
27 | 826 |
def OnConnectionTool(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
827 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION) |
121 | 828 |
selected = self.GetPageSelection() |
0 | 829 |
if selected != -1: |
121 | 830 |
self.GetPage(selected).SetMode(MODE_CONNECTION) |
0 | 831 |
event.Skip() |
832 |
||
27 | 833 |
def OnWireTool(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
834 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARWIRE) |
121 | 835 |
selected = self.GetPageSelection() |
6 | 836 |
if selected != -1: |
121 | 837 |
self.GetPage(selected).SetMode(MODE_WIRE) |
6 | 838 |
event.Skip() |
839 |
||
27 | 840 |
def OnPowerRailTool(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
841 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL) |
121 | 842 |
selected = self.GetPageSelection() |
27 | 843 |
if selected != -1: |
121 | 844 |
self.GetPage(selected).SetMode(MODE_POWERRAIL) |
27 | 845 |
event.Skip() |
846 |
||
847 |
def OnRungTool(self, event): |
|
121 | 848 |
selected = self.GetPageSelection() |
0 | 849 |
if selected != -1: |
121 | 850 |
self.GetPage(selected).AddLadderRung() |
0 | 851 |
event.Skip() |
852 |
||
27 | 853 |
def OnCoilTool(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
854 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOIL) |
121 | 855 |
selected = self.GetPageSelection() |
0 | 856 |
if selected != -1: |
121 | 857 |
self.GetPage(selected).SetMode(MODE_COIL) |
27 | 858 |
event.Skip() |
859 |
||
860 |
def OnContactTool(self, event): |
|
861 |
if self.DrawingMode == FREEDRAWING_MODE: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
862 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONTACT) |
121 | 863 |
selected = self.GetPageSelection() |
0 | 864 |
if selected != -1: |
27 | 865 |
if self.DrawingMode == FREEDRAWING_MODE: |
121 | 866 |
self.GetPage(selected).SetMode(MODE_CONTACT) |
867 |
else: |
|
868 |
self.GetPage(selected).AddLadderContact() |
|
27 | 869 |
event.Skip() |
870 |
||
871 |
def OnBranchTool(self, event): |
|
121 | 872 |
selected = self.GetPageSelection() |
0 | 873 |
if selected != -1: |
121 | 874 |
self.GetPage(selected).AddLadderBranch() |
27 | 875 |
event.Skip() |
876 |
||
877 |
def OnInitialStepTool(self, event): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
878 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP) |
121 | 879 |
selected = self.GetPageSelection() |
27 | 880 |
if selected != -1: |
121 | 881 |
self.GetPage(selected).SetMode(MODE_INITIALSTEP) |
27 | 882 |
event.Skip() |
883 |
||
884 |
def OnStepTool(self, event): |
|
885 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
886 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARSTEP) |
121 | 887 |
selected = self.GetPageSelection() |
27 | 888 |
if selected != -1: |
889 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
121 | 890 |
self.GetPage(selected).SetMode(MODE_STEP) |
891 |
else: |
|
892 |
self.GetPage(selected).AddStep() |
|
27 | 893 |
event.Skip() |
894 |
||
895 |
def OnActionBlockTool(self, event): |
|
896 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
897 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK) |
121 | 898 |
selected = self.GetPageSelection() |
27 | 899 |
if selected != -1: |
900 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
121 | 901 |
self.GetPage(selected).SetMode(MODE_ACTION) |
902 |
else: |
|
903 |
self.GetPage(selected).AddStepAction() |
|
27 | 904 |
event.Skip() |
905 |
||
906 |
def OnTransitionTool(self, event): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
907 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION) |
121 | 908 |
selected = self.GetPageSelection() |
27 | 909 |
if selected != -1: |
121 | 910 |
self.GetPage(selected).SetMode(MODE_TRANSITION) |
27 | 911 |
event.Skip() |
912 |
||
913 |
def OnDivergenceTool(self, event): |
|
914 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
915 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE) |
121 | 916 |
selected = self.GetPageSelection() |
27 | 917 |
if selected != -1: |
918 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
121 | 919 |
self.GetPage(selected).SetMode(MODE_DIVERGENCE) |
920 |
else: |
|
921 |
self.GetPage(selected).AddDivergence() |
|
27 | 922 |
event.Skip() |
923 |
||
924 |
def OnJumpTool(self, event): |
|
925 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
926 |
self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARJUMP) |
121 | 927 |
selected = self.GetPageSelection() |
27 | 928 |
if selected != -1: |
929 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
121 | 930 |
self.GetPage(selected).SetMode(MODE_JUMP) |
931 |
else: |
|
932 |
self.GetPage(selected).AddJump() |
|
0 | 933 |
event.Skip() |
934 |
||
935 |
def OnPouSelectedChanged(self, event): |
|
121 | 936 |
if wx.VERSION < (2, 8, 0) or event.GetActive(): |
937 |
old_selected = self.GetPageSelection() |
|
938 |
if old_selected >= 0: |
|
939 |
self.GetPage(old_selected).ResetBuffer() |
|
940 |
if wx.VERSION >= (2, 8, 0): |
|
941 |
window = event.GetEventObject().GetViewer() |
|
942 |
else: |
|
943 |
selected = event.GetSelection() |
|
944 |
if selected >= 0: |
|
945 |
window = self.GetPage(selected) |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
946 |
else: |
121 | 947 |
window = None |
948 |
if window: |
|
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
949 |
if self.ProjectTree: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
950 |
root = self.ProjectTree.GetRootItem() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
951 |
words = window.GetTagName().split("::") |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
952 |
if words[0] == "P": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
953 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_POU)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
954 |
elif words[0] == "T": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
955 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_POU), (words[2], ITEM_TRANSITION)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
956 |
elif words[0] == "A": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
957 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_POU), (words[2], ITEM_ACTION)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
958 |
elif words[0] == "C": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
959 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_CONFIGURATION)]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
960 |
elif words[0] == "R": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
961 |
self.SelectProjectTreeItem(root, [(words[1], ITEM_CONFIGURATION), (words[2], ITEM_RESOURCE)]) |
121 | 962 |
window.RefreshView() |
963 |
self.VariablePanelIndexer.ChangeVariablePanel(window.GetTagName()) |
|
964 |
self.RefreshFileMenu() |
|
965 |
self.RefreshEditMenu() |
|
966 |
self.RefreshToolBar() |
|
0 | 967 |
event.Skip() |
968 |
||
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
969 |
def SelectProjectTreeItem(self, root, items): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
970 |
found = False |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
971 |
if self.ProjectTree: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
972 |
if wx.VERSION >= (2, 6, 0): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
973 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
974 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
975 |
item, root_cookie = self.ProjectTree.GetFirstChild(root, 0) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
976 |
while item.IsOk() and not found: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
977 |
if (self.ProjectTree.GetItemText(item), self.ProjectTree.GetPyData(item)) == items[0]: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
978 |
if len(items) == 1: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
979 |
self.SelectedItem = item |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
980 |
self.ProjectTree.SelectItem(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
981 |
wx.CallAfter(self.ResetSelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
982 |
return True |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
983 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
984 |
found = self.SelectProjectTreeItem(item, items[1:]) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
985 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
986 |
found = self.SelectProjectTreeItem(item, items) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
987 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
988 |
return found |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
989 |
|
7 | 990 |
def OnProjectTreeBeginDrag(self, event): |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
991 |
if self.SelectedItem is not None and self.ProjectTree.GetPyData(self.SelectedItem) == ITEM_POU: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
992 |
block_name = self.ProjectTree.GetItemText(self.SelectedItem) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
993 |
block_type = self.Controler.GetPouType(block_name) |
53 | 994 |
if block_type != "program": |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
995 |
data = wx.TextDataObject(str((block_name, block_type, ""))) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
996 |
dragSource = wx.DropSource(self.ProjectTree) |
53 | 997 |
dragSource.SetData(data) |
998 |
dragSource.DoDragDrop() |
|
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
999 |
self.ResetSelectedItem() |
7 | 1000 |
|
107 | 1001 |
def RefreshEditorNames(self, item_type, old_name, new_name): |
121 | 1002 |
for i in xrange(self.GetPageCount()): |
1003 |
editor = self.GetPage(i) |
|
107 | 1004 |
editor.RefreshName(item_type, old_name, new_name) |
1005 |
||
0 | 1006 |
def OnProjectTreeItemEndEdit(self, event): |
6 | 1007 |
message = None |
1008 |
abort = False |
|
0 | 1009 |
new_name = event.GetLabel() |
1010 |
if new_name != "": |
|
6 | 1011 |
if not TestIdentifier(new_name): |
1012 |
message = "\"%s\" is not a valid identifier!"%new_name |
|
1013 |
elif new_name.upper() in IEC_KEYWORDS: |
|
1014 |
message = "\"%s\" is a keyword. It can't be used!"%new_name |
|
1015 |
else: |
|
0 | 1016 |
item = event.GetItem() |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1017 |
old_name = self.ProjectTree.GetItemText(item) |
0 | 1018 |
itemtype = self.ProjectTree.GetPyData(item) |
1019 |
if itemtype == ITEM_PROJECT: |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1020 |
self.Controler.SetProjectProperties(name = new_name) |
0 | 1021 |
elif itemtype == ITEM_POU: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1022 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames() if name != old_name]: |
6 | 1023 |
message = "\"%s\" pou already exists!"%new_name |
1024 |
abort = True |
|
70 | 1025 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1026 |
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1027 |
if messageDialog.ShowModal() == wx.ID_NO: |
6 | 1028 |
abort = True |
1029 |
messageDialog.Destroy() |
|
1030 |
if not abort: |
|
1031 |
self.Controler.ChangePouName(old_name, new_name) |
|
107 | 1032 |
self.RefreshEditorNames(itemtype, old_name, new_name) |
121 | 1033 |
self.RefreshPageTitles() |
0 | 1034 |
elif itemtype == ITEM_TRANSITION: |
108 | 1035 |
parent = self.ProjectTree.GetItemParent(item) |
107 | 1036 |
parent_type = self.ProjectTree.GetPyData(parent) |
1037 |
while parent_type != ITEM_POU: |
|
1038 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1039 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1040 |
pou_name = self.ProjectTree.GetItemText(parent) |
|
70 | 1041 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
6 | 1042 |
message = "A pou with \"%s\" as name exists!"%new_name |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1043 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]: |
6 | 1044 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
1045 |
else: |
|
1046 |
self.Controler.ChangePouTransitionName(pou_name, old_name, new_name) |
|
107 | 1047 |
self.RefreshEditorNames(itemtype, old_name, new_name) |
121 | 1048 |
self.RefreshPageTitles() |
0 | 1049 |
elif itemtype == ITEM_ACTION: |
108 | 1050 |
parent = self.ProjectTree.GetItemParent(item) |
107 | 1051 |
parent_type = self.ProjectTree.GetPyData(parent) |
1052 |
while parent_type != ITEM_POU: |
|
1053 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1054 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1055 |
pou_name = self.ProjectTree.GetItemText(parent) |
|
70 | 1056 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
6 | 1057 |
message = "A pou with \"%s\" as name exists!"%new_name |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1058 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables(pou_name) if name != old_name]: |
6 | 1059 |
message = "A variable with \"%s\" as name already exists in this pou!"%new_name |
1060 |
else: |
|
1061 |
self.Controler.ChangePouActionName(pou_name, old_name, new_name) |
|
107 | 1062 |
self.RefreshEditorNames(itemtype, old_name, new_name) |
121 | 1063 |
self.RefreshPageTitles() |
107 | 1064 |
elif itemtype == ITEM_CONFIGURATION: |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1065 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames() if name != old_name]: |
107 | 1066 |
message = "\"%s\" config already exists!"%new_name |
1067 |
abort = True |
|
1068 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1069 |
messageDialog = wx.MessageDialog(self, "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1070 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1071 |
abort = True |
|
1072 |
messageDialog.Destroy() |
|
1073 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: |
|
1074 |
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1075 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1076 |
abort = True |
|
1077 |
messageDialog.Destroy() |
|
1078 |
if not abort: |
|
1079 |
self.Controler.ChangeConfigurationName(old_name, new_name) |
|
1080 |
self.RefreshEditorNames(itemtype, old_name, new_name) |
|
121 | 1081 |
self.RefreshPageTitles() |
107 | 1082 |
elif itemtype == ITEM_RESOURCE: |
108 | 1083 |
parent = self.ProjectTree.GetItemParent(item) |
107 | 1084 |
parent_type = self.ProjectTree.GetPyData(parent) |
1085 |
while parent_type != ITEM_CONFIGURATION: |
|
1086 |
parent = self.ProjectTree.GetItemParent(parent) |
|
1087 |
parent_type = self.ProjectTree.GetPyData(parent) |
|
1088 |
config_name = self.ProjectTree.GetItemText(parent) |
|
1089 |
if new_name.upper() in [name.upper() for name in self.Controler.GetProjectConfigNames()]: |
|
1090 |
message = "\"%s\" config already exists!"%new_name |
|
1091 |
abort = True |
|
1092 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames()]: |
|
1093 |
messageDialog = wx.MessageDialog(self, "A pou is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1094 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1095 |
abort = True |
|
1096 |
messageDialog.Destroy() |
|
1097 |
elif new_name.upper() in [name.upper() for name in self.Controler.GetProjectPouVariables()]: |
|
1098 |
messageDialog = wx.MessageDialog(self, "A variable is defined with \"%s\" as name. It can generate a conflict. Do you wish to continue?"%new_name, "Error", wx.YES_NO|wx.ICON_QUESTION) |
|
1099 |
if messageDialog.ShowModal() == wx.ID_NO: |
|
1100 |
abort = True |
|
1101 |
messageDialog.Destroy() |
|
1102 |
if not abort: |
|
1103 |
self.Controler.ChangeConfigurationResourceName(config_name, old_name, new_name) |
|
1104 |
self.RefreshEditorNames(itemtype, old_name, new_name) |
|
121 | 1105 |
self.RefreshPageTitles() |
6 | 1106 |
if message or abort: |
1107 |
if message: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1108 |
messageDialog = wx.MessageDialog(self, message, "Error", wx.OK|wx.ICON_ERROR) |
6 | 1109 |
messageDialog.ShowModal() |
1110 |
messageDialog.Destroy() |
|
0 | 1111 |
item = event.GetItem() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1112 |
wx.CallAfter(self.ProjectTree.EditLabel, item) |
0 | 1113 |
event.Veto() |
6 | 1114 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1115 |
wx.CallAfter(self.RefreshProjectTree) |
121 | 1116 |
selected = self.GetPageSelection() |
1117 |
if selected != -1: |
|
1118 |
self.GetPage(selected).RefreshView() |
|
6 | 1119 |
event.Skip() |
0 | 1120 |
|
1121 |
def OnProjectTreeItemBeginEdit(self, event): |
|
1122 |
selected = event.GetItem() |
|
1123 |
if self.ProjectTree.GetPyData(selected) == ITEM_UNEDITABLE: |
|
1124 |
event.Veto() |
|
1125 |
else: |
|
1126 |
event.Skip() |
|
1127 |
||
1128 |
def OnProjectTreeItemActivated(self, event): |
|
1129 |
selected = event.GetItem() |
|
1130 |
if self.ProjectTree.IsExpanded(selected): |
|
1131 |
self.ProjectTree.Collapse(selected) |
|
1132 |
else: |
|
1133 |
self.ProjectTree.Expand(selected) |
|
1134 |
name = self.ProjectTree.GetItemText(selected) |
|
1135 |
data = self.ProjectTree.GetPyData(selected) |
|
1136 |
if name == "Properties": |
|
27 | 1137 |
self.ShowProperties() |
121 | 1138 |
if data == ITEM_POU: |
1139 |
self.EditProjectElement(data, self.Controler.ComputePouName(name)) |
|
1140 |
elif data == ITEM_CONFIGURATION: |
|
1141 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationName(name)) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1142 |
elif data == ITEM_RESOURCE: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1143 |
item = self.ProjectTree.GetItemParent(selected) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1144 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1145 |
while item_type != ITEM_CONFIGURATION: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1146 |
item = self.ProjectTree.GetItemParent(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1147 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1148 |
config_name = self.ProjectTree.GetItemText(item) |
121 | 1149 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationResourceName(config_name, name)) |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1150 |
elif data in [ITEM_TRANSITION, ITEM_ACTION]: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1151 |
item = self.ProjectTree.GetItemParent(selected) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1152 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1153 |
while item_type != ITEM_POU: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1154 |
item = self.ProjectTree.GetItemParent(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1155 |
item_type = self.ProjectTree.GetPyData(item) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1156 |
pou_name = self.ProjectTree.GetItemText(item) |
121 | 1157 |
if data == ITEM_TRANSITION: |
1158 |
tagname = self.Controler.ComputePouTransitionName(pou_name, name) |
|
1159 |
elif data == ITEM_ACTION: |
|
1160 |
tagname = self.Controler.ComputePouActionName(pou_name, name) |
|
1161 |
self.EditProjectElement(data, tagname) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1162 |
|
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1163 |
def OnProjectTreeLeftUp(self, event): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1164 |
if self.SelectedItem is not None: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1165 |
print "LeftUp", self.ProjectTree.GetItemText(self.SelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1166 |
self.ProjectTree.SelectItem(self.SelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1167 |
name = self.ProjectTree.GetItemText(self.SelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1168 |
data = self.ProjectTree.GetPyData(self.SelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1169 |
if data == ITEM_POU: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1170 |
self.EditProjectElement(data, self.Controler.ComputePouName(name), True) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1171 |
elif data == ITEM_CONFIGURATION: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1172 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationName(name), True) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1173 |
elif data == ITEM_RESOURCE: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1174 |
item = self.ProjectTree.GetItemParent(self.SelectedItem) |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1175 |
item_type = self.ProjectTree.GetPyData(item) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1176 |
while item_type != ITEM_CONFIGURATION: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1177 |
item = self.ProjectTree.GetItemParent(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1178 |
item_type = self.ProjectTree.GetPyData(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1179 |
config_name = self.ProjectTree.GetItemText(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1180 |
self.EditProjectElement(data, self.Controler.ComputeConfigurationResourceName(config_name, name), True) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1181 |
elif data in [ITEM_TRANSITION, ITEM_ACTION]: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1182 |
item = self.ProjectTree.GetItemParent(self.SelectedItem) |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1183 |
item_type = self.ProjectTree.GetPyData(item) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1184 |
while item_type != ITEM_POU: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1185 |
item = self.ProjectTree.GetItemParent(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1186 |
item_type = self.ProjectTree.GetPyData(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1187 |
pou_name = self.ProjectTree.GetItemText(item) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1188 |
if data == ITEM_TRANSITION: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1189 |
tagname = self.Controler.ComputePouTransitionName(pou_name, name) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1190 |
elif data == ITEM_ACTION: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1191 |
tagname = self.Controler.ComputePouActionName(pou_name, name) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1192 |
self.EditProjectElement(data, tagname, True) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1193 |
wx.CallAfter(self.ResetSelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1194 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1195 |
print "LeftUp", None |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1196 |
event.Skip() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1197 |
|
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1198 |
def OnProjectTreeItemChanging(self, event): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1199 |
if self.SelectedItem is not None: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1200 |
print "Changing", self.ProjectTree.GetItemText(event.GetItem()), self.ProjectTree.GetItemText(self.SelectedItem) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1201 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1202 |
print "Changing", None, self.ProjectTree.GetItemText(event.GetItem()) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1203 |
if self.ProjectTree.GetPyData(event.GetItem()) != ITEM_UNEDITABLE and self.SelectedItem is None: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1204 |
self.SelectedItem = event.GetItem() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1205 |
event.Veto() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1206 |
else: |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1207 |
event.Skip() |
121 | 1208 |
|
1209 |
def IsOpened(self, tagname): |
|
1210 |
for idx in xrange(self.GetPageCount()): |
|
1211 |
if self.GetPage(idx).IsViewing(tagname): |
|
1212 |
return idx |
|
1213 |
return None |
|
1214 |
||
1215 |
def EditProjectElement(self, elementtype, tagname, onlyopened = False): |
|
1216 |
openedidx = self.IsOpened(tagname) |
|
1217 |
if openedidx is not None: |
|
1218 |
old_selected = self.GetPageSelection() |
|
1219 |
if old_selected != openedidx: |
|
1220 |
if old_selected >= 0: |
|
1221 |
self.GetPage(old_selected).ResetBuffer() |
|
1222 |
self.SetPageSelection(openedidx) |
|
1223 |
self.GetPage(openedidx).RefreshView() |
|
1224 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
1225 |
self.RefreshPageTitles() |
|
1226 |
self.RefreshFileMenu() |
|
1227 |
self.RefreshEditMenu() |
|
1228 |
self.RefreshToolBar() |
|
1229 |
elif not onlyopened: |
|
1230 |
if wx.VERSION >= (2, 8, 0): |
|
1231 |
if elementtype == ITEM_CONFIGURATION: |
|
1232 |
new_window = MDIConfigurationEditor(self, tagname, self, self.Controler) |
|
1233 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "config") |
|
1234 |
elif elementtype == ITEM_RESOURCE: |
|
1235 |
new_window = MDIResourceEditor(self, tagname, self, self.Controler) |
|
1236 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "resource") |
|
1237 |
elif elementtype in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
|
1238 |
bodytype = self.Controler.GetEditedElementBodyType(tagname) |
|
1239 |
if bodytype == "FBD": |
|
1240 |
new_window = MDIViewer(self, tagname, self, self.Controler) |
|
1241 |
elif bodytype == "LD": |
|
1242 |
new_window = LD_MDIViewer(self, tagname, self, self.Controler) |
|
1243 |
elif bodytype == "SFC": |
|
1244 |
new_window = SFC_MDIViewer(self, tagname, self, self.Controler) |
|
1245 |
else: |
|
1246 |
new_window = TextMDIViewer(self, tagname, self, self.Controler) |
|
1247 |
viewer = new_window.GetViewer() |
|
1248 |
viewer.SetTextSyntax(elementtype) |
|
1249 |
if bodytype == "IL": |
|
1250 |
viewer.SetKeywords(IL_KEYWORDS) |
|
1251 |
else: |
|
1252 |
viewer.SetKeywords(ST_KEYWORDS) |
|
1253 |
new_window.Bind(wx.EVT_ACTIVATE, self.OnPouSelectedChanged) |
|
1254 |
new_window.Bind(wx.EVT_CLOSE, self.OnPageClose) |
|
1255 |
else: |
|
1256 |
if elementtype == ITEM_CONFIGURATION: |
|
1257 |
new_window = ConfigurationEditor(self.TabsOpened, tagname, self, self.Controler) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1258 |
self.TabsOpened.AddPage(new_window, "") |
121 | 1259 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "config") |
1260 |
elif elementtype == ITEM_RESOURCE: |
|
1261 |
new_window = ResourceEditor(self.TabsOpened, tagname, self, self.Controler) |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1262 |
self.TabsOpened.AddPage(new_window, "") |
121 | 1263 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "resource") |
1264 |
elif elementtype in [ITEM_POU, ITEM_TRANSITION, ITEM_ACTION]: |
|
1265 |
bodytype = self.Controler.GetEditedElementBodyType(tagname) |
|
1266 |
if bodytype == "FBD": |
|
1267 |
new_window = Viewer(self.TabsOpened, tagname, self, self.Controler) |
|
1268 |
elif bodytype == "LD": |
|
1269 |
new_window = LD_Viewer(self.TabsOpened, tagname, self, self.Controler) |
|
1270 |
elif bodytype == "SFC": |
|
1271 |
new_window = SFC_Viewer(self.TabsOpened, tagname, self, self.Controler) |
|
1272 |
else: |
|
1273 |
new_window = TextViewer(self.TabsOpened, tagname, self, self.Controler) |
|
1274 |
new_window.SetTextSyntax(elementtype) |
|
1275 |
if bodytype == "IL": |
|
1276 |
new_window.SetKeywords(IL_KEYWORDS) |
|
1277 |
else: |
|
1278 |
new_window.SetKeywords(ST_KEYWORDS) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
1279 |
self.TabsOpened.AddPage(new_window, "") |
121 | 1280 |
if elementtype == ITEM_POU: |
1281 |
words = tagname.split("::") |
|
1282 |
self.VariablePanelIndexer.AddVariablePanel(tagname, self.Controler.GetPouType(words[1])) |
|
1283 |
elif elementtype == ITEM_TRANSITION: |
|
1284 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "transition") |
|
1285 |
elif elementtype == ITEM_TRANSITION: |
|
1286 |
self.VariablePanelIndexer.AddVariablePanel(tagname, "action") |
|
1287 |
self.VariablePanelIndexer.ChangeVariablePanel(tagname) |
|
1288 |
openedidx = self.IsOpened(tagname) |
|
1289 |
old_selected = self.GetPageSelection() |
|
1290 |
if old_selected != openedidx: |
|
1291 |
if old_selected >= 0: |
|
1292 |
self.GetPage(old_selected).ResetBuffer() |
|
1293 |
for i in xrange(self.GetPageCount()): |
|
1294 |
window = self.GetPage(i) |
|
1295 |
if window.GetTagName() == tagname: |
|
1296 |
self.SetPageSelection(i) |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1297 |
window.RefreshView() |
121 | 1298 |
self.RefreshPageTitles() |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1299 |
self.RefreshFileMenu() |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1300 |
self.RefreshEditMenu() |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1301 |
self.RefreshToolBar() |
0 | 1302 |
|
1303 |
def OnProjectTreeRightUp(self, event): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1304 |
cursor_pos = event.GetPosition() |
0 | 1305 |
selected = self.ProjectTree.GetSelection() |
1306 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1307 |
name = self.ProjectTree.GetItemText(selected) |
|
1308 |
if self.Controler.GetPouBodyType(name) == "SFC": |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1309 |
self.PopupMenuXY(self.SFCMenu, cursor_pos.x, cursor_pos.y) |
0 | 1310 |
elif self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
1311 |
self.PopupMenu(self.ConfigMenu) |
|
1312 |
event.Skip() |
|
1313 |
||
1314 |
def RefreshProjectTree(self): |
|
1315 |
infos = self.Controler.GetProjectInfos() |
|
1316 |
root = self.ProjectTree.GetRootItem() |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1317 |
if not root.IsOk(): |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1318 |
root = self.ProjectTree.AddRoot(infos["name"]) |
0 | 1319 |
self.GenerateTreeBranch(root, infos) |
1320 |
self.ProjectTree.Expand(self.ProjectTree.GetRootItem()) |
|
1321 |
||
1322 |
def GenerateTreeBranch(self, root, infos): |
|
1323 |
to_delete = [] |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1324 |
self.ProjectTree.SetItemText(root, infos["name"]) |
0 | 1325 |
self.ProjectTree.SetPyData(root, infos["type"]) |
95 | 1326 |
if infos["type"] == ITEM_POU and wx.Platform != '__WXMSW__': |
9 | 1327 |
self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"]))) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1328 |
if wx.VERSION >= (2, 5, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1329 |
item, root_cookie = self.ProjectTree.GetFirstChild(root) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1330 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1331 |
item, root_cookie = self.ProjectTree.GetFirstChild(root, 0) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1332 |
for values in infos["values"]: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1333 |
if not item.IsOk(): |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1334 |
item = self.ProjectTree.AppendItem(root, "") |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
1335 |
if wx.Platform != '__WXMSW__': |
0 | 1336 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1337 |
self.GenerateTreeBranch(item, values) |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
1338 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
0 | 1339 |
while item.IsOk(): |
1340 |
to_delete.append(item) |
|
27 | 1341 |
item, root_cookie = self.ProjectTree.GetNextChild(root, root_cookie) |
0 | 1342 |
for item in to_delete: |
1343 |
self.ProjectTree.Delete(item) |
|
27 | 1344 |
|
6 | 1345 |
def ResetToolBar(self): |
1346 |
for item in self.CurrentToolBar: |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1347 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1348 |
self.Unbind(wx.EVT_MENU, id=item) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1349 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1350 |
self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) |
120 | 1351 |
|
1352 |
if wx.VERSION < (2, 8, 0): |
|
1353 |
ToolBar = self.ToolBar |
|
1354 |
else: |
|
1355 |
ToolBar = self.Panes["ToolBar"] |
|
121 | 1356 |
if ToolBar: |
1357 |
ToolBar.DeleteTool(item) |
|
1358 |
ToolBar.Realize() |
|
1359 |
if wx.VERSION >= (2, 8, 0): |
|
1360 |
self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize()) |
|
1361 |
self.AUIManager.Update() |
|
6 | 1362 |
|
0 | 1363 |
def RefreshToolBar(self): |
121 | 1364 |
selected = self.GetPageSelection() |
1365 |
if selected != -1: |
|
1366 |
language = self.Controler.GetEditedElementBodyType(self.GetPage(selected).GetTagName()) |
|
1367 |
else: |
|
1368 |
language = None |
|
1369 |
if language is not None and language != self.CurrentLanguage: |
|
27 | 1370 |
self.ResetToolBar() |
1371 |
self.CurrentLanguage = language |
|
1372 |
self.CurrentToolBar = [] |
|
120 | 1373 |
if wx.VERSION < (2, 8, 0): |
1374 |
ToolBar = self.ToolBar |
|
1375 |
else: |
|
1376 |
ToolBar = self.Panes["ToolBar"] |
|
121 | 1377 |
if ToolBar: |
1378 |
for radio, modes, id, method, picture, help in ToolBarItems[language]: |
|
1379 |
if modes & self.DrawingMode: |
|
1380 |
if radio or self.DrawingMode == FREEDRAWING_MODE: |
|
1381 |
ToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help) |
|
1382 |
else: |
|
1383 |
ToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help) |
|
1384 |
self.Bind(wx.EVT_TOOL, getattr(self, method), id=id) |
|
1385 |
self.CurrentToolBar.append(id) |
|
1386 |
ToolBar.Realize() |
|
1387 |
if wx.VERSION >= (2, 8, 0): |
|
1388 |
self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize()) |
|
1389 |
self.AUIManager.Update() |
|
95 | 1390 |
elif not language: |
1391 |
self.ResetToolBar() |
|
1392 |
self.CurrentLanguage = language |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1393 |
self.ResetCurrentMode() |
0 | 1394 |
|
121 | 1395 |
def RefreshPageTitles(self): |
1396 |
for idx in xrange(self.GetPageCount()): |
|
1397 |
window = self.GetPage(idx) |
|
1398 |
words = window.GetTagName().split("::") |
|
1399 |
self.SetPageText(idx, "-".join(words[1:])) |
|
0 | 1400 |
|
1401 |
def OnRefreshMenu(self, event): |
|
121 | 1402 |
selected = self.GetPageSelection() |
0 | 1403 |
if selected != -1: |
121 | 1404 |
window = self.GetPage(selected) |
1405 |
window.RefreshView() |
|
1406 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
0 | 1407 |
event.Skip() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1408 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1409 |
def OnUndoMenu(self, event): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1410 |
self.Controler.LoadPrevious() |
121 | 1411 |
selected = self.GetPageSelection() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1412 |
if selected != -1: |
121 | 1413 |
window = self.GetPage(selected) |
1414 |
window.RefreshView() |
|
1415 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1416 |
self.RefreshTitle() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1417 |
self.RefreshEditMenu() |
80 | 1418 |
self.RefreshProjectTree() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1419 |
event.Skip() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1420 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1421 |
def OnRedoMenu(self, event): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1422 |
self.Controler.LoadNext() |
121 | 1423 |
selected = self.GetPageSelection() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1424 |
if selected != -1: |
121 | 1425 |
window = self.GetPage(selected) |
1426 |
window.RefreshView() |
|
1427 |
self.VariablePanelIndexer.RefreshVariablePanel(window.GetTagName()) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1428 |
self.RefreshTitle() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1429 |
self.RefreshEditMenu() |
80 | 1430 |
self.RefreshProjectTree() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1431 |
event.Skip() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
1432 |
|
0 | 1433 |
def OnCutMenu(self, event): |
121 | 1434 |
selected = self.GetPageSelection() |
0 | 1435 |
if selected != -1: |
51 | 1436 |
try: |
121 | 1437 |
self.GetPage(selected).Cut() |
51 | 1438 |
except: |
1439 |
pass |
|
0 | 1440 |
event.Skip() |
1441 |
||
1442 |
def OnCopyMenu(self, event): |
|
121 | 1443 |
selected = self.GetPageSelection() |
0 | 1444 |
if selected != -1: |
51 | 1445 |
try: |
121 | 1446 |
self.GetPage(selected).Copy() |
51 | 1447 |
except: |
1448 |
pass |
|
0 | 1449 |
event.Skip() |
1450 |
||
1451 |
def OnPasteMenu(self, event): |
|
121 | 1452 |
selected = self.GetPageSelection() |
0 | 1453 |
if selected != -1: |
51 | 1454 |
try: |
121 | 1455 |
self.GetPage(selected).Paste() |
51 | 1456 |
except: |
1457 |
pass |
|
0 | 1458 |
event.Skip() |
1459 |
||
1460 |
def OnAddPouMenu(self, event): |
|
1461 |
dialog = PouDialog(self) |
|
1462 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
70 | 1463 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1464 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1465 |
values = dialog.GetValues() |
1466 |
self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"]) |
|
80 | 1467 |
self.RefreshTitle() |
1468 |
self.RefreshEditMenu() |
|
0 | 1469 |
self.RefreshProjectTree() |
1470 |
dialog.Destroy() |
|
1471 |
event.Skip() |
|
1472 |
||
1473 |
def OnRemovePouMenu(self, event): |
|
1474 |
pous = self.Controler.GetProjectPouNames() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1475 |
dialog = wx.SingleChoiceDialog(self, "Select POU to remove:", "POU Remove", pous, wx.OK|wx.CANCEL) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1476 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1477 |
selected = dialog.GetStringSelection() |
1478 |
if not self.Controler.PouIsUsed(selected): |
|
1479 |
self.Controler.ProjectRemovePou(selected) |
|
121 | 1480 |
tagname = self.Controler.ComputePouName(selected) |
1481 |
idx = self.IsOpened(tagname) |
|
1482 |
if idx is not None: |
|
1483 |
self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName()) |
|
1484 |
self.DeletePage(idx) |
|
80 | 1485 |
self.RefreshTitle() |
1486 |
self.RefreshEditMenu() |
|
0 | 1487 |
self.RefreshProjectTree() |
1488 |
self.RefreshToolBar() |
|
1489 |
else: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1490 |
message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR) |
0 | 1491 |
message.ShowModal() |
1492 |
message.Destroy() |
|
1493 |
event.Skip() |
|
1494 |
||
1495 |
def OnAddConfigurationMenu(self, event): |
|
80 | 1496 |
dialog = ConfigurationNameDialog(self, "Please enter configuration name", "Add new configuration") |
1497 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1498 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1499 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1500 |
value = dialog.GetValue() |
1501 |
self.Controler.ProjectAddConfiguration(value) |
|
80 | 1502 |
self.RefreshTitle() |
1503 |
self.RefreshEditMenu() |
|
0 | 1504 |
self.RefreshProjectTree() |
1505 |
dialog.Destroy() |
|
1506 |
event.Skip() |
|
1507 |
||
1508 |
def OnRemoveConfigurationMenu(self, event): |
|
1509 |
configs = self.Controler.GetProjectConfigNames() |
|
80 | 1510 |
dialog = wx.SingleChoiceDialog(self, "Please select a configuration", "Remove configuration", configs, wx.OK|wx.CANCEL) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1511 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1512 |
selected = dialog.GetStringSelection() |
1513 |
self.Controler.ProjectRemoveConfiguration(selected) |
|
121 | 1514 |
tagname = self.Controler.ComputeConfigurationName(selected) |
1515 |
idx = self.IsOpened(tagname) |
|
1516 |
if idx is not None: |
|
1517 |
self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName()) |
|
1518 |
self.DeletePage(idx) |
|
80 | 1519 |
self.RefreshTitle() |
1520 |
self.RefreshEditMenu() |
|
0 | 1521 |
self.RefreshProjectTree() |
1522 |
event.Skip() |
|
1523 |
||
1524 |
def OnAddPouTransitionMenu(self, event): |
|
45 | 1525 |
selected = self.ProjectTree.GetSelection() |
1526 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1527 |
pouname = self.ProjectTree.GetItemText(selected) |
|
1528 |
if self.Controler.GetPouBodyType(pouname) == "SFC": |
|
1529 |
dialog = PouTransitionDialog(self) |
|
70 | 1530 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1531 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname)) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1532 |
if dialog.ShowModal() == wx.ID_OK: |
45 | 1533 |
values = dialog.GetValues() |
1534 |
self.Controler.ProjectAddPouTransition(pouname, values["transitionName"], values["language"]) |
|
80 | 1535 |
self.RefreshTitle() |
1536 |
self.RefreshEditMenu() |
|
45 | 1537 |
self.RefreshProjectTree() |
1538 |
dialog.Destroy() |
|
0 | 1539 |
event.Skip() |
1540 |
||
1541 |
def OnRemovePouTransitionMenu(self, event): |
|
46 | 1542 |
selected = self.ProjectTree.GetSelection() |
1543 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1544 |
pouname = self.ProjectTree.GetItemText(selected) |
|
1545 |
if self.Controler.GetPouBodyType(pouname) == "SFC": |
|
1546 |
transitions = self.Controler.GetPouTransitions(pouname) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1547 |
dialog = wx.SingleChoiceDialog(self, "Select Transition to remove:", "Remove transition", transitions, wx.OK|wx.CANCEL) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1548 |
if dialog.ShowModal() == wx.ID_OK: |
46 | 1549 |
selected = dialog.GetStringSelection() |
1550 |
self.Controler.ProjectRemovePouTransition(pouname, selected) |
|
121 | 1551 |
tagname = self.Controler.ComputePouTransitionName(pouname, selected) |
1552 |
idx = self.IsOpened(tagname) |
|
1553 |
if idx is not None: |
|
1554 |
self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName()) |
|
1555 |
self.DeletePage(idx) |
|
80 | 1556 |
self.RefreshTitle() |
1557 |
self.RefreshEditMenu() |
|
46 | 1558 |
self.RefreshProjectTree() |
1559 |
dialog.Destroy() |
|
0 | 1560 |
event.Skip() |
1561 |
||
1562 |
def OnAddPouActionMenu(self, event): |
|
45 | 1563 |
selected = self.ProjectTree.GetSelection() |
1564 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1565 |
pouname = self.ProjectTree.GetItemText(selected) |
|
1566 |
if self.Controler.GetPouBodyType(pouname) == "SFC": |
|
1567 |
dialog = PouActionDialog(self) |
|
70 | 1568 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1569 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pouname)) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1570 |
if dialog.ShowModal() == wx.ID_OK: |
45 | 1571 |
values = dialog.GetValues() |
1572 |
self.Controler.ProjectAddPouAction(pouname, values["actionName"], values["language"]) |
|
80 | 1573 |
self.RefreshTitle() |
1574 |
self.RefreshEditMenu() |
|
45 | 1575 |
self.RefreshProjectTree() |
1576 |
dialog.Destroy() |
|
0 | 1577 |
event.Skip() |
1578 |
||
1579 |
def OnRemovePouActionMenu(self, event): |
|
46 | 1580 |
selected = self.ProjectTree.GetSelection() |
1581 |
if self.ProjectTree.GetPyData(selected) == ITEM_POU: |
|
1582 |
pouname = self.ProjectTree.GetItemText(selected) |
|
1583 |
if self.Controler.GetPouBodyType(pouname) == "SFC": |
|
1584 |
actions = self.Controler.GetPouActions(pouname) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1585 |
dialog = wx.SingleChoiceDialog(self, "Select Action to remove:", "Remove action", actions, wx.OK|wx.CANCEL) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1586 |
if dialog.ShowModal() == wx.ID_OK: |
46 | 1587 |
selected = dialog.GetStringSelection() |
1588 |
self.Controler.ProjectRemovePouAction(pouname, selected) |
|
121 | 1589 |
tagname = self.Controler.ComputePouActionName(pouname, selected) |
1590 |
idx = self.IsOpened(tagname) |
|
1591 |
if idx is not None: |
|
1592 |
self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName()) |
|
1593 |
self.DeletePage(idx) |
|
80 | 1594 |
self.RefreshTitle() |
1595 |
self.RefreshEditMenu() |
|
46 | 1596 |
self.RefreshProjectTree() |
1597 |
dialog.Destroy() |
|
0 | 1598 |
event.Skip() |
1599 |
||
1600 |
def OnAddResourceMenu(self, event): |
|
1601 |
selected = self.ProjectTree.GetSelection() |
|
1602 |
if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
1603 |
config_name = self.ProjectTree.GetItemText(selected) |
|
80 | 1604 |
dialog = ResourceNameDialog(self, "Please enter resource name", "Add new resource") |
1605 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
|
1606 |
dialog.SetPouElementNames(self.Controler.GetProjectPouVariables()) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1607 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1608 |
value = dialog.GetValue() |
1609 |
self.Controler.ProjectAddConfigurationResource(config_name, value) |
|
121 | 1610 |
tagname = self.Controler.ComputeConfigurationResourceName(config_name, selected) |
1611 |
idx = self.IsOpened(tagname) |
|
1612 |
if idx is not None: |
|
1613 |
self.VariablePanelIndexer.RemoveVariablePanel(self.GetPage(idx).GetTagName()) |
|
1614 |
self.DeletePage(idx) |
|
80 | 1615 |
self.RefreshTitle() |
1616 |
self.RefreshEditMenu() |
|
0 | 1617 |
self.RefreshProjectTree() |
1618 |
dialog.Destroy() |
|
1619 |
event.Skip() |
|
1620 |
||
1621 |
def OnRemoveResourceMenu(self, event): |
|
1622 |
selected = self.ProjectTree.GetSelection() |
|
1623 |
if self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION: |
|
1624 |
config_name = self.ProjectTree.GetItemText(selected) |
|
1625 |
infos = self.Controler.GetProjectInfos() |
|
1626 |
resources = [] |
|
1627 |
for config in infos["configs"]: |
|
1628 |
if config["name"] == config_name: |
|
1629 |
resources = config["resources"] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1630 |
dialog = wx.SingleChoiceDialog(self, "Select Resource to remove:", "Remove resource", resources, wx.OK|wx.CANCEL) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1631 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 1632 |
resource = dialog.GetStringSelection() |
1633 |
self.Controler.ProjectRemoveConfigurationResource(config_name, resource) |
|
80 | 1634 |
self.RefreshTitle() |
1635 |
self.RefreshEditMenu() |
|
0 | 1636 |
self.RefreshProjectTree() |
1637 |
dialog.Destroy() |
|
1638 |
event.Skip() |
|
1639 |
||
1640 |
def OnPLCOpenMenu(self, event): |
|
1641 |
result = OpenPDFDoc() |
|
1642 |
if type(result) == StringType: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1643 |
message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 1644 |
message.ShowModal() |
1645 |
message.Destroy() |
|
1646 |
event.Skip() |
|
1647 |
||
1648 |
current_num = 0 |
|
1649 |
def GetNewNum(): |
|
1650 |
global current_num |
|
1651 |
current_num += 1 |
|
1652 |
return current_num |
|
1653 |
||
1654 |
#------------------------------------------------------------------------------- |
|
1655 |
# Create Project Dialog |
|
1656 |
#------------------------------------------------------------------------------- |
|
1657 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1658 |
[ID_PROJECTDIALOG, ID_PROJECTDIALOGPROJECTNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1659 |
ID_PROJECTDIALOGCOMPANYNAME, ID_PROJECTDIALOGCOMPANYURL, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1660 |
ID_PROJECTDIALOGPRODUCTNAME, ID_PROJECTDIALOGPRODUCTVERSION, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1661 |
ID_PROJECTDIALOGPRODUCTRELEASE, ID_PROJECTDIALOGCONTENTDESCRIPTION, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1662 |
ID_PROJECTDIALOGSTATICTEXT1, ID_PROJECTDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1663 |
ID_PROJECTDIALOGSTATICTEXT3, ID_PROJECTDIALOGSTATICTEXT4, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1664 |
ID_PROJECTDIALOGSTATICTEXT5, ID_PROJECTDIALOGSTATICTEXT6, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1665 |
ID_PROJECTDIALOGSTATICTEXT7, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1666 |
] = [wx.NewId() for _init_ctrls in range(15)] |
0 | 1667 |
|
1668 |
class ProjectDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1669 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1670 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1671 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1672 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1673 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1674 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1675 |
|
0 | 1676 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1677 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1678 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1679 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1680 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1681 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1682 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1683 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1684 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1685 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1686 |
parent.AddWindow(self.ProjectName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1687 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1688 |
parent.AddWindow(self.CompanyName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1689 |
parent.AddWindow(self.staticText3, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1690 |
parent.AddWindow(self.CompanyURL, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1691 |
parent.AddWindow(self.staticText4, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1692 |
parent.AddWindow(self.ProductName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1693 |
parent.AddWindow(self.staticText5, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1694 |
parent.AddWindow(self.ProductVersion, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1695 |
parent.AddWindow(self.staticText6, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1696 |
parent.AddWindow(self.ProductRelease, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1697 |
parent.AddWindow(self.staticText7, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1698 |
parent.AddWindow(self.ContentDescription, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1699 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1700 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1701 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1702 |
parent.AddGrowableRow(6) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1703 |
|
0 | 1704 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1705 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1706 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=7, vgap=15) |
0 | 1707 |
|
1708 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1709 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1710 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1711 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 1712 |
|
1713 |
self.SetSizer(self.flexGridSizer1) |
|
1714 |
||
1715 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1716 |
wx.Dialog.__init__(self, id=ID_PROJECTDIALOG, |
0 | 1717 |
name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), |
1718 |
size=wx.Size(550, 450), style=wx.DEFAULT_DIALOG_STYLE, |
|
1719 |
title='Create a new project') |
|
1720 |
self.SetClientSize(wx.Size(550, 450)) |
|
1721 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1722 |
self.staticText1 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1723 |
label='Project Name (required):', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1724 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1725 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1726 |
self.ProjectName = wx.TextCtrl(id=ID_PROJECTDIALOGPROJECTNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1727 |
name='ProjectName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1728 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1729 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1730 |
self.staticText2 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1731 |
label='Company Name (required):', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1732 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1733 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1734 |
self.CompanyName = wx.TextCtrl(id=ID_PROJECTDIALOGCOMPANYNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1735 |
name='CompanyName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1736 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1737 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1738 |
self.staticText3 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1739 |
label='Company URL (optional):', name='staticText3', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1740 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1741 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1742 |
self.CompanyURL = wx.TextCtrl(id=ID_PROJECTDIALOGCOMPANYURL, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1743 |
name='CompanyURL', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1744 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1745 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1746 |
self.staticText4 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT4, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1747 |
label='Product Name (required):', name='staticText4', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1748 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1749 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1750 |
self.ProductName = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1751 |
name='ProductName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1752 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1753 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1754 |
self.staticText5 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT5, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1755 |
label='Product Version (required):', name='staticText5', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1756 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1757 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1758 |
self.ProductVersion = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTVERSION, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1759 |
name='ProductVersion', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1760 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1761 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1762 |
self.staticText6 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT6, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1763 |
label='Product Release (optional):', name='staticText6', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1764 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1765 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1766 |
self.ProductRelease = wx.TextCtrl(id=ID_PROJECTDIALOGPRODUCTRELEASE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1767 |
name='ProductRelease', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1768 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1769 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1770 |
self.staticText7 = wx.StaticText(id=ID_PROJECTDIALOGSTATICTEXT7, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1771 |
label='Content Description (optional):', name='staticText7', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1772 |
pos=wx.Point(0, 0), size=wx.Size(200, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1773 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1774 |
self.ContentDescription = wx.TextCtrl(id=ID_PROJECTDIALOGCONTENTDESCRIPTION, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1775 |
name='ProductRelease', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1776 |
size=wx.Size(0, 120), style=wx.TE_MULTILINE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1777 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1778 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1779 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1780 |
|
0 | 1781 |
self._init_sizers() |
1782 |
||
1783 |
def __init__(self, parent): |
|
1784 |
self._init_ctrls(parent) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1785 |
|
0 | 1786 |
def OnOK(self, event): |
1787 |
error = [] |
|
1788 |
if self.ProjectName.GetValue() == "": |
|
1789 |
error.append("Project Name") |
|
1790 |
if self.CompanyName.GetValue() == "": |
|
1791 |
error.append("Company Name") |
|
1792 |
if self.ProductName.GetValue() == "": |
|
1793 |
error.append("Product Name") |
|
1794 |
if self.ProductVersion.GetValue() == "": |
|
1795 |
error.append("Product Version") |
|
1796 |
if len(error) > 0: |
|
1797 |
text = "" |
|
1798 |
for i, item in enumerate(error): |
|
1799 |
if i == 0: |
|
1800 |
text += item |
|
1801 |
elif i == len(error) - 1: |
|
1802 |
text += " and %s"%item |
|
1803 |
else: |
|
1804 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1805 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 1806 |
message.ShowModal() |
1807 |
message.Destroy() |
|
1808 |
else: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1809 |
self.EndModal(wx.ID_OK) |
0 | 1810 |
|
1811 |
def SetValues(self, values): |
|
1812 |
for item, value in values.items(): |
|
1813 |
if item == "projectName": |
|
1814 |
self.ProjectName.SetValue(value) |
|
1815 |
elif item == "companyName": |
|
1816 |
self.CompanyName.SetValue(value) |
|
1817 |
elif item == "companyURL": |
|
1818 |
self.CompanyURL.SetValue(value) |
|
1819 |
elif item == "productName": |
|
1820 |
self.ProductName.SetValue(value) |
|
1821 |
elif item == "productVersion": |
|
1822 |
self.ProductVersion.SetValue(value) |
|
1823 |
elif item == "productRelease": |
|
1824 |
self.ProductRelease.SetValue(value) |
|
1825 |
elif item == "contentDescription": |
|
1826 |
self.ContentDescription.SetValue(value) |
|
1827 |
||
1828 |
def GetValues(self): |
|
1829 |
values = {} |
|
1830 |
values["projectName"] = self.ProjectName.GetValue() |
|
1831 |
values["companyName"] = self.CompanyName.GetValue() |
|
1832 |
if self.CompanyURL.GetValue() != None: |
|
1833 |
values["companyURL"] = self.CompanyURL.GetValue() |
|
1834 |
values["productName"] = self.ProductName.GetValue() |
|
1835 |
values["productVersion"] = self.ProductVersion.GetValue() |
|
1836 |
if self.ProductRelease.GetValue() != None: |
|
1837 |
values["productRelease"] = self.ProductRelease.GetValue() |
|
1838 |
if self.ProductRelease.GetValue() != None: |
|
1839 |
values["contentDescription"] = self.ContentDescription.GetValue() |
|
1840 |
return values |
|
1841 |
||
1842 |
#------------------------------------------------------------------------------- |
|
1843 |
# Create Pou Dialog |
|
1844 |
#------------------------------------------------------------------------------- |
|
1845 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1846 |
[ID_POUDIALOG, ID_POUDIALOGPOUNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1847 |
ID_POUDIALOGPOUTYPE, ID_POUDIALOGLANGUAGE, ID_POUDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1848 |
ID_POUDIALOGSTATICTEXT2, ID_POUDIALOGSTATICTEXT3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1849 |
] = [wx.NewId() for _init_ctrls in range(7)] |
0 | 1850 |
|
1851 |
class PouDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1852 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1853 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1854 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1855 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1856 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1857 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
1858 |
|
0 | 1859 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1860 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1861 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1862 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1863 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1864 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1865 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1866 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1867 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1868 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1869 |
parent.AddWindow(self.PouName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1870 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1871 |
parent.AddWindow(self.PouType, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
1872 |
parent.AddWindow(self.staticText3, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1873 |
parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1874 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1875 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1876 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1877 |
|
0 | 1878 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1879 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1880 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=3, vgap=15) |
0 | 1881 |
|
1882 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1883 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1884 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1885 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 1886 |
|
1887 |
self.SetSizer(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1888 |
|
0 | 1889 |
def _init_ctrls(self, prnt): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1890 |
wx.Dialog.__init__(self, id=ID_POUDIALOG, |
16 | 1891 |
name='PouDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 1892 |
size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, |
16 | 1893 |
title='Create a new POU') |
0 | 1894 |
self.SetClientSize(wx.Size(300, 200)) |
1895 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1896 |
self.staticText1 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1897 |
label='POU Name:', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1898 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1899 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1900 |
self.PouName = wx.TextCtrl(id=ID_POUDIALOGPOUNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1901 |
name='POUName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1902 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1903 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1904 |
self.staticText2 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1905 |
label='POU Type:', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1906 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1907 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1908 |
self.PouType = wx.Choice(id=ID_POUDIALOGPOUTYPE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1909 |
name='POUType', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1910 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1911 |
self.Bind(wx.EVT_CHOICE, self.OnTypeChanged, id=ID_POUDIALOGPOUTYPE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1912 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1913 |
self.staticText3 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT3, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1914 |
label='Language:', name='staticText3', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1915 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1916 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1917 |
self.Language = wx.Choice(id=ID_POUDIALOGLANGUAGE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1918 |
name='Language', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1919 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1920 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1921 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1922 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1923 |
|
0 | 1924 |
self._init_sizers() |
1925 |
||
1926 |
def __init__(self, parent): |
|
1927 |
self._init_ctrls(parent) |
|
1928 |
||
1929 |
for option in ["function","functionBlock","program"]: |
|
1930 |
self.PouType.Append(option) |
|
1931 |
self.RefreshLanguage() |
|
1932 |
||
6 | 1933 |
self.PouNames = [] |
70 | 1934 |
self.PouElementNames = [] |
6 | 1935 |
|
0 | 1936 |
def OnOK(self, event): |
1937 |
error = [] |
|
1938 |
pou_name = self.PouName.GetValue() |
|
1939 |
if pou_name == "": |
|
1940 |
error.append("POU Name") |
|
1941 |
if self.PouType.GetStringSelection() == "": |
|
1942 |
error.append("POU Type") |
|
1943 |
if self.Language.GetStringSelection() == "": |
|
1944 |
error.append("Language") |
|
1945 |
if len(error) > 0: |
|
1946 |
text = "" |
|
1947 |
for i, item in enumerate(error): |
|
1948 |
if i == 0: |
|
1949 |
text += item |
|
1950 |
elif i == len(error) - 1: |
|
1951 |
text += " and %s"%item |
|
1952 |
else: |
|
1953 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1954 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 1955 |
message.ShowModal() |
1956 |
message.Destroy() |
|
1957 |
elif not TestIdentifier(pou_name): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1958 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) |
0 | 1959 |
message.ShowModal() |
1960 |
message.Destroy() |
|
1961 |
elif pou_name.upper() in IEC_KEYWORDS: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1962 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) |
0 | 1963 |
message.ShowModal() |
1964 |
message.Destroy() |
|
1965 |
elif pou_name.upper() in self.PouNames: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1966 |
message = wx.MessageDialog(self, "\"%s\" pou already exists!"%pou_name, "Error", wx.OK|wx.ICON_ERROR) |
0 | 1967 |
message.ShowModal() |
1968 |
message.Destroy() |
|
70 | 1969 |
elif pou_name.upper() in self.PouElementNames: |
1970 |
message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%pou_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) |
|
1971 |
result = message.ShowModal() |
|
1972 |
message.Destroy() |
|
1973 |
if result == wx.ID_YES: |
|
1974 |
self.EndModal(wx.ID_OK) |
|
0 | 1975 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1976 |
self.EndModal(wx.ID_OK) |
0 | 1977 |
|
1978 |
def RefreshLanguage(self): |
|
1979 |
selection = self.Language.GetStringSelection() |
|
1980 |
self.Language.Clear() |
|
1981 |
for option in ["IL","ST","LD","FBD","SFC"]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1982 |
if option != "SFC" or self.PouType.GetStringSelection() != "function": |
0 | 1983 |
self.Language.Append(option) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1984 |
if self.Language.FindString(selection) != wx.NOT_FOUND: |
0 | 1985 |
self.Language.SetStringSelection(selection) |
1986 |
||
1987 |
def OnTypeChanged(self, event): |
|
1988 |
self.RefreshLanguage() |
|
1989 |
event.Skip() |
|
1990 |
||
1991 |
def SetPouNames(self, pou_names): |
|
1992 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
1993 |
||
70 | 1994 |
def SetPouElementNames(self, element_names): |
1995 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
|
1996 |
||
0 | 1997 |
def SetValues(self, values): |
1998 |
for item, value in values.items(): |
|
1999 |
if item == "pouName": |
|
2000 |
self.PouName.SetValue(value) |
|
2001 |
elif item == "pouType": |
|
2002 |
self.PouType.SetStringSelection(value) |
|
2003 |
elif item == "language": |
|
2004 |
self.Language.SetStringSelection(value) |
|
2005 |
||
2006 |
def GetValues(self): |
|
2007 |
values = {} |
|
2008 |
values["pouName"] = self.PouName.GetValue() |
|
2009 |
values["pouType"] = self.PouType.GetStringSelection() |
|
2010 |
values["language"] = self.Language.GetStringSelection() |
|
2011 |
return values |
|
2012 |
||
2013 |
||
2014 |
#------------------------------------------------------------------------------- |
|
2015 |
# Create Pou Transition Dialog |
|
2016 |
#------------------------------------------------------------------------------- |
|
2017 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2018 |
[ID_POUTRANSITIONDIALOG, ID_POUTRANSITIONDIALOGTRANSITIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2019 |
ID_POUTRANSITIONDIALOGLANGUAGE, ID_POUTRANSITIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2020 |
ID_POUTRANSITIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2021 |
] = [wx.NewId() for _init_ctrls in range(5)] |
0 | 2022 |
|
2023 |
class PouTransitionDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2024 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2025 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2026 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2027 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2028 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2029 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2030 |
|
0 | 2031 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2032 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2033 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2034 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2035 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2036 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2037 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2038 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2039 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2040 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2041 |
parent.AddWindow(self.TransitionName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2042 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2043 |
parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2044 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2045 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2046 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2047 |
|
0 | 2048 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2049 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2050 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) |
0 | 2051 |
|
2052 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2053 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2054 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2055 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 2056 |
|
2057 |
self.SetSizer(self.flexGridSizer1) |
|
2058 |
||
2059 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2060 |
wx.Dialog.__init__(self, id=ID_POUTRANSITIONDIALOG, |
45 | 2061 |
name='PouTransitionDialog', parent=prnt, pos=wx.Point(376, 223), |
0 | 2062 |
size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE, |
45 | 2063 |
title='Create a new transition') |
2064 |
self.SetClientSize(wx.Size(350, 160)) |
|
0 | 2065 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2066 |
self.staticText1 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2067 |
label='Transition Name:', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2068 |
pos=wx.Point(0, 0), size=wx.Size(120, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2069 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2070 |
self.TransitionName = wx.TextCtrl(id=ID_POUTRANSITIONDIALOGTRANSITIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2071 |
name='TransitionName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2072 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2073 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2074 |
self.staticText2 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2075 |
label='Language:', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2076 |
pos=wx.Point(0, 0), size=wx.Size(120, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2077 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2078 |
self.Language = wx.Choice(id=ID_POUTRANSITIONDIALOGLANGUAGE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2079 |
name='Language', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2080 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2081 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2082 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2083 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2084 |
|
0 | 2085 |
self._init_sizers() |
2086 |
||
2087 |
def __init__(self, parent): |
|
2088 |
self._init_ctrls(parent) |
|
45 | 2089 |
|
0 | 2090 |
for option in ["IL","ST","LD","FBD"]: |
2091 |
self.Language.Append(option) |
|
70 | 2092 |
|
2093 |
self.PouNames = [] |
|
2094 |
self.PouElementNames = [] |
|
0 | 2095 |
|
2096 |
def OnOK(self, event): |
|
2097 |
error = [] |
|
70 | 2098 |
transition_name = self.TransitionName.GetValue() |
0 | 2099 |
if self.TransitionName.GetValue() == "": |
2100 |
error.append("Transition Name") |
|
2101 |
if self.Language.GetStringSelection() == "": |
|
2102 |
error.append("Language") |
|
2103 |
if len(error) > 0: |
|
2104 |
text = "" |
|
2105 |
for i, item in enumerate(error): |
|
2106 |
if i == 0: |
|
2107 |
text += item |
|
2108 |
elif i == len(error) - 1: |
|
2109 |
text += " and %s"%item |
|
2110 |
else: |
|
2111 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2112 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2113 |
message.ShowModal() |
2114 |
message.Destroy() |
|
70 | 2115 |
elif not TestIdentifier(transition_name): |
2116 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2117 |
message.ShowModal() |
|
2118 |
message.Destroy() |
|
2119 |
elif transition_name.upper() in IEC_KEYWORDS: |
|
2120 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2121 |
message.ShowModal() |
|
2122 |
message.Destroy() |
|
2123 |
elif transition_name.upper() in self.PouNames: |
|
2124 |
message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2125 |
message.ShowModal() |
|
2126 |
message.Destroy() |
|
2127 |
elif transition_name.upper() in self.PouElementNames: |
|
2128 |
message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%transition_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2129 |
message.ShowModal() |
|
2130 |
message.Destroy() |
|
0 | 2131 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2132 |
self.EndModal(wx.ID_OK) |
70 | 2133 |
|
2134 |
def SetPouNames(self, pou_names): |
|
2135 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2136 |
||
2137 |
def SetPouElementNames(self, pou_names): |
|
2138 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
2139 |
||
0 | 2140 |
def SetValues(self, values): |
2141 |
for item, value in values.items(): |
|
45 | 2142 |
if item == "transitionName": |
0 | 2143 |
self.TransitionName.SetValue(value) |
2144 |
elif item == "language": |
|
2145 |
self.Language.SetStringSelection(value) |
|
2146 |
||
2147 |
def GetValues(self): |
|
2148 |
values = {} |
|
2149 |
values["transitionName"] = self.TransitionName.GetValue() |
|
2150 |
values["language"] = self.Language.GetStringSelection() |
|
2151 |
return values |
|
2152 |
||
2153 |
#------------------------------------------------------------------------------- |
|
2154 |
# Create Pou Action Dialog |
|
2155 |
#------------------------------------------------------------------------------- |
|
2156 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2157 |
[ID_POUACTIONDIALOG, ID_POUACTIONDIALOGACTIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2158 |
ID_POUACTIONDIALOGLANGUAGE, ID_POUACTIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2159 |
ID_POUACTIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2160 |
] = [wx.NewId() for _init_ctrls in range(5)] |
0 | 2161 |
|
2162 |
class PouActionDialog(wx.Dialog): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2163 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2164 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2165 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2166 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2167 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2168 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2169 |
|
0 | 2170 |
def _init_coll_flexGridSizer1_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2171 |
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2172 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2173 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2174 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2175 |
parent.AddGrowableCol(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2176 |
parent.AddGrowableRow(0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2177 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2178 |
def _init_coll_MainSizer_Items(self, parent): |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2179 |
parent.AddWindow(self.staticText1, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2180 |
parent.AddWindow(self.ActionName, 0, border=0, flag=wx.GROW) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
114
diff
changeset
|
2181 |
parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2182 |
parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2183 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2184 |
def _init_coll_MainSizer_Growables(self, parent): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2185 |
parent.AddGrowableCol(1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2186 |
|
0 | 2187 |
def _init_sizers(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2188 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2189 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=2, vgap=15) |
0 | 2190 |
|
2191 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2192 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2193 |
self._init_coll_MainSizer_Items(self.MainSizer) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2194 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
0 | 2195 |
|
2196 |
self.SetSizer(self.flexGridSizer1) |
|
2197 |
||
2198 |
def _init_ctrls(self, prnt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2199 |
wx.Dialog.__init__(self, id=ID_POUACTIONDIALOG, |
45 | 2200 |
name='PouActionDialog', parent=prnt, pos=wx.Point(376, 223), |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2201 |
size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, |
45 | 2202 |
title='Create a new action') |
2203 |
self.SetClientSize(wx.Size(320, 160)) |
|
0 | 2204 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2205 |
self.staticText1 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT1, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2206 |
label='Action Name:', name='staticText1', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2207 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2208 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2209 |
self.ActionName = wx.TextCtrl(id=ID_POUACTIONDIALOGACTIONNAME, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2210 |
name='ActionName', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2211 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2212 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2213 |
self.staticText2 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT2, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2214 |
label='Language:', name='staticText2', parent=self, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2215 |
pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2216 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2217 |
self.Language = wx.Choice(id=ID_POUACTIONDIALOGLANGUAGE, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2218 |
name='Language', parent=self, pos=wx.Point(0, 0), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2219 |
size=wx.Size(0, 24), style=0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2220 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2221 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2222 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2223 |
|
0 | 2224 |
self._init_sizers() |
2225 |
||
2226 |
def __init__(self, parent): |
|
2227 |
self._init_ctrls(parent) |
|
45 | 2228 |
|
0 | 2229 |
for option in ["IL","ST","LD","FBD"]: |
2230 |
self.Language.Append(option) |
|
2231 |
||
70 | 2232 |
self.PouNames = [] |
2233 |
self.PouElementNames = [] |
|
2234 |
||
0 | 2235 |
def OnOK(self, event): |
2236 |
error = [] |
|
70 | 2237 |
action_name = self.ActionName.GetValue() |
2238 |
if action_name == "": |
|
0 | 2239 |
error.append("Action Name") |
2240 |
if self.Language.GetStringSelection() == "": |
|
2241 |
error.append("Language") |
|
2242 |
if len(error) > 0: |
|
2243 |
text = "" |
|
2244 |
for i, item in enumerate(error): |
|
2245 |
if i == 0: |
|
2246 |
text += item |
|
2247 |
elif i == len(error) - 1: |
|
2248 |
text += " and %s"%item |
|
2249 |
else: |
|
2250 |
text += ", %s"%item |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2251 |
message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) |
0 | 2252 |
message.ShowModal() |
2253 |
message.Destroy() |
|
70 | 2254 |
elif not TestIdentifier(action_name): |
2255 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2256 |
message.ShowModal() |
|
2257 |
message.Destroy() |
|
2258 |
elif action_name.upper() in IEC_KEYWORDS: |
|
2259 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2260 |
message.ShowModal() |
|
2261 |
message.Destroy() |
|
2262 |
elif action_name.upper() in self.PouNames: |
|
2263 |
message = wx.MessageDialog(self, "A pou with \"%s\" for name exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2264 |
message.ShowModal() |
|
2265 |
message.Destroy() |
|
2266 |
elif action_name.upper() in self.PouElementNames: |
|
2267 |
message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%action_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2268 |
message.ShowModal() |
|
2269 |
message.Destroy() |
|
0 | 2270 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2271 |
self.EndModal(wx.ID_OK) |
70 | 2272 |
|
2273 |
def SetPouNames(self, pou_names): |
|
2274 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2275 |
||
2276 |
def SetPouElementNames(self, element_names): |
|
2277 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
|
2278 |
||
0 | 2279 |
def SetValues(self, values): |
2280 |
for item, value in values.items(): |
|
45 | 2281 |
if item == "actionName": |
0 | 2282 |
self.ActionName.SetValue(value) |
2283 |
elif item == "language": |
|
2284 |
self.Language.SetStringSelection(value) |
|
2285 |
||
2286 |
def GetValues(self): |
|
2287 |
values = {} |
|
2288 |
values["actionName"] = self.ActionName.GetValue() |
|
2289 |
values["language"] = self.Language.GetStringSelection() |
|
2290 |
return values |
|
2291 |
||
2292 |
#------------------------------------------------------------------------------- |
|
80 | 2293 |
# Configuration Name Dialog |
2294 |
#------------------------------------------------------------------------------- |
|
2295 |
||
2296 |
class ConfigurationNameDialog(wx.TextEntryDialog): |
|
2297 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2298 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2299 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2300 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2301 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2302 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2303 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2304 |
|
80 | 2305 |
def __init__(self, parent, message, caption = "Please enter configuration name", defaultValue = "", |
2306 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
|
2307 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
2308 |
||
2309 |
self.PouNames = [] |
|
2310 |
self.PouElementNames = [] |
|
2311 |
||
2312 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
2313 |
||
2314 |
def OnOK(self, event): |
|
2315 |
config_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2316 |
if config_name == "": |
|
2317 |
message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
|
2318 |
message.ShowModal() |
|
2319 |
message.Destroy() |
|
2320 |
elif not TestIdentifier(config_name): |
|
2321 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%config_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2322 |
message.ShowModal() |
|
2323 |
message.Destroy() |
|
2324 |
elif config_name.upper() in IEC_KEYWORDS: |
|
2325 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%config_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2326 |
message.ShowModal() |
|
2327 |
message.Destroy() |
|
2328 |
elif config_name.upper() in self.PouNames: |
|
2329 |
message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%config_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2330 |
message.ShowModal() |
|
2331 |
message.Destroy() |
|
2332 |
elif config_name.upper() in self.PouElementNames: |
|
2333 |
message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%config_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) |
|
2334 |
result = message.ShowModal() |
|
2335 |
message.Destroy() |
|
2336 |
if result == wx.ID_YES: |
|
2337 |
self.EndModal(wx.ID_OK) |
|
2338 |
else: |
|
2339 |
self.EndModal(wx.ID_OK) |
|
2340 |
||
2341 |
def SetPouNames(self, pou_names): |
|
2342 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2343 |
||
2344 |
def SetPouElementNames(self, pou_names): |
|
2345 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
2346 |
||
2347 |
def GetValue(self): |
|
2348 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2349 |
||
2350 |
#------------------------------------------------------------------------------- |
|
2351 |
# Resource Name Dialog |
|
2352 |
#------------------------------------------------------------------------------- |
|
2353 |
||
2354 |
class ResourceNameDialog(wx.TextEntryDialog): |
|
2355 |
||
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2356 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2357 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2358 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2359 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2360 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2361 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2362 |
|
80 | 2363 |
def __init__(self, parent, message, caption = "Please enter resource name", defaultValue = "", |
2364 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
|
2365 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
2366 |
||
2367 |
self.PouNames = [] |
|
2368 |
self.PouElementNames = [] |
|
2369 |
||
2370 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
2371 |
||
2372 |
def OnOK(self, event): |
|
2373 |
resource_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2374 |
if resource_name == "": |
|
2375 |
message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
|
2376 |
message.ShowModal() |
|
2377 |
message.Destroy() |
|
2378 |
elif not TestIdentifier(resource_name): |
|
2379 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%resource_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2380 |
message.ShowModal() |
|
2381 |
message.Destroy() |
|
2382 |
elif resource_name.upper() in IEC_KEYWORDS: |
|
2383 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%resource_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2384 |
message.ShowModal() |
|
2385 |
message.Destroy() |
|
2386 |
elif resource_name.upper() in self.PouNames: |
|
2387 |
message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%resource_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2388 |
message.ShowModal() |
|
2389 |
message.Destroy() |
|
2390 |
elif resource_name.upper() in self.PouElementNames: |
|
2391 |
message = wx.MessageDialog(self, "A pou has an element with \"%s\" for name. It can generate a conflict. Do you wish to continue?"%resource_name, "Warning", wx.YES_NO|wx.ICON_EXCLAMATION) |
|
2392 |
result = message.ShowModal() |
|
2393 |
message.Destroy() |
|
2394 |
if result == wx.ID_YES: |
|
2395 |
self.EndModal(wx.ID_OK) |
|
2396 |
else: |
|
2397 |
self.EndModal(wx.ID_OK) |
|
2398 |
||
2399 |
def SetPouNames(self, pou_names): |
|
2400 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2401 |
||
2402 |
def SetPouElementNames(self, pou_names): |
|
2403 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
2404 |
||
2405 |
def GetValue(self): |
|
2406 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2407 |
||
2408 |
#------------------------------------------------------------------------------- |
|
121 | 2409 |
# Variables Editor Panel |
2410 |
#------------------------------------------------------------------------------- |
|
2411 |
||
2412 |
class VariablePanelIndexer(wx.Panel): |
|
2413 |
||
2414 |
def _init_sizers(self): |
|
2415 |
self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
2416 |
||
2417 |
self.SetSizer(self.MainSizer) |
|
2418 |
||
2419 |
def _init_ctrls(self, prnt): |
|
2420 |
wx.Panel.__init__(self, id=wx.NewId(), |
|
2421 |
name='VariablePanelIndexer', parent=prnt, pos=wx.Point(0, 0), |
|
2422 |
size=wx.Size(0, 300), style=wx.TAB_TRAVERSAL) |
|
2423 |
||
2424 |
self._init_sizers() |
|
2425 |
||
2426 |
def __init__(self, parent, controler): |
|
2427 |
self._init_ctrls(parent) |
|
2428 |
||
2429 |
self.ParentWindow = parent |
|
2430 |
self.Controler = controler |
|
2431 |
||
2432 |
self.VariablePanelList = {} |
|
2433 |
self.CurrentPanel = None |
|
2434 |
||
2435 |
def AddVariablePanel(self, tagname, element_type): |
|
2436 |
new_panel = VariablePanel(self, self.ParentWindow, self.Controler, element_type) |
|
2437 |
new_panel.SetTagName(tagname) |
|
2438 |
new_panel.Hide() |
|
2439 |
new_panel.RefreshView() |
|
2440 |
self.MainSizer.AddWindow(new_panel, 1, border=0, flag=wx.GROW) |
|
2441 |
self.VariablePanelList[tagname] = new_panel |
|
2442 |
||
2443 |
def RemoveVariablePanel(self, tagname): |
|
2444 |
if tagname in self.VariablePanelList: |
|
2445 |
panel = self.VariablePanelList.pop(tagname) |
|
2446 |
panel.Hide() |
|
2447 |
self.MainSizer.Remove(panel) |
|
2448 |
if self.CurrentPanel == tagname: |
|
2449 |
self.CurrentPanel = None |
|
2450 |
||
2451 |
def RemoveAllPanels(self): |
|
2452 |
if self.CurrentPanel is not None and self.CurrentPanel in self.VariablePanelList: |
|
2453 |
self.VariablePanelList[self.CurrentPanel].Hide() |
|
2454 |
self.VariablePanelList = {} |
|
2455 |
self.MainSizer.Clear() |
|
2456 |
self.CurrentPanel = None |
|
2457 |
||
2458 |
def UpdateVariablePanelTagName(self, old_tagname, new_tagname): |
|
2459 |
if old_name in self.VariablePanelList: |
|
2460 |
self.VariablePanelList[new_tagname] = self.VariablePanelList.pop(old_tagname) |
|
2461 |
if self.CurrentPanel == old_tagname: |
|
2462 |
self.CurrentPanel = new_tagname |
|
2463 |
||
2464 |
def ChangeVariablePanel(self, tagname): |
|
2465 |
if tagname in self.VariablePanelList and tagname != self.CurrentPanel: |
|
2466 |
if self.CurrentPanel is not None: |
|
2467 |
self.VariablePanelList[self.CurrentPanel].Hide() |
|
2468 |
self.CurrentPanel = tagname |
|
2469 |
self.VariablePanelList[self.CurrentPanel].RefreshView() |
|
2470 |
self.VariablePanelList[self.CurrentPanel].Show() |
|
2471 |
self.MainSizer.Layout() |
|
2472 |
||
2473 |
def RefreshVariablePanel(self, tagname): |
|
2474 |
if tagname in self.VariablePanelList: |
|
2475 |
self.VariablePanelList[self.CurrentPanel].RefreshView() |
|
2476 |
||
2477 |
#------------------------------------------------------------------------------- |
|
2478 |
# Variables Editor Panel |
|
0 | 2479 |
#------------------------------------------------------------------------------- |
2480 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2481 |
class VariableTable(wx.grid.PyGridTableBase): |
0 | 2482 |
|
2483 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2484 |
A custom wx.grid.Grid Table using user supplied data |
0 | 2485 |
""" |
2486 |
def __init__(self, parent, data, colnames): |
|
2487 |
# The base class must be initialized *first* |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2488 |
wx.grid.PyGridTableBase.__init__(self) |
0 | 2489 |
self.data = data |
58 | 2490 |
self.old_value = None |
0 | 2491 |
self.colnames = colnames |
2492 |
self.Parent = parent |
|
2493 |
# XXX |
|
2494 |
# we need to store the row length and collength to |
|
2495 |
# see if the table has changed size |
|
2496 |
self._rows = self.GetNumberRows() |
|
2497 |
self._cols = self.GetNumberCols() |
|
2498 |
||
2499 |
def GetNumberCols(self): |
|
2500 |
return len(self.colnames) |
|
2501 |
||
2502 |
def GetNumberRows(self): |
|
2503 |
return len(self.data) |
|
2504 |
||
2505 |
def GetColLabelValue(self, col): |
|
2506 |
if col < len(self.colnames): |
|
2507 |
return self.colnames[col] |
|
2508 |
||
2509 |
def GetRowLabelValues(self, row): |
|
2510 |
return row |
|
2511 |
||
2512 |
def GetValue(self, row, col): |
|
2513 |
if row < self.GetNumberRows(): |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2514 |
if col == 0: |
80 | 2515 |
return self.data[row]["Number"] |
0 | 2516 |
name = str(self.data[row].get(self.GetColLabelValue(col), "")) |
2517 |
return name |
|
2518 |
||
2519 |
def SetValue(self, row, col, value): |
|
2520 |
if col < len(self.colnames): |
|
58 | 2521 |
colname = self.GetColLabelValue(col) |
2522 |
if colname == "Name": |
|
2523 |
self.old_value = self.data[row][colname] |
|
2524 |
self.data[row][colname] = value |
|
2525 |
||
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2526 |
def GetValueByName(self, row, colname): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2527 |
if row < self.GetNumberRows(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2528 |
return self.data[row].get(colname) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2529 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2530 |
def SetValueByName(self, row, colname, value): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2531 |
if row < self.GetNumberRows(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2532 |
self.data[row][colname] = value |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2533 |
|
58 | 2534 |
def GetOldValue(self): |
2535 |
return self.old_value |
|
2536 |
||
0 | 2537 |
def ResetView(self, grid): |
2538 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2539 |
(wx.grid.Grid) -> Reset the grid view. Call this to |
0 | 2540 |
update the grid if rows and columns have been added or deleted |
2541 |
""" |
|
2542 |
grid.BeginBatch() |
|
2543 |
for current, new, delmsg, addmsg in [ |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2544 |
(self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2545 |
(self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
0 | 2546 |
]: |
2547 |
if new < current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2548 |
msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
0 | 2549 |
grid.ProcessTableMessage(msg) |
2550 |
elif new > current: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2551 |
msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
0 | 2552 |
grid.ProcessTableMessage(msg) |
2553 |
self.UpdateValues(grid) |
|
2554 |
grid.EndBatch() |
|
2555 |
||
2556 |
self._rows = self.GetNumberRows() |
|
2557 |
self._cols = self.GetNumberCols() |
|
2558 |
# update the column rendering scheme |
|
2559 |
self._updateColAttrs(grid) |
|
2560 |
||
2561 |
# update the scrollbars and the displayed part of the grid |
|
2562 |
grid.AdjustScrollbars() |
|
2563 |
grid.ForceRefresh() |
|
2564 |
||
2565 |
def UpdateValues(self, grid): |
|
2566 |
"""Update all displayed values""" |
|
2567 |
# This sends an event to the grid table to update all of the values |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2568 |
msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
0 | 2569 |
grid.ProcessTableMessage(msg) |
2570 |
||
2571 |
def _updateColAttrs(self, grid): |
|
2572 |
""" |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2573 |
wx.grid.Grid -> update the column attributes to add the |
0 | 2574 |
appropriate renderer given the column name. |
2575 |
||
2576 |
Otherwise default to the default renderer. |
|
2577 |
""" |
|
2578 |
||
2579 |
typelist = None |
|
2580 |
accesslist = None |
|
2581 |
for row in range(self.GetNumberRows()): |
|
2582 |
for col in range(self.GetNumberCols()): |
|
2583 |
editor = None |
|
2584 |
renderer = None |
|
2585 |
colname = self.GetColLabelValue(col) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2586 |
if col != 0 and self.GetValueByName(row, "Edit"): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2587 |
grid.SetReadOnly(row, col, False) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2588 |
if colname == "Name": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2589 |
if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2590 |
grid.SetReadOnly(row, col, True) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2591 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2592 |
editor = wx.grid.GridCellTextEditor() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2593 |
renderer = wx.grid.GridCellStringRenderer() |
107 | 2594 |
elif colname == "Initial Value": |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2595 |
editor = wx.grid.GridCellTextEditor() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2596 |
renderer = wx.grid.GridCellStringRenderer() |
107 | 2597 |
elif colname == "Location": |
2598 |
if self.GetValueByName(row, "Class") in ["Local", "Global"]: |
|
2599 |
editor = wx.grid.GridCellTextEditor() |
|
2600 |
renderer = wx.grid.GridCellStringRenderer() |
|
2601 |
else: |
|
2602 |
grid.SetReadOnly(row, col, True) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2603 |
elif colname == "Class": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2604 |
if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2605 |
grid.SetReadOnly(row, col, True) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2606 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2607 |
editor = wx.grid.GridCellChoiceEditor() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2608 |
excluded = [] |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2609 |
if self.Parent.PouIsUsed: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2610 |
excluded.extend(["Input","Output","InOut"]) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2611 |
editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2612 |
elif colname in ["Retain", "Constant"]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2613 |
editor = wx.grid.GridCellChoiceEditor() |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2614 |
editor.SetParameters(self.Parent.OptionList) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2615 |
elif colname == "Type": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2616 |
editor = wx.grid.GridCellTextEditor() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2617 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2618 |
grid.SetReadOnly(row, col, True) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2619 |
|
0 | 2620 |
grid.SetCellEditor(row, col, editor) |
2621 |
grid.SetCellRenderer(row, col, renderer) |
|
2622 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2623 |
grid.SetCellBackgroundColour(row, col, wx.WHITE) |
0 | 2624 |
|
2625 |
def SetData(self, data): |
|
2626 |
self.data = data |
|
2627 |
||
2628 |
def GetData(self): |
|
2629 |
return self.data |
|
2630 |
||
2631 |
def GetCurrentIndex(self): |
|
2632 |
return self.CurrentIndex |
|
2633 |
||
2634 |
def SetCurrentIndex(self, index): |
|
2635 |
self.CurrentIndex = index |
|
2636 |
||
2637 |
def AppendRow(self, row_content): |
|
2638 |
self.data.append(row_content) |
|
2639 |
||
2640 |
def RemoveRow(self, row_index): |
|
2641 |
self.data.pop(row_index) |
|
12 | 2642 |
|
2643 |
def GetRow(self, row_index): |
|
2644 |
return self.data[row_index] |
|
0 | 2645 |
|
2646 |
def Empty(self): |
|
2647 |
self.data = [] |
|
2648 |
self.editors = [] |
|
2649 |
||
53 | 2650 |
class VariableDropTarget(wx.TextDropTarget): |
2651 |
||
2652 |
def __init__(self, parent): |
|
2653 |
wx.TextDropTarget.__init__(self) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
2654 |
self.ParentWindow = parent |
53 | 2655 |
|
2656 |
def OnDropText(self, x, y, data): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
2657 |
col = self.ParentWindow.VariablesGrid.XToCol(x) |
97 | 2658 |
row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize()) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2659 |
if col != wx.NOT_FOUND and row != wx.NOT_FOUND: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
2660 |
if self.ParentWindow.Table.GetColLabelValue(col) != "Location": |
53 | 2661 |
return |
107 | 2662 |
message = None |
2663 |
if not self.ParentWindow.Table.GetValueByName(row, "Edit"): |
|
2664 |
message = "Can't affect a location to a function block instance" |
|
2665 |
elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]: |
|
2666 |
message = "Can affect a location only to local or global variables" |
|
2667 |
else: |
|
2668 |
try: |
|
2669 |
values = eval(data) |
|
2670 |
except: |
|
2671 |
values = None |
|
2672 |
if values and values[1] == "location": |
|
2673 |
location = values[0] |
|
2674 |
variable_type = self.ParentWindow.Table.GetValueByName(row, "Type") |
|
2675 |
message = None |
|
2676 |
if location[0].isdigit() and variable_type != "BOOL": |
|
2677 |
message = "Incompatible size of data between \"%s\" and \"BOOL\""%location |
|
2678 |
elif location[0] not in LOCATIONDATATYPES: |
|
2679 |
message = "Unrecognized data size \"%s\""%location[0] |
|
2680 |
elif variable_type not in LOCATIONDATATYPES[location[0]]: |
|
2681 |
message = "Incompatible size of data between \"%s\" and \"%s\""%(location, variable_type) |
|
53 | 2682 |
else: |
107 | 2683 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, "Select a variable class:", "Variable class", ["Input", "Output", "Memory"], wx.OK|wx.CANCEL) |
2684 |
if dialog.ShowModal() == wx.ID_OK: |
|
2685 |
selected = dialog.GetSelection() |
|
2686 |
if selected == 0: |
|
2687 |
location = "%I" + location |
|
2688 |
elif selected == 1: |
|
2689 |
location = "%Q" + location |
|
2690 |
else: |
|
2691 |
location = "%M" + location |
|
2692 |
self.ParentWindow.Table.SetValue(row, col, location) |
|
2693 |
self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid) |
|
2694 |
self.ParentWindow.SaveValues() |
|
2695 |
dialog.Destroy() |
|
2696 |
if message is not None: |
|
2697 |
message = wx.MessageDialog(self.ParentWindow, message, "Error", wx.OK|wx.ICON_ERROR) |
|
2698 |
message.ShowModal() |
|
2699 |
message.Destroy() |
|
53 | 2700 |
|
121 | 2701 |
[ID_VARIABLEEDITORPANEL, ID_VARIABLEEDITORPANELVARIABLESGRID, |
2702 |
ID_VARIABLEEDITORPANELRETURNTYPE, ID_VARIABLEEDITORPANELCLASSFILTER, |
|
2703 |
ID_VARIABLEEDITORPANELADDBUTTON, ID_VARIABLEEDITORPANELDELETEBUTTON, |
|
2704 |
ID_VARIABLEEDITORPANELUPBUTTON, ID_VARIABLEEDITORPANELDOWNBUTTON, |
|
2705 |
ID_VARIABLEEDITORPANELSTATICTEXT1, ID_VARIABLEEDITORPANELSTATICTEXT2, |
|
2706 |
ID_VARIABLEEDITORPANELSTATICTEXT3, |
|
2707 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
2708 |
||
2709 |
class VariablePanel(wx.Panel): |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2710 |
|
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2711 |
if wx.VERSION < (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2712 |
def Bind(self, event, function, id = None): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2713 |
if id is not None: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2714 |
event(self, id, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2715 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2716 |
event(self, function) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2717 |
|
121 | 2718 |
def _init_coll_MainSizer_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2719 |
parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2720 |
parent.AddSizer(self.ControlPanelSizer, 0, border=0, flag=wx.GROW) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2721 |
|
121 | 2722 |
def _init_coll_MainSizer_Growables(self, parent): |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2723 |
parent.AddGrowableCol(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2724 |
parent.AddGrowableRow(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2725 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2726 |
def _init_coll_ControlPanelSizer_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2727 |
parent.AddSizer(self.ChoicePanelSizer, 0, border=0, flag=wx.GROW) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2728 |
parent.AddSizer(self.ButtonPanelSizer, 0, border=0, flag=wx.ALIGN_CENTER) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2729 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2730 |
def _init_coll_ControlPanelSizer_Growables(self, parent): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2731 |
parent.AddGrowableCol(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2732 |
parent.AddGrowableRow(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2733 |
parent.AddGrowableRow(1) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2734 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2735 |
def _init_coll_ChoicePanelSizer_Items(self, parent): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2736 |
parent.AddWindow(self.staticText1, 0, border=0, flag=wx.ALIGN_BOTTOM) |
52 | 2737 |
parent.AddWindow(self.ReturnType, 0, border=0, flag=0) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2738 |
parent.AddWindow(self.staticText2, 0, border=0, flag=wx.ALIGN_BOTTOM) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2739 |
parent.AddWindow(self.ClassFilter, 0, border=0, flag=0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2740 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2741 |
def _init_coll_ButtonPanelSizer_Items(self, parent): |
52 | 2742 |
parent.AddWindow(self.UpButton, 0, border=0, flag=0) |
51 | 2743 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
52 | 2744 |
parent.AddWindow(self.DownButton, 0, border=0, flag=0) |
51 | 2745 |
parent.AddWindow(self.DeleteButton, 0, border=0, flag=0) |
52 | 2746 |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2747 |
def _init_coll_ButtonPanelSizer_Growables(self, parent): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2748 |
parent.AddGrowableCol(0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2749 |
parent.AddGrowableCol(1) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2750 |
parent.AddGrowableCol(2) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2751 |
parent.AddGrowableCol(3) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2752 |
parent.AddGrowableRow(0) |
0 | 2753 |
|
2754 |
def _init_sizers(self): |
|
121 | 2755 |
self.MainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=0) |
52 | 2756 |
self.ControlPanelSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
2757 |
self.ChoicePanelSizer = wx.GridSizer(cols=1, hgap=5, rows=4, vgap=5) |
|
2758 |
self.ButtonPanelSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2759 |
|
121 | 2760 |
self._init_coll_MainSizer_Items(self.MainSizer) |
2761 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2762 |
self._init_coll_ControlPanelSizer_Items(self.ControlPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2763 |
self._init_coll_ControlPanelSizer_Growables(self.ControlPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2764 |
self._init_coll_ChoicePanelSizer_Items(self.ChoicePanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2765 |
self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2766 |
self._init_coll_ButtonPanelSizer_Growables(self.ButtonPanelSizer) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2767 |
|
121 | 2768 |
self.SetSizer(self.MainSizer) |
2769 |
||
2770 |
def _init_ctrls(self, prnt): |
|
2771 |
wx.Panel.__init__(self, id=ID_VARIABLEEDITORPANEL, |
|
2772 |
name='VariableEditorPanel', parent=prnt, pos=wx.Point(0, 0), |
|
80 | 2773 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2774 |
|
121 | 2775 |
self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1, |
2776 |
label='Return Type:', name='staticText1', parent=self, |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2777 |
pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2778 |
|
121 | 2779 |
self.ReturnType = wx.Choice(id=ID_VARIABLEEDITORPANELRETURNTYPE, |
2780 |
name='ReturnType', parent=self, pos=wx.Point(0, 0), |
|
52 | 2781 |
size=wx.Size(145, 24), style=0) |
121 | 2782 |
self.Bind(wx.EVT_CHOICE, self.OnReturnTypeChanged, id=ID_VARIABLEEDITORPANELRETURNTYPE) |
2783 |
||
2784 |
self.staticText2 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT2, |
|
2785 |
label='Class Filter:', name='staticText2', parent=self, |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2786 |
pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2787 |
|
121 | 2788 |
self.ClassFilter = wx.Choice(id=ID_VARIABLEEDITORPANELCLASSFILTER, |
2789 |
name='ClassFilter', parent=self, pos=wx.Point(0, 0), |
|
52 | 2790 |
size=wx.Size(145, 24), style=0) |
121 | 2791 |
self.Bind(wx.EVT_CHOICE, self.OnClassFilter, id=ID_VARIABLEEDITORPANELCLASSFILTER) |
2792 |
||
2793 |
self.VariablesGrid = wx.grid.Grid(id=ID_VARIABLEEDITORPANELVARIABLESGRID, |
|
2794 |
name='VariablesGrid', parent=self, pos=wx.Point(0, 0), |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2795 |
size=wx.Size(0, 150), style=wx.VSCROLL) |
0 | 2796 |
self.VariablesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
2797 |
'Sans')) |
|
2798 |
self.VariablesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
2799 |
False, 'Sans')) |
|
107 | 2800 |
self.VariablesGrid.SetSelectionBackground(wx.WHITE) |
2801 |
self.VariablesGrid.SetSelectionForeground(wx.BLACK) |
|
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2802 |
if wx.VERSION >= (2, 6, 0): |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2803 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2804 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2805 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2806 |
self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2807 |
else: |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2808 |
wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2809 |
wx.grid.EVT_GRID_SELECT_CELL(self.VariablesGrid, self.OnVariablesGridSelectCell) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2810 |
wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) |
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
2811 |
wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown) |
53 | 2812 |
self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
2813 |
||
121 | 2814 |
self.AddButton = wx.Button(id=ID_VARIABLEEDITORPANELADDBUTTON, label='Add', |
2815 |
name='AddButton', parent=self, pos=wx.Point(345, 340), |
|
0 | 2816 |
size=wx.Size(72, 32), style=0) |
121 | 2817 |
self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_VARIABLEEDITORPANELADDBUTTON) |
2818 |
||
2819 |
self.DeleteButton = wx.Button(id=ID_VARIABLEEDITORPANELDELETEBUTTON, label='Delete', |
|
2820 |
name='DeleteButton', parent=self, pos=wx.Point(425, 340), |
|
0 | 2821 |
size=wx.Size(72, 32), style=0) |
121 | 2822 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_VARIABLEEDITORPANELDELETEBUTTON) |
2823 |
||
2824 |
self.UpButton = wx.Button(id=ID_VARIABLEEDITORPANELUPBUTTON, label='^', |
|
2825 |
name='UpButton', parent=self, pos=wx.Point(505, 340), |
|
0 | 2826 |
size=wx.Size(32, 32), style=0) |
121 | 2827 |
self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_VARIABLEEDITORPANELUPBUTTON) |
2828 |
||
2829 |
self.DownButton = wx.Button(id=ID_VARIABLEEDITORPANELDOWNBUTTON, label='v', |
|
2830 |
name='DownButton', parent=self, pos=wx.Point(545, 340), |
|
0 | 2831 |
size=wx.Size(32, 32), style=0) |
121 | 2832 |
self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_VARIABLEEDITORPANELDOWNBUTTON) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2833 |
|
0 | 2834 |
self._init_sizers() |
2835 |
||
121 | 2836 |
def __init__(self, parent, window, controler, element_type): |
2837 |
self._init_ctrls(parent) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
2838 |
self.ParentWindow = window |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2839 |
self.Controler = controler |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2840 |
self.ElementType = element_type |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2841 |
|
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2842 |
self.Filter = "All" |
0 | 2843 |
self.FilterChoices = [] |
2844 |
self.FilterChoiceTransfer = {"All" : "All", "Interface" : "Interface", |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2845 |
" Input" : "Input", " Output" : "Output", " InOut" : "InOut", |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2846 |
" External" : "External", "Variables" : "Variables", " Local" : "Local", |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2847 |
" Temp" : "Temp", "Global" : "Global", "Access" : "Access"} |
0 | 2848 |
|
121 | 2849 |
if element_type in ["config", "resource"]: |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2850 |
self.DefaultTypes = {"All" : "Global"} |
80 | 2851 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True} |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2852 |
else: |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2853 |
self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"} |
80 | 2854 |
self.DefaultValue = {"Name" : "", "Class" : "", "Type" : "INT", "Location" : "", "Initial Value" : "", "Retain" : "No", "Constant" : "No", "Edit" : True} |
121 | 2855 |
if element_type in ["config", "resource"] or element_type in ["program", "transition", "action"]: |
70 | 2856 |
self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Location", "Initial Value", "Retain", "Constant"]) |
121 | 2857 |
if element_type not in ["config", "resource"]: |
0 | 2858 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp","Global","Access"] |
2859 |
else: |
|
2860 |
self.FilterChoices = ["All","Global","Access"] |
|
70 | 2861 |
self.ColSizes = [40, 80, 70, 80, 80, 80, 60, 70] |
2862 |
self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER] |
|
2863 |
else: |
|
2864 |
self.Table = VariableTable(self, [], ["#", "Name", "Class", "Type", "Initial Value", "Retain", "Constant"]) |
|
0 | 2865 |
self.FilterChoices = ["All","Interface"," Input"," Output"," InOut"," External","Variables"," Local"," Temp"] |
70 | 2866 |
self.ColSizes = [40, 120, 70, 80, 120, 60, 70] |
2867 |
self.ColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_CENTER, wx.ALIGN_CENTER] |
|
0 | 2868 |
for choice in self.FilterChoices: |
2869 |
self.ClassFilter.Append(choice) |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2870 |
reverse_transfer = {} |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2871 |
for filter, choice in self.FilterChoiceTransfer.items(): |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2872 |
reverse_transfer[choice] = filter |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2873 |
self.ClassFilter.SetStringSelection(reverse_transfer[self.Filter]) |
0 | 2874 |
self.RefreshTypeList() |
2875 |
||
2876 |
self.OptionList = "Yes,No" |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2877 |
self.TypeList = [value for value, parent in TypeHierarchy_list if not value.startswith("ANY")] |
0 | 2878 |
|
121 | 2879 |
if element_type == "function": |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
2880 |
for value, parent in TypeHierarchy_list: |
0 | 2881 |
if not value.startswith("ANY"): |
2882 |
self.ReturnType.Append(value) |
|
2883 |
self.ReturnType.Enable(True) |
|
2884 |
else: |
|
2885 |
self.ReturnType.Enable(False) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2886 |
self.staticText1.Hide() |
0 | 2887 |
self.ReturnType.Hide() |
2888 |
||
2889 |
self.VariablesGrid.SetTable(self.Table) |
|
2890 |
self.VariablesGrid.SetRowLabelSize(0) |
|
107 | 2891 |
for col in range(self.Table.GetNumberCols()): |
2892 |
attr = wx.grid.GridCellAttr() |
|
2893 |
attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
|
2894 |
self.VariablesGrid.SetColAttr(col, attr) |
|
2895 |
self.VariablesGrid.SetColSize(col, self.ColSizes[col]) |
|
2896 |
||
121 | 2897 |
def SetTagName(self, tagname): |
2898 |
self.TagName = tagname |
|
2899 |
||
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2900 |
def RefreshView(self): |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2901 |
self.PouNames = self.Controler.GetProjectPouNames() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2902 |
|
121 | 2903 |
words = self.TagName.split("::") |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2904 |
if self.ElementType == "config": |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2905 |
self.PouIsUsed = False |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2906 |
returnType = None |
121 | 2907 |
self.Values = self.Controler.GetConfigurationGlobalVars(words[1]) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2908 |
elif self.ElementType == "resource": |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2909 |
self.PouIsUsed = False |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2910 |
returnType = None |
121 | 2911 |
self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2]) |
2912 |
else: |
|
2913 |
self.PouIsUsed = self.Controler.PouIsUsed(words[1]) |
|
2914 |
returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName) |
|
2915 |
self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2916 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2917 |
if returnType and self.ReturnType.IsEnabled(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2918 |
self.ReturnType.SetStringSelection(returnType) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2919 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2920 |
self.RefreshValues() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2921 |
self.RefreshButtons() |
67
3a1b0afdaf84
Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents:
65
diff
changeset
|
2922 |
|
80 | 2923 |
def OnReturnTypeChanged(self, event): |
121 | 2924 |
words = self.TagName.split("::") |
2925 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
|
80 | 2926 |
self.Controler.BufferProject() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
2927 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
2928 |
self.ParentWindow.RefreshEditMenu() |
80 | 2929 |
event.Skip() |
2930 |
||
0 | 2931 |
def OnClassFilter(self, event): |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2932 |
self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()] |
0 | 2933 |
self.RefreshTypeList() |
2934 |
self.RefreshValues() |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2935 |
self.RefreshButtons() |
0 | 2936 |
event.Skip() |
2937 |
||
2938 |
def RefreshTypeList(self): |
|
2939 |
if self.Filter == "All": |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2940 |
self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All","Interface","Variables"]] |
0 | 2941 |
elif self.Filter == "Interface": |
2942 |
self.ClassList = ["Input","Output","InOut","External"] |
|
2943 |
elif self.Filter == "Variables": |
|
2944 |
self.ClassList = ["Local","Temp"] |
|
2945 |
else: |
|
2946 |
self.ClassList = [self.Filter] |
|
2947 |
||
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2948 |
def RefreshButtons(self): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
98
diff
changeset
|
2949 |
if getattr(self, "Table", None): |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2950 |
table_length = len(self.Table.data) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2951 |
row_class = None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2952 |
if table_length and self.PouIsUsed: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2953 |
row = self.VariablesGrid.GetGridCursorRow() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2954 |
row_class = self.Table.GetValueByName(row, "Class") |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2955 |
self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2956 |
self.DeleteButton.Enable(table_length > 0 and row_class not in ["Input", "Output", "InOut"]) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2957 |
self.UpButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
55
diff
changeset
|
2958 |
self.DownButton.Enable(table_length > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
2959 |
|
0 | 2960 |
def OnAddButton(self, event): |
11 | 2961 |
new_row = self.DefaultValue.copy() |
2962 |
if self.Filter in self.DefaultTypes: |
|
2963 |
new_row["Class"] = self.DefaultTypes[self.Filter] |
|
2964 |
else: |
|
2965 |
new_row["Class"] = self.Filter |
|
12 | 2966 |
self.Values.append(new_row) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2967 |
self.SaveValues() |
12 | 2968 |
self.RefreshValues() |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2969 |
self.RefreshButtons() |
0 | 2970 |
event.Skip() |
2971 |
||
2972 |
def OnDeleteButton(self, event): |
|
12 | 2973 |
row = self.Table.GetRow(self.VariablesGrid.GetGridCursorRow()) |
2974 |
self.Values.remove(row) |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
2975 |
self.SaveValues() |
12 | 2976 |
self.RefreshValues() |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2977 |
self.RefreshButtons() |
0 | 2978 |
event.Skip() |
2979 |
||
2980 |
def OnUpButton(self, event): |
|
12 | 2981 |
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), -1) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2982 |
self.RefreshButtons() |
0 | 2983 |
event.Skip() |
2984 |
||
2985 |
def OnDownButton(self, event): |
|
12 | 2986 |
self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
2987 |
self.RefreshButtons() |
0 | 2988 |
event.Skip() |
2989 |
||
6 | 2990 |
def OnVariablesGridCellChange(self, event): |
2991 |
row, col = event.GetRow(), event.GetCol() |
|
2992 |
colname = self.Table.GetColLabelValue(col) |
|
2993 |
value = self.Table.GetValue(row, col) |
|
2994 |
if colname == "Name": |
|
2995 |
if not TestIdentifier(value): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
2996 |
message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 2997 |
message.ShowModal() |
2998 |
message.Destroy() |
|
2999 |
event.Veto() |
|
3000 |
elif value.upper() in IEC_KEYWORDS: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3001 |
message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3002 |
message.ShowModal() |
3003 |
message.Destroy() |
|
3004 |
event.Veto() |
|
3005 |
elif value.upper() in self.PouNames: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3006 |
message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3007 |
message.ShowModal() |
3008 |
message.Destroy() |
|
3009 |
event.Veto() |
|
3010 |
elif value.upper() in [var["Name"].upper() for var in self.Values if var != self.Table.data[row]]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3011 |
message = wx.MessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wx.OK|wx.ICON_ERROR) |
6 | 3012 |
message.ShowModal() |
3013 |
message.Destroy() |
|
3014 |
event.Veto() |
|
3015 |
else: |
|
58 | 3016 |
self.SaveValues(False) |
3017 |
old_value = self.Table.GetOldValue() |
|
3018 |
if old_value != "": |
|
121 | 3019 |
self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value) |
58 | 3020 |
self.Controler.BufferProject() |
121 | 3021 |
self.ParentWindow.RefreshEditor(variablepanel = False) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3022 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3023 |
self.ParentWindow.RefreshEditMenu() |
6 | 3024 |
event.Skip() |
3025 |
else: |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3026 |
self.SaveValues() |
107 | 3027 |
if colname == "Class": |
3028 |
self.Table.ResetView(self.VariablesGrid) |
|
6 | 3029 |
event.Skip() |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3030 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3031 |
def OnVariablesGridEditorShown(self, event): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3032 |
row, col = event.GetRow(), event.GetCol() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3033 |
if self.Table.GetColLabelValue(col) == "Type": |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3034 |
type_menu = wx.Menu(title='') |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3035 |
base_menu = wx.Menu(title='') |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3036 |
for base_type in self.TypeList: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3037 |
new_id = wx.NewId() |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3038 |
AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3039 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3040 |
type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3041 |
functionblock_menu = wx.Menu(title='') |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3042 |
for functionblock_type in self.Controler.GetFunctionBlockTypes(): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3043 |
new_id = wx.NewId() |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3044 |
AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3045 |
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
114
06454545e5d0
Adding support for block copy and for wxpython 2.4
lbessard
parents:
108
diff
changeset
|
3046 |
type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu) |
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3047 |
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3048 |
self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize()) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3049 |
event.Veto() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3050 |
else: |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3051 |
event.Skip() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3052 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3053 |
def GetVariableTypeFunction(self, base_type): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3054 |
def VariableTypeFunction(event): |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3055 |
row = self.VariablesGrid.GetGridCursorRow() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3056 |
self.Table.SetValueByName(row, "Type", base_type) |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3057 |
self.Table.ResetView(self.VariablesGrid) |
98 | 3058 |
self.SaveValues(False) |
121 | 3059 |
self.ParentWindow.RefreshEditor(variablepanel = False) |
98 | 3060 |
self.Controler.BufferProject() |
3061 |
self.ParentWindow.RefreshTitle() |
|
3062 |
self.ParentWindow.RefreshEditMenu() |
|
68
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3063 |
event.Skip() |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3064 |
return VariableTypeFunction |
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3065 |
|
66308e07402c
Adding support for allowing declarations of function block into POU interface
lbessard
parents:
67
diff
changeset
|
3066 |
def OnVariablesGridCellLeftClick(self, event): |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3067 |
if event.GetCol() == 0: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3068 |
row = event.GetRow() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3069 |
var_name = self.Table.GetValueByName(row, "Name") |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3070 |
var_class = self.Table.GetValueByName(row, "Class") |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3071 |
var_type = self.Table.GetValueByName(row, "Type") |
121 | 3072 |
data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName))) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3073 |
dragSource = wx.DropSource(self.VariablesGrid) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3074 |
dragSource.SetData(data) |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3075 |
dragSource.DoDragDrop() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3076 |
event.Skip() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3077 |
|
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3078 |
def OnVariablesGridSelectCell(self, event): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3079 |
wx.CallAfter(self.RefreshButtons) |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3080 |
event.Skip() |
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3081 |
|
12 | 3082 |
def MoveValue(self, value_index, move): |
3083 |
new_index = max(0, min(value_index + move, len(self.Values) - 1)) |
|
3084 |
if new_index != value_index: |
|
3085 |
self.Values.insert(new_index, self.Values.pop(value_index)) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
3086 |
self.RefreshValues() |
12 | 3087 |
self.VariablesGrid.SetGridCursor(new_index, self.VariablesGrid.GetGridCursorCol()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
3088 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
3089 |
self.RefreshValues() |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3090 |
self.SaveValues() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3091 |
|
0 | 3092 |
def RefreshValues(self): |
37
256eedd275d0
Adding support for disable interface variable change if a POU is used
lbessard
parents:
28
diff
changeset
|
3093 |
if len(self.Table.data) > 0: |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3094 |
self.VariablesGrid.SetGridCursor(0, 1) |
0 | 3095 |
data = [] |
80 | 3096 |
for num, variable in enumerate(self.Values): |
0 | 3097 |
if variable["Class"] in self.ClassList: |
80 | 3098 |
variable["Number"] = num + 1 |
0 | 3099 |
data.append(variable) |
3100 |
self.Table.SetData(data) |
|
3101 |
self.Table.ResetView(self.VariablesGrid) |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3102 |
|
58 | 3103 |
def SaveValues(self, buffer = True): |
121 | 3104 |
words = self.TagName.split("::") |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3105 |
if self.ElementType == "config": |
121 | 3106 |
self.Controler.SetConfigurationGlobalVars(words[1], self.Values) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3107 |
elif self.ElementType == "resource": |
121 | 3108 |
self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values) |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3109 |
else: |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3110 |
if self.ReturnType.IsEnabled(): |
121 | 3111 |
self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
3112 |
self.Controler.SetPouInterfaceVars(words[1], self.Values) |
|
58 | 3113 |
if buffer: |
3114 |
self.Controler.BufferProject() |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3115 |
self.ParentWindow.RefreshTitle() |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
82
diff
changeset
|
3116 |
self.ParentWindow.RefreshEditMenu() |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
46
diff
changeset
|
3117 |
|
0 | 3118 |
#------------------------------------------------------------------------------- |
3119 |
# Exception Handler |
|
3120 |
#------------------------------------------------------------------------------- |
|
3121 |
||
3122 |
Max_Traceback_List_Size = 20 |
|
3123 |
||
3124 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
3125 |
trcbck_lst = [] |
|
3126 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
3127 |
trcbck = " " + str(i+1) + ". " |
|
3128 |
if line[0].find(os.getcwd()) == -1: |
|
3129 |
trcbck += "file : " + str(line[0]) + ", " |
|
3130 |
else: |
|
3131 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
3132 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
3133 |
trcbck_lst.append(trcbck) |
|
3134 |
||
3135 |
# Allow clicking.... |
|
3136 |
cap = wx.Window_GetCapture() |
|
3137 |
if cap: |
|
3138 |
cap.ReleaseMouse() |
|
3139 |
||
3140 |
dlg = wx.SingleChoiceDialog(None, |
|
3141 |
""" |
|
3142 |
An error happens. |
|
3143 |
||
3144 |
Click on OK for saving an error report. |
|
3145 |
||
3146 |
Please contact LOLITech at: |
|
3147 |
+33 (0)3 29 52 95 67 |
|
3148 |
bugs_PLCOpenEditor@lolitech.fr |
|
3149 |
||
3150 |
||
3151 |
Error: |
|
3152 |
""" + |
|
3153 |
str(e_type) + " : " + str(e_value), |
|
3154 |
"Error", |
|
3155 |
trcbck_lst) |
|
3156 |
try: |
|
3157 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
3158 |
finally: |
|
3159 |
dlg.Destroy() |
|
3160 |
||
3161 |
return res |
|
3162 |
||
3163 |
def Display_Error_Dialog(e_value): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3164 |
message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) |
0 | 3165 |
message.ShowModal() |
3166 |
message.Destroy() |
|
3167 |
||
3168 |
def get_last_traceback(tb): |
|
3169 |
while tb.tb_next: |
|
3170 |
tb = tb.tb_next |
|
3171 |
return tb |
|
3172 |
||
3173 |
||
3174 |
def format_namespace(d, indent=' '): |
|
3175 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
3176 |
||
3177 |
||
3178 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
3179 |
||
65
cb6bed0720f0
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
64
diff
changeset
|
3180 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 3181 |
|
3182 |
def handle_exception(e_type, e_value, e_traceback): |
|
3183 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
3184 |
last_tb = get_last_traceback(e_traceback) |
|
3185 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
3186 |
if str(e_value).startswith("!!!"): |
|
3187 |
Display_Error_Dialog(e_value) |
|
3188 |
elif ex not in ignored_exceptions: |
|
3189 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
3190 |
if result: |
|
3191 |
ignored_exceptions.append(ex) |
|
3192 |
info = { |
|
3193 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
3194 |
'app-version' : app_version, |
|
3195 |
'wx-version' : wx.VERSION_STRING, |
|
3196 |
'wx-platform' : wx.Platform, |
|
3197 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
3198 |
'platform' : platform.platform(), |
|
3199 |
'e-type' : e_type, |
|
3200 |
'e-value' : e_value, |
|
3201 |
'date' : time.ctime(), |
|
3202 |
'cwd' : os.getcwd(), |
|
3203 |
} |
|
3204 |
if e_traceback: |
|
3205 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
3206 |
last_tb = get_last_traceback(e_traceback) |
|
3207 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
3208 |
info['locals'] = format_namespace(exception_locals) |
|
3209 |
if 'self' in exception_locals: |
|
3210 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
3211 |
||
3212 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
3213 |
lst = info.keys() |
|
3214 |
lst.sort() |
|
3215 |
for a in lst: |
|
3216 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
3217 |
||
3218 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
3219 |
sys.excepthook = handle_exception |
|
3220 |
||
3221 |
if __name__ == '__main__': |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3222 |
def usage(): |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3223 |
print "\nUsage of PLCOpenEditor.py :" |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3224 |
print "\n %s [Filepath]\n"%sys.argv[0] |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3225 |
|
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3226 |
try: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3227 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3228 |
except getopt.GetoptError: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3229 |
# print help information and exit: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3230 |
usage() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3231 |
sys.exit(2) |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3232 |
|
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3233 |
for o, a in opts: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3234 |
if o in ("-h", "--help"): |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3235 |
usage() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3236 |
sys.exit() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3237 |
|
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3238 |
fileOpen = None |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3239 |
if len(args) > 1: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3240 |
usage() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3241 |
sys.exit() |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3242 |
elif len(args) == 1: |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3243 |
fileOpen = args[0] |
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3244 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3245 |
app = wx.PySimpleApp() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
3246 |
wx.InitAllImageHandlers() |
0 | 3247 |
|
3248 |
# Install a exception handle for bug reports |
|
65
cb6bed0720f0
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
64
diff
changeset
|
3249 |
AddExceptHook(os.getcwd(),__version__) |
0 | 3250 |
|
92
76d5001393df
Adding support for refreshing PLCOpenEditor block list
lbessard
parents:
90
diff
changeset
|
3251 |
frame = PLCOpenEditor(None, fileOpen=fileOpen) |
0 | 3252 |
|
3253 |
frame.Show() |
|
3254 |
app.MainLoop() |
|
3255 |