Simplify WinSearch usage

As there is auto-completion, there is no more need to automaticaly fill the
field with unique matching result.

issue4006
review13511002
This commit is contained in:
Cédric Krier committed 2014-09-18 19:10:42 +02:00
1 parent 8316c17406
commit 7b1e3d71f6
5 files changed
+37 -146

No files matched your search

@@ -369,16 +369,8 @@ class DictWidget(Widget):
def _sig_add(self, *args):
context = self.field.context_get(self.record)
value = self.wid_text.get_text()
value = self.wid_text.get_text().decode('utf-8')
domain = self.field.domain_get(self.record)
dom = [('rec_name', 'ilike', '%%%s%%' % value)] if value else []
dom.append(('id', 'not in',
[self.keys[f]['id'] for f in self.fields]))
try:
ids = RPCExecute('model', self.schema_model, 'search',
domain + dom, 0, CONFIG['client.limit'], None, context=context)
except RPCException:
return False
def callback(result):
if result:
@@ -395,11 +387,9 @@ class DictWidget(Widget):
self.add_line(new_field['name'])
self.wid_text.set_text('')
if len(ids) != 1:
WinSearch(self.schema_model, callback, sel_multi=True, ids=ids,
context=context, domain=domain, new=False)
else:
callback([(id, None) for id in ids])
win = WinSearch(self.schema_model, callback, sel_multi=True,
context=context, domain=domain, new=False)
win.screen.search_filter(value)
def _sig_remove(self, button, key, modified=True):
del self.fields[key]
@@ -6,10 +6,8 @@ from tryton.gui.window.view_form.screen import Screen
from .widget import Widget
from tryton.gui.window.win_search import WinSearch
from tryton.gui.window.win_form import WinForm
from tryton.config import CONFIG
import tryton.common as common
import gettext
from tryton.common import RPCExecute, RPCException
from tryton.common.placeholder_entry import PlaceholderEntry
from tryton.common.completion import get_completion, update_completion
@@ -138,7 +136,7 @@ class Many2Many(Widget):
widget.modify_text(gtk.STATE_INSENSITIVE,
self.colors['text_color_insensitive'])
def _sig_add(self, *args, **kwargs):
def _sig_add(self, *args):
if not self.focus_out:
return
domain = self.field.domain_get(self.record)
@@ -146,19 +144,9 @@ class Many2Many(Widget):
if add_remove:
domain = [domain, add_remove]
context = self.field.context_get(self.record)
value = self.wid_text.get_text()
value = self.wid_text.get_text().decode('utf-8')
self.focus_out = False
try:
if value:
dom = [('rec_name', 'ilike', '%' + value + '%'), domain]
else:
dom = domain
ids = RPCExecute('model', self.attrs['relation'], 'search',
dom, 0, CONFIG['client.limit'], None, context=context)
except RPCException:
self.focus_out = True
return False
def callback(result):
self.focus_out = True
@@ -168,14 +156,12 @@ class Many2Many(Widget):
self.screen.display(res_id=ids[0])
self.screen.set_cursor()
self.wid_text.set_text('')
if len(ids) != 1 or not value or kwargs.get('win_search', False):
WinSearch(self.attrs['relation'], callback, sel_multi=True,
ids=ids, context=context, domain=domain,
view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}),
new=self.attrs.get('create', True))
else:
callback([(i, None) for i in ids])
win = WinSearch(self.attrs['relation'], callback, sel_multi=True,
context=context, domain=domain,
view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}),
new=self.attrs.get('create', True))
win.screen.search_filter(value)
def _sig_remove(self, *args):
self.screen.remove(remove=True)
@@ -269,7 +255,7 @@ class Many2Many(Widget):
def _completion_action_activated(self, completion, index):
if index == 0:
self._sig_add(win_search=True)
self._sig_add()
self.wid_text.grab_focus()
elif index == 1:
model = self.attrs['relation']
@@ -9,9 +9,7 @@ import tryton.common as common
from tryton.gui.window.view_form.screen import Screen
from tryton.gui.window.win_search import WinSearch
from tryton.gui.window.win_form import WinForm
from tryton.config import CONFIG
from tryton.common.popup_menu import populate
from tryton.common import RPCExecute, RPCException
from tryton.common.completion import get_completion, update_completion
from tryton.common.entry_position import manage_entry_position
@@ -132,27 +130,7 @@ class Many2One(Widget):
self.record)['required'])):
domain = self.field.domain_get(self.record)
context = self.field.context_get(self.record)
self.wid_text.grab_focus()
try:
if self.wid_text.get_text():
dom = [('rec_name', 'ilike',
'%' + self.wid_text.get_text() + '%'),
domain]
else:
dom = domain
ids = RPCExecute('model', model, 'search', dom, 0,
CONFIG['client.limit'], None, context=context)
except RPCException:
self.focus_out = True
self.changed = True
return
if len(ids) == 1:
self.field.set_client(self.record,
self.value_from_id(ids[0]), force_change=True)
self.focus_out = True
self.changed = True
return
text = self.wid_text.get_text().decode('utf-8')
def callback(result):
if result:
@@ -163,11 +141,12 @@ class Many2One(Widget):
self.focus_out = True
self.changed = True
WinSearch(model, callback, sel_multi=False,
ids=ids, context=context, domain=domain,
win = WinSearch(model, callback, sel_multi=False,
context=context, domain=domain,
view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}),
new=self.create_access)
win.screen.search_filter(text)
return
self.focus_out = True
self.changed = True
@@ -224,26 +203,7 @@ class Many2One(Widget):
elif model and not self._readonly:
domain = self.field.domain_get(self.record)
context = self.field.context_get(self.record)
self.wid_text.grab_focus()
try:
if self.wid_text.get_text():
dom = [('rec_name', 'ilike',
'%' + self.wid_text.get_text() + '%'),
domain]
else:
dom = domain
ids = RPCExecute('model', model, 'search', dom, 0,
CONFIG['client.limit'], None, context=context)
except RPCException:
self.focus_out = True
self.changed = True
return False
if len(ids) == 1:
self.field.set_client(self.record, self.value_from_id(ids[0]),
force_change=True)
self.focus_out = True
return True
text = self.wid_text.get_text().decode('utf-8')
def callback(result):
if result:
@@ -251,11 +211,12 @@ class Many2One(Widget):
self.value_from_id(*result[0]), force_change=True)
self.focus_out = True
self.changed = True
WinSearch(model, callback, sel_multi=False,
ids=ids, context=context, domain=domain,
win = WinSearch(model, callback, sel_multi=False,
context=context, domain=domain,
view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}),
new=self.create_access)
win.screen.search_filter(text)
return
self.focus_out = True
self.changed = True
@@ -7,9 +7,7 @@ from .widget import Widget
from tryton.gui.window.view_form.screen import Screen
from tryton.gui.window.win_search import WinSearch
from tryton.gui.window.win_form import WinForm
from tryton.config import CONFIG
import tryton.common as common
from tryton.common import RPCExecute, RPCException
from tryton.common.placeholder_entry import PlaceholderEntry
from tryton.common.completion import get_completion, update_completion
@@ -384,7 +382,7 @@ class One2Many(Widget):
def _sig_undelete(self, button):
self.screen.unremove()
def _sig_add(self, *args, **kwargs):
def _sig_add(self, *args):
if not self.focus_out:
return
access = common.MODELACCESS[self.screen.model_name]
@@ -395,20 +393,10 @@ class One2Many(Widget):
context = self.field.context_get(self.record)
domain = [domain, self.record.expr_eval(self.attrs.get('add_remove'))]
removed_ids = self.field.get_removed_ids(self.record)
domain = ['OR', domain, ('id', 'in', removed_ids)]
text = self.wid_text.get_text().decode('utf-8')
self.focus_out = False
try:
if self.wid_text.get_text():
dom = [('rec_name', 'ilike',
'%' + self.wid_text.get_text() + '%'),
['OR', domain, ('id', 'in', removed_ids)]]
else:
dom = ['OR', domain, ('id', 'in', removed_ids)]
ids = RPCExecute('model', self.attrs['relation'], 'search', dom,
0, CONFIG['client.limit'], None, context=context)
except RPCException:
self.focus_out = True
return False
sequence = None
if self.screen.current_view.view_type == 'tree':
@@ -425,14 +413,12 @@ class One2Many(Widget):
self.screen.set_cursor()
self.wid_text.set_text('')
if len(ids) != 1 or kwargs.get('win_search', False):
WinSearch(self.attrs['relation'], callback, sel_multi=True,
ids=ids, context=context, domain=domain,
view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}),
new=self.but_new.get_property('sensitive'))
else:
callback([(i, None) for i in ids])
win = WinSearch(self.attrs['relation'], callback, sel_multi=True,
context=context, domain=domain,
view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}),
new=self.but_new.get_property('sensitive'))
win.screen.search_filter(text)
def _sig_label(self, screen, signal_data):
self._position = signal_data[0]
@@ -511,7 +497,7 @@ class One2Many(Widget):
def _completion_action_activated(self, completion, index):
if index == 0:
self._sig_add(win_search=True)
self._sig_add()
self.wid_text.grab_focus()
elif index == 1:
self._sig_new()
@@ -28,10 +28,8 @@ from tryton.common.cellrendererbinary import CellRendererBinary
from tryton.common.cellrendererclickablepixbuf import \
CellRendererClickablePixbuf
from tryton.translate import date_format
from tryton.common import RPCExecute, RPCException
from tryton.common.completion import get_completion, update_completion
from tryton.common.selection import SelectionMixin, PopdownMixin
from tryton.config import CONFIG
_ = gettext.gettext
@@ -528,22 +526,8 @@ class M2O(Char):
relation = record[self.attrs['name']].attrs['relation']
domain = record[self.attrs['name']].domain_get(record)
context = record[self.attrs['name']].context_get(record)
dom = [('rec_name', 'ilike', '%' + text + '%'), domain]
try:
ids = RPCExecute('model', relation, 'search', dom, 0, None, None,
context=context)
except RPCException:
field.set_client(record, (None, ''))
if callback:
callback()
return
if len(ids) != 1:
self.search_remote(record, relation, ids, domain=domain,
context=context, callback=callback)
return
field.set_client(record, ids[0])
if callback:
callback()
self.search_remote(record, relation, text, domain=domain,
context=context, callback=callback)
def open_remote(self, record, create=True, changed=False, text=None,
callback=None):
@@ -563,24 +547,7 @@ class M2O(Char):
elif not changed:
obj_id = field.get(record)
else:
if text:
dom = [('rec_name', 'ilike', '%' + text + '%'), domain]
else:
dom = domain
try:
ids = RPCExecute('model', relation, 'search', dom, 0,
CONFIG['client.limit'], None, context=context)
except RPCException:
field.set_client(record, False)
if callback:
callback()
return
if len(ids) == 1:
field.set_client(record, ids[0])
if callback:
callback()
return
self.search_remote(record, relation, ids, domain=domain,
self.search_remote(record, relation, text, domain=domain,
context=context, callback=callback)
return
screen = Screen(relation, domain=domain, context=context,
@@ -599,7 +566,7 @@ class M2O(Char):
else:
WinForm(screen, open_callback, new=True, save_current=True)
def search_remote(self, record, relation, ids=None, domain=None,
def search_remote(self, record, relation, text, domain=None,
context=None, callback=None):
field = record.group.fields[self.attrs['name']]
@@ -610,8 +577,9 @@ class M2O(Char):
field.set_client(record, value)
if callback:
callback()
WinSearch(relation, search_callback, sel_multi=False, ids=ids,
win = WinSearch(relation, search_callback, sel_multi=False,
context=context, domain=domain)
win.screen.search_filter(text.decode('utf-8'))
def set_completion(self, entry, path):
if entry.get_completion():