winipedia-utils 0.1.39__py3-none-any.whl → 0.1.41__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.
@@ -14,11 +14,17 @@ class Browser(BasePage):
14
14
 
15
15
  @final
16
16
  def setup(self) -> None:
17
- """Setup the UI."""
18
- # add a download button in the top right
17
+ """Setup the UI.
18
+
19
+ Initializes the browser page by adding a browser widget to the layout.
20
+ """
19
21
  self.add_brwoser()
20
22
 
21
23
  @final
22
24
  def add_brwoser(self) -> None:
23
- """Add a browser to surfe the web."""
25
+ """Add a browser to surf the web.
26
+
27
+ Creates and adds a BrowserWidget instance to the vertical layout,
28
+ enabling web browsing functionality within the page.
29
+ """
24
30
  self.browser = BrowserWidget(self.v_layout)
@@ -3,8 +3,12 @@
3
3
  This module contains the player page class for the VideoVault application.
4
4
  """
5
5
 
6
+ from abc import abstractmethod
7
+ from collections.abc import Callable
6
8
  from pathlib import Path
7
- from typing import final
9
+ from typing import Any, final
10
+
11
+ from cryptography.hazmat.primitives.ciphers.aead import AESGCM
8
12
 
9
13
  from winipedia_utils.pyside.ui.pages.base.base import Base as BasePage
10
14
  from winipedia_utils.pyside.ui.widgets.media_player import MediaPlayer
@@ -13,15 +17,73 @@ from winipedia_utils.pyside.ui.widgets.media_player import MediaPlayer
13
17
  class Player(BasePage):
14
18
  """Player page for the VideoVault application."""
15
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
+
16
29
  @final
17
30
  def setup(self) -> None:
18
- """Setup the UI."""
31
+ """Setup the UI.
32
+
33
+ Initializes the media player widget and adds it to the layout.
34
+ """
19
35
  self.media_player = MediaPlayer(self.v_layout)
20
36
 
21
37
  @final
22
- def play_file(self, path: Path) -> None:
23
- """Play the video."""
38
+ def play_file_from_func(
39
+ self,
40
+ play_func: Callable[..., Any],
41
+ path: Path,
42
+ position: int = 0,
43
+ **kwargs: Any,
44
+ ) -> None:
45
+ """Play a file using the specified function.
46
+
47
+ Sets the current page to player and calls the provided play function
48
+ with the given path and additional arguments.
49
+
50
+ Args:
51
+ play_func: The function to call for playing the file.
52
+ path: The file path to play.
53
+ position: The position to start playback from in milliseconds.
54
+ **kwargs: Additional keyword arguments to pass to the play function.
55
+ """
24
56
  # set current page to player
25
57
  self.set_current_page(self.__class__)
26
58
  # Stop current playback and clean up resources
27
- self.media_player.play_file(path)
59
+ play_func(path=path, position=position, **kwargs)
60
+
61
+ @final
62
+ def play_file(self, path: Path, position: int = 0) -> None:
63
+ """Play a regular video file.
64
+
65
+ Args:
66
+ path: The file path to play.
67
+ position: The position to start playback from in milliseconds.
68
+ """
69
+ self.play_file_from_func(
70
+ self.media_player.play_file, path=path, position=position
71
+ )
72
+
73
+ @final
74
+ def play_encrypted_file(
75
+ self, path: Path, aes_gcm: AESGCM, position: int = 0
76
+ ) -> None:
77
+ """Play an encrypted video file.
78
+
79
+ Args:
80
+ path: The encrypted file path to play.
81
+ aes_gcm: The AES-GCM cipher instance for decryption.
82
+ position: The position to start playback from in milliseconds.
83
+ """
84
+ self.play_file_from_func(
85
+ self.media_player.play_encrypted_file,
86
+ path=path,
87
+ position=position,
88
+ aes_gcm=aes_gcm,
89
+ )
@@ -26,7 +26,13 @@ class Browser(QWebEngineView):
26
26
  """Browser class that creates a simple ready to use browser and not just a view."""
27
27
 
28
28
  def __init__(self, parent_layout: QLayout, *args: Any, **kwargs: Any) -> None:
29
- """Initialize the browser."""
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
+ """
30
36
  super().__init__(*args, **kwargs)
31
37
  self.parent_layout = parent_layout
32
38
  self.make_widget()
@@ -34,7 +40,11 @@ class Browser(QWebEngineView):
34
40
  self.load_first_url()
35
41
 
36
42
  def make_address_bar(self) -> None:
37
- """Make the address bar."""
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
+ """
38
48
  self.address_bar_layout = QHBoxLayout()
39
49
 
40
50
  # Add back button
@@ -65,12 +75,19 @@ class Browser(QWebEngineView):
65
75
  self.browser_layout.addLayout(self.address_bar_layout)
66
76
 
67
77
  def navigate_to_url(self) -> None:
68
- """Navigate to the URL entered in the address bar."""
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
+ """
69
82
  url = self.address_bar.text()
70
83
  self.load(QUrl(url))
71
84
 
72
85
  def make_widget(self) -> None:
73
- """Make the widget."""
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
+ """
74
91
  self.browser_widget = QWidget()
75
92
  self.browser_layout = QVBoxLayout(self.browser_widget)
76
93
  self.set_size_policy()
@@ -79,53 +96,99 @@ class Browser(QWebEngineView):
79
96
  self.parent_layout.addWidget(self.browser_widget)
80
97
 
81
98
  def set_size_policy(self) -> None:
82
- """Set the size policy."""
99
+ """Set the size policy.
100
+
101
+ Sets the browser to expand in both horizontal and vertical directions.
102
+ """
83
103
  self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
84
104
 
85
105
  def connect_signals(self) -> None:
86
- """Connect the signals."""
106
+ """Connect the signals.
107
+
108
+ Connects load finished signal and cookie added signal handlers.
109
+ """
87
110
  self.connect_load_finished_signal()
88
111
  self.connect_on_cookie_added_signal()
89
112
 
90
113
  def connect_load_finished_signal(self) -> None:
91
- """Connect the load finished signal."""
92
- self.loadFinished.connect(self.on_load_finished)
114
+ """Connect the load finished signal.
93
115
 
94
- def on_load_finished(self, _ok: bool) -> None: # noqa: FBT001
95
- """Handle the load finished signal."""
116
+ Connects the loadStarted signal to the on_load_started handler.
117
+ """
118
+ self.loadStarted.connect(self.on_load_started)
119
+
120
+ def on_load_started(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
+ """
96
126
  self.update_address_bar(self.url())
97
127
 
98
128
  def update_address_bar(self, url: QUrl) -> None:
99
- """Update the address bar with the current URL."""
129
+ """Update the address bar with the current URL.
130
+
131
+ Args:
132
+ url: The QUrl to display in the address bar.
133
+ """
100
134
  self.address_bar.setText(url.toString())
101
135
 
102
136
  def connect_on_cookie_added_signal(self) -> None:
103
- """Connect the on cookie added signal."""
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
+ """
104
142
  self.cookies: dict[str, list[QNetworkCookie]] = defaultdict(list)
105
143
  self.page().profile().cookieStore().cookieAdded.connect(self.on_cookie_added)
106
144
 
107
145
  def on_cookie_added(self, cookie: Any) -> None:
108
- """Handle the on cookie added signal."""
146
+ """Handle the on cookie added signal.
147
+
148
+ Args:
149
+ cookie: The QNetworkCookie that was added.
150
+ """
109
151
  self.cookies[cookie.domain()].append(cookie)
110
152
 
111
153
  def load_first_url(self) -> None:
112
- """Load the first URL."""
154
+ """Load the first URL.
155
+
156
+ Loads Google's homepage as the initial page when the browser starts.
157
+ """
113
158
  self.load(QUrl("https://www.google.com/"))
114
159
 
115
160
  @property
116
161
  def http_cookies(self) -> dict[str, list[Cookie]]:
117
- """Get the http cookies for the given URL."""
162
+ """Get the http cookies for all domains.
163
+
164
+ Returns:
165
+ Dictionary mapping domain names to lists of http.cookiejar.Cookie objects.
166
+ """
118
167
  return {
119
168
  domain: self.qcookies_to_httpcookies(qcookies)
120
169
  for domain, qcookies in self.cookies.items()
121
170
  }
122
171
 
123
172
  def qcookies_to_httpcookies(self, qcookies: list[QNetworkCookie]) -> list[Cookie]:
124
- """Convert a list of QNetworkCookies to a CookieJar."""
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
+ """
125
181
  return [self.qcookie_to_httpcookie(q_cookie) for q_cookie in qcookies]
126
182
 
127
183
  def qcookie_to_httpcookie(self, qcookie: QNetworkCookie) -> Cookie:
128
- """Convert a QNetworkCookie to a http.cookiejar.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
+ """
129
192
  name = bytes(qcookie.name().data()).decode()
130
193
  value = bytes(qcookie.value().data()).decode()
131
194
  domain = qcookie.domain()
@@ -157,10 +220,24 @@ class Browser(QWebEngineView):
157
220
  )
158
221
 
159
222
  def get_domain_cookies(self, domain: str) -> list[QNetworkCookie]:
160
- """Get the cookies for the given domain."""
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
+ """
161
231
  return self.cookies[domain]
162
232
 
163
233
  def get_domain_http_cookies(self, domain: str) -> list[Cookie]:
164
- """Get the http cookies for the given domain."""
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
+ """
165
242
  cookies = self.get_domain_cookies(domain)
166
243
  return self.qcookies_to_httpcookies(cookies)
@@ -1,3 +1,9 @@
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
+
1
7
  from typing import Any
2
8
 
3
9
  from PySide6.QtCore import Qt, Signal
@@ -6,24 +12,46 @@ from PySide6.QtWidgets import QWidget
6
12
 
7
13
 
8
14
  class ClickableWidget(QWidget):
9
- """Widget that can be clicked."""
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
+ """
10
20
 
11
21
  clicked = Signal()
12
22
 
13
23
  def mousePressEvent(self, event: Any) -> None: # noqa: N802
14
- """Handle mouse press event."""
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
+ """
15
32
  if event.button() == Qt.MouseButton.LeftButton:
16
33
  self.clicked.emit()
17
34
  super().mousePressEvent(event)
18
35
 
19
36
 
20
37
  class ClickableVideoWidget(QVideoWidget):
21
- """Video widget that can be clicked."""
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
+ """
22
43
 
23
44
  clicked = Signal()
24
45
 
25
46
  def mousePressEvent(self, event: Any) -> None: # noqa: N802
26
- """Handle mouse press event."""
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
+ """
27
55
  if event.button() == Qt.MouseButton.LeftButton:
28
56
  self.clicked.emit()
29
57
  super().mousePressEvent(event)