문제

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.

도움이 되었습니까?

해결책

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()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top