dialogs/DurationEditorDialog.py
author Laurent Bessard
Mon, 25 Jun 2012 23:10:49 +0200
changeset 715 6a3792a6bf7b
parent 714 131ea7f237b9
permissions -rw-r--r--
Fix bugs on Debug Variable Panel after splitting it from PLCOpenEditor.py
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     3
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     6
#
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     8
#
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    10
#
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    15
#
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    19
#General Public License for more details.
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    20
#
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    24
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    25
import re
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    26
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    27
import wx
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    28
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    29
#-------------------------------------------------------------------------------
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    30
#                                  Helpers
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    31
#-------------------------------------------------------------------------------
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    32
584
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
    33
MICROSECONDS = 0.001
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
    34
MILLISECONDS = 1
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    35
SECOND = 1000
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    36
MINUTE = 60 * SECOND
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    37
HOUR = 60 * MINUTE
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    38
DAY = 24 * HOUR
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    39
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    40
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]+)?"})
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    41
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    42
CONTROLS = [
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    43
    ("Days", _('Days:')),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    44
    ("Hours", _('Hours:')),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    45
    ("Minutes", _('Minutes:')),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    46
    ("Seconds", _('Seconds:')),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    47
    ("Milliseconds", _('Milliseconds:')),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    48
    ("Microseconds", _('Microseconds:')),
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    49
]
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    50
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    51
#-------------------------------------------------------------------------------
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    52
#                         Edit Duration Value Dialog
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    53
#-------------------------------------------------------------------------------
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    54
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    55
class DurationEditorDialog(wx.Dialog):
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    56
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    57
    def __init__(self, parent):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    58
        wx.Dialog.__init__(self, parent, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    59
              size=wx.Size(700, 200), title=_('Edit Duration'))
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    60
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    61
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    62
        main_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    63
        main_sizer.AddGrowableRow(0)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    64
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    65
        controls_sizer = wx.FlexGridSizer(cols=len(CONTROLS), hgap=10, rows=2, vgap=10)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    66
        main_sizer.AddSizer(controls_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    67
              flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    68
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    69
        controls = []
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    70
        for i, (name, label) in enumerate(CONTROLS):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    71
            controls_sizer.AddGrowableCol(i)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    72
            
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    73
            st = wx.StaticText(self, label=label)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    74
            txtctrl = wx.TextCtrl(self, value='0', style=wx.TE_PROCESS_ENTER)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    75
            self.Bind(wx.EVT_TEXT_ENTER, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    76
                      self.GetControlValueTestFunction(txtctrl), 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    77
                      txtctrl)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    78
            setattr(self, name, txtctrl)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    79
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    80
            controls.append((st, txtctrl))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    81
            
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    82
        for st, txtctrl in controls:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    83
            controls_sizer.AddWindow(st, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    84
            
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    85
        for st, txtctrl in controls:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    86
            controls_sizer.AddWindow(txtctrl, flag=wx.GROW)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    87
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    88
        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    89
        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    90
        main_sizer.AddSizer(button_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    91
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    92
        
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 584
diff changeset
    93
        self.SetSizer(main_sizer)
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    94
        
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 564
diff changeset
    95
        self.Days.SetFocus()
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 564
diff changeset
    96
        
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    97
    def SetDuration(self, value):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    98
        result = IEC_TIME_MODEL.match(value.upper())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    99
        if result is not None:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   100
            values = result.groups()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   101
            for control, index in [(self.Days, 1), (self.Hours, 2),
584
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   102
                                   (self.Minutes, 3), (self.Seconds, 4)]:
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   103
                value = values[index]
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   104
                if value is not None:
584
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   105
                    control.SetValue(value)
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   106
                else:
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   107
                    control.SetValue("0")
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   108
            milliseconds = values[5]
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   109
            if milliseconds is not None:
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   110
                self.Milliseconds.SetValue("%d" % int(float(milliseconds)))
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   111
                self.Microseconds.SetValue("%.3f" % ((float(milliseconds) % MILLISECONDS) / MICROSECONDS))
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   112
            else:
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   113
                self.Milliseconds.SetValue("0")
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   114
                self.Microseconds.SetValue("0")
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   115
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   116
    def GetControlValueTestFunction(self, control):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   117
        def OnValueChanged(event):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   118
            try:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   119
                value = float(control.GetValue())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   120
            except ValueError, e:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   121
                message = wx.MessageDialog(self, _("Invalid value!\nYou must fill a numeric value."), _("Error"), wx.OK|wx.ICON_ERROR)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   122
                message.ShowModal()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   123
                message.Destroy()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   124
            event.Skip()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   125
        return OnValueChanged
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   126
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   127
    def GetDuration(self):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   128
        milliseconds = 0
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   129
        for control, factor in [(self.Days, DAY), (self.Hours, HOUR),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   130
                                (self.Minutes, MINUTE), (self.Seconds, SECOND),
584
c04e7af597d9 Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents: 577
diff changeset
   131
                                (self.Milliseconds, MILLISECONDS), (self.Microseconds, MICROSECONDS)]:
564
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   132
            
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   133
            milliseconds += float(control.GetValue()) * factor
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   134
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   135
        not_null = False
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   136
        duration = "T#"
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   137
        for value, format in [(int(milliseconds) / DAY, "%dd"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   138
                            ((int(milliseconds) % DAY) / HOUR, "%dh"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   139
                            ((int(milliseconds) % HOUR) / MINUTE, "%dm"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   140
                            ((int(milliseconds) % MINUTE) / SECOND, "%ds")]:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   141
            
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   142
            if value > 0 or not_null:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   143
                duration += format % value
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   144
                not_null = True
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   145
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   146
        duration += "%gms" % (milliseconds % SECOND)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   147
        return duration
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   148
    
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   149
    def OnOK(self, event):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   150
        errors = []
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   151
        for control, name in [(self.Days, "days"), (self.Hours, "hours"), 
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   152
                              (self.Minutes, "minutes"), (self.Seconds, "seconds"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   153
                              (self.Milliseconds, "milliseconds")]:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   154
            try:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   155
                value = float(control.GetValue())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   156
            except ValueError, e:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   157
                errors.append(name)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   158
        if len(errors) > 0:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   159
            if len(errors) == 1:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   160
                message = _("Field %s hasn't a valid value!") % errors[0]
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   161
            else:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   162
                message = _("Fields %s haven't a valid value!") % ",".join(errors)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   163
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   164
            dialog.ShowModal()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   165
            dialog.Destroy()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   166
        else:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   167
            self.EndModal(wx.ID_OK)