Tomb in a thread: gui don't freeze anymore

This commit is contained in:
BoySka 2011-10-28 02:29:03 +02:00 committed by boyska
parent 559c1d8710
commit c6784c6b64
3 changed files with 58 additions and 45 deletions

View File

@ -1,4 +1,6 @@
import sys, os import sys, os
from functools import partial
from PyQt4.QtGui import QApplication, QWizard from PyQt4.QtGui import QApplication, QWizard
from PyQt4 import QtCore from PyQt4 import QtCore
from PyQt4 import QtGui from PyQt4 import QtGui
@ -6,7 +8,7 @@ from ui_create import Ui_Wizard
parentdir = sys.path[0].split(os.sep)[:-1] parentdir = sys.path[0].split(os.sep)[:-1]
sys.path.append(os.sep.join(parentdir)) sys.path.append(os.sep.join(parentdir))
from tomblib import tomb from tomblib.tomb import Tomb
try: try:
_fromUtf8 = QtCore.QString.fromUtf8 _fromUtf8 = QtCore.QString.fromUtf8
@ -46,9 +48,20 @@ class TombCreateWizard(QWizard):
if not keyloc: if not keyloc:
raise ValueError raise ValueError
tomb.Tomb.create(self.ui.lineEdit_tombpath.text(), str(self.ui.spinBox_size.value()), keyloc) self.thread = TombCreateThread(self.ui.lineEdit_tombpath.text(), str(self.ui.spinBox_size.value()), keyloc)
self.ui.progressBar.setValue(100) self.thread.finished.connect(partial(self.ui.progressBar.setValue, 100))
self.thread.terminated.connect(partial(self.ui.progressBar.setValue, 100))
self.thread.start()
class TombCreateThread(QtCore.QThread):
def __init__(self, tombpath, size, keypath):
QtCore.QThread.__init__(self)
self.tombpath = tombpath
self.size = size
self.keypath = keypath
def run(self):
Tomb.create(self.tombpath, str(self.size), self.keypath)
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)

View File

