def welcome_screen(): welcome_word = TextPygame("Welcome to PruVide", screen, CURRENT_TIME, font = 20, textpos = (85,10,15,130)) image = pygame.image.load("/home/pi/all_projects/pru_vide/pruvide_gui/images/cooking_ingredients.jpg") image_rotated = pygame.transform.rotate(image,90) imagepos = image_rotated.get_rect() screen.blit(image_rotated,(0,20,80,120)) welcome_word.render_and_draw() pygame.display.update()
class MenuSystem: def __init__(self, screen, menu_items, font = 24): self.screen = screen self.font_size = font self.current_item = 0 self.font = pygame.font.Font(None, font) self.centerx = 30 self.starty = 15 self.menu_objects = deque() self.menu_items = deque(menu_items) self.padding = 5 self.make_menu_objects() def place_carrot(self): pos = self.menu_objects[0].textpos x = pos[0] y = pos[1] + pos[3] self.carrot = TextPygame(">", self.screen, (x,y) , prefix = "", textpos = ()) def make_menu_objects(self): self.menu_objects = deque() currenty = self.starty self.menu_objects.append(TextPygame(self.menu_items[0], self.screen, (currenty, self.centerx), prefix = "", textpos = ())) for item in itertools.islice(self.menu_items, 1, len(self.menu_items)): currenty = (self.font_size/2) + currenty + self.padding self.menu_objects.append(TextPygame(item, self.screen, (currenty, self.centerx) , prefix = "", textpos = ())) def return_current(self): print self.menu_items[0] def up_menu(self): self.menu_items.rotate(-1) self.make_menu_objects() def down_menu(self): self.menu_items.rotate(1) self.make_menu_objects() def clear_screen(self): self.screen.fill((250,250,250)) pygame.display.update() def draw_menu(self): self.clear_screen() for item in self.menu_objects: item.render_and_draw() self.place_carrot() self.carrot.render_and_draw()
class Button: def __init__(self, rect_pos, text_dict): self.screen = text_dict['screen'] self.rect_pos = rect_pos self.rect = self.draw_rect(rect_pos) self.text_object = TextPygame(**text_dict) self.calculate_and_set_text_center() def draw_rect(self, location): rect = pygame.draw.rect(self.screen, (0,0,0), location, 2) pygame.display.update() return rect def render_and_draw(self): self.text_object.render_text() self.text_object.draw_text() def calculate_and_set_text_center(self): textx, texty = self.text_object.get_text_size() newx = self.rect_pos[0] + (textx/2) newy = self.rect_pos[1] + 10 self.text_object.set_screen_location((newx,newy))
temporary_temp.render_and_draw() elif pin == ENTER: menu_state_map['send_temperature'] elif pin == MENU: # Init screen and buttons pygame.init() screen = pygame.display.set_mode((120,160)) screen.fill(WHITE) pygame.display.update() font = pygame.font.Font(None, 26) initiate_buttons() set_point = TextPygame("50", screen, SET_POINT, prefix = "Setpoint: ", textpos = ()) current_temp = TextPygame("70", screen, CURRENT_TEMP, prefix = "Temp: ", textpos = ()) current_time = TextPygame("0", screen, CURRENT_TIME, prefix = "Time(min): ", textpos = ()) temporary_temp = TextPygame("50", screen, SET_POINT, prefix = "", textpos = ()) all_temps = [ set_point, current_temp, current_time] menu = {'Set Temp': '50', 'Pre-sets': {'beef' : '140', 'fish': '65', 'veggies': '100' }, 'Config': {'Device': 'Rice Cooker', 'Probe': '28-0000000000'} } some_state = UiStateMachine() my_menu = MenuSystem(screen, menu_level(menu)) def menu_level(full_menu): level = [] for k,v in full_menu.items(): level.append(v) return level
class MenuSystem: def __init__(self, screen, menu_dict, font = 24): self.screen = screen self.font_size = font self.current_item = 0 self.font = pygame.font.Font(None, font) self.centerx = 30 self.starty = 15 self.full_menu = menu_dict self.menu_objects = deque() self.current_selection = "" self.menu_items = deque(make_menu_level()) self.padding = 5 self.make_menu_objects() def set_new_menu(self, menu_items): self.menu_items = deque(menu_items) self.make_menu_objects() def make_menu_level(self): level = [] for k,v in self.full_menu.items(): level.append(v) return level def select_menu_item(self): # get new level items. # set current selection # make menu_objects # draw_menu selections def back_menu_item(self): # get new level items. # set current selection # make menu_objects # draw_menu selections def place_carrot(self): pos = self.menu_objects[0].textpos x = pos[0] y = pos[1] + pos[3] self.carrot = TextPygame(">", self.screen, (x,y) , prefix = "", textpos = ()) def make_menu_objects(self): self.menu_objects = deque() currenty = self.starty self.menu_objects.append(TextPygame(self.menu_items[0], self.screen, (currenty, self.centerx), prefix = "", textpos = ())) for item in itertools.islice(self.menu_items, 1, len(self.menu_items)): currenty = (self.font_size/2) + currenty + self.padding self.menu_objects.append(TextPygame(item, self.screen, (currenty, self.centerx) , prefix = "", textpos = ())) def return_current(self): return self.menu_items[0] def up_menu(self): self.menu_items.rotate(-1) self.make_menu_objects() def down_menu(self): self.menu_items.rotate(1) self.make_menu_objects() def clear_screen(self): self.screen.fill((250,250,250)) pygame.display.update() def draw_menu(self): self.clear_screen() for item in self.menu_objects: item.render_and_draw() self.place_carrot() self.carrot.render_and_draw()
def place_carrot(self): pos = self.menu_objects[0].textpos x = pos[0] y = pos[1] + pos[3] self.carrot = TextPygame(">", self.screen, (x,y) , prefix = "", textpos = ())
def one_item(default_settings): blah = TextPygame(**default_settings) blah.render_and_draw() return blah
def __init__(self, rect_pos, text_dict): self.screen = text_dict['screen'] self.rect_pos = rect_pos self.rect = self.draw_rect(rect_pos) self.text_object = TextPygame(**text_dict) self.calculate_and_set_text_center()