Beispiel #1
0
class Main:
    def __init__(self):
        pubsub = PubSub()
        events_dispatcher = EventsDispatcher(pubsub)
        display = self.display_surface()
        repo = Repository(config["repo_path"])
        branches = repo.listall_branches()
        drawer = Drawer(repo, branches, display, pubsub)

        pubsub.sub("on_program_exit", self.exit_program)

        self.main_loop = MainLoop(display, drawer, events_dispatcher)
        self.init_screen()

    def start(self):
        self.log_start()
        self.main_loop.start()

    @staticmethod
    def log_start():
        if config["log_events"]:
            print("start " + config["title"])

    @staticmethod
    def exit_program(obs):

        if config["log_events"]:
            print("exit " + config["title"])

        while True:
            try:
                if obs:
                    obs.stop()
                    obs.join()
                break
            except AttributeError:
                continue
        pygame.quit()
        sys.exit(0)

    @staticmethod
    def display_surface():
        if config["full_screen"]:
            return pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            return pygame.display.set_mode(config["resolution"], pygame.RESIZABLE)

    def init_screen(self):
        pygame.init()
        self.set_centered_on_screen()
        self.set_title()

    @staticmethod
    def set_centered_on_screen():
        if config["centered_on_screen"]:
            os.environ["SDL_VIDEO_CENTERED"] = "1"

    @staticmethod
    def set_title():
        pygame.display.set_caption(config["title"])
Beispiel #2
0
    def __init__(self):
        pubsub = PubSub()
        events_dispatcher = EventsDispatcher(pubsub)
        display = self.display_surface()
        repo = Repository(config["repo_path"])
        branches = repo.listall_branches()
        drawer = Drawer(repo, branches, display, pubsub)

        pubsub.sub("on_program_exit", self.exit_program)

        self.main_loop = MainLoop(display, drawer, events_dispatcher)
        self.init_screen()