2012-07-18 4 views
5

버스 이름, 객체 경로 및 인터페이스가있는 경우 Gnome-shell extension에서 DBus 메소드를 호출하는 방법은 무엇입니까?Gjs/Gnome 쉘에서 DBus 메소드 호출

나는 다음과 같은 파이썬 코드에 해당하는 찾고 있어요 :

import dbus 
bus = dbus.SessionBus() 
obj = bus.get_object("org.gnome.Caribou.Keyboard", "/org/gnome/SessionManager/EndSessionDialog") 
obj.Open(0, 0, 120, dbus.Array(signature="o")) 

(I 명시 적으로 인해 일부 파이썬 DBUS 마법 인터페이스를 사용하지 않습니다,하지만 난 iface = dbus.interface(obj, "org.gnome.SessionManager.EndSessionDialog")에있을 수 있었다. Gnome-shell로 다시 호출 할 때 Gnome에서는이 예제가 Gjs에서 어리 석다는 것을주의하십시오.)

답변

1

이렇게하면 더 좋은 아이디어를 얻을 수 있습니다 :

gjs> const DBus = imports.dbus; 
gjs> for (let i in DBus) log(i); 
8

임포트 imports.dbus은 gnome-shell 3.4부터 사용되지 않습니다. here을 설명 새로운 방법은 Gio을 사용하는 것입니다

const Gio = imports.gi.Gio; 

const MyIface = '<interface name="org.example.MyInterface">\ 
<method name="Activate" />\ 
</interface>'; 
const MyProxy = Gio.DBusProxy.makeProxyWrapper(MyIface); 

let instance = new MyProxy(Gio.DBus.session, 'org.example.BusName', 
'/org/example/Path'); 

(정확이 makeProxyWrapper있는 원래의 게시물이 makeProxyClass를 사용합니다.)

할 수 있습니다 예를 들어, 자기 반성을 사용하여 인터페이스 정의를 얻을 수 . 피진/보라색 DO의 경우 : 성찰과 인터페이스의 검사에

$ dbus-send --print-reply --dest=im.pidgin.purple.PurpleService \ 
/im/pidgin/purple/PurpleObject org.freedesktop.DBus.Introspectable.Introspect 

추가 설명은 here를 찾을 수 있습니다.