[英]udev interface for python3?
Is there any example on how to capture udev
events in Python3?有没有关于如何在 Python3 中捕获
udev
事件的示例? I can't get events working at all in.237 (or 1.0?).我无法让事件在.237(或 1.0?)中工作。 And couldn't get any examples of GUdev with Introspection.
并且无法通过 Introspection 获得任何GUdev 示例。
I'm not sure where the problem lies.我不确定问题出在哪里。 I found an example
test.py
but there, parameters are given when instantiating Client
like in client = GUdev.Client(['block'])
.我找到了一个示例
test.py
但在那里,在实例化Client
时给出了参数,例如client = GUdev.Client(['block'])
。 Those parameters are not accepted in the actual version ( TypeError: GObject.__init__() takes exactly 0 arguments (1 given)
).实际版本中不接受这些参数(
TypeError: GObject.__init__() takes exactly 0 arguments (1 given)
)。
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GUdev', '1.0')
from gi.repository import Gtk, GUdev, GLib
def on_uevent(client, action, device):
print(action)
client = GUdev.Client()
client.connect('uevent', on_uevent)
GLib.MainLoop().run()
Ah, well.呃,好吧。 Seems the G(NU|nome|object)-Introspection changed a few things in its workings.
似乎 G(NU|nome|object)-Introspection 在其工作中改变了一些东西。
...
client = GUdev.Client.new(['block'])
client.connect('uevent', on_uevent)
...
works fine.工作正常。 I don't know why the old syntax (see above) doesn't throw any errors...
我不知道为什么旧语法(见上文)不会抛出任何错误......
BTW, GUdev.Client.new(['block'])
accepts multiple values in the list.顺便说一句,
GUdev.Client.new(['block'])
接受列表中的多个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.