3 # Copyright 2014 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # -*- mode: python; encoding: utf-8; -*-
28 class StringForm(BaseForm):
29 def __init__(self, name, value):
37 def set_value(self, value):
40 class OptionsForm(BaseForm):
41 def __init__(self, name, options, value):
44 self.options = options
46 self.index = self.find_index()
48 return map(lambda x: x[0], self.options).index(self.value)
50 return len(self.options)
51 def get_display(self, index):
52 return self.options[index][1]
53 def get_value(self, index):
54 return self.options[index][0]
55 def get_cur_display(self):
56 return self.options[self.index][1]
57 def get_cur_value(self):
61 def set_value(self, value):
63 self.index = self.find_index()
65 class AttrForm(StringForm):
66 def __init__(self, name, attr, element):
67 self.element = element
69 StringForm.__init__(self, name, self.element.get_attr(self.attr))
70 def set_value(self, value):
71 StringForm.set_value(self, value)
72 self.element.set_attr(self.attr, value)
74 class TipoForm(OptionsForm):
75 def __init__(self, name, attr, element, oclass, vnp):
77 o = map(lambda x: (x[vnp[0]], x[vnp[1]]), l)
78 self.element = element
80 OptionsForm.__init__(self, name, o, element.get_attr(attr))
81 def set_value(self, value):
82 OptionsForm.set_value(self, value)
83 self.element.set_attr(self.attr, value)