FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
StreamController/GtkHelper/GenerativeUI/FileDialogRow.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
/
FileDialogRow.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
113 lines (92 loc) · 4.58 KB
Breadcrumbs
StreamController
/
GtkHelper
/
GenerativeUI
/
FileDialogRow.py
Copy path
File metadata and controls
113 lines (92 loc) · 4.58 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
from
dataclasses
import
dataclass
from
GtkHelper
.
GenerativeUI
.
GenerativeUI
import
GenerativeUI
from
GtkHelper
.
FileDialogRow
import
FileDialogRow
as
FileDialog
,
FileDialogFilter
import
gi
from
gi
.
repository
import
Gtk
,
Adw
,
Gio
,
Gdk
from
typing
import
TYPE_CHECKING
,
Callable
if
TYPE_CHECKING
:
from
src
.
backend
.
PluginManager
.
ActionCore
import
ActionCore
class
FileDialogRow
(
GenerativeUI
[
str
]):
"""
A class that represents a file dialog row widget that allows the user to select a file
from the file system. It includes functionality to display a dialog with filters and
manage the file selection.
Inherits from `GenerativeUI` to provide generic UI management and functionality.
Attributes:
selected_file (Gio.File): The currently selected file in the dialog.
"""
def
__init__
(
self
,
action_core
:
"ActionCore"
,
var_name
:
str
,
default_value
:
str
,
title
:
str
=
None
,
subtitle
:
str
=
None
,
dialog_title
:
str
=
None
,
block_interaction
:
bool
=
True
,
only_show_filename
:
bool
=
True
,
filters
:
list
[
FileDialogFilter
]
=
None
,
on_change
:
callable
=
None
,
can_reset
:
bool
=
True
,
auto_add
:
bool
=
True
,
complex_var_name
:
bool
=
False
):
"""
Initializes the FileDialogRow widget with a file dialog for selecting a file.
Args:
action_core (ActionCore): The base action that provides context for this file dialog row.
var_name (str): The variable name to associate with this file dialog row.
default_value (str): The initial path to display in the file dialog.
title (str, optional): The title to display for the file dialog row.
subtitle (str, optional): The subtitle to display for the file dialog row.
dialog_title (str, optional): The title of the file dialog window.
block_interaction (bool, optional): Whether to block interaction while the dialog is open. Defaults to True.
only_show_filename (bool, optional): Whether to display only the filename in the dialog. Defaults to True.
filters (list[FileDialogFilter], optional): A list of file dialog filters to apply. Defaults to None.
on_change (callable, optional): A callback function to call when the file selection changes.
can_reset (bool, optional): Whether the value can be reset. Defaults to True.
auto_add (bool, optional): Whether to automatically add this entry to the UI. Defaults to True.
"""
super
().
__init__
(
action_core
,
var_name
,
default_value
,
can_reset
,
auto_add
,
complex_var_name
,
on_change
)
self
.
_widget
:
FileDialog
=
FileDialog
(
title
=
self
.
get_translation
(
title
),
subtitle
=
self
.
get_translation
(
subtitle
),
dialog_title
=
self
.
get_translation
(
dialog_title
),
initial_path
=
default_value
,
block_interaction
=
block_interaction
,
only_show_filename
=
only_show_filename
,
filters
=
filters
,
file_change_callback
=
self
.
_file_changed
)
self
.
_handle_reset_button_creation
()
def
set_file
(
self
,
path
:
str
,
update_setting
:
bool
=
False
):
"""
Sets the file path in the file dialog widget and optionally updates the associated setting.
Args:
path (str): The file path to set in the file dialog.
update_setting (bool, optional): If True, updates the setting with the new file path. Defaults to False.
"""
self
.
set_ui_value
(
path
)
if
update_setting
:
self
.
set_value
(
path
)
def
get_file
(
self
)
->
Gio
.
File
:
"""
Retrieves the currently selected file from the file dialog.
Returns:
Gio.File: The selected file in the file dialog.
"""
return
self
.
widget
.
selected_file
def
_file_changed
(
self
,
file
:
Gio
.
File
):
"""
Handles the change in file selection in the file dialog.
This method is called when the user selects a new file. It updates the associated value accordingly.
Args:
file (Gio.File): The newly selected file in the file dialog.
"""
self
.
_handle_value_changed
(
file
.
get_path
())
@
GenerativeUI
.
signal_manager
def
set_ui_value
(
self
,
value
:
str
):
"""
Sets the value (file path) in the UI file dialog widget.
Args:
value (str): The file path to set in the UI widget.
"""
self
.
widget
.
load_from_path
(
value
)
Back
|
FazBrowse Home
|
New Git URL