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)
def ok_clicked(self): self.value = Board.new_rectangle(int(self.width_input.value), int(self.height_input.value)) self.filename = preference.map_filename(self.filename_input.value) self.send(gui.CHANGE)
def new_size(self): self.board = Board.new_rectangle(int(self.width_input.value), int(self.height_input.value)) self.preview.set_map(self.board)