GUI: progressbar monitor tomb output

Warning: sudo behave strangely when watching both stdout and stderr
It seems to be solved watching only stderr, which is where 99% of tomb
output goes, but this is quite an hack
This commit is contained in:
BoySka 2011-10-30 22:07:16 +01:00 committed by boyska
parent 51b5394bbc
commit bbe25d0f85
5 changed files with 77 additions and 64 deletions

View File

@ -1,6 +1,6 @@
all: ui_create.py all: ui_create.py
test: ui_create.py test: ui_create.py
python2 create.py python2 -3 create.py
ui_create.py: create.ui ui_create.py: create.ui
pyuic4 create.ui -o ui_create.py pyuic4 create.ui -o ui_create.py

View File

@ -1,5 +1,5 @@
import sys, os import sys, os
from functools import partial #from functools import partial
from PyQt4.QtGui import QApplication, QWizard from PyQt4.QtGui import QApplication, QWizard
from PyQt4 import QtCore from PyQt4 import QtCore
@ -9,6 +9,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.tomb import Tomb from tomblib.tomb import Tomb
from worker import TombCreateThread
try: try:
_fromUtf8 = QtCore.QString.fromUtf8 _fromUtf8 = QtCore.QString.fromUtf8
@ -70,25 +71,15 @@ class TombCreateWizard(QWizard):
self.ui.wizardPage_progress.setFinalPage(True) self.ui.wizardPage_progress.setFinalPage(True)
self.ui.wizardPage_progress.completeChanged.emit() self.ui.wizardPage_progress.completeChanged.emit()
def create_tomb(self, *args, **kwargs): 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 = 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.finished.connect(self.on_thread_creation_finished)
self.thread.terminated.connect(self.on_thread_creation_finished) self.thread.terminated.connect(self.on_thread_creation_finished)
self.thread.line_received.connect(self.ui.textBrowser_log.append)
def err_append_to_log(text):
self.ui.textBrowser_log.append('Error: <strong>' + text + '</strong>')
self.thread.error_received.connect(err_append_to_log)
self.thread.start() 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):
self.status = Tomb.create(self.tombpath, str(self.size), self.keypath)
def get_success(self):
return self.status
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)

View File

