Beispiel #1
0
    def choose_player(self):
        if self.painter.board is not None:
            title = gui.Label("Choose player")
            table = gui.Table()
            players = list(sorted(self.painter.board.players))
            radios = gui.Group(value=self.player_input.value)
            for player in players:
                table.td(gui.Radio(radios, value=str(player)), style=td_style)
            table.tr()
            for player in players:
                table.td(
                    ImageWidget(image=self.items[self.amount][player],
                                style=td_style,
                                width=request("map_editor.view_width"),
                                height=request("map_editor.view_height")))
            button = gui.Button("  Apply  ")
            table.tr()
            table.td(button, style=td_style)
            dialog = gui.Dialog(title, table)

            def on_click():
                dialog.value = int(radios.value)
                dialog.send(gui.CHANGE)
                dialog.close()

            button.connect(gui.CLICK, on_click)
            dialog.connect(gui.CHANGE, lambda: self.new_player(dialog.value))
            dialog.open()
Beispiel #2
0
    def __init__(self):
        self.desktop = gui.Desktop(theme=self.theme)
        self.desktop.connect(gui.QUIT, self.on_quit)

        self.table = gui.Table(width=request("main_menu.width"),
                               height=request("main_menu.height"))
        self.table.tr()
        self.table.td(gui.Label("Menu"), colspan=4)
        self.table.tr()
        self.new_game_button = gui.Button("New game")
        self.new_game_button.connect(gui.CLICK, self.new_game)
        self.table.td(self.new_game_button)
        self.table.tr()
        self.load_last_button = gui.Button("Load")
        self.load_last_button.connect(gui.CLICK, self.load_game)
        self.table.td(self.load_last_button)
        self.table.tr()
        self.map_editor_button = gui.Button("Map editor")
        self.map_editor_button.connect(gui.CLICK, self.to_map_editor)
        self.table.td(self.map_editor_button)
        self.table.tr()
        self.rules_button = gui.Button("Rules")
        self.rules_button.connect(gui.CLICK, self.show_rules)
        self.table.td(self.rules_button)
        self.table.tr()
        self.quit_button = gui.Button("Quit")
        self.quit_button.connect(gui.CLICK, self.quit)
        self.table.td(self.quit_button)
        # self.menu = gui.Menus(menu_data)
        # self.table.td(self.menu, rowspan=10, colspan=10, columnspan=5)
        self.desktop.run(self.table)
Beispiel #3
0
def add_block(document, align, text, space, br=None):
    if br is None: br = space[1]
    document.block(align=align)
    for word in text.split(' '):
        document.add(gui.Label(word))
        document.space(space)
    document.br(br)
Beispiel #4
0
 def __init__(self, filename=request("dialog.new_map_dialog.filename")):
     self.filename = filename
     title = gui.Label("New map")
     self.table = table = gui.Table()
     table.tr()
     table.td(gui.Label("Width"), style=td_style)
     table.td(gui.Label("Height"), style=td_style)
     table.tr()
     self.width_input = gui.Input(str(
         request("dialog.new_map_dialog.board_width")),
                                  size=5)
     table.td(self.width_input, style=td_style)
     self.height_input = gui.Input(
         request("dialog.new_map_dialog.board_height"), size=5)
     table.td(self.height_input, style=td_style)
     add_event_handler(self.width_input, enter_pressed,
                       lambda e: self.new_size())
     add_event_handler(self.height_input, enter_pressed,
                       lambda e: self.new_size())
     table.tr()
     show_button = gui.Button('Show')
     show_button.connect(gui.CLICK, self.new_size)
     table.td(show_button, style=td_style)
     self.board = Board.new_rectangle(
         request("dialog.new_map_dialog.board_width"),
         request("dialog.new_map_dialog.board_height"))
     self.preview = Preview()
     table.tr()
     table.td(self.preview, style=td_style)
     self.preview.set_map(self.board)
     table.tr()
     self.filename_input = gui.Input(self.filename)
     table.td(self.filename_input)
     table.tr()
     button = gui.Button('  Ok  ')
     table.td(button, style=td_style)
     button.connect(gui.CLICK, self.ok_clicked)
     gui.Dialog.__init__(self, title, table)
