pyqt4: setText() inside a function

Diez B. Roggisch deets at nospam.web.de
Thu Apr 16 20:17:53 CEST 2009


l.freschi at gmail.com schrieb:
> I'm developing a PyQt4 application.
> 
> I have created a button:
> ...
> self.start_button=QtGui.QPushButton("start simulation", self)
> ...
> 
> that is connected to a function:
> ...
> self.connect(self.start_button, QtCore.SIGNAL('clicked()'),
> self.simulate)
> ...
> 
> This is the function:
> ...
> def simulate(self):
> 
>                 self.log_inspector.setText('')
>                 cmds=['rm engine','make engine', './
> engine']
>                 first_cmd="./parser "+str(self.filename)
>                 cmds.insert(0, first_cmd)
>                 for cmd in cmds:
>                         self.status_inspector.setText(cmd)
>                         status, output = commands.getstatusoutput(cmd)
>                         output_list=output.split("\n")
>                         output_list.reverse()
>                         output_def="\n".join(output_list)
>                         if status != 0:
>                                 self.log_inspector.setText(cmd"...
> [ERROR]\n"+output_def)
>                                 return
>                 self.status_inspector.setText("Done!")
> ...
> 
> I would like to change the value of status_inspector (It's a QLabel)
> during the execution of the function.
> Is it possible?

If you want GUI-updates while performing time-consuming tasks, you need 
to make sure Qt's event-loop get's called every now and then. This 
should help you:

void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags 
flags = QEventLoop::AllEvents )   [static]


Diez



More information about the Python-list mailing list