Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the code to support Python 3.12.4 #10

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: "ubuntu-20.04"
tools:
python: "3.9"
python: "3.12"

sphinx:
fail_on_warning: true
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- VERSION 0.11.0 --
* 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Types
=====

.. automodule:: pygamepopup.types
.. automodule:: pygamepopup.type_definitions
:members:
:undoc-members:

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
author = "Grimmys"

# The full version, including alpha/beta/rc tags
release = "0.7.0"
release = "0.11.0"

# The major version only
version = "0.7"
version = "0.11"


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pygame-popup",
version="0.10.0",
version="0.11.0",
author="Grimmys",
author_email="grimmys.programming@gmail.com",
description="A popup manager for pygame",
Expand All @@ -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"],
)
2 changes: 1 addition & 1 deletion src/pygamepopup/components/box_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions src/pygamepopup/components/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import os.path
from enum import Enum
from typing import Union, Callable, Sequence
from importlib import resources

import pygame

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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/pygamepopup/components/dynamic_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
21 changes: 13 additions & 8 deletions src/pygamepopup/components/image_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

import os
from typing import Callable, Sequence
from importlib import resources

import pygame

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):
Expand Down Expand Up @@ -96,24 +97,27 @@ 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 = (
os.path.abspath(frame_background_hover_path)
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))

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/pygamepopup/components/info_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os.path
from typing import Union, Sequence, Callable, Optional
from importlib import resources

import pygame

Expand All @@ -22,7 +23,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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pygamepopup/components/text_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 7 additions & 17 deletions src/pygamepopup/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,23 @@
from os.path import abspath
from typing import Union

import pkg_resources
from importlib import resources
import pygame

from .constants import WHITE

resource_package = __name__
resource_package = __package__

_default_sprites: dict[str, Union[dict[str, str], str]] = {
"button_background": {
"inactive": pkg_resources.resource_filename(
resource_package, "/".join(("images", "default_box.png"))
),
"active": pkg_resources.resource_filename(
resource_package, "/".join(("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": pkg_resources.resource_filename(
resource_package, "/".join(("images", "default_box.png"))
),
"active": pkg_resources.resource_filename(
resource_package, "/".join(("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": pkg_resources.resource_filename(
resource_package, "/".join(("images", "default_box.png"))
),
"info_box_background": resources.files(resource_package) / 'images' / 'default_box.png',
}

_default_fonts_description: dict[str, dict[str, any]] = {
Expand Down
2 changes: 1 addition & 1 deletion src/pygamepopup/menu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pygame

from .components.info_box import InfoBox
from .types import Position
from .type_definitions import Position


class MenuManager:
Expand Down
File renamed without changes.
Loading