Coverage for src / ezqt_app / widgets / ui_main.py: 97.56%

74 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-06 13:12 +0000

1# /////////////////////////////////////////////////////////////// 

2# WIDGETS.UI_MAIN - Main window user interface setup 

3# Project: ezqt_app 

4# /////////////////////////////////////////////////////////////// 

5 

6"""Ui_MainWindow — setupUi builder for the main application window.""" 

7 

8from __future__ import annotations 

9 

10# /////////////////////////////////////////////////////////////// 

11# IMPORTS 

12# /////////////////////////////////////////////////////////////// 

13# Third-party imports 

14from PySide6.QtCore import QMetaObject, QSize 

15from PySide6.QtWidgets import QFrame, QHBoxLayout, QMainWindow, QVBoxLayout, QWidget 

16 

17# Local imports 

18from ..services.settings import get_settings_service 

19from ..services.translation import get_translation_manager 

20from ..services.ui import Fonts 

21from ..widgets.core import BottomBar, Header, PageContainer 

22 

23# /////////////////////////////////////////////////////////////// 

24# CLASSES 

25# /////////////////////////////////////////////////////////////// 

26 

27 

28class Ui_MainWindow: 

29 """ 

30 Main application user interface. 

31 

32 This class defines the structure of the main user interface 

33 with all its components (header, menu, content, etc.). 

34 """ 

35 

36 # /////////////////////////////////////////////////////////////// 

37 # INIT 

38 # /////////////////////////////////////////////////////////////// 

39 

40 def __init__(self) -> None: 

41 """Initialize the main user interface.""" 

42 

43 # /////////////////////////////////////////////////////////////// 

44 # PUBLIC METHODS 

45 # /////////////////////////////////////////////////////////////// 

46 

47 def setupUi( 

48 self, 

49 MainWindow: QMainWindow, 

50 has_menu: bool = True, 

51 has_settings_panel: bool = True, 

52 ) -> None: 

53 """ 

54 Configure the main user interface. 

55 

56 Args: 

57 MainWindow: The main window to configure. 

58 has_menu: Whether to include the left menu (default: True). 

59 has_settings_panel: Whether to include the settings panel (default: True). 

60 """ 

61 if not MainWindow.objectName(): 61 ↛ 63line 61 didn't jump to line 63 because the condition on line 61 was always true

62 MainWindow.setObjectName("MainWindow") 

63 MainWindow.resize(1280, 720) 

64 MainWindow.setMinimumSize(QSize(940, 560)) 

65 settings_service = get_settings_service() 

66 

67 # Main stylesheet widget 

68 self.style_sheet = QWidget(MainWindow) 

69 self.style_sheet.setObjectName("style_sheet") 

70 if Fonts.SEGOE_UI_10_REG is not None: 70 ↛ 74line 70 didn't jump to line 74 because the condition on line 70 was always true

71 self.style_sheet.setFont(Fonts.SEGOE_UI_10_REG) 

72 

73 # Main margins layout 

74 self.app_margins_layout = QVBoxLayout(self.style_sheet) 

75 self.app_margins_layout.setSpacing(0) 

76 self.app_margins_layout.setObjectName("app_margins_layout") 

77 self.app_margins_layout.setContentsMargins(10, 10, 10, 10) 

78 

79 # Background app frame 

80 self.bg_app_frame = QFrame(self.style_sheet) 

81 self.bg_app_frame.setObjectName("bg_app_frame") 

82 self.bg_app_frame.setFrameShape(QFrame.Shape.NoFrame) 

83 self.bg_app_frame.setFrameShadow(QFrame.Shadow.Raised) 

84 self.app_margins_layout.addWidget(self.bg_app_frame) 

85 

86 # App layout 

87 self.app_layout = QVBoxLayout(self.bg_app_frame) 

88 self.app_layout.setSpacing(0) 

89 self.app_layout.setObjectName("app_layout") 

90 self.app_layout.setContentsMargins(0, 0, 0, 0) 

91 

92 # Header 

93 self.header_container = Header(parent=self.bg_app_frame) 

94 self.app_layout.addWidget(self.header_container) 

95 

96 # Content bottom frame (middle layer) 

97 self.content_bottom_frame = QFrame(self.bg_app_frame) 

98 self.content_bottom_frame.setObjectName("content_bottom_frame") 

99 self.content_bottom_frame.setFrameShape(QFrame.Shape.NoFrame) 

100 self.content_bottom_frame.setFrameShadow(QFrame.Shadow.Raised) 

101 self.app_layout.addWidget(self.content_bottom_frame) 

102 

103 # Content bottom layout (horizontal) 

104 self.content_bottom_layout = QHBoxLayout(self.content_bottom_frame) 

105 self.content_bottom_layout.setSpacing(0) 

106 self.content_bottom_layout.setObjectName("content_bottom_layout") 

107 self.content_bottom_layout.setContentsMargins(0, 0, 0, 0) 

108 

109 # Menu 

110 if has_menu: 

111 from ..widgets.core import Menu 

112 

113 self.menu_container = Menu( 

114 parent=self.content_bottom_frame, 

115 shrink_width=settings_service.gui.MENU_PANEL_SHRINKED_WIDTH, 

116 extended_width=settings_service.gui.MENU_PANEL_EXTENDED_WIDTH, 

117 ) 

118 else: 

119 from .core.null_widgets import NullMenuContainer 

120 

121 self.menu_container = NullMenuContainer(parent=self.content_bottom_frame) 

122 

123 self.content_bottom_layout.addWidget(self.menu_container) 

124 

125 # Content center frame 

126 self.content_frame = QFrame(self.content_bottom_frame) 

127 self.content_frame.setObjectName("content_frame") 

128 self.content_frame.setFrameShape(QFrame.Shape.NoFrame) 

129 self.content_frame.setFrameShadow(QFrame.Shadow.Raised) 

130 self.content_bottom_layout.addWidget(self.content_frame, 1) 

131 

132 # Content layout 

133 self.content_layout = QHBoxLayout(self.content_frame) 

134 self.content_layout.setSpacing(0) 

135 self.content_layout.setObjectName("content_layout") 

136 self.content_layout.setContentsMargins(0, 0, 0, 0) 

137 

138 # Pages container 

139 self.pages_container = PageContainer(self.content_frame) 

140 self.content_layout.addWidget(self.pages_container) 

141 

142 # Settings panel (right side) 

143 if has_settings_panel: 

144 from ..widgets.core import SettingsPanel 

145 

146 self.settings_panel = SettingsPanel( 

147 parent=self.content_bottom_frame, 

148 width=settings_service.gui.SETTINGS_PANEL_WIDTH, 

149 ) 

150 else: 

151 from .core.null_widgets import NullSettingsPanel 

152 

153 self.settings_panel = NullSettingsPanel(parent=self.content_bottom_frame) 

154 

155 self.content_bottom_layout.addWidget(self.settings_panel) 

156 

157 # Bottom bar 

158 self.bottom_bar = BottomBar(parent=self.bg_app_frame) 

159 self.app_layout.addWidget(self.bottom_bar) 

160 

161 # Translation indicators 

162 translation_manager = get_translation_manager() 

163 translation_manager.translation_started.connect( 

164 self.bottom_bar.show_translation_indicator 

165 ) 

166 translation_manager.translation_finished.connect( 

167 self.bottom_bar.hide_translation_indicator 

168 ) 

169 

170 # Finalize setup 

171 MainWindow.setCentralWidget(self.style_sheet) 

172 QMetaObject.connectSlotsByName(MainWindow) 

173 

174 

175# /////////////////////////////////////////////////////////////// 

176# PUBLIC API 

177# /////////////////////////////////////////////////////////////// 

178 

179__all__ = ["Ui_MainWindow"]