@ -146,7 +146,7 @@ p, li { white-space: pre-wrap; }
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QRadioButton" name="radioButton"> <widget class="QRadioButton" name="radioButton_usb">
<property name="text"> <property name="text">
<string>On a USB pen (best security)</string> <string>On a USB pen (best security)</string>
</property> </property>
@ -185,7 +185,7 @@ p, li { white-space: pre-wrap; }
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioButton_2"> <widget class="QRadioButton" name="radioButton_near">
<property name="toolTip"> <property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
@ -200,7 +200,7 @@ p, li { white-space: pre-wrap; }
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QRadioButton" name="radioButton_3"> <widget class="QRadioButton" name="radioButton_custom">
<property name="text"> <property name="text">
<string>Specify location</string> <string>Specify location</string>
</property> </property>
@ -227,14 +227,14 @@ p, li { white-space: pre-wrap; }
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_2"> <widget class="QLineEdit" name="lineEdit_custom">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_2"> <widget class="QPushButton" name="pushButton_custom">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -268,7 +268,7 @@ p, li { white-space: pre-wrap; }
<property name="subTitle"> <property name="subTitle">
<string>Please wait</string> <string>Please wait</string>
</property> </property>
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>30</x> <x>30</x>
@ -333,9 +333,9 @@ p, li { white-space: pre-wrap; }
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
<sender>radioButton_3</sender> <sender>radioButton_custom</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
<receiver>lineEdit_2</receiver> <receiver>lineEdit_custom</receiver>
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -349,9 +349,9 @@ p, li { white-space: pre-wrap; }
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>radioButton_3</sender> <sender>radioButton_custom</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
<receiver>pushButton_2</receiver> <receiver>pushButton_custom</receiver>
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'create.ui' # Form implementation generated from reading ui file 'create.ui'
# #
# Created: Thu Oct 27 01:57:45 2011 # Created: Fri Oct 28 02:27:24 2011
# by: PyQt4 UI code generator 4.8.5 # by: PyQt4 UI code generator 4.8.5
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -98,11 +98,11 @@ class Ui_Wizard(object):
self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
self.verticalLayout_4 = QtGui.QVBoxLayout() self.verticalLayout_4 = QtGui.QVBoxLayout()
self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
self.radioButton = QtGui.QRadioButton(self.wizardPage_key_location) self.radioButton_usb = QtGui.QRadioButton(self.wizardPage_key_location)
self.radioButton.setText(QtGui.QApplication.translate("Wizard", "On a USB pen (best security)", None, QtGui.QApplication.UnicodeUTF8)) self.radioButton_usb.setText(QtGui.QApplication.translate("Wizard", "On a USB pen (best security)", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton.setChecked(True) self.radioButton_usb.setChecked(True)
self.radioButton.setObjectName(_fromUtf8("radioButton")) self.radioButton_usb.setObjectName(_fromUtf8("radioButton_usb"))
self.verticalLayout_4.addWidget(self.radioButton) self.verticalLayout_4.addWidget(self.radioButton_usb)
self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4")) self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Minimum) spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Minimum)
@ -113,34 +113,34 @@ class Ui_Wizard(object):
self.horizontalLayout_4.addWidget(self.label_6) self.horizontalLayout_4.addWidget(self.label_6)
self.verticalLayout_4.addLayout(self.horizontalLayout_4) self.verticalLayout_4.addLayout(self.horizontalLayout_4)
self.verticalLayout_5.addLayout(self.verticalLayout_4) self.verticalLayout_5.addLayout(self.verticalLayout_4)
self.radioButton_2 = QtGui.QRadioButton(self.wizardPage_key_location) self.radioButton_near = QtGui.QRadioButton(self.wizardPage_key_location)
self.radioButton_2.setToolTip(QtGui.QApplication.translate("Wizard", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" self.radioButton_near.setToolTip(QtGui.QApplication.translate("Wizard", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n" "p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">It will be created as a regular file in the same directory of your tomb.</p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">It will be created as a regular file in the same directory of your tomb.</p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">It is much easier to use, but also much more <span style=\" font-style:italic;\">insecure</span>: all your security will be guaranteed by your <span style=\" font-weight:600;\">password</span>. If you really want to do this, choose a strong password (lot of random/non-dictionary words, spaces, numbers, odd characters)</p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">It is much easier to use, but also much more <span style=\" font-style:italic;\">insecure</span>: all your security will be guaranteed by your <span style=\" font-weight:600;\">password</span>. If you really want to do this, choose a strong password (lot of random/non-dictionary words, spaces, numbers, odd characters)</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_2.setText(QtGui.QApplication.translate("Wizard", "Near to the tomb itself (this is BAD)", None, QtGui.QApplication.UnicodeUTF8)) self.radioButton_near.setText(QtGui.QApplication.translate("Wizard", "Near to the tomb itself (this is BAD)", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_2.setObjectName(_fromUtf8("radioButton_2")) self.radioButton_near.setObjectName(_fromUtf8("radioButton_near"))
self.verticalLayout_5.addWidget(self.radioButton_2) self.verticalLayout_5.addWidget(self.radioButton_near)
self.radioButton_3 = QtGui.QRadioButton(self.wizardPage_key_location) self.radioButton_custom = QtGui.QRadioButton(self.wizardPage_key_location)
self.radioButton_3.setText(QtGui.QApplication.translate("Wizard", "Specify location", None, QtGui.QApplication.UnicodeUTF8)) self.radioButton_custom.setText(QtGui.QApplication.translate("Wizard", "Specify location", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_3.setObjectName(_fromUtf8("radioButton_3")) self.radioButton_custom.setObjectName(_fromUtf8("radioButton_custom"))
self.verticalLayout_5.addWidget(self.radioButton_3) self.verticalLayout_5.addWidget(self.radioButton_custom)
self.verticalLayout_6.addLayout(self.verticalLayout_5) self.verticalLayout_6.addLayout(self.verticalLayout_5)
self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Minimum) spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem1) self.horizontalLayout_3.addItem(spacerItem1)
self.lineEdit_2 = QtGui.QLineEdit(self.wizardPage_key_location) self.lineEdit_custom = QtGui.QLineEdit(self.wizardPage_key_location)
self.lineEdit_2.setEnabled(False) self.lineEdit_custom.setEnabled(False)
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2")) self.lineEdit_custom.setObjectName(_fromUtf8("lineEdit_custom"))
self.horizontalLayout_3.addWidget(self.lineEdit_2) self.horizontalLayout_3.addWidget(self.lineEdit_custom)
self.pushButton_2 = QtGui.QPushButton(self.wizardPage_key_location) self.pushButton_custom = QtGui.QPushButton(self.wizardPage_key_location)
self.pushButton_2.setEnabled(False) self.pushButton_custom.setEnabled(False)
self.pushButton_2.setText(QtGui.QApplication.translate("Wizard", "Choose location", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton_custom.setText(QtGui.QApplication.translate("Wizard", "Choose location", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) self.pushButton_custom.setObjectName(_fromUtf8("pushButton_custom"))
self.horizontalLayout_3.addWidget(self.pushButton_2) self.horizontalLayout_3.addWidget(self.pushButton_custom)
self.verticalLayout_6.addLayout(self.horizontalLayout_3) self.verticalLayout_6.addLayout(self.horizontalLayout_3)
self.label_11 = QtGui.QLabel(self.wizardPage_key_location) self.label_11 = QtGui.QLabel(self.wizardPage_key_location)
self.label_11.setText(QtGui.QApplication.translate("Wizard", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" self.label_11.setText(QtGui.QApplication.translate("Wizard", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
@ -156,13 +156,13 @@ class Ui_Wizard(object):
self.wizardPage_progress.setTitle(QtGui.QApplication.translate("Wizard", "Creating", None, QtGui.QApplication.UnicodeUTF8)) self.wizardPage_progress.setTitle(QtGui.QApplication.translate("Wizard", "Creating", None, QtGui.QApplication.UnicodeUTF8))
self.wizardPage_progress.setSubTitle(QtGui.QApplication.translate("Wizard", "Please wait", None, QtGui.QApplication.UnicodeUTF8)) self.wizardPage_progress.setSubTitle(QtGui.QApplication.translate("Wizard", "Please wait", None, QtGui.QApplication.UnicodeUTF8))
self.wizardPage_progress.setObjectName(_fromUtf8("wizardPage_progress")) self.wizardPage_progress.setObjectName(_fromUtf8("wizardPage_progress"))
self.widget = QtGui.QWidget(self.wizardPage_progress) self.layoutWidget = QtGui.QWidget(self.wizardPage_progress)
self.widget.setGeometry(QtCore.QRect(30, 30, 276, 52)) self.layoutWidget.setGeometry(QtCore.QRect(30, 30, 276, 52))
self.widget.setObjectName(_fromUtf8("widget")) self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
self.verticalLayout_7 = QtGui.QVBoxLayout(self.widget) self.verticalLayout_7 = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout_7.setMargin(0) self.verticalLayout_7.setMargin(0)
self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7")) self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
self.progressBar = QtGui.QProgressBar(self.widget) self.progressBar = QtGui.QProgressBar(self.layoutWidget)
self.progressBar.setProperty("value", 0) self.progressBar.setProperty("value", 0)
self.progressBar.setTextVisible(True) self.progressBar.setTextVisible(True)
self.progressBar.setInvertedAppearance(False) self.progressBar.setInvertedAppearance(False)
@ -170,7 +170,7 @@ class Ui_Wizard(object):
self.verticalLayout_7.addWidget(self.progressBar) self.verticalLayout_7.addWidget(self.progressBar)
self.horizontalLayout_5 = QtGui.QHBoxLayout() self.horizontalLayout_5 = QtGui.QHBoxLayout()
self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5")) self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5"))
self.label_7 = QtGui.QLabel(self.widget) self.label_7 = QtGui.QLabel(self.layoutWidget)
self.label_7.setText(QtGui.QApplication.translate("Wizard", "Creating tomb, please wait...", None, QtGui.QApplication.UnicodeUTF8)) self.label_7.setText(QtGui.QApplication.translate("Wizard", "Creating tomb, please wait...", None, QtGui.QApplication.UnicodeUTF8))
self.label_7.setObjectName(_fromUtf8("label_7")) self.label_7.setObjectName(_fromUtf8("label_7"))
self.horizontalLayout_5.addWidget(self.label_7) self.horizontalLayout_5.addWidget(self.label_7)
@ -195,8 +195,8 @@ class Ui_Wizard(object):
self.label_4.setBuddy(self.lineEdit_tombpath) self.label_4.setBuddy(self.lineEdit_tombpath)
self.retranslateUi(Wizard) self.retranslateUi(Wizard)
QtCore.QObject.connect(self.radioButton_3, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.lineEdit_2.setEnabled) QtCore.QObject.connect(self.radioButton_custom, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.lineEdit_custom.setEnabled)
QtCore.QObject.connect(self.radioButton_3, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.pushButton_2.setEnabled) QtCore.QObject.connect(self.radioButton_custom, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.pushButton_custom.setEnabled)
QtCore.QObject.connect(Wizard, QtCore.SIGNAL(_fromUtf8("currentIdChanged(int)")), self.label_11.hide) QtCore.QObject.connect(Wizard, QtCore.SIGNAL(_fromUtf8("currentIdChanged(int)")), self.label_11.hide)
QtCore.QObject.connect(Wizard, QtCore.SIGNAL(_fromUtf8("helpRequested()")), self.label_11.show) QtCore.QObject.connect(Wizard, QtCore.SIGNAL(_fromUtf8("helpRequested()")), self.label_11.show)
QtCore.QMetaObject.connectSlotsByName(Wizard) QtCore.QMetaObject.connectSlotsByName(Wizard)