Elemento deve ser criado a partir de Documento.
[cascardo/irpf-gui.git] / src / rendimentoPJ.py
index ddd3318..b3958c1 100644 (file)
@@ -1,3 +1,4 @@
+# coding=utf-8
 #
 #   Copyright 2013 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
 #
@@ -18,8 +19,11 @@ import xml.dom.minidom
 from contribuinte import Contribuinte
 
 class RendimentoPJ:
-    def __init__(self, el):
-        self.rendimento = el
+    def __init__(self, el = None):
+        if el == None:
+            self.rendimento = xml.dom.minidom.Element("item")
+        else:
+            self.rendimento = el
 
     def get_attr(self, attr):
         if attr in self.rendimento.attributes.keys():
@@ -27,7 +31,7 @@ class RendimentoPJ:
         return None
 
     def set_attr(self, attr, val):
-        self.rendimento.attributes[attr].nodeValue = val
+        self.rendimento.setAttribute(attr, val)
 
 class RendimentosPJ:
     def __init__(self, contribuinte):
@@ -53,6 +57,20 @@ class RendimentosPJ:
     def set_colecao(self, attr, val):
         self._set_attr(self.colecao, attr, val)
 
+    def add_item(self, item):
+        self.items.append(item)
+        self.colecao.appendChild(item.rendimento)
+
+    def new_item(self):
+        item = RendimentoPJ(self.colecao.ownerDocument.createElement("item"))
+        self.add_item(item)
+        return item
+
+    def remove_item(self, i):
+        self.items.pop(i)
+        els = self.colecao.getElementsByTagName("item")
+        self.colecao.removeChild(els[i])
+
 if __name__ == '__main__':
     import sys