author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Mon, 14 Aug 2017 23:38:28 +0300 | |
changeset 1738 | d2e979738700 |
parent 1736 | 7e61baa047f0 |
child 1744 | 69dfdb26f600 |
permissions | -rw-r--r-- |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
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:
1259
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:
1259
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
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:
1585
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
814 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
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:
1259
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:
1259
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:
1259
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
814 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
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:
1259
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:
1259
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:
1259
diff
changeset
|
20 |
# GNU General Public License for more details. |
814 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
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:
1259
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:
1259
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
26 |
import wx |
|
27 |
||
1251 | 28 |
from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ |
29 |
SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE |
|
30 |
from graphics.SFC_Objects import SFC_Divergence |
|
31 |
from BlockPreviewDialog import BlockPreviewDialog |
|
814 | 32 |
|
33 |
#------------------------------------------------------------------------------- |
|
34 |
# Create New Divergence Dialog |
|
35 |
#------------------------------------------------------------------------------- |
|
36 |
||
1251 | 37 |
|
38 |
class SFCDivergenceDialog(BlockPreviewDialog): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
39 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
40 |
Class that implements a dialog for defining parameters for creating a new |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
divergence graphic element |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
42 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
43 |
|
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
44 |
def __init__(self, parent, controller, tagname, poss_div_types = None): |
1251 | 45 |
""" |
46 |
Constructor |
|
47 |
@param parent: Parent wx.Window of dialog for modal |
|
48 |
@param controller: Reference to project controller |
|
49 |
@param tagname: Tagname of project POU edited |
|
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
50 |
@param poss_div_types: Types of divergence that will be available in the dialog window |
1251 | 51 |
""" |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1585
diff
changeset
|
52 |
BlockPreviewDialog.__init__(self, parent, controller, tagname, |
814 | 53 |
title=_('Create a new divergence or convergence')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
54 |
|
1251 | 55 |
# Init common sizers |
56 |
self._init_sizers(2, 0, 7, None, 2, 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
57 |
|
1251 | 58 |
# Create label for divergence type |
59 |
type_label = wx.StaticText(self, label=_('Type:')) |
|
60 |
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
|
61 |
|
1251 | 62 |
# Create radio buttons for selecting divergence type |
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
63 |
divergence_buttons = [ |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
64 |
(SELECTION_DIVERGENCE, _('Selection Divergence')), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
65 |
(SELECTION_CONVERGENCE, _('Selection Convergence')), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
66 |
(SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')), |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
67 |
(SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))] |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
68 |
poss_div_btns = [] |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
69 |
if poss_div_types is not None: |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
70 |
for val in poss_div_types: |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
71 |
poss_div_btns.append(divergence_buttons[val]) |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
72 |
else: |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
73 |
poss_div_btns = divergence_buttons |
1251 | 74 |
self.TypeRadioButtons = {} |
75 |
first = True |
|
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
76 |
focusbtn = None |
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
77 |
for type, label in poss_div_btns: |
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, |
1251 | 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 |
self.TypeRadioButtons[type] = radio_button |
|
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
84 |
if first: focusbtn = type |
1251 | 85 |
first = False |
814 | 86 |
|
1251 | 87 |
# Create label for number of divergence sequences |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
88 |
sequences_label = wx.StaticText(self, |
814 | 89 |
label=_('Number of sequences:')) |
1251 | 90 |
self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
91 |
|
1251 | 92 |
# Create spin control for defining number of divergence sequences |
1585
60c0db313ec9
fix initial(equal to the min) number of sequences in SFC Divergence dialog.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1584
diff
changeset
|
93 |
self.Sequences = wx.SpinCtrl(self, min=2, max=20, initial=2) |
814 | 94 |
self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences) |
1251 | 95 |
self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
96 |
|
1251 | 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) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
100 |
|
1251 | 101 |
# Add buttons sizer to sizers |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
102 |
self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
1251 | 103 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
104 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1585
diff
changeset
|
105 |
self.Fit() |
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1585
diff
changeset
|
106 |
|
1251 | 107 |
# Selection divergence radio button is default control having keyboard |
108 |
# focus |
|
1584
431f4ef34bde
make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1571
diff
changeset
|
109 |
self.TypeRadioButtons[focusbtn].SetFocus() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
110 |
|
1251 | 111 |
def GetMinElementSize(self): |
112 |
""" |
|
113 |
Get minimal graphic element size |
|
114 |
@return: Tuple containing minimal size (width, height) or None if no |
|
115 |
element defined |
|
116 |
""" |
|
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1251
diff
changeset
|
117 |
return self.Element.GetMinSize(True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
118 |
|
1251 | 119 |
def GetDivergenceType(self): |
120 |
""" |
|
121 |
Return type selected for SFC divergence |
|
122 |
@return: Type selected (None if not found) |
|
123 |
""" |
|
124 |
# Go through radio buttons and return type associated to the one that |
|
125 |
# is selected |
|
126 |
for type, control in self.TypeRadioButtons.iteritems(): |
|
127 |
if control.GetValue(): |
|
128 |
return type |
|
129 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
130 |
|
814 | 131 |
def GetValues(self): |
1251 | 132 |
""" |
133 |
Set default SFC divergence parameters |
|
134 |
@param values: Divergence parameters values |
|
135 |
""" |
|
136 |
return {"type": self.GetDivergenceType(), |
|
137 |
"number": self.Sequences.GetValue()} |
|
814 | 138 |
|
139 |
def OnTypeChanged(self, event): |
|
1251 | 140 |
""" |
141 |
Called when SFC divergence type changed |
|
142 |
@param event: wx.RadioButtonEvent |
|
143 |
""" |
|
814 | 144 |
self.RefreshPreview() |
145 |
event.Skip() |
|
146 |
||
147 |
def OnSequencesChanged(self, event): |
|
1251 | 148 |
""" |
149 |
Called when SFC divergence number of sequences changed |
|
150 |
@param event: wx.SpinEvent |
|
151 |
""" |
|
814 | 152 |
self.RefreshPreview() |
153 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
154 |
|
814 | 155 |
def RefreshPreview(self): |
1251 | 156 |
""" |
157 |
Refresh preview panel of graphic element |
|
158 |
Override BlockPreviewDialog function |
|
159 |
""" |
|
160 |
# Set graphic element displayed, creating a SFC divergence |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
161 |
self.Element = SFC_Divergence(self.Preview, |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
162 |
self.GetDivergenceType(), |
1251 | 163 |
self.Sequences.GetValue()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
164 |
|
1251 | 165 |
# Call BlockPreviewDialog function |
166 |
BlockPreviewDialog.RefreshPreview(self) |