Fix Selection with domain to allow internal value that doesn't respect the
domain for issue1303 (transplanted from 1827c031c69ae080fe45889f507ba30d1b805fa2)
This commit is contained in:
1 parent
22e93e271a
commit
b15ea49f78
2 files changed
+21
-7
No files matched your search
@@ -30,7 +30,8 @@ class Selection(WidgetInterface):
|
||||
self.widget.set_focus_chain([child])
|
||||
|
||||
self._selection = {}
|
||||
selection = attrs.get('selection', [])
|
||||
selection = attrs.get('selection', [])[:]
|
||||
self.selection = selection[:]
|
||||
if 'relation' in attrs:
|
||||
try:
|
||||
result = rpc.execute('model',
|
||||
@@ -41,6 +42,7 @@ class Selection(WidgetInterface):
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self._window)
|
||||
selection = []
|
||||
self.selection = selection[:]
|
||||
else:
|
||||
if not isinstance(selection, (list, tuple)):
|
||||
try:
|
||||
@@ -49,6 +51,7 @@ class Selection(WidgetInterface):
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self._window)
|
||||
selection = []
|
||||
self.selection = selection[:]
|
||||
|
||||
for dom in common.filter_domain(attrs.get('domain', [])):
|
||||
if dom[1] in ('=', '!='):
|
||||
@@ -64,7 +67,6 @@ class Selection(WidgetInterface):
|
||||
|
||||
if attrs.get('sort', True):
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
attrs['selection'] = selection
|
||||
self.set_popdown(selection)
|
||||
self.last_key = (None, 0)
|
||||
|
||||
@@ -150,6 +152,16 @@ class Selection(WidgetInterface):
|
||||
child.set_text(long_text)
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
for sel_value, long_text in self.selection:
|
||||
if str(sel_value) == str(value):
|
||||
self._selection[long_text] = sel_value
|
||||
model = self.entry.get_model()
|
||||
i = model.append()
|
||||
model.set(i, 0, long_text)
|
||||
child.set_text(long_text)
|
||||
found = True
|
||||
break
|
||||
self.changed = True
|
||||
|
||||
def display_value(self):
|
||||
|
||||
@@ -680,7 +680,8 @@ class Selection(Char):
|
||||
super(Selection, self).__init__(*args)
|
||||
self.renderer = CellRendererCombo()
|
||||
selection_data = gtk.ListStore(str, str)
|
||||
selection = self.attrs.get('selection', [])
|
||||
selection = self.attrs.get('selection', [])[:]
|
||||
self.selection = selection[:]
|
||||
if 'relation' in self.attrs:
|
||||
try:
|
||||
result = rpc.execute('model',
|
||||
@@ -691,6 +692,7 @@ class Selection(Char):
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
selection = []
|
||||
self.selection = selection[:]
|
||||
else:
|
||||
if not isinstance(selection, (list, tuple)):
|
||||
try:
|
||||
@@ -699,6 +701,7 @@ class Selection(Char):
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
selection = []
|
||||
self.selection = selection[:]
|
||||
|
||||
for dom in common.filter_domain(self.attrs.get('domain', [])):
|
||||
if dom[1] in ('=', '!='):
|
||||
@@ -714,9 +717,8 @@ class Selection(Char):
|
||||
|
||||
if self.attrs.get('sort', True):
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
self.attrs['selection'] = selection
|
||||
self.selection = selection
|
||||
for i in self.selection:
|
||||
self._selection = selection
|
||||
for i in selection:
|
||||
selection_data.append(i)
|
||||
self.renderer.set_property('model', selection_data)
|
||||
self.renderer.set_property('text-column', 1)
|
||||
@@ -729,7 +731,7 @@ class Selection(Char):
|
||||
|
||||
def value_from_text(self, model, text):
|
||||
res = False
|
||||
for val, txt in self.selection:
|
||||
for val, txt in self._selection:
|
||||
if txt[:len(text)].lower() == text.lower():
|
||||
if len(txt) == len(text):
|
||||
return val
|
||||
|
||||
Reference in new issue
Block a user