Example #1
0
class View:
    def __init__(self):
        reader = CSVElectionInterpreter(PATH)
        formatted_info = reader.get_dict()
        tree = dict_to_tree(formatted_info)
        self.drawer = MapDrawer(tree, COLOR_ASSIGNMENTS)

    def loop(self):
        running = True
        pygame.display.update()
        pos = None
        self.drawer.update_map()
        self.drawer.draw_rectangles()
        while running:
            self.drawer.update_screen()
            all_events = pygame.event.get()
            for event in all_events:
                # handle MOUSEBUTTONUP
                if event.type == pygame.MOUSEBUTTONUP:
                    pos = pygame.mouse.get_pos()
                    if pos[0] <= 500:
                        self.drawer.update_text(pos[0], pos[1])
            if keyboard.is_pressed('o'):
                # enlarge
                if pos is not None:
                    self.drawer.enlarge(pos[0], pos[1])
                    print('1')
                pos = None
            elif keyboard.is_pressed('q'):
                # close tree
                print('2')
                self.drawer.close_all()
                self.drawer.draw_rectangles()
                pos = None
            elif keyboard.is_pressed('e'):
                # expand
                if pos is not None:
                    self.drawer.expand(pos[0], pos[1])
                    self.drawer.update_map()
                    self.drawer.draw_rectangles()
                    pos = None
            elif keyboard.is_pressed('c'):
                if pos is not None:
                    self.drawer.close_parent(pos[0], pos[1])
                pos = None
            elif keyboard.is_pressed('z'):
                running = False