Gio.FileMonitor

g GObject.Object GObject.Object Gio.FileMonitor Gio.FileMonitor GObject.Object->Gio.FileMonitor

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

cancel ()

emit_event (child, other_file, event_type)

is_cancelled ()

set_rate_limit (limit_msecs)

Virtual Methods

Inherited:

GObject.Object (7)

do_cancel ()

do_changed (file, other_file, event_type)

Properties

Name

Type

Flags

Short Description

cancelled

bool

r

Whether the monitor has been cancelled

rate-limit

int

r/w/en

The limit of the monitor to watch for changes, in milliseconds

Signals

Inherited:

GObject.Object (1)

Name

Short Description

changed

Emitted when file has been changed.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Gio.FileMonitor(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Gio.FileMonitorClass

Monitors a file or directory for changes.

To obtain a Gio.FileMonitor for a file or directory, use Gio.File.monitor(), Gio.File.monitor_file(), or Gio.File.monitor_directory().

To get informed about changes to the file or directory you are monitoring, connect to the Gio.FileMonitor ::changed signal. The signal will be emitted in the thread-default main context 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).

cancel()[source]
Returns:

always True

Return type:

bool

Cancels a file monitor.

emit_event(child, other_file, event_type)[source]
Parameters:

Emits the Gio.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 of the thread that the monitor was created in.

is_cancelled()[source]
Returns:

True if monitor is canceled. False otherwise.

Return type:

bool

Returns whether the monitor is canceled.

set_rate_limit(limit_msecs)[source]
Parameters:

limit_msecs (int) – a non-negative integer with the limit in milliseconds to poll for changes

Sets the rate limit to which the self will report consecutive change events to the same file.

do_cancel() virtual
Returns:

always True

Return type:

bool

Cancels a file monitor.

do_changed(file, other_file, event_type) virtual
Parameters:

Signal Details

Gio.FileMonitor.signals.changed(file_monitor, file, other_file, event_type)
Signal Name:

changed

Flags:

RUN_LAST

Parameters:

Emitted when file has been changed.

If using Gio.FileMonitorFlags.WATCH_MOVES on a directory monitor, and the information is available (and if supported by the backend), event_type may be Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN or Gio.FileMonitorEvent.MOVED_OUT.

In all cases file will be a child of the monitored directory. For renames, file will be the old name and other_file is the new name. For “moved in” events, file is the name of the file that appeared and other_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 and other_file is the name of the file at its new location.

It makes sense to treat Gio.FileMonitorEvent.MOVED_IN as equivalent to Gio.FileMonitorEvent.CREATED and Gio.FileMonitorEvent.MOVED_OUT as equivalent to Gio.FileMonitorEvent.DELETED, with extra information. Gio.FileMonitorEvent.RENAMED is equivalent to a delete/create pair. This is exactly how the events will be reported in the case that the Gio.FileMonitorFlags.WATCH_MOVES flag is not in use.

If using the deprecated flag Gio.FileMonitorFlags.SEND_MOVED flag and event_type is Gio.FileMonitorEvent.MOVED, file will be set to a Gio.File containing the old path, and other_file will be set to a Gio.File containing the new path.

In all the other cases, other_file will be set to None.

Property Details

Gio.FileMonitor.props.cancelled
Name:

cancelled

Type:

bool

Default Value:

False

Flags:

READABLE

Whether the monitor has been cancelled

Gio.FileMonitor.props.rate_limit
Name:

rate-limit

Type:

int

Default Value:

800

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The limit of the monitor to watch for changes, in milliseconds