### Basic Pygame Window Setup Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst Initializes Pygame and creates a basic window with a black background. This serves as the foundation for Pygame GUI applications. ```python import pygame pygame.init() pygame.display.set_caption('Quick Start') window_surface = pygame.display.set_mode((800, 600)) background = pygame.Surface((800, 600)) background.fill(pygame.Color('#000000')) is_running = True while is_running: for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False window_surface.blit(background, (0, 0)) pygame.display.update() ``` -------------------------------- ### Install Pygame GUI Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst Command to install the Pygame GUI library using pip. This is a prerequisite for using Pygame GUI features. ```console pip install pygame_gui ``` -------------------------------- ### Theme JSON Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Demonstrates a theme.json file with various valid color expressions for different UI states and elements. ```json { "defaults": { "colours": { "normal_bg": "#f2f", "hovered_bg": "#ff7a", "disabled_bg": "rgb(200, 150, 60)", "selected_bg": "rgba(20, 50, 89, 225)", "dark_bg": "hsl(30, 0.6, 0.7)", "normal_text": "hsla(3deg, 0.5, 0.7, 90%)", "hovered_text": "#FFFFFF", "selected_text": "purple", "disabled_text": "RGB(40, 70, 90)", "link_text": "HSV(50deg, 30%, 40%)", "link_hover": "cmy(50%, 30%, 0.7)", "link_selected": "teal", "text_shadow": "skyblue", "normal_border": "gold" } } } ``` -------------------------------- ### Initialize Pygame GUI UIManager Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst Integrates Pygame GUI by importing the library and creating a UIManager instance, which is essential for managing UI elements. ```python import pygame import pygame_gui pygame.init() pygame.display.set_caption('Quick Start') window_surface = pygame.display.set_mode((800, 600)) background = pygame.Surface((800, 600)) background.fill(pygame.Color('#000000')) manager = pygame_gui.UIManager((800, 600)) is_running = True while is_running: for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False window_surface.blit(background, (0, 0)) pygame.display.update() ``` -------------------------------- ### Create a Pygame GUI Button Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst Demonstrates creating a UIButton element with specified text and position, managed by the UIManager. This is the first interactive UI element added to the application. ```python import pygame import pygame_gui pygame.init() pygame.display.set_caption('Quick Start') window_surface = pygame.display.set_mode((800, 600)) background = pygame.Surface((800, 600)) background.fill(pygame.Color('#000000')) manager = pygame_gui.UIManager((800, 600)) hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((350, 275), (100, 50)), text='Say Hello', manager=manager) clock = pygame.time.Clock() is_running = True while is_running: time_delta = clock.tick(60)/1000.0 ``` -------------------------------- ### Basic Button Theme Structure Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start_theming.rst Defines the initial structure for theming 'button' elements in a JSON theme file. This serves as a starting point for customization. ```json { "button": { } } ``` -------------------------------- ### Pygame GUI Initialization and Event Handling Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst This snippet demonstrates the core loop of a Pygame application using Pygame GUI. It initializes Pygame, sets up the display window, creates a UI manager, adds a button, and processes events. The loop handles window closing and specifically checks for UI_BUTTON_PRESSED events to print 'Hello World!' when the 'Say Hello' button is clicked. It also updates and draws the UI elements. ```python import pygame import pygame_gui pygame.init() pygame.display.set_caption('Quick Start') window_surface = pygame.display.set_mode((800, 600)) background = pygame.Surface((800, 600)) background.fill(pygame.Color('#000000')) manager = pygame_gui.UIManager((800, 600)) hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((350, 275), (100, 50)), text='Say Hello', manager=manager) clock = pygame.time.Clock() is_running = True while is_running: time_delta = clock.tick(60)/1000.0 for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False if event.type == pygame_gui.UI_BUTTON_PRESSED: if event.ui_element == hello_button: print('Hello World!') manager.process_events(event) manager.update(time_delta) window_surface.blit(background, (0, 0)) manager.draw_ui(window_surface) pygame.display.update() ``` -------------------------------- ### Basic Theme Configuration (JSON) Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst An example of a basic theme file in JSON format, showcasing the 'defaults' block for setting 'colours' and 'misc' properties. This includes default UI colors and basic shape/layout configurations. ```json { "defaults": { "colours": { "normal_bg":"#45494e", "hovered_bg":"#35393e", "disabled_bg":"#25292e", "selected_bg":"#193754", "dark_bg":"#15191e", "normal_text":"#c5cbd8", "hovered_text":"#FFFFFF", "selected_text":"#FFFFFF", "disabled_text":"#6d736f", "link_text": "#0000EE", "link_hover": "#2020FF", "link_selected": "#551A8B", "text_shadow": "#777777", "normal_border": "#DDDDDD", "hovered_border": "#B0B0B0", "disabled_border": "#808080", "selected_border": "#8080B0", "active_border": "#8080B0", "filled_bar":"#f4251b", "unfilled_bar":"#CCCCCC" }, "misc": { "shape": "rectangle", "border_width": {"left": 1, "right": 1, "top": 1, "bottom": 1}, "shadow_width": 2, "shape_corner_radius": 2, "border_overlap": 1, "enable_title_bar": "1", "text_horiz_alignment": "left", "text_vert_alignment": "center", "text_horiz_alignment_padding": 4, "text_vert_alignment_padding": 4, "text_shadow_size": 1, "text_shadow_offset": [1, 1], "tool_tip_delay": 1.0, "title_bar_height": 28 } } } ``` -------------------------------- ### Update and Draw UI with Clock Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst Sets up a Pygame Clock to manage frame rate and delta time, then updates and draws the UI managed by the UIManager. This is crucial for animations and time-dependent UI behavior. ```python import pygame import pygame_gui pygame.init() pygame.display.set_caption('Quick Start') window_surface = pygame.display.set_mode((800, 600)) background = pygame.Surface((800, 600)) background.fill(pygame.Color('#000000')) manager = pygame_gui.UIManager((800, 600)) clock = pygame.time.Clock() is_running = True while is_running: time_delta = clock.tick(60)/1000.0 for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False manager.process_events(event) manager.update(time_delta) window_surface.blit(background, (0, 0)) manager.draw_ui(window_surface) pygame.display.update() ``` -------------------------------- ### UIWindow Theming Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_window.rst An example of a UIWindow theming block in a JSON file, demonstrating the usage of color and miscellaneous parameters. ```json { "window": { "colours": { "dark_bg":"#21282D", "normal_border": "#999999" }, "misc": { "shape": "rounded_rectangle", "shape_corner_radius": "10", "border_width": "1", "shadow_width": "15", "title_bar_height": "20" } }, "window.#title_bar": { "misc": { "text_horiz_alignment": "center" } } } ``` -------------------------------- ### Example UISelectionList Theme Configuration Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_selection_list.rst An example of a JSON theme file demonstrating the configuration of UISelectionList and its sub-elements using the described theming parameters. ```json { "selection_list": { "colours": { "dark_bg":"#21282D", "normal_border": "#999999" }, "background_image": { "path": "data/images/splat.png", "sub_surface_rect": "0,0,32,32" }, "misc": { "shape": "rounded_rectangle", "shape_corner_radius": "10", "border_width": "1", "shadow_width": "15", "list_item_height": "30" } }, "selection_list.@selection_list_item": { "misc": { "border_width": "2" } } } ``` -------------------------------- ### Example UITextEntryBox Theme Configuration Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_text_entry_box.rst An example of a UITextEntryBox theme configuration in JSON format, demonstrating the usage of various theming parameters. ```json { "text_entry_box": { "colours": { "dark_bg": ("180, 180, 180"), "selected_bg": ("255, 255, 255"), "normal_border": ("0, 0, 0"), "selected_text": ("0, 0, 0"), "link_text": ("0, 0, 255"), "link_hover": ("200, 200, 255"), "link_selected": ("255, 0, 0"), "text_cursor": ("0, 0, 0") }, "misc": { "shape": "rounded_rectangle", "shape_corner_radius": "10", "border_width": "2", "shadow_width": "1", "padding": "10,10", "link_normal_underline": "1", "link_hover_underline": "1", "text_horiz_alignment": "left", "text_vert_alignment": "center", "line_spacing": "1.5" } } } ``` -------------------------------- ### Example UITextEntryLine Theme Configuration Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_text_entry_line.rst A JSON example demonstrating the structure and usage of theming parameters for a UITextEntryLine element. ```json { "text_entry_line": { "colours": { "dark_bg": "#333333", "selected_bg": "#555555", "normal_text": "#FFFFFF", "selected_text": "#000000", "normal_border": "#AAAAAA", "text_cursor": "#FF0000" }, "font": { "name": "default", "size": 20, "bold": "0", "italic": "0", "regular_resource": { "package": "pygame_gui.data.fonts", "resource": "FiraCode-Regular.ttf" } }, "misc": { "shape": "rounded_rectangle", "shape_corner_radius": 5, "border_width": 2, "shadow_width": 1, "padding": "5,3", "tool_tip_delay": 0.5 } } } ``` -------------------------------- ### Theme File Structure for ObjectIDs Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst An example of a JSON theme file demonstrating how to define styles for different ObjectIDs. It shows how to style a general 'button', a class_id '@friendly_buttons', and a specific object_id '#hello_button'. ```json { "button": { "misc": { "border_width": "1", "shadow_width": "2" } }, "@friendly_buttons": { "misc": { "shadow_width": "5", "shape": "rounded_rectangle" } }, "#hello_button": { "misc": { "text_horiz_alignment": "left" } } } ``` -------------------------------- ### Example UITextBox Theme Configuration Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_text_box.rst An example of a UITextBox theme configuration in JSON format, demonstrating the usage of various color and miscellaneous parameters. ```json { "text_box": { "colours": { "dark_bg":"#21282D", "normal_border": "#999999", "link_text": "#FF0000" } } } ``` -------------------------------- ### Theme Prototypes Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Demonstrates using theme prototypes to apply common styling to multiple UI elements. A '#new_shape_style' block defines shared properties, which are then inherited by 'button' and 'horizontal_slider' elements. ```json { "#new_shape_style": { "misc": { "shape": "rectangle", "border_width": "2", "shadow_width": "1" } }, "button": { "prototype": "#new_shape_style" }, "horizontal_slider": { "prototype": "#new_shape_style", "misc": { "enable_arrow_buttons": 0 } } } ``` -------------------------------- ### Install Pygame GUI Source: https://github.com/myremylar/pygame_gui/blob/main/README.md This snippet shows the command to install the Pygame GUI library using pip. It's a straightforward installation process for Python packages. ```bash pip install pygame_gui ``` -------------------------------- ### UITooltip Theming Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_tooltip.rst An example of a UITooltip theming block in a JSON file, demonstrating the 'misc' parameters for rect_width and styling for its internal text box. ```json { "tool_tip": { "misc": { "rect_width": "170" } }, "tool_tip.text_box": { "colours": { "dark_bg":"#505050", "normal_border": "#FFFFFF" }, "misc": { "border_width": "2", "padding": "5,5" } } } ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/myremylar/pygame_gui/blob/main/CONTRIBUTING.md Installs all necessary dependencies for building the documentation and running tests for Pygame GUI. ```python python -m pip install sphinx sphinx_rtd_theme pytest pytest-cov pytest-benchmark ``` -------------------------------- ### UIPanel Single Image Mode JSON Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_panel.rst An example of a JSON theme file demonstrating the single image mode for a UIPanel. ```json { "panel": { "colours": { "dark_bg": "#333333", "normal_border": "#CCCCCC" }, "images": { "background_image": { "path": "my_gui_package/images/panel_background.png", "sub_surface_rect": "0,0,100,100", "position": "0.2, 0.2" } }, "misc": { "shape": "rounded_rectangle", "shape_corner_radius": "10", "border_width": "2", "shadow_width": "3" } } } ``` -------------------------------- ### Example UIProgressBar JSON Theme Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_progress_bar.rst An example of a progress bar theming block in a JSON file, demonstrating the usage of various parameters. ```json { "progress_bar": { "colours": { "normal_text": "#c5cbd8", "text_shadow": "#777777", "normal_border": "#DDDDDD", ``` -------------------------------- ### Theme File Colors for Buttons Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst An example of a JSON theme file snippet showing how to define color properties for a 'button' element. This includes various states like normal, hovered, disabled, and selected backgrounds and text colors. ```json { "defaults": { "colours": { "normal_bg":"#45494e", "hovered_bg":"#35393e", "disabled_bg":"#25292e", "selected_bg":"#193754", "dark_bg":"#15191e", "normal_text":"#c5cbd8", "hovered_text":"#FFFFFF", "selected_text":"#FFFFFF", "disabled_text":"#6d736f", "link_text": "#0000EE", "link_hover": "#2020FF", "link_selected": "#551A8B", "text_shadow": "#777777", "normal_border": "#DDDDDD", "hovered_border": "#B0B0B0", "disabled_border": "#808080", "selected_border": "#8080B0", "active_border": "#8080B0", "filled_bar":"#f4251b", "unfilled_bar":"#CCCCCC" } }, "button": { "colours": { "normal_bg":"#45494e", "hovered_bg":"#35393e", "disabled_bg":"#25292e", "selected_bg":"#193754", ``` -------------------------------- ### Build Pygame GUI from Source Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/index.rst Builds and installs the latest version of Pygame GUI from its GitHub repository. This involves downloading the source code, navigating to the project directory, and then using setup.py and pip to install it. ```python python setup.py install pip install . -U ``` -------------------------------- ### UIWorldSpaceHealthBar Theming Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_world_space_health_bar.rst An example of a UIWorldSpaceHealthBar theme configuration in JSON format, demonstrating the usage of color and miscellaneous parameters. ```json { "world_space_health_bar": { "colours": { "normal_border": "#AAAAAA", "filled_bar": "#f4251b", "unfilled_bar": "#CCCCCC" }, "misc": { "follow_sprite_offset": "-5, 32", "border_width": "0" } } } ``` -------------------------------- ### Install Pygame GUI Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/index.rst Installs the latest release of Pygame GUI from PyPI using pip. The -U flag ensures that the package is upgraded to the latest version if it's already installed. ```console pip install pygame_gui -U ``` -------------------------------- ### Color Formats Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Details various color formats supported, including hex, RGB, RGBA, HSL, HSLA, HSV, HSVA, and CMY. It specifies the expected input types and provides examples for each. ```APIDOC Hexadecimal Color: - Supports shorthand (e.g., #AF2F) and full hex values (e.g., #AAFF22FF). - Case-insensitive. RGB: - Three numbers between 0 and 255. - Example: rgb(20, 230, 43) RGBA: - Four numbers between 0 and 255 (Red, Green, Blue, Alpha). - Example: rgba(60, 30, 97, 255) HSL: - Hue (degree), Saturation (percentage), Luminance (percentage). - Example: hsl(190deg, 40%, .5) HSLA: - Hue (degree), Saturation (percentage), Luminance (percentage), Alpha (percentage). - Example: hsla(10deg, 40%, .5, 0.7) HSV: - Hue (degree), Saturation (percentage), Value (percentage). - Example: hsv(282deg, 63%, 92%) HSVA: - Hue (degree), Saturation (percentage), Value (percentage), Alpha (percentage). - Example: hsva(20deg, 40%, .5, 70%) CMY: - Three percentage values (Cyan, Magenta, Yellow). - Example: cmy(.3, .5, .7) ``` -------------------------------- ### UIVerticalScrollBar Theming Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_vertical_scroll_bar.rst An example JSON theme file demonstrating how to style the UIVerticalScrollBar and its sub-elements, including colors and miscellaneous properties. ```json { "vertical_scroll_bar": { "colours": { "normal_bg": "#25292e", "hovered_bg": "#35393e", "disabled_bg": "#25292e", "selected_bg": "#25292e", "active_bg": "#193784", "dark_bg": "#15191e", "normal_text": "#c5cbd8", "hovered_text": "#FFFFFF", "selected_text": "#FFFFFF", "disabled_text": "#6d736f" }, "misc": { "shape": "rectangle", "border_width": "0", "enable_arrow_buttons": "0" } }, "vertical_scroll_bar.button": { "misc": { "border_width": "1" } }, "vertical_scroll_bar.#sliding_button": { "colours": { "normal_bg": "#FF0000" } } } ``` -------------------------------- ### UIStatusBar Theming Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_status_bar.rst An example of a status bar theming block in a JSON file, demonstrating the usage of color and miscellaneous parameters. ```json { "status_bar": { "colours": { "normal_border": "#AAAAAA", "filled_bar": "#f4251b", "unfilled_bar": "#CCCCCC" }, "misc": { "follow_sprite_offset": "-5, 32", "border_width": "0" } } } ``` -------------------------------- ### UIDropDownMenu Theming Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_drop_down_menu.rst An example of a UIDropDownMenu theming block in a JSON file, demonstrating the use of 'misc' and 'colours' parameters for both the main drop down menu and its selected option. ```json { "drop_down_menu": { "misc": { "expand_direction": "down" }, "colours": { "normal_bg": "#25292e", "hovered_bg": "#35393e" } }, "drop_down_menu.#selected_option": { "misc": { "border_width": "1", "open_button_width": "10" } } } ``` -------------------------------- ### Install All Pygame GUI Dependencies (One-Liner) Source: https://github.com/myremylar/pygame_gui/blob/main/CONTRIBUTING.md A single command to set up a virtual environment with all core Pygame GUI dependencies and development tools. ```python python -m pip install pygame-ce python-i18n importlib_resources typing_extensions sphinx sphinx_rtd_theme pytest pytest-cov pytest-benchmark ``` -------------------------------- ### Install PyInstaller Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/freezing.rst Installs the PyInstaller package from the Python Package Index (PyPI). This is the first step to using PyInstaller for creating executables. ```shell pip install pyinstaller ``` -------------------------------- ### UICheckBox Single Image Mode Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_check_box.rst A JSON configuration example demonstrating how to theme a UICheckBox using a single image file for multiple states (normal, hovered, selected, disabled) by specifying different sub-surface rectangles. ```json { "check_box": { "colours": { "normal_bg": "#25292e", "normal_border": "#AAAAAA", "hovered_bg": "#35393e", "hovered_border": "#B0B0B0", "disabled_bg": "#25292e", "disabled_border": "#808080", "selected_bg": "#193784", "selected_border": "#8080B0", "normal_text": "#c5cbd8", "hovered_text": "#FFFFFF", "disabled_text": "#6d736f", "selected_text": "#FFFFFF", "normal_text_shadow": "#10101070", "hovered_text_shadow": "#10101070", "disabled_text_shadow": "#10101070", "selected_text_shadow": "#10101070" }, "font": { "name": "fira_code", "size": "14", "bold": "0", "italic": "0" }, "images": { "normal_image": { "package": "data.images", "resource": "checkbox_states.png", "sub_surface_rect": "0,0,16,16" }, "hovered_image": { "package": "data.images", "resource": "checkbox_states.png", "sub_surface_rect": "16,0,16,16" }, "selected_image": { "package": "data.images", "resource": "checkbox_states.png", "sub_surface_rect": "32,0,16,16" }, "disabled_image": { "package": "data.images", "resource": "checkbox_states.png", "sub_surface_rect": "48,0,16,16" } }, "misc": { "shape": "ellipse", "shape_corner_radius": "3", "border_width": "2", "shadow_width": "2", "border_overlap": "1", "check_symbol": "✓", "indeterminate_symbol": "−", "text_offset": "8", "tool_tip_delay": "1.5" } } } ``` -------------------------------- ### Example UILabel Theme Configuration (JSON) Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_label.rst A sample JSON structure demonstrating how to configure UILabel theming parameters within a theme file. It includes settings for colors. ```json { "label": { "colours": { "dark_bg": "#25292e", "normal_text": "#c5cbd8", "text_shadow": "#505050" } } } ``` -------------------------------- ### Loading a Theme File in Pygame GUI Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Demonstrates how to initialize the UIManager with a specific theme file. The path to the theme file can be absolute or relative to the current working directory. ```python import pygame_gui manager = pygame_gui.UIManager((800, 600), 'theme.json') ``` -------------------------------- ### PyInstaller Spec File Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/freezing.rst An example of a PyInstaller spec file used to configure the build process for an application. It specifies analysis options, data files, and executable details. The `datas` and `binaries` options are crucial for including necessary assets. ```python # -*- mode: python legalese block_cipher = None a = Analysis(['../pyinstaller_test.py'], pathex=[], binaries=[], datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) a.datas += Tree('data', prefix='data') pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) # enable this to see verbose output # options = [ ('v', None, 'OPTION')] exe = EXE(pyz, a.scripts, # options, exclude_binaries=True, name='pyinstaller_test_release', debug=False, # set this to True for debug output strip=False, upx=True, console=True ) # set this to False this to remove the console coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name='pyinstaller_test_release') ``` -------------------------------- ### Custom Translation File Example (French) Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/localization.rst An example of a JSON file containing French translations for application strings, following the 'namespace.key' format. ```json { "fr": { "holmes_text_test": "
Ce matin-là, M. Sherlock Holmes qui, sauf les cas assez fréquents où il passait les nuits, se levait tard, était assis devant la table de la salle à manger. Je me tenais près de la cheminée, examinant la canne que notre visiteur de la veille avait oubliée. C’était un joli bâton, solide, terminé par une boule — ce qu’on est convenu d’appeler « une permission de minuit ». Immédiatement au-dessous de la pomme, un cercle d’or, large de deux centimètres, portait l’inscription et la date suivantes : « À M. James Mortimer, ses amis du C. C. H. — 1884 ». Cette canne, digne, grave, rassurante, ressemblait à celles dont se servent les médecins « vieux jeu ».
", "hello_world_message_text": "Bonjour le monde" } } ``` -------------------------------- ### Nuitka Command Line Example Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/freezing.rst Example command for using Nuitka to compile a Python application into a single executable file. It includes options to enable plugins, include data directories, specify the output file name, and set the output directory. The `--include-plugin-directory=pygame_gui/data` flag is crucial for including Pygame GUI's data files. ```shell nuitka --onefile --plugin-enable=numpy --plugin-enable=pylint-warnings --include-plugin-directory=pygame_gui/data -o package/YourExeName.exe --output-dir=package ``` -------------------------------- ### Install Nuitka Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/freezing.rst Installs the Nuitka compiler from the Python Package Index (PyPI). Nuitka is an alternative tool for creating executables from Python code. ```shell pip install nuitka ``` -------------------------------- ### Example Horizontal Slider Theme Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_horizontal_slider.rst A JSON example demonstrating how to theme a UIHorizontalSlider and its sub-elements using the defined parameters. This includes colors, miscellaneous settings, and specific button styling. ```json { "horizontal_slider": { "colours": { "normal_bg": "#25292e", "hovered_bg": "#35393e", "disabled_bg": "#25292e", "selected_bg": "#25292e", "active_bg": "#193784", "dark_bg": "#15191e,#202020,0", "normal_text": "#c5cbd8", "hovered_text": "#FFFFFF", "selected_text": "#FFFFFF", "disabled_text": "#6d736f" }, "misc": { "shape": "rectangle", "enable_arrow_buttons": "0", "sliding_button_width": "15" } }, "horizontal_slider.button": { "misc": { "border_width": "1" } }, "horizontal_slider.#sliding_button": { "colours": { "normal_bg": "#FF0000" } } } ``` -------------------------------- ### Theming Specific UI Elements Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Explains how to apply theming to specific UI elements by using hierarchical IDs, including referencing sub-elements and using 'object_id' and 'class_id'. ```APIDOC Theming Specific UI Elements: - Additional blocks can be added at the same level as 'defaults' to theme specific UI elements. - These blocks require an ID that references the elements they apply to. - IDs have a hierarchy, allowing referencing of sub-elements by joining them with a full stop (e.g., 'text_box.vertical_scroll_bar'). - Parts of a theming block ID can be an element ID or an 'ObjectID'. - ObjectID objects contain 'object_id' (for specific object identification) and 'class_id' (for identifying objects within a class). Example: - To theme the vertical scroll bars of a text box: 'text_box.vertical_scroll_bar' ``` -------------------------------- ### Creating and Applying ObjectID in Python Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Demonstrates how to import the ObjectID class and apply it to a UIButton element when creating it. This allows for specific theming of individual UI elements. ```python from pygame_gui.core import ObjectID from pygame_gui.elements import UIButton ... # other code omitted here - # see quick start guide for how to get up and running with a single button hello_button = UIButton(relative_rect=pygame.Rect((350, 280), (-1, -1)), text='Hello', manager=manager, object_id=ObjectID(class_id='@friendly_buttons', object_id='#hello_button')) ``` -------------------------------- ### Gradient Color Syntax Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Illustrates how to define gradients in theme.json, specifying colors and direction. ```json { "defaults": { "colours": { "normal_bg":"#45494e,#65696e,90", "hovered_bg":"rgb(30, 40, 60),#f3f,rgb(50, 60, 70),90deg" } } } ``` -------------------------------- ### Loading Theme in Pygame GUI Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start_theming.rst Demonstrates how to initialize Pygame, create a UI manager, and load a custom theme file ('quick_start.json') into the application. This script also includes basic event processing and UI updates. ```python import pygame import pygame_gui pygame.init() pygame.display.set_caption('Quick Start') window_surface = pygame.display.set_mode((800, 600)) background = pygame.Surface((800, 600)) background.fill(pygame.Color('#000000')) manager = pygame_gui.UIManager((800, 600), theme_path="quick_start.json") hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((350, 275), (100, 50)), text='Say Hello', manager=manager) clock = pygame.time.Clock() is_running = True while is_running: time_delta = clock.tick(60)/1000.0 for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False if event.type == pygame_gui.UI_BUTTON_PRESSED: if event.ui_element == hello_button: print('Hello World!') manager.process_events(event) manager.update(time_delta) window_surface.blit(background, (0, 0)) manager.draw_ui(window_surface) pygame.display.update() ``` -------------------------------- ### Closing Pygame Window Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start.rst Adds the pygame.quit() call to ensure the Pygame window closes properly, especially when running in certain IDEs like IDLE. ```python pygame.quit() ``` -------------------------------- ### Customizing Button Colors Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/quick_start_theming.rst Adds a 'colours' block to the theme file to customize the button's border, background, and text color. This example sets the button to have a white border, slate gray background, and white text. ```json { "button": { "colours": { "normal_border": "White", "normal_bg": "SlateGray", "normal_text": "White" } } } ``` -------------------------------- ### Stretching UI Elements with Anchors Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/layout_guide.rst Demonstrates how to set anchors to make UI elements stretch horizontally and vertically within their container. This is achieved by setting 'left' to 'left' and 'right' to 'right' for horizontal stretching, and 'top' to 'top' and 'bottom' to 'bottom' for vertical stretching. The example shows a UIButton stretching to fill the width and height of its parent window. ```python button_layout_rect = pygame.Rect(30, 20, 100, 20) UIButton(relative_rect=button_layout_rect, text='Hello', manager=manager, container=ui_window, anchors={'left': 'left', 'right': 'right', 'top': 'top', 'bottom': 'bottom'}) ``` -------------------------------- ### Using Anchor Targets for Relative Positioning Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/layout_guide.rst Shows how to use anchor targets to position UI elements relative to other elements within the same container, rather than just container edges. This is useful for dynamically sized elements. The example demonstrates anchoring a button's 'bottom' and 'right' sides to the 'bottom' and 'right' of the container, respectively, and also to the 'bottom_target' and 'right_target' of other buttons. ```python button_3 = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((-10, -40), (-1, 30)), text='Anchored', manager=manager, container=dynamic_dimensions_window, anchors={'bottom': 'bottom', 'right': 'right', 'bottom_target': button_1, 'right_target': button_2}) ``` -------------------------------- ### Example UIHorizontalScrollBar Theme Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_reference/theme_horizontal_scroll_bar.rst An example of how to define theming for the UIHorizontalScrollBar and its sub-elements in a JSON theme file. ```json { "horizontal_scroll_bar": { "colours": { "normal_bg": "#25292e", "hovered_bg": "#35393e", "disabled_bg": "#25292e", "selected_bg": "#25292e", "active_bg": "#193784", "dark_bg": "#15191e", "normal_text": "#c5cbd8", "hovered_text": "#FFFFFF", "selected_text": "#FFFFFF", "disabled_text": "#6d736f" }, "misc": { "shape": "rectangle", "border_width": "0", "enable_arrow_buttons": "1" } }, "horizontal_scroll_bar.button": { "misc": { "border_width": "1" } }, "horizontal_scroll_bar.@arrow_button": { "misc": { "shadow_width": "0" } }, "horizontal_scroll_bar.#sliding_button": { "colours": { "normal_bg": "#FF0000" } } } ``` -------------------------------- ### Set Starting Locale Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/localization.rst Initializes the UIManager with a specific starting language using its ISO 639-1 code. ```python manager = UIManager((800, 600), starting_language='ja') ``` -------------------------------- ### Pygame GUI Package Overview Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/pygame_gui.rst This section provides an overview of the pygame_gui package structure. It lists the available subpackages (core, elements, windows) and submodules, indicating that detailed documentation for each can be found in their respective sections. ```python pygame_gui package =================== Subpackages ----------- .. toctree:: pygame_gui.core pygame_gui.elements pygame_gui.windows Submodules ---------- pygame_gui.ui_manager module ------------------------------ .. automodule:: pygame_gui.ui_manager :members: :no-undoc-members: :show-inheritance: Module contents --------------- .. automodule:: pygame_gui :members: :no-undoc-members: :show-inheritance: ``` -------------------------------- ### pygame_gui.core.text Module Contents Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/pygame_gui.core.text.rst Documentation for the main pygame_gui.core.text module, providing an overview of its members and inheritance. ```python import pygame_gui.core.text # Accessing members (conceptual): # text_manager = pygame_gui.core.text.TextManager(...) ``` -------------------------------- ### Install Pygame GUI Development Dependencies in Venv Source: https://github.com/myremylar/pygame_gui/blob/main/CONTRIBUTING.md Installs core Pygame GUI dependencies and development tools within a virtual environment. ```python python -m pip install pygame-ce python-i18n importlib_resources typing_extensions ``` -------------------------------- ### pygame_gui.core.ui_appearance_theme Module Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/pygame_gui.core.rst Documentation for the ui_appearance_theme module, which manages the visual styling and theming of UI elements. It supports inheritance. ```python .. automodule:: pygame_gui.core.ui_appearance_theme :members: :no-undoc-members: :show-inheritance: ``` -------------------------------- ### Invalid URL Fix for Examples Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/change_list.rst Corrects an invalid URL used in the game project examples. Thanks to @Grimmys for the pull request #216. ```python # Fix invalid URL for game project examples # Thanks to @Grimmys, see pull #216. ``` -------------------------------- ### pygame_gui.core.ui_window_stack Module Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/pygame_gui.core.rst Documentation for the ui_window_stack module, responsible for managing the stacking order of windows in the GUI. It supports inheritance. ```python .. automodule:: pygame_gui.core.ui_window_stack :members: :no-undoc-members: :show-inheritance: ``` -------------------------------- ### UIStatusBar Element Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/change_list.rst A new UIStatusBar element has been added, providing a status bar component for applications. An example demonstrating its usage is available in the examples project. ```python # Example of UIStatusBar: # from pygame_gui.elements import UIStatusBar # status_bar = UIStatusBar(pygame.Rect(0, 0, 100, 20), manager=ui_manager) ``` -------------------------------- ### Basic Button Creation Source: https://github.com/myremylar/pygame_gui/blob/main/requirements.txt Demonstrates how to create and manage a simple button using pygame_gui. This involves creating a button widget and handling its events. ```python import pygame import pygame_gui pygame.init() screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption('Pygame GUI Example') manager = pygame_gui.UIManager((screen_width, screen_height)) hello_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((350, 275), (100, 50)), text='Hello', manager=manager) running = True while running: time_delta = pygame.time.Clock().tick(60) / 1000.0 for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame_gui.UI_BUTTON_CLICKED: if event.ui_element == hello_button: print('Hello World!') manager.process_events(event) manager.update(time_delta) screen.fill((0, 0, 0)) manager.draw_ui(screen) pygame.display.flip() pygame.quit() ``` -------------------------------- ### pygame_gui.core.resource_loaders Module Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/pygame_gui.core.rst Documentation for the resource_loaders module, which handles loading of various resources for the GUI. It supports inheritance. ```python .. automodule:: pygame_gui.core.resource_loaders :members: :no-undoc-members: :show-inheritance: ``` -------------------------------- ### Loading Multiple Theme Files Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/theme_guide.rst Shows how to load multiple theme files into a Pygame GUI UI Manager. This allows for modular theming, where different aspects of the UI can be defined in separate JSON files. ```python manager = pygame_gui.UIManager((800, 600), 'base_theme.json') manager.get_theme().load_theme('menu_theme.json') manager.get_theme().load_theme('hud_theme.json') ``` -------------------------------- ### pygame_gui.core Module Contents Source: https://github.com/myremylar/pygame_gui/blob/main/docs/source/pygame_gui.core.rst Documentation for the main pygame_gui.core module, listing its members, and indicating support for inheritance and undocumented members. ```python .. automodule:: pygame_gui.core :members: :no-undoc-members: :show-inheritance: ```