Hey Fabien,

So you made your principal function run on a timer every 2 seconds?  And 
by "lag" do you mean that the GUI is unresponsive?  I'm still not seeing 
when the loop stops, but what you can do is set the timer at a 0 
interval so it will call the principal function as fast as it can (but 
with no loop).  The problem with this is that you have those 2 sleep 
calls in the function.  I'm not sure why you have the sleeps, but if you 
need them you have two choices:

1. Make you GUI multi-threaded and you could emit a Qt signal from the 
data thread when the GUI thread needs to update the GUI.  Yes this could 
get complicated, but if the sleeps are required then its probably the 
best way.

2. (From what I've been told, the Qt experts don't approve this) You can 
use app.processEvents() in your loop (after each sleep maybe) and this 
will pause your function and tell the main event loop to process any 
queued events (like GUI actions/events) which will make your GUI more 
responsive.

If that doesn't make sense let me know.

-Dave

On 12/12/11 9:16 AM, Fabien Lafont wrote:
> Hi David! Sorry about the delay I was abroad and without any way to
> connect to the internet.
>
> Thank you very much. I've tried to put the principal inside the
> timerEvent. It work but it lags. In fact I've set the interval of the
> Timer to 2 seconds because the principal loop takes roughly 2seconds
> but it's not very accurate...
>
> Is there a way to do the principal loop, show it on the screen, then
> redo the loop?
>
> Thanks again!
>
> Fabien
>
> 2011/12/5 David Hoese<dho...@gmail.com>:
>> If I'm understanding your question correctly and reading your code 
>> correctly, you're asking why the timer method of doing things works, but the 
>> principal() while loop method does not.
>>
>> I had a couple solutions that involved the main event loop, but I just 
>> noticed 2 main things that are probably wrong with your code:
>> 1. You are calling 'principal' from inside __init__ so you never actually 
>> return from __init__ which means that you never call "window.show()" and 
>> therefore never call "qApp.exec_()".  If you really want to use the 
>> 'principal' method you would have to connect it to a one shot timer anyway 
>> to have it run after you have started the application ('qApp.exec_()').  I 
>> think the recommended way would be to use the timer the way you did in your 
>> latest email.
>>
>> 2. At least in the way my email client reads your original code, your calls 
>> to the matplotlib drawing functions aren't inside the while loop and the 
>> while loop never ends...although this doesn't matter if you don't fix #1 
>> above.
>>
>> Hope that made sense.
>>
>> -Dave
>>
>>
>> On 12/5/11 1:44 PM, matplotlib-users-requ...@lists.sourceforge.net wrote:
>>> Message: 3
>>> Date: Mon, 5 Dec 2011 15:46:02 +0100
>>> From: Fabien Lafont<lafont.fab...@gmail.com>
>>> Subject: Re: [Matplotlib-users] [ploting data] Live data
>>> Cc:matplotlib-users@lists.sourceforge.net
>>> Message-ID:
>>>        <CAC9H_cjrgQBE6e6+jzZHyfYHonTeAg0XwU7c_2G-hu=s+z7...@mail.gmail.com>
>>> Content-Type: text/plain; charset=ISO-8859-1
>>>
>>> Thx all for your remarks,
>>>
>>> I can't understand why this code works (when I use the timer method):
>>
>> ------------------------------------------------------------------------------
>> All the data continuously generated in your IT infrastructure
>> contains a definitive record of customers, application performance,
>> security threats, fraudulent activity, and more. Splunk takes this
>> data and makes sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-novd2d
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to