Frage

I'm using Gio monitor_file like this.

def callback(*args):
    print 'ok'

gio_pointer = Gio.File.new_for_path(os.environ['HOME']+'/temp')
monitor = gio_pointer.monitor_file(Gio.FileMonitorFlags.NONE, None)
monitor.connect("changed", callback)

Nothing happens for the modified file. Gio works for other file operations like creation, read, and write.

Am I using it wrong, or could this be a system problem?

My environment: Gtk graphics, Python, Linux Ubuntu 12.10, regular pc.

War es hilfreich?

Lösung

It could be failing because gobject's main loop is required in order for signals to work.

The following complete example works for me:

import os
from gi.repository import Gtk, Gio

# This allows Ctrl+C to exit the program
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)

def callback(m, f, o, event):
    # Without this check, multiple 'ok's will be printed for each file change
    if event == Gio.FileMonitorEvent.CHANGES_DONE_HINT:
        print ('ok')

gio_file = Gio.File.new_for_path(os.environ['HOME']+'/temp')
monitor = gio_file.monitor_file(Gio.FileMonitorFlags.NONE, None)
monitor.connect("changed", callback)

Gtk.main()
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top