diff --git a/pygame_gui/core/drawable_shapes/drawable_shape.py b/pygame_gui/core/drawable_shapes/drawable_shape.py index 4bdc17f9..722183cd 100644 --- a/pygame_gui/core/drawable_shapes/drawable_shape.py +++ b/pygame_gui/core/drawable_shapes/drawable_shape.py @@ -344,14 +344,14 @@ def full_rebuild_on_size_change(self): self.should_trigger_full_rebuild = False self.full_rebuild_countdown = self.time_until_full_rebuild_after_changing_size - def redraw_all_states(self): + def redraw_all_states(self, force_full_redraw: bool = False): """ Starts the redrawing process for all states of this shape that auto pre-generate. Redrawing is done one state at a time so will take a few loops of the game to complete if this shape has many states. """ self.states_to_redraw_queue = deque([state_id for state_id, state in self.states.items() - if state.should_auto_pregen]) + if (state.should_auto_pregen or force_full_redraw)]) initial_state = self.states_to_redraw_queue.popleft() self.redraw_state(initial_state) @@ -595,7 +595,10 @@ def set_text(self, text: str): """ self.theming['text'] = text self.build_text_layout() - self.redraw_all_states() + if 'disabled' in self.states and self.active_state == self.states['disabled']: + self.redraw_all_states(force_full_redraw=True) + else: + self.redraw_all_states() def set_text_alpha(self, alpha: int): """ diff --git a/pygame_gui/core/drawable_shapes/ellipse_drawable_shape.py b/pygame_gui/core/drawable_shapes/ellipse_drawable_shape.py index 1b2b2c68..0107ec93 100644 --- a/pygame_gui/core/drawable_shapes/ellipse_drawable_shape.py +++ b/pygame_gui/core/drawable_shapes/ellipse_drawable_shape.py @@ -82,7 +82,10 @@ def full_rebuild_on_size_change(self): self.border_width + self.shadow_width), (self.click_area_shape.width - (2 * self.border_width), self.click_area_shape.height - (2 * self.border_width))) - self.redraw_all_states() + if 'disabled' in self.states and self.active_state == self.states['disabled']: + self.redraw_all_states(force_full_redraw=True) + else: + self.redraw_all_states() def collide_point(self, point: Union[pygame.math.Vector2, Tuple[int, int], diff --git a/pygame_gui/core/drawable_shapes/rect_drawable_shape.py b/pygame_gui/core/drawable_shapes/rect_drawable_shape.py index 41398e63..3b51e94b 100644 --- a/pygame_gui/core/drawable_shapes/rect_drawable_shape.py +++ b/pygame_gui/core/drawable_shapes/rect_drawable_shape.py @@ -92,7 +92,10 @@ def full_rebuild_on_size_change(self): self.border_width + self.shadow_width), (self.click_area_shape.width - (2 * self.border_width), self.click_area_shape.height - (2 * self.border_width))) - self.redraw_all_states() + if 'disabled' in self.states and self.active_state == self.states['disabled']: + self.redraw_all_states(force_full_redraw=True) + else: + self.redraw_all_states() def collide_point(self, point: Union[pygame.math.Vector2, Tuple[int, int], diff --git a/pygame_gui/core/drawable_shapes/rounded_rect_drawable_shape.py b/pygame_gui/core/drawable_shapes/rounded_rect_drawable_shape.py index 3c584ae0..8085b4aa 100644 --- a/pygame_gui/core/drawable_shapes/rounded_rect_drawable_shape.py +++ b/pygame_gui/core/drawable_shapes/rounded_rect_drawable_shape.py @@ -150,7 +150,10 @@ def full_rebuild_on_size_change(self): self.border_width + self.shadow_width), (self.click_area_shape.width - (2 * self.border_width), self.click_area_shape.height - (2 * self.border_width))) - self.redraw_all_states() + if 'disabled' in self.states and self.active_state == self.states['disabled']: + self.redraw_all_states(force_full_redraw=True) + else: + self.redraw_all_states() def collide_point(self, point: Union[pygame.math.Vector2, Tuple[int, int], diff --git a/pygame_gui/core/ui_container.py b/pygame_gui/core/ui_container.py index c43a5492..f0d1cad2 100644 --- a/pygame_gui/core/ui_container.py +++ b/pygame_gui/core/ui_container.py @@ -93,6 +93,11 @@ def add_element(self, element: IUIElementInterface): element.change_layer(self._layer + element.get_starting_height()) self.elements.append(element) self.calc_add_element_changes_thickness(element) + if not self.is_enabled: + element.disable() + if not self.visible: + if hasattr(element, 'hide'): + element.hide() def remove_element(self, element: IUIElementInterface): """ diff --git a/pygame_gui/core/ui_element.py b/pygame_gui/core/ui_element.py index 6ba9eaef..cf01eb9f 100644 --- a/pygame_gui/core/ui_element.py +++ b/pygame_gui/core/ui_element.py @@ -148,6 +148,8 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[int, int, int, int]], self.border_width = None # type: Union[None, int] self.shape_corner_radius = None # type: Union[None, int] + self.tool_tip = None + self._setup_container(container) self.dirty = 1 diff --git a/pygame_gui/elements/ui_button.py b/pygame_gui/elements/ui_button.py index bc46661e..1659ec1d 100644 --- a/pygame_gui/elements/ui_button.py +++ b/pygame_gui/elements/ui_button.py @@ -89,7 +89,6 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[float, float], pygame self.tool_tip_text_kwargs = {} if tool_tip_text_kwargs is not None: self.tool_tip_text_kwargs = tool_tip_text_kwargs - self.tool_tip = None self.tool_tip_object_id = tool_tip_object_id self.ui_root_container = self.ui_manager.get_root_container() @@ -282,7 +281,8 @@ def on_unhovered(self): Called when we leave the hover state. Resets the colours and images to normal and kills any tooltip that was created while we were hovering the button. """ - self.drawable_shape.set_active_state(self._get_appropriate_state_name()) + if self.drawable_shape is not None: + self.drawable_shape.set_active_state(self._get_appropriate_state_name()) if self.tool_tip is not None: self.tool_tip.kill() self.tool_tip = None @@ -430,7 +430,8 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.drawable_shape.set_active_state('disabled') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('disabled') # clear other button state self.held = False @@ -444,7 +445,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.drawable_shape.set_active_state('normal') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('normal') def _set_active(self): """ @@ -768,6 +770,10 @@ def rebuild(self): ['normal', 'hovered', 'disabled', 'selected', 'active'], self.ui_manager) + if not self.is_enabled: + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('disabled') + self.on_fresh_drawable_shape_ready() self._on_contents_changed() diff --git a/pygame_gui/elements/ui_drop_down_menu.py b/pygame_gui/elements/ui_drop_down_menu.py index 9ad8314b..c30bd480 100644 --- a/pygame_gui/elements/ui_drop_down_menu.py +++ b/pygame_gui/elements/ui_drop_down_menu.py @@ -418,19 +418,23 @@ def disable(self): """ Disables the closed state so that it is no longer interactive. """ - self.selected_option_button.disable() + if self.selected_option_button is not None: + self.selected_option_button.disable() if self.open_button is not None: self.open_button.disable() - self.drop_down_menu_ui.drawable_shape.set_active_state('disabled') + if self.drop_down_menu_ui.drawable_shape is not None: + self.drop_down_menu_ui.drawable_shape.set_active_state('disabled') def enable(self): """ Re-enables the closed state so we can once again interact with it. """ - self.selected_option_button.enable() + if self.selected_option_button is not None: + self.selected_option_button.enable() if self.open_button is not None: self.open_button.enable() - self.drop_down_menu_ui.drawable_shape.set_active_state('normal') + if self.drop_down_menu_ui.drawable_shape is not None: + self.drop_down_menu_ui.drawable_shape.set_active_state('normal') def rebuild(self): """ @@ -916,12 +920,15 @@ def set_relative_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Sets the dimensions of this drop down, updating all subordinate button elements at the same time. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ super().set_dimensions(dimensions) @@ -941,12 +948,13 @@ def disable(self): if self.is_enabled: self.is_enabled = False # switch back to the closed state if we are in the expanded state - if self.current_state is self.menu_states['expanded']: - self.current_state.finish() - self.current_state = self.menu_states['closed'] - self.current_state.selected_option = self.selected_option - self.current_state.start() - self.current_state.disable() + if self.current_state is not None: + if self.current_state is self.menu_states['expanded']: + self.current_state.finish() + self.current_state = self.menu_states['closed'] + self.current_state.selected_option = self.selected_option + self.current_state.start() + self.current_state.disable() def enable(self): """ @@ -954,7 +962,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.current_state.enable() + if self.current_state is not None: + self.current_state.enable() def show(self): """ diff --git a/pygame_gui/elements/ui_horizontal_scroll_bar.py b/pygame_gui/elements/ui_horizontal_scroll_bar.py index 57a1675b..9978f80f 100644 --- a/pygame_gui/elements/ui_horizontal_scroll_bar.py +++ b/pygame_gui/elements/ui_horizontal_scroll_bar.py @@ -39,6 +39,10 @@ def __init__(self, anchors: Optional[Dict[str, Union[str, UIElement]]] = None, visible: int = 1): + # Need to move some declarations early as they are indirectly referenced via the ui element + # constructor + self.button_container = None + super().__init__(relative_rect, manager, container, layer_thickness=2, starting_height=1, @@ -509,11 +513,14 @@ def set_relative_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Method to directly set the dimensions of an element. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ super().set_dimensions(dimensions) @@ -547,9 +554,11 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.button_container.disable() + if self.button_container is not None: + self.button_container.disable() - self.drawable_shape.set_active_state('disabled') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('disabled') def enable(self): """ @@ -557,9 +566,11 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.button_container.enable() + if self.button_container is not None: + self.button_container.enable() - self.drawable_shape.set_active_state('normal') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('normal') def show(self): """ @@ -576,5 +587,5 @@ def hide(self): will propagate and hide all the buttons. """ super().hide() - - self.button_container.hide() + if self.button_container is not None: + self.button_container.hide() diff --git a/pygame_gui/elements/ui_horizontal_slider.py b/pygame_gui/elements/ui_horizontal_slider.py index c8ec8177..482607f3 100644 --- a/pygame_gui/elements/ui_horizontal_slider.py +++ b/pygame_gui/elements/ui_horizontal_slider.py @@ -45,6 +45,8 @@ def __init__(self, click_increment: Union[float, int] = 1 ): + self.sliding_button = None + self.button_container = None super().__init__(relative_rect, manager, container, layer_thickness=2, starting_height=1, @@ -491,11 +493,14 @@ def set_relative_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Method to directly set the dimensions of an element. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ super().set_dimensions(dimensions) @@ -525,12 +530,14 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.sliding_button.disable() + if self.sliding_button is not None: + self.sliding_button.disable() if self.left_button: self.left_button.disable() if self.right_button: self.right_button.disable() - self.drawable_shape.set_active_state('disabled') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('disabled') def enable(self): """ @@ -538,12 +545,14 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.sliding_button.enable() + if self.sliding_button is not None: + self.sliding_button.enable() if self.left_button: self.left_button.enable() if self.right_button: self.right_button.enable() - self.drawable_shape.set_active_state('normal') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('normal') def show(self): """ @@ -563,6 +572,7 @@ def hide(self): """ super().hide() - self.sliding_button.hide() + if self.sliding_button is not None: + self.sliding_button.hide() if self.button_container is not None: self.button_container.hide() diff --git a/pygame_gui/elements/ui_image.py b/pygame_gui/elements/ui_image.py index aca54bc1..06b5fbaa 100644 --- a/pygame_gui/elements/ui_image.py +++ b/pygame_gui/elements/ui_image.py @@ -55,11 +55,14 @@ def __init__(self, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Set the dimensions of this image, scaling the image surface to match. :param dimensions: The new dimensions of the image. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ super().set_dimensions(dimensions) diff --git a/pygame_gui/elements/ui_label.py b/pygame_gui/elements/ui_label.py index 86c3a4f8..d134b286 100644 --- a/pygame_gui/elements/ui_label.py +++ b/pygame_gui/elements/ui_label.py @@ -270,7 +270,8 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.drawable_shape.set_active_state('disabled') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('disabled') def enable(self): """ @@ -278,7 +279,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.drawable_shape.set_active_state('normal') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('normal') def on_locale_changed(self): font = self.ui_theme.get_font(self.combined_element_ids) diff --git a/pygame_gui/elements/ui_panel.py b/pygame_gui/elements/ui_panel.py index dcd216c4..03eb2b21 100644 --- a/pygame_gui/elements/ui_panel.py +++ b/pygame_gui/elements/ui_panel.py @@ -156,12 +156,15 @@ def kill(self): def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Set the size of this panel and then re-sizes and shifts the contents of the panel container to fit the new size. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ # Don't use a basic gate on this set dimensions method because the container may be a @@ -280,7 +283,8 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.panel_container.disable() + if self.panel_container is not None: + self.panel_container.disable() def enable(self): """ @@ -288,7 +292,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.panel_container.enable() + if self.panel_container is not None: + self.panel_container.enable() def show(self): """ diff --git a/pygame_gui/elements/ui_scrolling_container.py b/pygame_gui/elements/ui_scrolling_container.py index c2bf93b9..c0f43c2b 100644 --- a/pygame_gui/elements/ui_scrolling_container.py +++ b/pygame_gui/elements/ui_scrolling_container.py @@ -160,7 +160,8 @@ def set_relative_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Method to directly set the dimensions of an element. @@ -168,6 +169,8 @@ def set_dimensions(self, dimensions: Union[pygame.math.Vector2, may make a mess of them. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ super().set_dimensions(dimensions) @@ -416,7 +419,8 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self._root_container.disable() + if self._root_container is not None: + self._root_container.disable() def enable(self): """ @@ -424,7 +428,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self._root_container.enable() + if self._root_container is not None: + self._root_container.enable() def show(self): """ diff --git a/pygame_gui/elements/ui_selection_list.py b/pygame_gui/elements/ui_selection_list.py index 923ad601..e61d94aa 100644 --- a/pygame_gui/elements/ui_selection_list.py +++ b/pygame_gui/elements/ui_selection_list.py @@ -65,7 +65,9 @@ def __init__(self, List[str], List[Tuple[str, str]] # Multi-selection lists ]] = None, ): - + # Need to move some declarations early as they are indirectly referenced via the ui element + # constructor + self.list_and_scroll_bar_container = None super().__init__(relative_rect, manager, container, @@ -488,12 +490,15 @@ def process_event(self, event: pygame.event.Event) -> bool: def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Set the size of this panel and then resizes and shifts the contents of the panel container to fit the new size. + :param dimensions: The new dimensions to set. + :param clamp_to_container: clamp these dimensions to the size of the element's container. """ # Don't use a basic gate on this set dimensions method because the container may be a @@ -680,11 +685,13 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.list_and_scroll_bar_container.disable() + if self.list_and_scroll_bar_container is not None: + self.list_and_scroll_bar_container.disable() # clear selections - for item in self.item_list: - item['selected'] = False + if self.item_list is not None: + for item in self.item_list: + item['selected'] = False def enable(self): """ @@ -692,7 +699,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.list_and_scroll_bar_container.enable() + if self.list_and_scroll_bar_container is not None: + self.list_and_scroll_bar_container.enable() def show(self): """ @@ -713,5 +721,5 @@ def hide(self): there is no need to call their hide() methods separately. """ super().hide() - - self.list_and_scroll_bar_container.hide() + if self.list_and_scroll_bar_container is not None: + self.list_and_scroll_bar_container.hide() diff --git a/pygame_gui/elements/ui_text_box.py b/pygame_gui/elements/ui_text_box.py index 04c4c1e4..c58d5405 100644 --- a/pygame_gui/elements/ui_text_box.py +++ b/pygame_gui/elements/ui_text_box.py @@ -98,6 +98,9 @@ def __init__(self, allow_split_dashes: bool = True, plain_text_display_only: bool = False, should_html_unescape_input_text: bool = False): + # Need to move some declarations early as they are indirectly referenced via the ui element + # constructor + self.scroll_bar = None relative_rect.height = -1 if wrap_to_height else relative_rect.height super().__init__(relative_rect, manager, container, starting_height=starting_height, @@ -129,7 +132,7 @@ def __init__(self, self.active_text_effect = None # type: Optional[TextEffect] self.active_text_chunk_effects = [] - self.scroll_bar = None + self.scroll_bar_width = 20 self.border_width = None @@ -497,11 +500,14 @@ def set_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Method to directly set the dimensions of a text box. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ self.relative_rect.width = int(dimensions[0]) diff --git a/pygame_gui/elements/ui_tool_tip.py b/pygame_gui/elements/ui_tool_tip.py index 714d7727..0bc2b89c 100644 --- a/pygame_gui/elements/ui_tool_tip.py +++ b/pygame_gui/elements/ui_tool_tip.py @@ -192,11 +192,14 @@ def set_relative_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Directly sets the dimensions of this tool tip. This will overwrite the normal theming. - :param dimensions: The new dimensions to set + :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ self.rect_width = dimensions[0] diff --git a/pygame_gui/elements/ui_vertical_scroll_bar.py b/pygame_gui/elements/ui_vertical_scroll_bar.py index c11c96b0..46266350 100644 --- a/pygame_gui/elements/ui_vertical_scroll_bar.py +++ b/pygame_gui/elements/ui_vertical_scroll_bar.py @@ -38,6 +38,9 @@ def __init__(self, object_id: Optional[Union[ObjectID, str]] = None, anchors: Optional[Dict[str, Union[str, UIElement]]] = None, visible: int = 1): + # Need to move some declarations early as they are indirectly referenced via the ui element + # constructor + self.button_container = None super().__init__(relative_rect, manager, container, layer_thickness=2, @@ -86,8 +89,6 @@ def __init__(self, self.sliding_button = None self.enable_arrow_buttons = True - self.button_container = None - self.rebuild_from_changed_theme_data() scroll_bar_height = max(5, int(self.scrollable_height * self.visible_percentage)) @@ -501,11 +502,14 @@ def set_relative_position(self, position: Union[pygame.math.Vector2, def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Method to directly set the dimensions of an element. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ super().set_dimensions(dimensions) @@ -539,9 +543,11 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self.button_container.disable() + if self.button_container is not None: + self.button_container.disable() - self.drawable_shape.set_active_state('disabled') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('disabled') def enable(self): """ @@ -549,9 +555,11 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self.button_container.enable() + if self.button_container is not None: + self.button_container.enable() - self.drawable_shape.set_active_state('normal') + if self.drawable_shape is not None: + self.drawable_shape.set_active_state('normal') def show(self): """ @@ -568,5 +576,5 @@ def hide(self): propagate and hide all the buttons. """ super().hide() - - self.button_container.hide() + if self.button_container is not None: + self.button_container.hide() diff --git a/pygame_gui/elements/ui_window.py b/pygame_gui/elements/ui_window.py index 0790bfb0..54a4928d 100644 --- a/pygame_gui/elements/ui_window.py +++ b/pygame_gui/elements/ui_window.py @@ -107,12 +107,15 @@ def set_blocking(self, state: bool): def set_dimensions(self, dimensions: Union[pygame.math.Vector2, Tuple[int, int], - Tuple[float, float]]): + Tuple[float, float]], + clamp_to_container: bool = False): """ Set the size of this window and then re-sizes and shifts the contents of the windows container to fit the new size. :param dimensions: The new dimensions to set. + :param clamp_to_container: Whether we should clamp the dimensions to the + dimensions of the container or not. """ # Don't use a basic gate on this set dimensions method because the container may be a @@ -696,7 +699,8 @@ def disable(self): """ if self.is_enabled: self.is_enabled = False - self._window_root_container.disable() + if self._window_root_container is not None: + self._window_root_container.disable() def enable(self): """ @@ -704,7 +708,8 @@ def enable(self): """ if not self.is_enabled: self.is_enabled = True - self._window_root_container.enable() + if self._window_root_container is not None: + self._window_root_container.enable() def show(self): """ @@ -712,8 +717,8 @@ def show(self): propagate and show all the children. """ super().show() - - self._window_root_container.show() + if self._window_root_container is not None: + self._window_root_container.show() def hide(self): """ @@ -721,8 +726,8 @@ def hide(self): propagate and hide all the children. """ super().hide() - - self._window_root_container.hide() + if self._window_root_container is not None: + self._window_root_container.hide() def get_relative_mouse_pos(self): """ diff --git a/pygame_gui/windows/ui_colour_picker_dialog.py b/pygame_gui/windows/ui_colour_picker_dialog.py index a79a09fc..e95784a9 100644 --- a/pygame_gui/windows/ui_colour_picker_dialog.py +++ b/pygame_gui/windows/ui_colour_picker_dialog.py @@ -52,6 +52,9 @@ def __init__(self, object_id: Optional[Union[ObjectID, str]] = None, anchors: Optional[Dict[str, Union[str, UIElement]]] = None, visible: int = 1): + # Need to move some declarations early as they are indirectly referenced via the ui element + # constructor when hiding on creation + self.element_container = None super().__init__(relative_rect, manager, @@ -289,8 +292,8 @@ def hide(self): - which will propagate to the sub-elements - label, entry and slider. """ super().hide() - - self.element_container.hide() + if self.element_container is not None: + self.element_container.hide() class UIColourPickerDialog(UIWindow):