Handle ingredients table

This commit is contained in:
Marcel Kapfer 2020-04-30 22:17:39 +02:00
parent 7c661ce01f
commit 3b5629d2ed
Signed by: mmk2410
GPG key ID: CADE6F0C09F21B09

23
init.py
View file

@ -10,7 +10,7 @@ MIT License
""" """
import sys import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QTableWidgetItem
from ui_mainwindow import Ui_MainWindow from ui_mainwindow import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
@ -25,11 +25,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Conncect recipe name typing # Conncect recipe name typing
self.e_recipe_name.textChanged.connect(self.updateTitle) self.e_recipe_name.textChanged.connect(self.updateTitle)
# Handle category buttons # Handle categories
self.b_category_add.clicked.connect(self.category_add) self.b_category_add.clicked.connect(self.category_add)
self.e_category.returnPressed.connect(self.category_add) self.e_category.returnPressed.connect(self.category_add)
self.b_category_remove.clicked.connect(self.category_remove) 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() self.show()
def updateTitle(self): def updateTitle(self):
@ -49,6 +53,21 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def category_remove(self): def category_remove(self):
self.v_categories.takeItem(self.v_categories.currentRow()) 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): def close(self):
""" """
Close the application. A warning is shown before. Close the application. A warning is shown before.