Allow to have string for digits that will be evalutate with the record values.

This commit is contained in:
Cédric Krier committed 2008-07-28 18:09:37 +02:00
1 parent 1471b6150e
commit b0eaf37427
6 files changed
+29 -8

No files matched your search

+5 -1
View File
@@ -171,8 +171,12 @@ class FloatField(CharField):
def set_client(self, model, value, test_state=True, force_change=False):
internal = model.value[self.name]
self.set(model, value, test_state)
if isinstance(self.attrs.get('digits'), str):
digits = model.expr_eval(self.attrs['digits'])
else:
digits = self.attrs.get('digits', (12, 2))
if abs(float(internal or 0.0) - float(model.value[self.name] or 0.0)) \
>= (10.0**(-int(self.attrs.get('digits', (12,4))[1]))):
>= (10.0**(-int(digits[1]))):
if not self.get_state_attrs(model).get('readonly', False):
model.modified = True
model.modified_fields.setdefault(self.name)
@@ -23,7 +23,11 @@ class Float(Integer):
if not model_field:
self.entry.set_text('')
return False
self.entry.set_text(locale.format('%.' + str(self.digits[1]) + 'f',
if isinstance(self.digits, str):
digits = self._view.model.expr_eval(self.digits)
else:
digits = self.digits
self.entry.set_text(locale.format('%.' + str(digits[1]) + 'f',
model_field.get(model) or 0.0, True))
def sig_insert_text(self, entry, new_text, new_text_length, position):
+1
View File
@@ -441,6 +441,7 @@ class ViewList(ParserView):
#self.widget.set_cursor(None,None,False)
if self.store:
self.widget_tree.set_model(self.store)
self.widget_tree.queue_draw()
self.set_state()
self.update_children()
@@ -171,8 +171,12 @@ class ParserTree(ParserInterface):
label.set_markup(label_str)
label_sum = gtk.Label()
label_sum.set_use_markup(True)
dict_widget[i] = (fname, label, label_sum,
fields.get('digits', (16,2))[1], label_bold)
if isinstance(fields.get('digits'), str):
digits = 2
else:
digits = fields.get('digits', (16, 2))[1]
dict_widget[i] = (fname, label, label_sum, digits,
label_bold)
if not bool(int(attrs.get('fill', '0'))):
col = gtk.TreeViewColumn()
col.name = None
@@ -347,7 +351,10 @@ class Datetime(Date):
class Float(Char):
def get_textual_value(self, model):
digit = self.attrs.get('digits', (16, 2))[1]
if isinstance(self.attrs.get('digits'), str):
digit = model.expr_eval(self.attrs['digits'])[1]
else:
digit = self.attrs.get('digits', (16, 2))[1]
return locale.format('%.'+str(digit)+'f',
model[self.field_name].get_client(model) or 0.0, True)
@@ -10,7 +10,10 @@ class Float(Integer):
def __init__(self, name, parent, attrs=None):
super(Float, self).__init__(name, parent, attrs=attrs)
self.digits = attrs.get('digits', (14, 2))
if isinstance(attrs.get('digits'), str):
self.digits = (14, 2)
else:
self.digits = attrs.get('digits', (14, 2))
def _value_get(self):
try:
+4 -2
View File
@@ -134,9 +134,11 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
selection = []
self.fields_type[field]['selection'] = selection
elif field_type in ('float', 'numeric'):
digit = self.fields_type[field].get('digits', (16, 2))[1]
digits = self.fields_type[field].get('digits', (16, 2))
if isinstance(digits, str):
digits = eval(digits, obj)
for obj in res_ids:
obj[field] = locale.format('%.' + str(digit) + 'f',
obj[field] = locale.format('%.' + str(digits[1]) + 'f',
obj[field] or 0.0, True)
elif field_type in ('interger',):
for obj in res_ids: