-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_main_window.py
More file actions
256 lines (238 loc) · 10.9 KB
/
ui_main_window.py
File metadata and controls
256 lines (238 loc) · 10.9 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
"""Qt widgets for the main application window."""
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import (
QGroupBox,
QComboBox,
QHBoxLayout,
QLabel,
QLineEdit,
QSlider,
QListWidget,
QMainWindow,
QMenu,
QMenuBar,
QPushButton,
QSplitter,
QStatusBar,
QTextEdit,
QToolButton,
QVBoxLayout,
QWidget,
)
from PyQt6.QtCore import Qt
from app.gui.settings_dialog import SettingsEditor
from app.model.app_settings import AppSettings
from app.model.ssml.ssml_config import SSMLConfig
class Ui_MainWindow:
"""
Richer in-repo UI definition inspired by the donor project.
"""
def setupUi(self, main_window):
main_window.setWindowTitle("Text To Speech")
central_widget = QWidget(main_window)
outer_layout = QHBoxLayout(central_widget)
main_panel = QWidget(central_widget)
root_layout = QVBoxLayout(main_panel)
outer_layout.addWidget(main_panel, 1)
self.audioControlsGroup = QGroupBox("Actions", central_widget)
action_row = QHBoxLayout(self.audioControlsGroup)
self.previewButton = QPushButton("Preview SSML", self.audioControlsGroup)
self.cleanTextButton = QPushButton("Clean Text", self.audioControlsGroup)
self.playButton = QPushButton("Generate && Play", self.audioControlsGroup)
self.generateButton = QPushButton("Generate File", self.audioControlsGroup)
self.stopButton = QPushButton("Stop", self.audioControlsGroup)
self.cancelTaskButton = QPushButton("Cancel Task", self.audioControlsGroup)
self.cancelTaskButton.setEnabled(False)
self.openSecondWindowButton = QPushButton(
"Import Document",
self.audioControlsGroup,
)
self.openSettingsButton = QPushButton(
"Settings",
self.audioControlsGroup,
)
for button in (
self.previewButton,
self.cleanTextButton,
self.playButton,
self.generateButton,
self.stopButton,
self.cancelTaskButton,
self.openSecondWindowButton,
self.openSettingsButton,
):
action_row.addWidget(button)
self.playbackVolumeSlider = QSlider(
Qt.Orientation.Horizontal,
self.audioControlsGroup,
)
self.playbackVolumeSlider.setRange(0, 100)
self.playbackVolumeSlider.setValue(80)
self.playbackVolumeSlider.setToolTip("Playback Volume")
self.playbackVolumeValueLabel = QLabel("80%", self.audioControlsGroup)
action_row.addStretch(1)
action_row.addWidget(self.playbackVolumeSlider)
action_row.addWidget(self.playbackVolumeValueLabel)
root_layout.addWidget(self.audioControlsGroup)
self.narrationControlsGroup = QGroupBox("Narration Section", central_widget)
narration_row = QHBoxLayout(self.narrationControlsGroup)
self.narrationSpeakerEdit = QLineEdit(self.narrationControlsGroup)
self.narrationSpeakerEdit.setPlaceholderText("Speaker")
self.narrationVoiceCombo = QComboBox(self.narrationControlsGroup)
self.narrationVoiceCombo.setEditable(True)
self.narrationVoiceCombo.addItems(SSMLConfig().list_voices())
self.narrationRateCombo = QComboBox(self.narrationControlsGroup)
self.narrationRateCombo.addItems(
["default", "x-slow", "slow", "medium", "fast", "x-fast"]
)
self.narrationVolumeCombo = QComboBox(self.narrationControlsGroup)
self.narrationVolumeCombo.addItems(
["default", "silent", "x-soft", "soft", "medium", "loud", "x-loud"]
)
self.narrationPauseCombo = QComboBox(self.narrationControlsGroup)
self.narrationPauseCombo.addItems(["none", "250ms", "500ms", "1s", "2s"])
self.applyNarrationButton = QPushButton(
"Apply To Selection",
self.narrationControlsGroup,
)
for label_text, widget in (
("Speaker", self.narrationSpeakerEdit),
("Voice", self.narrationVoiceCombo),
("Rate", self.narrationRateCombo),
("Volume", self.narrationVolumeCombo),
("Pause", self.narrationPauseCombo),
):
narration_row.addWidget(QLabel(label_text, self.narrationControlsGroup))
narration_row.addWidget(widget)
narration_row.addStretch(1)
narration_row.addWidget(self.applyNarrationButton)
root_layout.addWidget(self.narrationControlsGroup)
self.actionHintLabel = QLabel(
"Type or import text to enable preview and generation actions.",
central_widget,
)
self.actionHintLabel.setObjectName("actionHintLabel")
self.actionHintLabel.setWordWrap(True)
root_layout.addWidget(self.actionHintLabel)
content_row = QHBoxLayout()
self.editorSplitter = QSplitter(Qt.Orientation.Horizontal, central_widget)
self.textEdit = QTextEdit(self.editorSplitter)
self.textEdit.setPlaceholderText(
"Type or paste text here, or import text from a supported document."
)
self.ssmlPreview = QTextEdit(self.editorSplitter)
self.ssmlPreview.setReadOnly(True)
self.ssmlPreview.setPlaceholderText("Generated SSML preview appears here.")
self.editorSplitter.addWidget(self.textEdit)
self.editorSplitter.addWidget(self.ssmlPreview)
self.editorSplitter.setSizes([700, 500])
content_row.addWidget(self.editorSplitter, 1)
root_layout.addLayout(content_row, 1)
self.historyGroup = QGroupBox(central_widget)
self.historyGroup.setObjectName("historyGroup")
history_layout = QVBoxLayout(self.historyGroup)
history_layout.setContentsMargins(10, 6, 10, 10)
history_layout.setSpacing(4)
self.historyHeader = QWidget(self.historyGroup)
self.historyHeader.setObjectName("historyHeader")
history_header_layout = QHBoxLayout(self.historyHeader)
history_header_layout.setContentsMargins(0, 0, 0, 0)
self.historyTitleLabel = QLabel("Recent Audio", self.historyHeader)
self.historyTitleLabel.setObjectName("historyTitleLabel")
history_header_layout.addWidget(self.historyTitleLabel)
history_header_layout.addStretch(1)
self.historyToggleButton = QToolButton(self.historyGroup)
self.historyToggleButton.setObjectName("historyToggleButton")
self.historyToggleButton.setText("-")
self.historyToggleButton.setToolTip("Collapse Recent Audio")
self.historyToggleButton.setFixedSize(22, 22)
history_header_layout.addWidget(self.historyToggleButton)
history_layout.addWidget(self.historyHeader)
self.historyList = QListWidget(self.historyGroup)
self.historyList.setAlternatingRowColors(True)
self.historyList.setSelectionMode(
QListWidget.SelectionMode.SingleSelection
)
self.historyList.setContextMenuPolicy(
Qt.ContextMenuPolicy.CustomContextMenu
)
self.historyList.setToolTip(
"Double-click generated audio to play it, or right-click for history actions."
)
self.historyGroup.setMaximumHeight(170)
self.historyGroup.setMinimumHeight(48)
history_layout.addWidget(self.historyList)
root_layout.addWidget(self.historyGroup)
self.settingsSidebar = QGroupBox("Settings", central_widget)
self.settingsSidebar.setObjectName("settingsSidebar")
settings_sidebar_layout = QVBoxLayout(self.settingsSidebar)
self.sidebarSettingsEditor = SettingsEditor(
AppSettings(),
self.settingsSidebar,
)
settings_sidebar_layout.addWidget(self.sidebarSettingsEditor, 1)
sidebar_button_row = QHBoxLayout()
self.applySidebarSettingsButton = QPushButton(
"Apply",
self.settingsSidebar,
)
self.collapseSettingsSidebarButton = QPushButton(
"Collapse",
self.settingsSidebar,
)
sidebar_button_row.addStretch(1)
sidebar_button_row.addWidget(self.applySidebarSettingsButton)
sidebar_button_row.addWidget(self.collapseSettingsSidebarButton)
settings_sidebar_layout.addLayout(sidebar_button_row)
self.settingsSidebar.setMinimumWidth(320)
self.settingsSidebar.setMaximumWidth(420)
self.settingsSidebar.hide()
outer_layout.addWidget(self.settingsSidebar)
main_window.setCentralWidget(central_widget)
self.menubar = QMenuBar(main_window)
self.menuFile = QMenu("File", self.menubar)
self.menuTools = QMenu("Tools", self.menubar)
self.menuHelp = QMenu("Help", self.menubar)
self.actionOpenText = QAction("Open Document", main_window)
self.actionOpenUrl = QAction("Open URL", main_window)
self.actionOpenRawHtml = QAction("Import Raw HTML", main_window)
self.actionExportEditorText = QAction("Export Editor Text", main_window)
self.actionExportAudio = QAction("Export Audio", main_window)
self.actionExit = QAction("Exit", main_window)
self.actionSettings = QAction("Settings", main_window)
self.actionOpenScraper = QAction("Import Document", main_window)
self.actionSetupGuide = QAction("Setup Guide", main_window)
self.actionAbout = QAction("About", main_window)
self.menuFile.addAction(self.actionOpenText)
self.menuFile.addAction(self.actionOpenUrl)
self.menuFile.addAction(self.actionOpenRawHtml)
self.menuFile.addAction(self.actionExportEditorText)
self.menuFile.addAction(self.actionExportAudio)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionExit)
self.menuTools.addAction(self.actionSettings)
self.menuTools.addAction(self.actionOpenScraper)
self.menuHelp.addAction(self.actionSetupGuide)
self.menuHelp.addSeparator()
self.menuHelp.addAction(self.actionAbout)
self.menubar.addMenu(self.menuFile)
self.menubar.addMenu(self.menuTools)
self.menubar.addMenu(self.menuHelp)
main_window.setMenuBar(self.menubar)
self.statusbar = QStatusBar(main_window)
self.outputStatusLabel = QLabel(
"Provider: Azure Speech | Voice: en-US-GuyNeural | Rate: medium | Speech Volume: medium | Output: data/dynamic/audio",
self.statusbar,
)
self.outputStatusLabel.setObjectName("outputStatusLabel")
self.outputStatusLabel.setAlignment(
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter
)
self.outputStatusLabel.setTextInteractionFlags(
Qt.TextInteractionFlag.TextSelectableByMouse
)
self.outputStatusLabel.setToolTip(
"Current provider, voice, rate, speech volume, and output location."
)
self.statusbar.addPermanentWidget(self.outputStatusLabel, 1)
main_window.setStatusBar(self.statusbar)