kivygradient 0.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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kenechukwu Akubue
|
|
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.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kivygradient
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: KivyGradient allows you to add a gradient color to your Kivy Widget
|
|
5
|
+
Author: Kenechukwu Akubue
|
|
6
|
+
Author-email: Kenechukwu Akubue <kengoon19@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
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: Operating System :: OS Independent
|
|
19
|
+
Classifier: Operating System :: Android
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Operating System :: POSIX :: BSD :: FreeBSD
|
|
22
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
23
|
+
Classifier: Operating System :: iOS
|
|
24
|
+
Classifier: Operating System :: MacOS
|
|
25
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
26
|
+
Classifier: Environment :: MacOS X
|
|
27
|
+
Classifier: Environment :: Win32 (MS Windows)
|
|
28
|
+
Classifier: Environment :: X11 Applications
|
|
29
|
+
Classifier: Intended Audience :: Developers
|
|
30
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
31
|
+
Classifier: Intended Audience :: Information Technology
|
|
32
|
+
Classifier: Intended Audience :: Science/Research
|
|
33
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
34
|
+
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
|
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
36
|
+
Requires-Dist: kivy>=2.3.1
|
|
37
|
+
Requires-Python: >=3.9
|
|
38
|
+
Project-URL: Homepage, https://github.com/kengoon/KivyGradient
|
|
39
|
+
Project-URL: Repository, https://github.com/kengoon/KivyGradient.git
|
|
40
|
+
Project-URL: Documentation, https://github.com/kengoon/KivyGradient/blob/master/README.md
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# KivyGradient
|
|
44
|
+
[](https://openbase.com/python/KivyGradient?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
|
|
45
|
+
[](https://openbase.com/python/KivyGradient?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
|
|
46
|
+
[](https://openbase.com/python/KivyGradient?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
|
|
47
|
+
|
|
48
|
+
KivyGradient allows you to add a gradient color to your Kivy Widget
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
`pip install kivygradient`
|
|
52
|
+
|
|
53
|
+
### Example Code
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from kivy.app import App
|
|
57
|
+
from kivy.lang import Builder
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
kv = """
|
|
61
|
+
#:import get_color_from_hex kivy.utils.get_color_from_hex
|
|
62
|
+
#:import Gradient kivy_gradient.Gradient
|
|
63
|
+
RelativeLayout:
|
|
64
|
+
BoxLayout
|
|
65
|
+
id: box
|
|
66
|
+
on_kv_post: print(get_color_from_hex("E91E63"))
|
|
67
|
+
canvas:
|
|
68
|
+
Rectangle:
|
|
69
|
+
size: self.size
|
|
70
|
+
pos: self.pos
|
|
71
|
+
texture: Gradient.horizontal(get_color_from_hex("E91E63"), get_color_from_hex("FCE4EC"))
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Test(App):
|
|
76
|
+
def build(self):
|
|
77
|
+
return Builder.load_string(kv)
|
|
78
|
+
|
|
79
|
+
def on_stop(self):
|
|
80
|
+
self.root.ids.box.export_to_png("gradient.png")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
Test().run()
|
|
84
|
+
```
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from kivy.app import App
|
|
90
|
+
from kivy.lang import Builder
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
kv = """
|
|
94
|
+
#:import get_color_from_hex kivy.utils.get_color_from_hex
|
|
95
|
+
#:import Gradient kivy_gradient.Gradient
|
|
96
|
+
RelativeLayout:
|
|
97
|
+
BoxLayout
|
|
98
|
+
id: box
|
|
99
|
+
canvas:
|
|
100
|
+
Rectangle:
|
|
101
|
+
size: self.size
|
|
102
|
+
pos: self.pos
|
|
103
|
+
texture:
|
|
104
|
+
Gradient.horizontal(
|
|
105
|
+
get_color_from_hex("E91E63"),
|
|
106
|
+
get_color_from_hex("FCE4EC"),
|
|
107
|
+
get_color_from_hex("2962FF")
|
|
108
|
+
)
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class Test(App):
|
|
113
|
+
def build(self):
|
|
114
|
+
return Builder.load_string(kv)
|
|
115
|
+
|
|
116
|
+
def on_stop(self):
|
|
117
|
+
self.root.ids.box.export_to_png("gradient.png")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
Test().run()
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+

|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# KivyGradient
|
|
2
|
+
[](https://openbase.com/python/KivyGradient?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
|
|
3
|
+
[](https://openbase.com/python/KivyGradient?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
|
|
4
|
+
[](https://openbase.com/python/KivyGradient?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge)
|
|
5
|
+
|
|
6
|
+
KivyGradient allows you to add a gradient color to your Kivy Widget
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
`pip install kivygradient`
|
|
10
|
+
|
|
11
|
+
### Example Code
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from kivy.app import App
|
|
15
|
+
from kivy.lang import Builder
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
kv = """
|
|
19
|
+
#:import get_color_from_hex kivy.utils.get_color_from_hex
|
|
20
|
+
#:import Gradient kivy_gradient.Gradient
|
|
21
|
+
RelativeLayout:
|
|
22
|
+
BoxLayout
|
|
23
|
+
id: box
|
|
24
|
+
on_kv_post: print(get_color_from_hex("E91E63"))
|
|
25
|
+
canvas:
|
|
26
|
+
Rectangle:
|
|
27
|
+
size: self.size
|
|
28
|
+
pos: self.pos
|
|
29
|
+
texture: Gradient.horizontal(get_color_from_hex("E91E63"), get_color_from_hex("FCE4EC"))
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Test(App):
|
|
34
|
+
def build(self):
|
|
35
|
+
return Builder.load_string(kv)
|
|
36
|
+
|
|
37
|
+
def on_stop(self):
|
|
38
|
+
self.root.ids.box.export_to_png("gradient.png")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
Test().run()
|
|
42
|
+
```
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from kivy.app import App
|
|
48
|
+
from kivy.lang import Builder
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
kv = """
|
|
52
|
+
#:import get_color_from_hex kivy.utils.get_color_from_hex
|
|
53
|
+
#:import Gradient kivy_gradient.Gradient
|
|
54
|
+
RelativeLayout:
|
|
55
|
+
BoxLayout
|
|
56
|
+
id: box
|
|
57
|
+
canvas:
|
|
58
|
+
Rectangle:
|
|
59
|
+
size: self.size
|
|
60
|
+
pos: self.pos
|
|
61
|
+
texture:
|
|
62
|
+
Gradient.horizontal(
|
|
63
|
+
get_color_from_hex("E91E63"),
|
|
64
|
+
get_color_from_hex("FCE4EC"),
|
|
65
|
+
get_color_from_hex("2962FF")
|
|
66
|
+
)
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Test(App):
|
|
71
|
+
def build(self):
|
|
72
|
+
return Builder.load_string(kv)
|
|
73
|
+
|
|
74
|
+
def on_stop(self):
|
|
75
|
+
self.root.ids.box.export_to_png("gradient.png")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Test().run()
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+

|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from itertools import chain
|
|
2
|
+
|
|
3
|
+
from kivy.graphics.texture import Texture
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Gradient(object):
|
|
7
|
+
"""
|
|
8
|
+
Utility class for creating horizontal and vertical gradient textures.
|
|
9
|
+
|
|
10
|
+
This class provides static methods to generate gradient textures either
|
|
11
|
+
horizontally or vertically, based on the provided colors. It is primarily
|
|
12
|
+
used in graphical rendering contexts where gradient textures are needed.
|
|
13
|
+
"""
|
|
14
|
+
@staticmethod
|
|
15
|
+
def horizontal(*args):
|
|
16
|
+
"""
|
|
17
|
+
Generates a horizontal gradient texture using the provided colors.
|
|
18
|
+
|
|
19
|
+
This method creates a gradient based on the RGBA values provided as arguments.
|
|
20
|
+
Each color should be represented as a tuple of four floats in the range [0, 1],
|
|
21
|
+
corresponding to red, green, blue, and alpha channels. The resulting texture
|
|
22
|
+
is configured to display the gradient horizontally.
|
|
23
|
+
|
|
24
|
+
:param args: The colors to use for the gradient, each represented as a tuple
|
|
25
|
+
of four floats (red, green, blue, alpha). At least one color must be provided.
|
|
26
|
+
:type args: tuple[float, float, float, float]
|
|
27
|
+
:raises ValueError: If no colors are provided in the arguments.
|
|
28
|
+
:return: A `Texture` object containing the horizontal gradient.
|
|
29
|
+
:rtype: Texture
|
|
30
|
+
"""
|
|
31
|
+
if not args:
|
|
32
|
+
raise ValueError('Gradient.horizontal() requires at least one color')
|
|
33
|
+
size = len(args)
|
|
34
|
+
texture = Texture.create(size=(size, 1), colorfmt='rgba')
|
|
35
|
+
buf = bytes([int(v * 255) for v in chain(*args)]) # flattens
|
|
36
|
+
|
|
37
|
+
texture.blit_buffer(buf, colorfmt='rgba', bufferfmt='ubyte')
|
|
38
|
+
|
|
39
|
+
if size < 2:
|
|
40
|
+
return texture
|
|
41
|
+
|
|
42
|
+
texture.uvpos = (0.5 / size, 0)
|
|
43
|
+
texture.uvsize = ((size - 1) / size, 1)
|
|
44
|
+
return texture
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def vertical(*args):
|
|
48
|
+
"""
|
|
49
|
+
Creates a vertical gradient texture from the provided colors. The gradient is composed
|
|
50
|
+
of the colors given as arguments and interpolates between them vertically.
|
|
51
|
+
|
|
52
|
+
:param args: A variable number of colors specified as tuples of RGBA values
|
|
53
|
+
(each component should be in the range [0.0, 1.0]). A minimum of
|
|
54
|
+
one color is required. If multiple colors are provided, the gradient
|
|
55
|
+
will interpolate between them.
|
|
56
|
+
:type args: tuple
|
|
57
|
+
:return: A Texture object representing the vertical gradient. The texture will
|
|
58
|
+
have interpolated UV position and size based on the number of colors
|
|
59
|
+
provided.
|
|
60
|
+
:rtype: Texture
|
|
61
|
+
:raises ValueError: If no colors are provided.
|
|
62
|
+
"""
|
|
63
|
+
if not args:
|
|
64
|
+
raise ValueError('Gradient.vertical() requires at least one color')
|
|
65
|
+
size = len(args)
|
|
66
|
+
texture = Texture.create(size=(1, size), colorfmt='rgba')
|
|
67
|
+
buf = bytes([int(v * 255) for v in chain(*args)]) # flattens
|
|
68
|
+
|
|
69
|
+
texture.blit_buffer(buf, colorfmt='rgba', bufferfmt='ubyte')
|
|
70
|
+
|
|
71
|
+
if size < 2:
|
|
72
|
+
return texture
|
|
73
|
+
|
|
74
|
+
texture.uvpos = (0, 0.5 / size)
|
|
75
|
+
texture.uvsize = (1, (size - 1) / size)
|
|
76
|
+
return texture
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def save_pixel_as_png(width, height, pixel_data, filename=None):
|
|
80
|
+
"""
|
|
81
|
+
Generates a PNG image byte sequence based on given pixel data and saves it to
|
|
82
|
+
a file if a filename is provided.
|
|
83
|
+
|
|
84
|
+
This function constructs a PNG image file by assembling the required PNG
|
|
85
|
+
chunks: IHDR, IDAT, and IEND. It generates the image bytes and writes them
|
|
86
|
+
to a specified file if a valid filename is provided.
|
|
87
|
+
|
|
88
|
+
:param width: The width of the image in pixels.
|
|
89
|
+
:type width: int
|
|
90
|
+
:param height: The height of the image in pixels.
|
|
91
|
+
:type height: int
|
|
92
|
+
:param pixel_data: A byte sequence containing the pixel data of the image.
|
|
93
|
+
Each pixel should be represented by four bytes (RGBA format).
|
|
94
|
+
:type pixel_data: bytes
|
|
95
|
+
:param filename: The optional filename where the PNG file will be saved. If
|
|
96
|
+
not provided, the generated PNG data will not be saved to disk.
|
|
97
|
+
:type filename: str or None
|
|
98
|
+
:return: A byte sequence representing the constructed PNG image.
|
|
99
|
+
:rtype: bytes
|
|
100
|
+
|
|
101
|
+
"""
|
|
102
|
+
# Prepare PNG header
|
|
103
|
+
png_header = b'\x89PNG\r\n\x1a\n'
|
|
104
|
+
|
|
105
|
+
# IHDR chunk
|
|
106
|
+
ihdr = (
|
|
107
|
+
struct.pack(">I", width)
|
|
108
|
+
+ struct.pack(">I", height)
|
|
109
|
+
+ b'\x08\x06\x00\x00\x00'
|
|
110
|
+
)
|
|
111
|
+
ihdr_crc = struct.pack(
|
|
112
|
+
">I",
|
|
113
|
+
zlib.crc32(b'IHDR' + ihdr) & 0xffffffff
|
|
114
|
+
)
|
|
115
|
+
ihdr_chunk = (
|
|
116
|
+
struct.pack(">I", len(ihdr))
|
|
117
|
+
+ b'IHDR' + ihdr + ihdr_crc
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# IDAT chunk
|
|
121
|
+
# Rearrange the pixels into scanlines
|
|
122
|
+
scanlines = b''.join(
|
|
123
|
+
b'\x00' + pixel_data[4 * i * width: 4 * (i + 1) * width]
|
|
124
|
+
for i in range(height)
|
|
125
|
+
)
|
|
126
|
+
compressed_data = zlib.compress(scanlines)
|
|
127
|
+
idat_crc = struct.pack(
|
|
128
|
+
">I",
|
|
129
|
+
zlib.crc32(b'IDAT' + compressed_data) & 0xffffffff
|
|
130
|
+
)
|
|
131
|
+
idat_chunk = (
|
|
132
|
+
struct.pack(">I", len(compressed_data))
|
|
133
|
+
+ b'IDAT' + compressed_data + idat_crc
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# IEND chunk
|
|
137
|
+
iend_chunk = (
|
|
138
|
+
struct.pack(">I", 0)
|
|
139
|
+
+ b'IEND'
|
|
140
|
+
+ struct.pack(">I", zlib.crc32(b'IEND') & 0xffffffff)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
image_byte = png_header + ihdr_chunk + idat_chunk + iend_chunk
|
|
144
|
+
|
|
145
|
+
# Write all chunks to the file
|
|
146
|
+
if filename:
|
|
147
|
+
with open(filename, 'wb') as f:
|
|
148
|
+
f.write(png_header)
|
|
149
|
+
f.write(ihdr_chunk)
|
|
150
|
+
f.write(idat_chunk)
|
|
151
|
+
f.write(iend_chunk)
|
|
152
|
+
|
|
153
|
+
return image_byte
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
__all__ = ("Gradient",)
|
|
2
|
+
|
|
3
|
+
from kivy.app import App
|
|
4
|
+
from kivy.uix.boxlayout import BoxLayout
|
|
5
|
+
from kivy.uix.widget import Widget
|
|
6
|
+
from kivy.graphics import RenderContext
|
|
7
|
+
from kivy.core.window import Window
|
|
8
|
+
from kivy.clock import mainthread
|
|
9
|
+
from kivy.properties import NumericProperty, ListProperty, BooleanProperty, ColorProperty
|
|
10
|
+
|
|
11
|
+
shader_code = '''
|
|
12
|
+
#ifdef GL_ES
|
|
13
|
+
precision highp float;
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
uniform vec2 u_resolution;
|
|
17
|
+
uniform vec2 u_position;
|
|
18
|
+
uniform float u_angle;
|
|
19
|
+
uniform bool u_circular;
|
|
20
|
+
uniform vec4 u_color_start;
|
|
21
|
+
uniform vec4 u_color_end;
|
|
22
|
+
|
|
23
|
+
void main() {
|
|
24
|
+
// Normalized coordinates (0–1)
|
|
25
|
+
vec2 uv = (gl_FragCoord.xy - u_position) / u_resolution;
|
|
26
|
+
|
|
27
|
+
// Convert angle to radians
|
|
28
|
+
float rad = radians(u_angle);
|
|
29
|
+
|
|
30
|
+
// Move origin to center and fix aspect ratio
|
|
31
|
+
vec2 centered = uv - 0.5;
|
|
32
|
+
float mixValue;
|
|
33
|
+
|
|
34
|
+
if (!u_circular) {
|
|
35
|
+
centered.x *= u_resolution.x / u_resolution.y;
|
|
36
|
+
|
|
37
|
+
// Direction vector of gradient
|
|
38
|
+
vec2 direction = vec2(cos(rad), sin(rad));
|
|
39
|
+
|
|
40
|
+
// Linear projection onto gradient direction
|
|
41
|
+
mixValue = dot(centered, direction) + 0.5;
|
|
42
|
+
} else {
|
|
43
|
+
// Rotation matrix
|
|
44
|
+
mat2 rotation = mat2(cos(rad), -sin(rad),
|
|
45
|
+
sin(rad), cos(rad));
|
|
46
|
+
vec2 rotated = rotation * centered + 0.5;
|
|
47
|
+
mixValue = distance(rotated, vec2(0.0, 1.0));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Blend the colors
|
|
51
|
+
vec4 finalColor = mix(u_color_start, u_color_end, clamp(mixValue, 0.0, 1.0));
|
|
52
|
+
|
|
53
|
+
gl_FragColor = finalColor;
|
|
54
|
+
}
|
|
55
|
+
'''
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class Gradient(Widget):
|
|
59
|
+
"""
|
|
60
|
+
Represents a gradient widget capable of rendering a smooth transition between
|
|
61
|
+
two colors, either linearly or circularly. This class provides fine-grained
|
|
62
|
+
control over the gradient's appearance through adjustable properties such
|
|
63
|
+
as angle, start color, end color, and whether the gradient should be circular.
|
|
64
|
+
|
|
65
|
+
The class uses a custom `RenderContext` for rendering, enabling the application
|
|
66
|
+
of fragment shaders to create high-performance gradient effects.
|
|
67
|
+
|
|
68
|
+
:ivar angle: The angle of the gradient in degrees. Defaults to 90 degrees.
|
|
69
|
+
:type angle: float
|
|
70
|
+
:ivar color_start: The RGBA start color of the gradient. Defaults to [0, 0, 0, 0].
|
|
71
|
+
:type color_start: list[float]
|
|
72
|
+
:ivar color_end: The RGBA end color of the gradient. Defaults to [0, 0, 0, 0].
|
|
73
|
+
:type color_end: list[float]
|
|
74
|
+
:ivar circular: Indicates whether the gradient is circular. Defaults to False.
|
|
75
|
+
:type circular: bool
|
|
76
|
+
"""
|
|
77
|
+
angle = NumericProperty(90)
|
|
78
|
+
color_start = ColorProperty([0, 0, 0, 0])
|
|
79
|
+
color_end = ColorProperty([0, 0, 0, 0])
|
|
80
|
+
circular = BooleanProperty(False)
|
|
81
|
+
|
|
82
|
+
def __init__(self, **kwargs):
|
|
83
|
+
# Use a RenderContext instead of normal canvas
|
|
84
|
+
super().__init__(**kwargs)
|
|
85
|
+
self.canvas = RenderContext(
|
|
86
|
+
use_parent_projection=True,
|
|
87
|
+
use_parent_modelview=True,
|
|
88
|
+
fs=shader_code,
|
|
89
|
+
)
|
|
90
|
+
fbind = self.fbind
|
|
91
|
+
fbind("angle", self._update_shader)
|
|
92
|
+
fbind("color_start", self._update_shader)
|
|
93
|
+
fbind("color_end", self._update_shader)
|
|
94
|
+
fbind("circular", self._update_shader)
|
|
95
|
+
fbind("size", self._update_shader)
|
|
96
|
+
fbind("pos", self._update_shader)
|
|
97
|
+
|
|
98
|
+
# with self.canvas:
|
|
99
|
+
# self.rect = Triangle(points=[0, 0, Window.width/2, Window.height, Window.width, 0])
|
|
100
|
+
self._setup()
|
|
101
|
+
|
|
102
|
+
@mainthread
|
|
103
|
+
def _setup(self, *args):
|
|
104
|
+
self._update_shader()
|
|
105
|
+
|
|
106
|
+
# def on_size(self, *args):
|
|
107
|
+
# self.canvas['u_resolution'] = list(map(float, self.size))
|
|
108
|
+
|
|
109
|
+
def _update_shader(self, *args):
|
|
110
|
+
self.canvas['u_angle'] = float(self.angle)
|
|
111
|
+
self.canvas['u_color_start'] = list(map(float, self.color_start))
|
|
112
|
+
self.canvas['u_color_end'] = list(map(float, self.color_end))
|
|
113
|
+
self.canvas['u_circular'] = int(self.circular)
|
|
114
|
+
self.canvas['u_resolution'] = list(map(float, self.size))
|
|
115
|
+
self.canvas['u_position'] = list(map(float, self.pos))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == '__main__':
|
|
119
|
+
from kivy.graphics import Rectangle
|
|
120
|
+
|
|
121
|
+
class ShaderGradientApp(App):
|
|
122
|
+
def build(self):
|
|
123
|
+
d = Gradient()
|
|
124
|
+
with d.canvas:
|
|
125
|
+
rect = Rectangle(size=Window.size, pos=(0, 0))
|
|
126
|
+
Window.bind(size=lambda _, s: setattr(rect, 'size', s))
|
|
127
|
+
return d
|
|
128
|
+
|
|
129
|
+
ShaderGradientApp().run()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "kivygradient"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "KivyGradient allows you to add a gradient color to your Kivy Widget"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
dependencies = ["kivy>=2.3.1"]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
10
|
+
"Programming Language :: Python :: 3",
|
|
11
|
+
"Programming Language :: Python :: 3.7",
|
|
12
|
+
"Programming Language :: Python :: 3.8",
|
|
13
|
+
"Programming Language :: Python :: 3.9",
|
|
14
|
+
"Programming Language :: Python :: 3.10",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Operating System :: Android",
|
|
20
|
+
"Operating System :: POSIX :: Linux",
|
|
21
|
+
"Operating System :: POSIX :: BSD :: FreeBSD",
|
|
22
|
+
"Operating System :: Microsoft :: Windows",
|
|
23
|
+
"Operating System :: iOS",
|
|
24
|
+
"Operating System :: MacOS",
|
|
25
|
+
"Operating System :: MacOS :: MacOS X",
|
|
26
|
+
"Environment :: MacOS X",
|
|
27
|
+
"Environment :: Win32 (MS Windows)",
|
|
28
|
+
"Environment :: X11 Applications",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Intended Audience :: End Users/Desktop",
|
|
31
|
+
"Intended Audience :: Information Technology",
|
|
32
|
+
"Intended Audience :: Science/Research",
|
|
33
|
+
"Topic :: Software Development :: User Interfaces",
|
|
34
|
+
"Topic :: Scientific/Engineering :: Human Machine Interfaces",
|
|
35
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
36
|
+
]
|
|
37
|
+
license = "MIT"
|
|
38
|
+
license-files = ["LICEN[CS]E*"]
|
|
39
|
+
|
|
40
|
+
[[project.authors]]
|
|
41
|
+
name = "Kenechukwu Akubue"
|
|
42
|
+
email = "kengoon19@gmail.com"
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/kengoon/KivyGradient"
|
|
46
|
+
Repository = "https://github.com/kengoon/KivyGradient.git"
|
|
47
|
+
Documentation = "https://github.com/kengoon/KivyGradient/blob/master/README.md"
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["uv_build>=0.12.17,<0.13"]
|
|
51
|
+
build-backend = "uv_build"
|
|
52
|
+
|
|
53
|
+
[tool.uv.build-backend]
|
|
54
|
+
module-name = "kivy_gradient"
|
|
55
|
+
module-root = ""
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "kivygradient"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "KivyGradient allows you to add a gradient color to your Kivy Widget"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"kivy>=2.3.1",
|
|
9
|
+
]
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Kenechukwu Akubue", email = "kengoon19@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.7",
|
|
17
|
+
"Programming Language :: Python :: 3.8",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Operating System :: Android",
|
|
25
|
+
"Operating System :: POSIX :: Linux",
|
|
26
|
+
"Operating System :: POSIX :: BSD :: FreeBSD",
|
|
27
|
+
"Operating System :: Microsoft :: Windows",
|
|
28
|
+
"Operating System :: iOS",
|
|
29
|
+
"Operating System :: MacOS",
|
|
30
|
+
"Operating System :: MacOS :: MacOS X",
|
|
31
|
+
"Environment :: MacOS X",
|
|
32
|
+
"Environment :: Win32 (MS Windows)",
|
|
33
|
+
"Environment :: X11 Applications",
|
|
34
|
+
"Intended Audience :: Developers",
|
|
35
|
+
"Intended Audience :: End Users/Desktop",
|
|
36
|
+
"Intended Audience :: Information Technology",
|
|
37
|
+
"Intended Audience :: Science/Research",
|
|
38
|
+
"Topic :: Software Development :: User Interfaces",
|
|
39
|
+
"Topic :: Scientific/Engineering :: Human Machine Interfaces",
|
|
40
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
41
|
+
]
|
|
42
|
+
license = "MIT"
|
|
43
|
+
license-files = ["LICEN[CS]E*"]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://github.com/kengoon/KivyGradient"
|
|
47
|
+
Repository = "https://github.com/kengoon/KivyGradient.git"
|
|
48
|
+
Documentation = "https://github.com/kengoon/KivyGradient/blob/master/README.md"
|
|
49
|
+
|
|
50
|
+
[build-system]
|
|
51
|
+
requires = ["uv_build>=0.12.17,<0.13"]
|
|
52
|
+
build-backend = "uv_build"
|
|
53
|
+
|
|
54
|
+
[tool.uv.build-backend]
|
|
55
|
+
module-name = "kivy_gradient"
|
|
56
|
+
module-root = ""
|