-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddEdge.py
59 lines (48 loc) · 1.8 KB
/
AddEdge.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
import pygame, sys, random
import pygame.locals as pl
import pygame.event as pe
import AddNode
from DFS import *
from Edge import Edge
from Graph import *
import Handle_Button
# add_edge func for drawing the edges on the screen
def add_edge(window, buttons, colors, graph, nodes, edges, i):
start_node = None
edge = None
while True:
window.fill(colors['paper'])
pygame.draw.line(window, colors['emerald'], (20, 70), (780, 70))
pos = pygame.mouse.get_pos()
edge = Edge(window, colors['blacksteel'])
Handle_Button.draw_btns(buttons, colors['emerald'])
# event handling
for event in pe.get():
if event.type == pl.QUIT:
pygame.quit()
sys.exit()
if event.type == pl.KEYDOWN:
if event.key == pl.K_ESCAPE:
pygame.quit()
sys.exit()
if event.type == pl.MOUSEBUTTONDOWN:
for node in nodes:
if node.isOver(pos):
if start_node != None:
edge.start_node = start_node
edge.end_node = node
edges.append(edge)
start_node = None
else:
start_node = node
Handle_Button.button_handler(window, buttons, colors, graph, nodes, edges, i, pos)
if event.type == pl.MOUSEMOTION:
for button in buttons:
if button.isOver(pos):
button.color = colors['silver']
else:
button.color = colors['blacksteel']
graph.edges = edges
# showing the graph
graph.graph_show()
pygame.display.update()