pyloid 0.20.2__py3-none-any.whl → 0.20.2.dev0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pyloid/__init__.py CHANGED
@@ -1,8 +1,8 @@
1
- from .pyloid import Pyloid
2
- from .api import PyloidAPI, Bridge
3
- from .utils import get_production_path, is_production
4
- from .tray import TrayEvent
5
- from .timer import PyloidTimer
6
- from .builder import build_from_spec, cleanup_before_build, create_spec_from_json, get_site_packages
7
-
1
+ from .pyloid import Pyloid
2
+ from .api import PyloidAPI, Bridge
3
+ from .utils import get_production_path, is_production
4
+ from .tray import TrayEvent
5
+ from .timer import PyloidTimer
6
+ from .builder import build_from_spec, cleanup_before_build, create_spec_from_json, get_site_packages
7
+
8
8
  __all__ = ['Pyloid', 'PyloidAPI', 'Bridge', 'get_production_path', 'is_production', 'TrayEvent', 'PyloidTimer', 'build_from_spec', 'cleanup_before_build', 'create_spec_from_json', 'get_site_packages']
pyloid/api.py CHANGED
@@ -1,104 +1,104 @@
1
- from PySide6.QtCore import QObject, Slot
2
- from typing import TYPE_CHECKING
3
-
4
- if TYPE_CHECKING:
5
- from pyloid.pyloid import Pyloid
6
- from pyloid.browser_window import BrowserWindow
7
-
8
-
9
- class PyloidAPI(QObject):
10
- """
11
- PyloidAPI class is derived from PySide6's QObject.
12
- It enables communication between JavaScript and Python.
13
-
14
- Usage Example
15
- -------------
16
- (Python)
17
- ```python
18
- from pyloid import Pyloid, PyloidAPI, Bridge
19
-
20
- app = Pyloid("Pyloid-App")
21
-
22
- class CustomAPI(PyloidAPI):
23
- @Bridge(str, result=str)
24
- def echo(self, message):
25
- return f"Message received in Python: {message}"
26
-
27
- # Create main window
28
- window = app.create_window(
29
- title="Pyloid Browser",
30
- js_apis=[CustomAPI()],
31
- )
32
-
33
- window.load_file("index.html")
34
-
35
- window.show()
36
- window.focus()
37
-
38
- app.run()
39
- ```
40
- ---
41
- (JavaScript)
42
- ```javascript
43
- document.addEventListener('pyloidReady', async function () {
44
- let result = await window.pyloid.CustomAPI.echo('Hello, Pyloid!');
45
- console.log(result);
46
- });
47
- ```
48
-
49
- """
50
-
51
- def __init__(self):
52
- super().__init__()
53
- self.window_id: str = None
54
- self.window: "BrowserWindow" = None
55
- self.app: "Pyloid" = None
56
-
57
-
58
- def Bridge(*args, **kwargs):
59
- """
60
- Bridge function creates a slot that can be called from JavaScript.
61
-
62
- Parameters
63
- ----------
64
- *args : tuple
65
- Variable length argument list.
66
- **kwargs : dict
67
- Arbitrary keyword arguments.
68
-
69
- Usage Example
70
- -------------
71
- (Python)
72
- ```python
73
- from pyloid import Pyloid, PyloidAPI, Bridge
74
-
75
- app = Pyloid("Pyloid-App")
76
-
77
- class CustomAPI(PyloidAPI):
78
- @Bridge(str, result=str)
79
- def echo(self, message):
80
- return f"Message received in Python: {message}"
81
-
82
- # Create main window
83
- window = app.create_window(
84
- title="Pyloid Browser",
85
- js_apis=[CustomAPI()],
86
- )
87
-
88
- window.load_file("index.html")
89
-
90
- window.show()
91
- window.focus()
92
-
93
- app.run()
94
- ```
95
- ---
96
- (JavaScript)
97
- ```javascript
98
- document.addEventListener('pyloidReady', async function () {
99
- let result = await window.pyloid.CustomAPI.echo('Hello, Pyloid!');
100
- console.log(result);
101
- });
102
- ```
103
- """
104
- return Slot(*args, **kwargs)
1
+ from PySide6.QtCore import QObject, Slot
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ from pyloid.pyloid import Pyloid
6
+ from pyloid.browser_window import BrowserWindow
7
+
8
+
9
+ class PyloidAPI(QObject):
10
+ """
11
+ PyloidAPI class is derived from PySide6's QObject.
12
+ It enables communication between JavaScript and Python.
13
+
14
+ Usage Example
15
+ -------------
16
+ (Python)
17
+ ```python
18
+ from pyloid import Pyloid, PyloidAPI, Bridge
19
+
20
+ app = Pyloid("Pyloid-App")
21
+
22
+ class CustomAPI(PyloidAPI):
23
+ @Bridge(str, result=str)
24
+ def echo(self, message):
25
+ return f"Message received in Python: {message}"
26
+
27
+ # Create main window
28
+ window = app.create_window(
29
+ title="Pyloid Browser",
30
+ js_apis=[CustomAPI()],
31
+ )
32
+
33
+ window.load_file("index.html")
34
+
35
+ window.show()
36
+ window.focus()
37
+
38
+ app.run()
39
+ ```
40
+ ---
41
+ (JavaScript)
42
+ ```javascript
43
+ document.addEventListener('pyloidReady', async function () {
44
+ let result = await window.pyloid.CustomAPI.echo('Hello, Pyloid!');
45
+ console.log(result);
46
+ });
47
+ ```
48
+
49
+ """
50
+
51
+ def __init__(self):
52
+ super().__init__()
53
+ self.window_id: str = None
54
+ self.window: "BrowserWindow" = None
55
+ self.app: "Pyloid" = None
56
+
57
+
58
+ def Bridge(*args, **kwargs):
59
+ """
60
+ Bridge function creates a slot that can be called from JavaScript.
61
+
62
+ Parameters
63
+ ----------
64
+ *args : tuple
65
+ Variable length argument list.
66
+ **kwargs : dict
67
+ Arbitrary keyword arguments.
68
+
69
+ Usage Example
70
+ -------------
71
+ (Python)
72
+ ```python
73
+ from pyloid import Pyloid, PyloidAPI, Bridge
74
+
75
+ app = Pyloid("Pyloid-App")
76
+
77
+ class CustomAPI(PyloidAPI):
78
+ @Bridge(str, result=str)
79
+ def echo(self, message):
80
+ return f"Message received in Python: {message}"
81
+
82
+ # Create main window
83
+ window = app.create_window(
84
+ title="Pyloid Browser",
85
+ js_apis=[CustomAPI()],
86
+ )
87
+
88
+ window.load_file("index.html")
89
+
90
+ window.show()
91
+ window.focus()
92
+
93
+ app.run()
94
+ ```
95
+ ---
96
+ (JavaScript)
97
+ ```javascript
98
+ document.addEventListener('pyloidReady', async function () {
99
+ let result = await window.pyloid.CustomAPI.echo('Hello, Pyloid!');
100
+ console.log(result);
101
+ });
102
+ ```
103
+ """
104
+ return Slot(*args, **kwargs)
pyloid/autostart.py CHANGED
@@ -1,101 +1,101 @@
1
- import sys
2
- import os
3
- if sys.platform == "win32":
4
- import winreg as reg
5
-
6
- class AutoStart:
7
- def __init__(self, app_name, app_path):
8
- self.app_name = app_name
9
- self.app_path = app_path
10
-
11
- def set_auto_start(self, enable: bool):
12
- if sys.platform == "win32":
13
- self._set_auto_start_windows(enable)
14
- elif sys.platform == "darwin":
15
- self._set_auto_start_macos(enable)
16
- elif sys.platform.startswith("linux"):
17
- self._set_auto_start_linux(enable)
18
-
19
- def _set_auto_start_windows(self, enable: bool):
20
- key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
21
- try:
22
- key = reg.OpenKey(reg.HKEY_CURRENT_USER, key_path, 0, reg.KEY_ALL_ACCESS)
23
- if enable:
24
- reg.SetValueEx(key, self.app_name, 0, reg.REG_SZ, self.app_path)
25
- else:
26
- reg.DeleteValue(key, self.app_name)
27
- reg.CloseKey(key)
28
- return True
29
- except WindowsError:
30
- return False
31
-
32
- def _set_auto_start_macos(self, enable: bool):
33
- plist_path = os.path.expanduser(f"~/Library/LaunchAgents/com.{self.app_name}.plist")
34
- plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
35
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
36
- <plist version="1.0">
37
- <dict>
38
- <key>Label</key>
39
- <string>com.{self.app_name}</string>
40
- <key>ProgramArguments</key>
41
- <array>
42
- <string>{self.app_path}</string>
43
- </array>
44
- <key>RunAtLoad</key>
45
- <true/>
46
- <key>KeepAlive</key>
47
- <false/>
48
- </dict>
49
- </plist>
50
- """
51
- try:
52
- if enable:
53
- os.makedirs(os.path.dirname(plist_path), exist_ok=True)
54
- with open(plist_path, "w") as f:
55
- f.write(plist_content)
56
- os.chmod(plist_path, 0o644)
57
- else:
58
- if os.path.exists(plist_path):
59
- os.remove(plist_path)
60
- return True
61
- except (IOError, OSError) as e:
62
- print(f"Error setting auto start on macOS: {e}")
63
- return False
64
-
65
- def _set_auto_start_linux(self, enable: bool):
66
- autostart_dir = os.path.expanduser("~/.config/autostart")
67
- desktop_file_path = os.path.join(autostart_dir, f"{self.app_name}.desktop")
68
- desktop_content = f"""[Desktop Entry]
69
- Type=Application
70
- Exec={self.app_path}
71
- Hidden=false
72
- NoDisplay=false
73
- X-GNOME-Autostart-enabled=true
74
- Name={self.app_name}
75
- Comment=Pylon Application
76
- """
77
- if enable:
78
- os.makedirs(autostart_dir, exist_ok=True)
79
- with open(desktop_file_path, "w") as f:
80
- f.write(desktop_content)
81
- else:
82
- if os.path.exists(desktop_file_path):
83
- os.remove(desktop_file_path)
84
-
85
- def is_auto_start(self):
86
- if sys.platform == "win32":
87
- key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
88
- try:
89
- key = reg.OpenKey(reg.HKEY_CURRENT_USER, key_path, 0, reg.KEY_READ)
90
- reg.QueryValueEx(key, self.app_name)
91
- reg.CloseKey(key)
92
- return True
93
- except WindowsError:
94
- return False
95
- elif sys.platform == "darwin":
96
- plist_path = os.path.expanduser(f"~/Library/LaunchAgents/com.{self.app_name}.plist")
97
- return os.path.exists(plist_path)
98
- elif sys.platform.startswith("linux"):
99
- desktop_file_path = os.path.expanduser(f"~/.config/autostart/{self.app_name}.desktop")
100
- return os.path.exists(desktop_file_path)
101
- return False
1
+ import sys
2
+ import os
3
+ if sys.platform == "win32":
4
+ import winreg as reg
5
+
6
+ class AutoStart:
7
+ def __init__(self, app_name, app_path):
8
+ self.app_name = app_name
9
+ self.app_path = app_path
10
+
11
+ def set_auto_start(self, enable: bool):
12
+ if sys.platform == "win32":
13
+ self._set_auto_start_windows(enable)
14
+ elif sys.platform == "darwin":
15
+ self._set_auto_start_macos(enable)
16
+ elif sys.platform.startswith("linux"):
17
+ self._set_auto_start_linux(enable)
18
+
19
+ def _set_auto_start_windows(self, enable: bool):
20
+ key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
21
+ try:
22
+ key = reg.OpenKey(reg.HKEY_CURRENT_USER, key_path, 0, reg.KEY_ALL_ACCESS)
23
+ if enable:
24
+ reg.SetValueEx(key, self.app_name, 0, reg.REG_SZ, self.app_path)
25
+ else:
26
+ reg.DeleteValue(key, self.app_name)
27
+ reg.CloseKey(key)
28
+ return True
29
+ except WindowsError:
30
+ return False
31
+
32
+ def _set_auto_start_macos(self, enable: bool):
33
+ plist_path = os.path.expanduser(f"~/Library/LaunchAgents/com.{self.app_name}.plist")
34
+ plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
35
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
36
+ <plist version="1.0">
37
+ <dict>
38
+ <key>Label</key>
39
+ <string>com.{self.app_name}</string>
40
+ <key>ProgramArguments</key>
41
+ <array>
42
+ <string>{self.app_path}</string>
43
+ </array>
44
+ <key>RunAtLoad</key>
45
+ <true/>
46
+ <key>KeepAlive</key>
47
+ <false/>
48
+ </dict>
49
+ </plist>
50
+ """
51
+ try:
52
+ if enable:
53
+ os.makedirs(os.path.dirname(plist_path), exist_ok=True)
54
+ with open(plist_path, "w") as f:
55
+ f.write(plist_content)
56
+ os.chmod(plist_path, 0o644)
57
+ else:
58
+ if os.path.exists(plist_path):
59
+ os.remove(plist_path)
60
+ return True
61
+ except (IOError, OSError) as e:
62
+ print(f"Error setting auto start on macOS: {e}")
63
+ return False
64
+
65
+ def _set_auto_start_linux(self, enable: bool):
66
+ autostart_dir = os.path.expanduser("~/.config/autostart")
67
+ desktop_file_path = os.path.join(autostart_dir, f"{self.app_name}.desktop")
68
+ desktop_content = f"""[Desktop Entry]
69
+ Type=Application
70
+ Exec={self.app_path}
71
+ Hidden=false
72
+ NoDisplay=false
73
+ X-GNOME-Autostart-enabled=true
74
+ Name={self.app_name}
75
+ Comment=Pylon Application
76
+ """
77
+ if enable:
78
+ os.makedirs(autostart_dir, exist_ok=True)
79
+ with open(desktop_file_path, "w") as f:
80
+ f.write(desktop_content)
81
+ else:
82
+ if os.path.exists(desktop_file_path):
83
+ os.remove(desktop_file_path)
84
+
85
+ def is_auto_start(self):
86
+ if sys.platform == "win32":
87
+ key_path = r"Software\Microsoft\Windows\CurrentVersion\Run"
88
+ try:
89
+ key = reg.OpenKey(reg.HKEY_CURRENT_USER, key_path, 0, reg.KEY_READ)
90
+ reg.QueryValueEx(key, self.app_name)
91
+ reg.CloseKey(key)
92
+ return True
93
+ except WindowsError:
94
+ return False
95
+ elif sys.platform == "darwin":
96
+ plist_path = os.path.expanduser(f"~/Library/LaunchAgents/com.{self.app_name}.plist")
97
+ return os.path.exists(plist_path)
98
+ elif sys.platform.startswith("linux"):
99
+ desktop_file_path = os.path.expanduser(f"~/.config/autostart/{self.app_name}.desktop")
100
+ return os.path.exists(desktop_file_path)
101
+ return False