From 3b5629d2ed115a7311358f0449ee1e3e0e6e6aff Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Thu, 30 Apr 2020 22:17:39 +0200 Subject: [PATCH] Handle ingredients table --- init.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/init.py b/init.py index 34eabe7..baa0562 100644 --- a/init.py +++ b/init.py @@ -10,7 +10,7 @@ MIT License """ import sys -from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox +from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QTableWidgetItem from ui_mainwindow import Ui_MainWindow class MainWindow(QMainWindow, Ui_MainWindow): @@ -25,11 +25,15 @@ class MainWindow(QMainWindow, Ui_MainWindow): # Conncect recipe name typing self.e_recipe_name.textChanged.connect(self.updateTitle) - # Handle category buttons + # Handle categories self.b_category_add.clicked.connect(self.category_add) self.e_category.returnPressed.connect(self.category_add) self.b_category_remove.clicked.connect(self.category_remove) + # Handle ingredients + self.b_ingredient_add.clicked.connect(self.ingredient_add) + self.b_ingredient_remove.clicked.connect(self.ingredient_remove) + self.show() def updateTitle(self): @@ -49,6 +53,21 @@ class MainWindow(QMainWindow, Ui_MainWindow): def category_remove(self): self.v_categories.takeItem(self.v_categories.currentRow()) + def ingredient_add(self): + if self.c_heading.checkState() == 2 or self.e_amount.text(): + if self.e_ingredient.text(): + if self.c_heading.checkState() == 2: + current_amount = QTableWidgetItem("") + else: + current_amount = QTableWidgetItem(self.e_amount.text()) + current_ingredient = QTableWidgetItem(self.e_ingredient.text()) + self.v_ingredients.setRowCount(self.v_ingredients.rowCount() + 1) + self.v_ingredients.setItem(self.v_ingredients.rowCount() - 1, 0, current_amount) + self.v_ingredients.setItem(self.v_ingredients.rowCount() - 1, 1, current_ingredient) + + def ingredient_remove(self): + self.v_ingredients.removeRow(self.v_ingredients.currentRow()) + def close(self): """ Close the application. A warning is shown before.