From 02ac12e3690b15efb1daa9e8ad22a6d963bb8a2c Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Mon, 24 Jun 2024 13:19:38 +0800 Subject: [PATCH 01/11] Update for Python 3.12.4 --- src/pygamepopup/configuration.py | 22 +++++++++---------- src/pygamepopup/menu_manager.py | 2 +- .../{types.py => type_definitions.py} | 0 3 files changed, 12 insertions(+), 12 deletions(-) rename src/pygamepopup/{types.py => type_definitions.py} (100%) diff --git a/src/pygamepopup/configuration.py b/src/pygamepopup/configuration.py index 190ccd8..44abb8b 100644 --- a/src/pygamepopup/configuration.py +++ b/src/pygamepopup/configuration.py @@ -8,7 +8,7 @@ from os.path import abspath from typing import Union -import pkg_resources +import importlib.resources as res import pygame from .constants import WHITE @@ -17,23 +17,23 @@ _default_sprites: dict[str, Union[dict[str, str], str]] = { "button_background": { - "inactive": pkg_resources.resource_filename( - resource_package, "/".join(("images", "default_box.png")) + "inactive": res.as_file( + res.files(resource_package) / "images" / 'default_box.png' ), - "active": pkg_resources.resource_filename( - resource_package, "/".join(("images", "default_box_hover.png")) + "active": res.as_file( + res.files(resource_package) / "images" / 'default_box_hover.png' ), }, "dynamic_button_background": { - "inactive": pkg_resources.resource_filename( - resource_package, "/".join(("images", "default_box.png")) + "inactive": res.as_file( + res.files(resource_package) / "images" / 'default_box.png' ), - "active": pkg_resources.resource_filename( - resource_package, "/".join(("images", "default_box_hover.png")) + "active": res.as_file( + res.files(resource_package) / "images" / 'default_box_hover.png' ), }, - "info_box_background": pkg_resources.resource_filename( - resource_package, "/".join(("images", "default_box.png")) + "info_box_background": res.as_file( + res.files(resource_package) / "images" / 'default_box.png' ), } diff --git a/src/pygamepopup/menu_manager.py b/src/pygamepopup/menu_manager.py index d53845f..0f6ae01 100644 --- a/src/pygamepopup/menu_manager.py +++ b/src/pygamepopup/menu_manager.py @@ -10,7 +10,7 @@ import pygame from .components.info_box import InfoBox -from .types import Position +from .type_definitions import Position class MenuManager: diff --git a/src/pygamepopup/types.py b/src/pygamepopup/type_definitions.py similarity index 100% rename from src/pygamepopup/types.py rename to src/pygamepopup/type_definitions.py From 3c04ffa04230905168c9544eec68ed556240878c Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 10:33:54 +0800 Subject: [PATCH 02/11] changed according to Grimmys --- .github/workflows/test-library.yml | 4 ++-- setup.py | 4 ++-- src/pygamepopup/configuration.py | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test-library.yml b/.github/workflows/test-library.yml index f8a153d..e898956 100644 --- a/.github/workflows/test-library.yml +++ b/.github/workflows/test-library.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.12 architecture: x64 - name: Install dependencies run: | @@ -44,7 +44,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.12 architecture: x64 - name: Install dependencies run: | diff --git a/setup.py b/setup.py index 578a3f7..5935053 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pygame-popup", - version="0.10.0", + version="0.10.1", author="Grimmys", author_email="grimmys.programming@gmail.com", description="A popup manager for pygame", @@ -23,6 +23,6 @@ package_dir={"": "src"}, packages=setuptools.find_packages(where="src"), package_data={"": ["images/*.png"]}, - python_requires=">=3.7", + python_requires=">=3.12", install_requires=["pygame-ce>=2.0.0"], ) diff --git a/src/pygamepopup/configuration.py b/src/pygamepopup/configuration.py index 44abb8b..27383b9 100644 --- a/src/pygamepopup/configuration.py +++ b/src/pygamepopup/configuration.py @@ -8,7 +8,7 @@ from os.path import abspath from typing import Union -import importlib.resources as res +from importlib import resources import pygame from .constants import WHITE @@ -17,23 +17,23 @@ _default_sprites: dict[str, Union[dict[str, str], str]] = { "button_background": { - "inactive": res.as_file( - res.files(resource_package) / "images" / 'default_box.png' + "inactive": resources.as_file( + resources.files(resource_package) / "images" / 'default_box.png' ), - "active": res.as_file( - res.files(resource_package) / "images" / 'default_box_hover.png' + "active": resources.as_file( + resources.files(resource_package) / "images" / 'default_box_hover.png' ), }, "dynamic_button_background": { - "inactive": res.as_file( - res.files(resource_package) / "images" / 'default_box.png' + "inactive": resources.as_file( + resources.files(resource_package) / "images" / 'default_box.png' ), - "active": res.as_file( - res.files(resource_package) / "images" / 'default_box_hover.png' + "active": resources.as_file( + resources.files(resource_package) / "images" / 'default_box_hover.png' ), }, - "info_box_background": res.as_file( - res.files(resource_package) / "images" / 'default_box.png' + "info_box_background": resources.as_file( + resources.files(resource_package) / "images" / 'default_box.png' ), } From 45248892be7cd426a465306865c0c9cb2ee87af3 Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 10:40:30 +0800 Subject: [PATCH 03/11] fix bug --- src/pygamepopup/components/box_element.py | 2 +- src/pygamepopup/components/button.py | 2 +- src/pygamepopup/components/dynamic_button.py | 2 +- src/pygamepopup/components/image_button.py | 2 +- src/pygamepopup/components/text_element.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pygamepopup/components/box_element.py b/src/pygamepopup/components/box_element.py index a9fa39d..bdaa7e6 100644 --- a/src/pygamepopup/components/box_element.py +++ b/src/pygamepopup/components/box_element.py @@ -11,7 +11,7 @@ from .. import initialization from .._exceptions.wrong_initialization_exception import WrongInitializationException -from ..types import Position, Margin +from ..type_definitions import Position, Margin class BoxElement: diff --git a/src/pygamepopup/components/button.py b/src/pygamepopup/components/button.py index 1df7667..6d7e4c5 100644 --- a/src/pygamepopup/components/button.py +++ b/src/pygamepopup/components/button.py @@ -13,7 +13,7 @@ from .box_element import BoxElement from ..configuration import _default_sprites, _default_fonts, _default_colors from ..constants import BUTTON_SIZE -from ..types import Position, Margin +from ..type_definitions import Position, Margin class Button(BoxElement): diff --git a/src/pygamepopup/components/dynamic_button.py b/src/pygamepopup/components/dynamic_button.py index fa7dcba..72f2967 100644 --- a/src/pygamepopup/components/dynamic_button.py +++ b/src/pygamepopup/components/dynamic_button.py @@ -12,7 +12,7 @@ from ..configuration import _default_fonts from ..constants import WHITE, BUTTON_SIZE -from ..types import Position, Margin +from ..type_definitions import Position, Margin from .button import Button diff --git a/src/pygamepopup/components/image_button.py b/src/pygamepopup/components/image_button.py index fe707c5..ae06eca 100644 --- a/src/pygamepopup/components/image_button.py +++ b/src/pygamepopup/components/image_button.py @@ -13,7 +13,7 @@ from .button import Button from ..configuration import _default_sprites from ..constants import WHITE, MIDNIGHT_BLUE, IMAGE_BUTTON_SIZE -from ..types import Position, Margin +from ..type_definitions import Position, Margin class ImageButton(Button): diff --git a/src/pygamepopup/components/text_element.py b/src/pygamepopup/components/text_element.py index 882e849..1cea054 100644 --- a/src/pygamepopup/components/text_element.py +++ b/src/pygamepopup/components/text_element.py @@ -11,7 +11,7 @@ from ..configuration import _default_fonts from ..constants import WHITE from .box_element import BoxElement -from ..types import Position, Margin +from ..type_definitions import Position, Margin class TextElement(BoxElement): From 10bf4991eb7628f407a291944b109ffe3a55d09b Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 10:44:29 +0800 Subject: [PATCH 04/11] fix bugs --- src/pygamepopup/components/info_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pygamepopup/components/info_box.py b/src/pygamepopup/components/info_box.py index 9de2abd..396faf6 100644 --- a/src/pygamepopup/components/info_box.py +++ b/src/pygamepopup/components/info_box.py @@ -22,7 +22,7 @@ from .box_element import BoxElement from .text_element import TextElement from .button import Button -from ..types import Position +from ..type_definitions import Position class _Row: From 85396d2f728f2ea658bc5358f6ac017e41c72199 Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 12:40:35 +0800 Subject: [PATCH 05/11] solve bugs --- src/pygamepopup/components/button.py | 11 ++++++----- src/pygamepopup/components/image_button.py | 19 ++++++++++++------- src/pygamepopup/components/info_box.py | 4 +++- src/pygamepopup/configuration.py | 22 ++++++---------------- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/pygamepopup/components/button.py b/src/pygamepopup/components/button.py index 6d7e4c5..c90c6eb 100644 --- a/src/pygamepopup/components/button.py +++ b/src/pygamepopup/components/button.py @@ -7,6 +7,7 @@ import os.path from enum import Enum from typing import Union, Callable, Sequence +from importlib import resources import pygame @@ -154,11 +155,11 @@ def render_sprite( rendered_text_lines (Sequence[pygame.Surface]): the sequence of text lines in order that should be clipped on the surface. """ - raw_sprite = ( - pygame.image.load(background_path) - if background_path - else pygame.Surface((0, 0)) - ) + if background_path: + with resources.as_file(background_path) as path: + raw_sprite = pygame.image.load(path) + else: + raw_sprite = pygame.Surface((0, 0)) sprite = pygame.transform.scale(raw_sprite.convert_alpha(), self.size) text_lines_count = len(rendered_text_lines) diff --git a/src/pygamepopup/components/image_button.py b/src/pygamepopup/components/image_button.py index ae06eca..2822d32 100644 --- a/src/pygamepopup/components/image_button.py +++ b/src/pygamepopup/components/image_button.py @@ -7,6 +7,7 @@ import os from typing import Callable, Sequence +from importlib import resources import pygame @@ -96,7 +97,8 @@ def __init__( if frame_background_path else _default_sprites["button_background"]["inactive"] ) - raw_frame = pygame.image.load(frame_background_path) + with resources.as_file(frame_background_path) as path: + raw_frame = pygame.image.load(path) frame = pygame.transform.scale(raw_frame.convert_alpha(), frame_size) frame_background_hover_path = ( @@ -104,16 +106,18 @@ def __init__( if frame_background_hover_path else _default_sprites["button_background"]["active"] ) - raw_frame_hover = pygame.image.load(frame_background_hover_path) + with resources.as_file(frame_background_hover_path) as path: + raw_frame_hover = pygame.image.load(path) frame_hover = pygame.transform.scale( raw_frame_hover.convert_alpha(), frame_size ) if image_path: - image = pygame.transform.scale( - pygame.image.load(image_path), - (frame_size[0] - padding * 2, frame_size[1] - padding * 2), - ) + with resources.as_file(image_path) as path: + image = pygame.transform.scale( + pygame.image.load(path), + (frame_size[0] - padding * 2, frame_size[1] - padding * 2), + ) frame.blit(image, (padding, padding)) frame_hover.blit(image, (padding, padding)) @@ -136,7 +140,8 @@ def render_sprite( rendered_text_lines (Sequence[pygame.Surface]): the sequence of text lines in order that should be clipped on the surface """ - raw_sprite = pygame.image.load(background_path) + with resources.as_file(background_path) as path: + raw_sprite = pygame.image.load(path) sprite = pygame.transform.scale(raw_sprite.convert_alpha(), self.size) text_lines_count = len(rendered_text_lines) diff --git a/src/pygamepopup/components/info_box.py b/src/pygamepopup/components/info_box.py index 396faf6..dab0900 100644 --- a/src/pygamepopup/components/info_box.py +++ b/src/pygamepopup/components/info_box.py @@ -6,6 +6,7 @@ import os.path from typing import Union, Sequence, Callable, Optional +from importlib import resources import pygame @@ -108,7 +109,8 @@ def __init__( if background_path else _default_sprites["info_box_background"] ) - self.sprite: pygame.Surface = pygame.image.load(background_path) + with resources.as_file(background_path) as path: + self.sprite: pygame.Surface = pygame.image.load(path) self.close_button_text: str = ( close_button_text if close_button_text is not None diff --git a/src/pygamepopup/configuration.py b/src/pygamepopup/configuration.py index 27383b9..022bff6 100644 --- a/src/pygamepopup/configuration.py +++ b/src/pygamepopup/configuration.py @@ -13,28 +13,18 @@ from .constants import WHITE -resource_package = __name__ +resource_package = 'pygamepopup' _default_sprites: dict[str, Union[dict[str, str], str]] = { "button_background": { - "inactive": resources.as_file( - resources.files(resource_package) / "images" / 'default_box.png' - ), - "active": resources.as_file( - resources.files(resource_package) / "images" / 'default_box_hover.png' - ), + "inactive": resources.files(resource_package) / 'images' / 'default_box.png', + "active": resources.files(resource_package) / 'images' / 'default_box_hover.png', }, "dynamic_button_background": { - "inactive": resources.as_file( - resources.files(resource_package) / "images" / 'default_box.png' - ), - "active": resources.as_file( - resources.files(resource_package) / "images" / 'default_box_hover.png' - ), + "inactive": resources.files(resource_package) / 'images' / 'default_box.png', + "active": resources.files(resource_package) / 'images' / 'default_box_hover.png', }, - "info_box_background": resources.as_file( - resources.files(resource_package) / "images" / 'default_box.png' - ), + "info_box_background": resources.files(resource_package) / 'images' / 'default_box.png', } _default_fonts_description: dict[str, dict[str, any]] = { From c96b52bf1578c79fe62dfafffbd871332b7bbf63 Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 12:44:22 +0800 Subject: [PATCH 06/11] fix --- src/pygamepopup/configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pygamepopup/configuration.py b/src/pygamepopup/configuration.py index 022bff6..229550b 100644 --- a/src/pygamepopup/configuration.py +++ b/src/pygamepopup/configuration.py @@ -13,7 +13,7 @@ from .constants import WHITE -resource_package = 'pygamepopup' +resource_package = __name__ _default_sprites: dict[str, Union[dict[str, str], str]] = { "button_background": { From 1165043d7d2c7f118398b1421f4f443b70e743de Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 13:19:01 +0800 Subject: [PATCH 07/11] replace __name__ by __package__ --- src/pygamepopup/configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pygamepopup/configuration.py b/src/pygamepopup/configuration.py index 229550b..9cd1a18 100644 --- a/src/pygamepopup/configuration.py +++ b/src/pygamepopup/configuration.py @@ -13,7 +13,7 @@ from .constants import WHITE -resource_package = __name__ +resource_package = __package__ _default_sprites: dict[str, Union[dict[str, str], str]] = { "button_background": { From 4e24c7ec4013d4b0c8dad92e7a5d99ab8d946fc0 Mon Sep 17 00:00:00 2001 From: JimZhouZZY Date: Wed, 26 Jun 2024 13:25:23 +0800 Subject: [PATCH 08/11] Changes on docs --- .readthedocs.yaml | 2 +- CHANGELOG.txt | 3 +++ docs/source/api/{types.rst => type_definitions.rst} | 2 +- docs/source/conf.py | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) rename docs/source/api/{types.rst => type_definitions.rst} (52%) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index b6c970f..2a40ec7 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -3,7 +3,7 @@ version: 2 build: os: "ubuntu-20.04" tools: - python: "3.9" + python: "3.12" sphinx: fail_on_warning: true diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 09438ce..4c75bb0 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,6 @@ +-- VERSION 0.10.1 -- +* Update the code to support Python 3.12.4 + -- VERSION 0.10.0 -- * Add possibility for any BoxElement (i.e. button or text element) to take the space of multiple columns (column_span argument) diff --git a/docs/source/api/types.rst b/docs/source/api/type_definitions.rst similarity index 52% rename from docs/source/api/types.rst rename to docs/source/api/type_definitions.rst index f0d5b4c..f5637f2 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/type_definitions.rst @@ -1,7 +1,7 @@ Types ===== -.. automodule:: pygamepopup.types +.. automodule:: pygamepopup.type_definitions :members: :undoc-members: diff --git a/docs/source/conf.py b/docs/source/conf.py index d531299..d442e77 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -22,10 +22,10 @@ author = "Grimmys" # The full version, including alpha/beta/rc tags -release = "0.7.0" +release = "0.10.1" # The major version only -version = "0.7" +version = "0.10" # -- General configuration --------------------------------------------------- From d672fe40f8973be4752b2b40f3dac7451d138e68 Mon Sep 17 00:00:00 2001 From: Jim Zhou Date: Sat, 6 Jul 2024 14:28:16 +0800 Subject: [PATCH 09/11] Update conf.py --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d442e77..3ff07ba 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -22,10 +22,10 @@ author = "Grimmys" # The full version, including alpha/beta/rc tags -release = "0.10.1" +release = "0.11.0" # The major version only -version = "0.10" +version = "0.11" # -- General configuration --------------------------------------------------- From 67a7c9114d24498fbfb7064abad0601ed5212ee3 Mon Sep 17 00:00:00 2001 From: Jim Zhou Date: Sat, 6 Jul 2024 14:29:06 +0800 Subject: [PATCH 10/11] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5935053..221111f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pygame-popup", - version="0.10.1", + version="0.11.0", author="Grimmys", author_email="grimmys.programming@gmail.com", description="A popup manager for pygame", From c329c720264e5d1dd6b9e53fff02f83bd2033167 Mon Sep 17 00:00:00 2001 From: Jim Zhou Date: Sun, 7 Jul 2024 11:22:55 +0800 Subject: [PATCH 11/11] Update CHANGELOG.txt --- CHANGELOG.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4c75bb0..4d34897 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,4 @@ --- VERSION 0.10.1 -- +-- VERSION 0.11.0 -- * Update the code to support Python 3.12.4 -- VERSION 0.10.0 --