author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 05 Dec 2024 16:45:37 +0100 | |
changeset 4061 | e0dfe8b8db4a |
parent 3972 | 5d46adf7bbba |
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 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
26 |
|
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 |
|
37 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
38 |
# ------------------------------------------------------------------------------- |
1244 | 39 |
# 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
|
40 |
# ------------------------------------------------------------------------------- |
814 | 41 |
|
1244 | 42 |
|
43 |
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
|
44 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
45 |
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
|
46 |
element |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
47 |
""" |
1244 | 48 |
|
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
49 |
def __init__(self, parent, controller, tagname, exclude_input=False): |
1244 | 50 |
""" |
51 |
Constructor |
|
52 |
@param parent: Parent wx.Window of dialog for modal |
|
53 |
@param controller: Reference to project controller |
|
54 |
@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
|
55 |
@param exclude_input: Exclude input from variable class selection |
1244 | 56 |
""" |
57 |
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
|
58 |
title=_('Variable Properties')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
59 |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
60 |
# Dictionaries containing correspondence between variable block class and string |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
61 |
# to be shown in Class combo box in both sense |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
62 |
self.VARIABLE_CLASSES_DICT = { |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
63 |
INPUT: _("Input"), |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
64 |
INOUT: _("InOut"), |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
65 |
OUTPUT: _("Output") |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
66 |
} |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
67 |
|
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
68 |
self.VARIABLE_CLASSES_DICT_REVERSE = dict( |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
69 |
[(value, key) for key, value in self.VARIABLE_CLASSES_DICT.items()]) |
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
70 |
|
1250
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
71 |
# Init common sizers |
7e6de17c687a
Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents:
1246
diff
changeset
|
72 |
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
|
73 |
|
1244 | 74 |
# Create label for variable class |
814 | 75 |
class_label = wx.StaticText(self, label=_('Class:')) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
76 |
self.LeftGridSizer.Add(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
|
77 |
|
1244 | 78 |
# Create a combo box for defining variable class |
814 | 79 |
self.Class = wx.ComboBox(self, style=wx.CB_READONLY) |
80 |
self.Bind(wx.EVT_COMBOBOX, self.OnClassChanged, self.Class) |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
81 |
self.LeftGridSizer.Add(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
|
82 |
|
1244 | 83 |
# 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
|
84 |
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
|
85 |
label=_('Execution Order:')) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
86 |
self.LeftGridSizer.Add(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
|
87 |
|
1244 | 88 |
# Create spin control for defining variable execution order |
814 | 89 |
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
|
90 |
self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, |
1244 | 91 |
self.ExecutionOrder) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
92 |
self.LeftGridSizer.Add(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
|
93 |
|
1244 | 94 |
# Create label for variable expression |
1182 | 95 |
name_label = wx.StaticText(self, label=_('Expression:')) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
96 |
self.RightGridSizer.Add(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
|
97 |
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
|
98 |
|
1244 | 99 |
# Create text control for defining variable expression |
1182 | 100 |
self.Expression = wx.TextCtrl(self) |
101 |
self.Bind(wx.EVT_TEXT, self.OnExpressionChanged, self.Expression) |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
102 |
self.RightGridSizer.Add(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
|
103 |
|
1244 | 104 |
# Create a list box to selected variable expression in the list of |
105 |
# 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
|
106 |
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
|
107 |
style=wx.LB_SINGLE | wx.LB_SORT) |
814 | 108 |
self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, self.VariableName) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
109 |
self.RightGridSizer.Add(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
|
110 |
|
1244 | 111 |
# Add preview panel and associated label to sizers |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
112 |
self.MainSizer.Add(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
|
113 |
flag=wx.GROW | wx.LEFT | wx.RIGHT) |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
114 |
self.MainSizer.Add(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
|
115 |
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
|
116 |
|
1244 | 117 |
# Add buttons sizer to sizers |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2591
diff
changeset
|
118 |
self.MainSizer.Add( |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
|
1244 | 122 |
# Set options that can be selected in class combo box |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
123 |
for var_class, choice in self.VARIABLE_CLASSES_DICT.items(): |
1259
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
124 |
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
|
125 |
self.Class.Append(choice) |
8350222a81c3
Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents:
1250
diff
changeset
|
126 |
self.Class.SetSelection(0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
127 |
|
1246 | 128 |
# Extract list of variables defined in POU |
129 |
self.RefreshVariableList() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
130 |
|
1244 | 131 |
# Refresh values in name list box |
814 | 132 |
self.RefreshNameList() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
133 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
134 |
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
|
135 |
self.Fit() |
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
136 |
|
1244 | 137 |
# Class combo box is default control having keyboard focus |
814 | 138 |
self.Class.SetFocus() |
139 |
||
140 |
def RefreshNameList(self): |
|
1244 | 141 |
""" |
142 |
Called to refresh names in name list box |
|
143 |
""" |
|
144 |
# Get variable class to select POU variable applicable |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
145 |
var_class = self.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
|
146 |
self.Class.GetStringSelection()] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
147 |
|
1244 | 148 |
# Refresh names in name list box by selecting variables in POU variables |
149 |
# list that can be applied to variable class |
|
814 | 150 |
self.VariableName.Clear() |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
151 |
for name, (var_type, _value_type) in self.VariableList.items(): |
814 | 152 |
if var_type != "Input" or var_class == INPUT: |
153 |
self.VariableName.Append(name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
154 |
|
1244 | 155 |
# Get variable expression and select corresponding value in name list |
156 |
# box if it exists |
|
157 |
selected = self.Expression.GetValue() |
|
3972
5d46adf7bbba
IDE: Workaround some reported WxPython/MacOS problems.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
158 |
self.VariableName.SetSelection( |
5d46adf7bbba
IDE: Workaround some reported WxPython/MacOS problems.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
159 |
wx.NOT_FOUND if selected == "" else self.VariableName.FindString(selected, True)) |
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 |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
174 |
self.Class.SetStringSelection(self.VARIABLE_CLASSES_DICT[var_class]) |
1244 | 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 |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3303
diff
changeset
|
179 |
for name, value in list(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 |
|
3972
5d46adf7bbba
IDE: Workaround some reported WxPython/MacOS problems.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
186 |
self.VariableName.SetSelection(self.VariableName.FindString(value, True)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
187 |
|
1244 | 188 |
# Parameter is variable execution order |
189 |
elif name == "executionOrder": |
|
190 |
self.ExecutionOrder.SetValue(value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
191 |
|
1244 | 192 |
# Refresh preview panel |
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
193 |
self.Refresh() |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
194 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
195 |
|
814 | 196 |
def GetValues(self): |
1244 | 197 |
""" |
198 |
Return block parameters defined in dialog |
|
199 |
@return: {parameter_name: parameter_value,...} |
|
200 |
""" |
|
201 |
expression = self.Expression.GetValue() |
|
202 |
values = { |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
203 |
"class": self.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
|
204 |
self.Class.GetStringSelection()], |
1244 | 205 |
"expression": expression, |
1246 | 206 |
"var_type": self.VariableList.get(expression, (None, None))[1], |
1244 | 207 |
"executionOrder": self.ExecutionOrder.GetValue()} |
208 |
values["width"], values["height"] = self.Element.GetSize() |
|
814 | 209 |
return values |
210 |
||
211 |
def OnOK(self, event): |
|
1244 | 212 |
""" |
213 |
Called when dialog OK button is pressed |
|
214 |
Test if parameters defined are valid |
|
215 |
@param event: wx.Event from OK button |
|
216 |
""" |
|
814 | 217 |
message = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
218 |
|
1244 | 219 |
# Test that an expression have been selected or typed by user |
1182 | 220 |
value = self.Expression.GetValue() |
814 | 221 |
if value == "": |
222 |
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
|
223 |
|
1244 | 224 |
# Show error message if an error is detected |
814 | 225 |
if message is not None: |
1244 | 226 |
self.ShowErrorMessage(message) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
227 |
|
814 | 228 |
else: |
1244 | 229 |
# Call BlockPreviewDialog function |
230 |
BlockPreviewDialog.OnOK(self, event) |
|
814 | 231 |
|
232 |
def OnClassChanged(self, event): |
|
1244 | 233 |
""" |
234 |
Called when variable class value changed |
|
235 |
@param event: wx.ComboBoxEvent |
|
236 |
""" |
|
237 |
# Refresh name list box values |
|
814 | 238 |
self.RefreshNameList() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
239 |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
240 |
self.Refresh() |
814 | 241 |
event.Skip() |
242 |
||
243 |
def OnNameChanged(self, event): |
|
1244 | 244 |
""" |
245 |
Called when name selected in name list box changed |
|
246 |
@param event: wx.ListBoxEvent |
|
247 |
""" |
|
248 |
# Change expression test control value to the value selected in name |
|
249 |
# list box if value selected is valid |
|
250 |
if self.VariableName.GetSelection() != wx.NOT_FOUND: |
|
251 |
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
|
252 |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
253 |
self.Refresh() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
254 |
event.Skip() |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
255 |
|
814 | 256 |
def OnExpressionChanged(self, event): |
1244 | 257 |
""" |
258 |
Called when expression text control is changed by user |
|
259 |
@param event: wx.ListBoxEvent |
|
260 |
""" |
|
261 |
# Select the corresponding value in name list box if it exists |
|
1182 | 262 |
self.VariableName.SetSelection( |
3972
5d46adf7bbba
IDE: Workaround some reported WxPython/MacOS problems.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3750
diff
changeset
|
263 |
self.VariableName.FindString(self.Expression.GetValue(), True)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
264 |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
265 |
self.Refresh() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
266 |
event.Skip() |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
267 |
|
814 | 268 |
def OnExecutionOrderChanged(self, event): |
1244 | 269 |
""" |
270 |
Called when block execution control value changed |
|
271 |
@param event: wx.SpinEvent |
|
272 |
""" |
|
2591
5f685bcd3ad6
Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents:
2587
diff
changeset
|
273 |
self.Refresh() |
2587
c67488bd8134
Fixed preview drawing/refresh problem in sfc/ld/fbd graphical element creation dialogs on windows (introduced in 9c5f835b031e, continuation of 9622418ac28c)
Edouard Tisserant
parents:
2301
diff
changeset
|
274 |
event.Skip() |
c67488bd8134
Fixed preview drawing/refresh problem in sfc/ld/fbd graphical element creation dialogs on windows (introduced in 9c5f835b031e, continuation of 9622418ac28c)
Edouard Tisserant
parents:
2301
diff
changeset
|
275 |
|
c67488bd8134
Fixed preview drawing/refresh problem in sfc/ld/fbd graphical element creation dialogs on windows (introduced in 9c5f835b031e, continuation of 9622418ac28c)
Edouard Tisserant
parents:
2301
diff
changeset
|
276 |
def DrawPreview(self): |
1244 | 277 |
""" |
278 |
Refresh preview panel of graphic element |
|
279 |
Override BlockPreviewDialog function |
|
280 |
""" |
|
281 |
# Get expression value to put in FBD variable element |
|
1182 | 282 |
name = self.Expression.GetValue() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
283 |
|
1244 | 284 |
# 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
|
285 |
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
|
286 |
self.Preview, |
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
287 |
self.VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()], |
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 |
name, |
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.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
|
290 |
executionOrder=self.ExecutionOrder.GetValue()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
291 |
|
1244 | 292 |
# Call BlockPreviewDialog function |
2587
c67488bd8134
Fixed preview drawing/refresh problem in sfc/ld/fbd graphical element creation dialogs on windows (introduced in 9c5f835b031e, continuation of 9622418ac28c)
Edouard Tisserant
parents:
2301
diff
changeset
|
293 |
BlockPreviewDialog.DrawPreview(self) |