-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore
95 lines (66 loc) · 2.46 KB
/
store
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# # удаление выделенного элемента
# def delete():
# global newWindow2
# # selection = languages_listbox.curselection()
# # # мы можем получить удаляемый элемент по индексу
# # # selected_language = languages_listbox.get(selection[0])
# # languages_listbox.delete(selection[0])
# newWindow2 = create_window()
def check_node(nod, kb):
for klemnaya_kolodka in kb:
if nod in klemnaya_kolodka:
return True
return False
def is_exist(n1, n2, links):
for link in links:
if (link[0] == n1 and link[1] == n2) or (link[1] == n1 and link[0] == n2):
return True
return False
def add_link(links, kb, n1, n2, info="", signal=""):
if check_node(n1, kb) and check_node(n2, kb):
if not is_exist(n1, n2, links):
links.append([n1, n2, signal, info])
return "link add success"
else:
return "link already exist"
return f"n1 in kb {check_node(n1, kb)} n2 in kb {check_node(n2, kb)}"
def rem_link(n1, n2, links):
link_to_rem = next((
link for link in links if (link[0] == n1 and link[1] == n2) or (
link[1] == n1 and link[0] == n2)), [None])
if link_to_rem is not None:
links.remove(link_to_rem)
return "remove success"
return "no such link"
def save_json(lst):
with open('data.json', 'w') as file:
json.dump(lst, file)
def load_json():
with open('data.json', 'r') as file:
return json.load(file)
def print_links(links):
for node in links:
print(node)
def get_row(list_name, row_index):
return [row[row_index] for row in list_name]
def get_signals(links):
lsl = get_row(links, 2)
lsl.sort()
lsl2 = [el for el, _ in groupby(lsl)]
return lsl2
def get_nodes_by_signal(links, signal_name):
if signal_name == "all signals":
return links
matches = [x for x in links if x[2] == signal_name]
return matches
def delete_signal(signal, blinks):
links_to_rem = []
for link in blinks:
if link[2] == signal:
links_to_rem.append(link)
for link in links_to_rem:
print(rem_link(link[0], link[1], blinks))
# label_example = ttk.Button(new_window, text="New Window", )
# label_example.pack(side="top", fill="both")
# label_example2 = ttk.Button(new_window, text="New Window", )
# label_example2.pack(side="top", fill="both")