mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-10 23:20:57 +00:00
GUI handles errors;progresschecked by isComplete
This commit is contained in:
parent
c6784c6b64
commit
51b5394bbc
10
src/gui/qt/Makefile
Normal file
10
src/gui/qt/Makefile
Normal file
@ -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
|
@ -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)
|
||||
|
@ -147,12 +147,18 @@ p, li { white-space: pre-wrap; }
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_usb">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>On a USB pen (best security)</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -175,6 +181,9 @@ p, li { white-space: pre-wrap; }
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>If you choose to do so, do not insert it NOW. Do it when you are asked to do so</string>
|
||||
</property>
|
||||
@ -197,6 +206,9 @@ p, li { white-space: pre-wrap; }
|
||||
<property name="text">
|
||||
<string>Near to the tomb itself (this is BAD)</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -294,7 +306,7 @@ p, li { white-space: pre-wrap; }
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<widget class="QLabel" name="label_progress">
|
||||
<property name="text">
|
||||
<string>Creating tomb, please wait...</string>
|
||||
</property>
|
||||
@ -315,7 +327,7 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<widget class="QCheckBox" name="checkBox_open">
|
||||
<property name="text">
|
||||
<string>Open the just-created tomb NOW!</string>
|
||||
</property>
|
||||
|
28
src/gui/qt/ui_create.py
Executable file → Normal file
28
src/gui/qt/ui_create.py
Executable file → Normal file
@ -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):
|
||||
"<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))
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user