winipedia-pyside 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of winipedia-pyside might be problematic. Click here for more details.
- winipedia_pyside/__init__.py +1 -0
- winipedia_pyside/core/__init__.py +1 -0
- winipedia_pyside/core/py_qiodevice.py +476 -0
- winipedia_pyside/py.typed +0 -0
- winipedia_pyside/ui/__init__.py +1 -0
- winipedia_pyside/ui/base/__init__.py +1 -0
- winipedia_pyside/ui/base/base.py +181 -0
- winipedia_pyside/ui/pages/__init__.py +1 -0
- winipedia_pyside/ui/pages/base/__init__.py +1 -0
- winipedia_pyside/ui/pages/base/base.py +92 -0
- winipedia_pyside/ui/pages/browser.py +26 -0
- winipedia_pyside/ui/pages/player.py +85 -0
- winipedia_pyside/ui/widgets/__init__.py +1 -0
- winipedia_pyside/ui/widgets/browser.py +243 -0
- winipedia_pyside/ui/widgets/clickable_widget.py +57 -0
- winipedia_pyside/ui/widgets/media_player.py +430 -0
- winipedia_pyside/ui/widgets/notification.py +77 -0
- winipedia_pyside/ui/windows/__init__.py +1 -0
- winipedia_pyside/ui/windows/base/__init__.py +1 -0
- winipedia_pyside/ui/windows/base/base.py +49 -0
- winipedia_pyside-0.2.0.dist-info/METADATA +20 -0
- winipedia_pyside-0.2.0.dist-info/RECORD +24 -0
- winipedia_pyside-0.2.0.dist-info/WHEEL +4 -0
- winipedia_pyside-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"""Media player module.
|
|
2
|
+
|
|
3
|
+
This module contains the media player class.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import time
|
|
7
|
+
from functools import partial
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
|
12
|
+
from PySide6.QtCore import Qt, QTimer, QUrl
|
|
13
|
+
from PySide6.QtMultimedia import QAudioOutput, QMediaPlayer
|
|
14
|
+
from PySide6.QtWidgets import (
|
|
15
|
+
QHBoxLayout,
|
|
16
|
+
QLayout,
|
|
17
|
+
QMenu,
|
|
18
|
+
QPushButton,
|
|
19
|
+
QSizePolicy,
|
|
20
|
+
QSlider,
|
|
21
|
+
QVBoxLayout,
|
|
22
|
+
QWidget,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from winipedia_pyside.core.py_qiodevice import (
|
|
26
|
+
EncryptedPyQFile,
|
|
27
|
+
PyQFile,
|
|
28
|
+
PyQIODevice,
|
|
29
|
+
)
|
|
30
|
+
from winipedia_pyside.ui.base.base import Base as BaseUI
|
|
31
|
+
from winipedia_pyside.ui.widgets.clickable_widget import ClickableVideoWidget
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class MediaPlayer(QMediaPlayer):
|
|
35
|
+
"""Media player class."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, parent_layout: QLayout, *args: Any, **kwargs: Any) -> None:
|
|
38
|
+
"""Initialize the media player.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
parent_layout: The parent layout to add the media player widget to.
|
|
42
|
+
*args: Additional positional arguments passed to parent constructor.
|
|
43
|
+
**kwargs: Additional keyword arguments passed to parent constructor.
|
|
44
|
+
"""
|
|
45
|
+
super().__init__(*args, **kwargs)
|
|
46
|
+
self.parent_layout = parent_layout
|
|
47
|
+
self.io_device: PyQIODevice | None = None
|
|
48
|
+
self.make_widget()
|
|
49
|
+
|
|
50
|
+
def make_widget(self) -> None:
|
|
51
|
+
"""Make the widget.
|
|
52
|
+
|
|
53
|
+
Creates the main media player widget with vertical layout, adds media controls
|
|
54
|
+
above and below the video widget, and creates the video widget itself.
|
|
55
|
+
"""
|
|
56
|
+
self.media_player_widget = QWidget()
|
|
57
|
+
self.media_player_layout = QVBoxLayout(self.media_player_widget)
|
|
58
|
+
self.parent_layout.addWidget(self.media_player_widget)
|
|
59
|
+
self.add_media_controls_above()
|
|
60
|
+
self.make_video_widget()
|
|
61
|
+
self.add_media_controls_below()
|
|
62
|
+
|
|
63
|
+
def make_video_widget(self) -> None:
|
|
64
|
+
"""Make the video widget.
|
|
65
|
+
|
|
66
|
+
Creates a clickable video widget with expanding size policy, sets up
|
|
67
|
+
audio output, and connects the click signal to toggle media controls.
|
|
68
|
+
"""
|
|
69
|
+
self.video_widget = ClickableVideoWidget()
|
|
70
|
+
self.video_widget.clicked.connect(self.on_video_clicked)
|
|
71
|
+
self.video_widget.setSizePolicy(
|
|
72
|
+
QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
|
|
73
|
+
)
|
|
74
|
+
self.setVideoOutput(self.video_widget)
|
|
75
|
+
|
|
76
|
+
self.audio_output = QAudioOutput()
|
|
77
|
+
self.setAudioOutput(self.audio_output)
|
|
78
|
+
|
|
79
|
+
self.media_player_layout.addWidget(self.video_widget)
|
|
80
|
+
|
|
81
|
+
def on_video_clicked(self) -> None:
|
|
82
|
+
"""Handle video widget click.
|
|
83
|
+
|
|
84
|
+
Toggles the visibility of media controls when the video widget is clicked.
|
|
85
|
+
"""
|
|
86
|
+
if self.media_controls_widget_above.isVisible():
|
|
87
|
+
self.hide_media_controls()
|
|
88
|
+
return
|
|
89
|
+
self.show_media_controls()
|
|
90
|
+
|
|
91
|
+
def show_media_controls(self) -> None:
|
|
92
|
+
"""Show media controls.
|
|
93
|
+
|
|
94
|
+
Makes both the above and below media control widgets visible.
|
|
95
|
+
"""
|
|
96
|
+
self.media_controls_widget_above.show()
|
|
97
|
+
self.media_controls_widget_below.show()
|
|
98
|
+
|
|
99
|
+
def hide_media_controls(self) -> None:
|
|
100
|
+
"""Hide media controls.
|
|
101
|
+
|
|
102
|
+
Hides both the above and below media control widgets.
|
|
103
|
+
"""
|
|
104
|
+
self.media_controls_widget_above.hide()
|
|
105
|
+
self.media_controls_widget_below.hide()
|
|
106
|
+
|
|
107
|
+
def add_media_controls_above(self) -> None:
|
|
108
|
+
"""Add media controls above the video.
|
|
109
|
+
|
|
110
|
+
Creates the top control bar with left, center, and right sections,
|
|
111
|
+
then adds speed, volume, playback, and fullscreen controls.
|
|
112
|
+
"""
|
|
113
|
+
# main above widget
|
|
114
|
+
self.media_controls_widget_above = QWidget()
|
|
115
|
+
self.media_controls_layout_above = QHBoxLayout(self.media_controls_widget_above)
|
|
116
|
+
self.media_player_layout.addWidget(self.media_controls_widget_above)
|
|
117
|
+
# left contorls
|
|
118
|
+
self.left_controls_widget = QWidget()
|
|
119
|
+
self.left_controls_layout = QHBoxLayout(self.left_controls_widget)
|
|
120
|
+
self.media_controls_layout_above.addWidget(
|
|
121
|
+
self.left_controls_widget, alignment=Qt.AlignmentFlag.AlignLeft
|
|
122
|
+
)
|
|
123
|
+
# center contorls
|
|
124
|
+
self.center_controls_widget = QWidget()
|
|
125
|
+
self.center_controls_layout = QHBoxLayout(self.center_controls_widget)
|
|
126
|
+
self.media_controls_layout_above.addWidget(
|
|
127
|
+
self.center_controls_widget, alignment=Qt.AlignmentFlag.AlignCenter
|
|
128
|
+
)
|
|
129
|
+
self.right_controls_widget = QWidget()
|
|
130
|
+
self.right_controls_layout = QHBoxLayout(self.right_controls_widget)
|
|
131
|
+
self.media_controls_layout_above.addWidget(
|
|
132
|
+
self.right_controls_widget, alignment=Qt.AlignmentFlag.AlignRight
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
self.add_speed_control()
|
|
136
|
+
self.add_volume_control()
|
|
137
|
+
self.add_playback_control()
|
|
138
|
+
self.add_fullscreen_control()
|
|
139
|
+
|
|
140
|
+
def add_media_controls_below(self) -> None:
|
|
141
|
+
"""Add media controls below the video.
|
|
142
|
+
|
|
143
|
+
Creates the bottom control bar and adds the progress control slider.
|
|
144
|
+
"""
|
|
145
|
+
self.media_controls_widget_below = QWidget()
|
|
146
|
+
self.media_controls_layout_below = QHBoxLayout(self.media_controls_widget_below)
|
|
147
|
+
self.media_player_layout.addWidget(self.media_controls_widget_below)
|
|
148
|
+
self.add_progress_control()
|
|
149
|
+
|
|
150
|
+
def add_playback_control(self) -> None:
|
|
151
|
+
"""Add playback control.
|
|
152
|
+
|
|
153
|
+
Creates a play/pause button with appropriate icons and connects it
|
|
154
|
+
to the toggle_playback method. Adds the button to the center controls.
|
|
155
|
+
"""
|
|
156
|
+
self.play_icon = BaseUI.get_svg_icon("play_icon")
|
|
157
|
+
self.pause_icon = BaseUI.get_svg_icon("pause_icon")
|
|
158
|
+
# Pause symbol: ⏸ (U+23F8)
|
|
159
|
+
self.playback_button = QPushButton()
|
|
160
|
+
self.playback_button.setIcon(self.pause_icon)
|
|
161
|
+
self.playback_button.clicked.connect(self.toggle_playback)
|
|
162
|
+
|
|
163
|
+
self.center_controls_layout.addWidget(self.playback_button)
|
|
164
|
+
|
|
165
|
+
def toggle_playback(self) -> None:
|
|
166
|
+
"""Toggle playback.
|
|
167
|
+
|
|
168
|
+
Switches between play and pause states, updating the button icon
|
|
169
|
+
accordingly based on the current playback state.
|
|
170
|
+
"""
|
|
171
|
+
if self.playbackState() == QMediaPlayer.PlaybackState.PlayingState:
|
|
172
|
+
self.pause()
|
|
173
|
+
self.playback_button.setIcon(self.play_icon)
|
|
174
|
+
else:
|
|
175
|
+
self.play()
|
|
176
|
+
self.playback_button.setIcon(self.pause_icon)
|
|
177
|
+
|
|
178
|
+
def add_speed_control(self) -> None:
|
|
179
|
+
"""Add speed control.
|
|
180
|
+
|
|
181
|
+
Creates a button in the top left that shows a dropdown menu to select
|
|
182
|
+
playback speed from predefined options (0.2x to 5x).
|
|
183
|
+
"""
|
|
184
|
+
self.default_speed = 1
|
|
185
|
+
self.speed_options = [0.2, 0.5, self.default_speed, 1.5, 2, 3, 4, 5]
|
|
186
|
+
self.speed_button = QPushButton(f"{self.default_speed}x")
|
|
187
|
+
self.speed_menu = QMenu(self.speed_button)
|
|
188
|
+
for speed in self.speed_options:
|
|
189
|
+
action = self.speed_menu.addAction(f"{speed}x")
|
|
190
|
+
action.triggered.connect(partial(self.change_speed, speed))
|
|
191
|
+
|
|
192
|
+
self.speed_button.setMenu(self.speed_menu)
|
|
193
|
+
self.left_controls_layout.addWidget(self.speed_button)
|
|
194
|
+
|
|
195
|
+
def change_speed(self, speed: float) -> None:
|
|
196
|
+
"""Change playback speed.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
speed: The new playback speed multiplier.
|
|
200
|
+
"""
|
|
201
|
+
self.setPlaybackRate(speed)
|
|
202
|
+
self.speed_button.setText(f"{speed}x")
|
|
203
|
+
|
|
204
|
+
def add_volume_control(self) -> None:
|
|
205
|
+
"""Add volume control.
|
|
206
|
+
|
|
207
|
+
Creates a horizontal slider for volume control with range 0-100
|
|
208
|
+
and connects it to the volume change handler.
|
|
209
|
+
"""
|
|
210
|
+
self.volume_slider = QSlider(Qt.Orientation.Horizontal)
|
|
211
|
+
self.volume_slider.setRange(0, 100)
|
|
212
|
+
self.volume_slider.valueChanged.connect(self.on_volume_changed)
|
|
213
|
+
self.left_controls_layout.addWidget(self.volume_slider)
|
|
214
|
+
|
|
215
|
+
def on_volume_changed(self, value: int) -> None:
|
|
216
|
+
"""Handle volume slider value change.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
value: The new volume value from 0-100.
|
|
220
|
+
"""
|
|
221
|
+
volume = value / 100.0 # Convert to 0.0-1.0 range
|
|
222
|
+
self.audio_output.setVolume(volume)
|
|
223
|
+
|
|
224
|
+
def add_fullscreen_control(self) -> None:
|
|
225
|
+
"""Add fullscreen control.
|
|
226
|
+
|
|
227
|
+
Creates a fullscreen toggle button with appropriate icons and determines
|
|
228
|
+
which widgets to hide/show when entering/exiting fullscreen mode.
|
|
229
|
+
"""
|
|
230
|
+
self.fullscreen_icon = BaseUI.get_svg_icon("fullscreen_icon")
|
|
231
|
+
self.exit_fullscreen_icon = BaseUI.get_svg_icon("exit_fullscreen_icon")
|
|
232
|
+
self.fullscreen_button = QPushButton()
|
|
233
|
+
self.fullscreen_button.setIcon(self.fullscreen_icon)
|
|
234
|
+
|
|
235
|
+
self.parent_widget = self.parent_layout.parentWidget()
|
|
236
|
+
self.other_visible_widgets = [
|
|
237
|
+
w
|
|
238
|
+
for w in set(self.parent_widget.findChildren(QWidget))
|
|
239
|
+
- {
|
|
240
|
+
self.media_player_widget,
|
|
241
|
+
*self.media_player_widget.findChildren(QWidget),
|
|
242
|
+
}
|
|
243
|
+
if w.isVisible() or not (w.isHidden() or w.isVisible())
|
|
244
|
+
]
|
|
245
|
+
self.fullscreen_button.clicked.connect(self.toggle_fullscreen)
|
|
246
|
+
|
|
247
|
+
self.right_controls_layout.addWidget(self.fullscreen_button)
|
|
248
|
+
|
|
249
|
+
def toggle_fullscreen(self) -> None:
|
|
250
|
+
"""Toggle fullscreen mode.
|
|
251
|
+
|
|
252
|
+
Switches between fullscreen and windowed mode, hiding/showing other
|
|
253
|
+
widgets and updating the button icon accordingly.
|
|
254
|
+
"""
|
|
255
|
+
# Get the main window
|
|
256
|
+
main_window = self.media_player_widget.window()
|
|
257
|
+
if main_window.isFullScreen():
|
|
258
|
+
for widget in self.other_visible_widgets:
|
|
259
|
+
widget.show()
|
|
260
|
+
# show the window in the previous size
|
|
261
|
+
main_window.showMaximized()
|
|
262
|
+
self.fullscreen_button.setIcon(self.fullscreen_icon)
|
|
263
|
+
else:
|
|
264
|
+
for widget in self.other_visible_widgets:
|
|
265
|
+
widget.hide()
|
|
266
|
+
main_window.showFullScreen()
|
|
267
|
+
self.fullscreen_button.setIcon(self.exit_fullscreen_icon)
|
|
268
|
+
|
|
269
|
+
def add_progress_control(self) -> None:
|
|
270
|
+
"""Add progress control.
|
|
271
|
+
|
|
272
|
+
Creates a horizontal progress slider and connects it to media player
|
|
273
|
+
signals for position updates and user interaction handling.
|
|
274
|
+
"""
|
|
275
|
+
self.progress_slider = QSlider(Qt.Orientation.Horizontal)
|
|
276
|
+
self.media_controls_layout_below.addWidget(self.progress_slider)
|
|
277
|
+
|
|
278
|
+
# Connect media player signals to update the progress slider
|
|
279
|
+
self.positionChanged.connect(self.update_slider_position)
|
|
280
|
+
self.durationChanged.connect(self.set_slider_range)
|
|
281
|
+
|
|
282
|
+
# Connect slider signals to update video position
|
|
283
|
+
self.last_slider_moved_update = time.time()
|
|
284
|
+
self.slider_moved_update_interval = 0.1
|
|
285
|
+
self.progress_slider.sliderMoved.connect(self.on_slider_moved)
|
|
286
|
+
self.progress_slider.sliderReleased.connect(self.on_slider_released)
|
|
287
|
+
|
|
288
|
+
def update_slider_position(self, position: int) -> None:
|
|
289
|
+
"""Update the progress slider position.
|
|
290
|
+
|
|
291
|
+
Args:
|
|
292
|
+
position: The current media position in milliseconds.
|
|
293
|
+
"""
|
|
294
|
+
# Only update if not being dragged to prevent jumps during manual sliding
|
|
295
|
+
if not self.progress_slider.isSliderDown():
|
|
296
|
+
self.progress_slider.setValue(position)
|
|
297
|
+
|
|
298
|
+
def set_slider_range(self, duration: int) -> None:
|
|
299
|
+
"""Set the progress slider range based on media duration.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
duration: The total media duration in milliseconds.
|
|
303
|
+
"""
|
|
304
|
+
self.progress_slider.setRange(0, duration)
|
|
305
|
+
|
|
306
|
+
def on_slider_moved(self, position: int) -> None:
|
|
307
|
+
"""Set the media position when slider is moved.
|
|
308
|
+
|
|
309
|
+
Implements throttling to prevent excessive position updates during
|
|
310
|
+
slider dragging for better performance.
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
position: The new position from the slider in milliseconds.
|
|
314
|
+
"""
|
|
315
|
+
current_time = time.time()
|
|
316
|
+
if (
|
|
317
|
+
current_time - self.last_slider_moved_update
|
|
318
|
+
> self.slider_moved_update_interval
|
|
319
|
+
):
|
|
320
|
+
self.setPosition(position)
|
|
321
|
+
self.last_slider_moved_update = current_time
|
|
322
|
+
|
|
323
|
+
def on_slider_released(self) -> None:
|
|
324
|
+
"""Handle slider release event.
|
|
325
|
+
|
|
326
|
+
Sets the final media position when the user releases the slider.
|
|
327
|
+
"""
|
|
328
|
+
self.setPosition(self.progress_slider.value())
|
|
329
|
+
|
|
330
|
+
def play_video(
|
|
331
|
+
self,
|
|
332
|
+
io_device: PyQIODevice,
|
|
333
|
+
source_url: QUrl,
|
|
334
|
+
position: int = 0,
|
|
335
|
+
) -> None:
|
|
336
|
+
"""Play the video.
|
|
337
|
+
|
|
338
|
+
Stops current playback and starts a new video using the provided
|
|
339
|
+
source function with a delay to prevent freezing.
|
|
340
|
+
|
|
341
|
+
Args:
|
|
342
|
+
io_device: The PyQIODevice to use as the media source.
|
|
343
|
+
source_url: The QUrl representing the source location.
|
|
344
|
+
position: The position to start playback from in milliseconds.
|
|
345
|
+
"""
|
|
346
|
+
self.stop_and_close_io_device()
|
|
347
|
+
|
|
348
|
+
self.resume_func = partial(self.resume_to_position, position=position)
|
|
349
|
+
self.mediaStatusChanged.connect(self.resume_func)
|
|
350
|
+
|
|
351
|
+
# SingleShot prevents freezing when starting new video while another is playing
|
|
352
|
+
QTimer.singleShot(
|
|
353
|
+
100,
|
|
354
|
+
partial(
|
|
355
|
+
self.set_source_and_play, io_device=io_device, source_url=source_url
|
|
356
|
+
),
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
def stop_and_close_io_device(self) -> None:
|
|
360
|
+
"""Stop playback and close the IO device."""
|
|
361
|
+
self.stop()
|
|
362
|
+
if self.io_device is not None:
|
|
363
|
+
self.io_device.close()
|
|
364
|
+
|
|
365
|
+
def resume_to_position(
|
|
366
|
+
self, status: QMediaPlayer.MediaStatus, position: int
|
|
367
|
+
) -> None:
|
|
368
|
+
"""Resume playback to a position.
|
|
369
|
+
|
|
370
|
+
Args:
|
|
371
|
+
status: The current media status.
|
|
372
|
+
position: The position to resume playback from in milliseconds.
|
|
373
|
+
"""
|
|
374
|
+
if status == QMediaPlayer.MediaStatus.BufferedMedia:
|
|
375
|
+
self.setPosition(position)
|
|
376
|
+
self.mediaStatusChanged.disconnect(self.resume_func)
|
|
377
|
+
|
|
378
|
+
def set_source_and_play(
|
|
379
|
+
self,
|
|
380
|
+
io_device: PyQIODevice,
|
|
381
|
+
source_url: QUrl,
|
|
382
|
+
) -> None:
|
|
383
|
+
"""Set the source and play the video.
|
|
384
|
+
|
|
385
|
+
Args:
|
|
386
|
+
io_device: The PyQIODevice to use as the media source.
|
|
387
|
+
source_url: The QUrl representing the source location.
|
|
388
|
+
"""
|
|
389
|
+
self.set_source_device(io_device, source_url)
|
|
390
|
+
self.play()
|
|
391
|
+
|
|
392
|
+
def set_source_device(self, io_device: PyQIODevice, source_url: QUrl) -> None:
|
|
393
|
+
"""Set the source device for playback.
|
|
394
|
+
|
|
395
|
+
Args:
|
|
396
|
+
io_device: The PyQIODevice to use as the media source.
|
|
397
|
+
source_url: The QUrl representing the source location.
|
|
398
|
+
"""
|
|
399
|
+
self.source_url = source_url
|
|
400
|
+
self.io_device = io_device
|
|
401
|
+
self.setSourceDevice(self.io_device, self.source_url)
|
|
402
|
+
|
|
403
|
+
def play_file(self, path: Path, position: int = 0) -> None:
|
|
404
|
+
"""Play a regular video file.
|
|
405
|
+
|
|
406
|
+
Args:
|
|
407
|
+
path: The file path to the video file to play.
|
|
408
|
+
position: The position to start playback from in milliseconds.
|
|
409
|
+
"""
|
|
410
|
+
self.play_video(
|
|
411
|
+
position=position,
|
|
412
|
+
io_device=PyQFile(path),
|
|
413
|
+
source_url=QUrl.fromLocalFile(path),
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
def play_encrypted_file(
|
|
417
|
+
self, path: Path, aes_gcm: AESGCM, position: int = 0
|
|
418
|
+
) -> None:
|
|
419
|
+
"""Play an encrypted video file.
|
|
420
|
+
|
|
421
|
+
Args:
|
|
422
|
+
path: The file path to the encrypted video file to play.
|
|
423
|
+
aes_gcm: The AES-GCM cipher instance for decryption.
|
|
424
|
+
position: The position to start playback from in milliseconds.
|
|
425
|
+
"""
|
|
426
|
+
self.play_video(
|
|
427
|
+
position=position,
|
|
428
|
+
io_device=EncryptedPyQFile(path, aes_gcm),
|
|
429
|
+
source_url=QUrl.fromLocalFile(path),
|
|
430
|
+
)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Notification module.
|
|
2
|
+
|
|
3
|
+
This module contains functions to show notifications.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from pyqttoast import Toast, ToastIcon, ToastPosition # type: ignore[import-untyped]
|
|
7
|
+
from PySide6.QtWidgets import QApplication
|
|
8
|
+
from winipedia_utils.text.string import value_to_truncated_string
|
|
9
|
+
|
|
10
|
+
Toast.setPosition(ToastPosition.TOP_MIDDLE)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Notification(Toast): # type: ignore[misc]
|
|
14
|
+
"""Notification class."""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
title: str,
|
|
19
|
+
text: str,
|
|
20
|
+
icon: ToastIcon = ToastIcon.INFORMATION,
|
|
21
|
+
duration: int = 10000,
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Initialize the notification.
|
|
24
|
+
|
|
25
|
+
The notification is shown in the top middle of the screen.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
title: The title of the notification.
|
|
29
|
+
text: The text of the notification.
|
|
30
|
+
icon: The icon of the notification. Defaults to INFORMATION.
|
|
31
|
+
duration: The duration of the notification in milliseconds.
|
|
32
|
+
Defaults to 10000.
|
|
33
|
+
"""
|
|
34
|
+
super().__init__(QApplication.activeWindow())
|
|
35
|
+
self.setDuration(duration)
|
|
36
|
+
self.setIcon(icon)
|
|
37
|
+
self.set_title(title)
|
|
38
|
+
self.set_text(text)
|
|
39
|
+
|
|
40
|
+
def set_title(self, title: str) -> None:
|
|
41
|
+
"""Set the title of the notification.
|
|
42
|
+
|
|
43
|
+
Truncates the title to fit within half the window width before setting it.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
title: The title text to set.
|
|
47
|
+
"""
|
|
48
|
+
title = self.str_to_half_window_width(title)
|
|
49
|
+
self.setTitle(title)
|
|
50
|
+
|
|
51
|
+
def set_text(self, text: str) -> None:
|
|
52
|
+
"""Set the text of the notification.
|
|
53
|
+
|
|
54
|
+
Truncates the text to fit within half the window width before setting it.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
text: The notification text to set.
|
|
58
|
+
"""
|
|
59
|
+
text = self.str_to_half_window_width(text)
|
|
60
|
+
self.setText(text)
|
|
61
|
+
|
|
62
|
+
def str_to_half_window_width(self, string: str) -> str:
|
|
63
|
+
"""Truncate the string to the width of the active window.
|
|
64
|
+
|
|
65
|
+
Calculates half the width of the active window and truncates the string
|
|
66
|
+
to fit within that width. Falls back to 500 pixels if no active window.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
string: The string to truncate.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
The truncated string that fits within half the window width.
|
|
73
|
+
"""
|
|
74
|
+
main_window = QApplication.activeWindow()
|
|
75
|
+
width = main_window.width() / 2 if main_window is not None else 500
|
|
76
|
+
width = int(width)
|
|
77
|
+
return value_to_truncated_string(string, width)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""__init__ module."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""__init__ module."""
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Base window module.
|
|
2
|
+
|
|
3
|
+
This module contains the base window class for the VideoVault application.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from abc import abstractmethod
|
|
7
|
+
|
|
8
|
+
from PySide6.QtWidgets import QMainWindow, QStackedWidget
|
|
9
|
+
|
|
10
|
+
from winipedia_pyside.ui.base.base import Base as BaseUI
|
|
11
|
+
from winipedia_pyside.ui.pages.base.base import Base as BasePage
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Base(BaseUI, QMainWindow):
|
|
15
|
+
"""Base window class for the VideoVault application."""
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def get_all_page_classes(cls) -> list[type[BasePage]]:
|
|
20
|
+
"""Get all page classes."""
|
|
21
|
+
|
|
22
|
+
@classmethod
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def get_start_page_cls(cls) -> type[BasePage]:
|
|
25
|
+
"""Get the start page class."""
|
|
26
|
+
|
|
27
|
+
def base_setup(self) -> None:
|
|
28
|
+
"""Get the Qt object of the UI."""
|
|
29
|
+
self.setWindowTitle(self.get_display_name())
|
|
30
|
+
|
|
31
|
+
self.stack = QStackedWidget()
|
|
32
|
+
self.setCentralWidget(self.stack)
|
|
33
|
+
|
|
34
|
+
self.make_pages()
|
|
35
|
+
|
|
36
|
+
self.set_start_page()
|
|
37
|
+
|
|
38
|
+
def make_pages(self) -> None:
|
|
39
|
+
"""Get the pages to add to the window."""
|
|
40
|
+
for page_cls in self.get_all_page_classes():
|
|
41
|
+
page_cls(base_window=self)
|
|
42
|
+
|
|
43
|
+
def set_start_page(self) -> None:
|
|
44
|
+
"""Set the start page."""
|
|
45
|
+
self.set_current_page(self.get_start_page_cls())
|
|
46
|
+
|
|
47
|
+
def add_page(self, page: BasePage) -> None:
|
|
48
|
+
"""Add the pages to the window."""
|
|
49
|
+
self.stack.addWidget(page)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: winipedia-pyside
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A package for pyside utils
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Winipedia
|
|
8
|
+
Author-email: win.steveker@gmx.de
|
|
9
|
+
Requires-Python: >=3.12,<3.14
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Requires-Dist: pyqt-toast-notification (>=1.3.3,<2.0.0)
|
|
14
|
+
Requires-Dist: pyside6 (>=6.10.0,<7.0.0)
|
|
15
|
+
Requires-Dist: winipedia-utils (>=0.2.2,<0.3.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# winipedia_pyside
|
|
19
|
+
A package for pyside utils
|
|
20
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
winipedia_pyside/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
2
|
+
winipedia_pyside/core/__init__.py,sha256=sIrST4EUetmzlqCyoDZ0Z0-fTnto7vM1hm_rOw5JTPg,50
|
|
3
|
+
winipedia_pyside/core/py_qiodevice.py,sha256=5onTJAE4Q328ACXrubZ2RsBO_PdJm0rXV6ZgqnzV4aU,15313
|
|
4
|
+
winipedia_pyside/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
winipedia_pyside/ui/__init__.py,sha256=RhyqY7bQQbxg9Q34tHOYG1dgpu2Dbk9vSchCgwnx0lM,48
|
|
6
|
+
winipedia_pyside/ui/base/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
7
|
+
winipedia_pyside/ui/base/base.py,sha256=AxpHFpE-PHNglyMYxMkue0qTFE9C2dQ0XaeNnpNz8cg,5584
|
|
8
|
+
winipedia_pyside/ui/pages/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
9
|
+
winipedia_pyside/ui/pages/base/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
10
|
+
winipedia_pyside/ui/pages/base/base.py,sha256=dORfCFOCRA4dAZN16LYV5uXkc67nwxEbT8gCbMa55VM,2936
|
|
11
|
+
winipedia_pyside/ui/pages/browser.py,sha256=whdXlWB3IaU1tkPN5usfSt8FtAkhcjPSXU0fs06_zpE,796
|
|
12
|
+
winipedia_pyside/ui/pages/player.py,sha256=mGNexrxFqM0EvMqNgv9Fn4dbQgY9hLzKhgsxD7zhb8A,2709
|
|
13
|
+
winipedia_pyside/ui/widgets/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
14
|
+
winipedia_pyside/ui/widgets/browser.py,sha256=KFuICHUTX_8w5DfgJ3IbTu6ipuiuo-mTJku5tg-qSz0,8171
|
|
15
|
+
winipedia_pyside/ui/widgets/clickable_widget.py,sha256=yMph7whLS6Bw65gf56LHdkZg-JzjWHUnSh3WW3IK25U,1722
|
|
16
|
+
winipedia_pyside/ui/widgets/media_player.py,sha256=qsUVMjP7c0rL5_XK5cLNPstHS28ZXfyVUUJSQbDbpl0,15758
|
|
17
|
+
winipedia_pyside/ui/widgets/notification.py,sha256=RM5oHfqWwvnf3tZ69uOlGrKkWhnpjpOpcPJQ8qSxduE,2478
|
|
18
|
+
winipedia_pyside/ui/windows/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
19
|
+
winipedia_pyside/ui/windows/base/__init__.py,sha256=XHsbmjiaGom-KX-S3leCY9cJD3aP9p_0X6xYMcdkHBU,23
|
|
20
|
+
winipedia_pyside/ui/windows/base/base.py,sha256=GMe6dhxrqMSiB_rIYr_dnjw3QYbYErDOoU0bqfEbEOw,1378
|
|
21
|
+
winipedia_pyside-0.2.0.dist-info/METADATA,sha256=SkBoWX38z-fMLDS1joNMJJvXwKO5q-rKA4VZWfSo6hM,607
|
|
22
|
+
winipedia_pyside-0.2.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
23
|
+
winipedia_pyside-0.2.0.dist-info/licenses/LICENSE,sha256=o316mE2gGzd__JT69p7S_zlOmKiHh8YjpImCCcWyTvM,1066
|
|
24
|
+
winipedia_pyside-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Winipedia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|