mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-10 23:20:57 +00:00
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:
parent
51b5394bbc
commit
bbe25d0f85
@ -1,6 +1,6 @@
|
||||
all: ui_create.py
|
||||
test: ui_create.py
|
||||
python2 create.py
|
||||
python2 -3 create.py
|
||||
ui_create.py: create.ui
|
||||
pyuic4 create.ui -o ui_create.py
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import sys, os
|
||||
from functools import partial
|
||||
#from functools import partial
|
||||
|
||||
from PyQt4.QtGui import QApplication, QWizard
|
||||
from PyQt4 import QtCore
|
||||
@ -9,6 +9,7 @@ from ui_create import Ui_Wizard
|
||||
parentdir = sys.path[0].split(os.sep)[:-1]
|
||||
sys.path.append(os.sep.join(parentdir))
|
||||
from tomblib.tomb import Tomb
|
||||
from worker import TombCreateThread
|
||||
|
||||
try:
|
||||
_fromUtf8 = QtCore.QString.fromUtf8
|
||||
@ -70,25 +71,15 @@ class TombCreateWizard(QWizard):
|
||||
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.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()
|
||||
|
||||
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__':
|
||||
app = QApplication(sys.argv)
|
||||
|
@ -65,6 +65,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_size">
|
||||
<property name="minimum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100000</number>
|
||||
</property>
|
||||
@ -280,42 +283,51 @@ p, li { white-space: pre-wrap; }
|
||||
<property name="subTitle">
|
||||
<string>Please wait</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>30</y>
|
||||
<width>276</width>
|
||||
<height>52</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_progress">
|
||||
<property name="text">
|
||||
<string>Creating tomb, please wait...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_progress">
|
||||
<property name="text">
|
||||
<string>Creating tomb, please wait...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textBrowser_log">
|
||||
<property name="documentTitle">
|
||||
<string>Log</string>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!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" /><title>Log</title><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<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>
|
||||
<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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="wizardPage_end">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 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
|
||||
#
|
||||
# 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.horizontalLayout.addWidget(self.label_3)
|
||||
self.spinBox_size = QtGui.QSpinBox(self.wizardPage_tomb_size)
|
||||
self.spinBox_size.setMinimum(10)
|
||||
self.spinBox_size.setMaximum(100000)
|
||||
self.spinBox_size.setProperty("value", 100)
|
||||
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.setSubTitle(QtGui.QApplication.translate("Wizard", "Please wait", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.wizardPage_progress.setObjectName(_fromUtf8("wizardPage_progress"))
|
||||
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_9 = QtGui.QVBoxLayout(self.wizardPage_progress)
|
||||
self.verticalLayout_9.setObjectName(_fromUtf8("verticalLayout_9"))
|
||||
self.verticalLayout_7 = QtGui.QVBoxLayout()
|
||||
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.setTextVisible(True)
|
||||
self.progressBar.setInvertedAppearance(False)
|
||||
@ -174,11 +173,22 @@ class Ui_Wizard(object):
|
||||
self.verticalLayout_7.addWidget(self.progressBar)
|
||||
self.horizontalLayout_5 = QtGui.QHBoxLayout()
|
||||
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.setObjectName(_fromUtf8("label_progress"))
|
||||
self.horizontalLayout_5.addWidget(self.label_progress)
|
||||
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)
|
||||
self.wizardPage_end = QtGui.QWizardPage()
|
||||
self.wizardPage_end.setObjectName(_fromUtf8("wizardPage_end"))
|
||||
|
@ -23,7 +23,7 @@ class Tomb(object):
|
||||
If you want to interact asynchronously with tomb, just do it in a separate
|
||||
layer.
|
||||
'''
|
||||
#TODO: support setting a "pipe" to pass out/err on
|
||||
tombexec = 'tomb'
|
||||
def _check_exec_path(self):
|
||||
'''Checks, using which, if tomb is available.
|
||||
Returns None on error, the path on success.
|
||||
@ -34,8 +34,8 @@ class Tomb(object):
|
||||
return None
|
||||
return path
|
||||
|
||||
@staticmethod
|
||||
def create(tombpath,tombsize,keypath):
|
||||
@classmethod
|
||||
def create(cls, tombpath,tombsize,keypath, stdout=None, stderr=None):
|
||||
'''If keypath is None, it will be created adjacent to the tomb.
|
||||
This is unsafe, and you should NOT do it.
|
||||
|
||||
@ -45,7 +45,7 @@ class Tomb(object):
|
||||
if keypath is not None:
|
||||
args += ['-k', keypath]
|
||||
try:
|
||||
subprocess.check_call(['tomb', 'create'] + args)
|
||||
subprocess.check_call([cls.tombexec, 'create'] + args, stdout=stdout, stderr=stderr)
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user