FileMonitor#
Superclasses: Object
Monitors a file or directory for changes.
To obtain a GFileMonitor for a file or directory, use
monitor, monitor_file, or
monitor_directory.
To get informed about changes to the file or directory you are
monitoring, connect to the changed signal. The
signal will be emitted in the thread-default main context (see
push_thread_default) of the thread that the monitor
was created in (though if the global default main context is blocked, this
may cause notifications to be blocked even if the thread-default
context is still running).
Methods#
- class FileMonitor
-
- do_changed(self, file: File, other_file: File, event_type: FileMonitorEvent) None#
- Parameters:
file
other_file
event_type
- emit_event(child: File, other_file: File | None, event_type: FileMonitorEvent) None#
Emits the
FileMonitor::changed signal if a change has taken place. Should be called from file monitor implementations only.Implementations are responsible to call this method from the thread-default main context (see
push_thread_default) of the thread that the monitor was created in.- Parameters:
child – a
File.other_file – a
File, orNone.event_type – a set of
FileMonitorEventflags.
Properties#
Signals#
- class FileMonitor.signals
- changed(file: File, other_file: File | None, event_type: FileMonitorEvent) None#
Emitted when
filehas been changed.If using
WATCH_MOVESon a directory monitor, and the information is available (and if supported by the backend),event_typemay beRENAMED,MOVED_INorMOVED_OUT.In all cases
filewill be a child of the monitored directory. For renames,filewill be the old name andother_fileis the new name. For “moved in” events,fileis the name of the file that appeared andother_fileis the old name that it was moved from (in another directory). For “moved out” events,fileis the name of the file that used to be in this directory andother_fileis the name of the file at its new location.It makes sense to treat
MOVED_INas equivalent toCREATEDandMOVED_OUTas equivalent toDELETED, with extra information.RENAMEDis equivalent to a delete/create pair. This is exactly how the events will be reported in the case that theWATCH_MOVESflag is not in use.If using the deprecated flag
SEND_MOVEDflag andevent_typeisMOVED,filewill be set to aFilecontaining the old path, andother_filewill be set to aFilecontaining the new path.In all the other cases,
other_filewill be set toNone.- Parameters:
file – a
File.other_file – a
FileorNone.event_type – a
FileMonitorEvent.