[PyQt] Need some assistance on QThread

emmanuel_mayssat at lynceantech.com emmanuel_mayssat at lynceantech.com
Thu May 12 00:17:29 BST 2011

Doesn't the QThread send a finished signal when completed?
Then why the QTimer?  (Maybe to kill the Thread if takes too long!?)

You need to instanciate the QThread in the QPushButton.__init__
On SIGNAL('clicked()') trigger a method which runs Qthread.start and disable button (self)

Then connect QThread SIGNAL('finished()') to a method which reenable the button.

Good luck!

On 11:37 Wed 11 May     , vijay swaminathan wrote:
> Hi All,
> I'm new bie to python and programming and would like to get some assistance
> on the problem stated below.
> I'm developing a GUI (using pyqt) to run some scripts (which were run on
> command line earlier).
> on the GUI I have a run button which calls a .bat file , which has the list
> of scripts to execute. Once the run button is clicked, the run button is
> disabled as  it invokes a command prompt, calls a .bat file and when I close
> the command prompt, I would like to re-enable the Run button.
> Since I wanted to monitor the command prompt, I thought of invoking the
> command prompt on a thread and monitor the thread. Correct me if I went
> techinically incorrect here.
> Run button on GUI:  - Here I call the runscript ()
>  self.connect(self.run_button, SIGNAL('clicked()'), self.runscript)
> def runscript(self):
>         file_operation.Generate_Bat_File(self.complete_file_path) # Generate
> a bat file.
>         self.timer = QTimer() # invoke timer for starting and monitoring the
> thread.
>         self.timer.connect(self.timer, SIGNAL("timeout()"),self.sendData)
>         self.timer.start(1000)
> class RunMonitor(QThread):
>     def __init__(self, parent=None):
>         QThread.__init__(self)
>     def run(self):
>         print 'Invoking Command Prompt..........'
>         subprocess.call(["start", "/DC:\\Scripts",
> "scripts_to_execute.bat"], shell=True)
> def sendData(self):
>         if self.run_timer:
>             run_monitor_object = RunMonitor()
>             print 'Starting the thread...........'
>             run_monitor_object.start()
>         if run_monitor_object.isRunning():
>             print 'The Thread is still Alive .......'
>         if run_monitor_object.isFinished():
>             print 'The Thread is not alive anymore......'
> I doubt the following.
> 1.is this the correct way to monitor the thread? if not any help towards
> this is appreciated.
> 2. Is this the correct way to invoke the command prompt in thread?
> 3. is it safe to assume that as long as the command prompt is alive, the
> thread is active and when command prompt is closed, the thread is no more
> active.
> Please help.....
> Eagerly looking forward for some help....I googled enough but could not
> arrive at a solution.
> -- 
> Vijay Swaminathan

> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list