-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_functions.py
84 lines (67 loc) · 2.48 KB
/
ui_functions.py
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
from graph_class import Vertex, Edge
def check_pos(canvas, elements, CURRENT):
"""
Checks elements on CURRENT position
Returns ID of element on CURRENT position or None
Parameters:
canvas - tkinter.Canvas object
elements - dictionary of elements on canvas
CURRENT - tkinter.CURRENT
"""
return_value = None
if CURRENT is not None:
index = canvas.find_withtag(CURRENT)
if len(index) > 0:
if index[0] in elements.keys():
return_value = index[0]
return return_value
def check_pos_set_focus(canvas, elements, graph, CURRENT):
"""
Create / delete focus of CURRENT element from elements
Returns None if CURRENT is None or if there is not any element on CURRENT position,
False if component got unfocused and index of element from dictionary if it got focus.
Parameters:
canvas - tkinter.Canvas object
elements - dictionary of elements on Canvas in form index : element object
graph - Graph object
CURRENT - tkinter.CURRENT (ID of element of canvas under the mouse)
"""
element_index = check_pos(canvas, elements, CURRENT)
return_value = None
if element_index is not None:
element = elements[element_index]
if type(element) == Vertex or type(element) == Edge:
return_value = graph.set_focus(element)
if return_value is True:
return_value = element_index
return return_value
def move_focused(x, y, element_index, elements):
"""
Changes vertex coordinates
Parameters:
x - new horizontal position of vertex on canvas
y - new vertical position of vertex on canvas
element_index - ID of element (vertex) on canvas
elements - dictionary of elements on canvas
"""
if element_index is None or element_index not in elements.keys():
return None
element = elements[element_index]
if type(element) != Vertex:
return None
element.x = x
element.y = y
def remove_object(object_index, elements, graph, canvas):
"""
Removes component from Graph object and from canvas
Returns modified Graph object
Parameters:
object_index - ID of element on canvas to be removed
element - dictionary of all elements on canvas
graph - instance of Graph class
canvas - tkinter.Canvas object
"""
if object_index:
canvas.delete(object_index)
graph = graph - elements[object_index]
return graph