-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_processor.py
More file actions
77 lines (65 loc) · 2.37 KB
/
script_processor.py
File metadata and controls
77 lines (65 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from PyQt6.QtCore import QTimer
class ScriptProcessor:
def __init__(self, add_new_tab, navigate_to_custom_url):
"""
Klasa do przetwarzania skryptów.
add_new_tab: Funkcja do otwierania nowej karty.
navigate_to_custom_url: Funkcja do nawigacji na konkretny URL.
"""
self.script_data = None
self.current_line = 0
self.add_new_tab = add_new_tab
self.navigate_to_custom_url = navigate_to_custom_url
def set_script_data(self, script_data):
"""
Ustaw dane skryptu do wykonania.
"""
self.script_data = script_data
self.current_line = 0
def process_next_command(self):
"""
Kontynuuj wykonywanie następnej komendy po czasie oczekiwania.
"""
if self.script_data is None:
print("Brak skryptu do wykonania!")
return
script = self.script_data["script"]
lines = script.splitlines()
if self.current_line >= len(lines):
print("Skrypt zakończony!")
return
line = lines[self.current_line].strip()
if not line:
self.current_line += 1
self.process_next_command()
return
if line.startswith("create_tab"):
url = self.extract_argument(line)
if url:
self.add_new_tab(url)
elif line.startswith("navigate_to"):
url = self.extract_argument(line)
if url:
self.navigate_to_custom_url(url)
elif line.startswith("wait"):
time_count = self.extract_argument(line)
if time_count:
time_count = int(time_count)
QTimer.singleShot(time_count * 1000, self.process_next_command)
self.current_line += 1
return
self.current_line += 1
self.process_next_command()
def extract_argument(self, line):
start = line.find("(")
end = line.rfind(")")
if start != -1 and end != -1:
return line[start + 1:end].strip().strip('"')
return None
def extract_arguments(self, line):
start = line.find('(')
end = line.find(')')
if start != -1 and end != -1:
arguments = line[start + 1:end].split(',')
return [arg.strip().strip('"').strip("'") for arg in arguments]
return []