Move classes Form para módulo próprio.
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Sat, 15 Mar 2014 01:23:47 +0000 (22:23 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Sat, 15 Mar 2014 01:23:47 +0000 (22:23 -0300)
Classes genéricas para campos de formulários estão em um módulo próprio.

src/baseui.py
src/form.py [new file with mode: 0644]
src/menu.py

index 196b753..1eca890 100644 (file)
 #   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 BaseUI():
     def get_string(self, prompt=""):
         return raw_input(prompt.encode("utf-8"))
diff --git a/src/form.py b/src/form.py
new file mode 100644 (file)
index 0000000..d61c0fc
--- /dev/null
@@ -0,0 +1,72 @@
+# 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)
index eece1c9..b042796 100644 (file)
@@ -21,39 +21,32 @@ import contribuinte
 import ocupacoes
 import rendimentoPJ
 import sys
+import form
+from form import AttrForm
 
-class OcupacaoForm(baseui.OptionsForm):
+class OcupacaoForm(form.OptionsForm):
     def __init__(self, ocupacoes, contribuinte):
         g = ocupacoes.groups()
         l = []
         for i in sorted(g):
             l.extend(g[i])
         o = map(lambda x: (x[0], x[3]), l)
-        baseui.OptionsForm.__init__(self, u"Ocupações", o, contribuinte.get_campo_contribuinte("ocupacaoPrincipal"))
+        form.OptionsForm.__init__(self, u"Ocupações", o, contribuinte.get_campo_contribuinte("ocupacaoPrincipal"))
         self.ocupacoes = ocupacoes
         self.contribuinte = contribuinte
     def set_value(self, value):
-        baseui.OptionsForm.set_value(self, value)
+        form.OptionsForm.set_value(self, value)
         self.contribuinte.set_campo_contribuinte("ocupacaoPrincipal", value)
 
-class ContribuinteForm(baseui.StringForm):
+class ContribuinteForm(form.StringForm):
     def __init__(self, name, attr, contribuinte):
         self.contribuinte = contribuinte
         self.attr = attr
-        baseui.StringForm.__init__(self, name, self.contribuinte.get_campo_contribuinte(self.attr))
+        form.StringForm.__init__(self, name, self.contribuinte.get_campo_contribuinte(self.attr))
     def set_value(self, value):
-        baseui.StringForm.set_value(self, value)
+        form.StringForm.set_value(self, value)
         self.contribuinte.set_campo_contribuinte(self.attr, value)
 
-class AttrForm(baseui.StringForm):
-    def __init__(self, name, attr, element):
-        self.element = element
-        self.attr = attr
-        baseui.StringForm.__init__(self, name, self.element.get_attr(self.attr))
-    def set_value(self, value):
-        baseui.StringForm.set_value(self, value)
-        self.element.set_attr(self.attr, value)
-
 def RendimentoPJ(UI, rend):
     form = []
     form.append(AttrForm("Nome", "nomeFontePagadora", rend))