|
6 | 6 | A menu for pygame. Simple, and easy to use. |
7 | 7 | """ |
8 | 8 |
|
9 | | -from __future__ import annotations |
10 | | - |
11 | | -__all__ = [ |
12 | | - # Common classes |
13 | | - "BaseImage", |
14 | | - "Menu", |
15 | | - "Sound", |
16 | | - "Theme", |
17 | | -] |
18 | | - |
19 | | -# Check if pygame exists, if not maybe the module is being used by setup.py |
20 | | -__pygame_version__ = None |
21 | | -try: |
22 | | - from pygame import version as __pygame_version__ |
23 | | - |
24 | | - __pygame_version__ = __pygame_version__.vernum |
25 | | -except (ModuleNotFoundError, ImportError): |
26 | | - pass |
27 | | - |
28 | | -# Import modules that require pygame |
29 | | -if __pygame_version__ is not None: |
30 | | - """ |
31 | | - BaseImage: Provides basic image loading and manipulation with pygame |
32 | | - """ |
33 | | - import pygame_menu.baseimage |
34 | | - from pygame_menu.baseimage import BaseImage |
35 | | - |
36 | | - """ |
37 | | - Controls: Default controls of menu object and key definition |
38 | | - """ |
39 | | - import pygame_menu.controls |
40 | | - |
41 | | - """ |
42 | | - Events: Menu events definition and locals |
43 | | - """ |
44 | | - import pygame_menu.events |
45 | | - |
46 | | - """ |
47 | | - Fonts: Menu fonts |
48 | | - """ |
49 | | - import pygame_menu.font |
50 | | - |
51 | | - """ |
52 | | - Locals: Local constants |
53 | | - """ |
54 | | - import pygame_menu.locals |
55 | | - |
56 | | - """ |
57 | | - Menu: Menu class |
58 | | - """ |
59 | | - from pygame_menu.menu import Menu |
60 | | - |
61 | | - """ |
62 | | - ScrollArea: Scrollarea class |
63 | | - """ |
64 | | - import pygame_menu._scrollarea |
65 | | - |
66 | | - """ |
67 | | - Sound: Sound class |
68 | | - """ |
69 | | - import pygame_menu.sound |
70 | | - from pygame_menu.sound import Sound |
| 9 | +import logging |
| 10 | +import os |
| 11 | +from datetime import datetime |
| 12 | +from importlib.metadata import PackageNotFoundError, metadata |
71 | 13 |
|
72 | | - """ |
73 | | - Themes: Menu themes |
74 | | - """ |
75 | | - import pygame_menu.themes |
76 | | - from pygame_menu.themes import Theme |
| 14 | +logger = logging.getLogger(__name__) |
77 | 15 |
|
78 | | - """ |
79 | | - Widgets: Menu widgets |
80 | | - """ |
81 | | - import pygame_menu.widgets |
| 16 | +__all__ = ["BaseImage", "Menu", "Sound", "Theme"] |
82 | 17 |
|
83 | | -""" |
84 | | -Version: Library version |
85 | | -""" |
86 | | -import pygame_menu.version |
| 18 | +# Metadata |
| 19 | +try: |
| 20 | + _meta = metadata("pygame-menu") |
| 21 | + __version__ = _meta.get("Version") |
| 22 | + __author__ = _meta.get("Author") |
| 23 | + __email__ = _meta.get("Author-email") |
| 24 | + __description__ = _meta.get("Summary") |
| 25 | + __license__ = _meta.get("License") |
| 26 | + __url__ = _meta.get("Home-page") |
| 27 | + __module_name__ = _meta.get("Name") |
| 28 | +except PackageNotFoundError: |
| 29 | + # Local fallback |
| 30 | + __version__ = "4.4.3" |
| 31 | + __author__ = "Pablo Pizarro R." |
| 32 | + |
| 33 | + __description__ = "A menu for pygame. Simple, and easy to use" |
| 34 | + __license__ = "MIT" |
| 35 | + __url__ = "https://pygame-menu.readthedocs.io" |
| 36 | + __module_name__ = "pygame-menu" |
| 37 | + |
| 38 | +# Extra metadata not provided by importlib |
| 39 | +__url_documentation__ = "https://pygame-menu.readthedocs.io" |
| 40 | +__url_source_code__ = "https://github.com/ppizarror/pygame-menu" |
| 41 | +__url_bug_tracker__ = "https://github.com/ppizarror/pygame-menu/issues" |
| 42 | +__keywords__ = "pygame menu menus gui widget input button pygame-menu image sound ui" |
| 43 | +__copyright__ = f"Copyright 2017-{datetime.now().year} Pablo Pizarro R." |
87 | 44 |
|
88 | | -""" |
89 | | -Metadata: Information about the project |
90 | | -""" |
91 | | -__author__ = "Pablo Pizarro R." |
92 | 45 | __contributors__ = [ |
93 | 46 | # Author |
94 | 47 | "ppizarror", |
|
116 | 69 | "werdeil", |
117 | 70 | "zPaw", |
118 | 71 | ] |
119 | | -__copyright__ = "Copyright 2017 Pablo Pizarro R. @ppizarror" |
120 | | -__description__ = "A menu for pygame. Simple, and easy to use" |
121 | | - |
122 | | -__keywords__ = "pygame menu menus gui widget input button pygame-menu image sound ui" |
123 | | -__license__ = "MIT" |
124 | | -__module_name__ = "pygame-menu" |
125 | | -__url__ = "https://pygame-menu.readthedocs.io" |
126 | | -__url_bug_tracker__ = "https://github.com/ppizarror/pygame-menu/issues" |
127 | | -__url_documentation__ = "https://pygame-menu.readthedocs.io" |
128 | | -__url_source_code__ = "https://github.com/ppizarror/pygame-menu" |
129 | | -__version__ = pygame_menu.version.ver |
130 | 72 |
|
131 | | -""" |
132 | | -Print pygame-menu version. |
133 | | -""" |
134 | | -import logging |
135 | | -import os |
| 73 | +# Pygame check |
| 74 | +__pygame_version__ = None |
| 75 | +try: |
| 76 | + from pygame import version as __pv |
136 | 77 |
|
137 | | -logger = logging.getLogger(__name__) |
| 78 | + __pygame_version__ = __pv.vernum |
| 79 | +except (ModuleNotFoundError, ImportError): |
| 80 | + # Pygame is not installed; skip pygame-dependent imports |
| 81 | + pass |
138 | 82 |
|
| 83 | +# Conditional imports |
| 84 | +if __pygame_version__ is not None: |
| 85 | + from pygame_menu import ( |
| 86 | + _scrollarea, |
| 87 | + baseimage, |
| 88 | + controls, |
| 89 | + events, |
| 90 | + font, |
| 91 | + locals, |
| 92 | + menu, |
| 93 | + sound, |
| 94 | + themes, |
| 95 | + widgets, |
| 96 | + ) |
| 97 | + |
| 98 | + BaseImage = baseimage.BaseImage |
| 99 | + Menu = menu.Menu |
| 100 | + Sound = sound.Sound |
| 101 | + Theme = themes.Theme |
| 102 | + |
| 103 | +# Version print |
139 | 104 | if ( |
140 | 105 | "PYGAME_MENU_HIDE_VERSION" not in os.environ |
141 | 106 | and "PYGAME_HIDE_SUPPORT_PROMPT" not in os.environ |
142 | 107 | ): |
143 | 108 | logger.info(f"{__module_name__} {__version__}") |
144 | | - |
145 | | -# Cleanup namespace |
146 | | -del os |
0 commit comments