Gtk.DirectoryList¶
class — extends GObject.Object, Gio.ListModel
A list model that wraps Gio.File.enumerate_children_async.
It presents a GListModel and fills it asynchronously with the GFileInfos
returned from that function.
Enumeration will start automatically when the
DirectoryList.file property is set.
While the GtkDirectoryList is being filled, the
DirectoryList.loading property will be set to True. You can
listen to that property if you want to show information like a GtkSpinner
or a "Loading..." text.
If loading fails at any point, the DirectoryList.error
property will be set to give more indication about the failure.
The GFileInfos returned from a GtkDirectoryList have the "standard::file"
attribute set to the GFile they refer to. This way you can get at the file
that is referred to in the same way you would via Gio.FileEnumerator.get_child.
This means you do not need access to the GtkDirectoryList, but can access
the GFile directly from the GFileInfo when operating with a GtkListView
or similar.
Constructors¶
new¶
@classmethod
def new(cls, attributes: str | None = ..., file: Gio.File | None = ...) -> DirectoryList
Creates a new GtkDirectoryList.
The GtkDirectoryList is querying the given file
with the given attributes.
Parameters:
attributes— The attributes to query withfile— The file to query
Methods¶
get_attributes¶
Gets the attributes queried on the children.
get_error¶
Gets the loading error, if any.
If an error occurs during the loading process, the loading process will finish and this property allows querying the error that happened. This error will persist until a file is loaded again.
An error being set does not mean that no files were loaded, and all successfully queried files will remain in the list.
get_file¶
Gets the file whose children are currently enumerated.
get_io_priority¶
Gets the IO priority set via DirectoryList.set_io_priority.
get_monitored¶
Returns whether the directory list is monitoring the directory for changes.
is_loading¶
Returns True if the children enumeration is currently in
progress.
Files will be added to self from time to time while loading is
going on. The order in which are added is undefined and may change
in between runs.
set_attributes¶
Sets the attributes to be enumerated and starts the enumeration.
If attributes is None, the list of file infos will still be created, it will just
not contain any extra attributes.
Parameters:
attributes— the attributes to enumerate
set_file¶
Sets the file to be enumerated and starts the enumeration.
If file is None, the result will be an empty list.
Parameters:
file— theGFileto be enumerated
set_io_priority¶
Sets the IO priority to use while loading directories.
Setting the priority while self is loading will reprioritize the
ongoing load as soon as possible.
The default IO priority is GLib.PRIORITY_DEFAULT, which is higher than
the GTK redraw priority. If you are loading a lot of directories in
parallel, lowering it to something like GLib.PRIORITY_DEFAULT_IDLE
may increase responsiveness.
Parameters:
io_priority— IO priority to use
set_monitored¶
Sets whether the directory list will monitor the directory for changes.
If monitoring is enabled, the ::items-changed signal will be emitted when the directory contents change.
When monitoring is turned on after the initial creation of the directory list, the directory is reloaded to avoid missing files that appeared between the initial loading and when monitoring was turned on.
Parameters:
monitored—Trueto monitor the directory for changes
Properties¶
attributes¶
The attributes to query.
error¶
Error encountered while loading files.
file¶
File to query.
io_priority¶
Priority used when loading.
item_type¶
The type of items. See Gio.ListModel.get_item_type.
loading¶
True if files are being loaded.
monitored¶
True if the directory is monitored for changed.
n_items¶
The number of items. See Gio.ListModel.get_n_items.