pyloid 0.15.2__tar.gz → 0.16.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyloid
3
- Version: 0.15.2
3
+ Version: 0.16.1
4
4
  Summary:
5
5
  Author: aesthetics-of-record
6
6
  Author-email: 111675679+aesthetics-of-record@users.noreply.github.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyloid"
3
- version = "0.15.2"
3
+ version = "0.16.1"
4
4
  description = ""
5
5
  authors = ["aesthetics-of-record <111675679+aesthetics-of-record@users.noreply.github.com>"]
6
6
  readme = "README.md"
@@ -22,6 +22,8 @@ from PySide6.QtWidgets import (
22
22
  )
23
23
  from .custom.titlebar import CustomTitleBar
24
24
  from .js_api.window_api import WindowAPI
25
+ from PySide6.QtGui import QPixmap, QMovie
26
+ from PySide6.QtWidgets import QSplashScreen, QLabel
25
27
 
26
28
 
27
29
  # 어차피 load 부분에만 쓰이니까 나중에 분리해서 load 위에서 선언하자.
@@ -341,13 +343,17 @@ class BrowserWindow:
341
343
  ]
342
344
  )
343
345
  self.web_view.page().runJavaScript(js_code % js_api_init)
346
+
347
+ # if splash screen is set, close it when the page is loaded
348
+ if self.close_on_load and self.splash_screen:
349
+ self.close_splash_screen()
344
350
  else:
345
351
  pass
346
352
 
347
353
  ###########################################################################################
348
354
  # Load
349
355
  ###########################################################################################
350
- def load_file(self, file_path):
356
+ def load_file(self, file_path: str):
351
357
  """
352
358
  Loads a local HTML file into the web view.
353
359
 
@@ -368,7 +374,7 @@ class BrowserWindow:
368
374
  self.web_view.setUrl(QUrl.fromLocalFile(file_path))
369
375
  self.web_view.focusProxy().installEventFilter(self.web_view)
370
376
 
371
- def load_url(self, url):
377
+ def load_url(self, url: str):
372
378
  """
373
379
  Sets the URL of the window.
374
380
 
@@ -388,6 +394,29 @@ class BrowserWindow:
388
394
  self.web_view.setUrl(QUrl(url))
389
395
  self.web_view.focusProxy().installEventFilter(self.web_view)
390
396
 
397
+ def load_html(self, html_content: str, base_url: str = ""):
398
+ """
399
+ Loads HTML content directly into the web view.
400
+
401
+ Parameters
402
+ ----------
403
+ html_content : str
404
+ The HTML content to be loaded.
405
+ base_url : str, optional
406
+ The base URL to use for resolving relative URLs (default is "").
407
+
408
+ Examples
409
+ --------
410
+ >>> app = Pyloid(app_name="Pyloid-App")
411
+ >>> window = app.create_window("pyloid-window")
412
+ >>> html_content = "<html><body><h1>Hello, Pyloid!</h1></body></html>"
413
+ >>> window.load_html(html_content)
414
+ >>> window.show()
415
+ """
416
+ self._load()
417
+ self.web_view.setHtml(html_content, QUrl(base_url))
418
+ self.web_view.focusProxy().installEventFilter(self.web_view)
419
+
391
420
  ###########################################################################################
392
421
  # Set Parameters
393
422
  ###########################################################################################
@@ -1263,11 +1292,12 @@ class BrowserWindow:
1263
1292
  return self.resizable
1264
1293
 
1265
1294
  ###########################################################################################
1266
- # Custom Pyside6 Features
1295
+ # For Custom Pyside6 Features
1267
1296
  ###########################################################################################
1268
1297
  def get_QMainWindow(self) -> QMainWindow:
1269
1298
  """
1270
1299
  Returns the QMainWindow object of the window.
1300
+
1271
1301
  you can use all the features of QMainWindow for customizing the window.
1272
1302
 
1273
1303
  Returns
@@ -1290,3 +1320,199 @@ class BrowserWindow:
1290
1320
  ```
1291
1321
  """
1292
1322
  return self._window
