def _process_mini_file_operation_button_events(self, event): """ Handle what happens when you press one of the tiny file/folder operation buttons. :param event: event to check. """ if event.type == UI_BUTTON_PRESSED and event.ui_element == self.delete_button: confirmation_rect = pygame.Rect(0, 0, 300, 200) confirmation_rect.center = self.rect.center selected_file_name = self.current_file_path.name long_desc = translate("pygame-gui.Delete_filename", file_name=str(selected_file_name)) self.delete_confirmation_dialog = UIConfirmationDialog( rect=confirmation_rect, manager=self.ui_manager, action_long_desc=long_desc, action_short_name='pygame-gui.Delete', window_title='pygame-gui.Delete') if event.type == UI_BUTTON_PRESSED and event.ui_element == self.parent_directory_button: self._change_directory_path( Path(self.current_directory_path).parent) if event.type == UI_BUTTON_PRESSED and event.ui_element == self.refresh_button: self._change_directory_path(Path(self.current_directory_path)) if event.type == UI_BUTTON_PRESSED and event.ui_element == self.home_button: self._change_directory_path(Path.home())
def on_locale_changed(self): font = self.ui_theme.get_font(self.combined_element_ids) if font != self.font: self.font = font self.rebuild() else: if self.drawable_shape is not None: self.drawable_shape.set_text(translate(self.text))
def set_text(self, text: str): """ Sets the text on the button. The button will rebuild. :param text: The new text to set. """ if text != self.text: self.text = text if self.dynamic_width: self.rebuild() else: self.drawable_shape.set_text(translate(self.text))
def parse_html_into_style_data(self): """ Parses HTML styled string text into a format more useful for styling pygame.freetype rendered text. """ self.parser.feed(translate(self.html_text) + self.appended_text) self.text_box_layout = TextBoxLayout( self.parser.layout_rect_queue, pygame.Rect((0, 0), (self.text_wrap_rect[2], self.text_wrap_rect[3])), pygame.Rect((0, 0), (self.text_wrap_rect[2], self.text_wrap_rect[3])), line_spacing=1.25) self.parser.empty_layout_queue() if self.text_wrap_rect[3] == -1: self.text_box_layout.view_rect.height = self.text_box_layout.layout_rect.height self._align_all_text_rows() self.text_box_layout.finalise_to_new()
def rebuild(self): """ A complete rebuild of the drawable shape used by this button. """ self.rect.width = -1 if self.dynamic_width else self.rect.width self.relative_rect.width = -1 if self.dynamic_width else self.relative_rect.width self.rect.height = -1 if self.dynamic_height else self.rect.height self.relative_rect.height = -1 if self.dynamic_height else self.relative_rect.height theming_parameters = { 'normal_bg': self.colours['normal_bg'], 'normal_text': self.colours['normal_text'], 'normal_text_shadow': self.colours['normal_text_shadow'], 'normal_border': self.colours['normal_border'], 'normal_image': self.normal_image, 'hovered_bg': self.colours['hovered_bg'], 'hovered_text': self.colours['hovered_text'], 'hovered_text_shadow': self.colours['hovered_text_shadow'], 'hovered_border': self.colours['hovered_border'], 'hovered_image': self.hovered_image, 'disabled_bg': self.colours['disabled_bg'], 'disabled_text': self.colours['disabled_text'], 'disabled_text_shadow': self.colours['disabled_text_shadow'], 'disabled_border': self.colours['disabled_border'], 'disabled_image': self.disabled_image, 'selected_bg': self.colours['selected_bg'], 'selected_text': self.colours['selected_text'], 'selected_text_shadow': self.colours['selected_text_shadow'], 'selected_border': self.colours['selected_border'], 'selected_image': self.selected_image, 'active_bg': self.colours['active_bg'], 'active_border': self.colours['active_border'], 'active_text': self.colours['active_text'], 'active_text_shadow': self.colours['active_text_shadow'], 'active_image': self.selected_image, 'border_width': self.border_width, 'shadow_width': self.shadow_width, 'font': self.font, 'text': translate(self.text), 'text_shadow': (self.text_shadow_size, self.text_shadow_offset[0], self.text_shadow_offset[1], self.colours['normal_text_shadow'], True), 'text_horiz_alignment': self.text_horiz_alignment, 'text_vert_alignment': self.text_vert_alignment, 'text_horiz_alignment_padding': self.text_horiz_alignment_padding, 'text_horiz_alignment_method': self.text_horiz_alignment_method, 'text_vert_alignment_padding': self.text_vert_alignment_padding, 'shape_corner_radius': self.shape_corner_radius, 'transitions': self.state_transitions } if self.shape == 'rectangle': self.drawable_shape = RectDrawableShape( self.rect, theming_parameters, ['normal', 'hovered', 'disabled', 'selected', 'active'], self.ui_manager) elif self.shape == 'ellipse': self.drawable_shape = EllipseDrawableShape( self.rect, theming_parameters, ['normal', 'hovered', 'disabled', 'selected', 'active'], self.ui_manager) elif self.shape == 'rounded_rectangle': self.drawable_shape = RoundedRectangleShape( self.rect, theming_parameters, ['normal', 'hovered', 'disabled', 'selected', 'active'], self.ui_manager) self.on_fresh_drawable_shape_ready() if self.relative_rect.width == -1 or self.relative_rect.height == -1: self.dynamic_width = self.relative_rect.width == -1 self.dynamic_height = self.relative_rect.height == -1 self.set_dimensions(self.image.get_size()) # if we have anchored the left side of our button to the right of it's container then # changing the width is going to mess up the horiz position as well. new_left = self.relative_rect.left new_top = self.relative_rect.top if self.anchors['left'] == 'right' and self.dynamic_width: left_offset = self.dynamic_dimensions_orig_top_left[0] new_left = left_offset - self.relative_rect.width # if we have anchored the top side of our button to the bottom of it's container then # changing the height is going to mess up the vert position as well. if self.anchors['top'] == 'bottom' and self.dynamic_height: top_offset = self.dynamic_dimensions_orig_top_left[1] new_top = top_offset - self.relative_rect.height self.set_relative_position((new_left, new_top))