def __init__(self): super(Zone, self).__init__() w, h = director.get_window_size() self.mode = model.INDUSTRY self.zone_images = { model.INDUSTRY: pyglet.resource.image('industry.png'), model.LOGISTICS: pyglet.resource.image('logistics.png'), model.MILITARY: pyglet.resource.image('military.png') } self.icons = { ('privileged', False): pyglet.resource.image('icon-priv_off.png'), ('privileged', True): pyglet.resource.image('icon-priv_on.png'), } w, h = director.get_window_size() self.active = Sprite(self.zone_images[model.INDUSTRY], anchor=((-(w-550), -(h-605))) ) self.add(self.active, z=-1) self.add(Button('but-ind_off.png', (self.zone1_x, self.y), 'industry', self.switch_zone_to), name=model.INDUSTRY) self.add(Button('but-log_off.png', (self.zone2_x, self.y), 'logistics', self.switch_zone_to), name=model.LOGISTICS) self.add(Button('but-mil_off.png', (self.zone3_x, self.y), 'military', self.switch_zone_to), name=model.MILITARY)
def set_dialog_buttons(self): if self.add_line: self.box.pack(HLine(self.box), fill=True, padding=5) else: self.box.pack((3, 3)) self.button_box = HPanel(self.box) self.box.pack(self.button_box, fill=True) self.ok_btn = Button( self.button_box, '', onclick=self.on_ok, default=True, pid=self.action_button) self.cancel_btn = Button( self.button_box, '', onclick=self.on_cancel, pid=const.BUTTON_CANCEL) self.left_button_box = HPanel(self.button_box) self.button_box.pack(self.left_button_box, expand=True, fill=True) if const.IS_MAC: self.button_box.pack(self.ok_btn, padding=5) self.button_box.pack(self.cancel_btn, padding=5) elif const.IS_MSW: self.button_box.pack(self.ok_btn, padding=2) self.button_box.pack(self.cancel_btn) else: self.button_box.pack(self.cancel_btn, padding=2) self.button_box.pack(self.ok_btn)
def initialize_board(screen, player1, player2, against): """ To initialize the board. """ screen.fill(screenfill) srect = pygame.Rect(0, 5, hsize, 55) brect = pygame.Rect(margin_left, margin_top, box_width*3, box_height*3) pygame.draw.rect(screen, fill_color, srect) pygame.draw.rect(screen, fill_color, brect) #buttons title = TextInput("Tic-Tac-Toe", hsize//2 - 130, 10, white, 60) if against == "is_human": pl1, pl2 = "Player 1", "Player 2" elif against == "is_random": pl1, pl2 = "Player", "Random agent" elif against == "is_ai": pl1, pl2 = "Player", "AI agent" players_def1 = Button(pl1 +" - " + player1, hsize//2-300, 100, white, 36, fill_color) players_def2 = Button(pl2+" - " + player2, hsize//2+120, 100, white, 36, fill_color) #vertical and horizontal lines pygame.draw.line(screen, white, (margin_left, margin_top+box_height), (hsize-margin_right, margin_top+box_height), 5) pygame.draw.line(screen, white, (margin_left, margin_top+box_height*2), (hsize-margin_right, margin_top+box_height*2), 5) pygame.draw.line(screen, white, (margin_left+box_width, margin_top), (margin_left+box_width, vsize-margin_bottom), 5) pygame.draw.line(screen, white, (hsize-margin_right-box_width, margin_top), (hsize-margin_right-box_width, vsize-margin_bottom), 5) title.add_text(screen) players_def1.add_button(screen) players_def2.add_button(screen) return screen
def save_new_subtopic(self): if self.selected_subtopic.cget('text') != self.new_subtopic_label_text: return self.subtopic_dialog = Toplevel(self.root) self.subtopic_dialog.title('New Note: Subtopic Input Dialog') headlab = LabelH3(self.subtopic_dialog, text='Unique subtopic name for new note:') self.subtopic_input = Entry(self.subtopic_dialog, width=64) self.subtopic_input.focus_set() buttonbox = Frame(self.subtopic_dialog) self.subtopic_dialog.grid_columnconfigure(0, weight=1) new_note_ok = Button(buttonbox, text='Submit Note and Subtitle', command=self.submit_new_note) new_note_cancel = Button(buttonbox, text='Cancel', command=self.close_subtopic_dialog) headlab.grid(column=0, row=0, pady=(24, 0), columnspan=2) self.subtopic_input.grid(column=0, row=1, padx=24, pady=24, columnspan=2) buttonbox.grid(column=1, row=2, sticky='we', padx=24, pady=24) new_note_ok.grid(column=0, row=0, sticky='e', padx=12) new_note_cancel.grid(column=1, row=0, sticky='e', padx=12) self.subtopic_dialog.bind('<Escape>', self.close_subtopic_dialog) self.subtopic_dialog.protocol('WM_DELETE_WINDOW', self.close_subtopic_dialog)
def __init__(self, display, list_of_turns, size): MainScreen.__init__(self, display) self.list_of_turns = list_of_turns self.current_step = 0 self.go_board = Board(size) self.size = size self.btn_prev = Button(lang.data["prev"], [150, 70], [700, 300]) self.btn_next = Button(lang.data["next"], [150, 70], [700, 400])
def __init__(self, display, size_of_board): MainScreen.__init__(self, display) self.go_board = Board(size_of_board) self.btn_pass = Button(lang.data["pass"], [170, 70], [690, 300]) self.btn_resign = Button(lang.data["resign"], [170, 70], [690, 425]) self.sound = pygame.mixer.Sound(os.path.join('sounds/gong.wav')) if sound: self.sound.play()
def first_screen(self): # Preenchendo background self.screen.fill(self.black) # Posição de referência self.first_screen_y = 200 self.first_screen_x = 150 # Desenhando "Escolha o oponente" self.screen.blit(self.font.render("Escolha o nÃvel", True, self.white), (self.first_screen_y + 40, self.first_screen_x - 50)) # Criando botões self.buttons.append( Button(self.first_screen_y, self.first_screen_x, H1())) self.buttons.append( Button(self.first_screen_y, self.first_screen_x + 50, H2())) self.buttons.append( Button(self.first_screen_y, self.first_screen_x + 100, KNN())) while True: # 30 FPS self.clock.tick(30) # Armazenando a posição do mouse self.mouse = pg.mouse.get_pos() self.screen.blit(self.images.load_piece(1), self.buttons[0].pos) self.screen.blit( self.font.render("H1", True, self.white), (self.buttons[0].pos[0] + 50, self.buttons[0].pos[1] + 7)) self.screen.blit(self.images.load_piece(2), self.buttons[1].pos) self.screen.blit( self.font.render("H2", True, self.white), (self.buttons[1].pos[0] + 50, self.buttons[1].pos[1] + 7)) self.screen.blit(self.images.load_piece(3), self.buttons[2].pos) self.screen.blit( self.font.render("KNN", True, self.white), (self.buttons[2].pos[0] + 50, self.buttons[2].pos[1] + 7)) # Desenhando os botões for button in self.buttons: button.verify(self.mouse) if button.rect.collidepoint(self.mouse): if pg.mouse.get_pressed()[0] == 1: #self.player2 = button.computer self.page = 2 return for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() exit(0) # Atualizando a tela pg.display.update()
def __init__(self, display): MainScreen.__init__(self, display) self.btn_sizes = [] self.btn_play_with_friend = Button(lang.data['play with friend'], [400, 100], [250, 160]) self.btn_play_online = Button(lang.data['play online'], [400, 100], [250, 290]) self.btn_watch_gotv = Button(lang.data['Go TV'], [400, 100], [250, 420])
def __init__(self, display, size_of_board, side, client): MainScreen.__init__(self, display) self.side = side self.client = client self.go_board = Board(size_of_board) self.btn_pass = Button(lang.data["pass"], [150, 70], [700, 300]) self.btn_resign = Button(lang.data["resign"], [150, 70], [700, 425]) self.show_err_msg = False self.request_for_pass = False
def __init__(self, parent=None): super().__init__(parent) self.screen_width, self.screen_height = get_screen_res(screen) self.screen_res: str = f'{self.screen_width}x{self.screen_height}' self.payload: Dict[str, str] = { 'sorting': 'random', 'categories': '100', 'atleast': self.screen_res } self.sw = StackedWidget() self.progressbar = ProgressBar() self.progressbar.hide() self.prev_btn = Button('angle-left.svg', key='left') self.next_btn = Button('angle-right.svg', key='right') self.update_btn = Button('sync-alt.svg', ' Update', key='r') self.apply_btn = Button('check.svg', 'Apply') self.save_btn = Button('save.svg', 'Save') self.prev_btn.clicked.connect(self.prev) self.next_btn.clicked.connect(self.next) self.apply_btn.clicked.connect(self.apply) self.update_btn.clicked.connect(self.update_) self.save_btn.clicked.connect(self.save) self.saved_msg = QLabel('Saved') self.image_count = QLabel() self.image_res = QLabel() self.saved_msg.setStyleSheet(f'color: {INFO_COLOR}') self.image_count.setStyleSheet(f'color: {INFO_COLOR}') self.image_res.setStyleSheet(f'color: {INFO_COLOR}') self.info_layout = QHBoxLayout() self.info_layout.addWidget(self.progressbar) self.info_layout.addStretch() self.info_layout.addWidget(self.image_count) self.info_layout.addWidget(self.image_res) button_layout = QHBoxLayout() button_layout.addWidget(self.prev_btn) button_layout.addWidget(self.next_btn) button_layout.addWidget(self.update_btn) button_layout.addWidget(self.apply_btn) button_layout.addWidget(self.save_btn) self.main_layout = QVBoxLayout() self.main_layout.addLayout(self.info_layout) self.main_layout.addWidget(self.sw) self.main_layout.addLayout(button_layout) self.setLayout(self.main_layout) self.sw.added.connect(self.change_image_count)
def __init__(self, w, h, gsm): self.width = w self.height = h self.gsm = gsm self.font = pygame.font.SysFont('Source Code Pro', 50) self.widgets = [ Button(self.width // 2, self.height // 2, 250, 75, 'Play', self.gsm.play), Button(self.width // 2, self.height // 2 + 100, 250, 75, 'Quit', self.gsm.stop), Text(self.width // 2, self.height // 3, 'Snake', (255, 255, 255)) ]
def __init__(self, w: int, h: int, gsm: GameStateManager) -> None: self.width = w self.height = h self.gsm = gsm self.font = pygame.font.SysFont('Source Code Pro', 50) self.widgets = [ Button(self.width // 2, self.height // 2, 250, 75, 'Resume', self.gsm.play), Button(self.width // 2, self.height // 2 + 100, 250, 75, 'Menu', self.gsm.menu), Text(self.width // 2, self.height // 3, 'Pause', (255, 255, 255)) ]
def show_board(screen, message, p1, p2): """ To show the board with current status. """ st1 = str(p1.wins) st2 = str(p2.wins) msg = Button(message, hsize//2 - 150, vsize-70, white, 48, fill_color) stat1 = Button(st1, hsize//2 - 300, margin_top-50, white, 48, fill_color) stat2 = Button(st2, hsize//2 +250, margin_top-50, white, 48, fill_color) msg.add_button(screen) stat1.add_button(screen) stat2.add_button(screen) return screen
def __init__(self, render_surface, surface_size): Screen.__init__(self, render_surface, surface_size) self.widgets = { "heading_menu": Heading(self.render_surface, (0, 0, 1920, 100), "Main menu").set_themed(), "button_play": Button(self.render_surface, (760, 450, 400, 100), "Play").set_themed(), "button_settings": Button(self.render_surface, (760, 600, 400, 100), "Settings").set_themed(), }
def __init__(self, display): MainScreen.__init__(self, display) self.btn_about_program = Button(lang.data["program"], [240, 50], [340, 270], 38) self.btn_rools = Button(lang.data["rools"], [240, 50], [340, 340], 38) self.btn_main_menu = Button(lang.data["main menu"], [240, 50], [340, 410], 38) self.tgl_music = Toggle([250, 130]) self.tgl_sound = Toggle([650, 130]) self.tgl_language = Toggle([420, 200]) if lang.current_language == 'russian': self.tgl_language.active = True if sound: self.tgl_sound.active = True
def __init__(self, master, command, *args, **kwargs): Frame.__init__(self, master, *args, **kwargs) self.ent = Entry(self, width=36) spacer = Label(self, width=3) ok_butt = Button(self, text='OK', command=command) cancel_butt = Button(self, text='CANCEL', command=self.remove_edit_row) spacer.grid(column=0, row=0) self.ent.grid(column=1, row=0, padx=3, pady=3) ok_butt.grid(column=2, row=0, padx=6, pady=6) cancel_butt.grid(column=3, row=0, padx=6, pady=6)
def open_error_message(parent, message, title, buttlab): def close(): error.destroy() error = Toplevel(parent) error.title(title) error.columnconfigure(0, weight=1) error.rowconfigure(0, weight=1) lab = Message(error, text=message, justify='left') lab.grid(column=0, row=0, sticky='news', padx=3, pady=3) button = Button(error, text=buttlab, command=close) button.grid(padx=3, pady=3) button.focus_set() # duplicate_places_with_duplicate_parents = ( # "There are too many levels of identically-named but different places " # "in the database. Use nicknames for all but one of the levels till more " # "code is written to handle this case.\n\n" # "Example: Two places named 'OK Ranch' existed somewhere and both " # "were in places called 'Pickens Township' but these were two " # "different townships. Due to two levels of duplicate nestings, " # "unique nicknames will have to be used for either the ranches " # "or the townships till code is written to handle this kind of duplex " # "duplication in nested places.")
def __init__(self, render_surface, surface_size): Screen.__init__(self, render_surface, surface_size) self.widgets = { "heading_kanjioptionsscreen": Heading(self.render_surface, (0, 0, 1920, 100), "Kanji Options").set_themed(), "button_back": Button(self.render_surface, (10, 10, 230, 80), "Back").set_themed(), } self.checkboxes = { "kanji_show_kun": Checkbox(self.render_surface, (600, 400, 720, 100), "Show 'kun' reading").set_themed(), "kanji_show_on": Checkbox(self.render_surface, (600, 550, 720, 100), "Show 'on' reading").set_themed(), "kanji_show_dutch": Checkbox(self.render_surface, (600, 700, 720, 100), "Show Dutch").set_themed(), } # set the 'selected' property of the checkboxes for checkbox_id, checkbox in self.checkboxes.items(): checkbox.selected = Settings.get(checkbox_id)
def setPlayerSelectionScreen(self): self.currentScreenInstance = self.playerScreen playerScreenBackButton = Button(50, 50, 50, 50, "<-", 40) playerScreenBackButton.setCallBack(self.setStartScreen) self.playerScreen.add(playerScreenBackButton) self.changeScreen(5)
def show_order(self, order, cta_title, cta_closure): widgets = [] widgets += [urwid.Divider()] # Order Items for item in order.menu_items: quantity = str(item.cart_quantity) columns = urwid.Columns([ ("fixed", 2, urwid.Text(quantity, align="right")), ("fixed", 1, urwid.Divider()), ("weight", 1, ColoredText(item.title, colors.ITEM_MEAL)), ]) widgets += [columns] # Driver name if order.driver_name: driver_name = "Driver's name: %s" % order.driver_name driver_phone = "Driver's phone: %s" % order.driver_phone_number if order.status == Order.STATUS_UNRATED: eta_tpl = "Delivered: %s" else: eta_tpl = "Estimated Time: %s" ETA = eta_tpl % pretty_date(order.customer_eta * 60) widgets += [urwid.Divider()] widgets += [ColoredText(driver_name, colors.LOW)] widgets += [ColoredText(driver_phone, colors.LOW)] widgets += [ColoredText(ETA, colors.LOW)] # Address address = [(colors.DELIVER_LABEL, "Delivering to ")] address += [(colors.DELIVER_ADDRESS, order.address.street_address)] widgets += [urwid.Divider()] widgets += [urwid.Text(address)] # Track driver button cta = Button(cta_title, cta_closure) if order.driver_location and cta: columns = urwid.Columns([ ("weight", 0.2, urwid.Divider()), ("weight", 0.6, cta), ("weight", 0.2, urwid.Divider()), ]) widgets += [urwid.Divider()] widgets += [columns] else: widgets += [urwid.Divider()] widgets += [urwid.Text("Waiting for driver...", align="center")] pile = urwid.Pile(widgets) pile = urwid.Padding(pile, left=2, right=2) pile = urwid.Columns([ ("weight", 0.2, urwid.Divider()), ("weight", 0.6, ColoredLineBox(pile, title="Food on your way!")), ("weight", 0.2, urwid.Divider()), ]) self.body = pile
def __init__(self, display): MainScreen.__init__(self, display) self.btn_main_menu = Button(lang.data["main menu"], [ 240, 50], [340, 530], 38) self.slider = Slider() image_rool = pygame.image.load(os.path.join('images/rools.png')) self.image_rool = pygame.transform.scale( image_rool, (800, image_rool.get_height() * 800 // image_rool.get_width()))
def createCloseButton(self, parent): """ Create a button for closing the window, setting the proper label and icon. """ return Button(parent, Message.LABEL_BUTTON_CLOSE, Icon.ACTION_CLOSE, command=self.close)
def _init_choice_buttons(self): self.button_frame = RelativeWidget(parent = self.window, left = 0, right = 0, top=0, height = 50) increment = 1 / len(self.button_text) for index, t in enumerate(self.button_text): left = index * increment right = 1 - left - increment button_holder = RelativeWidget(parent = self.button_frame, left = left, right = right, top=0, bottom=0) button = Button(parent=button_holder, text=t, text_padding = 3) button.push_handlers(on_press = self._button_cb)
def _fillButtonsFrame(self, frame): """ Add button to the bottom frame if the selectMode is distinct from SELECT_NONE. """ Button(frame, "Close", Icon.BUTTON_CLOSE, command=self._close).grid(row=0, column=0, padx=(0,5)) if self.selectButton: HotButton(frame, self.selectButton, Icon.BUTTON_SELECT, command=self._select).grid(row=0, column=1)
def set_order_visible(self, visible, scheduled=False): text = "Order when ready" if scheduled else "Order" size = len(text) + 4 columns = urwid.Columns([("weight", 1, urwid.Divider()), ("fixed", size, Button(text, "order", scheduled, self))]) row = columns if visible else urwid.Divider() self.body[1].contents[-1] = row, ("weight", 1)
def __init__(self, experiment): SceneBase.__init__(self) # data to keep track of the experiment's progress self.experiment = experiment self.experiment_running = False self.total = experiment.iterations # constants defining where stuff can be drawn self.MARGIN = 96 self.TITLE_SIZE = 56 self.LABEL_SIZE = 48 self.INFO_BOX = pygame.Rect(self.MARGIN, self.MARGIN * 1.5, 1920 - self.MARGIN * 2, 1080 * 0.66 - 2 * self.MARGIN) self.PROGRESS_BAR_WIDTH = 1920 - 2 * self.MARGIN self.PROGRESS_BAR_HEIGHT = 100 self.PROGRESS_BAR_X = self.MARGIN self.PROGRESS_BAR_Y = self.INFO_BOX.y + self.INFO_BOX.height + 0.5 * self.PROGRESS_BAR_HEIGHT self.PROGRESS_BORDER = pygame.Rect(self.PROGRESS_BAR_X, self.PROGRESS_BAR_Y, self.PROGRESS_BAR_WIDTH, self.PROGRESS_BAR_HEIGHT) self.PROGRESS_BG = pygame.Rect(self.PROGRESS_BAR_X + 4, self.PROGRESS_BAR_Y + 4, self.PROGRESS_BAR_WIDTH - 8, self.PROGRESS_BAR_HEIGHT - 8) self.title_font = FontService.get_regular_font(self.TITLE_SIZE) self.label_font = FontService.get_regular_font(self.LABEL_SIZE) font_color = Settings.theme['font'] self.heading_surface = self.title_font.render( "%s vs %s" % (self.experiment.p1.name, self.experiment.p2.name), False, font_color) self.heading_size = self.title_font.size( "%s vs %s" % (self.experiment.p1.name, self.experiment.p2.name)) self.heading_location = (self.INFO_BOX.centerx - 0.5 * self.heading_size[0], self.INFO_BOX.top - 1.5 * self.heading_size[1]) self.insertion_msg_surface = self.label_font.render( "Saving results... (This may take some time)", False, font_color) self.insertion_msg_size = self.title_font.size( "Saving results... (This may take some time)") self.insertion_msg_location = (self.INFO_BOX.centerx - 0.5 * self.insertion_msg_size[0], self.PROGRESS_BG.bottom + 12) # "Done" button def back_to_mm(): SceneManager.go_to_main_menu(self) self.done_btn = Button(1920 * 0.5 - 150, self.PROGRESS_BG.bottom + 24, 300, 100, "Done", back_to_mm)
def set_dialog_buttons(self): self.button_box = HPanel(self.box) self.box.pack(self.button_box, fill=True, padding_all=self.button_box_padding) self.button_box.pack(HPanel(self.button_box), fill=True, expand=True) self.cancel_btn = Button(self.button_box, '', onclick=self.on_cancel, default=True, pid=const.BUTTON_CANCEL) self.cancel_btn.set_enable(False) self.button_box.pack(self.cancel_btn) self.fit()
def context_help(self): help = Toplevel() help.title(self.help_title) text = LabelStylable(help, width=75) text.grid(padx=24, pady=24) text.insert('end', self.message) off = Button(help, text='Done', command=help.destroy) off.grid(padx=24, pady=24, sticky='e') config_generic(help) off.focus_set()
def __init__(self, w, h, gsm): self.width = w self.height = h self.gsm = gsm self.widgets = [ Button(self.width // 2, self.height // 2, 250, 75, 'Menu', self.gsm.menu), Text(self.width // 2, self.height // 3, 'You Won!', (255, 255, 255)) ]
def __init__(self, display, mode): MainScreen.__init__(self, display) sizes = [5, 6, 7, 8, 9, 11, 13, 15, 19] self.btn_sizes = [] for i in range(len(sizes)): self.btn_sizes.append( Button('%dx%d' % (sizes[i], sizes[i]), [120, 120], [150 * (i % 3) + 200, 150 * (i // 3) + 100])) self.show = True self.mode = mode