Backup before switching to flexx for GUI
Added serial communication class that can succesfully communicate with the arduino. Started work on pygame GUI but I've decided to switch direction to using Flexx instead.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import pygame
|
||||
import serial
|
||||
from Button import Button
|
||||
from Comm import Comm
|
||||
|
||||
def createText(font, text, position):
|
||||
text = font.render(text, True, (0,0,0), (255,255,255))
|
||||
@@ -23,14 +24,17 @@ texts.append(createText(font, 'Pressure (PSI)', positions[0]))
|
||||
texts.append(createText(font, 'Heart Rate (BPM)', positions[1]))
|
||||
texts.append(createText(font, '0', positions[2]))
|
||||
texts.append(createText(font, '0', positions[3]))
|
||||
def test(nothing):
|
||||
|
||||
comm = Comm('COM10', 115200)
|
||||
def test():
|
||||
return
|
||||
testButton = Button([10,10], [50,50], pygame, test, "Hello")
|
||||
testButton = Button([10,10], [50,50], screen, test, "Hello")
|
||||
|
||||
def main():
|
||||
done = False
|
||||
while not done:
|
||||
screen.fill((255, 255, 255))
|
||||
testButton.drawButton()
|
||||
for text in texts:
|
||||
screen.blit(text[0], text[1])
|
||||
for event in pygame.event.get():
|
||||
@@ -42,33 +46,5 @@ def main():
|
||||
pygame.quit()
|
||||
return
|
||||
|
||||
class Button:
|
||||
pos = [0,0]
|
||||
size = [0,0]
|
||||
def __init__(self, position, size, pygame, function, argument):
|
||||
self.pos = position
|
||||
self.size = size
|
||||
self.function = function
|
||||
self.argument = argument
|
||||
self.pygame = pygame
|
||||
return
|
||||
|
||||
def isClicked(self):
|
||||
x, y = self.pygame.get_pos()[0], self.pygame.get_pos()[1]
|
||||
if x >= self.pos[0] and x <= self.pos[0]+self.size[0]:
|
||||
if y >= self.pos[1] and y <= self.pos[1]+self.size[1]:
|
||||
if pygame.mouse.get_pressed()[0] == True:
|
||||
self.function(self.argument)
|
||||
return True
|
||||
return False
|
||||
|
||||
def setPosition(self, x, y):
|
||||
self.pos[0], self.pos[1] = x, y
|
||||
return
|
||||
|
||||
def setArgument(self, argument):
|
||||
self.argument = argument
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user