def setUp(self): e = Frame(cargo="eee") self.FrameList = FrameList(e) (a, b, c, d) = (Frame(cargo="aaa"), Frame(cargo="bbb"), Frame(cargo="ccc"), Frame(cargo="ddd")) self.Frames = [a, b, c, d] self.downFrame = e
def handle_methods(string, frame, s, display_speed): """ pre : string commence par $. frame est un Frame. s est un SenseHatEncodator post : execute la fonction designee par string """ function = string[1:] if function == "append_new_message": frame.append_new_message("proto-message.txt") if function == "display_proto_message": s.display_proto_message(display_speed) if function == "snake_password_append": a = s.run_snake_game(0.75) num = a[0] * 8 + a[1] frame = Frame(chr(num)) frame.append_new_message("proto-password.txt") if function == "snake_password_append2": a = s.run_snake_game(0.75) num = a[0] * 8 + a[1] frame = Frame(chr(num)) frame.append_new_message("entered_password.txt") if function == "register_message": s.register_message("proto-message.txt", "proto-password.txt", display_speed) if function == "read_message": s.read_message() if function == "show_registered_message": s.show_registered_message("entered_password.txt", display_speed)
def test_add_last(self): self.FrameList.add_last(self.Frames[0]) self.assertEqual(self.FrameList.lenght(), 1) self.assertEqual(str(self.FrameList.head()), "aaa") for i in range(1, len(self.Frames)): self.FrameList.add_last(self.Frames[i]) self.assertEqual(self.FrameList.lenght(), 4) self.assertEqual(str(self.FrameList.head()), "aaa") self.assertEqual(str(self.FrameList.tail_end()), "ddd") for Frame in self.Frames: self.assertEqual(str(Frame.down()), "eee")
display_speed) if function == "read_message": s.read_message() if function == "show_registered_message": s.show_registered_message("entered_password.txt", display_speed) if __name__ == "__main__": #Creation des FrameLists qui composent les menus (a remplacer plus tard) main_menu = FrameList() read_message_menu = FrameList() new_message_menu = FrameList() keyboard_menu = FrameList() keyboard_menu_frames = [] for i in range(10): frame = Frame(cargo=i) #TODO : define a up attribute here frame.setup("$append_new_message") keyboard_menu_frames.append(frame) (a1, a2, a3, a4) = (Frame(cargo = "Entrer un message", up = keyboard_menu), Frame(cargo = "Entrer le mot de passe", up = "$snake_password_append"),\ Frame(cargo = "Voir le message", up = "$display_proto_message"), Frame(cargo = "Valider", up = "$register_message")) new_message_menu_frames = [a1, a2, a3, a4] (b1, b2) = (Frame(cargo="Nouveau caractere de mot de passe", up="$snake_password_append2"), Frame(cargo="Voir le message", up="$show_registered_message")) read_message_menu_frames = [b1, b2] (b, a) = (Frame(cargo = "Lire le message", up = read_message_menu),\ Frame(cargo = "Nouveau message", up = new_message_menu)) main_menu_frames = [a, b] keyboard_menu.setdown(a1) new_message_menu.setdown(a)
def setUp(self): self.FrameList = FrameList() (a, b, c, d) = (Frame(cargo="aaa"), Frame(cargo="bbb"), Frame(cargo="ccc"), Frame(cargo="ddd")) self.Frames = [a, b, c, d]
""" function = string[1:] if function == append_new_message: frame.append_new_message("proto-message.txt") if function == display_proto_message: s.display_proto_message() if __name__ == "__main__": #Creation des FrameLists qui composent les menus (a remplacer plus tard) main_menu = FrameList() new_message_menu = FrameList() keyboard_menu = FrameList() keyboard_menu_frames = [] for i in range(10): frame = Frame(cargo = i) #TODO : define a up attribute here frame.setup("$append_new_message") keyboard_menu_frames.append(frame) (a1, a2, a3, a4) = (Frame(cargo = "Entrer un message", up = keyboard_menu), Frame(cargo = "Entrer le mot de passe"),\ Frame(cargo = "Voir le message", up = "$display_proto_message"), Frame(cargo = "Valider")) new_message_menu_frames = [a1, a2, a3, a4] (b, a) = (Frame(cargo = "Lire le message"),\ Frame(cargo = "Nouveau message", up = new_message_menu)) main_menu_frames = [a, b] keyboard_menu.setdown(a1) new_message_menu.setdown(a) for frame in keyboard_menu_frames: keyboard_menu.add_last(frame)
Ne gere pour le moment que les mouvements gauche droite du joistick. """ if event.action != "released": if event.direction == "right": return current_frame.next() if event.direction == "left": return current_frame.last() if event.direction == "down" and current_frame.down == None: call("sudo shutdown -h now", shell=True) #TODO : ajouter une demande de confirmation if __name__ == "__main__": #Creation des FrameLists qui composent les menus (a remplacer plus tard) main_menu = FrameList() (a, b) = (Frame(cargo = "Lire le message", up = "display_msg"),\ Frame(cargo = "Nouveau message", up = "register_message")) main_menu.add_last(a) main_menu.add_last(b) #Creation du SenseHat s = SenseHatEncodator() #Programme principal running = True current_menu = main_menu current_frame = a message_showed = True while running: if message_showed: #Empeche les inputs ne changeant pas le message afficher de faire celui-ci se repeter. s.show_message(text_string=str(current_frame), scroll_speed=0.05) event = s.stick.wait_for_event() print(event)