1323
+
1324
+ ###########################################################################################
1325
+ # QMainWindow flags
1326
+ ###########################################################################################
1327
+ def set_window_stay_on_top(self, on_top: bool):
1328
+ """
1329
+ Sets the window stay on top flag of the window.
1330
+
1331
+ Parameters
1332
+ ----------
1333
+ on_top : bool
1334
+ True to keep the window on top, False otherwise
1335
+
1336
+ Examples
1337
+ --------
1338
+ ```python
1339
+ window.set_window_stay_on_top(True)
1340
+ window.set_window_stay_on_top(False)
1341
+ ```
1342
+ """
1343
+ flags = self._window.windowFlags()
1344
+ if on_top:
1345
+ flags |= Qt.WindowStaysOnTopHint
1346
+ else:
1347
+ flags &= ~Qt.WindowStaysOnTopHint
1348
+
1349
+ # Maintain existing flags while only changing WindowStaysOnTopHint
1350
+ # Explicitly add the close button
1351
+ flags |= Qt.WindowCloseButtonHint
1352
+
1353
+ self._window.setWindowFlags(flags)
1354
+
1355
+ # Show the window again to apply the changes
1356
+ self._window.show()
1357
+
1358
+ def set_window_stay_on_bottom(self, on_bottom: bool):
1359
+ """
1360
+ Sets the window stay on bottom flag of the window.
1361
+
1362
+ Parameters
1363
+ ----------
1364
+ on_bottom : bool
1365
+ True to keep the window on bottom, False otherwise
1366
+
1367
+ Examples
1368
+ --------
1369
+ ```python
1370
+ window.set_window_stay_on_bottom(True)
1371
+ window.set_window_stay_on_bottom(False)
1372
+ ```
1373
+ """
1374
+ flags = self._window.windowFlags()
1375
+ if on_bottom:
1376
+ flags |= Qt.WindowStaysOnBottomHint
1377
+ else:
1378
+ flags &= ~Qt.WindowStaysOnBottomHint
1379
+
1380
+ # Maintain existing flags while only changing WindowStaysOnBottomHint
1381
+ # Explicitly add the close button
1382
+ flags |= Qt.WindowCloseButtonHint
1383
+
1384
+ self._window.setWindowFlags(flags)
1385
+
1386
+ # Show the window again to apply the changes
1387
+ self._window.show()
1388
+
1389
+ ###########################################################################################
1390
+ # Splash Screen
1391
+ ###########################################################################################
1392
+ def set_static_image_splash_screen(
1393
+ self,
1394
+ image_path: str,
1395
+ close_on_load: bool = True,
1396
+ stay_on_top: bool = True,
1397
+ clickable: bool = True,
1398
+ ):
1399
+ """
1400
+ Sets the static image splash screen of the window.
1401
+
1402
+ Parameters
1403
+ ----------
1404
+ image_path : str
1405
+ Path to the image file
1406
+ close_on_load : bool, optional
1407
+ True to close the splash screen when the page is loaded, False otherwise (default is True)
1408
+ stay_on_top : bool, optional
1409
+ True to keep the splash screen on top, False otherwise (default is True)
1410
+ clickable : bool, optional
1411
+ True to make the splash screen clickable, False otherwise (default is True)
1412
+ if clickable is True, you can click the splash screen to close it.
1413
+
1414
+ Examples
1415
+ --------
1416
+ ```python
1417
+ window.set_image_splash_screen("./assets/loading.png", close_on_load=True, stay_on_top=True)
1418
+ ```
1419
+ """
1420
+ pixmap = QPixmap(image_path)
1421
+
1422
+ if not clickable:
1423
+
1424
+ class NonClickableSplashScreen(QSplashScreen):
1425
+ def mousePressEvent(self, event):
1426
+ pass # Ignore click events
1427
+
1428
+ splash = NonClickableSplashScreen(
1429
+ pixmap, Qt.WindowStaysOnTopHint if stay_on_top else Qt.WindowType(0)
1430
+ )
1431
+ else:
1432
+ splash = QSplashScreen(
1433
+ pixmap, Qt.WindowStaysOnTopHint if stay_on_top else Qt.WindowType(0)
1434
+ )
1435
+
1436
+ self.close_on_load = close_on_load
1437
+ self.splash_screen = splash
1438
+ self.splash_screen.show()
1439
+
1440
+ def set_gif_splash_screen(
1441
+ self,
1442
+ gif_path: str,
1443
+ close_on_load: bool = True,
1444
+ stay_on_top: bool = True,
1445
+ clickable: bool = True,
1446
+ ):
1447
+ """
1448
+ Sets the gif splash screen of the window.
1449
+
1450
+ Parameters
1451
+ ----------
1452
+ gif_path : str
1453
+ Path to the gif file
1454
+ close_on_load : bool, optional
1455
+ True to close the splash screen when the page is loaded, False otherwise (default is True)
1456
+ stay_on_top : bool, optional
1457
+ True to keep the splash screen on top, False otherwise (default is True)
1458
+ clickable : bool, optional
1459
+ True to make the splash screen clickable, False otherwise (default is True)
1460
+ if clickable is True, you can click the splash screen to close it.
1461
+
1462
+ Examples
1463
+ --------
1464
+ ```python
1465
+ window.set_gif_splash_screen("./assets/loading.gif", close_on_load=True, stay_on_top=True)
1466
+ ```
1467
+ """
1468
+
1469
+ if not clickable:
1470
+
1471
+ class NonClickableSplashScreen(QSplashScreen):
1472
+ def mousePressEvent(self, event):
1473
+ pass # Ignore click events
1474
+
1475
+ # Create splash screen (using animated GIF)
1476
+ splash = NonClickableSplashScreen(
1477
+ QPixmap(1, 1),
1478
+ Qt.WindowStaysOnTopHint if stay_on_top else Qt.WindowType(0),
1479
+ ) # Start with 1x1 transparent pixmap
1480
+ else:
1481
+ splash = QSplashScreen(
1482
+ QPixmap(1, 1),
1483
+ Qt.WindowStaysOnTopHint if stay_on_top else Qt.WindowType(0),
1484
+ )
1485
+
1486
+ splash.setAttribute(Qt.WA_TranslucentBackground)
1487
+
1488
+ # Create QLabel for GIF animation
1489
+ label = QLabel(splash)
1490
+ movie = QMovie(gif_path)
1491
+ label.setMovie(movie)
1492
+
1493
+ # Start animation and show splash screen
1494
+ movie.start()
1495
+ splash.show()
1496
+
1497
+ # Adjust splash screen size to match GIF size
1498
+ movie.frameChanged.connect(
1499
+ lambda: splash.setFixedSize(movie.currentPixmap().size())
1500
+ )
1501
+
1502
+ self.close_on_load = close_on_load
1503
+ self.splash_screen = splash
1504
+
1505
+ def close_splash_screen(self):
1506
+ """
1507
+ Closes the splash screen if it exists.
1508
+
1509
+ Examples
1510
+ --------
1511
+ ```python
1512
+ window.close_splash_screen()
1513
+ ```
1514
+ """
1515
+ if hasattr(self, "splash_screen") and self.splash_screen:
1516
+ self.splash_screen.close()
1517
+ self.close_on_load = None
1518
+ self.splash_screen = None
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes