taste-progress-dialog.py 1.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#!/usr/bin/env python

import sys
import PySide
import time
import signal

from PySide.QtCore import QThread, Signal, QObject

from PySide.QtGui import (QApplication,
                          QMessageBox,
                          QProgressDialog)

class MyThread(QThread, QObject):
    signal = Signal(str)
    progress = Signal(int)
    quit = Signal()
    def run(self):
        value = 10
        while True:
            # read from stdin without any buffering
            line = sys.stdin.readline()
            if len(line) == 0:
                print ("Bye")
                self.quit.emit()
                return
            elif line[0] == 'q':
                print ("Quit")
                self.quit.emit()
                return
            else:
                self.signal.emit(line)
                self.progress.emit(value)
                value += 10
                if value == 100:
                    value = 0
                time.sleep(0.1)


def check_crazyflie():
    ''' This function should be in a different module '''
    return

def check_snoopy():
    raise NotImplementedError()


def run_gui():
        app = QApplication(sys.argv)
        thread = MyThread()       
        progress = QProgressDialog()
        progress.setValue(0)
        thread.signal.connect(progress.setLabelText)
        thread.quit.connect(progress.cancel)
        thread.progress.connect(progress.setValue)
        thread.start()
        progress.exec_()

def main():
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    run_gui()

if __name__ == '__main__':
    main()