[IMP] Added missing vim mode lines
[odoo/odoo.git] / openerp / addons / base / ir / wizard / wizard_screen.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    Copyright (C) 2010 OpenERP s.a. (<http://www.openerp.com>).
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU Affero General Public License as
8 #    published by the Free Software Foundation, either version 3 of the
9 #    License, or (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU Affero General Public License for more details.
15 #
16 #    You should have received a copy of the GNU Affero General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
18 #
19 ##############################################################################
20 import base64
21 import os
22 import random
23
24 import tools
25 from osv import fields,osv
26
27 # Simple base class for wizards that wish to use random images on the left
28 # side of the form.
29 class wizard_screen(osv.osv_memory):
30     _name = 'ir.wizard.screen'
31
32     def _get_image(self, cr, uid, context=None):
33         path = os.path.join('base','res','config_pixmaps','%d.png'%random.randrange(1,4))
34         image_file = file_data = tools.file_open(path,'rb')
35         try:
36             file_data = image_file.read()
37             return base64.encodestring(file_data)
38         finally:
39             image_file.close()
40
41     def _get_image_fn(self, cr, uid, ids, name, args, context=None):
42         image = self._get_image(cr, uid, context)
43         return dict.fromkeys(ids, image) # ok to use .fromkeys() as the image is same for all 
44
45     _columns = {
46         'config_logo': fields.function(_get_image_fn, string='Image', type='binary', method=True),
47     }
48
49     _defaults = {
50         'config_logo': _get_image
51     }
52 wizard_screen()
53 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: