예제 #1
0
 def test_set_text(self, _init_pygame, default_ui_manager,
                   _display_surface_return_none):
     label = UILabel(relative_rect=pygame.Rect(100, 100, 150, 30),
                     text="Test Label",
                     manager=default_ui_manager)
     label.set_text("new text")
     assert label.image is not None
class EverythingWindow(UIWindow):
    def __init__(self, rect, ui_manager):

        element_ids = ['everything_window']

        super().__init__(rect, ui_manager, element_ids=element_ids)

        # create shadow
        shadow_padding = (2, 2)

        self.image = self.ui_manager.get_shadow(self.rect.size)
        self.image.fill(self.ui_manager.get_theme().get_colour(self.object_ids, self.element_ids, 'dark_bg'),
                        pygame.Rect(shadow_padding,
                                    (self.rect.width - shadow_padding[0] * 2,
                                     self.rect.height - shadow_padding[1] * 2)
                                    ))

        self.get_container().relative_rect.width = self.rect.width - shadow_padding[0] * 2
        self.get_container().relative_rect.height = self.rect.height - shadow_padding[1] * 2
        self.get_container().relative_rect.x = self.get_container().relative_rect.x + shadow_padding[0]
        self.get_container().relative_rect.y = self.get_container().relative_rect.y + shadow_padding[1]
        self.get_container().update_containing_rect_position()

        self.close_window_button = UIButton(relative_rect=pygame.Rect((self.get_container().rect.width-20, 0),
                                                                      (20, 20)),
                                            text='╳',
                                            manager=ui_manager,
                                            container=self.get_container(),
                                            parent_element=self
                                            )
        self.menu_bar = UIButton(relative_rect=pygame.Rect((0, 0),
                                                           (self.get_container().rect.width-20, 20)),
                                 text='Everything Container',
                                 manager=ui_manager,
                                 container=self.get_container(),
                                 parent_element=self,
                                 object_id='#message_window_title_bar'
                                 )
        self.menu_bar.set_hold_range((100, 100))

        self.grabbed_window = False
        self.starting_grab_difference = (0, 0)

        self.test_slider = UIHorizontalSlider(pygame.Rect((int(self.rect.width / 2),
                                                           int(self.rect.height * 0.70)),
                                                          (240, 25)),
                                              50.0,
                                              (0.0, 100.0),
                                              self.ui_manager,
                                              container=self.get_container(),
                                              parent_element=self)

        self.slider_label = UILabel(pygame.Rect((int(self.rect.width / 2) + 250,
                                                 int(self.rect.height * 0.70)),
                                                (27, 25)),
                                    str(int(self.test_slider.get_current_value())),
                                    self.ui_manager,
                                    container=self.get_container(),
                                    parent_element=self)

        self.test_text_entry = UITextEntryLine(pygame.Rect((int(self.rect.width / 2),
                                                            int(self.rect.height * 0.50)),
                                                           (200, -1)),
                                               self.ui_manager,
                                               container=self.get_container(),
                                               parent_element=self)
        self.test_text_entry.set_forbidden_characters('numbers')

        current_resolution_string = 'Item 1'
        self.test_drop_down_menu = UIDropDownMenu(['Item 1',
                                                   'Item 2',
                                                   'Item 3',
                                                   'Item 4',
                                                   'Item 5',
                                                   'Item 6'],
                                                  current_resolution_string,
                                                  pygame.Rect((int(self.rect.width / 2),
                                                               int(self.rect.height * 0.3)),
                                                              (200, 25)),
                                                  self.ui_manager,
                                                  container=self.get_container(),
                                                  parent_element=self)

        self.health_bar = UIScreenSpaceHealthBar(pygame.Rect((int(self.rect.width / 9),
                                                              int(self.rect.height * 0.7)),
                                                             (200, 20)),
                                                 self.ui_manager,
                                                 container=self.get_container(),
                                                 parent_element=self)

        loaded_test_image = pygame.image.load('data/images/splat.png').convert_alpha()

        self.test_image = UIImage(pygame.Rect((int(self.rect.width / 9),
                                               int(self.rect.height * 0.3)),
                                              loaded_test_image.get_rect().size),
                                  loaded_test_image, self.ui_manager,
                                  container=self.get_container(),
                                  parent_element=self)
        self.is_selected = False

    def select(self):
        self.is_selected = True

    def unselect(self):
        self.is_selected = False

    def process_event(self, event):
        processed_event = False
        if self.is_selected:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:
                    self.test_slider.set_current_value(50)

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                mouse_x, mouse_y = event.pos
                if self.rect.collidepoint(mouse_x, mouse_y):
                    processed_event = True
                    self.window_stack.move_window_to_front(self)

        return processed_event

    def update(self, time_delta):
        if self.alive():
            if self.test_slider.has_moved_recently:
                self.slider_label.set_text(str(int(self.test_slider.get_current_value())))

            if self.menu_bar.held:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                if not self.grabbed_window:
                    self.window_stack.move_window_to_front(self)
                    self.grabbed_window = True
                    self.starting_grab_difference = (mouse_x - self.rect.x,
                                                     mouse_y - self.rect.y)

                current_grab_difference = (mouse_x - self.rect.x,
                                           mouse_y - self.rect.y)

                adjustment_required = (current_grab_difference[0] - self.starting_grab_difference[0],
                                       current_grab_difference[1] - self.starting_grab_difference[1])

                self.rect.x += adjustment_required[0]
                self.rect.y += adjustment_required[1]
                self.get_container().relative_rect.x += adjustment_required[0]
                self.get_container().relative_rect.y += adjustment_required[1]
                self.get_container().update_containing_rect_position()

            else:
                self.grabbed_window = False

            if self.close_window_button.check_pressed():
                self.kill()

        super().update(time_delta)
예제 #3
0
파일: task9.py 프로젝트: 9kin/yandex_api
                    map_type = "sat"
                elif event.text == "гибрид":
                    map_type = "skl"
                res = render_map(ll, map_type, z=ZOOM)
                if not res:
                    map_type = old_map_type

            if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                if event.ui_element == search_button:
                    try:
                        json = geocoder_request(text_entry.text)
                        ll, _ = get_ll_spn(json)
                        pt = ll.copy()
                        render_map(ll, map_type, z=ZOOM)
                        try:
                            label.set_text(
                                full_adress(json) + get_postal_code(json))
                        except:
                            label.set_text(full_adress(json))
                    except:
                        pass
                if event.ui_element == cancel_button:
                    pt = None
                    render_map(ll, map_type, z=ZOOM)
                if event.ui_element == postal_button:
                    json = geocoder_request(to_ll(ll))
                    if postal_button.text == "wiew postal code":
                        label.set_text(
                            full_adress(json) + get_postal_code(json))
                        postal_button.set_text("don't wiew postal code")
                    elif postal_button.text == "don't wiew postal code":
                        label.set_text(full_adress(json))
예제 #4
0
파일: task8.py 프로젝트: 9kin/yandex_api
                    map_type = "sat"
                elif event.text == "гибрид":
                    map_type = "skl"
                res = render_map(ll, map_type, z=ZOOM)
                if not res:
                    map_type = old_map_type

            if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                if event.ui_element == search_button:
                    try:

                        json = geocoder_request(text_entry.text)
                        ll, _ = get_ll_spn(json)
                        pt = ll.copy()
                        render_map(ll, map_type, z=ZOOM)
                        label.set_text(full_adress(json))
                    except:
                        pass
                if event.ui_element == cancel_button:
                    pt = None
                    render_map(ll, map_type, z=ZOOM)

        if event.type == pygame.QUIT:
            run = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_PAGEUP:
                if render_map(ll, map_type, z=ZOOM + 1):
                    ZOOM += 1
            elif event.key == pygame.K_PAGEDOWN:
                if render_map(ll, map_type, z=ZOOM - 1):
                    ZOOM -= 1