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