1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
##############################################################################
40
from widget.screen import Screen
45
from modules.gui.window.win_search import win_search
47
class many2many(interface.widget_interface):
48
def __init__(self, window, parent, model, attrs={}):
49
interface.widget_interface.__init__(self, window, parent, model, attrs)
51
self.widget = gtk.VBox(homogeneous=False, spacing=1)
53
hb = gtk.HBox(homogeneous=False, spacing=3)
54
self.wid_text = gtk.Entry()
55
self.wid_text.set_property('width_chars', 13)
56
self.wid_text.connect('activate', self._sig_activate)
57
self.wid_text.connect('button_press_event', self._menu_open)
58
hb.pack_start(self.wid_text, expand=True, fill=True)
60
hb.pack_start(gtk.VSeparator(), padding=2, expand=False, fill=False)
62
self.wid_but_add = gtk.Button(stock='gtk-add')
63
self.wid_but_add.set_relief(gtk.RELIEF_HALF)
64
self.wid_but_add.set_focus_on_click(True)
65
self.wid_but_add.connect('clicked', self._sig_add)
66
hb.pack_start(self.wid_but_add, padding=3, expand=False, fill=False)
68
self.wid_but_remove = gtk.Button(stock='gtk-remove')
69
self.wid_but_remove.set_relief(gtk.RELIEF_HALF)
70
self.wid_but_remove.set_focus_on_click(True)
71
self.wid_but_remove.connect('clicked', self._sig_remove)
72
hb.pack_start(self.wid_but_remove, expand=False, fill=False)
74
self.widget.pack_start(hb, expand=False, fill=False)
75
self.widget.pack_start(gtk.HSeparator(), expand=False, fill=True)
77
scroll = gtk.ScrolledWindow()
78
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
79
scroll.set_placement(gtk.CORNER_TOP_LEFT)
80
scroll.set_shadow_type(gtk.SHADOW_NONE)
82
self.screen = Screen(attrs['relation'], view_type=['tree'])
83
scroll.add_with_viewport(self.screen.widget)
84
self.widget.pack_start(scroll, expand=True, fill=True)
93
def _menu_sig_default_set(self):
94
self.set_value(self._view.modelfield)
95
return super(many2many, self)._menu_sig_default_set()
97
def _menu_sig_default(self, obj):
98
res = rpc.session.rpc_exec_auth('/object', 'execute', self.attrs['model'], 'default_get', [self.attrs['name']])
99
self.value = res.get(self.attrs['name'], False)
101
def _sig_add(self, *args):
102
domain = self._view.modelfield.domain_get(self._view.model)
103
context = self._view.modelfield.context_get(self._view.model)
105
ids = rpc.session.rpc_exec_auth('/object', 'execute', self.attrs['relation'], 'name_search', self.wid_text.get_text(), domain, 'ilike', context)
106
ids = map(lambda x: x[0], ids)
108
win = win_search(self.attrs['relation'], sel_multi=True, ids=ids, context=context, domain=domain, parent=self._window)
111
self.screen.load(ids)
112
self.screen.display()
113
self.wid_text.set_text('')
115
def _sig_remove(self, *args):
117
self.screen.display()
119
def _sig_activate(self, *args):
122
def _readonly_set(self, ro):
123
self.wid_text.set_editable(not ro)
124
self.wid_text.set_sensitive(not ro)
125
self.wid_but_remove.set_sensitive(not ro)
126
self.wid_but_add.set_sensitive(not ro)
128
def display(self, model, model_field):
129
super(many2many, self).display(model, model_field)
132
ids = model_field.get_client(model)
135
self.screen.load(ids)
137
self.screen.display()
140
def set_value(self, model, model_field):
141
model_field.set_client(model, [x.id for x in self.screen.models.models])