dialogs/ForceVariableDialog.py
author Minyoung Sung
Mon, 27 Aug 2012 17:41:35 +0200
changeset 749 7b17f3c5cf21
parent 747 f36838792511
permissions -rw-r--r--
Update Korean translations
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     2
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     3
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     4
#based on the plcopen standard. 
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     5
#
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     6
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     7
#
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     8
#See COPYING file for copyrights details.
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
     9
#
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    11
#modify it under the terms of the GNU General Public
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    14
#
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    18
#General Public License for more details.
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    19
#
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    20
#You should have received a copy of the GNU General Public
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    23
519
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    24
import re
516
40290ddff19c Initial TIME support in forcing
Edouard Tisserant
parents: 479
diff changeset
    25
import datetime
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    26
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
    27
import wx
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
    28
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    29
#-------------------------------------------------------------------------------
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
    30
#                                Helpers
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    32
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    33
LOCATIONDATATYPES = {"X" : ["BOOL"],
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    34
                     "B" : ["SINT", "USINT", "BYTE", "STRING"],
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    35
                     "W" : ["INT", "UINT", "WORD", "WSTRING"],
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    36
                     "D" : ["DINT", "UDINT", "REAL", "DWORD"],
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    37
                     "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    38
475
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    39
def gen_get_function(f):
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    40
    def get_function(v):
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    41
        try:
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    42
            return f(v)
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    43
        except:
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    44
            return None
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
    45
    return get_function
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    46
476
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 475
diff changeset
    47
getinteger = gen_get_function(int)
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 475
diff changeset
    48
getfloat = gen_get_function(float)
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 475
diff changeset
    49
getstring = gen_get_function(str)
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
    50
519
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    51
SECOND = 1000000
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    52
MINUTE = 60 * SECOND
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    53
HOUR = 60 * MINUTE
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    54
DAY = 24 * HOUR
525
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    55
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents: 536
diff changeset
    56
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]+)?"})
525
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    57
IEC_DATE_MODEL = re.compile("(?:(?:D|DATE)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})")
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    58
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]+)?)")
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    59
IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)")
519
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    60
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    61
def gettime(v):    
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    62
    result = IEC_TIME_MODEL.match(v.upper())
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    63
    if result is not None:
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    64
        negative, days, hours, minutes, seconds, milliseconds = result.groups()
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    65
        microseconds = 0
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    66
        not_null = False
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    67
        for value, factor in [(days, DAY),
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    68
                              (hours, HOUR),
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    69
                              (minutes, MINUTE),
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    70
                              (seconds, SECOND),
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    71
                              (milliseconds, 1000)]:
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    72
            if value is not None:
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    73
                microseconds += float(value) * factor
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    74
                not_null = True
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    75
        if not not_null:
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    76
            return None
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    77
        if negative is not None:
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    78
            microseconds = -microseconds
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    79
        return datetime.timedelta(microseconds=microseconds)
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    80
    
722714c04dcd Adding support for displaying and forcing TIME variables according to IEC 61131 literal format
laurent
parents: 516
diff changeset
    81
    else: 
516
40290ddff19c Initial TIME support in forcing
Edouard Tisserant
parents: 479
diff changeset
    82
        return None
40290ddff19c Initial TIME support in forcing
Edouard Tisserant
parents: 479
diff changeset
    83
525
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    84
def getdate(v):
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    85
    result = IEC_DATE_MODEL.match(v.upper())
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    86
    if result is not None:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    87
        year, month, day = result.groups()
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    88
        try:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    89
            date = datetime.datetime(int(year), int(month), int(day))
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    90
        except ValueError, e:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    91
            return None
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    92
        base_date = datetime.datetime(1970, 1, 1)
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    93
        return date - base_date
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    94
    else: 
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    95
        return None
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    96
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    97
def getdatetime(v):
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    98
    result = IEC_DATETIME_MODEL.match(v.upper())
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
    99
    if result is not None:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   100
        year, month, day, hours, minutes, seconds = result.groups()
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   101
        try:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   102
            date = datetime.datetime(int(year), int(month), int(day), int(hours), int(minutes), int(float(seconds)), int((float(second) * SECOND) % SECOND))
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   103
        except ValueError, e:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   104
            return None
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   105
        base_date = datetime.datetime(1970, 1, 1)
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   106
        return date - base_date
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   107
    else: 
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   108
        return None
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   109
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   110
def gettimeofday(v):
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   111
    result = IEC_TIMEOFDAY_MODEL.match(v.upper())
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   112
    if result is not None:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   113
        hours, minutes, seconds = result.groups()
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   114
        microseconds = 0
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   115
        for value, factor in [(hours, HOUR),
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   116
                              (minutes, MINUTE),
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   117
                              (seconds, SECOND)]:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   118
            microseconds += float(value) * factor
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   119
        return datetime.timedelta(microseconds=microseconds)
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   120
    else:
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   121
        return None
516
40290ddff19c Initial TIME support in forcing
Edouard Tisserant
parents: 479
diff changeset
   122
536
288324dddfb8 Adding '0' and '1' as possible value to force boolean variables
laurent
parents: 525
diff changeset
   123
GetTypeValue = {"BOOL": lambda x: {"TRUE": True, "FALSE": False, "0": False, "1": True}.get(x.upper(), None),
475
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   124
                "SINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   125
                "INT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   126
                "DINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   127
                "LINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   128
                "USINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   129
                "UINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   130
                "UDINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   131
                "ULINT": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   132
                "BYTE": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   133
                "WORD": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   134
                "DWORD": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   135
                "LWORD": getinteger,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   136
                "REAL": getfloat,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   137
                "LREAL": getfloat,
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   138
                "STRING": getstring,
516
40290ddff19c Initial TIME support in forcing
Edouard Tisserant
parents: 479
diff changeset
   139
                "WSTRING": getstring,
525
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   140
                "TIME": gettime,
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   141
                "DATE": getdate,
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   142
                "DT": getdatetime,
e8d5ab0855d3 Adding support for debugging and forcing DATE, DT and TOD in Beremiz interface
laurent
parents: 519
diff changeset
   143
                "TOD": gettimeofday}
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   144
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   145
#-------------------------------------------------------------------------------
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   146
#                            Force Variable Dialog
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   147
#-------------------------------------------------------------------------------
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   148
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   149
class ForceVariableDialog(wx.TextEntryDialog):
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   150
479
2fab0eefa66e Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
laurent
parents: 476
diff changeset
   151
    def __init__(self, parent, iec_type, defaultValue=""):
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   152
        wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), 
747
f36838792511 Update list of messages to be translated for internationalization and french translations
Laurent Bessard
parents: 732
diff changeset
   153
                caption = _("Please enter value for a \"%s\" variable:") % iec_type, defaultValue = defaultValue, 
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   154
                style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition)
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   155
        
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   156
        self.IEC_Type = iec_type 
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   157
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   158
        self.Bind(wx.EVT_BUTTON, self.OnOK, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   159
              self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton())
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   160
        
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   161
    def OnOK(self, event):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   162
        message = None
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   163
        value = self.GetSizer().GetItem(1).GetWindow().GetValue()
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   164
        if value == "":
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   165
            message = _("You must type a value!")
475
9ca03fdff80f ForceVariableDialog return a python value instead of string
laurent
parents: 469
diff changeset
   166
        elif GetTypeValue[self.IEC_Type](value) is None:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   167
            message = _("Invalid value \"%s\" for \"%s\" variable!") % (value, self.IEC_Type)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   168
        if message is not None:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   169
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   170
            dialog.ShowModal()
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   171
            dialog.Destroy()
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   172
        else:
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   173
            self.EndModal(wx.ID_OK)
732
7991eb6bcb5a Fix bug with dialogs inherited from TextEntryDialog
Laurent Bessard
parents: 714
diff changeset
   174
        event.Skip()
469
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   175
17411b970353 Adding support for forcing PLC variable in Viewer
laurent
parents:
diff changeset
   176
    def GetValue(self):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 564
diff changeset
   177
        return GetTypeValue[self.IEC_Type](wx.TextEntryDialog.GetValue(self))