author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 09 Aug 2017 14:13:17 +0300 | |
changeset 1724 | fde6ad246866 |
parent 1696 | 8043f32de7b8 |
child 1730 | 64d8f52bc8c8 |
permissions | -rw-r--r-- |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1554
diff
changeset
|
1 |
#!/usr/bin/env python |
814 | 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:
1554
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:
1554
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:
1554
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1554
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:
1554
diff
changeset
|
9 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1554
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:
1554
diff
changeset
|
11 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1554
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:
1554
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:
1554
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:
1554
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:
1554
diff
changeset
|
16 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1554
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:
1554
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:
1554
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:
1554
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:
1554
diff
changeset
|
21 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1554
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:
1554
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:
1554
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
26 |
import wx |
|
27 |
||
1252 | 28 |
from graphics.SFC_Objects import SFC_Transition |
29 |
from BlockPreviewDialog import BlockPreviewDialog |
|
814 | 30 |
|
31 |
#------------------------------------------------------------------------------- |
|
1252 | 32 |
# Set Transition Parameters Dialog |
814 | 33 |
#------------------------------------------------------------------------------- |
34 |
||
1252 | 35 |
""" |
36 |
Class that implements a dialog for defining parameters of a transition graphic |
|
37 |
element |
|
38 |
""" |
|
39 |
||
40 |
class SFCTransitionDialog(BlockPreviewDialog): |
|
41 |
||
42 |
def __init__(self, parent, controller, tagname, connection=True): |
|
43 |
""" |
|
44 |
Constructor |
|
45 |
@param parent: Parent wx.Window of dialog for modal |
|
46 |
@param controller: Reference to project controller |
|
47 |
@param tagname: Tagname of project POU edited |
|
48 |
@param connection: True if transition value can be defined by a |
|
49 |
connection (default: True) |
|
50 |
""" |
|
51 |
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
|
52 |
title=_('Edit transition')) |
814 | 53 |
|
1252 | 54 |
# Init common sizers |
55 |
self._init_sizers(2, 0, 8, None, 2, 1) |
|
56 |
||
57 |
# Create label for transition type |
|
814 | 58 |
type_label = wx.StaticText(self, label=_('Type:')) |
1252 | 59 |
self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
60 |
||
61 |
# Create combo box for selecting reference value |
|
62 |
reference = wx.ComboBox(self, style=wx.CB_READONLY) |
|
63 |
reference.Append("") |
|
64 |
for transition in controller.GetEditedElementTransitions(tagname): |
|
65 |
reference.Append(transition) |
|
66 |
self.Bind(wx.EVT_COMBOBOX, self.OnReferenceChanged, reference) |
|
67 |
||
68 |
# Create Text control for defining inline value |
|
69 |
inline = wx.TextCtrl(self) |
|
70 |
self.Bind(wx.EVT_TEXT, self.OnInlineChanged, inline) |
|
71 |
||
72 |
# Create radio buttons for selecting power rail type |
|
73 |
self.TypeRadioButtons = {} |
|
74 |
first = True |
|
75 |
for type, label, control in [('reference', _('Reference'), reference), |
|
76 |
('inline', _('Inline'), inline), |
|
77 |
('connection', _('Connection'), None)]: |
|
78 |
radio_button = wx.RadioButton(self, label=label, |
|
79 |
style=(wx.RB_GROUP if first else 0)) |
|
80 |
radio_button.SetValue(first) |
|
81 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
|
82 |
self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
|
83 |
if control is not None: |
|
84 |
control.Enable(first) |
|
85 |
self.LeftGridSizer.AddWindow(control, flag=wx.GROW) |
|
86 |
self.TypeRadioButtons[type] = (radio_button, control) |
|
87 |
first = False |
|
88 |
||
89 |
# Create label for transition priority |
|
814 | 90 |
priority_label = wx.StaticText(self, label=_('Priority:')) |
1252 | 91 |
self.LeftGridSizer.AddWindow(priority_label, flag=wx.GROW) |
92 |
||
93 |
# Create spin control for defining priority value |
|
814 | 94 |
self.Priority = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) |
95 |
self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, self.Priority) |
|
1252 | 96 |
self.LeftGridSizer.AddWindow(self.Priority, flag=wx.GROW) |
97 |
||
98 |
# Add preview panel and associated label to sizers |
|
99 |
self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
|
100 |
self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
|
101 |
||
102 |
# Add buttons sizer to sizers |
|
103 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
|
814 | 104 |
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
|
105 |
|
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
106 |
self.Fit() |
814 | 107 |
|
1252 | 108 |
# Reference radio button is default control having keyboard focus |
109 |
self.TypeRadioButtons["reference"][0].SetFocus() |
|
110 |
||
111 |
def GetTransitionType(self): |
|
112 |
""" |
|
113 |
Return type selected for SFC transition and associated value |
|
114 |
@return: Type selected and associated value (None if no value) |
|
115 |
""" |
|
116 |
# Go through radio buttons and return type and value associated to the |
|
117 |
# one that is selected |
|
118 |
for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
|
119 |
if radio.GetValue(): |
|
120 |
if isinstance(control, wx.ComboBox): |
|
121 |
return type, control.GetStringSelection() |
|
122 |
elif isinstance(control, wx.TextCtrl): |
|
123 |
return type, control.GetValue() |
|
124 |
else: |
|
125 |
return type, None |
|
126 |
return None, None |
|
127 |
||
128 |
def SetValues(self, values): |
|
129 |
""" |
|
130 |
Set default SFC transition parameters |
|
131 |
@param values: Transition parameters values |
|
132 |
""" |
|
133 |
# Extract transition value according to type |
|
134 |
type_value = values.get("value", None) |
|
135 |
||
136 |
# For each parameters defined, set corresponding control value |
|
137 |
for name, value in values.items(): |
|
138 |
||
139 |
# Parameter is SFC transition priority |
|
140 |
if name == "priority": |
|
141 |
self.Priority.SetValue(values["priority"]) |
|
142 |
||
143 |
# Parameter is SFC transition type |
|
144 |
elif name == "type": |
|
145 |
for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
|
146 |
radio.SetValue(type == value) |
|
147 |
if control is not None: |
|
148 |
# Enable associated control to type and set value |
|
149 |
control.Enable(type == value) |
|
150 |
if type == value: |
|
151 |
if isinstance(control, wx.ComboBox): |
|
152 |
control.SetStringSelection(type_value) |
|
153 |
elif isinstance(control, wx.TextCtrl): |
|
154 |
control.ChangeValue(type_value) |
|
155 |
||
156 |
# Refresh preview panel |
|
157 |
self.RefreshPreview() |
|
158 |
||
159 |
def GetValues(self): |
|
160 |
""" |
|
161 |
Return SFC transition parameters defined in dialog |
|
162 |
@return: {parameter_name: parameter_value,...} |
|
163 |
""" |
|
164 |
values = {"priority" : self.Priority.GetValue()} |
|
165 |
values["type"], values["value"] = self.GetTransitionType() |
|
166 |
values["width"], values["height"] = self.Element.GetSize() |
|
167 |
return values |
|
168 |
||
169 |
def OnOK(self, event): |
|
170 |
""" |
|
171 |
Called when dialog OK button is pressed |
|
172 |
Test if parameters defined are valid |
|
173 |
@param event: wx.Event from OK button |
|
174 |
""" |
|
175 |
message = None |
|
176 |
||
177 |
# Get transition type and value associated |
|
178 |
type, value = self.GetTransitionType() |
|
179 |
||
180 |
# Test that value associated to type is defined |
|
181 |
if type != "connection" and value == "": |
|
182 |
message = _("Form isn't complete. %s must be filled!") % type |
|
183 |
||
184 |
# Show error message if an error is detected |
|
185 |
if message is not None: |
|
186 |
self.ShowErrorMessage(message) |
|
187 |
||
188 |
else: |
|
189 |
# Call BlockPreviewDialog function |
|
190 |
BlockPreviewDialog.OnOK(self, event) |
|
191 |
||
192 |
def OnTypeChanged(self, event): |
|
193 |
""" |
|
194 |
Called when transition type changed |
|
195 |
@param event: wx.RadioButtonEvent |
|
196 |
""" |
|
197 |
# Refresh sensibility of control associated to transition types |
|
198 |
for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
|
199 |
if control is not None: |
|
200 |
control.Enable(radio.GetValue()) |
|
201 |
||
202 |
# Refresh preview panel |
|
203 |
self.RefreshPreview() |
|
204 |
event.Skip() |
|
205 |
||
206 |
def OnReferenceChanged(self, event): |
|
207 |
""" |
|
208 |
Called when SFC transition reference value changed |
|
209 |
@param event: wx.ComboBoxEvent |
|
210 |
""" |
|
211 |
self.RefreshPreview() |
|
212 |
event.Skip() |
|
213 |
||
214 |
def OnInlineChanged(self, event): |
|
215 |
""" |
|
216 |
Called when SFC transition inline value changed |
|
217 |
@param event: wx.TextEvent |
|
218 |
""" |
|
219 |
self.RefreshPreview() |
|
220 |
event.Skip() |
|
221 |
||
222 |
def OnPriorityChanged(self, event): |
|
223 |
""" |
|
224 |
Called when block inputs number changed |
|
225 |
@param event: wx.SpinEvent |
|
226 |
""" |
|
227 |
self.RefreshPreview() |
|
228 |
event.Skip() |
|
229 |
||
230 |
def RefreshPreview(self): |
|
231 |
""" |
|
232 |
Refresh preview panel of graphic element |
|
233 |
Override BlockPreviewDialog function |
|
234 |
""" |
|
235 |
# Set graphic element displayed, creating a SFC transition |
|
814 | 236 |
self.Element = SFC_Transition(self.Preview) |
1252 | 237 |
self.Element.SetType(*self.GetTransitionType()) |
238 |
self.Element.SetPriority(self.Priority.GetValue()) |
|
239 |
||
240 |
# Call BlockPreviewDialog function |
|
241 |
BlockPreviewDialog.RefreshPreview(self) |