pyloid 0.26.9__tar.gz → 0.27.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyloid
3
- Version: 0.26.9
3
+ Version: 0.27.1
4
4
  Summary:
5
5
  Author: aesthetics-of-record
6
6
  Author-email: 111675679+aesthetics-of-record@users.noreply.github.com
@@ -59,7 +59,7 @@ npm create pyloid-app@latest
59
59
 
60
60
  ## Documentation 📚
61
61
 
62
- [Pyloid Documentation](https://docs.pyloid.com/)
62
+ [Pyloid Documentation](https://pyloid.com/)
63
63
 
64
64
  ## License
65
65
 
@@ -39,7 +39,7 @@ npm create pyloid-app@latest
39
39
 
40
40
  ## Documentation 📚
41
41
 
42
- [Pyloid Documentation](https://docs.pyloid.com/)
42
+ [Pyloid Documentation](https://pyloid.com/)
43
43
 
44
44
  ## License
45
45
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyloid"
3
- version = "0.26.9"
3
+ version = "0.27.1"
4
4
  description = ""
5
5
  authors = ["aesthetics-of-record <111675679+aesthetics-of-record@users.noreply.github.com>"]
6
6
  readme = "README.md"
@@ -408,7 +408,7 @@ class _BrowserWindow:
408
408
  frame: bool = True,
409
409
  context_menu: bool = False,
410
410
  dev_tools: bool = False,
411
- transparent: bool = False,
411
+ transparent: bool = False,
412
412
  IPCs: List[PyloidIPC] = [],
413
413
  ):
414
414
  ###########################################################################################
@@ -730,6 +730,8 @@ class _BrowserWindow:
730
730
  };
731
731
  // console.log('pyloid.EventAPI object initialized:', window.pyloid.EventAPI);
732
732
 
733
+ window.ipc = {};
734
+
733
735
  %s
734
736
 
735
737
  %s
@@ -748,17 +750,18 @@ class _BrowserWindow:
748
750
  console.error('QWebChannel is not defined.');
749
751
  }
750
752
  """
751
- ipcs_init_code = "\n".join(
752
- [
753
- f"window['ipc']['{ipc.__class__.__name__}'] = channel.objects['{ipc.__class__.__name__}'];\n"
754
- f"console.log('{ipc.__class__.__name__} object initialized:', window['ipc']['{ipc.__class__.__name__}']);"
755
- for ipc in self.IPCs
756
- ]
753
+ ipcs_init_code = '\n'.join(
754
+ [
755
+ f"window['ipc']['{ipc.__class__.__name__}'] = channel.objects['{ipc.__class__.__name__}'];\n"
756
+ f"console.log('{ipc.__class__.__name__} object initialized:', window['ipc']['{ipc.__class__.__name__}']);"
757
+ for ipc in self.IPCs
758
+ if ipc.__class__.__name__ != 'BaseIPC'
759
+ ]
757
760
  )
758
761
 
759
762
  base_ipc_init = "window['__PYLOID__'] = channel.objects['__PYLOID__'];\n"
760
763
 
761
- self.web_view.page().runJavaScript(js_code % base_ipc_init % ipcs_init_code)
764
+ self.web_view.page().runJavaScript(js_code % (base_ipc_init, ipcs_init_code))
762
765
 
763
766
  # if splash screen is set, close it when the page is loaded
764
767
  if self.close_on_load and self.splash_screen:
@@ -0,0 +1,164 @@
1
+ from PySide6.QtCore import (
2
+ QObject,
3
+ Slot,
4
+ )
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ )
8
+
9
+ if TYPE_CHECKING:
10
+ from pyloid.pyloid import (
11
+ Pyloid,
12
+ )
13
+ from pyloid.browser_window import (
14
+ BrowserWindow,
15
+ )
16
+
17
+
18
+ class PyloidIPC(QObject):
19
+ """
20
+ PyloidIPC class.
21
+ It enables communication between JavaScript and Python via IPC.
22
+
23
+ Usage Example
24
+ -------------
25
+ (Python)
26
+ ```python
27
+ from pyloid import Pyloid
28
+ from pyloid.ipc import PyloidIPC, Bridge
29
+
30
+ app = Pyloid('Pyloid-App')
31
+
32
+ class CustomIPC(PyloidIPC):
33
+ @Bridge(str, result=str)
34
+ def echo(self, message):
35
+ return f'Message received in Python: {message}'
36
+
37
+ @Bridge(int, int, result=int)
38
+ def add(self, a, b):
39
+ return a + b
40
+
41
+ @Bridge(result=str)
42
+ def create_window(self):
43
+ win = self.pyloid.create_window(title='Pyloid Browser')
44
+ win.load_url('https://www.google.com')
45
+ win.show()
46
+ win.focus()
47
+ return win.get_id()
48
+
49
+ # Create main window
50
+ window = app.create_window(
51
+ title='Pyloid Browser',
52
+ ipc=[CustomIPC()],
53
+ )
54
+
55
+ window.load_file('index.html')
56
+ window.show()
57
+ window.focus()
58
+
59
+ app.run()
60
+ ```
61
+
62
+ ---
63
+
64
+ (JavaScript)
65
+ ```javascript
66
+ import { ipc } from 'pyloid-js';
67
+
68
+ let result = await ipc.CustomIPC.echo('Hello, Pyloid!').then((result) => {
69
+ console.log(result); // "Message received in Python: Hello, Pyloid!"
70
+ })
71
+
72
+ let sum = await ipc.CustomIPC.add(5, 3).then((sum) => {
73
+ console.log(sum); // 8
74
+ })
75
+
76
+ let window_id = await ipc.CustomIPC.create_window().then((window_id) => {
77
+ console.log(window_id); // "eae338a3-c8cb-4103-852f-404486beea0d"
78
+ })
79
+ ```
80
+ """
81
+
82
+ def __init__(
83
+ self,
84
+ ):
85
+ super().__init__()
86
+ self.window_id: str = None
87
+ self.window: 'BrowserWindow' = None
88
+ self.pyloid: 'Pyloid' = None
89
+
90
+
91
+ def Bridge(
92
+ *args,
93
+ **kwargs,
94
+ ):
95
+ """
96
+ Bridge function creates a slot that can be IPC from JavaScript.
97
+
98
+ Parameters
99
+ ----------
100
+ *args : tuple
101
+ Variable length argument list.
102
+ **kwargs : dict
103
+ Arbitrary keyword arguments.
104
+
105
+ Usage Example
106
+ -------------
107
+ (Python)
108
+ ```python
109
+ from pyloid import Pyloid
110
+ from pyloid.ipc import PyloidIPC, Bridge
111
+
112
+ app = Pyloid('Pyloid-App')
113
+
114
+ class CustomIPC(PyloidIPC):
115
+ @Bridge(str, result=str)
116
+ def echo(self, message):
117
+ return f'Message received in Python: {message}'
118
+
119
+ @Bridge(int, int, result=int)
120
+ def add(self, a, b):
121
+ return a + b
122
+
123
+ @Bridge(result=str)
124
+ def create_window(self):
125
+ win = self.pyloid.create_window(title='Pyloid Browser')
126
+ win.load_url('https://www.google.com')
127
+ win.show()
128
+ win.focus()
129
+ return win.get_id()
130
+
131
+ # Create main window
132
+ window = app.create_window(
133
+ title='Pyloid Browser',
134
+ ipc=[CustomIPC()],
135
+ )
136
+
137
+ window.load_file('index.html')
138
+ window.show()
139
+ window.focus()
140
+
141
+ app.run()
142
+ ```
143
+ ---
144
+ (JavaScript)
145
+ ```javascript
146
+ import { ipc } from 'pyloid-js';
147
+
148
+ let result = await ipc.CustomIPC.echo('Hello, Pyloid!').then((result) => {
149
+ console.log(result); // "Message received in Python: Hello, Pyloid!"
150
+ })
151
+
152
+ let sum = await ipc.CustomIPC.add(5, 3).then((sum) => {
153
+ console.log(sum); // 8
154
+ })
155
+
156
+ let window_id = await ipc.CustomIPC.create_window().then((window_id) => {
157
+ console.log(window_id); // "eae338a3-c8cb-4103-852f-404486beea0d"
158
+ })
159
+ ```
160
+ """
161
+ return Slot(
162
+ *args,
163
+ **kwargs,
164
+ )
@@ -1,142 +0,0 @@
1
- from PySide6.QtCore import (
2
- QObject,
3
- Slot,
4
- )
5
- from typing import (
6
- TYPE_CHECKING,
7
- )
8
-
9
- if TYPE_CHECKING:
10
- from pyloid.pyloid import (
11
- Pyloid,
12
- )
13
- from pyloid.browser_window import (
14
- BrowserWindow,
15
- )
16
-
17
-
18
- class PyloidIPC(QObject):
19
- """
20
- PyloidIPC class.
21
- It enables communication between JavaScript and Python via IPC.
22
-
23
- Usage Example
24
- -------------
25
- (Python)
26
- ```python
27
- from pyloid import (
28
- Pyloid,
29
- )
30
- from pyloid.ipc import (
31
- PyloidIPC,
32
- Bridge,
33
- )
34
-
35
- app = Pyloid('Pyloid-App')
36
-
37
-
38
- class CustomIPC(PyloidIPC):
39
- @Bridge(
40
- str,
41
- result=str,
42
- )
43
- def echo(
44
- self,
45
- message,
46
- ):
47
- return f'Message received in Python: {message}'
48
-
49
-
50
- # Create main window
51
- window = app.create_window(
52
- title='Pyloid Browser',
53
- ipc=[CustomIPC()],
54
- )
55
-
56
- window.load_file('index.html')
57
-
58
- window.show()
59
- window.focus()
60
-
61
- app.run()
62
- ```
63
- ---
64
- (JavaScript)
65
- ```javascript
66
- let result = await window.pyloid.CustomIPC.echo('Hello, Pyloid!');
67
- console.log(result);
68
- ```
69
- """
70
-
71
- def __init__(
72
- self,
73
- ):
74
- super().__init__()
75
- self.window_id: str = None
76
- self.window: 'BrowserWindow' = None
77
- self.pyloid: 'Pyloid' = None
78
-
79
-
80
- def Bridge(
81
- *args,
82
- **kwargs,
83
- ):
84
- """
85
- Bridge function creates a slot that can be IPC from JavaScript.
86
-
87
- Parameters
88
- ----------
89
- *args : tuple
90
- Variable length argument list.
91
- **kwargs : dict
92
- Arbitrary keyword arguments.
93
-
94
- Usage Example
95
- -------------
96
- (Python)
97
- ```python
98
- from pyloid import (
99
- Pyloid,
100
- PyloidIPC,
101
- Bridge,
102
- )
103
-
104
- app = Pyloid('Pyloid-App')
105
-
106
-
107
- class CustomIPC(PyloidIPC):
108
- @Bridge(
109
- str,
110
- result=str,
111
- )
112
- def echo(
113
- self,
114
- message,
115
- ):
116
- return f'Message received in Python: {message}'
117
-
118
-
119
- # Create main window
120
- window = app.create_window(
121
- title='Pyloid Browser',
122
- ipc=[CustomIPC()],
123
- )
124
-
125
- window.load_file('index.html')
126
-
127
- window.show()
128
- window.focus()
129
-
130
- app.run()
131
- ```
132
- ---
133
- (JavaScript)
134
- ```javascript
135
- let result = await window.pyloid.CustomIPC.echo('Hello, Pyloid!');
136
- console.log(result);
137
- ```
138
- """
139
- return Slot(
140
- *args,
141
- **kwargs,
142
- )
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
File without changes