From 47c8460e11c7c191dce84fa5381eb78b724f17aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 13 Apr 2009 01:33:07 +0200 Subject: [PATCH] Make '0' behaves like '_' in date widget and set next char to '0' if text doesn't match the regexp for issue980 --- tryton/common/date_widget.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tryton/common/date_widget.py b/tryton/common/date_widget.py index 86aae96137..ce30ae6d06 100644 --- a/tryton/common/date_widget.py +++ b/tryton/common/date_widget.py @@ -14,10 +14,9 @@ import mx.DateTime mapping = { '%y': ('__', '([_ 0-9][_ 0-9])'), - '%Y': ('____', '([_ 0-9][_ 0-9][_ 0-9][_ 1-9]|[_ 1-9][_ 0-9][_ 0-9][_ 0-9]|' \ - '[_ 0-9][_ 1-9][_ 0-9][_ 0-9]|[_ 0-9][_ 0-9][_ 1-9][_ 0-9])'), - '%m': ('__', '([_ 0][_ 1-9]|[_ 1][_ 0-2])'), - '%d': ('__', '([_ 0][_ 1-9]|[_ 1-2][_ 0-9]|[_ 3][_ 0-1])'), + '%Y': ('____', '([_ 0-9][_ 0-9][_ 0-9][_ 0-9])'), + '%m': ('__', '([_ 0][_ 0-9]|[_ 1][_ 0-2])'), + '%d': ('__', '([_ 0][_ 0-9]|[_ 1-2][_ 0-9]|[_ 3][_ 0-1])'), '%H': ('__', '([_ 0-1][_ 0-9]|[_ 2][_ 0-4])'), '%M': ('__', '([_ 0-5][_ 0-9]|[_ 6][_ 0])'), '%S': ('__', '([_ 0-5][_ 0-9]|[_ 6][_ 0])'), @@ -87,6 +86,11 @@ class DateEntry(gtk.Entry): if self.regex.match(text): self.set_text(text) gobject.idle_add(self.set_position, pos) + else: + text = text[:pos] + '0' + text[pos + 1:] + if self.regex.match(text): + self.set_text(text) + gobject.idle_add(self.set_position, pos) self.stop_emission('insert-text') self.show() return @@ -159,6 +163,7 @@ class DateEntry(gtk.Entry): n = len(val) val = val.strip() val = val.strip('_') + val = val.strip('0') if not val: continue fchar = '0'