2626import logging
2727import logging .handlers
2828
29- from PyQt5 import QtCore , QtWidgets
29+ from PyQt5 import QtCore
3030# specifically import from PyQt5.QtGui and QWidgets for startup time improvement :
31- from PyQt5 .QtWidgets import QMainWindow , QHBoxLayout , QVBoxLayout , QApplication , QSplashScreen
31+ from PyQt5 .QtWidgets import QMainWindow , QApplication , QSplashScreen , QWidget
3232from PyQt5 .QtGui import QPixmap , QFontDatabase
33- from PyQt5 .QtQml import QQmlEngine , qmlRegisterSingletonType , qmlRegisterType , QQmlComponent
34- from PyQt5 .QtQuickWidgets import QQuickWidget
33+ from PyQt5 .QtQml import QQmlEngine , qmlRegisterSingletonType , qmlRegisterType
3534from PyQt5 .QtCore import QObject
35+ from PyQt5 .QtQuick import QQuickView
3636
3737import platformdirs
3838
3939# importing friture.exceptionhandler also installs a temporary exception hook
4040from friture .exceptionhandler import errorBox , fileexcepthook
4141import friture
42+ from friture .main_toolbar_view_model import MainToolbarViewModel
4243from friture .playback .playback_control_view_model import PlaybackControlViewModel
4344from friture .ui_friture import Ui_MainWindow
4445from friture .about import About_Dialog # About dialog
6667from friture .spectrum_data import Spectrum_Data
6768from friture .plotFilledCurve import PlotFilledCurve
6869from friture .filled_curve import FilledCurve
69- from friture .qml_tools import qml_url , raise_if_error , component_raise_if_error
70+ from friture .qml_tools import qml_url , view_raise_if_error
7071from friture .generators .sine import Sine_Generator_Settings_View_Model
7172from friture .generators .white import White_Generator_Settings_View_Model
7273from friture .generators .pink import Pink_Generator_Settings_View_Model
@@ -113,6 +114,7 @@ def __init__(self):
113114 qmlRegisterType (LevelViewModel , 'Friture' , 1 , 0 , 'LevelViewModel' )
114115 qmlRegisterType (PlaybackControlViewModel , 'Friture' , 1 , 0 , 'PlaybackControlViewModel' )
115116 qmlRegisterType (MainWindowViewModel , 'Friture' , 1 , 0 , 'MainWindowViewModel' )
117+ qmlRegisterType (MainToolbarViewModel , 'Friture' , 1 , 0 , 'MainToolbarViewModel' )
116118 qmlRegisterType (Axis , 'Friture' , 1 , 0 , 'Axis' )
117119 qmlRegisterType (Curve , 'Friture' , 1 , 0 , 'Curve' )
118120 qmlRegisterType (FilledCurve , 'Friture' , 1 , 0 , 'FilledCurve' )
@@ -156,35 +158,22 @@ def __init__(self):
156158 self .about_dialog = About_Dialog (self , self .slow_timer )
157159 self .settings_dialog = Settings_Dialog (self )
158160
159- self .centralQuickWidget = QQuickWidget (self .qml_engine , self )
160- self .centralQuickWidget .setObjectName ("centralQuickWidget" )
161- self .centralQuickWidget .setSizePolicy (QtWidgets .QSizePolicy .Expanding , QtWidgets .QSizePolicy .Expanding )
162- self .centralQuickWidget .setResizeMode (QQuickWidget .SizeRootObjectToView )
163- self .centralQuickWidget .setSource (qml_url ("FritureHost.qml" ))
164-
165- raise_if_error (self .centralQuickWidget )
161+ self ._main_window_view_model = MainWindowViewModel (self .qml_engine )
166162
167- self .hboxLayout = QHBoxLayout (self .ui .centralwidget )
168- self .hboxLayout .setContentsMargins (0 , 0 , 0 , 0 )
169- self .hboxLayout .addWidget (self .centralQuickWidget )
163+ self .quick_view = QQuickView (self .qml_engine , None )
164+ self .quick_view .setResizeMode (QQuickView .SizeRootObjectToView )
165+ self .quick_view .setInitialProperties ({
166+ "main_window_view_model" : self ._main_window_view_model ,
167+ "fixedFont" : QFontDatabase .systemFont (QFontDatabase .FixedFont ).family ()
168+ })
169+ self .quick_view .setSource (qml_url ("FritureMainWindow.qml" ))
170170
171- qml_component = QQmlComponent (self .qml_engine )
172- qml_component .loadUrl (qml_url ("MainWindow.qml" ))
173- component_raise_if_error (qml_component )
171+ view_raise_if_error (self .quick_view )
174172
175- self ._main_window_view_model = MainWindowViewModel (self .qml_engine )
173+ self .quick_container = QWidget .createWindowContainer (self .quick_view , self )
174+ self .setCentralWidget (self .quick_container )
176175
177- context = self .qml_engine .rootContext ()
178- central_widget_root = qml_component .createWithInitialProperties (
179- {
180- "main_window_view_model" : self ._main_window_view_model ,
181- "fixedFont" : QFontDatabase .systemFont (QFontDatabase .FixedFont ).family ()
182- },
183- context ) # type: ignore
184- central_widget_root .setParent (self .qml_engine )
185- central_widget_root .setParentItem (self .centralQuickWidget .rootObject ()) # type: ignore
186-
187- self .main_tile_layout = central_widget_root .findChild (QObject , "main_tile_layout" )
176+ self .main_tile_layout = self .quick_view .findChild (QObject , "main_tile_layout" )
188177 assert self .main_tile_layout is not None , "Main tile layout not found in CentralWidget.qml"
189178
190179 self .level_widget = Levels_Widget (self , self ._main_window_view_model .level_view_model )
@@ -201,10 +190,10 @@ def __init__(self):
201190 self .display_timer .timeout .connect (AudioBackend ().fetchAudioData )
202191
203192 # toolbar clicks
204- self .ui . actionStart . triggered .connect (self .timer_toggle )
205- self .ui . actionSettings . triggered .connect (self .settings_called )
206- self .ui . actionAbout . triggered .connect (self .about_called )
207- self .ui . actionNew_dock . triggered .connect (self .dockmanager . new_dock )
193+ self ._main_window_view_model . toolbar_view_model . recording_clicked .connect (self .timer_toggle )
194+ self ._main_window_view_model . toolbar_view_model . new_dock_clicked .connect (self .dockmanager . new_dock )
195+ self ._main_window_view_model . toolbar_view_model . settings_clicked .connect (self .settings_called )
196+ self ._main_window_view_model . toolbar_view_model . about_clicked .connect (self .about_called )
208197 self .playback_widget .recording_toggled .connect (self .timer_changed )
209198
210199 # settings changes
@@ -214,15 +203,6 @@ def __init__(self):
214203 # restore the settings and widgets geometries
215204 self .restoreAppState ()
216205
217- # make sure the toolbar is shown
218- # in case it was closed by mistake (before it was made impossible)
219- self .ui .toolBar .setVisible (True )
220-
221- # prevent from hiding or moving the toolbar
222- self .ui .toolBar .toggleViewAction ().setVisible (False )
223- self .ui .toolBar .setMovable (False )
224- self .ui .toolBar .setFloatable (False )
225-
226206 # start timers
227207 self .timer_toggle ()
228208 self .slow_timer .start ()
@@ -341,14 +321,14 @@ def timer_toggle(self):
341321 if self .display_timer .isActive ():
342322 self .logger .info ("Timer stop" )
343323 self .display_timer .stop ()
344- self .ui . actionStart . setText ( "Start" )
324+ self ._main_window_view_model . toolbar_view_model . recording = False
345325 self .playback_widget .stop_recording ()
346326 AudioBackend ().pause ()
347327 self .dockmanager .pause ()
348328 else :
349329 self .logger .info ("Timer start" )
350330 self .display_timer .start ()
351- self .ui . actionStart . setText ( "Stop" )
331+ self ._main_window_view_model . toolbar_view_model . recording = True
352332 self .playback_widget .start_recording ()
353333 AudioBackend ().restart ()
354334 self .dockmanager .restart ()
@@ -358,15 +338,15 @@ def timer_changed(self, recording: bool):
358338 if not recording and self .display_timer .isActive ():
359339 self .logger .info ("Timer stop" )
360340 self .display_timer .stop ()
361- self .ui . actionStart . setText ( "Start" )
341+ self ._main_window_view_model . toolbar_view_model . recording = False
362342 self .playback_widget .stop_recording ()
363343 AudioBackend ().pause ()
364344 self .dockmanager .pause ()
365345
366346 if recording and not self .display_timer .isActive ():
367347 self .logger .info ("Timer start" )
368348 self .display_timer .start ()
369- self .ui . actionStart . setText ( "Stop" )
349+ self ._main_window_view_model . toolbar_view_model . recording = True
370350 self .playback_widget .start_recording ()
371351 AudioBackend ().restart ()
372352 self .dockmanager .restart ()
0 commit comments