This is the autocompletion patch on the client side

Please review this at http://codereview.appspot.com/4286049/

Affected files:
   M tryton/gui/window/view_form/model/field.py
   M tryton/gui/window/view_form/model/record.py
   M tryton/gui/window/view_form/view/form_gtk/char.py
   M tryton/gui/window/view_form/view/form_gtk/parser.py


Index: tryton/gui/window/view_form/model/field.py
===================================================================

--- a/tryton/gui/window/view_form/model/field.py
+++ b/tryton/gui/window/view_form/model/field.py
@@ -42,6 +42,7 @@
          if self.attrs.get('change_default', False):
              record.cond_default(self.attrs['name'], self.get(record))
          record.on_change_with(self.name)
+        record.autocomplete_with(self.name)

      def domains_get(self, record):
          screen_domain = domain_inversion(record.group.domain,

Index: tryton/gui/window/view_form/model/record.py
===================================================================

--- a/tryton/gui/window/view_form/model/record.py
+++ b/tryton/gui/window/view_form/model/record.py
@@ -35,6 +35,7 @@
          self.attachment_count = -1
          self.next = {} # Used in Group list
          self.value = {}
+        self.autocompletion = {}

      def __getitem__(self, name):
          if name not in self._loaded and self.id > 0:
@@ -438,6 +439,25 @@
                      return
              self.group.fields[fieldname].set_on_change(self, res)

+    def autocomplete_with(self, field_name):
+        for fieldname, fieldinfo in self.group.fields.items():
+            self.autocompletion[fieldname] = []
+            autocomplete = fieldinfo.attrs.get('autocomplete', [])
+            if field_name not in autocomplete:
+                continue
+            args = self._get_on_change_args(autocomplete)
+            ctx = rpc.CONTEXT.copy()
+            ctx.update(self.context_get())
+ args = ('model', self.model_name, 'autocomplete_' + fieldname, args,
+                ctx)
+            try:
+                res = rpc.execute(*args)
+            except Exception, exception:
+ res = common.process_exception(exception, self.window, *args)
+                if not res:
+                    return
+            self.autocompletion[fieldname] = res
+
      def cond_default(self, field_name, value):
          ctx = rpc.CONTEXT.copy()
          ctx.update(self.context_get())

Index: tryton/gui/window/view_form/view/form_gtk/char.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/char.py
+++ b/tryton/gui/window/view_form/view/form_gtk/char.py
@@ -1,6 +1,8 @@
  #This file is part of Tryton.  The COPYRIGHT file at the top level of
  #this repository contains the full copyright notices and license terms.
+import gobject
  import gtk
+
  from interface import WidgetInterface

  class Char(WidgetInterface):
@@ -20,6 +22,13 @@
          self.entry.connect('focus-in-event', lambda x, y: self._focus_in())
self.entry.connect('focus-out-event', lambda x, y: self._focus_out())
          self.widget.pack_start(self.entry)
+        self.autocomplete_fields = attrs['autocomplete']
+        if self.autocomplete_fields:
+            self.completion = gtk.EntryCompletion()
+            self.completion_store = gtk.ListStore(gobject.TYPE_STRING)
+            self.completion.set_model(self.completion_store)
+            self.completion.set_text_column(0)
+            self.entry.set_completion(self.completion)

      def _color_widget(self):
          return self.entry
@@ -32,6 +41,12 @@

      def display(self, record, field):
          super(Char, self).display(record, field)
+        if record and self.autocomplete_fields:
+            self.completion_store.clear()
+            for row in record.autocompletion.get(self.field_name, []):
+                self.completion_store.append((row,))
+        elif self.autocomplete_fields:
+            self.completion_store.clear()
          if not field:
              self.entry.set_text('')
              return False

Index: tryton/gui/window/view_form/view/form_gtk/parser.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/parser.py
+++ b/tryton/gui/window/view_form/view/form_gtk/parser.py
@@ -543,7 +543,8 @@
                      continue
                  for attr_name in ('relation', 'domain', 'selection',
                          'relation_field', 'string', 'views', 'invisible',
-                        'add_remove', 'sort', 'context', 'size', 'filename'):
+                        'add_remove', 'sort', 'context', 'size', 'filename',
+                        'autocomplete'):
                      if attr_name in fields[name].attrs and \
                              not attr_name in attrs:
                          attrs[attr_name] = fields[name].attrs[attr_name]



--
[email protected] mailing list

Reply via email to