diff --git a/src/gui/qt/Makefile b/src/gui/qt/Makefile new file mode 100644 index 0000000..9aa5313 --- /dev/null +++ b/src/gui/qt/Makefile @@ -0,0 +1,10 @@ +all: ui_create.py +test: ui_create.py + python2 create.py +ui_create.py: create.ui + pyuic4 create.ui -o ui_create.py + +clean: + rm ui_create.py + +.PHONY: test clean diff --git a/src/gui/qt/create.py b/src/gui/qt/create.py index d63634b..6c47b09 100755 --- a/src/gui/qt/create.py +++ b/src/gui/qt/create.py @@ -26,16 +26,14 @@ class TombCreateWizard(QWizard): QtCore.QObject.connect(ui.button_tombpath, QtCore.SIGNAL(_fromUtf8('clicked()')), self.on_tomb_location_clicked) QtCore.QObject.connect(self, QtCore.SIGNAL(_fromUtf8('currentIdChanged(int)')), self.on_change_page) + def check_progress_complete(*args, **kwargs): + if self.ui.progressBar.value() == 100: + return True + return False + self.ui.wizardPage_progress.isComplete = check_progress_complete + self.finished.connect(self.on_finish) - def on_tomb_location_clicked(self, *args, **kwargs): - filename = QtGui.QFileDialog.getSaveFileName(self, 'Create Tomb', filter="*.tomb") - self.ui.lineEdit_tombpath.setText(filename) - def on_change_page(self, pagenumber): - if self.currentPage() == self.ui.wizardPage_progress: - self.create_tomb() - def create_tomb(self, *args, **kwargs): - #FIXME: this will lock up the GUI - #FIXME: no support for other keypath than "next to tomb" + def _keyloc(self): keyloc = None if self.ui.radioButton_usb.isChecked(): print 'Warning: it is not supported' @@ -47,10 +45,36 @@ class TombCreateWizard(QWizard): keyloc = self.ui.lineEdit_custom.text() if not keyloc: raise ValueError + return keyloc - 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)) + def on_tomb_location_clicked(self, *args, **kwargs): + filename = QtGui.QFileDialog.getSaveFileName(self, 'Create Tomb', filter="*.tomb") + self.ui.lineEdit_tombpath.setText(filename) + def on_change_page(self, pagenumber): + if self.currentPage() == self.ui.wizardPage_progress: + self.create_tomb() + + def on_finish(self, finishedint): + if self.currentPage() != self.ui.wizardPage_end: + #there has been an error + return + + if self.ui.checkBox_open.isChecked(): + Tomb.open(self.ui.lineEdit_tombpath.text(), self._keyloc()) + def on_thread_creation_finished(self): + if self.thread.get_success(): + self.ui.progressBar.setValue(100) + else: + self.ui.progressBar.setEnabled(False) + self.ui.label_progress.setText('Error while creating the tomb!') + self.ui.wizardPage_progress.setFinalPage(True) + self.ui.wizardPage_progress.completeChanged.emit() + def create_tomb(self, *args, **kwargs): + #TODO: report error + keyloc = self._keyloc() + self.thread = TombCreateThread(self.ui.lineEdit_tombpath.text(), str(self.ui.spinBox_size.value()), self._keyloc()) + self.thread.finished.connect(self.on_thread_creation_finished) + self.thread.terminated.connect(self.on_thread_creation_finished) self.thread.start() class TombCreateThread(QtCore.QThread): @@ -61,7 +85,10 @@ class TombCreateThread(QtCore.QThread): self.keypath = keypath def run(self): - Tomb.create(self.tombpath, str(self.size), self.keypath) + self.status = Tomb.create(self.tombpath, str(self.size), self.keypath) + + def get_success(self): + return self.status if __name__ == '__main__': app = QApplication(sys.argv) diff --git a/src/gui/qt/create.ui b/src/gui/qt/create.ui index 3723d68..9b8782e 100755 --- a/src/gui/qt/create.ui +++ b/src/gui/qt/create.ui @@ -147,12 +147,18 @@ p, li { white-space: pre-wrap; } + + false + On a USB pen (best security) - + true + + false + @@ -175,6 +181,9 @@ p, li { white-space: pre-wrap; } + + false + If you choose to do so, do not insert it NOW. Do it when you are asked to do so @@ -197,6 +206,9 @@ p, li { white-space: pre-wrap; } Near to the tomb itself (this is BAD) + + true + @@ -294,7 +306,7 @@ p, li { white-space: pre-wrap; } - + Creating tomb, please wait... @@ -315,7 +327,7 @@ p, li { white-space: pre-wrap; } - + Open the just-created tomb NOW! diff --git a/src/gui/qt/ui_create.py b/src/gui/qt/ui_create.py old mode 100755 new mode 100644 index 5cb5476..d9f5659 --- 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: Fri Oct 28 02:27:24 2011 +# Created: Fri Oct 28 10:43:28 2011 # by: PyQt4 UI code generator 4.8.5 # # WARNING! All changes made in this file will be lost! @@ -99,8 +99,10 @@ class Ui_Wizard(object): self.verticalLayout_4 = QtGui.QVBoxLayout() self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.radioButton_usb = QtGui.QRadioButton(self.wizardPage_key_location) + self.radioButton_usb.setEnabled(False) 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.setCheckable(True) + self.radioButton_usb.setChecked(False) self.radioButton_usb.setObjectName(_fromUtf8("radioButton_usb")) self.verticalLayout_4.addWidget(self.radioButton_usb) self.horizontalLayout_4 = QtGui.QHBoxLayout() @@ -108,6 +110,7 @@ class Ui_Wizard(object): spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Minimum) self.horizontalLayout_4.addItem(spacerItem) self.label_6 = QtGui.QLabel(self.wizardPage_key_location) + self.label_6.setEnabled(False) self.label_6.setText(QtGui.QApplication.translate("Wizard", "If you choose to do so, do not insert it NOW. Do it when you are asked to do so", None, QtGui.QApplication.UnicodeUTF8)) self.label_6.setObjectName(_fromUtf8("label_6")) self.horizontalLayout_4.addWidget(self.label_6) @@ -121,6 +124,7 @@ class Ui_Wizard(object): "

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_near.setText(QtGui.QApplication.translate("Wizard", "Near to the tomb itself (this is BAD)", None, QtGui.QApplication.UnicodeUTF8)) + self.radioButton_near.setChecked(True) self.radioButton_near.setObjectName(_fromUtf8("radioButton_near")) self.verticalLayout_5.addWidget(self.radioButton_near) self.radioButton_custom = QtGui.QRadioButton(self.wizardPage_key_location) @@ -170,10 +174,10 @@ 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.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) + self.label_progress = QtGui.QLabel(self.layoutWidget) + self.label_progress.setText(QtGui.QApplication.translate("Wizard", "Creating tomb, please wait...", None, QtGui.QApplication.UnicodeUTF8)) + self.label_progress.setObjectName(_fromUtf8("label_progress")) + self.horizontalLayout_5.addWidget(self.label_progress) self.verticalLayout_7.addLayout(self.horizontalLayout_5) Wizard.addPage(self.wizardPage_progress) self.wizardPage_end = QtGui.QWizardPage() @@ -184,12 +188,12 @@ class Ui_Wizard(object): self.label_10.setText(QtGui.QApplication.translate("Wizard", "You successfully created the tomb!", None, QtGui.QApplication.UnicodeUTF8)) self.label_10.setObjectName(_fromUtf8("label_10")) self.verticalLayout_8.addWidget(self.label_10) - self.checkBox = QtGui.QCheckBox(self.wizardPage_end) - self.checkBox.setText(QtGui.QApplication.translate("Wizard", "Open the just-created tomb NOW!", None, QtGui.QApplication.UnicodeUTF8)) - self.checkBox.setChecked(True) - self.checkBox.setTristate(False) - self.checkBox.setObjectName(_fromUtf8("checkBox")) - self.verticalLayout_8.addWidget(self.checkBox) + self.checkBox_open = QtGui.QCheckBox(self.wizardPage_end) + self.checkBox_open.setText(QtGui.QApplication.translate("Wizard", "Open the just-created tomb NOW!", None, QtGui.QApplication.UnicodeUTF8)) + self.checkBox_open.setChecked(True) + self.checkBox_open.setTristate(False) + self.checkBox_open.setObjectName(_fromUtf8("checkBox_open")) + self.verticalLayout_8.addWidget(self.checkBox_open) Wizard.addPage(self.wizardPage_end) self.label_3.setBuddy(self.spinBox_size) self.label_4.setBuddy(self.lineEdit_tombpath)