dabo Commit
Revision 3205
Date: 2007-06-22 16:10:41 -0700 (Fri, 22 Jun 2007)
Author: Dj
Trac: http://svn.dabodev.com/trac/dabo/changeset/3205

Changed:
U   dj/dabo/ui/uiwx/dDateTextBox.py

Log:
Applied Ticket #1038

Diff:
Modified: dj/dabo/ui/uiwx/dDateTextBox.py
===================================================================
--- dj/dabo/ui/uiwx/dDateTextBox.py     2007-06-22 22:33:11 UTC (rev 3204)
+++ dj/dabo/ui/uiwx/dDateTextBox.py     2007-06-22 23:10:41 UTC (rev 3205)
@@ -2,6 +2,7 @@
 import re
 import locale
 import datetime
+from time import strptime
 import wx
 import dabo
 if __name__ == "__main__":
@@ -84,10 +85,14 @@
                # Do we display datetimes in 24-hour clock, or with AM/PM?
                self.ampm = False
 
+               #Set The default format
+               self._format = '%Y-%m-%d'
+               self._timeValue = datetime.datetime.now()
 
+
        def afterInit(self):
                self._baseClass = dDateTextBox
-               self.Value = datetime.date.today()
+               self.DateValue = self._timeValue
                if self.showCalButton:
                        # Create a button that will display the calendar
                        self.calButton = dButton(self.Parent, 
Size=(self.Height, self.Height),
@@ -125,9 +130,9 @@
        def showCalendar(self):
                availHt = self.Parent.Bottom - self.Bottom
                try:
-                       self.calPanel.cal.Date = self.Value
+                       self.calPanel.cal.Date = self.DateValue
                except:
-                       self.calPanel = CalPanel(self.Parent, dt=self.Value, 
ctrl=self)
+                       self.calPanel = CalPanel(self.Parent, 
dt=self.DateValue, ctrl=self)
                cp = self.calPanel
                cp.Position = (self.Left, self.Bottom)
                if self.Bottom + cp.Height > self.Parent.Bottom:
@@ -185,7 +190,7 @@
                                        # They've just finished typing a new 
date, or are just
                                        # positioned on the field. Either way, 
update the stored
                                        # date to make sure they are in sync.
-                                       self.Value = valDt
+                                       self.DateValue = valDt
                                        evt.Continue = False
                                if adjust:
                                        self.adjustDate(key, ctrl, shift)
@@ -203,12 +208,12 @@
 
 
        def __onLostFocus(self, evt):
-               val = self.Value
+               val = self.DateValue
                try:
                        newVal = self.strToDate(self.GetValue())
                        if newVal != val:
-                               self.Value = newVal
-               except: pass
+                               self.DateValue = newVal
+               except Exception, e: print e
 
 
        def adjustDate(self, key, ctrl=False, shift=False):
@@ -216,7 +221,7 @@
                shortcut keys.
                """
                # Save the original value for comparison
-               orig = self.Value.toordinal()
+               orig = self.DateValue.toordinal()
                # Default direction
                forward = True
                # Flag to indicate errors in date processing
@@ -224,16 +229,16 @@
                # Flag to indicate if we consider boundary conditions
                checkBoundary = True
                # Are we working with dates or datetimes
-               isDateTime = isinstance(self.Value, datetime.datetime)
+               isDateTime = isinstance(self.DateValue, datetime.datetime)
                # Did the key move to a boundary?
                toBoundary = False
 
                if key == "t":
                        # Today
                        if isDateTime:
-                               self.Value = datetime.datetime.now()
+                               self.DateValue = datetime.datetime.now()
                        else:
-                               self.Value = datetime.date.today()
+                               self.DateValue = datetime.date.today()
                elif key == "+":
                        # Forward 1 day
                        self.dayInterval(1)
@@ -254,7 +259,7 @@
                                        return
                        else:
                                # First day of month
-                               self.Value = self.Value.replace(day=1)
+                               self.DateValue = self.DateValue.replace(day=1)
                                forward = False
                                toBoundary = True
                elif key == "h":
@@ -285,12 +290,12 @@
                                return
                elif key == "y":
                        # First day of year
-                       self.Value = self.Value.replace(month=1, day=1)
+                       self.DateValue = self.DateValue.replace(month=1, day=1)
                        forward = False
                        toBoundary = True
                elif key == "r":
                        # Last day of year
-                       self.Value = self.Value.replace(month=12, day=31)
+                       self.DateValue = self.DateValue.replace(month=12, 
day=31)
                        toBoundary = True
                elif key == "[":
                        # Back one month
@@ -305,13 +310,13 @@
                        checkBoundary = False
                else:
                        # This shouldn't happen, because onChar would have 
filtered it out.
-                       dabo.logInfo("Warning in dDateTextBox.adjustDate: %s 
key sent." % key)
+                       dabo.infoLog.write("Warning in dDateTextBox.adjustDate: 
%s key sent." % key)
                        return
 
                if not self.dateOK:
                        return
                if toBoundary and checkBoundary and self.continueAtBoundary:
-                       if self.Value.toordinal() == orig:
+                       if self.DateValue.toordinal() == orig:
                                # Date hasn't changed; means we're at the 
boundary
                                # (first or last of the chosen interval). Move 
1 day in
                                # the specified direction, then re-apply the key
@@ -326,37 +331,37 @@
                """Adjusts the date by the given number of hours; negative
                values move backwards.
                """
-               self.Value += datetime.timedelta(hours=hours)
+               self.DateValue += datetime.timedelta(hours=hours)
 
 
        def minuteInterval(self, minutes):
                """Adjusts the date by the given number of minutes; negative
                values move backwards.
                """
-               self.Value += datetime.timedelta(minutes=minutes)
+               self.DateValue += datetime.timedelta(minutes=minutes)
 
 
        def secondInterval(self, seconds):
                """Adjusts the date by the given number of seconds; negative
                values move backwards.
                """
-               self.Value += datetime.timedelta(seconds=seconds)
+               self.DateValue += datetime.timedelta(seconds=seconds)
 
 
        def dayInterval(self, days):
                """Adjusts the date by the given number of days; negative
                values move backwards.
                """
-               self.Value += datetime.timedelta(days)
+               self.DateValue += datetime.timedelta(days)
 
 
        def monthInterval(self, months):
                """Adjusts the date by the given number of months; negative
                values move backwards.
                """
-               mn = self.Value.month + months
-               yr = self.Value.year
-               dy = self.Value.day
+               mn = self.DateValue.month + months
+               yr = self.DateValue.year
+               dy = self.DateValue.day
                while mn < 1:
                        yr -= 1
                        mn += 12
@@ -367,23 +372,23 @@
                ok = False
                while not ok:
                        try:
-                               self.Value = self.Value.replace(year=yr, 
month=mn, day=dy)
+                               self.DateValue = 
self.DateValue.replace(year=yr, month=mn, day=dy)
                                ok = True
                        except:
                                dy -= 1
 
 
        def setToLastMonthDay(self):
-               mn = self.Value.month
+               mn = self.DateValue.month
                td = datetime.timedelta(1)
-               while mn == self.Value.month:
-                       self.Value += td
+               while mn == self.DateValue.month:
+                       self.DateValue += td
                # We're now at the first of the next month. Go back one.
-               self.Value -= td
+               self.DateValue -= td
 
 
        def getDateTuple(self):
-               dt = self.Value
+               dt = self.DateValue
                return (dt.year, dt.month, dt.day )
 
 
@@ -391,13 +396,13 @@
                """Sets the Value to the passed date if this is holding a date 
value, or
                sets the date portion of the Value if it is a datetime.
                """
-               val = self.Value
+               val = self.GetValue()
                if isinstance(val, datetime.datetime):
-                       self.Value = val.replace(year=dt.year, month=dt.month, 
day=dt.day)
+                       self.DateValue = val.replace(year=dt.year, 
month=dt.month, day=dt.day)
                elif isinstance(val, basestring):
-                       self.Value = self.strToDate(dt)
+                       self.DateValue = self.strToDate(dt)
                else:
-                       self.Value = dt
+                       self.DateValue = dt
 
 
        def strToDate(self, val, testing=False):
@@ -451,7 +456,16 @@
                        day = int(day)
                else:
                        # See if there is a time component
+                       passed = False
                        try:
+                               (year, month, day, hr, mn, sec) = strptime(val, 
self.Format)[0:6]
+                               isDateTime = True
+                               passed = True
+                       except ValueError:
+                               passed = False
+
+                       if not passed:
+                       try:
                                (dt, tm) = val.split()
                                (hr, mn, sec) = tm.split(":")
                                hr = int(hr)
@@ -477,7 +491,7 @@
                                if not testing:
                                        # Don't fill up the logs with error 
messages from tests that
                                        # are expected to fail.
-                                       dabo.logError(_("Invalid datetime 
specified: %s") % val )
+                                       dabo.errorLog.write(_("Invalid datetime 
specified: %s") % val )
                                ret = None
                else:
                        try:
@@ -486,12 +500,42 @@
                                if not testing:
                                        # Don't fill up the logs with error 
messages from tests that
                                        # are expected to fail.
-                                       dabo.logError(_("Invalid date 
specified: %s") % val )
+                                       dabo.errorLog.write(_("Invalid date 
specified: %s") % val )
                                ret = None
                return ret
 
+       def _getFormat(self):
+               return self._format
 
+       def _setFormat(self, val):
+               try:
+                       datetime.date.today().strftime(val)
+                       self._format = val
+               except Exception, e:
+                       #Error is the format is invalid
+                       print e
 
+       def _getDateValue(self):
+               return self._timeValue
+
+       def _setDateValue(self, val):
+               self._timeValue = val
+               self.Value = self._timeValue.strftime(self.Format)
+
+       def _getValue(self):
+               self.Value = self._timeValue.strftime(self.Format)
+               return self._timeValue
+
+       def _setValue(self, val):
+               self.SetValue(val)
+
+       Format = property(_getFormat, _setFormat, None)
+       DateValue = property(_getDateValue, _setDateValue, None)
+       Value = property(_getValue, _setValue, None)
+
+       DynamicFormat = makeDynamicProperty(Format)
+       DynamicDateValue = makeDynamicProperty(DateValue)
+
 if __name__ == "__main__":
        import test
        test.Test().runTest(dDateTextBox)




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to