dabo Commit
Revision 3881
Date: 2008-01-17 13:48:04 -0800 (Thu, 17 Jan 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/3881
Changed:
U branches/paul/dabo/__init__.py
U branches/paul/dabo/dApp.py
U branches/paul/dabo/lib/dates.py
U branches/paul/dabo/ui/uiwx/dGrid.py
U branches/paul/dabo/ui/uiwx/dTextBoxMixin.py
Log:
Moved the setlocale() call to dApp.__init__, to give a developer a
chance to:
import dabo
dabo.settings.loadUserLocale = False
Followed through, adding datetime support.
Diff:
Modified: branches/paul/dabo/__init__.py
===================================================================
--- branches/paul/dabo/__init__.py 2008-01-17 21:06:03 UTC (rev 3880)
+++ branches/paul/dabo/__init__.py 2008-01-17 21:48:04 UTC (rev 3881)
@@ -102,7 +102,6 @@
import os
import sys
-import locale
try:
import pysqlite2
except ImportError:
@@ -151,9 +150,6 @@
# Import global settings (do this first, as other imports may rely on it):
from settings import *
-if settings.loadUserLocale:
- locale.setlocale(locale.LC_ALL, '')
-
from __version__ import version
import dColors
import dEvents
Modified: branches/paul/dabo/dApp.py
===================================================================
--- branches/paul/dabo/dApp.py 2008-01-17 21:06:03 UTC (rev 3880)
+++ branches/paul/dabo/dApp.py 2008-01-17 21:48:04 UTC (rev 3881)
@@ -157,6 +157,9 @@
def __init__(self, selfStart=False, properties=None, *args, **kwargs):
+ if dabo.settings.loadUserLocale:
+ locale.setlocale(locale.LC_ALL, '')
+
self._uiAlreadySet = False
dabo.dAppRef = self
self._beforeInit()
Modified: branches/paul/dabo/lib/dates.py
===================================================================
--- branches/paul/dabo/lib/dates.py 2008-01-17 21:06:03 UTC (rev 3880)
+++ branches/paul/dabo/lib/dates.py 2008-01-17 21:48:04 UTC (rev 3881)
@@ -150,13 +150,28 @@
return ret
+def getStringFromDateTime(dateTimeVal):
+ """Given a datetime.datetime, convert to string in
dabo.settings.dateTimeFormat style."""
+ dateTimeFormat = dabo.settings.dateTimeFormat
+ if dateTimeFormat is None:
+ # Delegate formatting to the time module, which will take the
+ # user's locale into account.
+ dateTimeFormat = "%x %X"
+ return dateTimeVal.strftime(dateTimeFormat)
+
+
def getDateTimeFromString(strVal, formats=None):
"""Given a string in a defined format, return a datetime object or
None."""
global _dtregex
+ dtFormat = dabo.settings.dateTimeFormat
ret = None
+
if formats is None:
formats = ["ISO8601"]
+
+ if dtFormat is not None:
+ formats.append(dtFormat)
for format in formats:
regex = _dtregex.get(format, None)
@@ -194,7 +209,14 @@
# (Sept. only has 30 days but the regex will
allow 31, etc.)
pass
if ret is not None:
- break
+ break
+ if ret is None:
+ if dtFormat is None:
+ # Fall back to the current locale setting in user's os
account:
+ try:
+ ret = datetime.datetime(*time.strptime(strVal,
"%x %X"))
+ except:
+ pass
return ret
Modified: branches/paul/dabo/ui/uiwx/dGrid.py
===================================================================
--- branches/paul/dabo/ui/uiwx/dGrid.py 2008-01-17 21:06:03 UTC (rev 3880)
+++ branches/paul/dabo/ui/uiwx/dGrid.py 2008-01-17 21:48:04 UTC (rev 3881)
@@ -348,7 +348,9 @@
def getStringValue(self, val):
"""Get the string value to display in the grid."""
- if isinstance(val, datetime.date):
+ if isinstance(val, datetime.datetime):
+ return dabo.lib.dates.getStringFromDateTime(val)
+ elif isinstance(val, datetime.date):
return dabo.lib.dates.getStringFromDate(val)
return val
Modified: branches/paul/dabo/ui/uiwx/dTextBoxMixin.py
===================================================================
--- branches/paul/dabo/ui/uiwx/dTextBoxMixin.py 2008-01-17 21:06:03 UTC (rev
3880)
+++ branches/paul/dabo/ui/uiwx/dTextBoxMixin.py 2008-01-17 21:48:04 UTC (rev
3881)
@@ -509,9 +509,7 @@
# keep it unicode instead of converting to str
strVal = value
elif isinstance(value, datetime.datetime):
- # Use the ISO 8601 datetime string format (with a " "
separator
- # instead of "T")
- strVal = value.isoformat(" ")
+ strVal = dabo.lib.dates.getStringFromDateTime(value)
elif isinstance(value, datetime.date):
strVal = dabo.lib.dates.getStringFromDate(value)
elif isinstance(value, datetime.time):
_______________________________________________
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]