fantomas 0.1.2__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.
@@ -0,0 +1,339 @@
1
+ import time, subprocess, random, os
2
+ from .virtual_cursor_path import VirtualCursorPath
3
+ from .random_sleeper import rsleep
4
+
5
+
6
+ class XdoToolActions:
7
+ def __init__(self,show_cursor):
8
+ self.show_cursor = show_cursor
9
+
10
+ @staticmethod
11
+ def xscroll_xdo_slow(x11_display, window_name, times):
12
+ env = os.environ.copy()
13
+ env["DISPLAY"] = x11_display
14
+ window_id = XdoToolBasicActions.get_window_id_x11(window_name,x11_display)
15
+ for _ in range(times):
16
+ subprocess.run(
17
+ [
18
+ "xdotool",
19
+ "windowfocus", "--sync", window_id,
20
+ "click", "--window", window_id, "5"
21
+ ],
22
+ env=env
23
+ )
24
+
25
+ @staticmethod
26
+ def xscroll_xdo(x11_display, window_name, times,delay):
27
+ env = os.environ.copy()
28
+ env["DISPLAY"] = x11_display
29
+ window_id = XdoToolBasicActions.get_window_id_x11(window_name,x11_display)
30
+ subprocess.run(
31
+ [
32
+ "xdotool",
33
+ "windowfocus", "--sync", window_id,
34
+ "click", "--repeat", str(times), "--delay", str(delay), "--window", window_id, "5"
35
+ ],
36
+ env=env
37
+ )
38
+
39
+ @staticmethod
40
+ def xscroll_xdo_up(x11_display, window_name, times,delay):
41
+ env = os.environ.copy()
42
+ env["DISPLAY"] = x11_display
43
+ window_id = XdoToolBasicActions.get_window_id_x11(window_name,x11_display)
44
+ subprocess.run(
45
+ [
46
+ "xdotool",
47
+ "windowfocus", "--sync", window_id,
48
+ "click", "--repeat", str(times), "--delay", str(delay), "--window", window_id, "4"
49
+ ],
50
+ env=env
51
+ )
52
+
53
+
54
+ def xsend_xdo(self,current_position,x,y,width,height,viewport_width,viewport_height,sleep_array,text,proportion=None):
55
+ sleep_before,sleep_after = sleep_array
56
+ self.xclick_xdo(current_position,x,y,width,height,viewport_width,viewport_height,sleep_array,proportion)
57
+ rsleep(sleep_before)
58
+ XdoToolActions.xfill_xdo(text)
59
+ rsleep(sleep_after)
60
+ return [x,y]
61
+
62
+ def xsend_xdo_x11(self,x11_display,window_name,current_position,x,y,width,height,viewport_width,viewport_height,sleep_array,text,proportion=None):
63
+ sleep_before,sleep_after = sleep_array
64
+ self.xclick_xdo_x11(x11_display,window_name,current_position,x,y,width,height,viewport_width,viewport_height,sleep_array,proportion)
65
+ rsleep(sleep_before)
66
+ XdoToolActions.xfill_xdo_x11(text,x11_display,window_name)
67
+ rsleep(sleep_after)
68
+ return [x,y]
69
+
70
+ def xclick_xdo(self, current_position,x,y, width,height,viewport_width,viewport_height,sleep_array,proportion=None):
71
+ new_cursor_position = None
72
+ sleep_before, sleep_after = sleep_array
73
+ self.emulate_movement = True #
74
+ if self.emulate_movement:
75
+ if proportion:
76
+ x = x + proportion[0]*width
77
+ y = y + proportion[1]*height
78
+ new_cursor_position = XdoToolActions(self.show_cursor).xmove_xdo(current_position, x,y,viewport_width,viewport_height)
79
+ rsleep(sleep_before)
80
+ XdoToolBasicActions().xdo_click()
81
+ rsleep(sleep_after)
82
+ return new_cursor_position
83
+
84
+ def xclick_xdo_x11(self,x11_display,window_name,current_position,x,y, width,height,viewport_width,viewport_height,sleep_array,proportion=None):
85
+ window_id = XdoToolBasicActions().get_window_id_x11(window_name,x11_display)
86
+ new_cursor_position = None
87
+ sleep_before, sleep_after = sleep_array
88
+ self.emulate_movement = True #
89
+ if self.emulate_movement:
90
+ if proportion:
91
+ x = x + proportion[0]*width
92
+ y = y + proportion[1]*height
93
+ new_cursor_position = XdoToolActions(self.show_cursor).xmove_xdo_x11(x11_display,window_name,current_position, x,y,viewport_width,viewport_height)
94
+ rsleep(sleep_before)
95
+ XdoToolBasicActions().xdo_click_x11(window_id,x11_display)
96
+ rsleep(sleep_after)
97
+ return new_cursor_position
98
+
99
+
100
+ def xsingle_send_xdo(self,key):
101
+ XdoToolBasicActions().xdo_send_key(key)
102
+
103
+ @staticmethod
104
+ def xfill_xdo(text):
105
+ interval_min = random.uniform(0.01, 0.09)
106
+ interval_max = random.uniform(0.1, 0.7)
107
+ for i in text:
108
+ sleeping_delay = random.uniform(interval_min, interval_max)
109
+ rsleep(sleeping_delay, activate_random=False)
110
+ time.sleep(0.01)
111
+ XdoToolBasicActions.xdo_send_key(i)
112
+ time.sleep(0.02)
113
+
114
+ @staticmethod
115
+ def xfill_xdo_x11(text,x11_display,window_name):
116
+ window_id = XdoToolBasicActions.get_window_id_x11(window_name,x11_display)
117
+ interval_min = random.uniform(0.01, 0.09)
118
+ interval_max = random.uniform(0.1, 0.7)
119
+ for i in text:
120
+ sleeping_delay = random.uniform(interval_min, interval_max)
121
+ rsleep(sleeping_delay, activate_random=False)
122
+ time.sleep(0.01)
123
+ XdoToolBasicActions.xdo_send_key_x11(x11_display,window_id,i)
124
+ time.sleep(0.02)
125
+
126
+ def xmove_xdo(self,current_position,x,y,viewport_width,viewport_height):
127
+ desired_position = [x,y]
128
+ path = VirtualCursorPath().get_virtual_cursor_path(current_position,desired_position,viewport_width,viewport_height)
129
+
130
+ if self.show_cursor:
131
+ cursor_illustration = XdoToolCursorIllustration()
132
+ cursor_illustration.initialize_cursor_illustration()
133
+
134
+ for i in range(len(path[0])):
135
+ XdoToolBasicActions().xdo_move(path,i)
136
+ time.sleep(0.01)
137
+
138
+ if self.show_cursor:
139
+ cursor_illustration.move_cursor_illustration(path,i)
140
+
141
+ if self.show_cursor:
142
+ cursor_illustration.kill_cursor_illustration()
143
+ return desired_position
144
+
145
+ def xmove_xdo_x11(self,x11_display,window_name,current_position,x,y,viewport_width,viewport_height):
146
+ desired_position = [x,y]
147
+ path = VirtualCursorPath().get_virtual_cursor_path(current_position,desired_position,viewport_width,viewport_height)
148
+ window_browser_id = XdoToolBasicActions().get_window_id_x11(window_name,x11_display)
149
+
150
+ if self.show_cursor:
151
+ cursor_illustration = XdoToolCursorIllustration()
152
+ cursor_illustration.initialize_cursor_illustration()
153
+
154
+ for i in range(len(path[0])):
155
+ XdoToolBasicActions().xdo_move_x11(x11_display,window_browser_id,path,i)
156
+ time.sleep(0.01)
157
+
158
+ if self.show_cursor:
159
+ cursor_illustration.move_cursor_illustration(path,i)
160
+
161
+ if self.show_cursor:
162
+ cursor_illustration.kill_cursor_illustration()
163
+ return desired_position
164
+
165
+
166
+ class XdoToolBasicActions:
167
+ def __init__(self):
168
+ pass
169
+
170
+ @staticmethod
171
+ def get_window_id(window_name):
172
+ output = os.popen(f"xdotool search --name '{window_name}'").read()
173
+ window_ids = output.strip().split("\n")
174
+ if window_ids:
175
+ return window_ids[0]
176
+ else:
177
+ print(f"XDOTOOL - Aucune fenêtre trouvée avec {window_name}")
178
+ return
179
+
180
+ @staticmethod
181
+ def get_window_id_x11(window_name, x11_display):
182
+ env = os.environ.copy()
183
+ env["DISPLAY"] = x11_display
184
+
185
+ try:
186
+ output = subprocess.check_output(
187
+ ["xdotool", "search", "--name", window_name],
188
+ env=env,
189
+ text=True
190
+ )
191
+ window_ids = output.strip().split("\n")
192
+ if window_ids:
193
+ return window_ids[0]
194
+ else:
195
+ print(f"XDOTOOL - Aucune fenêtre trouvée avec {window_name}")
196
+ return None
197
+ except subprocess.CalledProcessError:
198
+ print(f"XDOTOOL - Erreur lors de la recherche de la fenêtre {window_name}")
199
+ return None
200
+
201
+ @staticmethod
202
+ def xdo_send_key(key):
203
+ replacement = {
204
+ ".": "period",
205
+ ",": "comma",
206
+ "-": "minus",
207
+ "_": "underscore",
208
+ "+": "plus",
209
+ "=": "equal",
210
+ "/": "slash",
211
+ "\\": "backslash",
212
+ ":": "colon",
213
+ ";": "semicolon",
214
+ "'": "apostrophe",
215
+ "\"": "quotedbl",
216
+ "(": "parenleft",
217
+ ")": "parenright",
218
+ "[": "bracketleft",
219
+ "]": "bracketright",
220
+ "{": "braceleft",
221
+ "}": "braceright",
222
+ "!": "exclam",
223
+ "@": "at",
224
+ "#": "numbersign",
225
+ "$": "dollar",
226
+ "%": "percent",
227
+ "^": "asciicircum",
228
+ "&": "ampersand",
229
+ "*": "asterisk",
230
+ "~": "asciitilde",
231
+ "|": "bar",
232
+ "<": "less",
233
+ ">": "greater",
234
+ "?": "question",
235
+ "§": "section",
236
+ "€": "EuroSign",
237
+ " ": "space"
238
+ }
239
+ key = replacement.get(key,key)
240
+ writing_process = subprocess.Popen(["xdotool","key",str(key)]) #modif here
241
+
242
+ @staticmethod
243
+ def xdo_send_key_x11(x11_display,window_id,key):
244
+ replacement = {
245
+ ".": "period",
246
+ ",": "comma",
247
+ "-": "minus",
248
+ "_": "underscore",
249
+ "+": "plus",
250
+ "=": "equal",
251
+ "/": "slash",
252
+ "\\": "backslash",
253
+ ":": "colon",
254
+ ";": "semicolon",
255
+ "'": "apostrophe",
256
+ "\"": "quotedbl",
257
+ "(": "parenleft",
258
+ ")": "parenright",
259
+ "[": "bracketleft",
260
+ "]": "bracketright",
261
+ "{": "braceleft",
262
+ "}": "braceright",
263
+ "!": "exclam",
264
+ "@": "at",
265
+ "#": "numbersign",
266
+ "$": "dollar",
267
+ "%": "percent",
268
+ "^": "asciicircum",
269
+ "&": "ampersand",
270
+ "*": "asterisk",
271
+ "~": "asciitilde",
272
+ "|": "bar",
273
+ "<": "less",
274
+ ">": "greater",
275
+ "?": "question",
276
+ "§": "section",
277
+ "€": "EuroSign",
278
+ " ": "space"
279
+ }
280
+ key = replacement.get(key,key)
281
+ env = os.environ.copy()
282
+ env["DISPLAY"] = x11_display
283
+ writing_process = subprocess.Popen(["xdotool","key","--window", str(window_id),str(key)], env=env)
284
+
285
+ @staticmethod
286
+ def xdo_click():
287
+ clicking_process = subprocess.Popen(["xdotool", "click", "1"])
288
+
289
+ @staticmethod
290
+ def xdo_click_x11(window_id, x11_display):
291
+ env = os.environ.copy()
292
+ env["DISPLAY"] = x11_display
293
+ raising_process = subprocess.Popen(["xdotool", "windowraise", str(window_id)],env=env)
294
+ focusing_process = subprocess.Popen(["xdotool", "windowfocus", str(window_id)],env=env)
295
+ clicking_process = subprocess.Popen(["xdotool", "click", "1"],env=env)
296
+
297
+ @staticmethod
298
+ def xdo_move(path,step):
299
+ subprocess.Popen(["xdotool", "mousemove", str(path[0][step]),str(path[1][step])])
300
+
301
+ @staticmethod
302
+ def xdo_move_x11(x11_display,window_id,path,step):
303
+ env = os.environ.copy()
304
+ env["DISPLAY"] = x11_display
305
+ subprocess.Popen(["xdotool", "mousemove", "--window", str(window_id), str(path[0][step]),str(path[1][step])], env=env)
306
+
307
+ from PIL import Image
308
+ def create_red_square(nom_fichier="carre_rouge_20.png"):
309
+ # Create a new 20×20 pixel image, in RGB mode, filled with red.
310
+ image = Image.new("RGB", (20, 20), (255, 0, 0))
311
+ # Save the image in the current directory.
312
+ image.save(nom_fichier)
313
+
314
+ class XdoToolCursorIllustration:
315
+ def __init__(self):
316
+ self.window_cursor_id = None
317
+
318
+ def initialize_cursor_illustration(self):
319
+ create_red_square()
320
+ os.system("feh carre_rouge_20.png &")
321
+ time.sleep(0.2)
322
+ self.window_cursor_id = subprocess.check_output(["xdotool", "search", "--name", "carre_rouge_20"], text=True).strip()
323
+ time.sleep(0.2)
324
+ raising_process = subprocess.Popen(["xdotool", "windowraise", str(self.window_cursor_id)])
325
+
326
+ def move_cursor_illustration(self,path,move_number):
327
+ subprocess.run(["xdotool", "windowmove", self.window_cursor_id,str(path[0][move_number]),str(path[1][move_number])])
328
+
329
+ @staticmethod
330
+ def kill_cursor_illustration():
331
+ os.system("pkill feh")
332
+ os.remove("carre_rouge_20.png")
333
+
334
+
335
+ if __name__ == "__main__":
336
+ XdoToolActions(show_cursor=True).xclick_xdo("GitHub",[0,0],280,360,10,10,1000,1000,[0,0],[0,0])
337
+ XdoToolActions(show_cursor=True).xfill_xdo("Hello World")
338
+ XdoToolActions(show_cursor=True).xsingle_send_xdo("GitHub","F11")
339
+
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: fantomas
3
+ Version: 0.1.2
4
+ Summary: Augmented OS-Level Web Automation based on nodriver
5
+ Author-email: Marc Arnal <hello@marcarnal.com>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
@@ -0,0 +1,19 @@
1
+ fantomas/__init__.py,sha256=ucz8plorGtllIreHHT3ojU59no2awBn20GdgE2PhHeQ,331
2
+ fantomas/fantomas_no_driver.py,sha256=Ve4MAETYT0XHOrfX163heVrslpfrkYQc6ihr5N57AUY,22661
3
+ fantomas/identity.py,sha256=vYB7mYON0lvuoCXZnQ1BuqkgzLrkSkS_yC-Nk4TLFI8,3746
4
+ fantomas/proxy.py,sha256=nUOTkFa9z8LHjxzTIMbZ-9z9zS3EAcTkjcznbrB9dnk,7427
5
+ fantomas/random_sleeper.py,sha256=GIjoCgO9saVJuCkFY065teFzD6Iwfa17IgVYVfNVMSo,120
6
+ fantomas/raw_chrome.py,sha256=bUDrY9cDA0G6AqmgKE4lpxzPG6dgjAm_HK4rIz0oACI,1090
7
+ fantomas/raw_screen.py,sha256=BuR5JAnYExPLyk-CFVNr_f3vLvIgBtwlGHjaNvYgv98,1600
8
+ fantomas/screen.py,sha256=E55zOUguEmh_1nFup5egqiq-xEL0pl1be0NjqUOiLyw,1420
9
+ fantomas/secondary_flow.py,sha256=zOVy8iW1CeS2ZHXUaXRKL4tRwPbWuQHiUa7M2P2hjLw,1006
10
+ fantomas/utils.py,sha256=GTTS8E348Y8J-dAT1vA52VN3qq4ur6WHFzRf7D5GqfQ,554
11
+ fantomas/virtual_cursor_path.py,sha256=50ChlgH4Mlw2UNncMSBimNeW424ovTbNvrbuy7avbI8,2905
12
+ fantomas/xdotool_actions.py,sha256=70yh3VNcUZDUqRnroAbBfUHj62TERVPHlB47KNYEhDg,11967
13
+ fantomas/no_driver/CursorIllustration.py,sha256=DKqSqzYV6BkIgjfZVzZnYwXooXS4THTKmVCsymeyiJ4,2442
14
+ fantomas/no_driver/Geometry.py,sha256=p6mdv-wjxw2PzOjEzuSF7scyrTJi_aFdscLsUD-TV-o,1879
15
+ fantomas/no_driver/IframeManager.py,sha256=DM_TpxOiSxp34VbWYQdq2naMpozT84YOoyZAqIGoWMc,601
16
+ fantomas-0.1.2.dist-info/METADATA,sha256=_57sSPFuMAul2k-klKZHiZaxq_4LmO7DpxUPCq9Xbsw,247
17
+ fantomas-0.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
18
+ fantomas-0.1.2.dist-info/top_level.txt,sha256=4B1RRr4oV18m90JDa-djIkQKeNxHd1bMqDI73IYMDy4,9
19
+ fantomas-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ fantomas