author | laurent |
Mon, 07 Nov 2011 10:55:17 +0100 | |
changeset 585 | bd8c7a033b17 |
parent 584 | c04e7af597d9 |
child 714 | 131ea7f237b9 |
permissions | -rw-r--r-- |
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 |
|
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
29 |
MICROSECONDS = 0.001 |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
30 |
MILLISECONDS = 1 |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
31 |
SECOND = 1000 |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
32 |
MINUTE = 60 * SECOND |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
33 |
HOUR = 60 * MINUTE |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
34 |
DAY = 24 * HOUR |
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 |
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
|
37 |
|
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 |
# Edit Duration Value Dialog |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
40 |
#------------------------------------------------------------------------------- |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
41 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
42 |
[ID_DURATIONEDITORDIALOG, ID_DURATIONEDITORDIALOGDAYSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
43 |
ID_DURATIONEDITORDIALOGDAYS, ID_DURATIONEDITORDIALOGHOURSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
44 |
ID_DURATIONEDITORDIALOGHOURS, ID_DURATIONEDITORDIALOGMINUTESLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
45 |
ID_DURATIONEDITORDIALOGMINUTES, ID_DURATIONEDITORDIALOGSECONDSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
46 |
ID_DURATIONEDITORDIALOGSECONDS, ID_DURATIONEDITORDIALOGMILLISECONDSLABEL, |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
47 |
ID_DURATIONEDITORDIALOGMILLISECONDS, ID_DURATIONEDITORDIALOGMICROSECONDSLABEL, |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
48 |
ID_DURATIONEDITORDIALOGMICROSECONDS, |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
49 |
] = [wx.NewId() for _init_ctrls in range(13)] |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
50 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
51 |
class DurationEditorDialog(wx.Dialog): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
52 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
53 |
if wx.VERSION < (2, 6, 0): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
54 |
def Bind(self, event, function, id = None): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
55 |
if id is not None: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
56 |
event(self, id, function) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
57 |
else: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
58 |
event(self, function) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
59 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
60 |
def _init_coll_MainSizer_Items(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
64 |
def _init_coll_MainSizer_Growables(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
65 |
parent.AddGrowableCol(0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
66 |
parent.AddGrowableRow(0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
67 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
68 |
def _init_coll_ControlsSizer_Items(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
parent.AddWindow(self.MillisecondsLabel, 0, border=0, flag=wx.GROW) |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
74 |
parent.AddWindow(self.MicrosecondsLabel, 0, border=0, flag=wx.GROW) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
parent.AddWindow(self.Milliseconds, 0, border=0, flag=wx.GROW) |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
80 |
parent.AddWindow(self.Microseconds, 0, border=0, flag=wx.GROW) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
81 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
82 |
def _init_coll_ControlsSizer_Growables(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
83 |
parent.AddGrowableCol(0) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
84 |
parent.AddGrowableCol(1) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
85 |
parent.AddGrowableCol(2) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
86 |
parent.AddGrowableCol(3) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
87 |
parent.AddGrowableCol(4) |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
88 |
parent.AddGrowableCol(5) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
89 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
90 |
def _init_sizers(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
91 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
92 |
self.ControlsSizer = wx.FlexGridSizer(cols=6, hgap=10, rows=2, vgap=10) |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
93 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
94 |
self._init_coll_MainSizer_Items(self.MainSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
95 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
96 |
self._init_coll_ControlsSizer_Items(self.ControlsSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
97 |
self._init_coll_ControlsSizer_Growables(self.ControlsSizer) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
98 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
99 |
self.SetSizer(self.MainSizer) |
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 |
def _init_ctrls(self, prnt): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
102 |
wx.Dialog.__init__(self, id=ID_DURATIONEDITORDIALOG, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
103 |
name='DurationEditorDialog', parent=prnt, |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
104 |
size=wx.Size(700, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
105 |
title=_('Edit Duration')) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
106 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
107 |
self.DaysLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGDAYSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
108 |
label=_('Days:'), name='DaysLabel', parent=self, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
109 |
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
|
110 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
116 |
self.HoursLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGHOURSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
117 |
label=_('Hours:'), name='HoursLabel', parent=self, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
118 |
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
|
119 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
125 |
self.MinutesLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGMINUTESLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
126 |
label=_('Minutes:'), name='MinutesLabel', parent=self, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
127 |
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
|
128 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
134 |
self.SecondsLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGSECONDSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
135 |
label=_('Seconds:'), name='SecondsLabel', parent=self, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
136 |
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
|
137 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
143 |
self.MillisecondsLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGMILLISECONDSLABEL, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
144 |
label=_('Milliseconds:'), name='MillisecondsLabel', parent=self, |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
145 |
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
|
146 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
|
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
152 |
self.MicrosecondsLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGMICROSECONDSLABEL, |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
153 |
label=_('Microseconds:'), name='MicrosecondsLabel', parent=self, |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
154 |
pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
155 |
|
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
156 |
self.Microseconds = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGMICROSECONDS, value='0', |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
157 |
name='Microseconds', parent=self, pos=wx.Point(0, 0), |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
158 |
size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER) |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
159 |
self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Milliseconds), id=ID_DURATIONEDITORDIALOGMICROSECONDS) |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
160 |
|
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
161 |
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
|
162 |
if wx.VERSION >= (2, 5, 0): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
163 |
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
|
164 |
else: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
165 |
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
|
166 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
167 |
self._init_sizers() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
168 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
169 |
def __init__(self, parent): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
170 |
self._init_ctrls(parent) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
171 |
|
577
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
564
diff
changeset
|
172 |
self.Days.SetFocus() |
9dbb79722fbc
Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents:
564
diff
changeset
|
173 |
|
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
174 |
def SetDuration(self, value): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
175 |
result = IEC_TIME_MODEL.match(value.upper()) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
176 |
if result is not None: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
177 |
values = result.groups() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
178 |
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
|
179 |
(self.Minutes, 3), (self.Seconds, 4)]: |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
180 |
value = values[index] |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
181 |
if value is not None: |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
182 |
control.SetValue(value) |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
183 |
else: |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
184 |
control.SetValue("0") |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
185 |
milliseconds = values[5] |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
186 |
if milliseconds is not None: |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
187 |
self.Milliseconds.SetValue("%d" % int(float(milliseconds))) |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
188 |
self.Microseconds.SetValue("%.3f" % ((float(milliseconds) % MILLISECONDS) / MICROSECONDS)) |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
189 |
else: |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
190 |
self.Milliseconds.SetValue("0") |
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
191 |
self.Microseconds.SetValue("0") |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
192 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
193 |
def GetControlValueTestFunction(self, control): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
194 |
def OnValueChanged(event): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
195 |
try: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
196 |
value = float(control.GetValue()) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
197 |
except ValueError, e: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
198 |
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
|
199 |
message.ShowModal() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
200 |
message.Destroy() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
201 |
event.Skip() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
202 |
return OnValueChanged |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
203 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
204 |
def GetDuration(self): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
205 |
milliseconds = 0 |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
206 |
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
|
207 |
(self.Minutes, MINUTE), (self.Seconds, SECOND), |
584
c04e7af597d9
Adding support for directly defining microsecond value in DurationEditorDialog
laurent
parents:
577
diff
changeset
|
208 |
(self.Milliseconds, MILLISECONDS), (self.Microseconds, MICROSECONDS)]: |
564
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
209 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
210 |
milliseconds += float(control.GetValue()) * factor |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
211 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
212 |
not_null = False |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
213 |
duration = "T#" |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
214 |
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
|
215 |
((int(milliseconds) % DAY) / HOUR, "%dh"), |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
216 |
((int(milliseconds) % HOUR) / MINUTE, "%dm"), |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
217 |
((int(milliseconds) % MINUTE) / SECOND, "%ds")]: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
218 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
219 |
if value > 0 or not_null: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
220 |
duration += format % value |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
221 |
not_null = True |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
222 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
223 |
duration += "%gms" % (milliseconds % SECOND) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
224 |
return duration |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
225 |
|
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
226 |
def OnOK(self, event): |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
227 |
errors = [] |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
228 |
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
|
229 |
(self.Minutes, "minutes"), (self.Seconds, "seconds"), |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
230 |
(self.Milliseconds, "milliseconds")]: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
231 |
try: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
232 |
value = float(control.GetValue()) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
233 |
except ValueError, e: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
234 |
errors.append(name) |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
235 |
if len(errors) > 0: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
236 |
if len(errors) == 1: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
237 |
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
|
238 |
else: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
239 |
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
|
240 |
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
|
241 |
dialog.ShowModal() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
242 |
dialog.Destroy() |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
243 |
else: |
5024d42e1050
Adding custom cell editor for interval value in task informations of ResourceEditor
laurent
parents:
diff
changeset
|
244 |
self.EndModal(wx.ID_OK) |