Adding support for directly defining microsecond value in DurationEditorDialog
authorlaurent
Fri, 04 Nov 2011 10:59:12 +0100
changeset 584 c04e7af597d9
parent 583 3f3f9b25ff9f
child 585 bd8c7a033b17
Adding support for directly defining microsecond value in DurationEditorDialog
dialogs/DurationEditorDialog.py
--- a/dialogs/DurationEditorDialog.py	Thu Nov 03 23:38:23 2011 +0100
+++ b/dialogs/DurationEditorDialog.py	Fri Nov 04 10:59:12 2011 +0100
@@ -26,6 +26,8 @@
 
 import wx
 
+MICROSECONDS = 0.001
+MILLISECONDS = 1
 SECOND = 1000
 MINUTE = 60 * SECOND
 HOUR = 60 * MINUTE
@@ -42,8 +44,9 @@
  ID_DURATIONEDITORDIALOGHOURS, ID_DURATIONEDITORDIALOGMINUTESLABEL,
  ID_DURATIONEDITORDIALOGMINUTES, ID_DURATIONEDITORDIALOGSECONDSLABEL, 
  ID_DURATIONEDITORDIALOGSECONDS, ID_DURATIONEDITORDIALOGMILLISECONDSLABEL,
- ID_DURATIONEDITORDIALOGMILLISECONDS,
-] = [wx.NewId() for _init_ctrls in range(11)]
+ ID_DURATIONEDITORDIALOGMILLISECONDS, ID_DURATIONEDITORDIALOGMICROSECONDSLABEL,
+ ID_DURATIONEDITORDIALOGMICROSECONDS, 
+] = [wx.NewId() for _init_ctrls in range(13)]
 
 class DurationEditorDialog(wx.Dialog):
     
@@ -68,11 +71,13 @@
         parent.AddWindow(self.MinutesLabel, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.SecondsLabel, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.MillisecondsLabel, 0, border=0, flag=wx.GROW)
+        parent.AddWindow(self.MicrosecondsLabel, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.Days, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.Hours, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.Minutes, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.Seconds, 0, border=0, flag=wx.GROW)
         parent.AddWindow(self.Milliseconds, 0, border=0, flag=wx.GROW)
+        parent.AddWindow(self.Microseconds, 0, border=0, flag=wx.GROW)
         
     def _init_coll_ControlsSizer_Growables(self, parent):
         parent.AddGrowableCol(0)
@@ -80,10 +85,11 @@
         parent.AddGrowableCol(2)
         parent.AddGrowableCol(3)
         parent.AddGrowableCol(4)
+        parent.AddGrowableCol(5)
 
     def _init_sizers(self):
         self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
-        self.ControlsSizer = wx.FlexGridSizer(cols=5, hgap=10, rows=2, vgap=10)
+        self.ControlsSizer = wx.FlexGridSizer(cols=6, hgap=10, rows=2, vgap=10)
         
         self._init_coll_MainSizer_Items(self.MainSizer)
         self._init_coll_MainSizer_Growables(self.MainSizer)
@@ -95,7 +101,7 @@
     def _init_ctrls(self, prnt):
         wx.Dialog.__init__(self, id=ID_DURATIONEDITORDIALOG, 
               name='DurationEditorDialog', parent=prnt,  
-              size=wx.Size(600, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
+              size=wx.Size(700, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
               title=_('Edit Duration'))
         
         self.DaysLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGDAYSLABEL,
@@ -143,6 +149,15 @@
               size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
         self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Milliseconds), id=ID_DURATIONEDITORDIALOGMILLISECONDS)
         
+        self.MicrosecondsLabel = wx.StaticText(id=ID_DURATIONEDITORDIALOGMICROSECONDSLABEL,
+              label=_('Microseconds:'), name='MicrosecondsLabel', parent=self,
+              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
+        
+        self.Microseconds = wx.TextCtrl(id=ID_DURATIONEDITORDIALOGMICROSECONDS, value='0',
+              name='Microseconds', parent=self, pos=wx.Point(0, 0),
+              size=wx.Size(0, 24), style=wx.TE_PROCESS_ENTER)
+        self.Bind(wx.EVT_TEXT_ENTER, self.GetControlValueTestFunction(self.Milliseconds), id=ID_DURATIONEDITORDIALOGMICROSECONDS)
+        
         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
         if wx.VERSION >= (2, 5, 0):
             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
@@ -161,11 +176,19 @@
         if result is not None:
             values = result.groups()
             for control, index in [(self.Days, 1), (self.Hours, 2),
-                                   (self.Minutes, 3), (self.Seconds, 4),
-                                   (self.Milliseconds, 5)]:
+                                   (self.Minutes, 3), (self.Seconds, 4)]:
                 value = values[index]
                 if value is not None:
-                    control.SetValue(str(value))
+                    control.SetValue(value)
+                else:
+                    control.SetValue("0")
+            milliseconds = values[5]
+            if milliseconds is not None:
+                self.Milliseconds.SetValue("%d" % int(float(milliseconds)))
+                self.Microseconds.SetValue("%.3f" % ((float(milliseconds) % MILLISECONDS) / MICROSECONDS))
+            else:
+                self.Milliseconds.SetValue("0")
+                self.Microseconds.SetValue("0")
         
     def GetControlValueTestFunction(self, control):
         def OnValueChanged(event):
@@ -182,7 +205,7 @@
         milliseconds = 0
         for control, factor in [(self.Days, DAY), (self.Hours, HOUR),
                                 (self.Minutes, MINUTE), (self.Seconds, SECOND),
-                                (self.Milliseconds, 1)]:
+                                (self.Milliseconds, MILLISECONDS), (self.Microseconds, MICROSECONDS)]:
             
             milliseconds += float(control.GetValue()) * factor