class Friture(QMainWindow, ): def __init__(self, logger): QMainWindow.__init__(self) # logger self.logger = logger # Setup the user interface self.ui = Ui_MainWindow() self.ui.setupUi(self) # Initialize the audio data ring buffer self.audiobuffer = AudioBuffer(self.logger) # Initialize the audio backend self.audiobackend = AudioBackend(self.logger) # signal containing new data from the audio callback thread, processed as numpy array self.audiobackend.new_data_available.connect(self.audiobuffer.handle_new_data) # this timer is used to update widgets that just need to display as fast as they can self.display_timer = QtCore.QTimer() self.display_timer.setInterval(SMOOTH_DISPLAY_TIMER_PERIOD_MS) # constant timing # slow timer self.slow_timer = QtCore.QTimer() self.slow_timer.setInterval(SLOW_TIMER_PERIOD_MS) # constant timing self.about_dialog = About_Dialog(self, self.logger, self.audiobackend, self.slow_timer) self.settings_dialog = Settings_Dialog(self, self.logger, self.audiobackend) self.centralwidget = CentralWidget(self.ui.centralwidget, self.logger, "central_widget", 0) self.centralLayout = QVBoxLayout(self.ui.centralwidget) self.centralLayout.setContentsMargins(0, 0, 0, 0) self.centralLayout.addWidget(self.centralwidget) self.dockmanager = DockManager(self, self.logger) # timer ticks self.display_timer.timeout.connect(self.centralwidget.canvasUpdate) self.display_timer.timeout.connect(self.dockmanager.canvasUpdate) # toolbar clicks self.ui.actionStart.triggered.connect(self.timer_toggle) self.ui.actionSettings.triggered.connect(self.settings_called) self.ui.actionAbout.triggered.connect(self.about_called) self.ui.actionNew_dock.triggered.connect(self.dockmanager.new_dock) # restore the settings and widgets geometries self.restoreAppState() # start timers self.timer_toggle() self.slow_timer.start() self.logger.push("Init finished, entering the main loop") # slot def settings_called(self): self.settings_dialog.show() # slot def about_called(self): self.about_dialog.show() # event handler def closeEvent(self, event): self.audiobackend.close() self.saveAppState() event.accept() # method def saveAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.saveState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.saveState(settings) settings.endGroup() settings.beginGroup("MainWindow") windowGeometry = self.saveGeometry() settings.setValue("windowGeometry", windowGeometry) windowState = self.saveState() settings.setValue("windowState", windowState) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.saveState(settings) settings.endGroup() # method def restoreAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.restoreState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.restoreState(settings) settings.endGroup() settings.beginGroup("MainWindow") self.restoreGeometry(settings.value("windowGeometry", type=QtCore.QByteArray)) self.restoreState(settings.value("windowState", type=QtCore.QByteArray)) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.restoreState(settings) settings.endGroup() # slot def timer_toggle(self): if self.display_timer.isActive(): self.logger.push("Timer stop") self.display_timer.stop() self.ui.actionStart.setText("Start") self.audiobackend.pause() self.centralwidget.pause() self.dockmanager.pause() else: self.logger.push("Timer start") self.display_timer.start() self.ui.actionStart.setText("Stop") self.audiobackend.restart() self.centralwidget.restart() self.dockmanager.restart()
class Friture(QMainWindow, ): def __init__(self, logger): QMainWindow.__init__(self) # logger self.logger = logger # Setup the user interface self.ui = Ui_MainWindow() self.ui.setupUi(self) # sharedGLWidget is a hidden GL widget that will be used as a parent # to all QGLWidgets so that they have the same GL context, and can # share display lists, etc. self.sharedGLWidget = QtOpenGL.QGLWidget(self) self.sharedGLWidget.hide() # Initialize the audio data ring buffer self.audiobuffer = AudioBuffer(self.logger) # Initialize the audio backend self.audiobackend = AudioBackend(self.logger) # this timer is used to update widgets that just need to display as fast as they can self.display_timer = QtCore.QTimer() self.display_timer.setInterval(SMOOTH_DISPLAY_TIMER_PERIOD_MS) # constant timing # slow timer self.slow_timer = QtCore.QTimer() self.slow_timer.setInterval(SLOW_TIMER_PERIOD_MS) # constant timing self.about_dialog = About_Dialog(self, self.logger, self.audiobackend, self.slow_timer) self.settings_dialog = Settings_Dialog(self, self.logger, self.audiobackend) self.centralwidget = CentralWidget(self.ui.centralwidget, self.sharedGLWidget, self.logger, "central_widget", 0) self.centralLayout = QVBoxLayout(self.ui.centralwidget) self.centralLayout.setContentsMargins(0, 0, 0, 0) self.centralLayout.addWidget(self.centralwidget) self.dockmanager = DockManager(self, self.sharedGLWidget, self.logger) # timer ticks self.connect(self.display_timer, QtCore.SIGNAL('timeout()'), self.update_buffer) self.connect(self.display_timer, QtCore.SIGNAL('timeout()'), self.centralwidget.update) self.connect(self.display_timer, QtCore.SIGNAL('timeout()'), self.dockmanager.update) # toolbar clicks self.connect(self.ui.actionStart, QtCore.SIGNAL('triggered()'), self.timer_toggle) self.connect(self.ui.actionSettings, QtCore.SIGNAL('triggered()'), self.settings_called) self.connect(self.ui.actionAbout, QtCore.SIGNAL('triggered()'), self.about_called) self.connect(self.ui.actionNew_dock, QtCore.SIGNAL('triggered()'), self.dockmanager.new_dock) # restore the settings and widgets geometries self.restoreAppState() # start timers self.timer_toggle() self.slow_timer.start() self.logger.push("Init finished, entering the main loop") # slot def settings_called(self): self.settings_dialog.show() # slot def about_called(self): self.about_dialog.show() # event handler def closeEvent(self, event): self.saveAppState() event.accept() # method def saveAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.saveState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.saveState(settings) settings.endGroup() settings.beginGroup("MainWindow") windowGeometry = self.saveGeometry() settings.setValue("windowGeometry", windowGeometry) windowState = self.saveState() settings.setValue("windowState", windowState) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.saveState(settings) settings.endGroup() # method def restoreAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.restoreState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.restoreState(settings) settings.endGroup() settings.beginGroup("MainWindow") self.restoreGeometry(settings.value("windowGeometry").toByteArray()) self.restoreState(settings.value("windowState").toByteArray()) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.restoreState(settings) settings.endGroup() # slot def timer_toggle(self): if self.display_timer.isActive(): self.logger.push("Timer stop") self.display_timer.stop() self.ui.actionStart.setText("Start") self.centralwidget.pause() self.dockmanager.pause() else: self.logger.push("Timer start") self.display_timer.start() self.ui.actionStart.setText("Stop") self.centralwidget.restart() self.dockmanager.restart() # slot def update_buffer(self): newpoints = self.audiobackend.update(self.audiobuffer.ringbuffer) self.audiobuffer.set_newdata(newpoints)
class Friture( QMainWindow, ): def __init__(self, logger): QMainWindow.__init__(self) # exception hook that logs to console, file, and display a message box self.errorDialogOpened = False sys.excepthook = self.excepthook # logger self.logger = logger # Setup the user interface self.ui = Ui_MainWindow() self.ui.setupUi(self) # Initialize the audio data ring buffer self.audiobuffer = AudioBuffer(self.logger) # Initialize the audio backend self.audiobackend = AudioBackend(self.logger) # signal containing new data from the audio callback thread, processed as numpy array self.audiobackend.new_data_available.connect( self.audiobuffer.handle_new_data) # this timer is used to update widgets that just need to display as fast as they can self.display_timer = QtCore.QTimer() self.display_timer.setInterval( SMOOTH_DISPLAY_TIMER_PERIOD_MS) # constant timing # slow timer self.slow_timer = QtCore.QTimer() self.slow_timer.setInterval(SLOW_TIMER_PERIOD_MS) # constant timing self.about_dialog = About_Dialog(self, self.logger, self.audiobackend, self.slow_timer) self.settings_dialog = Settings_Dialog(self, self.logger, self.audiobackend) self.centralwidget = CentralWidget(self.ui.centralwidget, self.logger, "central_widget", 0) self.centralLayout = QVBoxLayout(self.ui.centralwidget) self.centralLayout.setContentsMargins(0, 0, 0, 0) self.centralLayout.addWidget(self.centralwidget) self.dockmanager = DockManager(self, self.logger) # timer ticks self.display_timer.timeout.connect(self.centralwidget.canvasUpdate) self.display_timer.timeout.connect(self.dockmanager.canvasUpdate) # toolbar clicks self.ui.actionStart.triggered.connect(self.timer_toggle) self.ui.actionSettings.triggered.connect(self.settings_called) self.ui.actionAbout.triggered.connect(self.about_called) self.ui.actionNew_dock.triggered.connect(self.dockmanager.new_dock) # restore the settings and widgets geometries self.restoreAppState() # start timers self.timer_toggle() self.slow_timer.start() self.logger.push("Init finished, entering the main loop") # exception hook that logs to console, file, and display a message box def excepthook(self, exception_type, exception_value, traceback_object): gui_message = fileexcepthook(exception_type, exception_value, traceback_object) # we do not want to flood the user with message boxes when the error happens repeatedly on each timer event if not self.errorDialogOpened: self.errorDialogOpened = True errorBox(gui_message) self.errorDialogOpened = False # slot def settings_called(self): self.settings_dialog.show() # slot def about_called(self): self.about_dialog.show() # event handler def closeEvent(self, event): self.audiobackend.close() self.saveAppState() event.accept() # method def saveAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.saveState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.saveState(settings) settings.endGroup() settings.beginGroup("MainWindow") windowGeometry = self.saveGeometry() settings.setValue("windowGeometry", windowGeometry) windowState = self.saveState() settings.setValue("windowState", windowState) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.saveState(settings) settings.endGroup() # method def restoreAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.restoreState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.restoreState(settings) settings.endGroup() settings.beginGroup("MainWindow") self.restoreGeometry( settings.value("windowGeometry", type=QtCore.QByteArray)) self.restoreState(settings.value("windowState", type=QtCore.QByteArray)) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.restoreState(settings) settings.endGroup() # slot def timer_toggle(self): if self.display_timer.isActive(): self.logger.push("Timer stop") self.display_timer.stop() self.ui.actionStart.setText("Start") self.audiobackend.pause() self.centralwidget.pause() self.dockmanager.pause() else: self.logger.push("Timer start") self.display_timer.start() self.ui.actionStart.setText("Stop") self.audiobackend.restart() self.centralwidget.restart() self.dockmanager.restart()
class Friture( QMainWindow, ): def __init__(self, logger): QMainWindow.__init__(self) # logger self.logger = logger # Setup the user interface self.ui = Ui_MainWindow() self.ui.setupUi(self) # sharedGLWidget is a hidden GL widget that will be used as a parent # to all QGLWidgets so that they have the same GL context, and can # share display lists, etc. self.sharedGLWidget = QtOpenGL.QGLWidget(self) self.sharedGLWidget.hide() # Initialize the audio data ring buffer self.audiobuffer = AudioBuffer(self.logger) # Initialize the audio backend self.audiobackend = AudioBackend(self.logger) # this timer is used to update widgets that just need to display as fast as they can self.display_timer = QtCore.QTimer() self.display_timer.setInterval( SMOOTH_DISPLAY_TIMER_PERIOD_MS) # constant timing # slow timer self.slow_timer = QtCore.QTimer() self.slow_timer.setInterval(SLOW_TIMER_PERIOD_MS) # constant timing self.about_dialog = About_Dialog(self, self.logger, self.audiobackend, self.slow_timer) self.settings_dialog = Settings_Dialog(self, self.logger, self.audiobackend) self.centralwidget = CentralWidget(self.ui.centralwidget, self.sharedGLWidget, self.logger, "central_widget", 0) self.centralLayout = QVBoxLayout(self.ui.centralwidget) self.centralLayout.setContentsMargins(0, 0, 0, 0) self.centralLayout.addWidget(self.centralwidget) self.dockmanager = DockManager(self, self.sharedGLWidget, self.logger) # timer ticks self.display_timer.timeout.connect(self.update_buffer) self.display_timer.timeout.connect(self.centralwidget.update) self.display_timer.timeout.connect(self.dockmanager.update) # toolbar clicks self.ui.actionStart.triggered.connect(self.timer_toggle) self.ui.actionSettings.triggered.connect(self.settings_called) self.ui.actionAbout.triggered.connect(self.about_called) self.ui.actionNew_dock.triggered.connect(self.dockmanager.new_dock) # restore the settings and widgets geometries self.restoreAppState() # start timers self.timer_toggle() self.slow_timer.start() self.logger.push("Init finished, entering the main loop") # slot def settings_called(self): self.settings_dialog.show() # slot def about_called(self): self.about_dialog.show() # event handler def closeEvent(self, event): self.saveAppState() event.accept() # method def saveAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.saveState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.saveState(settings) settings.endGroup() settings.beginGroup("MainWindow") windowGeometry = self.saveGeometry() settings.setValue("windowGeometry", windowGeometry) windowState = self.saveState() settings.setValue("windowState", windowState) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.saveState(settings) settings.endGroup() # method def restoreAppState(self): settings = QtCore.QSettings("Friture", "Friture") settings.beginGroup("Docks") self.dockmanager.restoreState(settings) settings.endGroup() settings.beginGroup("CentralWidget") self.centralwidget.restoreState(settings) settings.endGroup() settings.beginGroup("MainWindow") self.restoreGeometry( settings.value("windowGeometry", type=QtCore.QByteArray)) self.restoreState(settings.value("windowState", type=QtCore.QByteArray)) settings.endGroup() settings.beginGroup("AudioBackend") self.settings_dialog.restoreState(settings) settings.endGroup() # slot def timer_toggle(self): if self.display_timer.isActive(): self.logger.push("Timer stop") self.display_timer.stop() self.ui.actionStart.setText("Start") self.centralwidget.pause() self.dockmanager.pause() else: self.logger.push("Timer start") self.display_timer.start() self.ui.actionStart.setText("Stop") self.centralwidget.restart() self.dockmanager.restart() # slot def update_buffer(self): newpoints = self.audiobackend.update(self.audiobuffer.ringbuffer) self.audiobuffer.set_newdata(newpoints)