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