[PyQt] wx.MilliSleep equivalent
Tong Zhang
warriorlance at gmail.com
Wed Oct 3 15:26:07 BST 2018
Thanks Chris, it works! BTW, I read the doc of 'processEvents'
(http://doc.qt.io/qt-5/qcoreapplication.html#processEvents), which says
'You can call this function occasionally when your program is busy
performing a long operation (e.g. copying a file).', what does this
mean? Why call this function helps, is it to indicate when the busy task
is finished?
@Kyle, wx.MilliSleep does non-blocking wait, that is the app still can
respond other events during the period of millisleep time. While what I
wanna do is pretty much simple, that is just wait for some time before
going to next step while not block the app.
@Barry time.sleep() does not help since it will block the app.
'qWait' in QTest actually provides another way to do, just like Jones,
Bryan mentioned in previous email.
These are so far what I've learnt, thanks.
Tong
On 10/03/2018 05:44 AM, Chris Pezley wrote:
> I misread the description of the wait argument in processEvents. It
> looks like it will return earlier if it can. You'll have to define your
> own blocking processEvents:
>
>
> import time
>
> from PyQt5 import QtWidgets
>
>
> def processWait(time_to_block):
> """
> :param time_to_block: The time to block in seconds.
> :type time_to_block: float
> """
> start_time = time.time()
>
> # Keep processing events until we've exceeded the specified time.
> while time.time() - start_time < time_to_block:
> QtWidgets.qApp.processEvents()
>
>
>
> On 10/01/2018 11:02 PM, Tong Zhang wrote:
>> Hello Chris,
>>
>> Thanks, I've tried like this:
>>
>> from PyQt5.QtCore import QCoreApplication
>> from PyQt5.QtCore import QEventLoop
>>
>> QCoreApplication.processEvents(QEventLoop.WaitForMoreEvents, msec)
>>
>> but had no luck, it does not behavior the same as qWait(msec). Did I
>> use this method correctly?
>>
>> Tong
>>
>> On 09/22/2018 02:02 AM, Chris Pezley wrote:
>>> Hi Tong,
>>>
>>> maybe what you want is "QtWidgets.qApp.processEvents()"? (make sure
>>> to look at the one with the optional argument for maxtime)
>>> http://doc.qt.io/qt-5/qcoreapplication.html#processEvents-1
>>>
>>> On 21/09/2018 20.22, Tong Zhang wrote:
>>>> Hello,
>>>>
>>>> When I'm building applications by wxPython, there is a function
>>>> wx.MilliSleep could be used to do non-GUI-block sleep, while I
>>>> cannot find the similar thing in PyQt, is it available or not?
>>>> Otherwise, what I can do to is to use QThread. Any comment is
>>>> appreciated!
>>>>
>>>> Tong
>>>>
>>>>
>>>> _______________________________________________
>>>> PyQt mailing listPyQt at riverbankcomputing.com
>>>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> PyQt mailing list PyQt at riverbankcomputing.com
>>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>>
>>
>
More information about the PyQt
mailing list