PDA

View Full Version : Recipe Manager



gecko2903
12th February 2017, 15:45
I am trying to create a Recipe Manager using PyQT. I have created a main window that displays all the recipes within a selected folder.

I am trying to implement a New Recipe button to allow for new recipes to be created and stored in a text file.

To do this I have created two dialog windows.
The first window is used to enter the recipe name and the number of ingredients, and the second to enter each ingredient.

However, I need some help displaying the ingredient window the required amount of time e.g. if the number of ingredients is 2, the ingredient window must be opened once, get the input and store in the text file, and then reopened for the second ingredient in the recipe.

Is there any way to wait until the window has been closed?
e.g. for x in range(0, Number of ingredients):
self.IngredientWindow.show()
wait untill IngredientWindow has been closed

Any help on this would be much appreciated.

EDIT: Would the structure be similar to this question: http://stackoverflow.com/questions/815380/wait-until-qwidget-closes
Not sure how to apply this to Python

xtal256
12th February 2017, 22:45
If it's a modal dialog (http://doc.qt.io/qt-5/qdialog.html#modal-dialogs), then your code will not continue until the dialog is closed, so you don't have to do anything (i.e. that pseudo-code you provided will do what you want).

However, your users may prefer entering all information on just one window, rather than having many windows pop up in turn. It seems like you are quite new to this, but perhaps in the future you might think about ways to allow ingredients to all be entered in one window. I'd imagine a text box with an "Add" button below that adds another text box for the next ingredient. The window would have to grow or show scroll bars when the number of ingredients gets large.

That stack overflow page also mentions using a modal dialog. As for how to do it in Python, I'm sure PyQt also has a QDialog class with an exec method.