Re: trouble quitting PyQt4 App

2009-09-14 Thread MRAB

Soumen banerjee wrote:

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)

[snip]

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?


sys.exit() just raises a SystemExit exception, so only the thread is
terminated.
--
http://mail.python.org/mailman/listinfo/python-list


trouble quitting PyQt4 App

2009-09-13 Thread Soumen banerjee
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.QRect(0,
0, 357, 277))
   
self.scrollAreaWidgetContents.setObjectName(scrollAreaWidgetContents)
   self.textEdit = QtGui.QTextEdit(self.scrollAreaWidgetContents)
   self.textEdit.setGeometry(QtCore.QRect(-7, -6, 371, 291))
   self.textEdit.setObjectName(textEdit)
   self.scrollArea.setWidget(self.scrollAreaWidgetContents)
   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.translate(MainWindow,
MainWindow, None, QtGui.QApplication.UnicodeUTF8))
   
self.pushButton.setText(QtGui.QApplication.translate(MainWindow,
Open, None, QtGui.QApplication.UnicodeUTF8))
   
self.pushButton_2.setText(QtGui.QApplication.translate(MainWindow,
Pause/Resume, None, QtGui.QApplication.UnicodeUTF8))
   
self.pushButton_3.setText(QtGui.QApplication.translate(MainWindow,
Quit, None, QtGui.QApplication.UnicodeUTF8))
   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')