Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > trouble quitting PyQt4 App

Reply
Thread Tools

trouble quitting PyQt4 App

 
 
Soumen banerjee
Guest
Posts: n/a
 
      09-14-2009
Hi,
Im new to PyQt4 and im having fun using it. but ive run into a bit of
a problem. I cant quit the application.
The application has 2 modules. The gui module(gui.py) and then the
main program(main.py)
heres gui.py:

from PyQt4 import QtCore, QtGui
import sys
from subprocess import Popen
class Ui_MainWindow(object):
fileinit=False
paused=True
quit=False
filename=""
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(394, 414)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.scrollArea = QtGui.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(19, 9, 361, 281))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
self.scrollAreaWidgetContents.setGeometry(QtCore.Q Rect(0,
0, 357, 277))
self.scrollAreaWidgetContents.setObjectName("scrol lAreaWidgetContents")
self.textEdit = QtGui.QTextEdit(self.scrollAreaWidgetContents)
self.textEdit.setGeometry(QtCore.QRect(-7, -6, 371, 291))
self.textEdit.setObjectName("textEdit")
self.scrollArea.setWidget(self.scrollAreaWidgetCon tents)
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(30, 310, 80, 25))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(139, 310, 91, 25))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(280, 310, 80, 25))
self.pushButton_3.setObjectName("pushButton_3")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 394, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.pushButton,
QtCore.SIGNAL("clicked()"), self.Open)
QtCore.QObject.connect(self.pushButton_2,
QtCore.SIGNAL("clicked()"), self.Pause)
QtCore.QObject.connect(self.pushButton_3,
QtCore.SIGNAL("clicked()"), self.Quit)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.trans late("MainWindow",
"MainWindow", None, QtGui.QApplication.UnicodeUTF)
self.pushButton.setText(QtGui.QApplication.transla te("MainWindow",
"Open", None, QtGui.QApplication.UnicodeUTF)
self.pushButton_2.setText(QtGui.QApplication.trans late("MainWindow",
"Pause/Resume", None, QtGui.QApplication.UnicodeUTF)
self.pushButton_3.setText(QtGui.QApplication.trans late("MainWindow",
"Quit", None, QtGui.QApplication.UnicodeUTF)
def Pause(self):
print "Pause"
self.paused=not(self.paused)
def Quit(self):
self.quit=True
print "setting quit"
def Open(self):
print "Open"
self.filename=QtGui.QFileDialog.getOpenFileName()
self.filename=str(self.filename)
f=open("book.txt","r")
old=f.read(20)
f.close()
f=open(self.filename,'r')
new=f.read(20)
f.close()
if(old!=new):
Popen('rm log.txt',shell=True)
f=open("book.txt",'w')
f.write(new)
f.close()
self.fileinit=True
print "setting fileinit"


and heres the main.py

from PyQt4 import QtCore, QtGui
import sip,gui
import sys
from subprocess import Popen
from threading import Thread
class AppThread(Thread):
appinit=False
def run(self):
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
self.ui = gui.Ui_MainWindow()
self.ui.setupUi(MainWindow)
MainWindow.show()
self.appinit=True
#ui.textEdit.setText(ui.filename)
sys.exit(app.exec_())
class Speak(Thread):
def run(self):
print "starting speaker"
try:
log=open("log.txt",'r')
print log
self.index=log.read()
log.close()
self.index=int(self.index)
except IOError:
print "setting new"
index=0
#by now, index has been defined for both a new and an old book
self.book=open(a.ui.filename,'r')
self.book.seek(self.index)
while(a.ui.quit==False):
if (a.ui.paused==False):
sen=self.readsen()
print sen
#a.ui.textEdit.setText(sen)
command="soundwrapper espeak "+' " '+sen+' " '
k=Popen(command,shell=True)
print "read sentence"
k.wait()
print "quitted loop"
index=self.book.tell()
log=open("log.txt","w")
log.write(str(index))
log.close()
print "calling exit"
sys.exit()
def readsen(self):
line=""
sen=""
while(line.find(".")== -1):
sen=sen+line
line=self.book.readline()
sen=sen+line[0:line.find(".")+1]
self.book.seek(self.book.tell()-len(line)+line.find(".")+1)
return sen
a=AppThread()
a.start()
while 1:
if a.appinit== True:
if a.ui.fileinit==True:
s=Speak()
s.start()
break

so heres the problem:- when i hit the quit button, quit is set to high
(in the Gui module) and then the while loop in the speak thread
quits(printing quitting loop) and it updates the log file as its
supposed to do. then after it prints calling exit, the app freezes.
Isnt sys.exit() supposed to kill the interpreter? So, what is going
on? why does the app not quit?
Pls Help
Regards
Soumen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PyQt4.__file__ gives PyQt4/__init__.py as value wgw Python 1 08-15-2009 09:58 PM
Re: PyQt4 - widget signal trouble Marco Bizzarri Python 2 04-26-2009 01:04 PM
Timer hangs when quitting app Gitte Wange Python 1 11-28-2004 05:31 PM
After 12 hours, no network. I'm quitting. =?Utf-8?B?cGhvdG9zaG9wcGVy?= Wireless Networking 5 11-24-2004 03:27 AM
DVD Verdict reviews: QUITTING (ZUOTIAN), S.W.A.T.: THE COMPLETE FIRST SEASON, and more! DVD Verdict DVD Video 0 07-07-2003 09:03 AM



Advertisments