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
-
- emit_event(child: File, other_file: File, 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][g-main-context-push-thread-default] of the thread that the monitor was created in.
- Parameters:
child – a
File
.other_file – a
File
.event_type – a set of
FileMonitorEvent
flags.
Properties
Signals
- class FileMonitor.signals
- changed(file: File, other_file: File | None, event_type: FileMonitorEvent) None
Emitted when
file
has been changed.If using
WATCH_MOVES
on a directory monitor, and the information is available (and if supported by the backend),event_type
may beRENAMED
,MOVED_IN
orMOVED_OUT
.In all cases
file
will be a child of the monitored directory. For renames,file
will be the old name andother_file
is the new name. For “moved in” events,file
is the name of the file that appeared andother_file
is the old name that it was moved from (in another directory). For “moved out” events,file
is the name of the file that used to be in this directory andother_file
is the name of the file at its new location.It makes sense to treat
MOVED_IN
as equivalent toCREATED
andMOVED_OUT
as equivalent toDELETED
, with extra information.RENAMED
is equivalent to a delete/create pair. This is exactly how the events will be reported in the case that theWATCH_MOVES
flag is not in use.If using the deprecated flag
SEND_MOVED
flag andevent_type
isMOVED
,file
will be set to aFile
containing the old path, andother_file
will be set to aFile
containing the new path.In all the other cases,
other_file
will be set toNone
.- Parameters:
file – a
File
.other_file – a
File
orNone
.event_type – a
FileMonitorEvent
.