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 if self.value == None:
50 return map(lambda x: x[0], self.options).index(self.value)
52 return len(self.options)
53 def get_display(self, index):
54 return self.options[index][1]
55 def get_value(self, index):
56 return self.options[index][0]
57 def get_cur_display(self):
60 return self.options[self.index][1]
61 def get_cur_value(self):
65 def set_value(self, value):
67 self.index = self.find_index()
69 class AttrForm(StringForm):
70 def __init__(self, name, attr, element):
71 self.element = element
73 StringForm.__init__(self, name, self.element.get_attr(self.attr))
74 def set_value(self, value):
75 StringForm.set_value(self, value)
76 self.element.set_attr(self.attr, value)
78 class TipoForm(OptionsForm):
79 def __init__(self, name, attr, element, oclass, vnp):
81 o = map(lambda x: (x[vnp[0]], x[vnp[1]]), l)
82 self.element = element
84 OptionsForm.__init__(self, name, o, element.get_attr(attr))
85 def set_value(self, value):
86 OptionsForm.set_value(self, value)
87 self.element.set_attr(self.attr, value)