Beispiel #5
0
 def show_players_preference(self):
     self.players = self.map.players
     self.bots = {}
     self.bot_buttons = {}
     if self.preview is None:
         self.preview = Preview()
         self.table.td(self.preview, style=td_style)
     self.preview.set_map(self.map)
     if self.players_table:
         self.table.remove(self.players_table)
     self.players_table = gui.Table()
     init_td_style(self.players_table, style=td_style)
     self.players_table.td(gui.Label("Players:"), style=td_style)
     self.players_table.tr()
     self.strategy_labels = {}
     for i in sorted(self.players):
         self.players_table.td(gui.Label("Player #{}:".format(i)),
                               style=td_style)
         self.players_table.td(gui.Label("Bot"), style=td_style)
         self.bot_buttons[i] = gui.Switch(False)
         self.bot_buttons[i].connect(gui.CHANGE, self.tune_bot, i)
         self.players_table.td(self.bot_buttons[i], style=td_style)
         self.preference_button = gui.Button("Settings")
         self.preference_button.connect(gui.CLICK,
                                        self.show_player_preference, i)
         self.players_table.td(self.preference_button, style=td_style)
         self.strategy_labels[i] = gui.Input('', size=10)
         self.players_table.td(self.strategy_labels[i], style=td_style)
         self.players_table.tr()
     self.table.td(self.players_table, style=td_style)
     self.save_name_input = gui.Input(request("paths.autosave_name"))
     self.save_name_input.connect(gui.CHANGE, self.new_name)
     self.new_name()
     self.players_table.td(self.save_name_input)
     self.players_table.tr()
     self.start_button = gui.Button("  Start  ")
     self.start_button.connect(gui.CLICK, self.send, gui.CHANGE)
     self.players_table.td(self.start_button, style=td_style)
Beispiel #6
0
    def show_player_preference(self, i):
        self.preference_title = gui.Label("Player #{} preference".format(i))
        self.preference_form = gui.Form()
        self.preference_table = gui.Table()
        self.preference_table.td(gui.Label("Bot"), style=td_style)
        self.bot_switcher = gui.Switch(self.bot_buttons[i].value)
        self.preference_table.td(self.bot_switcher, style=td_style)
        self.preference_table.tr()
        self.preference_table.td(gui.Label("Strategy"), style=td_style)
        self.preference_table.tr()
        self.selector = gui.Select(
            value=self.bots.get(i, None) or request("core.bot"))
        for name, value in sorted(request("core.bots").items()):
            self.selector.add(name, value)
        self.preference_table.td(self.selector, style=td_style)
        self.preference_table.tr()
        self.apply_button = gui.Button("  Apply  ")
        self.apply_button.connect(gui.CLICK, self.deep_bot, i)
        self.preference_table.td(self.apply_button, style=td_style, align=0)

        self.preference_dialog = gui.Dialog(self.preference_title,
                                            self.preference_table)
        self.preference_dialog.open()
Beispiel #7
0
 def __init__(self, **params):
     self.title = gui.Label("New game")
     self.value = gui.Form()
     self.table = gui.Table()
     init_td_style(self.table, style=td_style)
     self.table.tr()
     self.table.td(gui.Label("Map"), align=-1, style=td_style)
     self.map_path = gui.Input(folder('map'))
     self.table.td(self.map_path, style=td_style)
     self.browse_button = gui.Button("Browse...")
     self.browse_button.connect(gui.CLICK, self.open_map)
     self.table.td(self.browse_button, style=td_style, align=-1)
     self.edit_button = gui.Button("Edit...", align=0)
     # self.edit_button.connect(gui.CLICK, ...) # to map editor: edit: choose if not chosen yet
     self.table.td(self.edit_button, style=td_style)
     self.create_button = gui.Button("Create...", align=0)
     # self.create_button.connect(gui.CLICK, ...) # to map editor: create
     self.table.td(self.create_button, style=td_style)
     self.table.tr()
     self.preview = None
     self.players_table = None
     gui.Dialog.__init__(self, self.title, self.table)
     self.connect(gui.QUIT, self.send, gui.CHANGE)
Beispiel #8
0
    def __init__(self, board=None, callback=None, **params):
        pygame.display.set_mode(
            (request("map_editor.width"), request("map_editor.height")))
        gui.Desktop.__init__(self, theme=self.theme, **params)
        self.callback = callback or (lambda *_, **__: None)
        self.connect(gui.QUIT, self.quit)
        self.board = board
        self.filename = None
        container = gui.Container(width=request("map_editor.width"),
                                  height=request("map_editor.height"))

        spacer = request("map_editor.space_size")

        self.new_dialog = NewMapDialog()
        self.new_dialog.connect(gui.CHANGE, self.action_new)
        self.open_dialog = FileDialog("Choose map",
                                      "Choose",
                                      path=folder('map'),
                                      preview=Preview(display_players=False),
                                      exts=['map', 'preset', 'state'])
        self.open_dialog.connect(gui.CHANGE, self.new_map)
        self.save_dialog = FileDialog("Enter filename to save with",
                                      "Choose",
                                      path=folder('map'),
                                      exts=['map'],
                                      save=True)
        self.save_dialog.connect(gui.CHANGE, self.action_saveas)

        # self.help_dialog = HelpDialog()
        # QUESTION: may be put it into json: {"<menu>": "<method name>", ...}
        self.menus = menus = gui.Menus([
            ('File/New', self.new_dialog.open, None),
            ('File/Open', self.open_dialog.open, None),
            ('File/Save', self.action_save, None),
            ('File/Save As', self.save_as, None),
            ('File/Exit', self.quit, None), ('Add/Extend', self.extend, None),
            ('Add/Add top row', self.add_top_row, None),
            ('Add/Add bottom row', self.add_bottom_row, None),
            ('Add/Add left column', self.add_left_column, None),
            ('Add/Add right column', self.add_right_column, None),
            ('Add/Add cells', self.add_cells, None),
            ('Remove/Reduce', self.reduce, None),
            ('Remove/Remove top row', self.remove_top_row, None),
            ('Remove/Remove bottom row', self.remove_bottom_row, None),
            ('Remove/Remove left column', self.remove_left_column, None),
            ('Remove/Remove right column', self.remove_right_column, None),
            ('Remove/Remove the same checkers', self.remove_same_checkers,
             None),
            ('Remove/Remove checkers with the same owner',
             self.remove_same_player_checkers, None),
            ('Remove/Remove checkers with the same level',
             self.remove_same_level_checkers, None),
            ('Remove/Remove all checkers', self.remove_checkers, None),
            ('Remove/Remove cells', self.remove_cells, None),
            ('Edit/Permute cells', self.permute_cells, None),
            ('Edit/Permute players', self.permute_players, None),
            ('Edit/Permute checkers', self.permute_checkers, None)
            # ('Help/Help', self.help_dialog.open)
        ])
        container.add(self.menus, 0, 0)
        self.menus.rect.w, self.menus.rect.h = menus.resize()
        self.filename_input = gui.Input("")
        container.add(self.filename_input, self.menus.rect.w + spacer, 0)

        # # new ::
        # self.mode = mode = gui.Group(name="brushes", value='player')
        # cell_tool = gui.Tool(self.mode, "Cell", 'cell')
        # empty_tool = gui.Tool(self.mode, "Empty", 'none')
        # player_tool = gui.Tool(self.mode, "Player", 'player')
        # # :: new
        self.mode = mode = gui.Toolbox([('Cell', 'cell'), ('Empty', 'none'),
                                        ('Player', 'player')],
                                       cols=1,
                                       value='player')  # NOTE: DEPERECATED
        self.mode.connect(gui.CHANGE, self.set_brush)
        self.player = request("map_editor.player")
        self.amount = request("map_editor.amount")
        container.add(mode, 0, self.menus.rect.bottom + spacer)
        # # new ::
        # container.add(cell_tool, 0, self.menus.rect.bottom + spacer)
        # container.add(empty_tool, 0, cell_tool.rect.bottom + spacer)
        # container.add(cell_tool, 0, empty_tool.rect.bottom + spacer)
        # # :: new
        mode.rect.x, mode.rect.y = mode.style.x, mode.style.y
        mode.rect.w, mode.rect.h = mode.resize()

        self.player_table = gui.Table()
        self.player_table.td(gui.Label("Holes"))
        self.player_table.tr()
        self.selector = gui.Select(value=request("map_editor.amount"))
        for i in sorted(self.items.keys()):
            self.selector.add(str(i), i)
        self.selector.connect(gui.CHANGE, self.new_amount)
        self.player_table.td(self.selector, style=td_style)
        self.player_table.tr()
        self.player_table.tr()
        self.player_button = gui.Button('Player')
        self.player_table.td(self.player_button, style=td_style)
        self.player_button.connect(gui.CLICK, self.choose_player)
        self.player_table.tr()
        self.player_input = gui.Input(str(self.player), size=5)
        add_event_handler(self.player_input, enter_pressed,
                          lambda e: self.new_player())
        self.player_table.td(self.player_input, style=td_style)
        self.player_table.tr()
        self.checker = ImageWidget(image=self.items[self.amount][self.player],
                                   width=request("map_editor.view_width"),
                                   height=request("map_editor.view_height"))
        self.player_table.td(self.checker, style=td_style)
        self.player_table.tr()
        # self.color = gui.Color("#000000", width=mode.rect.w, height=mode.rect.w)
        # self.color.connect(gui.CLICK, self.choose_player)
        # self.player_table.td(self.color, style=td_style)
        container.add(self.player_table, 0, mode.rect.bottom + spacer)

        self.painter = Painter(
            width=container.rect.w - mode.rect.w - spacer * 2,
            height=container.rect.h - self.menus.rect.h - spacer * 2,
            style={'border': 1})
        container.add(self.painter, mode.rect.w + spacer,
                      self.menus.rect.h + spacer)
        if board:
            self.painter.set_map(board)
        self.painter.rect.w, self.painter.rect.h = self.painter.resize()

        self.widget = container
