2012-10-24 2 views
2

내 넷북에서 외부 모니터를 활성화하거나 비활성화하는 간단한 스크립트를 먼저 호출 할 수 있기를 원합니다. 내 데스크톱으로 XFCE를 사용하여 Fedora 17을 실행하고 있습니다. 파이썬과 파이썬 dbus를 사용하여 토글을 켜고 끌 수 있어야합니다. 내 문제는 새로운 설정을 활성화하는 신호를 보내는 방법을 알아낼 수 없다는 것입니다. 불행히도 파이썬은 내가 자주 사용하는 언어가 아닙니다. 내가 자리에있는 코드는 : 그것은 실패 밖으로 걷어차는Python-dbus를 사용하여 dbus에서 신호 방출

import dbus 
item = 'org.xfce.Xfconf' 
path = '/org/xfce/Xfconf' 
channel = 'displays' 
base = '/' 
setting = '/Default/VGA1/Active' 

bus = dbus.SessionBus() 
remote_object = bus.get_object(item, path) 
remote_interface = dbus.Interface(remote_object, "org.xfce.Xfconf") 

if remote_interface.GetProperty(channel, setting): 
    remote_interface.SetProperty(channel, setting, '0') 
    remote_object.PropertyChanged(channel, setting, '0') 
else: 
    remote_interface.SetProperty(channel, setting, '1') 
    remote_object.PropertyChanged(channel, setting, '0') 

:

Traceback (most recent call last): File "./vgaToggle", line 31, in <module> 
remote_object.PropertyChanged(channel, setting, '0') 
File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 140, in __call__ 
**keywords) 
File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 630, in call_blocking 
message, timeout) dbus.exceptions.DBusException: 
org.freedesktop.DBus.Error.UnknownMethod: Method "PropertyChanged" 
with signature "sss" on interface "(null)" doesn't exist 

내가 검색 시간이 약간의 시간에 나는이 가까이에 아무것도 많은 파이썬 예제를 발견하고 있지 않다 . 미리 감사드립니다.

답변

0

PropertyChanged은 신호가 아니라 방법입니다. 통신하는 서비스는 신호를 방출합니다. 이 경우 PropertyChanged은 해당 객체 또는 인터페이스의 속성 값이 변경 될 때마다 암시 적으로 실행되어야합니다.

remote_interface.SetProperty(...)을 호출 할 때 암시 적으로 발생해야하며 메서드와 같이 신호를 명시 적으로 호출 할 필요가 없습니다.

신호 수신에 관심이 있다면 glib 메인 루프를 설정하고 프록시 객체에 connect_to_signal을 호출하여 호출 할 콜백 메소드를 전달해야합니다.

관련 문제