diff options
author | kali <kali@leap.se> | 2012-11-23 05:13:36 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-11-23 05:13:36 +0900 |
commit | 7a263b8ee74cc92ba39796cd9ad48395adfa7450 (patch) | |
tree | c3837025c602897729c23e298f93ce237776d9c1 /src/leap/gui/progress.py | |
parent | 60ae69dd79fc4a17e54e9f898b04c7130d8b9f6e (diff) |
refactor validation mixin; progress until register page
Diffstat (limited to 'src/leap/gui/progress.py')
-rw-r--r-- | src/leap/gui/progress.py | 149 |
1 files changed, 76 insertions, 73 deletions
diff --git a/src/leap/gui/progress.py b/src/leap/gui/progress.py index 331db6b2..4f3a7d81 100644 --- a/src/leap/gui/progress.py +++ b/src/leap/gui/progress.py @@ -168,13 +168,43 @@ class StepsTableWidget(QtGui.QTableWidget): class WithStepsMixIn(object): - def connect_step_status(self): - self.stepChanged.connect( - self.onStepStatusChanged) + # worker threads for checks + + def setupStepsProcessingQueue(self): + self.steps_queue = Queue.Queue() + self.stepscheck_timer = QtCore.QTimer() + self.stepscheck_timer.timeout.connect(self.processStepsQueue) + self.stepscheck_timer.start(100) + # we need to keep a reference to child threads + self.threads = [] - def connect_failstep_status(self): - self.stepFailed.connect( - self.set_failed_icon) + def do_checks(self): + + # yo dawg, I heard you like checks + # so I put a __do_checks in your do_checks + # for calling others' _do_checks + + def __do_checks(fun=None, queue=None): + + for checkcase in fun(): + checkmsg, checkfun = checkcase + + queue.put(checkmsg) + if checkfun() is False: + queue.put("failed") + break + + t = FunThread(fun=partial( + __do_checks, + fun=self._do_checks, + queue=self.steps_queue)) + t.finished.connect(self.on_checks_validation_ready) + t.begin() + self.threads.append(t) + + @QtCore.pyqtSlot() + def launch_checks(self): + self.do_checks() # slot #@QtCore.pyqtSlot(str, int) @@ -194,9 +224,9 @@ class WithStepsMixIn(object): and pass messages to the ui updater functions """ - while self.queue.qsize(): + while self.steps_queue.qsize(): try: - status = self.queue.get(0) + status = self.steps_queue.get(0) if status == "failed": self.set_failed_icon() else: @@ -300,6 +330,26 @@ class WithStepsMixIn(object): self.set_checking_icon() self.set_checked_icon(current=False) + # Sets/unsets done flag + # for isComplete checks + + def set_done(self): + self.done = True + self.completeChanged.emit() + + def set_undone(self): + self.done = False + self.completeChanged.emit() + + def is_done(self): + return self.done + + def go_back(self): + self.wizard().back() + + def go_next(self): + self.wizard().next() + """ We will use one base class for the intermediate pages @@ -318,36 +368,8 @@ class InlineValidationPage(QtGui.QWizardPage, WithStepsMixIn): def __init__(self, parent=None): super(InlineValidationPage, self).__init__(parent) - - self.queue = Queue.Queue() - self.timer = QtCore.QTimer() - self.timer.timeout.connect(self.processStepsQueue) - self.timer.start(100) - self.threads = [] - - def do_checks(self): - - # yo dawg, I heard you like checks - # so I put a __do_checks in your do_checks - # for calling others' _do_checks - - def __do_checks(fun=None, queue=None): - - for checkcase in fun(): - checkmsg, checkfun = checkcase - - queue.put(checkmsg) - if checkfun() is False: - queue.put("failed") - break - - t = FunThread(fun=partial( - __do_checks, - fun=self._do_checks, - queue=self.queue)) - t.finished.connect(self._inline_validation_ready) - t.begin() - self.threads.append(t) + self.setupStepsProcessingQueue() + self.done = False # slot @@ -356,6 +378,20 @@ class InlineValidationPage(QtGui.QWizardPage, WithStepsMixIn): self.valFrame.show() self.update() + # progress frame + + def setupValidationFrame(self): + qframe = QtGui.QFrame + valFrame = qframe() + valFrame.setFrameStyle(qframe.NoFrame) + valframeLayout = QtGui.QVBoxLayout() + zeros = (0, 0, 0, 0) + valframeLayout.setContentsMargins(*zeros) + + valframeLayout.addWidget(self.stepsTableWidget) + valFrame.setLayout(valframeLayout) + self.valFrame = valFrame + class ValidationPage(QtGui.QWizardPage, WithStepsMixIn): """ @@ -376,7 +412,7 @@ class ValidationPage(QtGui.QWizardPage, WithStepsMixIn): def __init__(self, parent=None): super(ValidationPage, self).__init__(parent) self.setupSteps() - self.connect_step_status() + #self.connect_step_status() layout = QtGui.QVBoxLayout() self.progress = QtGui.QProgressBar(self) @@ -387,48 +423,15 @@ class ValidationPage(QtGui.QWizardPage, WithStepsMixIn): self.layout = layout self.timer = QtCore.QTimer() - - self.done = False - - # Sets/unsets done flag - # for isComplete checks - - def set_done(self): - self.done = True - self.completeChanged.emit() - - def set_undone(self): self.done = False - self.completeChanged.emit() - def is_done(self): - return self.done + self.setupStepsProcessingQueue() def isComplete(self): return self.is_done() ######################## - def go_back(self): - self.wizard().back() - - def go_next(self): - self.wizard().next() - - def do_checks(self): - """ - launches a thread to do the checks - """ - signal = self.stepChanged - self.checks = FunThread( - self._do_checks(update_signal=signal)) - self.checks.finished.connect(self._do_validation) - self.checks.begin() - #logger.debug('check thread started!') - #logger.debug('waiting for it to terminate...') - # XXX needed for it to join? - self.checks.wait() - def show_progress(self): self.progress.show() self.stepsTableWidget.show() |