author | Surkov Sergey <surkovsv93@gmail.com> |
Tue, 04 Jul 2017 14:00:42 +0300 | |
changeset 1713 | ae58d214997c |
parent 1696 | 8043f32de7b8 |
child 1730 | 64d8f52bc8c8 |
permissions | -rwxr-xr-x |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
9 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
11 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
16 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
20 |
# GNU General Public License for more details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
21 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1487
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
26 |
import wx |
|
27 |
||
1245 | 28 |
from graphics.GraphicCommons import CONNECTOR, CONTINUATION |
29 |
from graphics.FBD_Objects import FBD_Connector |
|
30 |
from BlockPreviewDialog import BlockPreviewDialog |
|
814 | 31 |
|
32 |
#------------------------------------------------------------------------------- |
|
1245 | 33 |
# Set Connection Parameters Dialog |
814 | 34 |
#------------------------------------------------------------------------------- |
35 |
||
1249 | 36 |
""" |
37 |
Class that implements a dialog for defining parameters of a connection graphic |
|
38 |
element |
|
39 |
""" |
|
40 |
||
1245 | 41 |
class ConnectionDialog(BlockPreviewDialog): |
814 | 42 |
|
1245 | 43 |
def __init__(self, parent, controller, tagname, apply_button=False): |
44 |
""" |
|
45 |
Constructor |
|
46 |
@param parent: Parent wx.Window of dialog for modal |
|
47 |
@param controller: Reference to project controller |
|
48 |
@param tagname: Tagname of project POU edited |
|
49 |
@param apply_button: Enable button for applying connector modification |
|
50 |
to all connector having the same name in POU (default: False) |
|
51 |
""" |
|
52 |
BlockPreviewDialog.__init__(self, parent, controller, tagname, |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
53 |
title=_('Connection Properties')) |
814 | 54 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
55 |
# Init common sizers |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
56 |
self._init_sizers(2, 0, 7, 1, 0, None) |
814 | 57 |
|
1245 | 58 |
# Create label for connection type |
814 | 59 |
type_label = wx.StaticText(self, label=_('Type:')) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
60 |
self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
814 | 61 |
|
1245 | 62 |
# Create radio buttons for selecting connection type |
1246 | 63 |
self.TypeRadioButtons = {} |
1245 | 64 |
first = True |
65 |
for type, label in [(CONNECTOR, _('Connector')), |
|
66 |
(CONTINUATION, _('Continuation'))]: |
|
67 |
radio_button = wx.RadioButton(self, label=label, |
|
1247 | 68 |
style=(wx.RB_GROUP if first else 0)) |
1245 | 69 |
radio_button.SetValue(first) |
70 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
71 |
self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
1246 | 72 |
self.TypeRadioButtons[type] = radio_button |
1245 | 73 |
first = False |
74 |
||
75 |
# Create label for connection name |
|
814 | 76 |
name_label = wx.StaticText(self, label=_('Name:')) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
77 |
self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW) |
814 | 78 |
|
1245 | 79 |
# Create text control for defining connection name |
814 | 80 |
self.ConnectionName = wx.TextCtrl(self) |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
81 |
self.ConnectionName.SetMinSize(wx.Size(200,-1)) |
814 | 82 |
self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
83 |
self.LeftGridSizer.AddWindow(self.ConnectionName, flag=wx.GROW) |
814 | 84 |
|
1245 | 85 |
# Add preview panel and associated label to sizers |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
86 |
self.Preview.SetMinSize(wx.Size(-1,100)) |
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
87 |
self.LeftGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
88 |
self.LeftGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
814 | 89 |
|
1245 | 90 |
# Add buttons sizer to sizers |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1249
diff
changeset
|
91 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
814 | 92 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
93 |
self.ColumnSizer.RemoveSizer(self.RightGridSizer) |
814 | 94 |
|
1245 | 95 |
# Add button for applying connection name modification to all connection |
96 |
# of POU |
|
856
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
97 |
if apply_button: |
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
98 |
self.ApplyToAllButton = wx.Button(self, label=_("Propagate Name")) |
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
99 |
self.ApplyToAllButton.SetToolTipString( |
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
100 |
_("Apply name modification to all continuations with the same name")) |
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
101 |
self.Bind(wx.EVT_BUTTON, self.OnApplyToAll, self.ApplyToAllButton) |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
102 |
self.ButtonSizer.AddWindow(self.ApplyToAllButton, flag=wx.LEFT) |
1245 | 103 |
else: |
104 |
self.ConnectionName.ChangeValue( |
|
105 |
controller.GenerateNewName( |
|
106 |
tagname, None, "Connection%d", 0)) |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
107 |
self.Fit() |
856
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
108 |
|
1245 | 109 |
# Connector radio button is default control having keyboard focus |
1246 | 110 |
self.TypeRadioButtons[CONNECTOR].SetFocus() |
814 | 111 |
|
1249 | 112 |
def GetConnectionType(self): |
113 |
""" |
|
114 |
Return type selected for connection |
|
115 |
@return: Type selected (CONNECTOR or CONTINUATION) |
|
116 |
""" |
|
117 |
return (CONNECTOR |
|
118 |
if self.TypeRadioButtons[CONNECTOR].GetValue() |
|
119 |
else CONTINUATION) |
|
120 |
||
814 | 121 |
def SetValues(self, values): |
1245 | 122 |
""" |
123 |
Set default connection parameters |
|
124 |
@param values: Connection parameters values |
|
125 |
""" |
|
126 |
# For each parameters defined, set corresponding control value |
|
814 | 127 |
for name, value in values.items(): |
1245 | 128 |
|
129 |
# Parameter is connection type |
|
814 | 130 |
if name == "type": |
1246 | 131 |
self.TypeRadioButtons[value].SetValue(True) |
1245 | 132 |
|
133 |
# Parameter is connection name |
|
814 | 134 |
elif name == "name": |
135 |
self.ConnectionName.SetValue(value) |
|
1245 | 136 |
|
137 |
# Refresh preview panel |
|
814 | 138 |
self.RefreshPreview() |
139 |
||
140 |
def GetValues(self): |
|
1245 | 141 |
""" |
142 |
Return connection parameters defined in dialog |
|
143 |
@return: {parameter_name: parameter_value,...} |
|
144 |
""" |
|
145 |
values = { |
|
1249 | 146 |
"type": self.GetConnectionType(), |
1245 | 147 |
"name": self.ConnectionName.GetValue()} |
148 |
values["width"], values["height"] = self.Element.GetSize() |
|
814 | 149 |
return values |
150 |
||
1245 | 151 |
def TestConnectionName(self): |
152 |
""" |
|
153 |
Test that connection name is valid |
|
154 |
@return: True if connection name is valid |
|
155 |
""" |
|
814 | 156 |
message = None |
1245 | 157 |
|
158 |
# Get connection name typed by user |
|
814 | 159 |
connection_name = self.ConnectionName.GetValue() |
1245 | 160 |
|
161 |
# Test that a name have been defined |
|
814 | 162 |
if connection_name == "": |
163 |
message = _("Form isn't complete. Name must be filled!") |
|
1245 | 164 |
|
165 |
# If an error have been identify, show error message dialog |
|
814 | 166 |
if message is not None: |
1245 | 167 |
self.ShowErrorMessage(message) |
168 |
# Test failed |
|
856
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
169 |
return False |
1245 | 170 |
|
171 |
# Return result of element name test |
|
172 |
return self.TestElementName(connection_name) |
|
856
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
173 |
|
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
174 |
def OnOK(self, event): |
1245 | 175 |
""" |
176 |
Called when dialog OK button is pressed |
|
177 |
Test if connection name is valid |
|
178 |
@param event: wx.Event from OK button |
|
179 |
""" |
|
180 |
# Close dialog if connection name is valid |
|
181 |
if self.TestConnectionName(): |
|
814 | 182 |
self.EndModal(wx.ID_OK) |
183 |
||
856
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
184 |
def OnApplyToAll(self, event): |
1245 | 185 |
""" |
186 |
Called when Apply To All button is pressed |
|
187 |
Test if connection name is valid |
|
188 |
@param event: wx.Event from OK button |
|
189 |
""" |
|
190 |
# Close dialog if connection name is valid |
|
191 |
if self.TestConnectionName(): |
|
856
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
192 |
self.EndModal(wx.ID_YESTOALL) |
b64e436f000e
Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents:
814
diff
changeset
|
193 |
|
814 | 194 |
def OnTypeChanged(self, event): |
1245 | 195 |
""" |
196 |
Called when connection type changed |
|
197 |
@param event: wx.RadioButtonEvent |
|
198 |
""" |
|
814 | 199 |
self.RefreshPreview() |
200 |
event.Skip() |
|
201 |
||
202 |
def OnNameChanged(self, event): |
|
1245 | 203 |
""" |
204 |
Called when connection name value changed |
|
205 |
@param event: wx.TextEvent |
|
206 |
""" |
|
814 | 207 |
self.RefreshPreview() |
208 |
event.Skip() |
|
209 |
||
210 |
def RefreshPreview(self): |
|
1245 | 211 |
""" |
212 |
Refresh preview panel of graphic element |
|
213 |
Override BlockPreviewDialog function |
|
214 |
""" |
|
215 |
# Set graphic element displayed, creating a FBD connection element |
|
216 |
self.Element = FBD_Connector(self.Preview, |
|
1249 | 217 |
self.GetConnectionType(), |
1245 | 218 |
self.ConnectionName.GetValue()) |
219 |
||
220 |
# Call BlockPreviewDialog function |
|
221 |
BlockPreviewDialog.RefreshPreview(self) |
|
1487
789acd7cc347
increase height for ConnectionDialog and ArrayTypeDialog to have
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1250
diff
changeset
|
222 |