vali-ui 1.1.0__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.
- vali_ui-1.1.0/CHANGELOG.md +13 -0
- vali_ui-1.1.0/LICENSE +17 -0
- vali_ui-1.1.0/MANIFEST.in +5 -0
- vali_ui-1.1.0/PKG-INFO +145 -0
- vali_ui-1.1.0/README.md +116 -0
- vali_ui-1.1.0/examples/showcase.py +36 -0
- vali_ui-1.1.0/pyproject.toml +42 -0
- vali_ui-1.1.0/setup.cfg +4 -0
- vali_ui-1.1.0/tests/test_core.py +42 -0
- vali_ui-1.1.0/tests/test_non_graphical.py +29 -0
- vali_ui-1.1.0/tests/test_public_api.py +48 -0
- vali_ui-1.1.0/vali/__init__.py +24 -0
- vali_ui-1.1.0/vali/core/__init__.py +0 -0
- vali_ui-1.1.0/vali/core/app.py +49 -0
- vali_ui-1.1.0/vali/core/events.py +25 -0
- vali_ui-1.1.0/vali/core/window.py +155 -0
- vali_ui-1.1.0/vali/graphics/__init__.py +2 -0
- vali_ui-1.1.0/vali/graphics/animation.py +42 -0
- vali_ui-1.1.0/vali/layouts/__init__.py +2 -0
- vali_ui-1.1.0/vali/layouts/basic.py +151 -0
- vali_ui-1.1.0/vali/screens/__init__.py +2 -0
- vali_ui-1.1.0/vali/screens/screen.py +49 -0
- vali_ui-1.1.0/vali/themes/__init__.py +14 -0
- vali_ui-1.1.0/vali/utils/__init__.py +2 -0
- vali_ui-1.1.0/vali/utils/resources.py +27 -0
- vali_ui-1.1.0/vali/widgets/__init__.py +10 -0
- vali_ui-1.1.0/vali/widgets/base.py +27 -0
- vali_ui-1.1.0/vali/widgets/button.py +50 -0
- vali_ui-1.1.0/vali/widgets/display.py +80 -0
- vali_ui-1.1.0/vali/widgets/inputs.py +295 -0
- vali_ui-1.1.0/vali/widgets/label.py +33 -0
- vali_ui-1.1.0/vali_ui.egg-info/PKG-INFO +145 -0
- vali_ui-1.1.0/vali_ui.egg-info/SOURCES.txt +35 -0
- vali_ui-1.1.0/vali_ui.egg-info/dependency_links.txt +1 -0
- vali_ui-1.1.0/vali_ui.egg-info/requires.txt +7 -0
- vali_ui-1.1.0/vali_ui.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
- Added `Dropdown` and `RadioGroup` selection widgets.
|
|
6
|
+
- Added editable text cursor navigation, Home/End, Delete, password display, and `set_value()`.
|
|
7
|
+
- Added positional window dimensions: `create_window("Title", 800, 600)`.
|
|
8
|
+
- Kept compatibility with `create_window("Title", size=(800, 600))`.
|
|
9
|
+
- Added runtime theme/background changes and minimum resizable-window dimensions.
|
|
10
|
+
- Replaced the placeholder `AnchorLayout` with nine real anchor positions.
|
|
11
|
+
- Added `Label.set_text()` / `Label.set_color()` and intrinsic label/image dimensions.
|
|
12
|
+
- Improved validation, widget event handling, window closing, and documentation.
|
|
13
|
+
- Updated distribution metadata for the independent `vali-ui` package.
|
vali_ui-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eyal Laros
|
|
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.
|
vali_ui-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vali-ui
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: VALI - a lightweight Python desktop UI framework
|
|
5
|
+
Author: Eyal Laros
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: gui,ui,pygame,desktop,widgets,framework
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Win32 (MS Windows)
|
|
10
|
+
Classifier: Environment :: X11 Applications
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pygame>=2.5
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
26
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
27
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# VALI 1.1.0
|
|
31
|
+
|
|
32
|
+
**VALI** is a small Python desktop UI framework. It uses Pygame internally, but application code works with VALI classes and does not need to import Pygame.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
The intended package-install command after the first PyPI publication is:
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
py -m pip install vali-ui
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The Python import name is `vali`:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import vali
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> The Python import name is `vali`, while the PyPI distribution name is `vali-ui`.
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import vali
|
|
54
|
+
|
|
55
|
+
app = vali.App()
|
|
56
|
+
app.create_window("My first VALI app", 900, 600, theme="dark")
|
|
57
|
+
|
|
58
|
+
app.add(vali.Label("Hello from VALI", 30, 30, size=34))
|
|
59
|
+
app.add(vali.Button("Click me", 30, 100, on_click=lambda: print("Clicked!")))
|
|
60
|
+
app.add(vali.TextInput(30, 170, placeholder="Type something..."))
|
|
61
|
+
|
|
62
|
+
app.run()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
You can also use the older size-pair style:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
app.create_window("My app", size=(900, 600))
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Window options
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
app.create_window(
|
|
75
|
+
"My app",
|
|
76
|
+
1000,
|
|
77
|
+
700,
|
|
78
|
+
icon="assets/app.png",
|
|
79
|
+
theme="dark",
|
|
80
|
+
resizable=True,
|
|
81
|
+
min_size=(480, 320),
|
|
82
|
+
fps=60,
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `icon` accepts an image path or a Pygame `Surface` (only if your own code already uses Pygame).
|
|
87
|
+
- If no icon is supplied, VALI draws its own simple V icon; it does not use the Pygame snake icon.
|
|
88
|
+
- `window.set_icon(path)` changes the icon after creation.
|
|
89
|
+
- `window.set_theme("light")`, `window.set_theme("dark")`, or `app.set_theme(...)` changes the window theme/background.
|
|
90
|
+
- `window.set_background((r, g, b))` sets a custom background color.
|
|
91
|
+
|
|
92
|
+
## Included components
|
|
93
|
+
|
|
94
|
+
### Core
|
|
95
|
+
|
|
96
|
+
- `App`, `Window`, `Event`
|
|
97
|
+
- Window sizing, resize minimums, FPS cap, custom icon, close handling
|
|
98
|
+
- Multiple screens using `Screen` and `ScreenManager`
|
|
99
|
+
|
|
100
|
+
### Widgets
|
|
101
|
+
|
|
102
|
+
- `Label`, `Button`
|
|
103
|
+
- `TextInput` (cursor movement, Home/End, Backspace/Delete, max length, password display)
|
|
104
|
+
- `Checkbox`, `Switch`, `Slider`
|
|
105
|
+
- `Dropdown`, `RadioGroup`
|
|
106
|
+
- `Image`, `ProgressBar`, `Panel`
|
|
107
|
+
|
|
108
|
+
### Layouts
|
|
109
|
+
|
|
110
|
+
- `VerticalLayout`, `HorizontalLayout`, `GridLayout`
|
|
111
|
+
- `AnchorLayout` with nine anchor positions (`top_left`, `center`, `bottom_right`, etc.)
|
|
112
|
+
- Nested layouts and panels
|
|
113
|
+
|
|
114
|
+
### Utilities
|
|
115
|
+
|
|
116
|
+
- `Theme`, `DARK`, `LIGHT`
|
|
117
|
+
- `Animation`, `fade`, `slide`
|
|
118
|
+
- `ResourceManager` for image/font caching
|
|
119
|
+
|
|
120
|
+
## Examples
|
|
121
|
+
|
|
122
|
+
Run the showcase after installing the development copy or from the source folder:
|
|
123
|
+
|
|
124
|
+
```powershell
|
|
125
|
+
py examples\showcase.py
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Development / build
|
|
129
|
+
|
|
130
|
+
```powershell
|
|
131
|
+
py -m pip install -e ".[dev]"
|
|
132
|
+
py -m pytest
|
|
133
|
+
py -m build
|
|
134
|
+
py -m twine check dist\*
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The project distribution name is `vali-ui`; the import package remains `vali`.
|
|
138
|
+
|
|
139
|
+
## Version 1.1.0 scope
|
|
140
|
+
|
|
141
|
+
VALI 1.1.0 is a desktop 2D UI foundation. It is not a native-widget toolkit and does not claim full mobile support, screen-reader accessibility, advanced constraint-based responsive layouts, or a full-featured text editor. Those are separate engineering milestones rather than hidden promises.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT. See `LICENSE`.
|
vali_ui-1.1.0/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# VALI 1.1.0
|
|
2
|
+
|
|
3
|
+
**VALI** is a small Python desktop UI framework. It uses Pygame internally, but application code works with VALI classes and does not need to import Pygame.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
The intended package-install command after the first PyPI publication is:
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
py -m pip install vali-ui
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The Python import name is `vali`:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import vali
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
> The Python import name is `vali`, while the PyPI distribution name is `vali-ui`.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import vali
|
|
25
|
+
|
|
26
|
+
app = vali.App()
|
|
27
|
+
app.create_window("My first VALI app", 900, 600, theme="dark")
|
|
28
|
+
|
|
29
|
+
app.add(vali.Label("Hello from VALI", 30, 30, size=34))
|
|
30
|
+
app.add(vali.Button("Click me", 30, 100, on_click=lambda: print("Clicked!")))
|
|
31
|
+
app.add(vali.TextInput(30, 170, placeholder="Type something..."))
|
|
32
|
+
|
|
33
|
+
app.run()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can also use the older size-pair style:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
app.create_window("My app", size=(900, 600))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Window options
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
app.create_window(
|
|
46
|
+
"My app",
|
|
47
|
+
1000,
|
|
48
|
+
700,
|
|
49
|
+
icon="assets/app.png",
|
|
50
|
+
theme="dark",
|
|
51
|
+
resizable=True,
|
|
52
|
+
min_size=(480, 320),
|
|
53
|
+
fps=60,
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- `icon` accepts an image path or a Pygame `Surface` (only if your own code already uses Pygame).
|
|
58
|
+
- If no icon is supplied, VALI draws its own simple V icon; it does not use the Pygame snake icon.
|
|
59
|
+
- `window.set_icon(path)` changes the icon after creation.
|
|
60
|
+
- `window.set_theme("light")`, `window.set_theme("dark")`, or `app.set_theme(...)` changes the window theme/background.
|
|
61
|
+
- `window.set_background((r, g, b))` sets a custom background color.
|
|
62
|
+
|
|
63
|
+
## Included components
|
|
64
|
+
|
|
65
|
+
### Core
|
|
66
|
+
|
|
67
|
+
- `App`, `Window`, `Event`
|
|
68
|
+
- Window sizing, resize minimums, FPS cap, custom icon, close handling
|
|
69
|
+
- Multiple screens using `Screen` and `ScreenManager`
|
|
70
|
+
|
|
71
|
+
### Widgets
|
|
72
|
+
|
|
73
|
+
- `Label`, `Button`
|
|
74
|
+
- `TextInput` (cursor movement, Home/End, Backspace/Delete, max length, password display)
|
|
75
|
+
- `Checkbox`, `Switch`, `Slider`
|
|
76
|
+
- `Dropdown`, `RadioGroup`
|
|
77
|
+
- `Image`, `ProgressBar`, `Panel`
|
|
78
|
+
|
|
79
|
+
### Layouts
|
|
80
|
+
|
|
81
|
+
- `VerticalLayout`, `HorizontalLayout`, `GridLayout`
|
|
82
|
+
- `AnchorLayout` with nine anchor positions (`top_left`, `center`, `bottom_right`, etc.)
|
|
83
|
+
- Nested layouts and panels
|
|
84
|
+
|
|
85
|
+
### Utilities
|
|
86
|
+
|
|
87
|
+
- `Theme`, `DARK`, `LIGHT`
|
|
88
|
+
- `Animation`, `fade`, `slide`
|
|
89
|
+
- `ResourceManager` for image/font caching
|
|
90
|
+
|
|
91
|
+
## Examples
|
|
92
|
+
|
|
93
|
+
Run the showcase after installing the development copy or from the source folder:
|
|
94
|
+
|
|
95
|
+
```powershell
|
|
96
|
+
py examples\showcase.py
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Development / build
|
|
100
|
+
|
|
101
|
+
```powershell
|
|
102
|
+
py -m pip install -e ".[dev]"
|
|
103
|
+
py -m pytest
|
|
104
|
+
py -m build
|
|
105
|
+
py -m twine check dist\*
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The project distribution name is `vali-ui`; the import package remains `vali`.
|
|
109
|
+
|
|
110
|
+
## Version 1.1.0 scope
|
|
111
|
+
|
|
112
|
+
VALI 1.1.0 is a desktop 2D UI foundation. It is not a native-widget toolkit and does not claim full mobile support, screen-reader accessibility, advanced constraint-based responsive layouts, or a full-featured text editor. Those are separate engineering milestones rather than hidden promises.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import vali
|
|
2
|
+
|
|
3
|
+
app = vali.App()
|
|
4
|
+
app.create_window("VALI 1.1.0 Showcase", size=(900, 650), theme="dark", resizable=True)
|
|
5
|
+
|
|
6
|
+
home = vali.Screen()
|
|
7
|
+
layout = vali.VerticalLayout(x=36, y=28, spacing=16, padding=8)
|
|
8
|
+
|
|
9
|
+
title = vali.Label("VALI 1.1.0", size=38, color=(245,247,252))
|
|
10
|
+
subtitle = vali.Label("A Python UI framework", size=22, color=(180,190,210))
|
|
11
|
+
name = vali.TextInput(width=300, placeholder="Type something...")
|
|
12
|
+
remember = vali.Checkbox("Remember this", checked=True)
|
|
13
|
+
notifications = vali.Switch("Notifications", checked=False)
|
|
14
|
+
volume = vali.Slider(width=260, minimum=0, maximum=100, value=65,
|
|
15
|
+
on_change=lambda value: print("Slider:", round(value)))
|
|
16
|
+
progress = vali.ProgressBar(width=260, value=72)
|
|
17
|
+
quality = vali.Dropdown(["Low", "Medium", "High"], width=260, on_change=lambda value: print("Quality:", value))
|
|
18
|
+
mode = vali.RadioGroup(["Windowed", "Fullscreen"], value="Windowed")
|
|
19
|
+
|
|
20
|
+
def continue_clicked():
|
|
21
|
+
print("Button clicked. Input:", name.value)
|
|
22
|
+
|
|
23
|
+
button = vali.Button("Continue", width=190, height=48, on_click=continue_clicked)
|
|
24
|
+
|
|
25
|
+
layout.add(title, subtitle, name, remember, notifications, volume, progress, quality, mode, button)
|
|
26
|
+
home.add(layout)
|
|
27
|
+
|
|
28
|
+
settings = vali.Screen()
|
|
29
|
+
settings.add(
|
|
30
|
+
vali.Label("Settings screen", 36, 36, size=34, color=(245,247,252)),
|
|
31
|
+
vali.Button("Back", 36, 100, on_click=lambda: app.screens.show("home"))
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
app.screens.add("home", home) # First screen becomes active
|
|
35
|
+
app.screens.add("settings", settings)
|
|
36
|
+
app.run()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vali-ui"
|
|
7
|
+
version = "1.1.0"
|
|
8
|
+
description = "VALI - a lightweight Python desktop UI framework"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "Eyal Laros" }]
|
|
13
|
+
keywords = ["gui", "ui", "pygame", "desktop", "widgets", "framework"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Win32 (MS Windows)",
|
|
17
|
+
"Environment :: X11 Applications",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: User Interfaces",
|
|
26
|
+
]
|
|
27
|
+
dependencies = ["pygame>=2.5"]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["build>=1.2", "pytest>=8", "ruff>=0.6", "twine>=5"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["."]
|
|
35
|
+
include = ["vali*"]
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
testpaths = ["tests"]
|
|
39
|
+
addopts = "-ra"
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
line-length = 100
|
vali_ui-1.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
pygame = pytest.importorskip("pygame")
|
|
3
|
+
import vali
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_public_version_and_new_widgets():
|
|
7
|
+
assert vali.__version__ == "1.1.0"
|
|
8
|
+
assert vali.Dropdown(["A", "B"]).value == "A"
|
|
9
|
+
assert vali.RadioGroup(["A", "B"]).value == "A"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_dropdown_change_event():
|
|
13
|
+
values = []
|
|
14
|
+
dropdown = vali.Dropdown(["A", "B"], on_change=values.append)
|
|
15
|
+
dropdown.set_value("B")
|
|
16
|
+
assert dropdown.value == "B"
|
|
17
|
+
assert values == ["B"]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_radio_group_change_event():
|
|
21
|
+
values = []
|
|
22
|
+
radio = vali.RadioGroup(["one", "two"], on_change=values.append)
|
|
23
|
+
radio.set_value("two")
|
|
24
|
+
assert radio.value == "two"
|
|
25
|
+
assert values == ["two"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_app_accepts_positional_dimensions():
|
|
29
|
+
app = vali.App()
|
|
30
|
+
window = app.create_window("test", 640, 480)
|
|
31
|
+
assert (window.width, window.height) == (640, 480)
|
|
32
|
+
window.close()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_screen_manager_switches_screens():
|
|
36
|
+
manager = vali.ScreenManager()
|
|
37
|
+
first, second = vali.Screen(), vali.Screen()
|
|
38
|
+
manager.add("first", first)
|
|
39
|
+
manager.add("second", second)
|
|
40
|
+
assert manager.current is first
|
|
41
|
+
manager.show("second")
|
|
42
|
+
assert manager.current is second
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import importlib.util
|
|
3
|
+
|
|
4
|
+
# Load pure modules without importing the top-level package (which requires Pygame).
|
|
5
|
+
def load_module(name, path):
|
|
6
|
+
spec = importlib.util.spec_from_file_location(name, path)
|
|
7
|
+
module = importlib.util.module_from_spec(spec)
|
|
8
|
+
spec.loader.exec_module(module)
|
|
9
|
+
return module
|
|
10
|
+
|
|
11
|
+
ROOT = Path(__file__).parents[1] / "vali"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_animation_math():
|
|
15
|
+
animation = load_module("vali_animation_test", ROOT / "graphics" / "animation.py")
|
|
16
|
+
assert animation.fade(0, 10, 0.5) == 5
|
|
17
|
+
assert animation.slide(0, 0, 10, 20, 0.5) == (5, 10)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_event_dispatch():
|
|
21
|
+
events = load_module("vali_events_test", ROOT / "core" / "events.py")
|
|
22
|
+
event = events.Event()
|
|
23
|
+
received = []
|
|
24
|
+
callback = received.append
|
|
25
|
+
event.connect(callback)
|
|
26
|
+
event.emit("hello")
|
|
27
|
+
assert received == ["hello"]
|
|
28
|
+
event.disconnect(callback)
|
|
29
|
+
assert len(event) == 0
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import importlib.util
|
|
3
|
+
|
|
4
|
+
if importlib.util.find_spec("pygame") is None:
|
|
5
|
+
raise unittest.SkipTest("Pygame is required for public API tests")
|
|
6
|
+
|
|
7
|
+
import vali
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PublicAPITests(unittest.TestCase):
|
|
11
|
+
def test_version(self):
|
|
12
|
+
self.assertEqual(vali.__version__, "1.1.0")
|
|
13
|
+
|
|
14
|
+
def test_public_classes_exist(self):
|
|
15
|
+
for name in (
|
|
16
|
+
"App", "Window", "Event", "Widget", "Label", "Button",
|
|
17
|
+
"TextInput", "Checkbox", "Switch", "Slider", "Dropdown",
|
|
18
|
+
"RadioGroup", "Image", "ProgressBar", "Panel", "Layout",
|
|
19
|
+
"VerticalLayout", "HorizontalLayout", "GridLayout", "AnchorLayout",
|
|
20
|
+
"Screen", "ScreenManager", "Theme", "Animation", "ResourceManager",
|
|
21
|
+
):
|
|
22
|
+
self.assertTrue(hasattr(vali, name), name)
|
|
23
|
+
|
|
24
|
+
def test_screen_manager(self):
|
|
25
|
+
manager = vali.ScreenManager()
|
|
26
|
+
first, second = vali.Screen(), vali.Screen()
|
|
27
|
+
manager.add("first", first)
|
|
28
|
+
manager.add("second", second)
|
|
29
|
+
self.assertIs(manager.current, first)
|
|
30
|
+
manager.show("second")
|
|
31
|
+
self.assertIs(manager.current, second)
|
|
32
|
+
|
|
33
|
+
def test_layout_add(self):
|
|
34
|
+
layout = vali.VerticalLayout(spacing=5)
|
|
35
|
+
label = vali.Label("test")
|
|
36
|
+
layout.add(label)
|
|
37
|
+
self.assertEqual(layout.children, [label])
|
|
38
|
+
self.assertIs(label.parent, layout)
|
|
39
|
+
|
|
40
|
+
def test_animation(self):
|
|
41
|
+
animation = vali.Animation(0, 100, 2).start(now=10)
|
|
42
|
+
self.assertEqual(animation.update(now=11), 50)
|
|
43
|
+
self.assertEqual(animation.update(now=12), 100)
|
|
44
|
+
self.assertTrue(animation.finished)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
unittest.main()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""VALI: a lightweight, beginner-friendly Python desktop UI framework."""
|
|
2
|
+
|
|
3
|
+
from .core.app import App
|
|
4
|
+
from .core.window import Window
|
|
5
|
+
from .core.events import Event
|
|
6
|
+
from .widgets import (
|
|
7
|
+
Widget, Label, Button, TextInput, Checkbox, Switch, Slider,
|
|
8
|
+
Dropdown, RadioGroup, Image, ProgressBar, Panel,
|
|
9
|
+
)
|
|
10
|
+
from .layouts import Layout, VerticalLayout, HorizontalLayout, GridLayout, AnchorLayout
|
|
11
|
+
from .screens import Screen, ScreenManager
|
|
12
|
+
from .themes import Theme, DARK, LIGHT
|
|
13
|
+
from .graphics import Animation, fade, slide
|
|
14
|
+
from .utils import ResourceManager
|
|
15
|
+
|
|
16
|
+
__version__ = "1.1.0"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"App", "Window", "Event", "Widget", "Label", "Button", "TextInput",
|
|
20
|
+
"Checkbox", "Switch", "Slider", "Dropdown", "RadioGroup", "Image",
|
|
21
|
+
"ProgressBar", "Panel", "Layout", "VerticalLayout", "HorizontalLayout",
|
|
22
|
+
"GridLayout", "AnchorLayout", "Screen", "ScreenManager", "Theme", "DARK",
|
|
23
|
+
"LIGHT", "Animation", "fade", "slide", "ResourceManager", "__version__",
|
|
24
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from .window import Window
|
|
2
|
+
from ..screens import ScreenManager
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class App:
|
|
6
|
+
"""Main application object. Owns one window and a screen manager."""
|
|
7
|
+
|
|
8
|
+
def __init__(self):
|
|
9
|
+
self.window = None
|
|
10
|
+
self.screens = ScreenManager()
|
|
11
|
+
|
|
12
|
+
def create_window(self, title="VALI Application", width=800, height=600, *,
|
|
13
|
+
size=None, icon=None, background=None, theme="light",
|
|
14
|
+
resizable=False, fps=60, min_size=(320, 240), vsync=False):
|
|
15
|
+
"""Create the application window.
|
|
16
|
+
|
|
17
|
+
Supports both create_window(title, 800, 600) and the older
|
|
18
|
+
create_window(title, size=(800, 600)) form.
|
|
19
|
+
"""
|
|
20
|
+
if size is not None:
|
|
21
|
+
width, height = size
|
|
22
|
+
if self.window is not None:
|
|
23
|
+
self.window.close()
|
|
24
|
+
self.window = Window(
|
|
25
|
+
title, (width, height), icon=icon, background=background,
|
|
26
|
+
theme=theme, resizable=resizable, fps=fps,
|
|
27
|
+
screen_manager=self.screens, min_size=min_size, vsync=vsync,
|
|
28
|
+
)
|
|
29
|
+
return self.window
|
|
30
|
+
|
|
31
|
+
def add(self, widget):
|
|
32
|
+
if self.window is None:
|
|
33
|
+
raise RuntimeError("Call create_window() before app.add().")
|
|
34
|
+
return self.window.add(widget)
|
|
35
|
+
|
|
36
|
+
def run(self):
|
|
37
|
+
if self.window is None:
|
|
38
|
+
raise RuntimeError("No window has been created.")
|
|
39
|
+
self.window.run()
|
|
40
|
+
|
|
41
|
+
def quit(self):
|
|
42
|
+
if self.window is not None:
|
|
43
|
+
self.window.quit()
|
|
44
|
+
|
|
45
|
+
def set_theme(self, theme):
|
|
46
|
+
if self.window is None:
|
|
47
|
+
raise RuntimeError("Create a window before setting its theme.")
|
|
48
|
+
self.window.set_theme(theme)
|
|
49
|
+
return self
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Event:
|
|
2
|
+
"""A small callback collection."""
|
|
3
|
+
|
|
4
|
+
def __init__(self):
|
|
5
|
+
self._callbacks = []
|
|
6
|
+
|
|
7
|
+
def connect(self, callback):
|
|
8
|
+
if not callable(callback):
|
|
9
|
+
raise TypeError("callback must be callable")
|
|
10
|
+
if callback not in self._callbacks:
|
|
11
|
+
self._callbacks.append(callback)
|
|
12
|
+
return callback
|
|
13
|
+
|
|
14
|
+
def disconnect(self, callback):
|
|
15
|
+
self._callbacks.remove(callback)
|
|
16
|
+
|
|
17
|
+
def emit(self, *args, **kwargs):
|
|
18
|
+
for callback in tuple(self._callbacks):
|
|
19
|
+
callback(*args, **kwargs)
|
|
20
|
+
|
|
21
|
+
def clear(self):
|
|
22
|
+
self._callbacks.clear()
|
|
23
|
+
|
|
24
|
+
def __len__(self):
|
|
25
|
+
return len(self._callbacks)
|