[Tutor] Problems with Gauge Bar.

Alan Gauld alan.gauld at btinternet.com
Sun Aug 10 19:23:22 CEST 2008


"Olrik Lenstra" <o.lenstra at gmail.com> wrote

> I'm probably asking for a lot here. But I don't think I understand 
> this
> fully.

Thats OK.

>> def onScan(self):
>>    self.myfile = open('foo.txt')
>>    self.count = 0
>>    self.setTimer(0.01, self.processLine)
>>
>> def processLine(self)
>>   line = self.myfile.readline()
>>   if line:
>>       processLine(line)
>>       self.count += 1
>>       self.myGauge.setValue(count)
>>       self.setTimer(0.01, self.processLine)
>>   else:
>>      self.myGuage.setValue(0)

> Ok. So lets see if I got this right. In the onScan you define 
> self.myfile to
> open 'foo.txt' One thing I don't get here is what is foo.txt used 
> for?

Its the file that you want to scan - assuming there is a file.
It could be a list or anything else - I don't actually know from
your code what onScan is supposed to do! :-)

> Then you set the count to 0
> Then you set the timer to 0.01 with the event processLine?

Thats right. The idea is to set up a timer to fire after 1/100 of a 
second.
Then in processLine set up another one after processing each line
until the file (or list etc) is scanned.

> then in the processLine you add 1 to the count with every line that 
> is read?

Yes and set the Guage value to whatever count is. Then next time
the GUI draws itself the new cvalue will appear in the guage.

The important bit is that:
1) We use onScan to initialise things not to actually do the 
processing
2) We create the timer each time we process some data (you could
    opt to process more than one line - say batches of 10, but the
    important point is that its only ever a short period of 
processing.
3) We update the count and then the guage after each batch completes

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list