Ejemplo n.º 1
0
    def __init__(self, game, stats=DEFAULT_STATS, buttons=DEFAULT_BUTTONS_CONTINUE):
        self.action = None
        self.root = root = Tk()
        root.title("Iä! Shub-Niggurath! The Black Goat of the Woods with a Thousand Young!")
        root.protocol("WM_DELETE_WINDOW", self.close)

        root.pack_propagate(True)

        self.grid_canvas = Canvas(root, bd=5, relief=tkinter.SUNKEN)
        self.grid_canvas.pack(expand=True, fill=tkinter.BOTH, side=tkinter.LEFT)

        button_frame = Frame(root)
        button_frame.pack(fill=tkinter.BOTH, side=tkinter.LEFT)

        stat_frame = Frame(button_frame, bd=1)
        stat_frame.pack(fill=tkinter.BOTH)
        stat_frame.columnconfigure(1, weight=1)
        self.stat_textboxes = stat_textboxes = []
        for row, (text, callback) in enumerate(stats):
            label = Label(stat_frame, text=text + ":", anchor="e")
            label.grid(row=row, column=0, sticky="wens")
            textbox = Label(stat_frame, bd=1, relief=tkinter.SUNKEN)
            textbox.callback = callback  # for our own use.
            textbox.grid(row=row, column=1, sticky="wens")
            stat_textboxes.append(textbox)

        for name, bindings, action in buttons:

            def callback(event, action=action):
                if self.action is not None:
                    log.error("Action already set: %r when processing %r", self.action, action)
                self.action = action
                root.quit()

            text = name + (" ({})".format(bindings) if bindings else "")
            button = Button(button_frame, text=text, command=lambda: callback(None))
            button.pack()
            for it in bindings.split():
                root.bind(it, callback)

        if game is not None:
            self.update(game)