From c6784c6b6408079ec1f0a7d7aa2e584ab3813bce Mon Sep 17 00:00:00 2001 From: BoySka Date: Fri, 28 Oct 2011 02:29:03 +0200 Subject: [PATCH] Tomb in a thread: gui don't freeze anymore --- src/gui/qt/create.py | 19 ++++++++++-- src/gui/qt/create.ui | 20 ++++++------- src/gui/qt/ui_create.py | 64 ++++++++++++++++++++--------------------- 3 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/gui/qt/create.py b/src/gui/qt/create.py index 1dc200a..d63634b 100755 --- a/src/gui/qt/create.py +++ b/src/gui/qt/create.py @@ -1,4 +1,6 @@ import sys, os +from functools import partial + from PyQt4.QtGui import QApplication, QWizard from PyQt4 import QtCore from PyQt4 import QtGui @@ -6,7 +8,7 @@ from ui_create import Ui_Wizard parentdir = sys.path[0].split(os.sep)[:-1] sys.path.append(os.sep.join(parentdir)) -from tomblib import tomb +from tomblib.tomb import Tomb try: _fromUtf8 = QtCore.QString.fromUtf8 @@ -46,9 +48,20 @@ class TombCreateWizard(QWizard): if not keyloc: raise ValueError - tomb.Tomb.create(self.ui.lineEdit_tombpath.text(), str(self.ui.spinBox_size.value()), keyloc) - self.ui.progressBar.setValue(100) + self.thread = TombCreateThread(self.ui.lineEdit_tombpath.text(), str(self.ui.spinBox_size.value()), keyloc) + 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__': app = QApplication(sys.argv) diff --git a/src/gui/qt/create.ui b/src/gui/qt/create.ui index c9275e7..3723d68 100755 --- a/src/gui/qt/create.ui +++ b/src/gui/qt/create.ui @@ -146,7 +146,7 @@ p, li { white-space: pre-wrap; } - + On a USB pen (best security) @@ -185,7 +185,7 @@ p, li { white-space: pre-wrap; } - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -200,7 +200,7 @@ p, li { white-space: pre-wrap; } - + Specify location @@ -227,14 +227,14 @@ p, li { white-space: pre-wrap; } - + false - + false @@ -268,7 +268,7 @@ p, li { white-space: pre-wrap; } Please wait - + 30 @@ -333,9 +333,9 @@ p, li { white-space: pre-wrap; } - radioButton_3 + radioButton_custom toggled(bool) - lineEdit_2 + lineEdit_custom setEnabled(bool) @@ -349,9 +349,9 @@ p, li { white-space: pre-wrap; } - radioButton_3 + radioButton_custom toggled(bool) - pushButton_2 + pushButton_custom setEnabled(bool) diff --git a/src/gui/qt/ui_create.py b/src/gui/qt/ui_create.py index c2bae30..5cb5476 100755 --- a/src/gui/qt/ui_create.py +++ b/src/gui/qt/ui_create.py @@ -2,7 +2,7 @@ # 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 # # 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_4 = QtGui.QVBoxLayout() self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) - self.radioButton = 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.setChecked(True) - self.radioButton.setObjectName(_fromUtf8("radioButton")) - self.verticalLayout_4.addWidget(self.radioButton) + self.radioButton_usb = QtGui.QRadioButton(self.wizardPage_key_location) + self.radioButton_usb.setText(QtGui.QApplication.translate("Wizard", "On a USB pen (best security)", None, QtGui.QApplication.UnicodeUTF8)) + self.radioButton_usb.setChecked(True) + self.radioButton_usb.setObjectName(_fromUtf8("radioButton_usb")) + self.verticalLayout_4.addWidget(self.radioButton_usb) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4")) 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.verticalLayout_4.addLayout(self.horizontalLayout_4) self.verticalLayout_5.addLayout(self.verticalLayout_4) - self.radioButton_2 = QtGui.QRadioButton(self.wizardPage_key_location) - self.radioButton_2.setToolTip(QtGui.QApplication.translate("Wizard", "\n" + self.radioButton_near = QtGui.QRadioButton(self.wizardPage_key_location) + self.radioButton_near.setToolTip(QtGui.QApplication.translate("Wizard", "\n" "\n" "

It will be created as a regular file in the same directory of your tomb.

\n" "

It is much easier to use, but also much more insecure: all your security will be guaranteed by your password. If you really want to do this, choose a strong password (lot of random/non-dictionary words, spaces, numbers, odd characters)

