equal
deleted
inserted
replaced
20 #You should have received a copy of the GNU General Public |
20 #You should have received a copy of the GNU General Public |
21 #License along with this library; if not, write to the Free Software |
21 #License along with this library; if not, write to the Free Software |
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
23 |
24 import wx |
24 import wx |
|
25 import re |
25 import datetime |
26 import datetime |
26 |
27 |
27 #------------------------------------------------------------------------------- |
28 #------------------------------------------------------------------------------- |
28 # Force Variable Dialog |
29 # Force Variable Dialog |
29 #------------------------------------------------------------------------------- |
30 #------------------------------------------------------------------------------- |
44 |
45 |
45 getinteger = gen_get_function(int) |
46 getinteger = gen_get_function(int) |
46 getfloat = gen_get_function(float) |
47 getfloat = gen_get_function(float) |
47 getstring = gen_get_function(str) |
48 getstring = gen_get_function(str) |
48 |
49 |
49 def gettime(v): |
50 SECOND = 1000000 |
50 try: |
51 MINUTE = 60 * SECOND |
51 return datetime.timedelta(0, float(v)) |
52 HOUR = 60 * MINUTE |
52 except: |
53 DAY = 24 * HOUR |
|
54 IEC_TIME_MODEL = re.compile("(?:T|TIME)#(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?" % {"float": "[0-9]+(?:\.[0-9]+)?"}) |
|
55 |
|
56 def gettime(v): |
|
57 result = IEC_TIME_MODEL.match(v.upper()) |
|
58 if result is not None: |
|
59 negative, days, hours, minutes, seconds, milliseconds = result.groups() |
|
60 microseconds = 0 |
|
61 not_null = False |
|
62 for value, factor in [(days, DAY), |
|
63 (hours, HOUR), |
|
64 (minutes, MINUTE), |
|
65 (seconds, SECOND), |
|
66 (milliseconds, 1000)]: |
|
67 if value is not None: |
|
68 microseconds += float(value) * factor |
|
69 not_null = True |
|
70 if not not_null: |
|
71 return None |
|
72 if negative is not None: |
|
73 microseconds = -microseconds |
|
74 return datetime.timedelta(microseconds=microseconds) |
|
75 |
|
76 else: |
53 return None |
77 return None |
54 |
78 |
55 |
79 |
56 GetTypeValue = {"BOOL": lambda x: {"TRUE": True, "FALSE": False}.get(x.upper(), None), |
80 GetTypeValue = {"BOOL": lambda x: {"TRUE": True, "FALSE": False}.get(x.upper(), None), |
57 "SINT": getinteger, |
81 "SINT": getinteger, |