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.

@@ -0,0 +1,92 @@
1
+ """Base page module.
2
+
3
+ This module contains the base page class for the VideoVault application.
4
+ """
5
+
6
+ from functools import partial
7
+ from typing import TYPE_CHECKING, Any
8
+
9
+ from PySide6.QtCore import Qt
10
+ from PySide6.QtWidgets import (
11
+ QHBoxLayout,
12
+ QLayout,
13
+ QMenu,
14
+ QPushButton,
15
+ QSizePolicy,
16
+ QVBoxLayout,
17
+ QWidget,
18
+ )
19
+
20
+ from winipedia_pyside.ui.base.base import Base as BaseUI
21
+
22
+ if TYPE_CHECKING:
23
+ from winipedia_pyside.ui.windows.base.base import Base as BaseWindow
24
+
25
+
26
+ class Base(BaseUI, QWidget):
27
+ """Base page class for the VideoVault application."""
28
+
29
+ def __init__(self, base_window: "BaseWindow", *args: Any, **kwargs: Any) -> None:
30
+ """Initialize the base page."""
31
+ self.base_window = base_window
32
+ super().__init__(*args, **kwargs)
33
+
34
+ def base_setup(self) -> None:
35
+ """Setup the base Qt object of the UI.
36
+
37
+ Initializes the main vertical layout, adds a horizontal layout for the top row,
38
+ and sets up the menu dropdown button.
39
+ """
40
+ self.v_layout = QVBoxLayout()
41
+ self.setLayout(self.v_layout)
42
+
43
+ # add a horizontal layout for the top row
44
+ self.h_layout = QHBoxLayout()
45
+ self.v_layout.addLayout(self.h_layout)
46
+
47
+ self.add_menu_dropdown_button()
48
+ self.base_window.add_page(self)
49
+
50
+ def add_menu_dropdown_button(self) -> None:
51
+ """Add a dropdown menu that leads to each page.
52
+
53
+ Creates a menu button with a dropdown containing actions for all available
54
+ page subclasses. Each action connects to the set_current_page method.
55
+ """
56
+ self.menu_button = QPushButton("Menu")
57
+ self.menu_button.setIcon(self.get_svg_icon("menu_icon"))
58
+ self.menu_button.setSizePolicy(
59
+ QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum
60
+ )
61
+ self.h_layout.addWidget(
62
+ self.menu_button,
63
+ alignment=Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft,
64
+ )
65
+ self.menu_dropdown = QMenu(self.menu_button)
66
+ self.menu_button.setMenu(self.menu_dropdown)
67
+
68
+ for page_cls in self.base_window.get_all_page_classes():
69
+ action = self.menu_dropdown.addAction(page_cls.get_display_name())
70
+ action.triggered.connect(partial(self.set_current_page, page_cls))
71
+
72
+ def add_to_page_button(
73
+ self, to_page_cls: type["Base"], layout: QLayout
74
+ ) -> QPushButton:
75
+ """Add a button to go to the specified page.
76
+
77
+ Args:
78
+ to_page_cls: The page class to navigate to when button is clicked.
79
+ layout: The layout to add the button to.
80
+
81
+ Returns:
82
+ The created QPushButton widget.
83
+ """
84
+ button = QPushButton(to_page_cls.get_display_name())
85
+
86
+ # connect to open page on click
87
+ button.clicked.connect(lambda: self.set_current_page(to_page_cls))
88
+
89
+ # add to layout
90
+ layout.addWidget(button)
91
+
92
+ return button
@@ -0,0 +1,26 @@
1
+ """Add downloads page module.
2
+
3
+ This module contains the add downloads page class for the VideoVault application.
4
+ """
5
+
6
+ from winipedia_pyside.ui.pages.base.base import Base as BasePage
7
+ from winipedia_pyside.ui.widgets.browser import Browser as BrowserWidget
8
+
9
+
10
+ class Browser(BasePage):
11
+ """Add downloads page for the VideoVault application."""
12
+
13
+ def setup(self) -> None:
14
+ """Setup the UI.
15
+
16
+ Initializes the browser page by adding a browser widget to the layout.
17
+ """
18
+ self.add_brwoser()
19
+
20
+ def add_brwoser(self) -> None:
21
+ """Add a browser to surf the web.
22
+
23
+ Creates and adds a BrowserWidget instance to the vertical layout,
24
+ enabling web browsing functionality within the page.
25
+ """
26
+ self.browser = BrowserWidget(self.v_layout)
@@ -0,0 +1,85 @@
1
+ """Player page module.
2
+
3
+ This module contains the player page class for the VideoVault application.
4
+ """
5
+
6
+ from abc import abstractmethod
7
+ from collections.abc import Callable
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from cryptography.hazmat.primitives.ciphers.aead import AESGCM
12
+
13
+ from winipedia_pyside.ui.pages.base.base import Base as BasePage
14
+ from winipedia_pyside.ui.widgets.media_player import MediaPlayer
15
+
16
+
17
+ class Player(BasePage):
18
+ """Player page for the VideoVault application."""
19
+
20
+ @abstractmethod
21
+ def start_playback(self, path: Path, position: int = 0) -> None:
22
+ """Start the playback.
23
+
24
+ Args:
25
+ path: The file path to start playback for.
26
+ position: The position to start playback from in milliseconds.
27
+ """
28
+
29
+ def setup(self) -> None:
30
+ """Setup the UI.
31
+
32
+ Initializes the media player widget and adds it to the layout.
33
+ """
34
+ self.media_player = MediaPlayer(self.v_layout)
35
+
36
+ def play_file_from_func(
37
+ self,
38
+ play_func: Callable[..., Any],
39
+ path: Path,
40
+ position: int = 0,
41
+ **kwargs: Any,
42
+ ) -> None:
43
+ """Play a file using the specified function.
44
+
45
+ Sets the current page to player and calls the provided play function
46
+ with the given path and additional arguments.
47
+
48
+ Args:
49
+ play_func: The function to call for playing the file.
50
+ path: The file path to play.
51
+ position: The position to start playback from in milliseconds.
52
+ **kwargs: Additional keyword arguments to pass to the play function.
53
+ """
54
+ # set current page to player
55
+ self.set_current_page(self.__class__)
56
+ # Stop current playback and clean up resources
57
+ play_func(path=path, position=position, **kwargs)
58
+
59
+ def play_file(self, path: Path, position: int = 0) -> None:
60
+ """Play a regular video file.
61
+
62
+ Args:
63
+ path: The file path to play.
64
+ position: The position to start playback from in milliseconds.
65
+ """
66
+ self.play_file_from_func(
67
+ self.media_player.play_file, path=path, position=position
68
+ )
69
+
70
+ def play_encrypted_file(
71
+ self, path: Path, aes_gcm: AESGCM, position: int = 0
72
+ ) -> None:
73
+ """Play an encrypted video file.
74
+
75
+ Args:
76
+ path: The encrypted file path to play.
77
+ aes_gcm: The AES-GCM cipher instance for decryption.
78
+ position: The position to start playback from in milliseconds.
79
+ """
80
+ self.play_file_from_func(
81
+ self.media_player.play_encrypted_file,
82
+ path=path,
83
+ position=position,
84
+ aes_gcm=aes_gcm,
85
+ )
@@ -0,0 +1 @@
1
+ """__init__ module."""
@@ -0,0 +1,243 @@
1
+ """Browser module.
2
+
3
+ This module contains the browser class for the application.
4
+ """
5
+
6
+ from collections import defaultdict
7
+ from http.cookiejar import Cookie
8
+ from typing import Any
9
+
10
+ from PySide6.QtCore import QUrl
11
+ from PySide6.QtGui import QIcon
12
+ from PySide6.QtNetwork import QNetworkCookie
13
+ from PySide6.QtWebEngineWidgets import QWebEngineView
14
+ from PySide6.QtWidgets import (
15
+ QHBoxLayout,
16
+ QLayout,
17
+ QLineEdit,
18
+ QPushButton,
19
+ QSizePolicy,
20
+ QVBoxLayout,
21
+ QWidget,
22
+ )
23
+
24
+
25
+ class Browser(QWebEngineView):
26
+ """Browser class that creates a simple ready to use browser and not just a view."""
27
+
28
+ def __init__(self, parent_layout: QLayout, *args: Any, **kwargs: Any) -> None:
29
+ """Initialize the browser.
30
+
31
+ Args:
32
+ parent_layout: The parent layout to add the browser widget to.
33
+ *args: Additional positional arguments passed to parent constructor.
34
+ **kwargs: Additional keyword arguments passed to parent constructor.
35
+ """
36
+ super().__init__(*args, **kwargs)
37
+ self.parent_layout = parent_layout
38
+ self.make_widget()
39
+ self.connect_signals()
40
+ self.load_first_url()
41
+
42
+ def make_address_bar(self) -> None:
43
+ """Make the address bar.
44
+
45
+ Creates a horizontal layout containing back button, forward button,
46
+ address input field, and go button for browser navigation.
47
+ """
48
+ self.address_bar_layout = QHBoxLayout()
49
+
50
+ # Add back button
51
+ self.back_button = QPushButton()
52
+ self.back_button.setIcon(QIcon.fromTheme("go-previous"))
53
+ self.back_button.setToolTip("Go back")
54
+ self.back_button.clicked.connect(self.back)
55
+ self.address_bar_layout.addWidget(self.back_button)
56
+
57
+ # Add forward button
58
+ self.forward_button = QPushButton()
59
+ self.forward_button.setIcon(QIcon.fromTheme("go-next"))
60
+ self.forward_button.setToolTip("Go forward")
61
+ self.forward_button.clicked.connect(self.forward)
62
+ self.address_bar_layout.addWidget(self.forward_button)
63
+
64
+ # Add address bar
65
+ self.address_bar = QLineEdit()
66
+ self.address_bar.setPlaceholderText("Enter URL...")
67
+ self.address_bar.returnPressed.connect(self.navigate_to_url)
68
+ self.address_bar_layout.addWidget(self.address_bar)
69
+
70
+ # Add go button
71
+ self.go_button = QPushButton("Go")
72
+ self.go_button.clicked.connect(self.navigate_to_url)
73
+ self.address_bar_layout.addWidget(self.go_button)
74
+
75
+ self.browser_layout.addLayout(self.address_bar_layout)
76
+
77
+ def navigate_to_url(self) -> None:
78
+ """Navigate to the URL entered in the address bar.
79
+
80
+ Takes the URL from the address bar text field and loads it in the browser.
81
+ """
82
+ url = self.address_bar.text()
83
+ self.load(QUrl(url))
84
+
85
+ def make_widget(self) -> None:
86
+ """Make the widget.
87
+
88
+ Creates the main browser widget with vertical layout, sets size policy,
89
+ creates the address bar, and adds components to the parent layout.
90
+ """
91
+ self.browser_widget = QWidget()
92
+ self.browser_layout = QVBoxLayout(self.browser_widget)
93
+ self.set_size_policy()
94
+ self.make_address_bar()
95
+ self.browser_layout.addWidget(self)
96
+ self.parent_layout.addWidget(self.browser_widget)
97
+
98
+ def set_size_policy(self) -> None:
99
+ """Set the size policy.
100
+
101
+ Sets the browser to expand in both horizontal and vertical directions.
102
+ """
103
+ self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
104
+
105
+ def connect_signals(self) -> None:
106
+ """Connect the signals.
107
+
108
+ Connects load finished signal and cookie added signal handlers.
109
+ """
110
+ self.connect_load_finished_signal()
111
+ self.connect_on_cookie_added_signal()
112
+
113
+ def connect_load_finished_signal(self) -> None:
114
+ """Connect the load finished signal.
115
+
116
+ Connects the loadStarted signal to the on_load_started handler.
117
+ """
118
+ self.loadFinished.connect(self.on_load_finished)
119
+
120
+ def on_load_finished(self, _ok: bool) -> None: # noqa: FBT001
121
+ """Handle the load finished signal.
122
+
123
+ Args:
124
+ _ok: Boolean indicating if the load was successful (unused).
125
+ """
126
+ self.update_address_bar(self.url())
127
+
128
+ def update_address_bar(self, url: QUrl) -> None:
129
+ """Update the address bar with the current URL.
130
+
131
+ Args:
132
+ url: The QUrl to display in the address bar.
133
+ """
134
+ self.address_bar.setText(url.toString())
135
+
136
+ def connect_on_cookie_added_signal(self) -> None:
137
+ """Connect the on cookie added signal.
138
+
139
+ Initializes the cookies dictionary and connects the cookieAdded signal
140
+ to the on_cookie_added handler.
141
+ """
142
+ self.cookies: dict[str, list[QNetworkCookie]] = defaultdict(list)
143
+ self.page().profile().cookieStore().cookieAdded.connect(self.on_cookie_added)
144
+
145
+ def on_cookie_added(self, cookie: Any) -> None:
146
+ """Handle the on cookie added signal.
147
+
148
+ Args:
149
+ cookie: The QNetworkCookie that was added.
150
+ """
151
+ self.cookies[cookie.domain()].append(cookie)
152
+
153
+ def load_first_url(self) -> None:
154
+ """Load the first URL.
155
+
156
+ Loads Google's homepage as the initial page when the browser starts.
157
+ """
158
+ self.load(QUrl("https://www.google.com/"))
159
+
160
+ @property
161
+ def http_cookies(self) -> dict[str, list[Cookie]]:
162
+ """Get the http cookies for all domains.
163
+
164
+ Returns:
165
+ Dictionary mapping domain names to lists of http.cookiejar.Cookie objects.
166
+ """
167
+ return {
168
+ domain: self.qcookies_to_httpcookies(qcookies)
169
+ for domain, qcookies in self.cookies.items()
170
+ }
171
+
172
+ def qcookies_to_httpcookies(self, qcookies: list[QNetworkCookie]) -> list[Cookie]:
173
+ """Convert a list of QNetworkCookies to http.cookiejar.Cookie objects.
174
+
175
+ Args:
176
+ qcookies: List of QNetworkCookie objects to convert.
177
+
178
+ Returns:
179
+ List of converted http.cookiejar.Cookie objects.
180
+ """
181
+ return [self.qcookie_to_httpcookie(q_cookie) for q_cookie in qcookies]
182
+
183
+ def qcookie_to_httpcookie(self, qcookie: QNetworkCookie) -> Cookie:
184
+ """Convert a QNetworkCookie to a http.cookiejar.Cookie.
185
+
186
+ Args:
187
+ qcookie: The QNetworkCookie to convert.
188
+
189
+ Returns:
190
+ The converted http.cookiejar.Cookie object.
191
+ """
192
+ name = bytes(qcookie.name().data()).decode()
193
+ value = bytes(qcookie.value().data()).decode()
194
+ domain = qcookie.domain()
195
+ path = qcookie.path() if qcookie.path() else "/"
196
+ secure = qcookie.isSecure()
197
+ expires = None
198
+ if qcookie.expirationDate().isValid():
199
+ expires = int(qcookie.expirationDate().toSecsSinceEpoch())
200
+ rest = {"HttpOnly": str(qcookie.isHttpOnly())}
201
+
202
+ return Cookie(
203
+ version=0,
204
+ name=name,
205
+ value=value,
206
+ port=None,
207
+ port_specified=False,
208
+ domain=domain,
209
+ domain_specified=bool(domain),
210
+ domain_initial_dot=domain.startswith("."),
211
+ path=path,
212
+ path_specified=bool(path),
213
+ secure=secure,
214
+ expires=expires or None,
215
+ discard=False,
216
+ comment=None,
217
+ comment_url=None,
218
+ rest=rest,
219
+ rfc2109=False,
220
+ )
221
+
222
+ def get_domain_cookies(self, domain: str) -> list[QNetworkCookie]:
223
+ """Get the cookies for the given domain.
224
+
225
+ Args:
226
+ domain: The domain to get cookies for.
227
+
228
+ Returns:
229
+ List of QNetworkCookie objects for the specified domain.
230
+ """
231
+ return self.cookies[domain]
232
+
233
+ def get_domain_http_cookies(self, domain: str) -> list[Cookie]:
234
+ """Get the http cookies for the given domain.
235
+
236
+ Args:
237
+ domain: The domain to get cookies for.
238
+
239
+ Returns:
240
+ List of http.cookiejar.Cookie objects for the specified domain.
241
+ """
242
+ cookies = self.get_domain_cookies(domain)
243
+ return self.qcookies_to_httpcookies(cookies)
@@ -0,0 +1,57 @@
1
+ """Clickable widget module.
2
+
3
+ This module contains clickable widget classes that emit signals when clicked.
4
+ Provides both regular QWidget and QVideoWidget variants with click functionality.
5
+ """
6
+
7
+ from typing import Any
8
+
9
+ from PySide6.QtCore import Qt, Signal
10
+ from PySide6.QtMultimediaWidgets import QVideoWidget
11
+ from PySide6.QtWidgets import QWidget
12
+
13
+
14
+ class ClickableWidget(QWidget):
15
+ """Widget that can be clicked.
16
+
17
+ A QWidget subclass that emits a clicked signal when the left mouse
18
+ button is pressed on the widget.
19
+ """
20
+
21
+ clicked = Signal()
22
+
23
+ def mousePressEvent(self, event: Any) -> None: # noqa: N802
24
+ """Handle mouse press event.
25
+
26
+ Emits the clicked signal when the left mouse button is pressed
27
+ and passes the event to the parent class.
28
+
29
+ Args:
30
+ event: The mouse press event containing button and position information.
31
+ """
32
+ if event.button() == Qt.MouseButton.LeftButton:
33
+ self.clicked.emit()
34
+ super().mousePressEvent(event)
35
+
36
+
37
+ class ClickableVideoWidget(QVideoWidget):
38
+ """Video widget that can be clicked.
39
+
40
+ A QVideoWidget subclass that emits a clicked signal when the left mouse
41
+ button is pressed on the video widget.
42
+ """
43
+
44
+ clicked = Signal()
45
+
46
+ def mousePressEvent(self, event: Any) -> None: # noqa: N802
47
+ """Handle mouse press event.
48
+
49
+ Emits the clicked signal when the left mouse button is pressed
50
+ and passes the event to the parent class.
51
+
52
+ Args:
53
+ event: The mouse press event containing button and position information.
54
+ """
55
+ if event.button() == Qt.MouseButton.LeftButton:
56
+ self.clicked.emit()
57
+ super().mousePressEvent(event)