简体   繁体   English

python3的udev接口?

[英]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.

相关问题 来自Python3模块的接口Jython脚本? - Interface Jython script from Python3 module? Python3或C / C ++:TWAIN接口 - Python3 or C/C++: TWAIN interface 'str'不支持Python2中的缓冲接口Python3 - 'str' does not support the buffer interface Python3 from Python2 在python3 tkinter中,wigdet框架未在界面中显示 - In python3 tkinter, the wigdet frame doesn't show in interface Python3 CSV writerows,TypeError:'str'不支持缓冲区接口 - Python3 CSV writerows, TypeError: 'str' does not support the buffer interface TypeError:“ str”不支持缓冲区接口– Python3套接字 - TypeError: 'str' does not support the buffer interface – Python3 sockets Python3 CryptUnprotectData() TypeError 需要一个带有缓冲区接口的 object - Python3 CryptUnprotectData() TypeError expected an object with a buffer interface 使用子进程的Python3 LaTex PDF生成器,错误:memoryview:str对象没有缓冲区接口 - Python3 LaTex PDF generator using subprocess, Error: memoryview: str object does not have the buffer interface Python3 csv DictWriter:通过bz2写入失败(TypeError:'str'/ buffer接口) - Python3 csv DictWriter: writing through bz2 fails (TypeError: 'str'/buffer interface) 如何将 mac os x en1 接口置于监视模式以与 python3 scapy 一起使用? - How can I put mac os x en1 interface into monitor mode to use with python3 scapy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM