author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 29 Sep 2017 16:39:52 +0300 | |
changeset 1838 | 646245c1c0d9 |
parent 1782 | 5b6ad7a7fd9d |
child 1847 | 6198190bc121 |
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 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
31 |
# ------------------------------------------------------------------------------- |
1252 | 32 |
# Set Transition Parameters Dialog |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
33 |
# ------------------------------------------------------------------------------- |
814 | 34 |
|
1252 | 35 |
|
36 |
class SFCTransitionDialog(BlockPreviewDialog): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
37 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
38 |
Class that implements a dialog for defining parameters of a transition graphic |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
39 |
element |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
40 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
41 |
|
1252 | 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, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
52 |
title=_('Edit transition')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
53 |
|
1252 | 54 |
# Init common sizers |
55 |
self._init_sizers(2, 0, 8, None, 2, 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
56 |
|
1252 | 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) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
60 |
|
1252 | 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) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
67 |
|
1252 | 68 |
# Create Text control for defining inline value |
69 |
inline = wx.TextCtrl(self) |
|
70 |
self.Bind(wx.EVT_TEXT, self.OnInlineChanged, inline) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
71 |
|
1252 | 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)]: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
78 |
radio_button = wx.RadioButton(self, label=label, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
79 |
style=(wx.RB_GROUP if first else 0)) |
1252 | 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 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
88 |
|
1252 | 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) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
92 |
|
1252 | 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) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
97 |
|
1252 | 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) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
101 |
|
1252 | 102 |
# Add buttons sizer to sizers |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
103 |
self.MainSizer.AddSizer( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
104 |
self.ButtonSizer, border=20, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
105 |
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
|
106 |
|
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
107 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
108 |
|
1252 | 109 |
# Reference radio button is default control having keyboard focus |
110 |
self.TypeRadioButtons["reference"][0].SetFocus() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
111 |
|
1252 | 112 |
def GetTransitionType(self): |
113 |
""" |
|
114 |
Return type selected for SFC transition and associated value |
|
115 |
@return: Type selected and associated value (None if no value) |
|
116 |
""" |
|
117 |
# Go through radio buttons and return type and value associated to the |
|
118 |
# one that is selected |
|
119 |
for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
|
120 |
if radio.GetValue(): |
|
121 |
if isinstance(control, wx.ComboBox): |
|
122 |
return type, control.GetStringSelection() |
|
123 |
elif isinstance(control, wx.TextCtrl): |
|
124 |
return type, control.GetValue() |
|
125 |
else: |
|
126 |
return type, None |
|
127 |
return None, None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
128 |
|
1252 | 129 |
def SetValues(self, values): |
130 |
""" |
|
131 |
Set default SFC transition parameters |
|
132 |
@param values: Transition parameters values |
|
133 |
""" |
|
134 |
# Extract transition value according to type |
|
135 |
type_value = values.get("value", None) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
136 |
|
1252 | 137 |
# For each parameters defined, set corresponding control value |
138 |
for name, value in values.items(): |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
139 |
|
1252 | 140 |
# Parameter is SFC transition priority |
141 |
if name == "priority": |
|
142 |
self.Priority.SetValue(values["priority"]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
143 |
|
1252 | 144 |
# Parameter is SFC transition type |
145 |
elif name == "type": |
|
146 |
for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
|
147 |
radio.SetValue(type == value) |
|
148 |
if control is not None: |
|
149 |
# Enable associated control to type and set value |
|
150 |
control.Enable(type == value) |
|
151 |
if type == value: |
|
152 |
if isinstance(control, wx.ComboBox): |
|
153 |
control.SetStringSelection(type_value) |
|
154 |
elif isinstance(control, wx.TextCtrl): |
|
155 |
control.ChangeValue(type_value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
156 |
|
1252 | 157 |
# Refresh preview panel |
158 |
self.RefreshPreview() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
159 |
|
1252 | 160 |
def GetValues(self): |
161 |
""" |
|
162 |
Return SFC transition parameters defined in dialog |
|
163 |
@return: {parameter_name: parameter_value,...} |
|
164 |
""" |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
165 |
values = {"priority": self.Priority.GetValue()} |
1252 | 166 |
values["type"], values["value"] = self.GetTransitionType() |
167 |
values["width"], values["height"] = self.Element.GetSize() |
|
168 |
return values |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
169 |
|
1252 | 170 |
def OnOK(self, event): |
171 |
""" |
|
172 |
Called when dialog OK button is pressed |
|
173 |
Test if parameters defined are valid |
|
174 |
@param event: wx.Event from OK button |
|
175 |
""" |
|
176 |
message = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
177 |
|
1252 | 178 |
# Get transition type and value associated |
179 |
type, value = self.GetTransitionType() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
180 |
|
1252 | 181 |
# Test that value associated to type is defined |
182 |
if type != "connection" and value == "": |
|
183 |
message = _("Form isn't complete. %s must be filled!") % type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
184 |
|
1252 | 185 |
# Show error message if an error is detected |
186 |
if message is not None: |
|
187 |
self.ShowErrorMessage(message) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
188 |
|
1252 | 189 |
else: |
190 |
# Call BlockPreviewDialog function |
|
191 |
BlockPreviewDialog.OnOK(self, event) |
|
192 |
||
193 |
def OnTypeChanged(self, event): |
|
194 |
""" |
|
195 |
Called when transition type changed |
|
196 |
@param event: wx.RadioButtonEvent |
|
197 |
""" |
|
198 |
# Refresh sensibility of control associated to transition types |
|
199 |
for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
|
200 |
if control is not None: |
|
201 |
control.Enable(radio.GetValue()) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
202 |
|
1252 | 203 |
# Refresh preview panel |
204 |
self.RefreshPreview() |
|
205 |
event.Skip() |
|
206 |
||
207 |
def OnReferenceChanged(self, event): |
|
208 |
""" |
|
209 |
Called when SFC transition reference value changed |
|
210 |
@param event: wx.ComboBoxEvent |
|
211 |
""" |
|
212 |
self.RefreshPreview() |
|
213 |
event.Skip() |
|
214 |
||
215 |
def OnInlineChanged(self, event): |
|
216 |
""" |
|
217 |
Called when SFC transition inline value changed |
|
218 |
@param event: wx.TextEvent |
|
219 |
""" |
|
220 |
self.RefreshPreview() |
|
221 |
event.Skip() |
|
222 |
||
223 |
def OnPriorityChanged(self, event): |
|
224 |
""" |
|
225 |
Called when block inputs number changed |
|
226 |
@param event: wx.SpinEvent |
|
227 |
""" |
|
228 |
self.RefreshPreview() |
|
229 |
event.Skip() |
|
230 |
||
231 |
def RefreshPreview(self): |
|
232 |
""" |
|
233 |
Refresh preview panel of graphic element |
|
234 |
Override BlockPreviewDialog function |
|
235 |
""" |
|
236 |
# Set graphic element displayed, creating a SFC transition |
|
814 | 237 |
self.Element = SFC_Transition(self.Preview) |
1252 | 238 |
self.Element.SetType(*self.GetTransitionType()) |
239 |
self.Element.SetPriority(self.Priority.GetValue()) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
240 |
|
1252 | 241 |
# Call BlockPreviewDialog function |
242 |
BlockPreviewDialog.RefreshPreview(self) |