Changed the way ui files are handled

This commit is contained in:
Andreas Tsouchlos 2024-01-03 23:08:26 +01:00
parent c72885258b
commit d4211b6744
6 changed files with 112 additions and 196 deletions

View File

@ -6,11 +6,11 @@ import argparse
def categorize_func(args):
from banking_breakdown.statement_parser import get_stripped_statement
import pandas as pd
df = None
if args.i is not None:
df = get_stripped_statement(args.i)
df = pd.read_csv(args.i, delimiter=';')
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

View File

@ -74,7 +74,7 @@ import numpy as np
#
#
# def main():
# report_data = parse_statement("../res/banking_statement_2023.csv")
# report_data = parse_statement("../res/bank_statement_2023.csv")
#
#
# if __name__ == "__main__":

View File

@ -1,14 +1,12 @@
import sys
import typing
from functools import partial
import pandas as pd
from PyQt6.QtGui import QPixmap, QAction
from PyQt6.QtWidgets import QMainWindow, QTableView, QHBoxLayout, QLabel, \
QMenu, QHeaderView, QLineEdit
from PyQt6 import uic, QtGui, QtCore, QtWidgets
from PyQt6 import uic, QtGui, QtCore
from PyQt6.QtCore import Qt, QSortFilterProxyModel
from banking_breakdown.ui.main_window import Ui_MainWindow
from PyQt6.QtGui import QPixmap, QAction
from PyQt6.QtWidgets import QMainWindow, QPushButton, QHBoxLayout, QLabel, \
QVBoxLayout, QMenu, QApplication, QTableView, QListView
class PandasModel(QtCore.QAbstractTableModel):
@ -63,61 +61,43 @@ class PandasModel(QtCore.QAbstractTableModel):
return QtCore.QVariant(str(item))
class GeneratedWindowWrapper(QMainWindow):
class MainWindow(QMainWindow):
def __init__(self):
super(GeneratedWindowWrapper, self).__init__()
super(MainWindow, self).__init__()
uic.loadUi("res/main_window.ui", self)
self.setContentsMargins(9, 9, 9, 9)
self._window = Ui_MainWindow()
self._window.setupUi(self)
self._warning_layout \
= self.findChild(QVBoxLayout, "warningLayout")
# Populate categories
self._create_button \
= self.findChild(QPushButton, "createCategoryButton")
self._delete_button \
= self.findChild(QPushButton, "deleteCategoryButton")
self._apply_button \
= self.findChild(QPushButton, "applyCategoryButton")
self._list_view \
= self.findChild(QListView, "categoryListView")
self._table_view \
= self.findChild(QTableView, "transactionTableView")
self._category_model = QtGui.QStandardItemModel()
self._window.categoryListView.setModel(self._category_model)
self._list_view.setModel(self._category_model)
# Onclick handlers
self._window.createCategoryButton.clicked.connect(
self._create_button.clicked.connect(
self._handle_create_click)
header = self._window.transactionTableView.horizontalHeader()
header = self._table_view.horizontalHeader()
header.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
header.customContextMenuRequested.connect(self._header_right_clicked)
def _header_right_clicked(self, pos):
context = QMenu(self)
context.addAction(QAction("test 1", self))
context.addAction(QAction("test 2", self))
context.addAction(QAction("test 3", self))
context.exec(self.sender().mapToGlobal(pos))
def add_categories(self, categories: typing.Sequence[str]):
for category in categories:
item = QtGui.QStandardItem(category)
self._category_model.appendRow(item)
def set_statement_data(self, df: pd.DataFrame):
model = PandasModel(df)
proxyModel = QSortFilterProxyModel(self)
proxyModel.setSourceModel(model)
self._window.transactionTableView.setModel(proxyModel)
self._window.transactionTableView.resizeColumnsToContents()
def _handle_create_click(self):
self.add_categories(['asdf'])
def _handle_delete_click(self):
pass
def _handle_apply_click(self):
pass
def add_warning_text(self, text: str):
layout = QHBoxLayout()
warningIcon = QLabel()
pixmap = QPixmap('res/warning.png')
pixmap = QPixmap("res/warning.png")
warningIcon.setPixmap(pixmap)
label = QLabel(text)
@ -129,4 +109,76 @@ class GeneratedWindowWrapper(QMainWindow):
layout.setStretch(0, 0)
layout.setStretch(1, 1)
self._window.warningLayout.addLayout(layout)
self._warning_layout.addLayout(layout)
def set_statement_data(self, df: pd.DataFrame):
model = PandasModel(df)
proxyModel = QSortFilterProxyModel(self)
proxyModel.setSourceModel(model)
self._table_view.setModel(proxyModel)
self._table_view.resizeColumnsToContents()
def add_categories(self, categories: typing.Sequence[str]):
for category in categories:
item = QtGui.QStandardItem(category)
self._category_model.appendRow(item)
def _header_right_clicked(self, pos):
context = QMenu(self)
context.addAction(QAction("test 1", self))
context.addAction(QAction("test 2", self))
context.addAction(QAction("test 3", self))
context.exec(self.sender().mapToGlobal(pos))
def _handle_create_click(self):
self.add_categories(['asdf'])
def _handle_delete_click(self):
pass
def _handle_apply_click(self):
pass
def show_main_window(categories: typing.Sequence[str] = None,
df: pd.DataFrame = None):
app = QApplication(sys.argv)
window = MainWindow()
if categories is not None:
window.add_categories(categories)
if df is not None:
window.set_statement_data(df)
window.add_warning_text("The column 't' does not exist. Please rename the"
" column containing the dates of the transactions"
" to 't'.")
window.add_warning_text("The column 'balance' does not exist. Please"
" rename the column containing the balance after"
" each transaction to 'balance'")
window.add_warning_text("The column 'value' does not exist. Please rename"
" the column containing the values of the"
" transactions to 'value'.")
window.show()
app.exec()
def main():
from banking_breakdown.statement_parser import get_stripped_statement
import os
os.chdir("../")
categories = ["Food", "Rent & Utilities", "Hobbies", "Education",
"Transportation", "Social Life", "Other"]
df = pd.read_csv("res/bank_statement_2023.csv", delimiter=';')
# df = get_stripped_statement("res/bank_statement_2023.csv")
show_main_window(categories, df)
if __name__ == "__main__":
main()

View File

@ -1,47 +0,0 @@
import sys
import typing
import pandas as pd
from PyQt6.QtWidgets import QApplication
from banking_breakdown.ui.generated_wrapper import GeneratedWindowWrapper
def show_main_window(categories: typing.Sequence[str] = None,
df: pd.DataFrame = None):
app = QApplication(sys.argv)
window = GeneratedWindowWrapper()
if categories is not None:
window.add_categories(categories)
if df is not None:
window.set_statement_data(df)
# window.add_warning_text("The column 't' does not exist. Please rename the"
# " column containing the dates of the transactions"
# " to 't'.")
# window.add_warning_text("The column 'balance' does not exist. Please"
# " rename the column containing the balance after"
# " each transaction to 'balance'")
# window.add_warning_text("The column 'value' does not exist. Please rename"
# " the column containing the values of the"
# " transactions to 'value'.")
window.show()
app.exec()
def main():
from banking_breakdown.statement_parser import get_stripped_statement
categories = ["Food", "Rent & Utilities", "Hobbies", "Education",
"Transportation", "Social Life", "Other"]
df = get_stripped_statement("../../res/banking_statement_2023.csv")
show_main_window(categories, df)
if __name__ == "__main__":
main()

View File

@ -1,98 +0,0 @@
# Form implementation generated from reading ui file 'res/main_window.ui'
#
# Created by: PyQt6 UI code generator 6.6.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1300, 731)
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout_4.setSpacing(0)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.widget = QtWidgets.QWidget(parent=self.centralwidget)
self.widget.setObjectName("widget")
self.warningLayout = QtWidgets.QVBoxLayout(self.widget)
self.warningLayout.setContentsMargins(-1, 0, -1, 0)
self.warningLayout.setObjectName("warningLayout")
self.horizontalLayout_6.addWidget(self.widget)
self.verticalLayout_4.addLayout(self.horizontalLayout_6)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.groupBox = QtWidgets.QGroupBox(parent=self.centralwidget)
self.groupBox.setObjectName("groupBox")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.createCategoryButton = QtWidgets.QPushButton(parent=self.groupBox)
self.createCategoryButton.setObjectName("createCategoryButton")
self.horizontalLayout.addWidget(self.createCategoryButton)
self.deleteCategoryButton = QtWidgets.QPushButton(parent=self.groupBox)
self.deleteCategoryButton.setObjectName("deleteCategoryButton")
self.horizontalLayout.addWidget(self.deleteCategoryButton)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.categoryListView = QtWidgets.QListView(parent=self.groupBox)
self.categoryListView.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.SizeAdjustPolicy.AdjustToContents)
self.categoryListView.setObjectName("categoryListView")
self.verticalLayout_2.addWidget(self.categoryListView)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.horizontalLayout_2.addItem(spacerItem)
self.applyCategoryButton = QtWidgets.QPushButton(parent=self.groupBox)
self.applyCategoryButton.setObjectName("applyCategoryButton")
self.horizontalLayout_2.addWidget(self.applyCategoryButton)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3.addWidget(self.groupBox)
self.groupBox_2 = QtWidgets.QGroupBox(parent=self.centralwidget)
self.groupBox_2.setObjectName("groupBox_2")
self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox_2)
self.verticalLayout.setObjectName("verticalLayout")
self.transactionTableView = QtWidgets.QTableView(parent=self.groupBox_2)
self.transactionTableView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows)
self.transactionTableView.setObjectName("transactionTableView")
self.transactionTableView.horizontalHeader().setStretchLastSection(True)
self.verticalLayout.addWidget(self.transactionTableView)
self.horizontalLayout_3.addWidget(self.groupBox_2)
self.horizontalLayout_3.setStretch(1, 1)
self.verticalLayout_4.addLayout(self.horizontalLayout_3)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1300, 23))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(parent=self.menubar)
self.menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(parent=MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionSave = QtGui.QAction(parent=MainWindow)
self.actionSave.setObjectName("actionSave")
self.menuFile.addAction(self.actionSave)
self.menubar.addAction(self.menuFile.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.groupBox.setTitle(_translate("MainWindow", "Categories"))
self.createCategoryButton.setText(_translate("MainWindow", "Create"))
self.deleteCategoryButton.setText(_translate("MainWindow", "Delete"))
self.applyCategoryButton.setText(_translate("MainWindow", "Apply"))
self.groupBox_2.setTitle(_translate("MainWindow", "Transactions"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.actionSave.setText(_translate("MainWindow", "Save"))
self.actionSave.setShortcut(_translate("MainWindow", "Ctrl+S"))

View File

@ -22,6 +22,12 @@
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QWidget" name="widget" native="true">
<property name="maximumSize">
<size>
<width>600</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="warningLayout">
<property name="topMargin">
<number>0</number>
@ -105,6 +111,9 @@
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>