bugfix with shortcuts
[openerp-client.git] / bin / modules / gui / window / view_tree / view_tree_sc.py
blob2523fd0b6e2b0532339c2891cc71390b9bdaf5cc
1 ##############################################################################
3 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 # $Id$
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
12 # Service Company
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 ##############################################################################
30 import rpc
31 import gobject
32 import gtk
34 import gettext
35 import service
37 class view_tree_sc(object):
38 def __init__(self, tree, model):
39 self.model = model
40 self.tree = tree
41 self.tree.get_selection().set_mode('single')
42 column = gtk.TreeViewColumn (_('ID'), gtk.CellRendererText(), text=0)
43 self.tree.append_column(column)
44 column.set_visible(False)
45 cell = gtk.CellRendererText()
47 column = gtk.TreeViewColumn (_('Description'), cell, text=1)
48 self.tree.append_column(column)
49 self.update()
51 def update(self):
52 store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
53 uid = rpc.session.uid
54 sc = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.ui.view_sc', 'get_sc', uid, self.model, rpc.session.context) or []
55 for s in sc:
56 num = store.append()
57 store.set(num, 0, s['res_id'], 1, s['name'], 2, s['id'])
58 self.tree.set_model(store)
59 if self.model == 'ir.ui.menu':
60 service.LocalService('gui.main').shortcut_set(sc)
62 def remove(self, id):
63 self.update()
64 def add(self, id):
65 self.update()
67 def value_get(self, col):
68 sel = self.tree.get_selection().get_selected()
69 if not sel:
70 return None
71 (model, iter) = sel
72 if not iter:
73 return None
74 return model.get_value(iter, col)
76 def sel_id_get(self):
77 res = self.value_get(0)
78 res = eval(str(res))
79 if res:
80 return int(res[0])
81 return None
83 def serv_update(self, ids, action):
84 if (action==2):
85 self.update()