+# coding=utf-8
+#
+# Copyright 2014 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# -*- mode: python; encoding: utf-8; -*-
+
+class BaseForm():
+ def __init__(self):
+ self.type = "none"
+ self.name = "Entry"
+ def get_type(self):
+ return self.type
+ def get_name(self):
+ return self.name
+
+class StringForm(BaseForm):
+ def __init__(self, name, value):
+ self.type = "string"
+ self.name = name
+ if value == None:
+ value = ""
+ self.value = value
+ def get_value(self):
+ return self.value
+ def set_value(self, value):
+ self.value = value
+
+class OptionsForm(BaseForm):
+ def __init__(self, name, options, value):
+ self.type = "options"
+ self.name = name
+ self.options = options
+ self.value = value
+ self.index = self.find_index()
+ def find_index(self):
+ return map(lambda x: x[0], self.options).index(self.value)
+ def get_length(self):
+ return len(self.options)
+ def get_display(self, index):
+ return self.options[index][1]
+ def get_value(self, index):
+ return self.options[index][0]
+ def get_cur_display(self):
+ return self.options[self.index][1]
+ def get_cur_value(self):
+ return self.value
+ def get_index(self):
+ return self.index
+ def set_value(self, value):
+ self.value = value
+ self.index = self.find_index()
+
+class AttrForm(StringForm):
+ def __init__(self, name, attr, element):
+ self.element = element
+ self.attr = attr
+ StringForm.__init__(self, name, self.element.get_attr(self.attr))
+ def set_value(self, value):
+ StringForm.set_value(self, value)
+ self.element.set_attr(self.attr, value)