", 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_2.setObjectName(_fromUtf8("radioButton_2")) - self.verticalLayout_5.addWidget(self.radioButton_2) - self.radioButton_3 = QtGui.QRadioButton(self.wizardPage_key_location) - self.radioButton_3.setText(QtGui.QApplication.translate("Wizard", "Specify location", None, QtGui.QApplication.UnicodeUTF8)) - self.radioButton_3.setObjectName(_fromUtf8("radioButton_3")) - self.verticalLayout_5.addWidget(self.radioButton_3) + self.radioButton_near.setText(QtGui.QApplication.translate("Wizard", "Near to the tomb itself (this is BAD)", None, QtGui.QApplication.UnicodeUTF8)) + self.radioButton_near.setObjectName(_fromUtf8("radioButton_near")) + self.verticalLayout_5.addWidget(self.radioButton_near) + self.radioButton_custom = QtGui.QRadioButton(self.wizardPage_key_location) + self.radioButton_custom.setText(QtGui.QApplication.translate("Wizard", "Specify location", None, QtGui.QApplication.UnicodeUTF8)) + self.radioButton_custom.setObjectName(_fromUtf8("radioButton_custom")) + self.verticalLayout_5.addWidget(self.radioButton_custom) self.verticalLayout_6.addLayout(self.verticalLayout_5) self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem1) - self.lineEdit_2 = QtGui.QLineEdit(self.wizardPage_key_location) - self.lineEdit_2.setEnabled(False) - self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2")) - self.horizontalLayout_3.addWidget(self.lineEdit_2) - self.pushButton_2 = QtGui.QPushButton(self.wizardPage_key_location) - self.pushButton_2.setEnabled(False) - self.pushButton_2.setText(QtGui.QApplication.translate("Wizard", "Choose location", None, QtGui.QApplication.UnicodeUTF8)) - self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) - self.horizontalLayout_3.addWidget(self.pushButton_2) + self.lineEdit_custom = QtGui.QLineEdit(self.wizardPage_key_location) + self.lineEdit_custom.setEnabled(False) + self.lineEdit_custom.setObjectName(_fromUtf8("lineEdit_custom")) + self.horizontalLayout_3.addWidget(self.lineEdit_custom) + self.pushButton_custom = QtGui.QPushButton(self.wizardPage_key_location) + self.pushButton_custom.setEnabled(False) + self.pushButton_custom.setText(QtGui.QApplication.translate("Wizard", "Choose location", None, QtGui.QApplication.UnicodeUTF8)) + self.pushButton_custom.setObjectName(_fromUtf8("pushButton_custom")) + self.horizontalLayout_3.addWidget(self.pushButton_custom) self.verticalLayout_6.addLayout(self.horizontalLayout_3) self.label_11 = QtGui.QLabel(self.wizardPage_key_location) self.label_11.setText(QtGui.QApplication.translate("Wizard", "\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.setSubTitle(QtGui.QApplication.translate("Wizard", "Please wait", None, QtGui.QApplication.UnicodeUTF8)) self.wizardPage_progress.setObjectName(_fromUtf8("wizardPage_progress")) - self.widget = QtGui.QWidget(self.wizardPage_progress) - self.widget.setGeometry(QtCore.QRect(30, 30, 276, 52)) - self.widget.setObjectName(_fromUtf8("widget")) - self.verticalLayout_7 = QtGui.QVBoxLayout(self.widget) + self.layoutWidget = QtGui.QWidget(self.wizardPage_progress) + self.layoutWidget.setGeometry(QtCore.QRect(30, 30, 276, 52)) + self.layoutWidget.setObjectName(_fromUtf8("layoutWidget")) + self.verticalLayout_7 = QtGui.QVBoxLayout(self.layoutWidget) self.verticalLayout_7.setMargin(0) 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.setTextVisible(True) self.progressBar.setInvertedAppearance(False) @@ -170,7 +170,7 @@ class Ui_Wizard(object): self.verticalLayout_7.addWidget(self.progressBar) self.horizontalLayout_5 = QtGui.QHBoxLayout() 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.setObjectName(_fromUtf8("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.retranslateUi(Wizard) - QtCore.QObject.connect(self.radioButton_3, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), self.lineEdit_2.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.lineEdit_custom.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("helpRequested()")), self.label_11.show) QtCore.QMetaObject.connectSlotsByName(Wizard)