1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets, QtCore, QtGui
import sys
import os
import functools
app = QtWidgets.QApplication(sys.argv)
root = QtWidgets.QMainWindow()
root.setWindowTitle("Craft'Help - Flapili(busays-team)")
root.setMaximumSize(1, 1)
central_widget = QtWidgets.QWidget(root)
root.setCentralWidget(central_widget)
grid_layout = QtWidgets.QGridLayout(central_widget)
def check_if_widget_not_empty_text(widget):
if not widget.text():
widget.setStyleSheet("background-color: red")
else:
widget.setStyleSheet("background-color: white")
def load_item():
try:
combobox_Item.clear()
if combobox_categorie.currentText():
combobox_Item.addItems(os.listdir(os.path.join("craft", combobox_categorie.currentText())))
except:
pass
def add_item():
try:
with open(os.path.join("craft", combobox_categorie.currentText(), combobox_Item.currentText()), "r", encoding="utf-8") as file:
for line in file:
dict_ingredients[line.split(":")[0]] = int(str(line.split(":")[1]).rstrip("\n"))*int(quantite.text())
layout.addWidget(QtWidgets.QLabel(text=quantite.text() + "x " + combobox_Item.currentText()))
except:
pass
def voir_ingredients():
windowIngredient = QtWidgets.QDialog(root, flags=QtCore.Qt.WindowStaysOnTopHint)
windowIngredient.setWindowTitle("liste des ingredients")
# windowIngredient.setFixedSize(400, 800)
layout = QtWidgets.QVBoxLayout(windowIngredient)
scrollArea = QtWidgets.QScrollArea(windowIngredient)
layout.addWidget(scrollArea)
scrollAreaWidgetContents = QtWidgets.QWidget()
scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 300, 800))
scrollArea.setWidget(scrollAreaWidgetContents)
layout = QtWidgets.QGridLayout(scrollAreaWidgetContents)
layout.setAlignment(QtCore.Qt.AlignTop)
windowIngredient.show()
ligne = 0
for key, value in dict_ingredients.items():
checkbox = QtWidgets.QCheckBox()
checkbox.setMaximumSize(20, 20)
layout.addWidget(checkbox, ligne, 0)
layout.addWidget(QtWidgets.QLabel(text=(str(value) + "x " + key)), ligne, 1)
ligne += 1
dict_ingredients = {}
""" Catégorie """
combobox_categorie = QtWidgets.QComboBox()
combobox_categorie.currentTextChanged.connect(load_item)
grid_layout.addWidget(combobox_categorie, 0, 0)
combobox_categorie.setEditable(False)
combobox_categorie.setFixedSize(150,20)
combobox_categorie.addItem("")
combobox_categorie.addItems(os.listdir("craft"))
""" Item à Craft """
combobox_Item = QtWidgets.QComboBox()
grid_layout.addWidget(combobox_Item, 0, 1)
combobox_Item.setEditable(True)
combobox_Item.setFixedSize(200,20)
combobox_Item.setCurrentText("")
""" Quantité """
quantite = QtWidgets.QLineEdit("1")
grid_layout.addWidget(quantite, 0, 2)
quantite.setFixedSize(60,20)
quantite.textChanged.connect(functools.partial(check_if_widget_not_empty_text, quantite))
quantite.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp("^^[0-9]+$")))
""" Bouton ajouter à la liste """
buttonAddRecipe = QtWidgets.QPushButton(text="Ajouter")
buttonAddRecipe.clicked.connect(add_item)
grid_layout.addWidget(buttonAddRecipe, 0, 3)
""" Bouton voir ingredient """
buttonIngredients = QtWidgets.QPushButton(text="voir les ingredients")
buttonIngredients.clicked.connect(voir_ingredients)
grid_layout.addWidget(buttonIngredients, 0, 4)
""" fenetre liste Item """
windowItem = QtWidgets.QDialog(root, flags=QtCore.Qt.WindowMinimizeButtonHint)
windowItem.setWindowTitle("liste des craft")
# windowItem.setFixedSize(400, 800)
layout = QtWidgets.QVBoxLayout(windowItem)
scrollArea = QtWidgets.QScrollArea(windowItem)
layout.addWidget(scrollArea)
scrollAreaWidgetContents = QtWidgets.QWidget()
scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 300, 800))
scrollArea.setWidget(scrollAreaWidgetContents)
layout = QtWidgets.QVBoxLayout(scrollAreaWidgetContents)
layout.setAlignment(QtCore.Qt.AlignTop)
windowItem.show()
root.show()
app.exec_() |
Partager