Beispiel #9
0
 def __init__(self, title, width=400, height=200):
     self.title = gui.Label(title)
     self.document = gui.Document(width=width)
     self.space = self.title.style.font.size(" ")
Beispiel #10
0
 def __init__(self,
              title_text="File Browser",
              button_text="Okay",
              cls="dialog",
              path=None,
              preview=None,
              exts=['any'],
              save=False):
     """
         title_text -- title
         button_text -- button text
         path -- initial path
         preview -- instance of Preview class or None
         load_condition -- lambda filename: True/False
         ext -- initial format name
         exts -- [Format(...), ...]
         save -- check filename on existance (default: False)
     """
     if exts is None:
         exts = ['any']
     if 'any' not in exts:
         exts.append('any')
     self.formats = {name: formats[name] for name in exts}
     self.formats['any'] = formats['any']
     self.ext = exts[0]
     self.exts = exts
     self.save = save
     cls1 = "filedialog"
     if not path:
         self.curdir = os.getcwd()
     else:
         self.curdir = path
     self.dir_img = gui.Image(
         gui.pguglobals.app.theme.get(cls1 + ".folder", "", 'image'))
     self.title = gui.Label(title_text, cls=cls + ".title.label")
     self.body = gui.Table()
     self.list = gui.List(width=self.LIST_WIDTH, height=self.LIST_HEIGHT)
     self.input_dir = gui.Input()
     self.input_file = gui.Input()
     self.selector = gui.Select(value=self.ext)
     for name in self.exts:
         self.selector.add(formats[name].description, name)
     self.selector.connect(gui.CHANGE, self._new_ext)
     self._list_dir()
     self.button_ok = gui.Button(button_text)
     self.body.tr()
     self.body.td(gui.Label("Folder"), style=td_style, align=-1)
     self.body.td(self.input_dir, style=td_style)
     add_event_handler(self.input_dir, enter_pressed, self._dir_enter)
     self.body.tr()
     self.body.td(self.list, colspan=3, style=td_style)
     self.list.connect(gui.CHANGE, self._new_item)
     self.button_ok.connect(gui.CLICK, self._button_okay_clicked)
     self.preview = preview
     if preview is not None:
         self.body.td(self.preview, style=td_style)
     self.body.tr()
     self.body.td(gui.Label("File"), style=td_style, align=-1)
     add_event_handler(self.input_file, enter_pressed, self._file_enter)
     # self.input_file.event = _extended_event_handler(self.input_file, enter_pressed, self._file_enter)
     self.body.td(self.input_file, style=td_style)
     self.body.td(self.selector, style=td_style)
     self.body.td(self.button_ok, style=td_style)
     self.value = None
     gui.Dialog.__init__(self, self.title, self.body)
     arrow_pressed = lambda e: e.type == gui.KEYDOWN and e.key in (
         K_UP, K_DOWN, K_LEFT, K_RIGHT)
     add_event_handler(self, arrow_pressed, self._on_arrow_pressed)