openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #04561
[Merge] lp:~openerp-dev/openobject-client/trunk-locale-datefield-tfr into lp:openobject-client
tfr (Openerp) has proposed merging lp:~openerp-dev/openobject-client/trunk-locale-datefield-tfr into lp:openobject-client.
Requested reviews:
OpenERP sa GTK client R&D (openerp-dev-gtk)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client/trunk-locale-datefield-tfr/+merge/54668
--
https://code.launchpad.net/~openerp-dev/openobject-client/trunk-locale-datefield-tfr/+merge/54668
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-client/trunk-locale-datefield-tfr.
=== modified file 'bin/widget/view/form_gtk/calendar.py'
--- bin/widget/view/form_gtk/calendar.py 2011-01-12 12:44:53 +0000
+++ bin/widget/view/form_gtk/calendar.py 2011-03-24 09:57:52 +0000
@@ -85,7 +85,7 @@
return True
def get_value(self, model):
- str = self.entry.get_text()
+ str = self.entry.get_value()
if str == '':
return False
try:
@@ -112,9 +112,7 @@
return False
super(calendar, self).display(model, model_field)
value = model_field.get(model)
- if not value:
- self.entry.clear()
- else:
+ if value:
if len(value) >= (len(DT_FORMAT) + 2):
value=value[:len(DT_FORMAT) + 2]
date = DT.strptime(value[:len(DT_FORMAT) + 2], DT_FORMAT)
@@ -211,7 +209,7 @@
return True
def get_value(self, model, timezone=True):
- str = self.entry.get_text()
+ str = self.entry.get_value()
if str=='':
return False
return tools.datetime_util.local_to_server_timestamp(str[:self.fmt_length], self.format, DHM_FORMAT,
@@ -231,9 +229,7 @@
self.set_datetime(model_field.get(model))
def set_datetime(self, dt_val, timezone=True):
- if not dt_val:
- self.entry.clear()
- else:
+ if dt_val:
t = tools.datetime_util.server_to_local_timestamp(dt_val[:len(DHM_FORMAT) + 2],
DHM_FORMAT, self.format, tz_offset=timezone)
if len(t) > self.entry.get_width_chars():
@@ -319,7 +315,7 @@
return self.entry.grab_focus()
def get_value(self, model):
- str = self.entry.get_text()
+ str = self.entry.get_value()
if str=='':
res = False
try:
=== modified file 'bin/widget/view/form_gtk/date_widget.py'
--- bin/widget/view/form_gtk/date_widget.py 2011-01-31 10:08:03 +0000
+++ bin/widget/view/form_gtk/date_widget.py 2011-03-24 09:57:52 +0000
@@ -72,13 +72,14 @@
"""If format string doesn't contain
any of the `%Y, %m or %d` then returns default datetime format `%Y/%m/%d`
"""
- for x,y in [('%y','%Y'),('%B','%m'),('%A',''), ('%I','%H'), ('%p',''), ('%j',''), ('%a',''), ('%b',''),
+ for x,y in [('%y','%Y'),('%B','%m'),('%A',''), ('%I','%H'), ('%p',''), ('%j',''), ('%a',''), ('%b','%m'),
('%U',''), ('%W','')]:
fmt = fmt.replace(x, y)
- if (not (fmt.count('%Y') >= 1 and fmt.count('%m') >= 1 and fmt.count('%d') >= 1) or fmt.count('%x') >= 1) and (fmt.count('%H') == 0 and fmt.count('%M') == 0 and fmt.count('%S') == 0 and fmt.count('%X') == 0):
-
+ if (not (fmt.count('%Y') >= 1 and fmt.count('%m') >= 1 and fmt.count('%d') >= 1) or fmt.count('%x') >= 1) \
+ and (fmt.count('%H') == 0 and fmt.count('%M') == 0 and fmt.count('%S') == 0 and fmt.count('%X') == 0):
return '%Y/%m/%d'
+
elif not (fmt.count('%Y') >= 1 and fmt.count('%m') >= 1 and fmt.count('%d') >= 1) \
or (fmt.count('%x') >=1 or fmt.count('%c') >= 1):
return '%Y/%m/%d %H:%M:%S'
@@ -169,14 +170,30 @@
def set_text(self, text):
self._interactive_input = False
try:
+ self.set_max_length(len(text))
gtk.Entry.set_text(self, text)
date = self.isvalid_date(text);
if(date):
self.small_text = date.strftime(self.small_format)
+ elif(text==self.initial_value):
+ self.small_text = self.initial_value
finally:
self._interactive_input = True
+ def get_text(self):
+ date = self.isvalid_date(self.small_text)
+ if(date and not self.is_focus()):
+ return date.strftime(self.format)
+ return gtk.Entry.get_text(self)
+
+
+ def get_value(self):
+ date = self.isvalid_date(self.small_text)
+ if(date):
+ return date.strftime(self.format)
+ return gtk.Entry.get_text(self)
+
def date_set(self, dt):
if dt:
self.set_text( dt.strftime(self.format) )
=== modified file 'bin/widget_search/date_widget.py'
--- bin/widget_search/date_widget.py 2011-01-31 14:48:39 +0000
+++ bin/widget_search/date_widget.py 2011-03-24 09:57:52 +0000
@@ -19,15 +19,18 @@
#
##############################################################################
+
import gobject
import pango
import gtk
import re
import tools
+from datetime import datetime
import tools.datetime_util
import time
+
class DateEntry(gtk.Entry):
def __init__(self, format, callback=None, callback_process=None):
super(DateEntry, self).__init__()
@@ -69,13 +72,14 @@
"""If format string doesn't contain
any of the `%Y, %m or %d` then returns default datetime format `%Y/%m/%d`
"""
- for x,y in [('%y','%Y'),('%B','%m'),('%A',''), ('%I','%H'), ('%p',''), ('%j',''), ('%a',''), ('%b',''),
+ for x,y in [('%y','%Y'),('%B','%m'),('%A',''), ('%I','%H'), ('%p',''), ('%j',''), ('%a',''), ('%b','%m'),
('%U',''), ('%W','')]:
fmt = fmt.replace(x, y)
- if (not (fmt.count('%Y') >= 1 and fmt.count('%m') >= 1 and fmt.count('%d') >= 1) or fmt.count('%x') >= 1) and (fmt.count('%H') == 0 and fmt.count('%M') == 0 and fmt.count('%S') == 0 and fmt.count('%X') == 0):
-
+ if (not (fmt.count('%Y') >= 1 and fmt.count('%m') >= 1 and fmt.count('%d') >= 1) or fmt.count('%x') >= 1) \
+ and (fmt.count('%H') == 0 and fmt.count('%M') == 0 and fmt.count('%S') == 0 and fmt.count('%X') == 0):
return '%Y/%m/%d'
+
elif not (fmt.count('%Y') >= 1 and fmt.count('%m') >= 1 and fmt.count('%d') >= 1) \
or (fmt.count('%x') >=1 or fmt.count('%c') >= 1):
return '%Y/%m/%d %H:%M:%S'
@@ -166,14 +170,30 @@
def set_text(self, text):
self._interactive_input = False
try:
+ self.set_max_length(len(text))
gtk.Entry.set_text(self, text)
date = self.isvalid_date(text);
if(date):
self.small_text = date.strftime(self.small_format)
+ elif(text==self.initial_value):
+ self.small_text = self.initial_value
finally:
self._interactive_input = True
+ def get_text(self):
+ date = self.isvalid_date(self.small_text)
+ if(date and not self.is_focus()):
+ return date.strftime(self.format)
+ return gtk.Entry.get_text(self)
+
+
+ def get_value(self):
+ date = self.isvalid_date(self.small_text)
+ if(date):
+ return date.strftime(self.format)
+ return gtk.Entry.get_text(self)
+
def date_set(self, dt):
if dt:
self.set_text( dt.strftime(self.format) )
@@ -252,9 +272,6 @@
self.pack_start(self.widget, expand=True, fill=True)
self.pack_start(self.widget_cmd, expand=False, fill=True)
- def clear(self):
- self.widget.clear()
-
def _date_cb(self, event):
if event.keyval in (gtk.keysyms.BackSpace,):
text = self.widget_cmd.get_text()[:-1]
@@ -286,6 +303,9 @@
pass
self.widget_cmd.set_text('')
self.widget_cmd.hide()
+
+ def clear(self):
+ self.widget.clear()
if __name__ == '__main__':
import sys
Follow ups