def update(self, surface): if pygame.mouse.get_pressed()[0]: pos = pygame.mouse.get_pos() if self.bounds.collidepoint(pos): self.mode = (self.mode + 1) % 5 if self.mode == 1: self.mode += 1 self.value = 1 self.prev = 0 self.color = (0, 0, 0) if self.mode == 3: self.prev = 1 if pygame.mouse.get_pressed()[2]: pos = pygame.mouse.get_pos() if self.bounds.collidepoint(pos) and self.mode > 1: if self.mode == 2: txtbx = InputBox(self.x + 30, self.y + 30, pygame.font.SysFont("Arial", 20), 6, str(self.value), 'Resistance', 'mOm') if self.mode == 4: txtbx = InputBox(self.x + 30, self.y + 30, pygame.font.SysFont("Arial", 20), 6, str(self.value), 'Inductance', 'H') if self.mode == 3: txtbx = InputBox(self.x + 30, self.y + 30, pygame.font.SysFont("Arial", 20), 6, str(self.value), 'Capacity', 'F') while 1: events = pygame.event.get() pygame.draw.rect(surface, (255, 255, 255), (self.x + 30, self.y + 30, 300, 50), 0) pygame.draw.rect(surface, (0, 0, 0), (self.x + 30, self.y + 30, 300, 50), 2) ans = txtbx.update(events) if ans is not None: self.value = int(ans) break txtbx.draw(surface) pygame.display.flip()
def main(): clock = pg.time.Clock() input_box1 = InputBox(100, 100, 140, 32) done = False while not done: for event in pg.event.get(): if event.type == pg.QUIT: done = True input_box1.handle_event(event) screen.fill((30, 30, 30)) input_box1.draw(screen) input_box1.update() pg.display.flip() clock.tick(30)
def main(): pygame.init() screen = pygame.display.set_mode((600, 450)) screen.fill(pygame.Color('white')) mp = MapParams() input_box = InputBox(50, 10, 140, 32) im = Image.open('data/search_icon.png') im = im.resize((30, 30)) im.save('data/search_icon.png') button = pygame.image.load('data/search_icon.png').convert_alpha() b_rect = pygame.Rect(10, 10, 50, 50) reset = Button('Сброс поискового результата', 350, 10, 24) while True: event = pygame.event.wait() if event.type == pygame.QUIT: # Выход из программы break elif event.type == pygame.KEYUP: # Обрабатываем различные нажатые клавиши. mp.update(event) elif event.type == pygame.MOUSEBUTTONUP: # Выполняем поиск по клику мышки. if event.button == 1: # LEFT_MOUSE_BUTTON mp.add_reverse_toponym_search(event.pos) if b_rect.collidepoint(event.pos): text = input_box.text toponym = reverse_geocode(text) if toponym: point = toponym['Point']['pos'].split() mp.lon = float(point[0]) mp.lat = float(point[1]) mp.search_result = SearchResult( point, toponym["metaDataProperty"] ["GeocoderMetaData"]["text"] if toponym else None, toponym["metaDataProperty"]["GeocoderMetaData"] ["Address"].get("postal_code") if toponym else None) else: input_box.text = 'Ничего не найдено' if reset.rect.collidepoint(event.pos): mp.search_result = None elif event.button == 3: # RIGHT_MOUSE_BUTTON mp.add_reverse_org_search(event.pos) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN and input_box.active: text = input_box.text toponym = reverse_geocode(text) if toponym: point = toponym['Point']['pos'].split() mp.lon = float(point[0]) mp.lat = float(point[1]) mp.search_result = SearchResult( point, toponym["metaDataProperty"]["GeocoderMetaData"]["text"] if toponym else None, toponym["metaDataProperty"]["GeocoderMetaData"] ["Address"].get("postal_code") if toponym else None) else: input_box.text = 'Ничего не найдено' map_file = load_map(mp) screen.blit(pygame.image.load(map_file), (0, 0)) if mp.search_result: if mp.use_postal_code and mp.search_result.postal_code: text = render_text(mp.search_result.postal_code + ", " + mp.search_result.address) else: text = render_text(mp.search_result.address) screen.blit(text, (20, 400)) input_box.handle_event(event) input_box.update() input_box.draw(screen) screen.blit(button, b_rect) reset.draw(screen) screen.blit(screen, (0, 0)) pygame.display.flip() pygame.quit() os.remove(map_file)
screen.blit(title_display, (title_pos_x, title_pos_y)) banner_rect.x = math.ceil( (screen.get_width() - banner.get_width()) / 2) banner_rect.y = math.ceil((screen.get_height() - title_pos_y - text_height - banner.get_height()) / 2) screen.blit(play_button, (play_button_rect)) play_button_rect.x = math.ceil( (screen.get_width() - play_button.get_width()) / 2) play_button_rect.y = screen.get_height() - math.ceil( screen.get_height() - box.rect.y - box.rect.h - play_button.get_height() / 2) if seconds % 2 == 0: screen.blit( input_info, (width / 2 - input_info.get_width() / 2, height / 4 * 2.35)) box.update() box.draw(screen) if box.is_error: box.error_surface = FONT.render(box.error, True, (255, 255, 255)) else: box.error_surface = FONT.render(box.error, True, (0, 0, 0)) game.name_player = box.text.strip() screen.blit(box.error_surface, (math.ceil( (screen.get_width() - box.error_surface.get_width()) / 2), box.rect.y + box.rect.h + math.ceil( (play_button_rect.y - (box.rect.y + box.rect.h) - 32) / 2))) pygame.display.flip() # si le on ferme la fenetre for event in pygame.event.get():