-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomatasApp.py
More file actions
116 lines (98 loc) · 4.06 KB
/
AutomatasApp.py
File metadata and controls
116 lines (98 loc) · 4.06 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from kivy.app import App
from path import *
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.properties import ObjectProperty, ListProperty, NumericProperty
from arduinoPath import *
# from arduinoCommands import *
class GridUI(GridLayout):
status = ListProperty([0]*64)
options = [1,2,3]
color = {0: (.99, .89, .65, 1), 1: (.18, .8, .4, 1), 2: (.96, .28, .28, 1), 3: (.2, .6, .86, 1), 4: (.97, .58, .02, 1)}
buttons_list = []
button_inicio = ListProperty(None)
button_final = ListProperty(None)
button_obstaculos = ListProperty(None)
nodes = []
current_option = NumericProperty(1)
resultPath = []
def __init__(self, *args, **kwargs):
super(GridUI, self).__init__(*args, **kwargs)
for row in range(8):
for column in range(8):
node = Node(coords=(row,column))
self.nodes.append(node)
node.bind(on_press=self.button_pressed)
self.add_widget(node)
def button_pressed(self, button):
if button not in self.buttons_list:
self.buttons_list.append(button)
row, column = button.coords
status_index = 8*row + column
already_taken = self.status[status_index]
if already_taken not in self.options:
if (self.current_option == 1 or self.current_option == 2) and self.current_option in self.status:
for i in range(len(self.status)):
if self.status[i] == self.current_option:
self.status[i] = 0
c = i % 8
r = int(i / 8)
for b in self.buttons_list:
if b.coords == [r,c]:
b.background_color = self.color[0]
self.status[status_index] = self.current_option
button.background_color = self.color[self.current_option]
if self.current_option == 1 and len(self.button_inicio) == 0:
self.button_inicio.append(button.coords)
if self.current_option == 1 and len(self.button_inicio) > 0:
self.button_inicio[0] = button.coords
if self.current_option == 2 and len(self.button_final) == 0:
self.button_final.append(button.coords)
if self.current_option == 2 and len(self.button_final) > 0:
self.button_final[0] = button.coords
if self.current_option == 3:
self.button_obstaculos.append(button.coords)
else:
self.status[status_index] = 0
button.background_color = self.color[0]
if self.current_option == 3 and button.coords in self.button_obstaculos:
self.button_obstaculos.remove(button.coords)
def drawPath(self):
grid = Grid(8,self.button_obstaculos)
findPath = FindPath(grid,self.button_inicio[0],self.button_final[0])
self.resultPath = findPath.result
for node in self.nodes:
for i in self.resultPath[1:-1]:
if node.coords == i:
node.background_color = self.color[4]
print(self.resultPath)
Commands(self.resultPath)
def reset(self):
self.status = [0]*64
self.buttons_list = []
self.button_inicio = []
self.button_final = []
self.button_obstaculos = []
self.resultPath = []
for node in self.nodes:
node.background_color = self.color[0]
def send_arduino(self):
ArduinoPath(self.resultPath)
class Node(Button):
coords = ListProperty([0,0])
class CustomPopup(Popup):
pass
class Principal(BoxLayout):
def current_option(self,value):
self.ids.grid.current_option = value
def show_word(self):
return Commands(self.ids.grid.resultPath).commands
def showPopup(self,*args):
CustomPopup().open()
class AutomatasApp(App):
def build(self):
return Principal()
if __name__ == '__main__':
AutomatasApp().run()