pyloid 0.12.2__py3-none-any.whl → 0.13.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pyloid/pyloid.py CHANGED
@@ -262,17 +262,28 @@ class CustomWebEngineView(QWebEngineView):
262
262
  self.parent = parent
263
263
  self.drag_relative_position = None
264
264
  self.is_dragging = False
265
+ self.is_resizing = False
266
+ self.resize_start_pos = None
267
+ self.resize_direction = None
265
268
  self.screen_geometry = self.screen().availableGeometry()
269
+ self.is_resizing_enabled = True
266
270
 
267
271
  def mouse_press_event(self, event):
268
272
  if event.button() == Qt.LeftButton:
269
273
  self.drag_relative_position = event.pos()
274
+ if not self.parent.frame and self.is_resizing_enabled:
275
+ self.resize_direction = self.get_resize_direction(event.pos())
276
+ if self.resize_direction:
277
+ self.is_resizing = True
278
+ self.resize_start_pos = event.globalPos()
270
279
 
271
280
  def start_system_drag(self):
272
281
  self.is_dragging = True
273
282
 
274
283
  def mouse_move_event(self, event):
275
- if not self.parent.frame and self.is_dragging:
284
+ if self.is_resizing and self.is_resizing_enabled:
285
+ self.resize_window(event.globalPos())
286
+ elif not self.parent.frame and self.is_dragging:
276
287
  # 현재 마우스 위치를 전역 좌표로 가져옵니다
277
288
  current_global_pos = event.globalPos()
278
289
 
@@ -296,10 +307,20 @@ class CustomWebEngineView(QWebEngineView):
296
307
 
297
308
  # 창을 새 위치로 이동합니다
298
309
  self.parent._window.move(new_window_pos)
310
+ else:
311
+ # Change cursor based on resize direction
312
+ resize_direction = self.get_resize_direction(event.pos())
313
+ if resize_direction and self.is_resizing_enabled:
314
+ self.set_cursor_for_resize_direction(resize_direction)
315
+ else:
316
+ self.unsetCursor()
299
317
 
300
318
  def mouse_release_event(self, event):
301
319
  if event.button() == Qt.LeftButton:
302
320
  self.is_dragging = False
321
+ self.is_resizing = False
322
+ self.resize_direction = None
323
+ self.unsetCursor()
303
324
 
304
325
  def eventFilter(self, source, event):
305
326
  if self.focusProxy() is source:
@@ -311,6 +332,53 @@ class CustomWebEngineView(QWebEngineView):
311
332
  self.mouse_release_event(event)
312
333
  return super().eventFilter(source, event)
313
334
 
335
+ def get_resize_direction(self, pos):
336
+ if not self.parent.frame and self.is_resizing_enabled: # Check if frame is not present and resizing is enabled
337
+ margin = 5 # Margin in pixels to detect edge
338
+ rect = self.rect()
339
+ direction = None
340
+
341
+ if pos.x() <= margin:
342
+ direction = 'left'
343
+ elif pos.x() >= rect.width() - margin:
344
+ direction = 'right'
345
+
346
+ if pos.y() <= margin:
347
+ direction = 'top' if direction is None else direction + '-top'
348
+ elif pos.y() >= rect.height() - margin:
349
+ direction = 'bottom' if direction is None else direction + '-bottom'
350
+
351
+ return direction
352
+ return None
353
+
354
+ def set_cursor_for_resize_direction(self, direction):
355
+ if not self.parent.frame and direction and self.is_resizing_enabled: # Check if frame is not present and resizing is enabled
356
+ if direction in ['left', 'right']:
357
+ self.setCursor(Qt.SizeHorCursor)
358
+ elif direction in ['top', 'bottom']:
359
+ self.setCursor(Qt.SizeVerCursor)
360
+ elif direction in ['left-top', 'right-bottom']:
361
+ self.setCursor(Qt.SizeFDiagCursor)
362
+ elif direction in ['right-top', 'left-bottom']:
363
+ self.setCursor(Qt.SizeBDiagCursor)
364
+
365
+ def resize_window(self, global_pos):
366
+ if not self.parent.frame and self.resize_start_pos and self.resize_direction and self.is_resizing_enabled: # Check if frame is not present and resizing is enabled
367
+ delta = global_pos - self.resize_start_pos
368
+ new_geometry = self.parent._window.geometry()
369
+
370
+ if 'left' in self.resize_direction:
371
+ new_geometry.setLeft(new_geometry.left() + delta.x())
372
+ if 'right' in self.resize_direction:
373
+ new_geometry.setRight(new_geometry.right() + delta.x())
374
+ if 'top' in self.resize_direction:
375
+ new_geometry.setTop(new_geometry.top() + delta.y())
376
+ if 'bottom' in self.resize_direction:
377
+ new_geometry.setBottom(new_geometry.bottom() + delta.y())
378
+
379
+ self.parent._window.setGeometry(new_geometry)
380
+ self.resize_start_pos = global_pos
381
+
314
382
 
315
383
  class BrowserWindow:
316
384
  def __init__(
@@ -758,20 +826,49 @@ class BrowserWindow:
758
826
  def get_visible(self) -> bool:
759
827
  """Returns the visibility of the window."""
760
828
  return self._window.isVisible()
761
-
829
+
830
+ def get_frame(self) -> bool:
831
+ """Returns the frame enabled state of the window."""
832
+ return self.frame
833
+
834
+ ###########################################################################################
835
+ # Resize
836
+ ###########################################################################################
762
837
  def set_resizable(self, resizable: bool):
763
838
  """Sets the resizability of the window."""
764
839
  self.resizable = resizable
765
- if resizable:
766
- self._window.setWindowFlags(
767
- self._window.windowFlags() & ~Qt.MSWindowsFixedSizeDialogHint
768
- )
840
+ if self.frame:
841
+ flags = self._window.windowFlags() | Qt.WindowCloseButtonHint
842
+ if resizable:
843
+ pass
844
+ else:
845
+ flags |= Qt.MSWindowsFixedSizeDialogHint
846
+ self._window.setWindowFlags(flags)
769
847
  else:
770
- self._window.setWindowFlags(
771
- self._window.windowFlags() | Qt.MSWindowsFixedSizeDialogHint
772
- )
848
+ # 프레임이 없는 경우 커스텀 리사이징 로직을 설정합니다.
849
+ self.web_view.is_resizing_enabled = resizable
850
+
773
851
  self._window.show() # 변경사항을 적용하기 위해 창을 다시 표시합니다.
774
852
 
853
+ def set_minimum_size(self, min_width: int, min_height: int):
854
+ """Sets the minimum size of the window."""
855
+ self._window.setMinimumSize(min_width, min_height)
856
+
857
+ def set_maximum_size(self, max_width: int, max_height: int):
858
+ """Sets the maximum size of the window."""
859
+ self._window.setMaximumSize(max_width, max_height)
860
+
861
+ def get_minimum_size(self):
862
+ """Returns the minimum size of the window."""
863
+ return {'width': self._window.minimumWidth(), 'height': self._window.minimumHeight()}
864
+
865
+ def get_maximum_size(self):
866
+ """Returns the maximum size of the window."""
867
+ return {'width': self._window.maximumWidth(), 'height': self._window.maximumHeight()}
868
+
869
+ def get_resizable(self):
870
+ """Returns the resizability of the window."""
871
+ return self.resizable
775
872
 
776
873
  class _WindowController(QObject):
777
874
  create_window_signal = Signal(
@@ -790,6 +887,9 @@ class Pyloid(QApplication):
790
887
  self.windows = []
791
888
  self.server = None
792
889
 
890
+ self.app_name = app_name
891
+ self.icon = None
892
+
793
893
  self.clipboard_class = self.clipboard()
794
894
  self.shortcuts = {}
795
895
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyloid
3
- Version: 0.12.2
3
+ Version: 0.13.0
4
4
  Summary:
5
5
  Author: aesthetics-of-record
6
6
  Author-email: 111675679+aesthetics-of-record@users.noreply.github.com
@@ -65,114 +65,15 @@ Package URL: [https://pypi.org/project/pyloid/](https://pypi.org/project/pyloid/
65
65
  ```python
66
66
  from pyloid import Pyloid
67
67
 
68
- app = Pyloid(single_instance=True)
68
+ app = Pyloid(app_name="Pyloid-App", single_instance=True)
69
69
 
70
- # set icon
71
- if (is_production()):
72
- app.set_icon(os.path.join(get_production_path(), "icons/icon.png"))
73
- else:
74
- app.set_icon("src-pyloid/icons/icon.png")
75
-
76
- # create window
77
- window = app.create_window(
78
- title="Pyloid Browser",
79
- js_apis=[CustomAPI()],
80
- dev_tools=True
81
- )
82
-
83
- window.set_size(800, 600)
84
-
85
- # load html
86
- if (is_production()):
87
- window.set_dev_tools(False)
88
- window.load_file(os.path.join(get_production_path(), "src/index.html"))
89
- else:
90
- window.load_file("src/index.html")
91
-
92
- # show window
93
- window.show_and_focus()
70
+ win = app.create_window("pyloid-example")
71
+ win.load_url("https://www.example.com")
72
+ win.show_and_focus()
94
73
 
95
74
  app.run()
96
75
  ```
97
76
 
98
- ### Setting Up System Tray
99
-
100
- ```python
101
- from pyloid import TrayEvent
102
-
103
- def on_double_click():
104
- print("Tray icon was double-clicked.")
105
-
106
- app.set_tray_actions({
107
- TrayEvent.DoubleClick: on_double_click,
108
- })
109
- app.set_tray_menu_items([
110
- {"label": "Show Window", "callback": app.show_main_window},
111
- {"label": "Quit", "callback": app.quit},
112
- ])
113
- app.setup_tray()
114
- ```
115
-
116
- ```javascript
117
- // CustomAPI method usage example
118
- document.addEventListener('pyloidReady', function () {
119
- // Using the echo method
120
- window.pyloid.CustomAPI.echo('Hello', 42).then((result) => {
121
- console.log(result); // "Message received in Python: Hello, 42" output
122
- });
123
-
124
- // Using the getAppVersion method
125
- window.pyloid.CustomAPI.getAppVersion().then((version) => {
126
- console.log('App version:', version); // "App version: 1.0.0" output
127
- });
128
-
129
- // Example using async/await syntax
130
- async function useCustomAPI() {
131
- const echoResult = await window.pyloid.CustomAPI.echo('Test', 100);
132
- console.log(echoResult);
133
-
134
- const appVersion = await window.pyloid.CustomAPI.getAppVersion();
135
- console.log('Current app version:', appVersion);
136
- }
137
-
138
- useCustomAPI();
139
-
140
- // Button click event binding
141
- document.getElementById('myButton').addEventListener('click', function () {
142
- // Using the create_window method
143
- window.pyloid.CustomAPI.create_window().then((windowId) => {
144
- console.log('New window ID:', windowId); // "New window ID: [generated window ID]" output
145
- });
146
- });
147
- });
148
- ```
149
-
150
- ### Using React
151
-
152
- ```javascript
153
- import { StrictMode } from 'react';
154
- import { createRoot } from 'react-dom/client';
155
- import App from './App.jsx';
156
- import './index.css';
157
-
158
- document.addEventListener('pyloidReady', function () {
159
- createRoot(document.getElementById('root')).render(
160
- <StrictMode>
161
- <App />
162
- </StrictMode>
163
- );
164
- });
165
-
166
- function App() {
167
- console.log('Pyloid is ready');
168
-
169
- window.pyloid.CustomAPI.getAppVersion().then((version) => {
170
- console.log('App version:', version); // "App version: 1.0.0"
171
- });
172
- return <h1>Hello World</h1>;
173
- }
174
- ```
175
-
176
77
  ## License 📄
177
78
 
178
79
  This project is licensed under the terms of the Apache License 2.0. See the [LICENSE](./LICENSE) file for details.
@@ -4,11 +4,11 @@ pyloid/autostart.py,sha256=K7DQYl4LHItvPp0bt1V9WwaaZmVSTeGvadkcwG-KKrI,3899
4
4
  pyloid/custom/titlebar.py,sha256=itzK9pJbZMQ7BKca9kdbuHMffurrw15UijR6OU03Xsk,3894
5
5
  pyloid/filewatcher.py,sha256=n8N56D65le5TpsgxXb7z-FO_0lqv4UYD4yGq_UuMrAs,1285
6
6
  pyloid/monitor.py,sha256=fqDnZ_7dpxVZLVJ5gCluDRY2USrQ5YL_fw1AnYivhsk,12741
7
- pyloid/pyloid.py,sha256=Q6M2HyV7M8-DrRwSNtQu1Rxbm_tSyVEMsb3euIQ383g,48889
7
+ pyloid/pyloid.py,sha256=Fj60bHP6x9_GPCxWSB97t21VwzdDjQmhf_RIWzc4_k0,53585
8
8
  pyloid/timer.py,sha256=1bYhqte3rV77vaeMUkcTgmx2ux7FtCqLCx9lIC2-COg,4360
9
9
  pyloid/tray.py,sha256=rXgdkvzGxtie_EIcTSA7fjuta4nJk5THhNkGFcfv5Ew,634
10
10
  pyloid/utils.py,sha256=DQerZWU_0o8dHcJ5y3yXf9i5OXn7KQZqU-hVBq3uPUA,711
11
- pyloid-0.12.2.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
12
- pyloid-0.12.2.dist-info/METADATA,sha256=oS4sC1P8_eLHtxOLy2rg3vwTx8ViyDnA2AhhGPPx_Po,6069
13
- pyloid-0.12.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
- pyloid-0.12.2.dist-info/RECORD,,
11
+ pyloid-0.13.0.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
12
+ pyloid-0.13.0.dist-info/METADATA,sha256=q61MnQEpscRzhp5cQDk33lKSBgTCLm5xJ5-nX5L2o7w,3634
13
+ pyloid-0.13.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
+ pyloid-0.13.0.dist-info/RECORD,,