def loadInfo(self): date = self.mainWindow.transWindow.date.date() self.view.clear() self.view.setHeaderLabels( ['Categoria', 'Gasto em ' + date.toString("MMMM yyyy")]) for category in DATABASE.getCategoriesParent(): if category != TRANSFERS: item = TreeItem(self.view, category) item.setFont(1, BOLD) self.formatItem(item) for children in DATABASE.getChildrenFrom(category): child = TreeItem(item, children) self.formatItem(child) self.view.resizeColumnToContents(0) self.view.sortItems(0, Qt.AscendingOrder) balance = DATABASE.getMonthlyBalance(date) self.balance.setText("Balanço Mensal: R$ %.2f" % balance) if balance > 0: self.balance.setStyleSheet("QLabel {color:#007E00}") elif balance == 0: self.balance.setStyleSheet("QLabel {color:#000000}") else: self.balance.setStyleSheet("QLabel {color:#7E0000}")
def process(self): date = self.date.date() transaction = [date.day(), date.month(), date.year()] transaction += [self.description.text(), TRANSFERS, None] transaction += [self.account1.currentText(), -self.value.value()] DATABASE.addTransaction(transaction) transaction[6:8] = [self.account2.currentText(), self.value.value()] DATABASE.addTransaction(transaction)
def process(self, item): category = [self.name.text(), self.parentCat.currentText()] if not item: msg = DATABASE.addCategory(category) self.showMessage(msg) else: category += [item.text(0)] DATABASE.updateCategory(category) msg = "Categoria %s atualizada para %s." % (item.text(0), self.name.text()) self.showMessage(msg)
def deleteItems(self): items = self.view.getChecked(0) if items: result = QMessageBox.question( self, "Apagar Transações", "Deseja realmente apagar as %d transações selecionadas?" % len(items)) if result == QMessageBox.Yes: for item in items: DATABASE.delTransaction(item.ident) self.mainWindow.showMessage("%d transações Apagadas." % len(items)) self.mainWindow.loadInfo()
def deleteItem(self, item): date = item.parent().data(0, Qt.DisplayRole) result = QMessageBox.question( self, "Apagar Transação", "Deseja realmente apagar a transação:\n\n" + ">%s\n" % date.toString("dd/MM/yyyy") + ">%s\n" % item.text(1) + ">Conta:\t\t%s\n" % item.text(3) + ">Categoria:\t%s\n" % item.text(2) + ">Valor:\t\t%s" % item.text(4)) if result == QMessageBox.Yes: DATABASE.delTransaction(item.ident) self.mainWindow.showMessage("Transação Apagada.") self.mainWindow.loadInfo()
def deleteItems(self): items = self.viewTreasure.getChecked(0) items += self.viewStocks.getChecked(0) if items: result = QMessageBox.question( self, "Apagar Invetimentos", "Deseja realmente apagar os %d investimentos selecionados?" % len(items)) if result == QMessageBox.Yes: for item in items: DATABASE.delInvestiments(item.text(0)) self.mainWindow.showMessage("%d investimentos Apagados." % len(items)) self.mainWindow.loadInfo()
def createLayout(self): layout = QFormLayout() self.date = QDateEdit() self.date.setDate(QDate.currentDate()) self.date.setCalendarPopup(True) self.date.setFocusPolicy(Qt.StrongFocus) layout.addRow("Data", self.date) self.description = QLineEdit() self.description.setMaxLength(40) completer = QCompleter(DATABASE.getDescriptions()) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setCompletionMode(QCompleter.PopupCompletion) self.description.setCompleter(completer) layout.addRow("Descrição", self.description) self.account1 = QComboBox() self.account2 = QComboBox() self.account1.setEditable(False) self.account2.setEditable(False) accounts = DATABASE.getAccounts() for item in accounts: self.account1.addItem(item) self.account2.addItem(item) self.account2.setCurrentIndex(1) layout.addRow("De", self.account1) layout.addRow("Para", self.account2) self.value = QDoubleSpinBox() self.value.setDecimals(2) self.value.setPrefix("R$ ") self.value.setSingleStep(100) self.value.setRange(0, 1000000000) layout.addRow("Valor", self.value) sublayout = QHBoxLayout() self.ok = QPushButton("Adicionar") self.ok.clicked.connect(self.accept) if not accounts: self.ok.setEnabled(False) cancel = QPushButton("Cancelar") cancel.clicked.connect(self.reject) sublayout.addWidget(self.ok) sublayout.addWidget(cancel) layout.addRow(sublayout) self.setLayout(layout)
def loadInfo(self): self.view.clear() self.view.setHeaderLabels(COLUMNS) for item in DATABASE.getTransactions(self.date.date()): itemDate = QDate(item[3], item[2], item[1]) topDate = self.view.getTopItem(itemDate) if topDate: reg = TreeItem(topDate, '') else: top = TreeItem(self.view, '') top.setData(0, Qt.DisplayRole, itemDate) reg = TreeItem(top, '') reg.setIdent(item[0]) reg.setCheckState(0, Qt.Unchecked) reg.setText(1, item[4]) reg.setText(2, item[5]) reg.setTextAlignment(2, Qt.AlignCenter) reg.setText(3, item[7]) reg.setTextAlignment(3, Qt.AlignCenter) reg.setText(4, "R$ %.2f " % item[8]) reg.setTextAlignment(4, Qt.AlignRight) delBtn = DeleteButton(treeItem=reg) delBtn.clicked.connect(self.deleteItem) self.view.setItemWidget(reg, 5, delBtn) self.view.resizeColumnToContents(0) self.view.expandAll() self.view.sortItems(0, Qt.DescendingOrder)
def createLayout(self, item): layout = QFormLayout() types = QGroupBox("Tipo", self) self.bank = QRadioButton("Banco") self.bank.setChecked(True) self.card = QRadioButton("Cartão de Crédito") self.broker = QRadioButton("Corretora") hbox = QHBoxLayout() hbox.addWidget(self.bank) hbox.addWidget(self.card) hbox.addWidget(self.broker) types.setLayout(hbox) layout.addRow(types) self.name = QLineEdit() self.name.textChanged.connect(self.enableButton) self.name.setMaxLength(20) layout.addRow("Nome", self.name) self.limit = QDoubleSpinBox() self.limit.setPrefix("R$ ") self.limit.setDecimals(2) self.limit.setSingleStep(100) self.limit.setRange(0, 100000000) self.broker.toggled.connect(lambda: self.limit.setEnabled(not self.broker.isChecked())) layout.addRow("Limite", self.limit) self.expiration = QSpinBox() self.expiration.setPrefix("Dia ") self.expiration.setRange(1, 31) self.expiration.setEnabled(False) self.card.toggled.connect(lambda: self.expiration.setEnabled(self.card.isChecked())) layout.addRow("Vencimento da fatura", self.expiration) sublayout = QHBoxLayout() self.ok = QPushButton("Adicionar") self.ok.clicked.connect(self.accept) self.ok.setEnabled(False) cancel = QPushButton("Cancelar") cancel.clicked.connect(self.reject) sublayout.addWidget(self.ok) sublayout.addWidget(cancel) layout.addRow(sublayout) if item: self.name.setText(item.text(0)) account = DATABASE.getAccounts(True, item.text(0)) self.limit.setValue(account[2]) if account[1] == BANK: self.bank.setChecked(True) elif account[1] == CARD: self.card.setChecked(True) else: self.broker.setChecked(True) if account[3]: self.expiration.setValue(account[3]) self.ok.setText("Editar") self.setLayout(layout)
def showTable(self, inverse=False): self.table.clear() self.table.setHeaderLabels(["#",'Data', 'Descrição', 'Categoria', 'Valor']) self.accountView.setText(self.account.currentText()) self.date1.setText(self.period1.date().toString("dd/MM/yyyy")) self.date2.setText(self.period2.date().toString("dd/MM/yyyy")) transactions = DATABASE.getTransactionsFrom(self.period1.date(), self.period2.date(), self.account.currentText()) suma = 0 count = 1 for trans in transactions: row = TreeItem(self.table, '') row.setIdent(trans[0]) row.setData(0, Qt.DisplayRole, count) row.setData(1, Qt.DisplayRole, QDate(trans[3], trans[2], trans[1]), ) row.setCheckState(1, Qt.Checked) row.setText(2, trans[4]) row.setText(3, trans[5]) if inverse: row.setText(4, "R$ %.2f" % trans[8]) suma += trans[8] else: row.setText(4, "R$ %.2f" % -trans[8]) suma -= trans[8] if trans[8] > 0: defineColor(row, trans[8], 2) count += 1 self.totalValue.setText("R$ %.2f" % suma) self.table.resizeColumnToContents(0)
def process(self, item): investiment = [self.name.text()] if self.treasure.isChecked(): investiment += [1, TREASURE] else: investiment += [self.qtd.value(), STOCK] investiment += [self.unit.value(), self.broker.currentText()] if not item: msg = DATABASE.addInvestiment(investiment) self.showMessage(msg) else: investiment += [item.text(0)] DATABASE.updateInvestiment(investiment) msg = "Investimento %s Atualizada para %s." % (item.text(0), self.name.text()) self.showMessage(msg)
def process(self, item): account = [self.name.text()] if self.bank.isChecked(): account += [BANK, self.limit.value(), 0] elif self.card.isChecked(): account += [CARD, self.limit.value(), self.expiration.value()] else: account += [BROKER, "-------", 0] if not item: msg = DATABASE.addAccount(account) self.showMessage(msg) else: account += [item.text(0)] DATABASE.updateAccount(account) msg = "Conta %s Atualizada para %s." % (item.text(0), self.name.text()) self.showMessage(msg)
def deleteItems(self): items = DATABASE.getAccounts() dialog = DeleteDialog(self, "Deletar Contas", "del-inst.png", ["Conta", "Transações"], items) result = dialog.exec_() if result: dialog.process(_type=ACCOUNT) self.mainWindow.loadInfo()
def loadInfo(self): brokers = DATABASE.getBrokers() self.viewTreasure.clear() self.viewTreasure.setHeaderLabels(COLUMNSTREASURE) self.viewStocks.clear() self.viewStocks.setHeaderLabels(COLUMNSSTOCK) for broker in brokers: treasureItem = TreeItem(self.viewTreasure, broker) treasureItem.setFont(0, BOLD) treasureItem.setText( 1, "R$ %.2f" % DATABASE.getBalanceFromBroker(broker, TREASURE)) treasureItem.setTextAlignment(1, Qt.AlignRight) stockItem = TreeItem(self.viewStocks, broker) stockItem.setFont(0, BOLD) stockItem.setText( 3, "R$ %.2f" % DATABASE.getBalanceFromBroker(broker, STOCK)) stockItem.setTextAlignment(3, Qt.AlignRight) investiments = DATABASE.getInvestiments(broker) for investiment in investiments: if investiment[2] == TREASURE: item = TreeItem(treasureItem, investiment[0]) item.setCheckState(0, Qt.Unchecked) item.setText(1, "R$ %.2f" % investiment[3]) item.setTextAlignment(1, Qt.AlignRight) elif investiment[2] == STOCK: item = TreeItem(stockItem, investiment[0]) item.setCheckState(0, Qt.Unchecked) item.setText(1, "%d" % investiment[1]) item.setTextAlignment(1, Qt.AlignCenter) item.setText(2, "R$ %.2f" % investiment[3]) item.setTextAlignment(2, Qt.AlignRight) item.setText(3, "R$ %.2f" % (investiment[1] * investiment[3])) item.setTextAlignment(3, Qt.AlignRight) self.viewTreasure.expandAll() self.viewTreasure.resizeColumnToContents(0) self.viewTreasure.sortItems(0, Qt.AscendingOrder) self.viewStocks.expandAll() self.viewStocks.resizeColumnToContents(0) self.viewStocks.sortItems(0, Qt.AscendingOrder)
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle("De$compliconta$") self.setWindowIcon(Icon("main-icon.png")) self.area = QMdiArea() self.area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setCentralWidget(self.area) DATABASE.showInfo() self.createMenus() self.createWindows() self.loadInfo() self.showMaximized() self.showMessage("Iniciado")
def deleteItems(self): items = DATABASE.getCategories() dialog = DeleteDialog( self, "Deletar Categorias", "del-cat.png", ["Categoria", "Transações", "Filhas", "Trans. Filhas"], items) result = dialog.exec_() if result: dialog.process(_type=CATEGORY) self.mainWindow.loadInfo()
def updatePlot(self): self.canvas.axes.cla() date = self.mainWindow.transWindow.date.date() x = range(0, date.daysInMonth() + 1) previewBalance = DATABASE.getBalanceTo( QDate( date.addMonths(-1).year(), date.addMonths(-1).month(), date.addMonths(-1).daysInMonth())) y = [previewBalance] for i in range(1, len(x)): dayBalance = previewBalance + DATABASE.getBalanceFromDay( QDate(date.year(), date.month(), i)) y += [ previewBalance + DATABASE.getBalanceFromDay(QDate(date.year(), date.month(), i)) ] previewBalance = dayBalance self.canvas.axes.plot(x, y) self.canvas.draw()
def attPeriod(self, index): info = DATABASE.getAccounts(name=self.account.itemText(index), info=True) currentDate = QDate.currentDate() if info[3]: currentDate.setDate(currentDate.year(), currentDate.month() - 1, info[3] + 1) self.period1.setDate(currentDate.addDays(-10)) self.period2.setDate(currentDate.addMonths(1).addDays(-11)) self.showTable() else: currentDate.setDate(currentDate.year(), currentDate.month(), 1) self.period1.setDate(currentDate) self.period2.setDate(QDate(currentDate.year(), currentDate.month(), currentDate.daysInMonth())) self.showTable(inverse=True)
def process(self, item): if DATABASE.getCategories(self.category.currentText()): self.insertTransaction(item) self.parent().mainWindow.loadInfo() else: message = QMessageBox( QMessageBox.Warning, "Categoria Inexistente", "Deseja adicionar a categoria %s" % self.category.currentText(), QMessageBox.Ok | QMessageBox.Cancel) resultMsg = message.exec_() if resultMsg == QMessageBox.Ok: self.insertTransaction(item, True) self.parent().mainWindow.loadInfo()
def createLayout(self, item): layout = QFormLayout() self.name = QLineEdit() self.name.textChanged.connect(self.enableButton) self.name.setMaxLength(30) layout.addRow("Nome", self.name) self.parentCat = QComboBox() self.parentCat.addItem("") parents = DATABASE.getCategories(infos=True) for parentCat in parents: if not parentCat[1]: self.parentCat.addItem(parentCat[0]) layout.addRow("Categoria Pai", self.parentCat) sublayout = QHBoxLayout() self.ok = QPushButton("Adicionar") self.ok.clicked.connect(self.accept) self.ok.setEnabled(False) cancel = QPushButton("Cancelar") cancel.clicked.connect(self.reject) sublayout.addWidget(self.ok) sublayout.addWidget(cancel) layout.addRow(sublayout) if item: self.name.setText(item.text(0)) parentCat = DATABASE.getCategories(name=item.text(0))[1] idx = self.parentCat.findText(parentCat, Qt.MatchExactly) self.parentCat.setCurrentIndex(idx) if idx == 0: self.parentCat.removeItem( self.parentCat.findText(item.text(0), Qt.MatchExactly)) self.ok.setText("Editar") self.setLayout(layout)
def insertTransaction(self, item, newCategory=False): if self.expense.isChecked(): value = -self.value.value() else: value = self.value.value() if not item: value = value / self.subdivision.value() count = 0 for i in range(self.initial.value(), self.subdivision.value() + 1): date = self.date.date().addMonths(count) transaction = [date.day(), date.month(), date.year()] if self.subdivision.value() > 1: transaction += [ self.description.text() + " (%d/%d)" % (i, self.subdivision.value()) ] else: transaction += [self.description.text()] if newCategory: transaction += [self.category.currentText(), None] else: transaction += [ self.category.currentText(), DATABASE.getCategories(self.category.currentText(), infos=True)[1] ] transaction += [self.account.currentText(), value] DATABASE.addTransaction(transaction) self.showMessage("Transação Adicionada.") count += 1 else: date = self.date.date() transaction = [date.day(), date.month(), date.year()] transaction += [self.description.text()] if newCategory: transaction += [self.category.currentText(), None] else: transaction += [ self.category.currentText(), DATABASE.getCategories(self.category.currentText(), infos=True)[1] ] transaction += [self.account.currentText(), value, item.ident] DATABASE.updateTransaction(transaction) self.showMessage("Transação Editada.")
def loadInfo(self): self.view.clear() self.view.setHeaderLabels(COLUMNS) banks = TreeItem(self.view, "Bancos") banks.setFont(1, BOLD) banks.setTextAlignment(1, Qt.AlignRight) banks.setFont(2, BOLD) banks.setTextAlignment(2, Qt.AlignRight) cards = TreeItem(self.view, u"Cartões de Crédito") cards.setFont(1, BOLD) cards.setTextAlignment(1, Qt.AlignRight) cards.setFont(2, BOLD) cards.setTextAlignment(2, Qt.AlignRight) brokers = TreeItem(self.view, "Corretoras") brokers.setFont(1, BOLD) brokers.setTextAlignment(1, Qt.AlignRight) accounts = DATABASE.getAccounts(info=True) for account in accounts: balance = DATABASE.getBalance(account[0]) if account[1] == BANK: item = TreeItem(banks, account[0]) if balance >= 0: item.setText(2, "R$ %.2f" % account[2]) else: item.setText(2, "R$ %.2f" % (account[2] + balance)) item.setText(1, "R$ %.2f" % balance) defineColor(item, balance, 1) elif account[1] == CARD: item = TreeItem(cards, account[0]) item.setText(2, "R$ %.2f" % (account[2] + balance)) item.setText(1, "R$ %.2f" % balance) defineColor(item, balance, 1) else: item = TreeItem(brokers, account[0]) item.setText( 1, "R$ %.2f" % (balance + DATABASE.getBalanceFromBroker(account[0]))) defineColor( item, balance + DATABASE.getBalanceFromBroker(account[0]), 1) item.setTextAlignment(1, Qt.AlignRight) item.setTextAlignment(2, Qt.AlignRight) value = DATABASE.getBalance(_type=BANK) banks.setText(1, "R$ %.2f" % value) defineColor(banks, value, 1) accounts = DATABASE.getAccounts(info=True) limitDisp = 0 for account in accounts: balance = DATABASE.getBalance(account[0]) if account[1] == BANK and balance < 0: limitDisp += account[2] + balance elif account[1] == BANK: limitDisp += account[2] banks.setText(2, "R$ %.2f" % limitDisp) value = DATABASE.getBalance(_type=CARD) cards.setText(1, "R$ %.2f" % value) defineColor(cards, value, 1) limitDisp = 0 for account in accounts: balance = DATABASE.getBalance(account[0]) if account[1] == CARD: limitDisp += account[2] + balance cards.setText(2, "R$ %.2f" % limitDisp) brokers.setText( 1, "R$ %.2f" % (DATABASE.getBalance(_type=BROKER) + DATABASE.getBalanceFromBroker())) defineColor( brokers, DATABASE.getBalance(_type=BROKER) + DATABASE.getBalanceFromBroker(), 1) balance = DATABASE.getBalance() + DATABASE.getBalanceFromBroker() self.balance.setText("Balanço Total: R$ %.2f" % balance) if balance > 0: self.balance.setStyleSheet("QLabel {color:#007E00}") elif balance == 0: self.balance.setStyleSheet("QLabel {color:#000000}") else: self.balance.setStyleSheet("QLabel {color:#7E0000}") self.view.expandAll() self.view.resizeColumnToContents(0) self.view.sortItems(0, Qt.AscendingOrder)
def closeEvent(self, event): DATABASE.close()
def formatItem(self, item): value = DATABASE.getBalanceFromCategory( item.text(0), self.mainWindow.transWindow.date.date()) item.setText(1, "R$ %.2f" % value) defineColor(item, value, 1) item.setTextAlignment(1, Qt.AlignRight)
def process(self, _type=None): checkedItems = self.view.getChecked(0) if _type == CATEGORY: for category in checkedItems: msg = "Categoria %s Apagada. " % category.text(0) if category.checkState(1): DATABASE.delCategories(category.text(0), transaction=True) msg += "\n\t\t Suas transações também foram apagadas." if category.checkState(2): DATABASE.delCategories(category.text(0), children=True) msg += "\n\t\t Suas categorias filhas também foram apagadas" else: DATABASE.promoveChildrenFrom(category.text(0)) if category.checkState(3): DATABASE.delCategories(category.text(0), transChildren=True) msg += "\n\t\t As transações de suas categorias filhas também foram apagadas." DATABASE.delCategories(category.text(0)) self.showMessage(msg) elif _type == ACCOUNT: for account in checkedItems: if account.checkState(1): DATABASE.delAccounts(account.text(0), True) self.showMessage( "Conta %s e suas transações foram apagadas." % account.text(0)) else: DATABASE.delAccounts(account.text(0)) self.showMessage("Conta %s foi apagada." % account.text(0))
def __init__(self, parent=None): super().__init__(parent) self.setFixedSize(600, 650) self.setWindowTitle("Ver Fatura\Extrato: ") self.setWindowIcon(Icon('fatura.png')) layout = QFormLayout() self.account = QComboBox() accounts = DATABASE.getAccounts() for account in accounts: self.account.addItem(account) self.account.activated.connect(self.attPeriod) layout.addRow("Conta", self.account) self.period1 = QDateEdit() self.period1.setCalendarPopup(True) label = QLabel(" a ") label.setAlignment(Qt.AlignCenter) self.period2 = QDateEdit() self.period2.setCalendarPopup(True) dateLayout = QHBoxLayout() dateLayout.addWidget(self.period1, 1) dateLayout.addWidget(label) dateLayout.addWidget(self.period2, 1) layout.addRow("Periodo", dateLayout) infoBox = QHBoxLayout() infos = QFormLayout() self.accountView = QLabel() self.totalValue = QLabel() self.date1 = QLabel() label2 = QLabel(" a ") label2.setAlignment(Qt.AlignCenter) self.date2 = QLabel() dateLayout2 = QHBoxLayout() dateLayout2.addWidget(self.date1, 1) dateLayout2.addWidget(label2) dateLayout2.addWidget(self.date2, 1) infos.addRow("Conta", self.accountView) infos.addRow("Período ", dateLayout2) infos.addRow("Total", self.totalValue) infoBox.addLayout(infos) left = QToolButton() left.setArrowType(Qt.LeftArrow) left.clicked.connect(self.previousMonth) right = QToolButton() right.setArrowType(Qt.RightArrow) right.clicked.connect(self.nextMonth) infoBox.addWidget(left) infoBox.addWidget(right) infoBox.addStretch(1) layout.addRow(infoBox) self.table = Tree(4) self.table.setHeaderLabels(['Data', 'Descrição', 'Categoria', 'Valor']) self.table.setResizeColumn(2) self.table.itemDoubleClicked.connect(self.editItem) self.table.itemClicked.connect(self.alterSum) layout.addRow(self.table) self.attPeriod(0) self.period1.dateChanged.connect(self.showTable) self.period2.dateChanged.connect(self.showTable) self.setLayout(layout)
def createLayout(self, item): layout = QFormLayout() types = QGroupBox("Tipo", self) self.expense = QRadioButton("Despesa") self.expense.setChecked(True) self.expense.toggled.connect(lambda: changePrefix(self)) self.income = QRadioButton("Receita") self.income.toggled.connect(lambda: changePrefix(self)) hbox = QHBoxLayout() hbox.addWidget(self.expense) hbox.addWidget(self.income) types.setLayout(hbox) layout.addRow(types) self.date = QDateEdit() self.date.setDate(QDate.currentDate()) self.date.setCalendarPopup(True) self.date.setFocusPolicy(Qt.StrongFocus) layout.addRow("Data", self.date) self.description = QLineEdit() self.description.setMaxLength(40) completer = QCompleter(DATABASE.getDescriptions()) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setCompletionMode(QCompleter.InlineCompletion) self.description.setCompleter(completer) layout.addRow("Descrição", self.description) self.category = QComboBox() self.category.setEditable(True) self.category.completer().setCompletionMode(QCompleter.PopupCompletion) categories = DATABASE.getCategories() if not categories: DATABASE.populateCategories() categories = DATABASE.getCategories() for cat in categories: self.category.addItem(cat) layout.addRow("Categoria", self.category) self.account = QComboBox() self.account.setEditable(False) accounts = DATABASE.getAccounts() for acc in accounts: self.account.addItem(acc) layout.addRow("Conta", self.account) self.value = QDoubleSpinBox() self.value.setDecimals(2) self.value.setSingleStep(100) self.value.setRange(0, 1000000000) layout.addRow("Valor", self.value) divBox = QHBoxLayout() self.initial = QSpinBox() self.initial.setRange(1, 1000) label = QLabel(" de ") label.setAlignment(Qt.AlignCenter) self.subdivision = QSpinBox() self.subdivision.setRange(1, 1000) self.subdivision.setSuffix(" parcelas") self.subdivision.setAlignment(Qt.AlignCenter) divBox.addWidget(self.initial) divBox.addWidget(label) divBox.addWidget(self.subdivision) layout.addRow("Parcelas", divBox) sublayout = QHBoxLayout() self.ok = QPushButton("Adicionar") self.ok.clicked.connect(self.accept) if not accounts: self.ok.setEnabled(False) cancel = QPushButton("Cancelar") cancel.clicked.connect(self.reject) sublayout.addWidget(self.ok) sublayout.addWidget(cancel) layout.addRow(sublayout) if item: info = DATABASE.getTransactions(ident=item.ident) if info[-1] >= 0: self.income.setChecked(True) self.value.setPrefix("R$ ") else: self.expense.setChecked(True) self.value.setPrefix("R$ -") self.date.setDate(QDate(info[3], info[2], info[1])) self.description.setText(info[4]) idx = self.category.findText(info[5], Qt.MatchExactly) self.category.setCurrentIndex(idx) idx = self.account.findText(info[7], Qt.MatchExactly) self.account.setCurrentIndex(idx) self.value.setValue(abs(info[8])) self.ok.setText("Editar") self.initial.setEnabled(False) label.setEnabled(False) self.subdivision.setEnabled(False) self.setLayout(layout)
def createLayout(self, item): layout = QFormLayout() types = QGroupBox("Tipo", self) self.treasure = QRadioButton("Tesouro Direto") self.treasure.setChecked(True) self.stock = QRadioButton("Ações") hbox = QHBoxLayout() hbox.addWidget(self.treasure) hbox.addWidget(self.stock) types.setLayout(hbox) layout.addRow(types) self.name = QLineEdit() self.name.textChanged.connect(self.enableButton) self.name.setMaxLength(30) layout.addRow("Nome", self.name) self.qtd = QSpinBox() self.qtd.setSuffix(" papéis") self.qtd.setRange(1, 100000000) self.qtd.setEnabled(False) self.treasure.toggled.connect( lambda: self.qtd.setEnabled(not self.treasure.isChecked())) layout.addRow("Quantidade", self.qtd) self.unit = QDoubleSpinBox() self.unit.setPrefix("R$ ") self.unit.setDecimals(2) self.unit.setSingleStep(25) self.unit.setRange(0, 100000000) layout.addRow("Valor Unitário", self.unit) self.broker = QComboBox() brokers = DATABASE.getBrokers() self.broker.addItems(brokers) layout.addRow("Corretora", self.broker) sublayout = QHBoxLayout() self.ok = QPushButton("Adicionar") self.ok.clicked.connect(self.accept) self.ok.setEnabled(False) cancel = QPushButton("Cancelar") cancel.clicked.connect(self.reject) sublayout.addWidget(self.ok) sublayout.addWidget(cancel) layout.addRow(sublayout) if item: info = DATABASE.getInvestiments(name=item.text(0)) if info[2] == TREASURE: self.treasure.setChecked(True) else: self.stock.setChecked(True) self.name.setText(info[0]) self.qtd.setValue(info[1]) self.unit.setValue(info[3]) idx = self.broker.findText(info[4], Qt.MatchExactly) self.broker.setCurrentIndex(idx) self.ok.setText("Editar") self.setLayout(layout)