pyloid 0.23.10__py3-none-any.whl → 0.23.12__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.
pyloid/browser_window.py CHANGED
@@ -48,7 +48,7 @@ import threading
48
48
  from .rpc import PyloidRPC
49
49
 
50
50
  if TYPE_CHECKING:
51
- from .pyloid import _Pyloid
51
+ from .pyloid import _Pyloid, Pyloid
52
52
 
53
53
 
54
54
  class CustomWebPage(QWebEnginePage):
@@ -300,6 +300,7 @@ class _BrowserWindow:
300
300
  def __init__(
301
301
  self,
302
302
  app: "_Pyloid",
303
+ window_wrapper: "BrowserWindow",
303
304
  title: str = "pyloid app",
304
305
  width: int = 800,
305
306
  height: int = 600,
@@ -316,6 +317,7 @@ class _BrowserWindow:
316
317
  self._window = QMainWindow()
317
318
  self.web_view = CustomWebEngineView(self)
318
319
 
320
+
319
321
  if rpc:
320
322
  self.rpc = rpc
321
323
  self.rpc_url = rpc.url
@@ -330,6 +332,7 @@ class _BrowserWindow:
330
332
  self._window.closeEvent = self.closeEvent # Override closeEvent method
331
333
  ###########################################################################################
332
334
  self.app = app
335
+ self.window_wrapper = window_wrapper
333
336
  self.title = title
334
337
  self.width = width
335
338
  self.height = height
@@ -347,11 +350,14 @@ class _BrowserWindow:
347
350
  self.shortcuts = {}
348
351
  self.close_on_load = True
349
352
  self.splash_screen = None
350
- ###########################################################################################
353
+ ###########################################################################################
351
354
  # RPC 서버가 없으면 추가하지 않음
352
355
  if not self.rpc:
353
356
  return;
354
357
 
358
+ self.rpc.pyloid = self.app.pyloid_wrapper
359
+ # self.rpc.window = self.window_wrapper
360
+
355
361
  # RPC 서버 중복 방지
356
362
  if self.rpc in self.app.rpc_servers:
357
363
  return;
@@ -362,6 +368,8 @@ class _BrowserWindow:
362
368
  # Start unique RPC servers
363
369
  server_thread = threading.Thread(target=self.rpc.start, daemon=True)
364
370
  server_thread.start()
371
+ ###########################################################################################
372
+
365
373
 
366
374
  def _set_custom_frame(
367
375
  self,
@@ -2052,7 +2060,7 @@ class BrowserWindow(QObject):
2052
2060
  ):
2053
2061
  super().__init__()
2054
2062
  self._window = _BrowserWindow(
2055
- app, title, width, height, x, y, frame, context_menu, dev_tools, rpc
2063
+ app, self, title, width, height, x, y, frame, context_menu, dev_tools, rpc
2056
2064
  )
2057
2065
  self.command_signal.connect(self._handle_command)
2058
2066
 
pyloid/pyloid.py CHANGED
@@ -87,6 +87,7 @@ class _WindowController(QObject):
87
87
  class _Pyloid(QApplication):
88
88
  def __init__(
89
89
  self,
90
+ pyloid_wrapper: "Pyloid",
90
91
  app_name,
91
92
  single_instance=True,
92
93
  data=None,
@@ -115,6 +116,8 @@ class _Pyloid(QApplication):
115
116
  ```
116
117
  """
117
118
  super().__init__(sys.argv)
119
+
120
+ self.pyloid_wrapper = pyloid_wrapper
118
121
 
119
122
  self.data = data
120
123
 
@@ -1681,7 +1684,7 @@ class Pyloid(QObject):
1681
1684
 
1682
1685
  self.data = None # 나중에 데이터 필요 시 수정
1683
1686
 
1684
- self.app = _Pyloid(app_name, single_instance, self.data)
1687
+ self.app = _Pyloid(self, app_name, single_instance, self.data)
1685
1688
 
1686
1689
  self.command_signal.connect(self._handle_command)
1687
1690
 
pyloid/rpc.py CHANGED
@@ -130,7 +130,7 @@ class PyloidRPC:
130
130
  self._app = web.Application()
131
131
 
132
132
  self.pyloid: Optional["Pyloid"] = None
133
- self.window: Optional["BrowserWindow"] = None
133
+ # self.window: Optional["BrowserWindow"] = None
134
134
 
135
135
  # CORS 설정 추가
136
136
  cors = aiohttp_cors.setup(self._app, defaults={
@@ -177,12 +177,12 @@ class PyloidRPC:
177
177
  Examples
178
178
  --------
179
179
  ```python
180
- from pyloid.rpc import PyloidRPC
180
+ from pyloid.rpc import PyloidRPC, RPCContext
181
181
 
182
182
  rpc = PyloidRPC()
183
183
 
184
184
  @rpc.method()
185
- async def add(ctx, a: int, b: int) -> int:
185
+ async def add(ctx: RPCContext, a: int, b: int) -> int:
186
186
  # Access the application and window through ctx.pyloid and ctx.window
187
187
  if ctx.window:
188
188
  print(f"Window title: {ctx.window.title}")
@@ -205,16 +205,13 @@ class PyloidRPC:
205
205
  log.info(f"RPC function registered: {rpc_name}")
206
206
 
207
207
  @wraps(func)
208
- async def wrapper(*args, **kwargs):
209
- # If the function has a 'ctx' parameter and it's not provided, inject the context object
208
+ async def wrapper(*args, _pyloid_window_id=None, **kwargs):
210
209
  if has_ctx_param and 'ctx' not in kwargs:
211
210
  ctx = RPCContext(
212
211
  pyloid=self.pyloid,
213
- window=self.window
212
+ window=self.pyloid.get_window_by_id(_pyloid_window_id)
214
213
  )
215
214
  kwargs['ctx'] = ctx
216
-
217
- # Call the original function
218
215
  return await func(*args, **kwargs)
219
216
  return wrapper
220
217
  return decorator
@@ -316,10 +313,33 @@ class PyloidRPC:
316
313
 
317
314
  try:
318
315
  log.debug(f"Executing RPC method: {method_name}(params={params})")
316
+
317
+ # 함수의 서명 분석하여 ctx 매개변수 유무 확인
318
+ sig = inspect.signature(func)
319
+ has_ctx_param = 'ctx' in sig.parameters
320
+
321
+ # ctx 매개변수가 있으면 컨텍스트 객체 생성
322
+ if has_ctx_param and isinstance(params, dict) and 'ctx' not in params:
323
+ ctx = RPCContext(
324
+ pyloid=self.pyloid,
325
+ window=self.pyloid.get_window_by_id(request_id)
326
+ )
327
+ # 딕셔너리 형태로 params 사용할 때
328
+ params = params.copy() # 원본 params 복사
329
+ params['ctx'] = ctx
330
+
319
331
  # Call the function with positional or keyword arguments
320
332
  if isinstance(params, list):
321
- result = await func(*params)
322
- else: # isinstance(params, dict)
333
+ # 리스트 형태로 params 사용할 때 처리 필요
334
+ if has_ctx_param:
335
+ ctx = RPCContext(pyloid=self.pyloid, window=self.pyloid.get_window_by_id(request_id))
336
+ result = await func(ctx, *params, request_id=request_id)
337
+ else:
338
+ result = await func(*params, request_id=request_id)
339
+ else: # isinstance(params, dict)
340
+ internal_window_id = request_id # 기존 request_id에서 이름만 변경
341
+ params = params.copy()
342
+ params['_pyloid_window_id'] = internal_window_id
323
343
  result = await func(**params)
324
344
 
325
345
  # 5. Format Success Response (only for non-notification requests)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyloid
3
- Version: 0.23.10
3
+ Version: 0.23.12
4
4
  Summary:
5
5
  Author: aesthetics-of-record
6
6
  Author-email: 111675679+aesthetics-of-record@users.noreply.github.com
@@ -1,15 +1,15 @@
1
1
  pyloid/__init__.py,sha256=YKwMCSOds1QVi9N7EGfY0Z7BEjJn8j6HGqRblZlZClA,235
2
2
  pyloid/api.py,sha256=A61Kmddh8BlpT3LfA6NbPQNzFmD95vQ4WKX53oKsGYU,2419
3
3
  pyloid/autostart.py,sha256=K7DQYl4LHItvPp0bt1V9WwaaZmVSTeGvadkcwG-KKrI,3899
4
- pyloid/browser_window.py,sha256=h0BehbCg8oUW5QGAyG1i1XjAQ020U9VWDTftDrMdwpI,100261
4
+ pyloid/browser_window.py,sha256=4w9xsTzn66YEhRRuVzu4ZXcYGh_-GQL829fYGX6ZXwc,100593
5
5
  pyloid/custom/titlebar.py,sha256=itzK9pJbZMQ7BKca9kdbuHMffurrw15UijR6OU03Xsk,3894
6
6
  pyloid/filewatcher.py,sha256=3M5zWVUf1OhlkWJcDFC8ZA9agO4Q-U8WdgGpy6kaVz0,4601
7
7
  pyloid/js_api/base.py,sha256=XD3sqWYAb1nw6VgY3xXsU4ls5xLGrxpOqmLRJm_vBso,8669
8
8
  pyloid/js_api/event_api.py,sha256=w0z1DcmwcmseqfcoZWgsQmFC2iBCgTMVJubTaHeXI1c,957
9
9
  pyloid/js_api/window_api.py,sha256=-isphU3m2wGB5U0yZrSuK_4XiBz2mG45HsjYTUq7Fxs,7348
10
10
  pyloid/monitor.py,sha256=1mXvHm5deohnNlTLcRx4sT4x-stnOIb0dUQnnxN50Uo,28295
11
- pyloid/pyloid.py,sha256=gO1wrO_5JX5mUMGGhZ-EKK0K54t9jgfJHrXagjkB9VA,85665
12
- pyloid/rpc.py,sha256=y62hr2uqkyhwdASDvjryGqY8Bga9Cw6Hda_D6XaU0nQ,17092
11
+ pyloid/pyloid.py,sha256=r70Xa-SKk0yZsJ_d2Kl-adLy7P2VX1yqxymVBVeNNa8,85762
12
+ pyloid/rpc.py,sha256=gILZkC9_SU58VAad15iRp9S2_efddJjZPJYU0iCk4c8,18342
13
13
  pyloid/serve.py,sha256=wJIBqiLr1-8FvBdV3yybeBtVXsu94FfWYKjHL0eQ68s,1444
14
14
  pyloid/store.py,sha256=p0plJj52hQjjtNMVJhy20eNLXfQ3Qmf7LtGHQk7FiPg,4471
15
15
  pyloid/thread_pool.py,sha256=fKOBb8jMfZn_7crA_fJCno8dObBRZE31EIWaNQ759aw,14616
@@ -17,7 +17,7 @@ pyloid/timer.py,sha256=RqMsChFUd93cxMVgkHWiIKrci0QDTBgJSTULnAtYT8M,8712
17
17
  pyloid/tray.py,sha256=D12opVEc2wc2T4tK9epaN1oOdeziScsIVNM2uCN7C-A,1710
18
18
  pyloid/url_interceptor.py,sha256=AFjPANDELc9-E-1TnVvkNVc-JZBJYf0677dWQ8LDaqw,726
19
19
  pyloid/utils.py,sha256=NqB8W-irXDtTGb74rrJ2swU6tgzU0HSE8lGewrStOKc,5685
20
- pyloid-0.23.10.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
21
- pyloid-0.23.10.dist-info/METADATA,sha256=NQvORTInEGRJqpmqAh_PYZINIHVI7zpM5qsZ679oR88,3198
22
- pyloid-0.23.10.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
23
- pyloid-0.23.10.dist-info/RECORD,,
20
+ pyloid-0.23.12.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
21
+ pyloid-0.23.12.dist-info/METADATA,sha256=3956skq8Asmg8_yLWVtZohJP25YSmFq0Fl2AmXdiok8,3198
22
+ pyloid-0.23.12.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
23
+ pyloid-0.23.12.dist-info/RECORD,,