pyloid 0.13.0__py3-none-any.whl → 0.14.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pyloid/api.py +85 -2
- pyloid/browser_window.py +1190 -0
- pyloid/filewatcher.py +137 -9
- pyloid/js_api/event_api.py +25 -0
- pyloid/js_api/window_api.py +166 -0
- pyloid/monitor.py +602 -77
- pyloid/pyloid.py +661 -892
- pyloid/timer.py +222 -38
- pyloid/tray.py +30 -0
- pyloid/utils.py +55 -6
- {pyloid-0.13.0.dist-info → pyloid-0.14.0.dist-info}/METADATA +1 -1
- pyloid-0.14.0.dist-info/RECORD +17 -0
- pyloid-0.13.0.dist-info/RECORD +0 -14
- {pyloid-0.13.0.dist-info → pyloid-0.14.0.dist-info}/LICENSE +0 -0
- {pyloid-0.13.0.dist-info → pyloid-0.14.0.dist-info}/WHEEL +0 -0
pyloid/filewatcher.py
CHANGED
@@ -1,35 +1,163 @@
|
|
1
1
|
from PySide6.QtCore import QFileSystemWatcher, QObject, Signal
|
2
2
|
|
3
3
|
class FileWatcher(QObject):
|
4
|
+
"""
|
5
|
+
FileWatcher class for monitoring file and directory changes.
|
6
|
+
|
7
|
+
This class automatically detects changes in specific files or directories and provides notifications.
|
8
|
+
|
9
|
+
Attributes
|
10
|
+
----------
|
11
|
+
file_changed : Signal
|
12
|
+
Signal emitted when a file is changed.
|
13
|
+
directory_changed : Signal
|
14
|
+
Signal emitted when a directory is changed.
|
15
|
+
|
16
|
+
Methods
|
17
|
+
-------
|
18
|
+
add_path(path)
|
19
|
+
Adds a file or directory to the watch list.
|
20
|
+
remove_path(path)
|
21
|
+
Removes a file or directory from the watch list.
|
22
|
+
get_watched_paths()
|
23
|
+
Returns all currently watched paths (files and directories).
|
24
|
+
get_watched_files()
|
25
|
+
Returns all currently watched files.
|
26
|
+
get_watched_directories()
|
27
|
+
Returns all currently watched directories.
|
28
|
+
remove_all_paths()
|
29
|
+
Removes all paths from the watch list.
|
30
|
+
"""
|
31
|
+
|
4
32
|
file_changed = Signal(str)
|
5
33
|
directory_changed = Signal(str)
|
6
34
|
|
7
35
|
def __init__(self):
|
36
|
+
"""
|
37
|
+
Initializes the FileWatcher object.
|
38
|
+
"""
|
8
39
|
super().__init__()
|
9
40
|
self.watcher = QFileSystemWatcher()
|
10
41
|
self.watcher.fileChanged.connect(self.file_changed)
|
11
42
|
self.watcher.directoryChanged.connect(self.directory_changed)
|
12
43
|
|
13
44
|
def add_path(self, path):
|
14
|
-
"""
|
45
|
+
"""
|
46
|
+
Adds a file or directory to the watch list.
|
47
|
+
|
48
|
+
Parameters
|
49
|
+
----------
|
50
|
+
path : str
|
51
|
+
The path of the file or directory to watch.
|
52
|
+
|
53
|
+
Returns
|
54
|
+
-------
|
55
|
+
bool
|
56
|
+
Whether the path was successfully added.
|
57
|
+
|
58
|
+
Examples
|
59
|
+
--------
|
60
|
+
>>> watcher = FileWatcher()
|
61
|
+
>>> result = watcher.add_path("/path/to/file_or_directory")
|
62
|
+
>>> if result:
|
63
|
+
>>> print("Watch started")
|
64
|
+
>>> else:
|
65
|
+
>>> print("Failed to start watching")
|
66
|
+
"""
|
15
67
|
return self.watcher.addPath(path)
|
16
68
|
|
17
69
|
def remove_path(self, path):
|
18
|
-
"""
|
70
|
+
"""
|
71
|
+
Removes a file or directory from the watch list.
|
72
|
+
|
73
|
+
Parameters
|
74
|
+
----------
|
75
|
+
path : str
|
76
|
+
The path of the file or directory to remove.
|
77
|
+
|
78
|
+
Returns
|
79
|
+
-------
|
80
|
+
bool
|
81
|
+
Whether the path was successfully removed.
|
82
|
+
|
83
|
+
Examples
|
84
|
+
--------
|
85
|
+
>>> watcher = FileWatcher()
|
86
|
+
>>> result = watcher.remove_path("/path/to/file_or_directory")
|
87
|
+
>>> if result:
|
88
|
+
>>> print("Successfully stopped watching")
|
89
|
+
>>> else:
|
90
|
+
>>> print("Failed to stop watching")
|
91
|
+
"""
|
19
92
|
return self.watcher.removePath(path)
|
20
93
|
|
21
94
|
def get_watched_paths(self):
|
22
|
-
"""
|
95
|
+
"""
|
96
|
+
Returns all currently watched paths (files and directories).
|
97
|
+
|
98
|
+
Returns
|
99
|
+
-------
|
100
|
+
list of str
|
101
|
+
All currently watched paths.
|
102
|
+
|
103
|
+
Examples
|
104
|
+
--------
|
105
|
+
>>> watcher = FileWatcher()
|
106
|
+
>>> paths = watcher.get_watched_paths()
|
107
|
+
>>> print("Watched paths:", paths)
|
108
|
+
"""
|
23
109
|
return self.watcher.files() + self.watcher.directories()
|
24
|
-
|
110
|
+
|
25
111
|
def get_watched_files(self):
|
26
|
-
"""
|
112
|
+
"""
|
113
|
+
Returns all currently watched files.
|
114
|
+
|
115
|
+
Returns
|
116
|
+
-------
|
117
|
+
list of str
|
118
|
+
All currently watched files.
|
119
|
+
|
120
|
+
Examples
|
121
|
+
--------
|
122
|
+
>>> watcher = FileWatcher()
|
123
|
+
>>> files = watcher.get_watched_files()
|
124
|
+
>>> print("Watched files:", files)
|
125
|
+
"""
|
27
126
|
return self.watcher.files()
|
28
|
-
|
127
|
+
|
29
128
|
def get_watched_directories(self):
|
30
|
-
"""
|
129
|
+
"""
|
130
|
+
Returns all currently watched directories.
|
131
|
+
|
132
|
+
Returns
|
133
|
+
-------
|
134
|
+
list of str
|
135
|
+
All currently watched directories.
|
136
|
+
|
137
|
+
Examples
|
138
|
+
--------
|
139
|
+
>>> watcher = FileWatcher()
|
140
|
+
>>> directories = watcher.get_watched_directories()
|
141
|
+
>>> print("Watched directories:", directories)
|
142
|
+
"""
|
31
143
|
return self.watcher.directories()
|
32
|
-
|
144
|
+
|
33
145
|
def remove_all_paths(self):
|
34
|
-
"""
|
146
|
+
"""
|
147
|
+
Removes all paths from the watch list.
|
148
|
+
|
149
|
+
Returns
|
150
|
+
-------
|
151
|
+
bool
|
152
|
+
Whether all paths were successfully removed.
|
153
|
+
|
154
|
+
Examples
|
155
|
+
--------
|
156
|
+
>>> watcher = FileWatcher()
|
157
|
+
>>> result = watcher.remove_all_paths()
|
158
|
+
>>> if result:
|
159
|
+
>>> print("Successfully removed all paths")
|
160
|
+
>>> else:
|
161
|
+
>>> print("Failed to remove all paths")
|
162
|
+
"""
|
35
163
|
return self.watcher.removePaths(self.get_watched_paths())
|
@@ -0,0 +1,25 @@
|
|
1
|
+
from ..pyloid import Pyloid
|
2
|
+
from ..api import PyloidAPI, Bridge
|
3
|
+
from typing import Optional, Callable
|
4
|
+
|
5
|
+
|
6
|
+
# class EventAPI(PyloidAPI):
|
7
|
+
# def __init__(self, window_id: str, app):
|
8
|
+
# super().__init__()
|
9
|
+
# self.window_id: str = window_id
|
10
|
+
# self.app: PylonApp = app
|
11
|
+
# self.subscribers = {}
|
12
|
+
|
13
|
+
# @Bridge(str, Callable)
|
14
|
+
# def on(self, event_name: str, callback: Callable):
|
15
|
+
# """특정 이벤트를 구독합니다."""
|
16
|
+
# if event_name not in self.subscribers:
|
17
|
+
# self.subscribers[event_name] = []
|
18
|
+
# self.subscribers[event_name].append(callback)
|
19
|
+
|
20
|
+
# @Bridge(str, result=Optional[str])
|
21
|
+
# def emit(self, event_name: str, *args, **kwargs):
|
22
|
+
# """다른 윈도우로 특정 이벤트를 보냅니다."""
|
23
|
+
# if event_name in self.subscribers:
|
24
|
+
# for callback in self.subscribers[event_name]:
|
25
|
+
# callback(*args, **kwargs)
|
@@ -0,0 +1,166 @@
|
|
1
|
+
from ..api import PyloidAPI, Bridge
|
2
|
+
from typing import Optional
|
3
|
+
|
4
|
+
class WindowAPI(PyloidAPI):
|
5
|
+
def __init__(self, window_id: str, app):
|
6
|
+
super().__init__()
|
7
|
+
self.window_id: str = window_id
|
8
|
+
self.app = app
|
9
|
+
|
10
|
+
@Bridge(result=str)
|
11
|
+
def getWindowId(self):
|
12
|
+
"""Returns the current window ID."""
|
13
|
+
return self.window_id
|
14
|
+
|
15
|
+
@Bridge(result=dict)
|
16
|
+
def getWindowProperties(self):
|
17
|
+
"""Returns the properties of the window."""
|
18
|
+
window = self.app.get_window_by_id(self.window_id)
|
19
|
+
window_properties = window.get_window_properties()
|
20
|
+
return window_properties
|
21
|
+
|
22
|
+
@Bridge()
|
23
|
+
def close(self):
|
24
|
+
"""Closes the window."""
|
25
|
+
window = self.app.get_window_by_id(self.window_id)
|
26
|
+
if window:
|
27
|
+
window.close()
|
28
|
+
|
29
|
+
@Bridge()
|
30
|
+
def hide(self):
|
31
|
+
"""Hides the window."""
|
32
|
+
window = self.app.get_window_by_id(self.window_id)
|
33
|
+
if window:
|
34
|
+
window.hide()
|
35
|
+
|
36
|
+
@Bridge()
|
37
|
+
def show(self):
|
38
|
+
"""Shows and focuses the window."""
|
39
|
+
window = self.app.get_window_by_id(self.window_id)
|
40
|
+
if window:
|
41
|
+
window.show()
|
42
|
+
|
43
|
+
@Bridge()
|
44
|
+
def toggleFullscreen(self):
|
45
|
+
"""Toggles fullscreen mode for the window."""
|
46
|
+
window = self.app.get_window_by_id(self.window_id)
|
47
|
+
if window:
|
48
|
+
window.toggle_fullscreen()
|
49
|
+
|
50
|
+
@Bridge()
|
51
|
+
def minimize(self):
|
52
|
+
"""Minimizes the window."""
|
53
|
+
window = self.app.get_window_by_id(self.window_id)
|
54
|
+
if window:
|
55
|
+
window.minimize()
|
56
|
+
|
57
|
+
@Bridge()
|
58
|
+
def maximize(self):
|
59
|
+
"""Maximizes the window."""
|
60
|
+
window = self.app.get_window_by_id(self.window_id)
|
61
|
+
if window:
|
62
|
+
window.maximize()
|
63
|
+
|
64
|
+
@Bridge()
|
65
|
+
def unmaximize(self):
|
66
|
+
"""Restores the window to its normal state."""
|
67
|
+
window = self.app.get_window_by_id(self.window_id)
|
68
|
+
if window:
|
69
|
+
window.unmaximize()
|
70
|
+
|
71
|
+
@Bridge(str)
|
72
|
+
def setTitle(self, title: str):
|
73
|
+
"""Sets the title of the window."""
|
74
|
+
window = self.app.get_window_by_id(self.window_id)
|
75
|
+
if window:
|
76
|
+
window.set_title(title)
|
77
|
+
|
78
|
+
@Bridge(int, int)
|
79
|
+
def setSize(self, width: int, height: int):
|
80
|
+
"""Sets the size of the window."""
|
81
|
+
window = self.app.get_window_by_id(self.window_id)
|
82
|
+
if window:
|
83
|
+
window.set_size(width, height)
|
84
|
+
|
85
|
+
@Bridge(int, int)
|
86
|
+
def setPosition(self, x: int, y: int):
|
87
|
+
"""Sets the position of the window."""
|
88
|
+
window = self.app.get_window_by_id(self.window_id)
|
89
|
+
if window:
|
90
|
+
window.set_position(x, y)
|
91
|
+
|
92
|
+
@Bridge(bool)
|
93
|
+
def setFrame(self, frame: bool):
|
94
|
+
"""Sets the frame of the window."""
|
95
|
+
window = self.app.get_window_by_id(self.window_id)
|
96
|
+
if window:
|
97
|
+
window.set_frame(frame)
|
98
|
+
|
99
|
+
@Bridge(bool)
|
100
|
+
def setContextMenu(self, context_menu: bool):
|
101
|
+
"""Sets the context menu of the window."""
|
102
|
+
window = self.app.get_window_by_id(self.window_id)
|
103
|
+
if window:
|
104
|
+
window.set_context_menu(context_menu)
|
105
|
+
|
106
|
+
@Bridge(bool)
|
107
|
+
def setDevTools(self, enable: bool):
|
108
|
+
"""Sets the developer tools of the window."""
|
109
|
+
window = self.app.get_window_by_id(self.window_id)
|
110
|
+
if window:
|
111
|
+
window.set_dev_tools(enable)
|
112
|
+
|
113
|
+
@Bridge(str, result=Optional[str])
|
114
|
+
def capture(self, save_path: str) -> Optional[str]:
|
115
|
+
"""Captures the current window."""
|
116
|
+
window = self.app.get_window_by_id(self.window_id)
|
117
|
+
if window:
|
118
|
+
return window.capture(save_path)
|
119
|
+
return None
|
120
|
+
|
121
|
+
@Bridge(result=bool)
|
122
|
+
def getFrame(self):
|
123
|
+
"""Returns whether the window has a frame."""
|
124
|
+
window = self.app.get_window_by_id(self.window_id)
|
125
|
+
return window.frame if window else False
|
126
|
+
|
127
|
+
@Bridge(result=bool)
|
128
|
+
def getContextMenu(self):
|
129
|
+
"""Returns whether the window has a context menu."""
|
130
|
+
window = self.app.get_window_by_id(self.window_id)
|
131
|
+
return window.context_menu if window else False
|
132
|
+
|
133
|
+
@Bridge(result=bool)
|
134
|
+
def getDevTools(self):
|
135
|
+
"""Returns whether the window has developer tools."""
|
136
|
+
window = self.app.get_window_by_id(self.window_id)
|
137
|
+
return window.dev_tools if window else False
|
138
|
+
|
139
|
+
@Bridge(result=str)
|
140
|
+
def getTitle(self):
|
141
|
+
"""Returns the title of the window."""
|
142
|
+
window = self.app.get_window_by_id(self.window_id)
|
143
|
+
return window.title if window else ""
|
144
|
+
|
145
|
+
@Bridge(result=dict)
|
146
|
+
def getSize(self):
|
147
|
+
"""Returns the size of the window."""
|
148
|
+
window = self.app.get_window_by_id(self.window_id)
|
149
|
+
return (
|
150
|
+
{"width": window.width, "height": window.height}
|
151
|
+
if window
|
152
|
+
else {"width": 0, "height": 0}
|
153
|
+
)
|
154
|
+
|
155
|
+
@Bridge(result=dict)
|
156
|
+
def getPosition(self):
|
157
|
+
"""Returns the position of the window."""
|
158
|
+
window = self.app.get_window_by_id(self.window_id)
|
159
|
+
return {"x": window.x, "y": window.y} if window else {"x": 0, "y": 0}
|
160
|
+
|
161
|
+
@Bridge()
|
162
|
+
def startSystemDrag(self):
|
163
|
+
"""Starts the system drag."""
|
164
|
+
window = self.app.get_window_by_id(self.window_id)
|
165
|
+
if window:
|
166
|
+
window.web_view.start_system_drag()
|