~openerp-dev/openobject-client/6.0-opw-595350-rgo

« back to all changes in this revision

Viewing changes to bin/modules/gui/window/win_selection.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-56e9b555eeb500d42202250a3456cfa2a6dc78c7
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
import gtk
 
30
from gtk import glade
 
31
import gettext
 
32
import common
 
33
 
 
34
from view_tree import parse
 
35
import gobject
 
36
import rpc
 
37
 
 
38
fields_list_type = {
 
39
        'checkbox': gobject.TYPE_BOOLEAN
 
40
}
 
41
 
 
42
#
 
43
# Should be replaced by win_browse
 
44
#
 
45
 
 
46
class win_selection_class(object):
 
47
        def __init__(self, ids, model, view=None):
 
48
                self.glade = glade.XML(common.terp_path("terp.glade"), "win_selection",gettext.textdomain())
 
49
                self.win = self.glade.get_widget('win_selection')
 
50
 
 
51
                self.ids = ids
 
52
                self.view = self.glade.get_widget('win_sel_tree')
 
53
                self.view.get_selection().set_mode('single')
 
54
                if view==None:
 
55
                        fields = { 'name': {'type': 'char', 'string':_('Name')} }
 
56
                        xml = '''<?xml version="1.0"?>
 
57
<tree string="%s">
 
58
        <field name="name" string="%s"></field>
 
59
</tree>''' % (_('Ressource Name'), _('Names'))
 
60
                else:
 
61
                        fields = None
 
62
                        xml = None
 
63
 
 
64
                p = parse.parse(fields)
 
65
                p.parse(xml, self.view)
 
66
                self.view.set_expander_column(self.view.get_column(1))
 
67
                self.fields_order = p.fields_order
 
68
 
 
69
                types=[ gobject.TYPE_STRING ]
 
70
                for x in self.fields_order:
 
71
                        types.append( fields_list_type.get(fields[x]['type'], gobject.TYPE_STRING))
 
72
                self.model = gtk.ListStore(*types)
 
73
 
 
74
                if view==None:
 
75
                        res_ids = rpc.session.rpc_exec_auth('/object', 'execute', model, 'name_get', self.ids, rpc.session.context)
 
76
                        for res in res_ids:
 
77
                                num = self.model.append()
 
78
                                self.model.set(num, 0, res[0], 1, res[1])
 
79
                else:
 
80
                        pass # Todo
 
81
 
 
82
                self.view.set_model(self.model)
 
83
                self.view.show_all()
 
84
 
 
85
        def id_name_get(self):
 
86
                id = self.value_get(0)
 
87
                if id:
 
88
                        return (id, self.value_get(1))
 
89
                return None
 
90
 
 
91
        def value_get(self, col):
 
92
                sel = self.view.get_selection().get_selected()
 
93
                if sel==None:
 
94
                        return None
 
95
                (model, iter) = sel
 
96
                return model.get_value(iter, col)
 
97
 
 
98
        def go(self):
 
99
                button = self.win.run()
 
100
                if button==gtk.RESPONSE_OK:
 
101
                        res = self.id_name_get()
 
102
                else:
 
103
                        res=None
 
104
                self.win.destroy()
 
105
                return res
 
106
 
 
107
def win_selection_h(from_resource, ids, model, view=None):
 
108
        return win_selection(ids, model, view)
 
109
 
 
110
def win_selection(ids, model, view=None):
 
111
        if len(ids)==1:
 
112
                return rpc.session.rpc_exec_auth('/object', 'execute', model, 'name_get', ids, rpc.session.context)[0]
 
113
        win = win_selection_class(ids, model, view)
 
114
        res = win.go()
 
115
        return res