author | Edouard Tisserant |
Mon, 15 Oct 2018 15:27:47 +0200 | |
changeset 2311 | bef2b4b87370 |
parent 1881 | 091005ec69c4 |
child 2434 | 07f48018b6f5 |
permissions | -rw-r--r-- |
814 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
941
diff
changeset
|
3 |
# 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:
941
diff
changeset
|
4 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 5 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
941
diff
changeset
|
6 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 7 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
941
diff
changeset
|
8 |
# See COPYING file for copyrights details. |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
941
diff
changeset
|
10 |
# 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:
941
diff
changeset
|
11 |
# 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:
941
diff
changeset
|
12 |
# 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:
941
diff
changeset
|
13 |
# of the License, or (at your option) any later version. |
814 | 14 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
941
diff
changeset
|
15 |
# 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:
941
diff
changeset
|
16 |
# 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:
941
diff
changeset
|
17 |
# 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:
941
diff
changeset
|
18 |
# GNU General Public License for more details. |
814 | 19 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
941
diff
changeset
|
20 |
# 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:
941
diff
changeset
|
21 |
# 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:
941
diff
changeset
|
22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 23 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
24 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
25 |
from __future__ import absolute_import |
814 | 26 |
import re |
27 |
import datetime |
|
28 |
||
29 |
import wx |
|
30 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
31 |
# ------------------------------------------------------------------------------- |
814 | 32 |
# Helpers |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
33 |
# ------------------------------------------------------------------------------- |
814 | 34 |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
35 |
LOCATIONDATATYPES = {"X": ["BOOL"], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
36 |
"B": ["SINT", "USINT", "BYTE", "STRING"], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
37 |
"W": ["INT", "UINT", "WORD", "WSTRING"], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
38 |
"D": ["DINT", "UDINT", "REAL", "DWORD"], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
39 |
"L": ["LINT", "ULINT", "LREAL", "LWORD"]} |
814 | 40 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
|
814 | 42 |
def gen_get_function(f): |
43 |
def get_function(v): |
|
44 |
try: |
|
45 |
return f(v) |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
46 |
except Exception: |
814 | 47 |
return None |
48 |
return get_function |
|
49 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
50 |
|
878
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
51 |
def gen_get_string(delimiter): |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
52 |
STRING_MODEL = re.compile("%(delimiter)s([^%(delimiter)s]*)%(delimiter)s$" % {"delimiter": delimiter}) |
1750
acf02488f37f
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
53 |
|
878
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
54 |
def get_string(v): |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
55 |
result = STRING_MODEL.match(v) |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
56 |
if result is not None: |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
57 |
return result.group(1) |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
58 |
return None |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
59 |
return get_string |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
60 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
61 |
|
814 | 62 |
getinteger = gen_get_function(int) |
63 |
getfloat = gen_get_function(float) |
|
878
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
64 |
getstring = gen_get_string("'") |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
65 |
getwstring = gen_get_string('"') |
814 | 66 |
|
67 |
SECOND = 1000000 |
|
68 |
MINUTE = 60 * SECOND |
|
69 |
HOUR = 60 * MINUTE |
|
70 |
DAY = 24 * HOUR |
|
71 |
||
878
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
72 |
IEC_TIME_MODEL = re.compile("(?:(?:T|TIME)#)?(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M(?!S)_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?$" % {"float": "[0-9]+(?:\.[0-9]+)?"}) |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
73 |
IEC_DATE_MODEL = re.compile("(?:(?:D|DATE)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})$") |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
74 |
IEC_DATETIME_MODEL = re.compile("(?:(?:DT|DATE_AND_TIME)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
75 |
IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
814 | 76 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
77 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
78 |
def gettime(v): |
814 | 79 |
result = IEC_TIME_MODEL.match(v.upper()) |
80 |
if result is not None: |
|
81 |
negative, days, hours, minutes, seconds, milliseconds = result.groups() |
|
82 |
microseconds = 0 |
|
83 |
not_null = False |
|
84 |
for value, factor in [(days, DAY), |
|
85 |
(hours, HOUR), |
|
86 |
(minutes, MINUTE), |
|
87 |
(seconds, SECOND), |
|
88 |
(milliseconds, 1000)]: |
|
89 |
if value is not None: |
|
90 |
microseconds += float(value) * factor |
|
91 |
not_null = True |
|
92 |
if not not_null: |
|
93 |
return None |
|
94 |
if negative is not None: |
|
95 |
microseconds = -microseconds |
|
96 |
return datetime.timedelta(microseconds=microseconds) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
97 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
98 |
else: |
814 | 99 |
return None |
100 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
101 |
|
814 | 102 |
def getdate(v): |
103 |
result = IEC_DATE_MODEL.match(v.upper()) |
|
104 |
if result is not None: |
|
105 |
year, month, day = result.groups() |
|
106 |
try: |
|
107 |
date = datetime.datetime(int(year), int(month), int(day)) |
|
1846
14b40afccd69
remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
108 |
except ValueError: |
814 | 109 |
return None |
110 |
base_date = datetime.datetime(1970, 1, 1) |
|
111 |
return date - base_date |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
112 |
else: |
814 | 113 |
return None |
114 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
115 |
|
814 | 116 |
def getdatetime(v): |
117 |
result = IEC_DATETIME_MODEL.match(v.upper()) |
|
118 |
if result is not None: |
|
119 |
year, month, day, hours, minutes, seconds = result.groups() |
|
120 |
try: |
|
941
b6e93549de2e
Fixed bug ForceVariableDialog when forcing DATETIME variables
Laurent Bessard
parents:
878
diff
changeset
|
121 |
date = datetime.datetime(int(year), int(month), int(day), int(hours), int(minutes), int(float(seconds)), int((float(seconds) * SECOND) % SECOND)) |
1846
14b40afccd69
remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
122 |
except ValueError: |
814 | 123 |
return None |
124 |
base_date = datetime.datetime(1970, 1, 1) |
|
125 |
return date - base_date |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
126 |
else: |
814 | 127 |
return None |
128 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
129 |
|
814 | 130 |
def gettimeofday(v): |
131 |
result = IEC_TIMEOFDAY_MODEL.match(v.upper()) |
|
132 |
if result is not None: |
|
133 |
hours, minutes, seconds = result.groups() |
|
134 |
microseconds = 0 |
|
135 |
for value, factor in [(hours, HOUR), |
|
136 |
(minutes, MINUTE), |
|
137 |
(seconds, SECOND)]: |
|
138 |
microseconds += float(value) * factor |
|
139 |
return datetime.timedelta(microseconds=microseconds) |
|
140 |
else: |
|
141 |
return None |
|
142 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
143 |
|
814 | 144 |
GetTypeValue = {"BOOL": lambda x: {"TRUE": True, "FALSE": False, "0": False, "1": True}.get(x.upper(), None), |
145 |
"SINT": getinteger, |
|
146 |
"INT": getinteger, |
|
147 |
"DINT": getinteger, |
|
148 |
"LINT": getinteger, |
|
149 |
"USINT": getinteger, |
|
150 |
"UINT": getinteger, |
|
151 |
"UDINT": getinteger, |
|
152 |
"ULINT": getinteger, |
|
153 |
"BYTE": getinteger, |
|
154 |
"WORD": getinteger, |
|
155 |
"DWORD": getinteger, |
|
156 |
"LWORD": getinteger, |
|
157 |
"REAL": getfloat, |
|
158 |
"LREAL": getfloat, |
|
159 |
"STRING": getstring, |
|
878
37256069baed
Fix display of string variables value in debug
Laurent Bessard
parents:
814
diff
changeset
|
160 |
"WSTRING": getwstring, |
814 | 161 |
"TIME": gettime, |
162 |
"DATE": getdate, |
|
163 |
"DT": getdatetime, |
|
164 |
"TOD": gettimeofday} |
|
165 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
166 |
# ------------------------------------------------------------------------------- |
814 | 167 |
# Force Variable Dialog |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
168 |
# ------------------------------------------------------------------------------- |
814 | 169 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
170 |
|
814 | 171 |
class ForceVariableDialog(wx.TextEntryDialog): |
172 |
||
173 |
def __init__(self, parent, iec_type, defaultValue=""): |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
174 |
wx.TextEntryDialog.__init__( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
175 |
self, parent, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
176 |
message=_("Forcing Variable Value"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
177 |
caption=_("Please enter value for a \"%s\" variable:") % iec_type, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
178 |
defaultValue=defaultValue, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
179 |
style=wx.OK | wx.CANCEL | wx.CENTRE, pos=wx.DefaultPosition) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
180 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
181 |
self.IEC_Type = iec_type |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
182 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1701
diff
changeset
|
183 |
self.Bind(wx.EVT_BUTTON, self.OnOK, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
184 |
self.GetSizer().GetItem(2).GetSizer().GetItem(1). |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
185 |
GetSizer().GetAffirmativeButton()) |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
186 |
self.ValueTextCtrl = self.GetSizer().GetItem(1).GetWindow() |
1701
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
187 |
if self.IEC_Type == "BOOL": |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
188 |
self.ToggleButton = wx.ToggleButton(self, label=_("Toggle value")) |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
189 |
value = GetTypeValue[self.IEC_Type](defaultValue) |
1701
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
190 |
if value is not None: |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
191 |
self.ToggleButton.SetValue(value) |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
192 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
193 |
border = self.GetSizer().GetItem(1).GetBorder() |
1701
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
194 |
self.GetSizer().Insert(before=2, item=self.ToggleButton, |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
195 |
border=border, |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
196 |
flag=wx.LEFT | wx.RIGHT | wx.EXPAND) |
1701
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
197 |
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleBoolValue, self.ToggleButton) |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
198 |
|
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
199 |
self.Fit() |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
200 |
|
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
201 |
def ToggleBoolValue(self, event): |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
202 |
value = self.ToggleButton.GetValue() |
1701
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
203 |
self.ValueTextCtrl.SetValue(unicode(value)) |
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
204 |
|
814 | 205 |
def OnOK(self, event): |
206 |
message = None |
|
1701
8337f6c169d0
add button to ForceVariableDialog to toggle forced boolean value
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
207 |
value = self.ValueTextCtrl.GetValue() |
814 | 208 |
if value == "": |
209 |
message = _("You must type a value!") |
|
210 |
elif GetTypeValue[self.IEC_Type](value) is None: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
211 |
message = _("Invalid value \"{a1}\" for \"{a2}\" variable!").format(a1=value, a2=self.IEC_Type) |
814 | 212 |
if message is not None: |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
213 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 214 |
dialog.ShowModal() |
215 |
dialog.Destroy() |
|
216 |
else: |
|
217 |
self.EndModal(wx.ID_OK) |
|
218 |
event.Skip() |
|
219 |
||
220 |
def GetValue(self): |
|
221 |
return GetTypeValue[self.IEC_Type](wx.TextEntryDialog.GetValue(self)) |