@ -65,6 +65,9 @@
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBox_size"> <widget class="QSpinBox" name="spinBox_size">
<property name="minimum">
<number>10</number>
</property>
<property name="maximum"> <property name="maximum">
<number>100000</number> <number>100000</number>
</property> </property>
@ -280,42 +283,51 @@ 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="layoutWidget"> <layout class="QVBoxLayout" name="verticalLayout_9">
<property name="geometry"> <item>
<rect> <layout class="QVBoxLayout" name="verticalLayout_7">
<x>30</x> <item>
<y>30</y> <widget class="QProgressBar" name="progressBar">
<width>276</width> <property name="value">
<height>52</height> <number>0</number>
</rect> </property>
</property> <property name="textVisible">
<layout class="QVBoxLayout" name="verticalLayout_7"> <bool>true</bool>
<item> </property>
<widget class="QProgressBar" name="progressBar"> <property name="invertedAppearance">
<property name="value"> <bool>false</bool>
<number>0</number> </property>
</property> </widget>
<property name="textVisible"> </item>
<bool>true</bool> <item>
</property> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="invertedAppearance"> <item>
<bool>false</bool> <widget class="QLabel" name="label_progress">
</property> <property name="text">
</widget> <string>Creating tomb, please wait...</string>
</item> </property>
<item> </widget>
<layout class="QHBoxLayout" name="horizontalLayout_5"> </item>
<item> </layout>
<widget class="QLabel" name="label_progress"> </item>
<property name="text"> </layout>
<string>Creating tomb, please wait...</string> </item>
</property> <item>
</widget> <widget class="QTextBrowser" name="textBrowser_log">
</item> <property name="documentTitle">
</layout> <string>Log</string>
</item> </property>
</layout> <property name="html">
</widget> <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;title&gt;Log&lt;/title&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Log&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
<widget class="QWizardPage" name="wizardPage_end"> <widget class="QWizardPage" name="wizardPage_end">
<layout class="QVBoxLayout" name="verticalLayout_8"> <layout class="QVBoxLayout" name="verticalLayout_8">

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: Fri Oct 28 10:43:28 2011 # Created: Fri Oct 28 20:11:40 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!
@ -49,6 +49,7 @@ class Ui_Wizard(object):
self.label_3.setObjectName(_fromUtf8("label_3")) self.label_3.setObjectName(_fromUtf8("label_3"))
self.horizontalLayout.addWidget(self.label_3) self.horizontalLayout.addWidget(self.label_3)
self.spinBox_size = QtGui.QSpinBox(self.wizardPage_tomb_size) self.spinBox_size = QtGui.QSpinBox(self.wizardPage_tomb_size)
self.spinBox_size.setMinimum(10)
self.spinBox_size.setMaximum(100000) self.spinBox_size.setMaximum(100000)
self.spinBox_size.setProperty("value", 100) self.spinBox_size.setProperty("value", 100)
self.spinBox_size.setObjectName(_fromUtf8("spinBox_size")) self.spinBox_size.setObjectName(_fromUtf8("spinBox_size"))
@ -160,13 +161,11 @@ 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.layoutWidget = QtGui.QWidget(self.wizardPage_progress) self.verticalLayout_9 = QtGui.QVBoxLayout(self.wizardPage_progress)
self.layoutWidget.setGeometry(QtCore.QRect(30, 30, 276, 52)) self.verticalLayout_9.setObjectName(_fromUtf8("verticalLayout_9"))
self.layoutWidget.setObjectName(_fromUtf8("layoutWidget")) self.verticalLayout_7 = QtGui.QVBoxLayout()
self.verticalLayout_7 = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout_7.setMargin(0)
self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7")) self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
self.progressBar = QtGui.QProgressBar(self.layoutWidget) self.progressBar = QtGui.QProgressBar(self.wizardPage_progress)
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)
@ -174,11 +173,22 @@ 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_progress = QtGui.QLabel(self.layoutWidget) self.label_progress = QtGui.QLabel(self.wizardPage_progress)
self.label_progress.setText(QtGui.QApplication.translate("Wizard", "Creating tomb, please wait...", None, QtGui.QApplication.UnicodeUTF8)) self.label_progress.setText(QtGui.QApplication.translate("Wizard", "Creating tomb, please wait...", None, QtGui.QApplication.UnicodeUTF8))
self.label_progress.setObjectName(_fromUtf8("label_progress")) self.label_progress.setObjectName(_fromUtf8("label_progress"))
self.horizontalLayout_5.addWidget(self.label_progress) self.horizontalLayout_5.addWidget(self.label_progress)
self.verticalLayout_7.addLayout(self.horizontalLayout_5) self.verticalLayout_7.addLayout(self.horizontalLayout_5)
self.verticalLayout_9.addLayout(self.verticalLayout_7)
self.textBrowser_log = QtGui.QTextBrowser(self.wizardPage_progress)
self.textBrowser_log.setDocumentTitle(QtGui.QApplication.translate("Wizard", "Log", None, QtGui.QApplication.UnicodeUTF8))
self.textBrowser_log.setHtml(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\" /><title>Log</title><style type=\"text/css\">\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"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Log</span></p>\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;\"></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.textBrowser_log.setObjectName(_fromUtf8("textBrowser_log"))
self.verticalLayout_9.addWidget(self.textBrowser_log)
Wizard.addPage(self.wizardPage_progress) Wizard.addPage(self.wizardPage_progress)
self.wizardPage_end = QtGui.QWizardPage() self.wizardPage_end = QtGui.QWizardPage()
self.wizardPage_end.setObjectName(_fromUtf8("wizardPage_end")) self.wizardPage_end.setObjectName(_fromUtf8("wizardPage_end"))

View File

@ -23,7 +23,7 @@ class Tomb(object):
If you want to interact asynchronously with tomb, just do it in a separate If you want to interact asynchronously with tomb, just do it in a separate
layer. layer.
''' '''
#TODO: support setting a "pipe" to pass out/err on tombexec = 'tomb'
def _check_exec_path(self): def _check_exec_path(self):
'''Checks, using which, if tomb is available. '''Checks, using which, if tomb is available.
Returns None on error, the path on success. Returns None on error, the path on success.
@ -34,8 +34,8 @@ class Tomb(object):
return None return None
return path return path
@staticmethod @classmethod
def create(tombpath,tombsize,keypath): def create(cls, tombpath,tombsize,keypath, stdout=None, stderr=None):
'''If keypath is None, it will be created adjacent to the tomb. '''If keypath is None, it will be created adjacent to the tomb.
This is unsafe, and you should NOT do it. This is unsafe, and you should NOT do it.
@ -45,7 +45,7 @@ class Tomb(object):
if keypath is not None: if keypath is not None:
args += ['-k', keypath] args += ['-k', keypath]
try: try:
subprocess.check_call(['tomb', 'create'] + args) subprocess.check_call([cls.tombexec, 'create'] + args, stdout=stdout, stderr=stderr)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return False return False
return True return True