[PyQt] Need some assistance on QThread
vijay swaminathan
swavijay at gmail.com
Wed May 11 07:07:21 BST 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110511/47999fbc/attachment.html>
More information about the PyQt
mailing list