FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
StreamController/GtkHelper/GenerativeUI/ComboRow.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
/
GenerativeUI
/
ComboRow.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
186 lines (145 loc) · 7.04 KB
Breadcrumbs
StreamController
/
GtkHelper
/
GenerativeUI
/
ComboRow.py
Copy path
File metadata and controls
186 lines (145 loc) · 7.04 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
from
GtkHelper
.
ComboRow
import
ComboRow
as
Combo
,
BaseComboRowItem
from
GtkHelper
.
GenerativeUI
.
GenerativeUI
import
GenerativeUI
import
gi
from
gi
.
repository
import
Gtk
,
Adw
from
typing
import
TYPE_CHECKING
if
TYPE_CHECKING
:
from
src
.
backend
.
PluginManager
.
ActionCore
import
ActionCore
from
GtkHelper
.
GtkHelper
import
better_disconnect
class
ComboRow
(
GenerativeUI
[
BaseComboRowItem
]):
"""
A UI element representing a combo box (drop-down menu) with selectable items,
linked to an `ActionCore` instance.
Attributes:
_widget (Combo): The ComboRow widget instance.
"""
def
__init__
(
self
,
action_core
:
"ActionCore"
,
var_name
:
str
,
default_value
:
BaseComboRowItem
|
str
,
items
:
list
[
BaseComboRowItem
]
|
list
[
str
],
title
:
str
=
None
,
subtitle
:
str
=
None
,
enable_search
:
bool
=
False
,
on_change
:
callable
=
None
,
can_reset
:
bool
=
True
,
auto_add
:
bool
=
True
,
complex_var_name
:
bool
=
False
):
"""
Initializes the ComboRow UI element.
Args:
action_core (ActionCore): The associated action instance.
var_name (str): The variable name for storing the selected value.
default_value (BaseComboRowItem | str): The default selected item.
items (list[BaseComboRowItem] | list[str]): The list of selectable items.
title (str, optional): The title of the combo box. Defaults to None.
subtitle (str, optional): The subtitle of the combo box. Defaults to None.
enable_search (bool, optional): Enables search functionality. Defaults to False.
on_change (callable, optional): Callback triggered when selection changes. Defaults to None.
can_reset (bool, optional): Whether resetting is allowed. Defaults to True.
auto_add (bool, optional): Whether to automatically add this UI element to the action. Defaults to True.
"""
super
().
__init__
(
action_core
,
var_name
,
default_value
,
can_reset
,
auto_add
,
complex_var_name
,
on_change
)
self
.
_widget
:
Combo
=
Combo
(
title
=
self
.
get_translation
(
title
,
title
),
subtitle
=
self
.
get_translation
(
subtitle
,
subtitle
),
items
=
items
,
enable_search
=
enable_search
,
default_selection
=
self
.
_default_value
)
self
.
_handle_reset_button_creation
()
self
.
connect_signals
()
def
set_sensitive
(
self
,
sensitive
:
bool
):
self
.
widget
.
set_sensitive
(
sensitive
)
def
get_sensitive
(
self
):
return
self
.
widget
.
get_sensitive
()
def
connect_signals
(
self
):
"""Connects the signal to detect selection changes in the combo box."""
self
.
widget
.
connect
(
"notify::selected"
,
self
.
_value_changed
)
def
disconnect_signals
(
self
):
"""Disconnects the signal for selection changes."""
better_disconnect
(
self
.
widget
,
self
.
_value_changed
)
def
_value_changed
(
self
,
combo_row
:
Combo
,
_
):
"""Handles the event when a new item is selected."""
item
=
combo_row
.
get_selected_item
()
self
.
_handle_value_changed
(
item
)
def
_handle_value_changed
(
self
,
item
:
BaseComboRowItem
,
update_settings
:
bool
=
True
,
trigger_callback
:
bool
=
True
):
"""Handles updating the stored value and triggering the change callback."""
old_value
=
self
.
get_value
(
self
.
_default_value
)
if
update_settings
:
self
.
set_value
(
item
)
if
trigger_callback
and
self
.
on_change
:
old_value
=
self
.
get_item
(
old_value
)
self
.
on_change
(
self
.
widget
,
item
,
old_value
)
@
GenerativeUI
.
signal_manager
def
reset_value
(
self
):
selected_item
=
self
.
widget
.
set_selected_item
(
self
.
_default_value
)
self
.
_handle_value_changed
(
selected_item
)
def
load_initial_ui
(
self
):
value
=
self
.
get_value
()
selected_item
=
self
.
widget
.
set_selected_item
(
value
)
self
.
_handle_value_changed
(
selected_item
,
False
)
@
GenerativeUI
.
signal_manager
def
set_ui_value
(
self
,
value
:
BaseComboRowItem
|
str
):
"""Sets the selected item in the UI."""
self
.
widget
.
set_selected_item
(
value
)
def
set_value
(
self
,
item
:
BaseComboRowItem
|
str
):
"""Sets the selected item in the UI."""
if
isinstance
(
item
,
BaseComboRowItem
):
value
=
item
.
get_value
()
else
:
value
=
item
super
().
set_value
(
value
)
# Widget Wrappers
def
set_selected_item
(
self
,
item
:
BaseComboRowItem
|
str
=
""
,
update_setting
:
bool
=
False
):
"""Sets the selected item and optionally updates the stored value."""
selected_item
=
self
.
widget
.
set_selected_item
(
item
)
if
update_setting
:
self
.
set_value
(
selected_item
)
return
selected_item
@
GenerativeUI
.
signal_manager
def
add_item
(
self
,
combo_row_item
:
BaseComboRowItem
|
str
):
"""Adds a single item to the combo box."""
self
.
widget
.
add_item
(
combo_row_item
)
@
GenerativeUI
.
signal_manager
def
add_items
(
self
,
items
:
list
[
BaseComboRowItem
]
|
list
[
str
]):
"""Adds multiple items to the combo box."""
self
.
widget
.
add_items
(
items
)
@
GenerativeUI
.
signal_manager
def
remove_item_at_index
(
self
,
index
:
int
):
"""Removes an item from the combo box by its index."""
self
.
widget
.
remove_item_at_index
(
index
)
@
GenerativeUI
.
signal_manager
def
remove_item
(
self
,
item
:
BaseComboRowItem
|
str
):
"""Removes an item from the combo box by its value."""
self
.
widget
.
remove_item
(
item
)
@
GenerativeUI
.
signal_manager
def
remove_items
(
self
,
start
:
int
,
amount
:
int
):
"""Removes a range of items from the combo box."""
self
.
widget
.
remove_items
(
start
,
amount
)
@
GenerativeUI
.
signal_manager
def
remove_all_items
(
self
):
"""Clears all items from the combo box."""
self
.
widget
.
remove_all_items
()
def
get_item_at
(
self
,
index
:
int
)
->
BaseComboRowItem
:
"""Retrieves an item at a specific index."""
return
self
.
widget
.
get_item_at
(
index
)
def
get_item
(
self
,
name
:
str
)
->
BaseComboRowItem
:
"""Retrieves an item by its name."""
return
self
.
widget
.
get_item
(
name
)
def
get_selected_item
(
self
)
->
BaseComboRowItem
|
None
:
"""Returns the currently selected item."""
return
self
.
widget
.
get_selected_item
()
def
get_item_amount
(
self
):
return
self
.
widget
.
get_item_amount
()
@
GenerativeUI
.
signal_manager
def
populate
(
self
,
items
:
list
[
BaseComboRowItem
]
|
list
[
str
],
selected_item
:
BaseComboRowItem
|
str
=
""
,
update_settings
:
bool
=
False
,
trigger_callback
:
bool
=
True
):
"""Repopulates the combo box with new items and optionally updates the selection."""
self
.
widget
.
remove_all_items
()
self
.
widget
.
add_items
(
items
)
selected_item
=
self
.
widget
.
set_selected_item
(
selected_item
)
self
.
_handle_value_changed
(
selected_item
,
update_settings
,
trigger_callback
)
self
.
widget
.
set_selected_item
(
selected_item
)
Back
|
FazBrowse Home
|
New Git URL