PlayPy 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- playpy-0.2.1/LICENSE +21 -0
- playpy-0.2.1/PKG-INFO +191 -0
- playpy-0.2.1/README.md +158 -0
- playpy-0.2.1/pyproject.toml +23 -0
- playpy-0.2.1/setup.cfg +4 -0
- playpy-0.2.1/src/PlayPy.egg-info/PKG-INFO +191 -0
- playpy-0.2.1/src/PlayPy.egg-info/SOURCES.txt +15 -0
- playpy-0.2.1/src/PlayPy.egg-info/dependency_links.txt +1 -0
- playpy-0.2.1/src/PlayPy.egg-info/requires.txt +2 -0
- playpy-0.2.1/src/PlayPy.egg-info/top_level.txt +1 -0
- playpy-0.2.1/src/playpy/__init__.py +222 -0
- playpy-0.2.1/src/playpy/builtin.py +638 -0
- playpy-0.2.1/src/playpy/data/default_icon.ppm +5 -0
- playpy-0.2.1/src/playpy/elements.py +205 -0
- playpy-0.2.1/src/playpy/resources.py +147 -0
- playpy-0.2.1/src/playpy/state.py +565 -0
- playpy-0.2.1/src/playpy/workspace.py +432 -0
playpy-0.2.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Angel Ventura
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
playpy-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PlayPy
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.
|
|
5
|
+
Author-email: angel <angyv2861@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Angel Ventura
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Requires-Python: >=3.14
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pygame-ce>=2.5.6
|
|
31
|
+
Requires-Dist: colorama>=0.4.6
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# PlayPy (0.2.1)
|
|
35
|
+
|
|
36
|
+
PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
- Python `>=3.11`
|
|
41
|
+
- `pygame >=2.6.1`
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
To install PlayPy, enter the following line into your terminal: `pip install playpy`, or `python -m pip install playpy` if the first line does not work.
|
|
46
|
+
|
|
47
|
+
## Core Concepts
|
|
48
|
+
|
|
49
|
+
### Workspace
|
|
50
|
+
|
|
51
|
+
`Workspace` owns the window, render loop, input state, scene stack, and modal stack.
|
|
52
|
+
|
|
53
|
+
Key methods:
|
|
54
|
+
|
|
55
|
+
- `run()` starts runtime loop
|
|
56
|
+
- `quit()` stops runtime loop
|
|
57
|
+
- `queue_scene_change(scene)` replaces the current scene
|
|
58
|
+
- `queue_scene_push(scene)` / `queue_scene_pop()` stacks scenes
|
|
59
|
+
- `queue_modal_push(element)` / `queue_modal_pop()` manages overlays
|
|
60
|
+
|
|
61
|
+
### Layout Values
|
|
62
|
+
|
|
63
|
+
PlayPy uses two rectangle value types:
|
|
64
|
+
|
|
65
|
+
- `FRect(*args)`
|
|
66
|
+
Relative scale (fraction of parent rectangle).
|
|
67
|
+
- `Rect(*args)`
|
|
68
|
+
Absolute pixel offsets applied on top of scale.
|
|
69
|
+
- Overloads are: `x, y, w, h` \ `topleft, size` \ `(x, y, w, h)` \ `(topleft, size)`
|
|
70
|
+
|
|
71
|
+
Final element rect = `scale * parent_size + offset`.
|
|
72
|
+
|
|
73
|
+
### Parenting
|
|
74
|
+
|
|
75
|
+
Any `UIElement` can contain children. Assigning parent wires it automatically:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
child.parent = parent
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Or use helpers:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
parent.add_child(child)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You can use the `parent`, `ancestors`, `children`, and `descendants` properties to find ancestors or descendants of an element.
|
|
88
|
+
|
|
89
|
+
You can use other built-in methods to tell descendance:
|
|
90
|
+
- `is_parent_of(child)`, `is_child_of(parent)`
|
|
91
|
+
- `is_ancestor_of(descendant)`, `is_descendant_of(ancestor)`
|
|
92
|
+
|
|
93
|
+
## Built-in Elements
|
|
94
|
+
|
|
95
|
+
- `UIPanel`: colored rectangle container
|
|
96
|
+
- `UIScrollablePanel`: panel with wheel scrolling
|
|
97
|
+
- `UIText`: wrapped text rendering with alignment
|
|
98
|
+
- `UIButton`: clickable button with hover/pressed colors
|
|
99
|
+
- `UITextbox`: single-line text input with placeholder/caret
|
|
100
|
+
- `Scene`: root container for scene lifecycle
|
|
101
|
+
|
|
102
|
+
## Modifiers
|
|
103
|
+
|
|
104
|
+
Modifiers attach style/behavior to a single element.
|
|
105
|
+
|
|
106
|
+
- `UIPadding(scale=0, offset=10)` - Adds padding to the element.
|
|
107
|
+
- `UIOutline(color, width, edge_type)` - Adds an outline to the element.
|
|
108
|
+
- `UIBorderRadius(radius)` - Adds a border radius (rounded corners) to the element.
|
|
109
|
+
- `UIGradient(start_color, end_color, direction)` - Converts the background color of the element to a gradient.
|
|
110
|
+
- `UIFont(font_path=None, font_size=None, bold=None, italic=None, antialias=None)` - Changes the font of the text.
|
|
111
|
+
- `GlobalElement()` - If added to a `Workspace` descended element, makes this object shown and handled even when another scene is running.
|
|
112
|
+
|
|
113
|
+
Attach/get/remove:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
element.set_modifier(plp.UIOutline((0, 0, 0), 2, "middle"))
|
|
117
|
+
outline = element.get_modifier(plp.UIOutline)
|
|
118
|
+
element.remove_modifier(plp.UIOutline)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Event Helpers
|
|
122
|
+
|
|
123
|
+
Decorator helpers create `Event` elements attached to a workspace, scene, or element.
|
|
124
|
+
|
|
125
|
+
- `@on_start(target)` - Runs when the scene/workspace starts running/
|
|
126
|
+
- `@on_update(target)`
|
|
127
|
+
- `@on_quit(target)`
|
|
128
|
+
- `@on_scene_change(target)`
|
|
129
|
+
- `@on_modal_change(target)`
|
|
130
|
+
- `@create_event(target, condition)` for custom conditions
|
|
131
|
+
|
|
132
|
+
Events created on the main workspace will trigger in all scenes. Pass in `global_event=false` to disable this.
|
|
133
|
+
|
|
134
|
+
Example:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
@plp.on_update(ws)
|
|
138
|
+
def tick(w: plp.Workspace):
|
|
139
|
+
if plp.Key.ESCAPE in w.input.key_downs:
|
|
140
|
+
w.quit()
|
|
141
|
+
|
|
142
|
+
@plp.on_update(ws, global_event=false)
|
|
143
|
+
def tick(w: plp.Workspace):
|
|
144
|
+
if plp.Key.UP in w.input.key_downs:
|
|
145
|
+
w.push_scene(s)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Scene and Modal Behavior
|
|
149
|
+
|
|
150
|
+
- If a modal is active, input is only routed to the modal tree
|
|
151
|
+
- Scene descendants are clipped to the scene rectangle for both drawing and hit-testing
|
|
152
|
+
- `Workspace` tracks scene/modal transitions with:
|
|
153
|
+
- `current_scene`, `previous_scene`, `scene_changed`
|
|
154
|
+
- `current_modal`, `previous_modal`, `modal_changed`
|
|
155
|
+
- Scenes can implement lifecycle hooks:
|
|
156
|
+
- `on_enter`, `on_exit`, `on_pause`, `on_resume`
|
|
157
|
+
|
|
158
|
+
## Input State
|
|
159
|
+
|
|
160
|
+
Read per-frame input from `workspace.input`:
|
|
161
|
+
|
|
162
|
+
- `keys_pressed`, `key_downs`, `key_ups` contain `plp.Key` values
|
|
163
|
+
- `mouse_buttons_pressed`, `mouse_downs`, `mouse_ups` contain `plp.MouseButton` values
|
|
164
|
+
- `mouse_pos`, `mouse_delta`, `mouse_wheel`
|
|
165
|
+
- `text_input`
|
|
166
|
+
- `dt`, `runtime`, `quit`
|
|
167
|
+
- `key_held(key)`, `key_up(key)`, `key_down(key)`
|
|
168
|
+
- `mousebutton_held(mb)`, `mousebutton_up(mb)`, `mousebutton_down(mb)`
|
|
169
|
+
|
|
170
|
+
### Hover State
|
|
171
|
+
|
|
172
|
+
You can check the hovered objects and top hovered object using the helper methods in `Workspace`.
|
|
173
|
+
|
|
174
|
+
- `is_mouse_top(element)`, `just_hovered(element)`, `just_unhovered(element)` are for checking only the top hovered object.
|
|
175
|
+
- `is_mouse_over(element)`, `just_hovered_inclusive(element)`, `just_unhovered_inclusive(element)` are for checking all of the hovered objects.
|
|
176
|
+
|
|
177
|
+
event helpers come with these too.
|
|
178
|
+
|
|
179
|
+
- `@on_hover(scope, hovered)`, `@on_unhover(scope, hovered)`, `while_hovered(scope, hovered)` for only top.
|
|
180
|
+
- `@on_hover_inclusive(scope, hovered)`, `@on_unhover_inclusive(scope, hovered)`, `while_hovered_inclusive(scope, hovered)` for all.
|
|
181
|
+
|
|
182
|
+
These are useful because they can then be used to check if the user is clicking an object
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
obj = plp.UIPanel(plp.FRect(1, 1, 0, 0), plp.empty_rect(), (0, 0, 0))
|
|
186
|
+
|
|
187
|
+
@while_hovered(ws, obj)
|
|
188
|
+
def click_check(w: plp.Workspace):
|
|
189
|
+
if w.input.mousebutton_down(plp.MouseButton.LEFT):
|
|
190
|
+
print("LMB down!")
|
|
191
|
+
```
|
playpy-0.2.1/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# PlayPy (0.2.1)
|
|
2
|
+
|
|
3
|
+
PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Python `>=3.11`
|
|
8
|
+
- `pygame >=2.6.1`
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
To install PlayPy, enter the following line into your terminal: `pip install playpy`, or `python -m pip install playpy` if the first line does not work.
|
|
13
|
+
|
|
14
|
+
## Core Concepts
|
|
15
|
+
|
|
16
|
+
### Workspace
|
|
17
|
+
|
|
18
|
+
`Workspace` owns the window, render loop, input state, scene stack, and modal stack.
|
|
19
|
+
|
|
20
|
+
Key methods:
|
|
21
|
+
|
|
22
|
+
- `run()` starts runtime loop
|
|
23
|
+
- `quit()` stops runtime loop
|
|
24
|
+
- `queue_scene_change(scene)` replaces the current scene
|
|
25
|
+
- `queue_scene_push(scene)` / `queue_scene_pop()` stacks scenes
|
|
26
|
+
- `queue_modal_push(element)` / `queue_modal_pop()` manages overlays
|
|
27
|
+
|
|
28
|
+
### Layout Values
|
|
29
|
+
|
|
30
|
+
PlayPy uses two rectangle value types:
|
|
31
|
+
|
|
32
|
+
- `FRect(*args)`
|
|
33
|
+
Relative scale (fraction of parent rectangle).
|
|
34
|
+
- `Rect(*args)`
|
|
35
|
+
Absolute pixel offsets applied on top of scale.
|
|
36
|
+
- Overloads are: `x, y, w, h` \ `topleft, size` \ `(x, y, w, h)` \ `(topleft, size)`
|
|
37
|
+
|
|
38
|
+
Final element rect = `scale * parent_size + offset`.
|
|
39
|
+
|
|
40
|
+
### Parenting
|
|
41
|
+
|
|
42
|
+
Any `UIElement` can contain children. Assigning parent wires it automatically:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
child.parent = parent
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or use helpers:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
parent.add_child(child)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
You can use the `parent`, `ancestors`, `children`, and `descendants` properties to find ancestors or descendants of an element.
|
|
55
|
+
|
|
56
|
+
You can use other built-in methods to tell descendance:
|
|
57
|
+
- `is_parent_of(child)`, `is_child_of(parent)`
|
|
58
|
+
- `is_ancestor_of(descendant)`, `is_descendant_of(ancestor)`
|
|
59
|
+
|
|
60
|
+
## Built-in Elements
|
|
61
|
+
|
|
62
|
+
- `UIPanel`: colored rectangle container
|
|
63
|
+
- `UIScrollablePanel`: panel with wheel scrolling
|
|
64
|
+
- `UIText`: wrapped text rendering with alignment
|
|
65
|
+
- `UIButton`: clickable button with hover/pressed colors
|
|
66
|
+
- `UITextbox`: single-line text input with placeholder/caret
|
|
67
|
+
- `Scene`: root container for scene lifecycle
|
|
68
|
+
|
|
69
|
+
## Modifiers
|
|
70
|
+
|
|
71
|
+
Modifiers attach style/behavior to a single element.
|
|
72
|
+
|
|
73
|
+
- `UIPadding(scale=0, offset=10)` - Adds padding to the element.
|
|
74
|
+
- `UIOutline(color, width, edge_type)` - Adds an outline to the element.
|
|
75
|
+
- `UIBorderRadius(radius)` - Adds a border radius (rounded corners) to the element.
|
|
76
|
+
- `UIGradient(start_color, end_color, direction)` - Converts the background color of the element to a gradient.
|
|
77
|
+
- `UIFont(font_path=None, font_size=None, bold=None, italic=None, antialias=None)` - Changes the font of the text.
|
|
78
|
+
- `GlobalElement()` - If added to a `Workspace` descended element, makes this object shown and handled even when another scene is running.
|
|
79
|
+
|
|
80
|
+
Attach/get/remove:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
element.set_modifier(plp.UIOutline((0, 0, 0), 2, "middle"))
|
|
84
|
+
outline = element.get_modifier(plp.UIOutline)
|
|
85
|
+
element.remove_modifier(plp.UIOutline)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Event Helpers
|
|
89
|
+
|
|
90
|
+
Decorator helpers create `Event` elements attached to a workspace, scene, or element.
|
|
91
|
+
|
|
92
|
+
- `@on_start(target)` - Runs when the scene/workspace starts running/
|
|
93
|
+
- `@on_update(target)`
|
|
94
|
+
- `@on_quit(target)`
|
|
95
|
+
- `@on_scene_change(target)`
|
|
96
|
+
- `@on_modal_change(target)`
|
|
97
|
+
- `@create_event(target, condition)` for custom conditions
|
|
98
|
+
|
|
99
|
+
Events created on the main workspace will trigger in all scenes. Pass in `global_event=false` to disable this.
|
|
100
|
+
|
|
101
|
+
Example:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
@plp.on_update(ws)
|
|
105
|
+
def tick(w: plp.Workspace):
|
|
106
|
+
if plp.Key.ESCAPE in w.input.key_downs:
|
|
107
|
+
w.quit()
|
|
108
|
+
|
|
109
|
+
@plp.on_update(ws, global_event=false)
|
|
110
|
+
def tick(w: plp.Workspace):
|
|
111
|
+
if plp.Key.UP in w.input.key_downs:
|
|
112
|
+
w.push_scene(s)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Scene and Modal Behavior
|
|
116
|
+
|
|
117
|
+
- If a modal is active, input is only routed to the modal tree
|
|
118
|
+
- Scene descendants are clipped to the scene rectangle for both drawing and hit-testing
|
|
119
|
+
- `Workspace` tracks scene/modal transitions with:
|
|
120
|
+
- `current_scene`, `previous_scene`, `scene_changed`
|
|
121
|
+
- `current_modal`, `previous_modal`, `modal_changed`
|
|
122
|
+
- Scenes can implement lifecycle hooks:
|
|
123
|
+
- `on_enter`, `on_exit`, `on_pause`, `on_resume`
|
|
124
|
+
|
|
125
|
+
## Input State
|
|
126
|
+
|
|
127
|
+
Read per-frame input from `workspace.input`:
|
|
128
|
+
|
|
129
|
+
- `keys_pressed`, `key_downs`, `key_ups` contain `plp.Key` values
|
|
130
|
+
- `mouse_buttons_pressed`, `mouse_downs`, `mouse_ups` contain `plp.MouseButton` values
|
|
131
|
+
- `mouse_pos`, `mouse_delta`, `mouse_wheel`
|
|
132
|
+
- `text_input`
|
|
133
|
+
- `dt`, `runtime`, `quit`
|
|
134
|
+
- `key_held(key)`, `key_up(key)`, `key_down(key)`
|
|
135
|
+
- `mousebutton_held(mb)`, `mousebutton_up(mb)`, `mousebutton_down(mb)`
|
|
136
|
+
|
|
137
|
+
### Hover State
|
|
138
|
+
|
|
139
|
+
You can check the hovered objects and top hovered object using the helper methods in `Workspace`.
|
|
140
|
+
|
|
141
|
+
- `is_mouse_top(element)`, `just_hovered(element)`, `just_unhovered(element)` are for checking only the top hovered object.
|
|
142
|
+
- `is_mouse_over(element)`, `just_hovered_inclusive(element)`, `just_unhovered_inclusive(element)` are for checking all of the hovered objects.
|
|
143
|
+
|
|
144
|
+
event helpers come with these too.
|
|
145
|
+
|
|
146
|
+
- `@on_hover(scope, hovered)`, `@on_unhover(scope, hovered)`, `while_hovered(scope, hovered)` for only top.
|
|
147
|
+
- `@on_hover_inclusive(scope, hovered)`, `@on_unhover_inclusive(scope, hovered)`, `while_hovered_inclusive(scope, hovered)` for all.
|
|
148
|
+
|
|
149
|
+
These are useful because they can then be used to check if the user is clicking an object
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
obj = plp.UIPanel(plp.FRect(1, 1, 0, 0), plp.empty_rect(), (0, 0, 0))
|
|
153
|
+
|
|
154
|
+
@while_hovered(ws, obj)
|
|
155
|
+
def click_check(w: plp.Workspace):
|
|
156
|
+
if w.input.mousebutton_down(plp.MouseButton.LEFT):
|
|
157
|
+
print("LMB down!")
|
|
158
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "PlayPy"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.14"
|
|
11
|
+
dependencies = ["pygame-ce>=2.5.6", "colorama>=0.4.6"]
|
|
12
|
+
authors = [{name = "angel", email = "angyv2861@gmail.com"}]
|
|
13
|
+
license = { file = "LICENSE" }
|
|
14
|
+
|
|
15
|
+
[tool.setuptools]
|
|
16
|
+
package-dir = {"" = "src"}
|
|
17
|
+
include-package-data = true
|
|
18
|
+
|
|
19
|
+
[tool.setuptools.packages.find]
|
|
20
|
+
where = ["src"]
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.package-data]
|
|
23
|
+
"playpy.data" = ["default_icon.ppm", "fonts/*"]
|
playpy-0.2.1/setup.cfg
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PlayPy
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.
|
|
5
|
+
Author-email: angel <angyv2861@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Angel Ventura
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Requires-Python: >=3.14
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pygame-ce>=2.5.6
|
|
31
|
+
Requires-Dist: colorama>=0.4.6
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# PlayPy (0.2.1)
|
|
35
|
+
|
|
36
|
+
PlayPy is a lightweight Python library for creating simple games and interactive applications with ease. It provides a straightforward API for handling graphics, input, and basic game mechanics, making it ideal for beginners and those looking to quickly prototype their ideas.
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
- Python `>=3.11`
|
|
41
|
+
- `pygame >=2.6.1`
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
To install PlayPy, enter the following line into your terminal: `pip install playpy`, or `python -m pip install playpy` if the first line does not work.
|
|
46
|
+
|
|
47
|
+
## Core Concepts
|
|
48
|
+
|
|
49
|
+
### Workspace
|
|
50
|
+
|
|
51
|
+
`Workspace` owns the window, render loop, input state, scene stack, and modal stack.
|
|
52
|
+
|
|
53
|
+
Key methods:
|
|
54
|
+
|
|
55
|
+
- `run()` starts runtime loop
|
|
56
|
+
- `quit()` stops runtime loop
|
|
57
|
+
- `queue_scene_change(scene)` replaces the current scene
|
|
58
|
+
- `queue_scene_push(scene)` / `queue_scene_pop()` stacks scenes
|
|
59
|
+
- `queue_modal_push(element)` / `queue_modal_pop()` manages overlays
|
|
60
|
+
|
|
61
|
+
### Layout Values
|
|
62
|
+
|
|
63
|
+
PlayPy uses two rectangle value types:
|
|
64
|
+
|
|
65
|
+
- `FRect(*args)`
|
|
66
|
+
Relative scale (fraction of parent rectangle).
|
|
67
|
+
- `Rect(*args)`
|
|
68
|
+
Absolute pixel offsets applied on top of scale.
|
|
69
|
+
- Overloads are: `x, y, w, h` \ `topleft, size` \ `(x, y, w, h)` \ `(topleft, size)`
|
|
70
|
+
|
|
71
|
+
Final element rect = `scale * parent_size + offset`.
|
|
72
|
+
|
|
73
|
+
### Parenting
|
|
74
|
+
|
|
75
|
+
Any `UIElement` can contain children. Assigning parent wires it automatically:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
child.parent = parent
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Or use helpers:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
parent.add_child(child)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You can use the `parent`, `ancestors`, `children`, and `descendants` properties to find ancestors or descendants of an element.
|
|
88
|
+
|
|
89
|
+
You can use other built-in methods to tell descendance:
|
|
90
|
+
- `is_parent_of(child)`, `is_child_of(parent)`
|
|
91
|
+
- `is_ancestor_of(descendant)`, `is_descendant_of(ancestor)`
|
|
92
|
+
|
|
93
|
+
## Built-in Elements
|
|
94
|
+
|
|
95
|
+
- `UIPanel`: colored rectangle container
|
|
96
|
+
- `UIScrollablePanel`: panel with wheel scrolling
|
|
97
|
+
- `UIText`: wrapped text rendering with alignment
|
|
98
|
+
- `UIButton`: clickable button with hover/pressed colors
|
|
99
|
+
- `UITextbox`: single-line text input with placeholder/caret
|
|
100
|
+
- `Scene`: root container for scene lifecycle
|
|
101
|
+
|
|
102
|
+
## Modifiers
|
|
103
|
+
|
|
104
|
+
Modifiers attach style/behavior to a single element.
|
|
105
|
+
|
|
106
|
+
- `UIPadding(scale=0, offset=10)` - Adds padding to the element.
|
|
107
|
+
- `UIOutline(color, width, edge_type)` - Adds an outline to the element.
|
|
108
|
+
- `UIBorderRadius(radius)` - Adds a border radius (rounded corners) to the element.
|
|
109
|
+
- `UIGradient(start_color, end_color, direction)` - Converts the background color of the element to a gradient.
|
|
110
|
+
- `UIFont(font_path=None, font_size=None, bold=None, italic=None, antialias=None)` - Changes the font of the text.
|
|
111
|
+
- `GlobalElement()` - If added to a `Workspace` descended element, makes this object shown and handled even when another scene is running.
|
|
112
|
+
|
|
113
|
+
Attach/get/remove:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
element.set_modifier(plp.UIOutline((0, 0, 0), 2, "middle"))
|
|
117
|
+
outline = element.get_modifier(plp.UIOutline)
|
|
118
|
+
element.remove_modifier(plp.UIOutline)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Event Helpers
|
|
122
|
+
|
|
123
|
+
Decorator helpers create `Event` elements attached to a workspace, scene, or element.
|
|
124
|
+
|
|
125
|
+
- `@on_start(target)` - Runs when the scene/workspace starts running/
|
|
126
|
+
- `@on_update(target)`
|
|
127
|
+
- `@on_quit(target)`
|
|
128
|
+
- `@on_scene_change(target)`
|
|
129
|
+
- `@on_modal_change(target)`
|
|
130
|
+
- `@create_event(target, condition)` for custom conditions
|
|
131
|
+
|
|
132
|
+
Events created on the main workspace will trigger in all scenes. Pass in `global_event=false` to disable this.
|
|
133
|
+
|
|
134
|
+
Example:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
@plp.on_update(ws)
|
|
138
|
+
def tick(w: plp.Workspace):
|
|
139
|
+
if plp.Key.ESCAPE in w.input.key_downs:
|
|
140
|
+
w.quit()
|
|
141
|
+
|
|
142
|
+
@plp.on_update(ws, global_event=false)
|
|
143
|
+
def tick(w: plp.Workspace):
|
|
144
|
+
if plp.Key.UP in w.input.key_downs:
|
|
145
|
+
w.push_scene(s)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Scene and Modal Behavior
|
|
149
|
+
|
|
150
|
+
- If a modal is active, input is only routed to the modal tree
|
|
151
|
+
- Scene descendants are clipped to the scene rectangle for both drawing and hit-testing
|
|
152
|
+
- `Workspace` tracks scene/modal transitions with:
|
|
153
|
+
- `current_scene`, `previous_scene`, `scene_changed`
|
|
154
|
+
- `current_modal`, `previous_modal`, `modal_changed`
|
|
155
|
+
- Scenes can implement lifecycle hooks:
|
|
156
|
+
- `on_enter`, `on_exit`, `on_pause`, `on_resume`
|
|
157
|
+
|
|
158
|
+
## Input State
|
|
159
|
+
|
|
160
|
+
Read per-frame input from `workspace.input`:
|
|
161
|
+
|
|
162
|
+
- `keys_pressed`, `key_downs`, `key_ups` contain `plp.Key` values
|
|
163
|
+
- `mouse_buttons_pressed`, `mouse_downs`, `mouse_ups` contain `plp.MouseButton` values
|
|
164
|
+
- `mouse_pos`, `mouse_delta`, `mouse_wheel`
|
|
165
|
+
- `text_input`
|
|
166
|
+
- `dt`, `runtime`, `quit`
|
|
167
|
+
- `key_held(key)`, `key_up(key)`, `key_down(key)`
|
|
168
|
+
- `mousebutton_held(mb)`, `mousebutton_up(mb)`, `mousebutton_down(mb)`
|
|
169
|
+
|
|
170
|
+
### Hover State
|
|
171
|
+
|
|
172
|
+
You can check the hovered objects and top hovered object using the helper methods in `Workspace`.
|
|
173
|
+
|
|
174
|
+
- `is_mouse_top(element)`, `just_hovered(element)`, `just_unhovered(element)` are for checking only the top hovered object.
|
|
175
|
+
- `is_mouse_over(element)`, `just_hovered_inclusive(element)`, `just_unhovered_inclusive(element)` are for checking all of the hovered objects.
|
|
176
|
+
|
|
177
|
+
event helpers come with these too.
|
|
178
|
+
|
|
179
|
+
- `@on_hover(scope, hovered)`, `@on_unhover(scope, hovered)`, `while_hovered(scope, hovered)` for only top.
|
|
180
|
+
- `@on_hover_inclusive(scope, hovered)`, `@on_unhover_inclusive(scope, hovered)`, `while_hovered_inclusive(scope, hovered)` for all.
|
|
181
|
+
|
|
182
|
+
These are useful because they can then be used to check if the user is clicking an object
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
obj = plp.UIPanel(plp.FRect(1, 1, 0, 0), plp.empty_rect(), (0, 0, 0))
|
|
186
|
+
|
|
187
|
+
@while_hovered(ws, obj)
|
|
188
|
+
def click_check(w: plp.Workspace):
|
|
189
|
+
if w.input.mousebutton_down(plp.MouseButton.LEFT):
|
|
190
|
+
print("LMB down!")
|
|
191
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/PlayPy.egg-info/PKG-INFO
|
|
5
|
+
src/PlayPy.egg-info/SOURCES.txt
|
|
6
|
+
src/PlayPy.egg-info/dependency_links.txt
|
|
7
|
+
src/PlayPy.egg-info/requires.txt
|
|
8
|
+
src/PlayPy.egg-info/top_level.txt
|
|
9
|
+
src/playpy/__init__.py
|
|
10
|
+
src/playpy/builtin.py
|
|
11
|
+
src/playpy/elements.py
|
|
12
|
+
src/playpy/resources.py
|
|
13
|
+
src/playpy/state.py
|
|
14
|
+
src/playpy/workspace.py
|
|
15
|
+
src/playpy/data/default_icon.ppm
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
playpy
|