def __init__(self, text="", window=None, batch=None, group=None, theme=None, on_escape=None, have_focus=False): def on_ok(_): if on_escape is not None: on_escape(self) self.delete() button = FocusButton("Ok", on_press=on_ok) Manager.__init__(self, content=Frame(VerticalContainer( [Label(text), button])), window=window, batch=batch, group=group, theme=theme, is_movable=True) Manager.set_next_focus(self, 1)
def __init__(self, text="", ok="Ok", cancel="Cancel", window=None, batch=None, group=None, theme=None, on_ok=None, on_cancel=None): def on_ok_click(_): if on_ok is not None: on_ok(self) self.delete() def on_cancel_click(_): if on_cancel is not None: on_cancel(self) self.delete() Manager.__init__(self, content=Frame( VerticalContainer([ Label(text), HorizontalContainer([Button(ok, on_press=on_ok_click), None, Button(cancel, on_press=on_cancel_click)] )]) ), window=window, batch=batch, group=group, theme=theme, is_movable=True)
def __init__(self, rows, cols, setup=None, loop=None, hexagonal = False): screen_res = self.__get_square_screen_size__() self.rows, self.cols = rows, cols self.hexagonal = hexagonal self.__generation_count__ = 0 self.__grid_width__ = int(screen_res[0] * WIDTH_RATIO) self.__grid_height__ = int(screen_res[1] * HEIGHT_RATIO) self.__paused__ = False self.__game_paused__ = True self.__render_cells__ = {} self.theme = Theme({ "font": "Lucida Grande", "font_size": int((FONT_SIZE_NORMAL / 1280) * int(screen_res[0])), "font_size_small": int(FONT_SIZE_SMALL / 1280) * int(screen_res[0]), "gui_color": [255, 255, 255, 255], "disabled_color": [160, 160, 160, 255], "text_color": [255, 255, 255, 255], "highlight_color": [255, 255, 255, 64], "button": { "down": { "highlight": { "image": { "source": "button-highlight_2.png", "frame": [8, 6, 2, 2], "padding": [18, 18, 8, 6] } }, "image": { "source": "button-down_2.png", "frame": [6, 6, 3, 3], "padding": [12, 12, 4, 2] }, "text_color": [0, 0, 0, 255] }, "up": { "highlight": { "image": { "source": "button-highlight_2.png", "frame": [8, 6, 2, 2], "padding": [18, 18, 8, 6] } }, "image": { "source": "button_2.png", "frame": [6, 6, 3, 3], "padding": [12, 12, 4, 2] } } }}, resources_path='assets/') super(LifeWindow, self).__init__( self.__grid_width__, int((1/GRID_RATIO) * self.__grid_height__)) self.set_caption("Conway\'s Game of Life") self.setup = setup if self.setup != None: self.setup(self) self.loop = loop def on_press_play(is_pressed): self.__game_paused__ = not self.__game_paused__ if self.__game_paused__ == False: pyglet.clock.schedule_once(self.on_logic, SPEED) def on_press_reset(is_pressed): pyglet.clock.schedule_once(self.__reset_button__, RESET_BUTTON_PAUSE, self.reset) self.clear_grid() self.__generation_count__ = 0 if self.setup != None: self.setup(self) def on_press_step(is_pressed): pyglet.clock.schedule_once(self.__reset_button__, RESET_BUTTON_PAUSE, self.step) self.on_logic() self.play = HighlightedButton('Pause', on_press = on_press_play) self.play._is_pressed = True self.reset = HighlightedButton('Reset', on_press = on_press_reset) self.step = HighlightedButton('Step', on_press = on_press_step) self.generation = Label(str(self.__generation_count__)) self.button_container = Container(content=[self.play, self.reset, self.step, self.generation]) self.batch = pyglet.graphics.Batch() Manager(self.button_container, window = self, theme = self.theme, batch = self.batch) pyglet.clock.schedule_interval(self.on_draw, 1 / FRAMERATE) pyglet.app.run()