From bad57b4a5981681a95b3de0f87b82e164f171586 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Fri, 14 Mar 2014 22:23:47 -0300 Subject: [PATCH] =?utf8?q?Move=20classes=20Form=20para=20m=C3=B3dulo=20pr?= =?utf8?q?=C3=B3prio.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Classes genéricas para campos de formulários estão em um módulo próprio. --- src/baseui.py | 46 -------------------------------- src/form.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/menu.py | 23 ++++++---------- 3 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 src/form.py diff --git a/src/baseui.py b/src/baseui.py index 196b753..1eca890 100644 --- a/src/baseui.py +++ b/src/baseui.py @@ -16,52 +16,6 @@ # along with this program. If not, see . # -*- 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 index 0000000..d61c0fc --- /dev/null +++ b/src/form.py @@ -0,0 +1,72 @@ +# coding=utf-8 +# +# Copyright 2014 Thadeu Lima de Souza Cascardo +# +# 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 . +# -*- 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) diff --git a/src/menu.py b/src/menu.py index eece1c9..b042796 100644 --- a/src/menu.py +++ b/src/menu.py @@ -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)) -- 2.20.1