# Introduction to Qt - demonstrating events
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-03-31  Initial release

import  os, sys;            os.system('clear')
from    PySide6.QtWidgets   import  QApplication
from    PySide6.QtCore      import  QObject, QBasicTimer

# ================================== GUI =========================================

class GUI(QObject):

    def __init__(self):
        self.count = 0
        self.app = QApplication([])                 # Instantiate Qt framework
        super().__init__()
        self.timer = QBasicTimer()                  # self is required
        self.timer.start(1000, self)


    # print 10 times '*', then terminates
    def timerEvent(self, event):                    # event of type QTimerEvent
        print('*', end='', flush=True)
        self.count += 1
        if self.count == 10:
            self.timer.stop()
            sys.exit()

# ================================ Main ==========================================
      
gui = GUI()
gui.app.exec()                                      # start Qt thread / event loop

# ================================= End ==========================================
