A
A
Artem Gapchenko2012-05-07 10:10:19
Python
Artem Gapchenko, 2012-05-07 10:10:19

How to organize the start / stop of the widget rendering function?

The problem may seem very simple. True, I'm stuck on it and for the second day I've been trying to come up with something.
I am writing an application on PySide. The task, if you localize its problematic place, looks like this: by clicking on the “Play” button (the checkable property is set to True), a certain function is launched that performs calculations in a loop and updates the image of the cellular automaton using QPainter once every hundred milliseconds (which this is, in principle, also not important). On the second click on "Play", this function stops working.
If there are no questions with the first part of the task - we connect the checked slot of our button with the signal we defined (let's call it on_play), which starts the main loop, then what to do with the second part is not clear.
The problem is that after our on_play signal fires for the first time, it can run indefinitely. Therefore, even though we are trying to click on the “Play” button and thereby change its checked state to False (in on_play, you can set a check to see if the button is currently pressed or not, and depending on this , continue or stop calculations), we cannot do this - the previous launch of the signal has not yet completed its execution. Deadlock.
Do I understand correctly that this problem can be fixed only with the help of parallel programming? Run, say, on_play in a separate thread, and work with changing button states in the application itself. Or can you do without it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alz, 2012-05-07
@artemgapchenko

Timers use

I
ixSci, 2012-05-07
@ixSci

Why go without it? play should be executed asynchronously, which means there is nothing to think about here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question