author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 15 Sep 2017 20:28:54 +0300 | |
changeset 1813 | c18adf359d21 |
parent 1782 | 5b6ad7a7fd9d |
child 1847 | 6198190bc121 |
permissions | -rw-r--r-- |
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:
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. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
diff
changeset
|
6 |
# |
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:
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:
1259
diff
changeset
|
9 |
# |
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. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
diff
changeset
|
11 |
# |
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. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
diff
changeset
|
16 |
# |
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. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1259
diff
changeset
|
21 |
# |
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 |
||
1244 | 28 |
from graphics.GraphicCommons import INPUT, INOUT, OUTPUT |
29 |
from graphics.FBD_Objects import FBD_Variable |
|
30 |
from BlockPreviewDialog import BlockPreviewDialog |
|
814 | 31 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
32 |
# ------------------------------------------------------------------------------- |
814 | 33 |
# Helpers |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
34 |
# ------------------------------------------------------------------------------- |
814 | 35 |
|
1244 | 36 |
# Dictionaries containing correspondence between variable block class and string |
37 |
# to be shown in Class combo box in both sense |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
38 |
VARIABLE_CLASSES_DICT = { |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
39 |
INPUT: _("Input"), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
40 |
INOUT: _("InOut"), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
41 |
OUTPUT: _("Output") |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
42 |
} |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
43 |
|
814 | 44 |
VARIABLE_CLASSES_DICT_REVERSE = dict( |
45 |
[(value, key) for key, value in VARIABLE_CLASSES_DICT.iteritems()]) |
|
46 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
47 |
# ------------------------------------------------------------------------------- |
1244 | 48 |
# Set Variable Parameters Dialog |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
49 |
# ------------------------------------------------------------------------------- |
814 | 50 |
|
1244 | 51 |
|
52 |
class FBDVariableDialog(BlockPreviewDialog): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
53 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
54 |
Class that implements a dialog for defining parameters of a FBD variable graphic |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
55 |
element |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
56 |
""" |
1244 | 57 |
|
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
58 |
def __init__(self, parent, controller, tagname, exclude_input=False): |
1244 | 59 |
""" |
60 |
Constructor |
|
61 |
@param parent: Parent wx.Window of dialog for modal |
|
62 |
@param controller: Reference to project controller |
|
63 |
@param tagname: Tagname of project POU edited |
|
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
64 |
@param exclude_input: Exclude input from variable class selection |
1244 | 65 |
""" |
66 |
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:
1766
diff
changeset
|
67 |
title=_('Variable Properties')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
68 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
69 |
# Init common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
70 |
self._init_sizers(4, 2, 4, None, 3, 2) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
71 |
|
1244 | 72 |
# Create label for variable class |
814 | 73 |
class_label = wx.StaticText(self, label=_('Class:')) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
74 |
self.LeftGridSizer.AddWindow(class_label, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
75 |
|
1244 | 76 |
# Create a combo box for defining variable class |
814 | 77 |
self.Class = wx.ComboBox(self, style=wx.CB_READONLY) |
78 |
self.Bind(wx.EVT_COMBOBOX, self.OnClassChanged, self.Class) |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
79 |
self.LeftGridSizer.AddWindow(self.Class, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
80 |
|
1244 | 81 |
# Create label for variable execution order |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
82 |
execution_order_label = wx.StaticText(self, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
83 |
label=_('Execution Order:')) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
84 |
self.LeftGridSizer.AddWindow(execution_order_label, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
85 |
|
1244 | 86 |
# Create spin control for defining variable execution order |
814 | 87 |
self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
88 |
self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, |
1244 | 89 |
self.ExecutionOrder) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
90 |
self.LeftGridSizer.AddWindow(self.ExecutionOrder, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
91 |
|
1244 | 92 |
# Create label for variable expression |
1182 | 93 |
name_label = wx.StaticText(self, label=_('Expression:')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
94 |
self.RightGridSizer.AddWindow(name_label, border=5, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
95 |
flag=wx.GROW | wx.BOTTOM) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
96 |
|
1244 | 97 |
# Create text control for defining variable expression |
1182 | 98 |
self.Expression = wx.TextCtrl(self) |
99 |
self.Bind(wx.EVT_TEXT, self.OnExpressionChanged, self.Expression) |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
100 |
self.RightGridSizer.AddWindow(self.Expression, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
101 |
|
1244 | 102 |
# Create a list box to selected variable expression in the list of |
103 |
# variables defined in POU |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
104 |
self.VariableName = wx.ListBox(self, size=wx.Size(-1, 120), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
105 |
style=wx.LB_SINGLE | wx.LB_SORT) |
814 | 106 |
self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, self.VariableName) |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
107 |
self.RightGridSizer.AddWindow(self.VariableName, border=4, flag=wx.GROW | wx.TOP) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
108 |
|
1244 | 109 |
# Add preview panel and associated label to sizers |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
110 |
self.MainSizer.AddWindow(self.PreviewLabel, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
111 |
flag=wx.GROW | wx.LEFT | wx.RIGHT) |
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
112 |
self.MainSizer.AddWindow(self.Preview, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
113 |
flag=wx.GROW | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
114 |
|
1244 | 115 |
# 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:
1766
diff
changeset
|
116 |
self.MainSizer.AddSizer( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
117 |
self.ButtonSizer, border=20, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
118 |
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
|
119 |
|
1244 | 120 |
# Set options that can be selected in class combo box |
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
121 |
for var_class, choice in VARIABLE_CLASSES_DICT.iteritems(): |
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
122 |
if not exclude_input or var_class != INPUT: |
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
123 |
self.Class.Append(choice) |
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
124 |
self.Class.SetSelection(0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
125 |
|
1246 | 126 |
# Extract list of variables defined in POU |
127 |
self.RefreshVariableList() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
128 |
|
1244 | 129 |
# Refresh values in name list box |
814 | 130 |
self.RefreshNameList() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
131 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
132 |
self.Preview.SetInitialSize(wx.Size(-1, 60)) |
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
133 |
self.Fit() |
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
134 |
|
1244 | 135 |
# Class combo box is default control having keyboard focus |
814 | 136 |
self.Class.SetFocus() |
137 |
||
138 |
def RefreshNameList(self): |
|
1244 | 139 |
""" |
140 |
Called to refresh names in name list box |
|
141 |
""" |
|
142 |
# Get variable class to select POU variable applicable |
|
143 |
var_class = VARIABLE_CLASSES_DICT_REVERSE[ |
|
144 |
self.Class.GetStringSelection()] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
145 |
|
1244 | 146 |
# Refresh names in name list box by selecting variables in POU variables |
147 |
# list that can be applied to variable class |
|
814 | 148 |
self.VariableName.Clear() |
1246 | 149 |
for name, (var_type, value_type) in self.VariableList.iteritems(): |
814 | 150 |
if var_type != "Input" or var_class == INPUT: |
151 |
self.VariableName.Append(name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
152 |
|
1244 | 153 |
# Get variable expression and select corresponding value in name list |
154 |
# box if it exists |
|
155 |
selected = self.Expression.GetValue() |
|
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
156 |
if selected != "" and self.VariableName.FindString(selected) != wx.NOT_FOUND: |
814 | 157 |
self.VariableName.SetStringSelection(selected) |
158 |
else: |
|
1182 | 159 |
self.VariableName.SetSelection(wx.NOT_FOUND) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
160 |
|
1244 | 161 |
# Disable name list box if no name present inside |
814 | 162 |
self.VariableName.Enable(self.VariableName.GetCount() > 0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
163 |
|
814 | 164 |
def SetValues(self, values): |
1244 | 165 |
""" |
166 |
Set default variable parameters |
|
167 |
@param values: Variable parameters values |
|
168 |
""" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
169 |
|
1244 | 170 |
# Get class parameter value |
171 |
var_class = values.get("class", None) |
|
172 |
if var_class is not None: |
|
173 |
# Set class selected in class combo box |
|
174 |
self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[var_class]) |
|
175 |
# Refresh names in name list box according to var class |
|
814 | 176 |
self.RefreshNameList() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
177 |
|
1244 | 178 |
# For each parameters defined, set corresponding control value |
179 |
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
|
180 |
|
1244 | 181 |
# Parameter is variable expression |
182 |
if name == "expression": |
|
183 |
# Set expression text control value |
|
184 |
self.Expression.ChangeValue(value) |
|
185 |
# Select corresponding text in name list box if it exists |
|
186 |
if self.VariableName.FindString(value) != wx.NOT_FOUND: |
|
187 |
self.VariableName.SetStringSelection(value) |
|
188 |
else: |
|
189 |
self.VariableName.SetSelection(wx.NOT_FOUND) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
190 |
|
1244 | 191 |
# Parameter is variable execution order |
192 |
elif name == "executionOrder": |
|
193 |
self.ExecutionOrder.SetValue(value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
194 |
|
1244 | 195 |
# Refresh preview panel |
814 | 196 |
self.RefreshPreview() |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
197 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
198 |
|
814 | 199 |
def GetValues(self): |
1244 | 200 |
""" |
201 |
Return block parameters defined in dialog |
|
202 |
@return: {parameter_name: parameter_value,...} |
|
203 |
""" |
|
204 |
expression = self.Expression.GetValue() |
|
205 |
values = { |
|
206 |
"class": VARIABLE_CLASSES_DICT_REVERSE[ |
|
207 |
self.Class.GetStringSelection()], |
|
208 |
"expression": expression, |
|
1246 | 209 |
"var_type": self.VariableList.get(expression, (None, None))[1], |
1244 | 210 |
"executionOrder": self.ExecutionOrder.GetValue()} |
211 |
values["width"], values["height"] = self.Element.GetSize() |
|
814 | 212 |
return values |
213 |
||
214 |
def OnOK(self, event): |
|
1244 | 215 |
""" |
216 |
Called when dialog OK button is pressed |
|
217 |
Test if parameters defined are valid |
|
218 |
@param event: wx.Event from OK button |
|
219 |
""" |
|
814 | 220 |
message = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
221 |
|
1244 | 222 |
# Test that an expression have been selected or typed by user |
1182 | 223 |
value = self.Expression.GetValue() |
814 | 224 |
if value == "": |
225 |
message = _("At least a variable or an expression must be selected!") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
226 |
|
1244 | 227 |
# Show error message if an error is detected |
814 | 228 |
if message is not None: |
1244 | 229 |
self.ShowErrorMessage(message) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
230 |
|
814 | 231 |
else: |
1244 | 232 |
# Call BlockPreviewDialog function |
233 |
BlockPreviewDialog.OnOK(self, event) |
|
814 | 234 |
|
235 |
def OnClassChanged(self, event): |
|
1244 | 236 |
""" |
237 |
Called when variable class value changed |
|
238 |
@param event: wx.ComboBoxEvent |
|
239 |
""" |
|
240 |
# Refresh name list box values |
|
814 | 241 |
self.RefreshNameList() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
242 |
|
814 | 243 |
self.RefreshPreview() |
244 |
event.Skip() |
|
245 |
||
246 |
def OnNameChanged(self, event): |
|
1244 | 247 |
""" |
248 |
Called when name selected in name list box changed |
|
249 |
@param event: wx.ListBoxEvent |
|
250 |
""" |
|
251 |
# Change expression test control value to the value selected in name |
|
252 |
# list box if value selected is valid |
|
253 |
if self.VariableName.GetSelection() != wx.NOT_FOUND: |
|
254 |
self.Expression.ChangeValue(self.VariableName.GetStringSelection()) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
255 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
256 |
self.RefreshPreview() |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
257 |
event.Skip() |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
258 |
|
814 | 259 |
def OnExpressionChanged(self, event): |
1244 | 260 |
""" |
261 |
Called when expression text control is changed by user |
|
262 |
@param event: wx.ListBoxEvent |
|
263 |
""" |
|
264 |
# Select the corresponding value in name list box if it exists |
|
1182 | 265 |
self.VariableName.SetSelection( |
1244 | 266 |
self.VariableName.FindString(self.Expression.GetValue())) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
267 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
268 |
self.RefreshPreview() |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
269 |
event.Skip() |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
270 |
|
814 | 271 |
def OnExecutionOrderChanged(self, event): |
1244 | 272 |
""" |
273 |
Called when block execution control value changed |
|
274 |
@param event: wx.SpinEvent |
|
275 |
""" |
|
814 | 276 |
self.RefreshPreview() |
277 |
event.Skip() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
278 |
|
814 | 279 |
def RefreshPreview(self): |
1244 | 280 |
""" |
281 |
Refresh preview panel of graphic element |
|
282 |
Override BlockPreviewDialog function |
|
283 |
""" |
|
284 |
# Get expression value to put in FBD variable element |
|
1182 | 285 |
name = self.Expression.GetValue() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
286 |
|
1244 | 287 |
# Set graphic element displayed, creating a FBD variable element |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
288 |
self.Element = FBD_Variable( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
289 |
self.Preview, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
290 |
VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()], |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
291 |
name, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
292 |
self.VariableList.get(name, ("", ""))[1], |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
293 |
executionOrder=self.ExecutionOrder.GetValue()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
294 |
|
1244 | 295 |
# Call BlockPreviewDialog function |
296 |
BlockPreviewDialog.RefreshPreview(self) |