FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
StreamController/GtkHelper/ColorButtonRow.py at main · SithTech/StreamController · GitHub
SithTech
/
StreamController
Public
forked from
StreamController/StreamController
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
StreamController
/
GtkHelper
/
ColorButtonRow.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
75 lines (56 loc) · 2.89 KB
Breadcrumbs
StreamController
/
GtkHelper
/
ColorButtonRow.py
Copy path
File metadata and controls
75 lines (56 loc) · 2.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from
dataclasses
import
dataclass
from
typing
import
Callable
import
gi
gi
.
require_version
(
"Gtk"
,
"4.0"
)
gi
.
require_version
(
"Adw"
,
"1"
)
from
gi
.
repository
import
Gtk
,
Adw
,
Gdk
,
GLib
,
Gio
class
ColorButtonRow
(
Adw
.
ActionRow
):
"""
Initializes a ColorButtonRow widget with a color button and optional title and subtitle.
Parameters:
title (str, optional): The title to display in the row.
subtitle (str, optional): The subtitle to display below the title.
default_color (tuple[int, int, int, int], optional): The default color to set for the color button in
RGBA format (default is black with full opacity).
Description:
This constructor creates a new ColorButtonRow widget. It sets up a Gtk.ColorButton for selecting
a color and assigns it to the row. The initial color is set based on the provided `default_color`
tuple, which represents the color in RGBA format (each value ranges from 0 to 255).
Additionally, the color button is connected to the `color-set` signal, which triggers the `_on_color_changed`
method when the color is modified. The color is stored internally as a tuple of integers representing
the RGBA values.
The row is set up with a title and subtitle if provided.
"""
def
__init__
(
self
,
title
:
str
=
None
,
subtitle
:
str
=
None
,
default_color
:
tuple
[
int
,
int
,
int
,
int
]
=
(
0
,
0
,
0
,
255
),
):
super
().
__init__
(
title
=
title
,
subtitle
=
subtitle
)
self
.
color_button
=
Gtk
.
ColorButton
(
valign
=
Gtk
.
Align
.
CENTER
)
self
.
add_suffix
(
self
.
color_button
)
self
.
color
=
default_color
@
property
def
color
(
self
)
->
tuple
[
int
,
int
,
int
,
int
]:
rgba
=
self
.
color_button
.
get_rgba
()
return
self
.
convert_from_rgba
(
rgba
)
@
color
.
setter
def
color
(
self
,
value
:
tuple
[
int
,
int
,
int
,
int
]):
rgba
=
self
.
convert_to_rgba
(
value
)
self
.
color_button
.
set_rgba
(
rgba
)
self
.
color_button
.
emit
(
"color-set"
)
def
convert_from_rgba
(
self
,
color
:
Gdk
.
RGBA
)
->
tuple
[
int
,
int
,
int
,
int
]:
color
=
(
color
.
red
,
color
.
green
,
color
.
blue
,
color
.
alpha
)
return
self
.
normalize_to_255
(
color
)
def
convert_to_rgba
(
self
,
color
:
tuple
[
int
,
int
,
int
,
int
])
->
Gdk
.
RGBA
:
color
=
self
.
normalize_to_1
(
color
)
rgba
=
Gdk
.
RGBA
()
rgba
.
red
=
color
[
0
]
rgba
.
green
=
color
[
1
]
rgba
.
blue
=
color
[
2
]
rgba
.
alpha
=
color
[
3
]
return
rgba
def
normalize_to_255
(
self
,
color
:
tuple
[
float
,
float
,
float
,
float
])
->
tuple
[
int
,
int
,
int
,
int
]:
return
tuple
(
round
(
value
*
255
)
for
value
in
color
)
def
normalize_to_1
(
self
,
color
:
tuple
[
int
,
int
,
int
,
int
])
->
tuple
[
float
,
float
,
float
,
float
]:
return
tuple
(
value
/
255.0
for
value
in
color
)
Back
|
FazBrowse Home
|
New Git URL