FileMonitor#

class ignis.utils.Utils.FileMonitor(path: str, recursive: bool = False, flags: gi.repository.Gio.FileMonitorFlags = gi.repository.Gio.FileMonitorFlags.NONE, callback: Callable | None = None, prevent_gc: bool = True)#

Monitor changes of the file or directory.

Parameters:
  • path (str) -- The path to the file or directory to be monitored.

  • recursive (bool, default: False) -- Whether monitoring is recursive (monitor all subdirectories and files).

  • flags (FileMonitorFlags, default: gi.repository.Gio.FileMonitorFlags.NONE) -- What the monitor will watch for. See Gio.FileMonitorFlags for more info.

  • callback (Callable | None, default: None) -- A function to call when the file or directory changes. See callback for more info.

  • prevent_gc (bool, default: True) -- Whether to prevent the garbage collector from collecting this file monitor.

Example usage:

Utils.FileMonitor(
    path="path/to/something",
    recursive=False,
    callback=lambda path, event_type: print(path, event_type),
)
signal changed#

Emitted when the file or directory changed.

Parameters:
  • path (str) -- The path to the changed file or directory.

  • event_type (str) -- The event type. A list of all event types described in callback.

gproperty path: str#
  • read-only

The path to the file or directory to be monitored.

gproperty flags: gi.repository.Gio.FileMonitorFlags#
  • read-only

What the monitor will watch for.

See Gio.FileMonitorFlags for more info.

gproperty callback: Callable | None#
  • read-write

A function to call when the file or directory changes. It should take two arguments: 1. The path to the changed file or directory 2. The event type.

Event types:

  • changed

  • changes_done_hint

  • moved_out

  • deleted

  • created

  • attribute_changed

  • pre_unmount

  • unmounted

  • moved

  • renamed

  • moved_in

See Gio.FileMonitorEvent for more info.

gproperty recursive: bool#
  • read-only

Whether monitoring is recursive (monitor all subdirectories and files).

gproperty prevent_gc: bool#
  • read-only

Whether to prevent the garbage collector from collecting this file monitor.

cancel() None#

Cancel the monitoring process.

Return type:

None