dialogs/DurationEditorDialog.py
author laurent
Sun, 09 Oct 2011 20:04:35 +0200
changeset 567 eb523c4fa2da
parent 564 5024d42e1050
child 577 9dbb79722fbc
permissions -rw-r--r--
Disable definition of location for directly declared array variables
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
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    29
SECOND = 1000
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    30
MINUTE = 60 * SECOND
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    31
HOUR = 60 * MINUTE
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    32
DAY = 24 * HOUR
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    33
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    34
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
    35
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    36
#-------------------------------------------------------------------------------
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    37
#                         Edit Duration Value Dialog
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    38
#-------------------------------------------------------------------------------
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
[ID_DURATIONEDITORDIALOG, ID_DURATIONEDITORDIALOGDAYSLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    41
 ID_DURATIONEDITORDIALOGDAYS, ID_DURATIONEDITORDIALOGHOURSLABEL, 
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    42
 ID_DURATIONEDITORDIALOGHOURS, ID_DURATIONEDITORDIALOGMINUTESLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    43
 ID_DURATIONEDITORDIALOGMINUTES, ID_DURATIONEDITORDIALOGSECONDSLABEL, 
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    44
 ID_DURATIONEDITORDIALOGSECONDS, ID_DURATIONEDITORDIALOGMILLISECONDSLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    45
 ID_DURATIONEDITORDIALOGMILLISECONDS,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    46
] = [wx.NewId() for _init_ctrls in range(11)]
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    47
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    48
class DurationEditorDialog(wx.Dialog):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    49
    
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    50
    if wx.VERSION < (2, 6, 0):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    51
        def Bind(self, event, function, id = None):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    52
            if id is not None:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    53
                event(self, id, function)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    54
            else:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    55
                event(self, function)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    56
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    57
    def _init_coll_MainSizer_Items(self, parent):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    58
        parent.AddSizer(self.ControlsSizer, 0, border=20, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    59
        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    60
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    61
    def _init_coll_MainSizer_Growables(self, parent):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    62
        parent.AddGrowableCol(0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    63
        parent.AddGrowableRow(0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    64
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    65
    def _init_coll_ControlsSizer_Items(self, parent):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    66
        parent.AddWindow(self.DaysLabel, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    67
        parent.AddWindow(self.HoursLabel, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    68
        parent.AddWindow(self.MinutesLabel, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    69
        parent.AddWindow(self.SecondsLabel, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    70
        parent.AddWindow(self.MillisecondsLabel, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    71
        parent.AddWindow(self.Days, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    72
        parent.AddWindow(self.Hours, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    73
        parent.AddWindow(self.Minutes, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    74
        parent.AddWindow(self.Seconds, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    75
        parent.AddWindow(self.Milliseconds, 0, border=0, flag=wx.GROW)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    76
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    77
    def _init_coll_ControlsSizer_Growables(self, parent):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    78
        parent.AddGrowableCol(0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    79
        parent.AddGrowableCol(1)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    80
        parent.AddGrowableCol(2)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    81
        parent.AddGrowableCol(3)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    82
        parent.AddGrowableCol(4)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    83
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    84
    def _init_sizers(self):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    85
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    86
        self.ControlsSizer = wx.FlexGridSizer(cols=5, hgap=10, rows=2, vgap=10)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    87
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    88
        self._init_coll_MainSizer_Items(self.MainSizer)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    89
        self._init_coll_MainSizer_Growables(self.MainSizer)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    90
        self._init_coll_ControlsSizer_Items(self.ControlsSizer)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    91
        self._init_coll_ControlsSizer_Growables(self.ControlsSizer)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    92
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    93
        self.SetSizer(self.MainSizer)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    94
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    95
    def _init_ctrls(self, prnt):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    96
        wx.Dialog.__init__(self, id=ID_DURATIONEDITORDIALOG, 
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    97
              name='DurationEditorDialog', parent=prnt,  
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    98
              size=wx.Size(600, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
    99
              title=_('Edit Duration'))
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   100
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   101
        self.DaysLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGDAYSLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   102
              label=_('Days:'), name='DaysLabel', parent=self,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   103
              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   104
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   105
        self.Days = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGDAYS, value='0',
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   106
              name='Days', parent=self, pos=wx.Point(0, 0),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   107
              size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   108
        self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Days), id=ID_DURATIONEDITORDIALOGDAYS)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   109
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   110
        self.HoursLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGHOURSLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   111
              label=_('Hours:'), name='HoursLabel', parent=self,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   112
              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   113
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   114
        self.Hours = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGHOURS, value='0',
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   115
              name='Hours', parent=self, pos=wx.Point(0, 0),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   116
              size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   117
        self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Hours), id=ID_DURATIONEDITORDIALOGHOURS)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   118
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   119
        self.MinutesLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGMINUTESLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   120
              label=_('Minutes:'), name='MinutesLabel', parent=self,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   121
              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   122
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   123
        self.Minutes = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGMINUTES, value='0',
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   124
              name='Minutes', parent=self, pos=wx.Point(0, 0),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   125
              size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   126
        self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Minutes), id=ID_DURATIONEDITORDIALOGMINUTES)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   127
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   128
        self.SecondsLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGSECONDSLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   129
              label=_('Seconds:'), name='SecondsLabel', parent=self,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   130
              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   131
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   132
        self.Seconds = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGSECONDS, value='0',
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   133
              name='Seconds', parent=self, pos=wx.Point(0, 0),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   134
              size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   135
        self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Seconds), id=ID_DURATIONEDITORDIALOGSECONDS)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   136
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   137
        self.MillisecondsLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGMILLISECONDSLABEL,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   138
              label=_('Milliseconds:'), name='MillisecondsLabel', parent=self,
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   139
              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   140
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   141
        self.Milliseconds = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGMILLISECONDS, value='0',
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   142
              name='Milliseconds', parent=self, pos=wx.Point(0, 0),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   143
              size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   144
        self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Milliseconds), id=ID_DURATIONEDITORDIALOGMILLISECONDS)
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
        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   147
        if wx.VERSION >= (2, 5, 0):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   148
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   149
        else:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   150
            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   151
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   152
        self._init_sizers()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   153
    
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   154
    def __init__(self, parent):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   155
        self._init_ctrls(parent)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   156
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   157
    def SetDuration(self, value):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   158
        result = IEC_TIME_MODEL.match(value.upper())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   159
        if result is not None:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   160
            values = result.groups()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   161
            for control, index in [(self.Days, 1), (self.Hours, 2),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   162
                                   (self.Minutes, 3), (self.Seconds, 4),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   163
                                   (self.Milliseconds, 5)]:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   164
                value = values[index]
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   165
                if value is not None:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   166
                    control.SetValue(str(value))
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   167
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   168
    def GetControlValueTestFunction(self, control):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   169
        def OnValueChanged(event):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   170
            try:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   171
                value = float(control.GetValue())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   172
            except ValueError, e:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   173
                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
   174
                message.ShowModal()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   175
                message.Destroy()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   176
            event.Skip()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   177
        return OnValueChanged
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   178
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   179
    def GetDuration(self):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   180
        milliseconds = 0
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   181
        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
   182
                                (self.Minutes, MINUTE), (self.Seconds, SECOND),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   183
                                (self.Milliseconds, 1)]:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   184
            
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   185
            milliseconds += float(control.GetValue()) * factor
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   186
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   187
        not_null = False
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   188
        duration = "T#"
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   189
        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
   190
                            ((int(milliseconds) % DAY) / HOUR, "%dh"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   191
                            ((int(milliseconds) % HOUR) / MINUTE, "%dm"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   192
                            ((int(milliseconds) % MINUTE) / SECOND, "%ds")]:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   193
            
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   194
            if value > 0 or not_null:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   195
                duration += format % value
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   196
                not_null = True
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   197
        
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   198
        duration += "%gms" % (milliseconds % SECOND)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   199
        return duration
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   200
    
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   201
    def OnOK(self, event):
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   202
        errors = []
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   203
        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
   204
                              (self.Minutes, "minutes"), (self.Seconds, "seconds"),
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   205
                              (self.Milliseconds, "milliseconds")]:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   206
            try:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   207
                value = float(control.GetValue())
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   208
            except ValueError, e:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   209
                errors.append(name)
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   210
        if len(errors) > 0:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   211
            if len(errors) == 1:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   212
                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
   213
            else:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   214
                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
   215
            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
   216
            dialog.ShowModal()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   217
            dialog.Destroy()
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   218
        else:
5024d42e1050 Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff changeset
   219
            self.EndModal(wx.ID_OK)