本文介绍了我使用Gio GFile monitor_file错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这样使用Gio monitor_file.
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)
修改后的文件没有任何反应.Gio可以进行其他文件操作,例如创建,读取和写入.
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?
我的环境:Gtk图形,Python,Linux Ubuntu 12.10,常规PC.
My environment: Gtk graphics, Python, Linux Ubuntu 12.10, regular pc.
推荐答案
它可能会失败,因为需要gobject的主循环才能使信号正常工作.
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()
这篇关于我使用Gio GFile monitor_file错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!