Created
September 5, 2012 17:42
-
-
Save cwacek/3640980 to your computer and use it in GitHub Desktop.
Skype DBus example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://forum.skype.com/index.php?showtopic=480701 | |
import time | |
import gobject | |
import dbus, sys | |
import dbus.service | |
from dbus.mainloop.glib import DBusGMainLoop | |
from threading import Thread | |
class SkypeNotify(dbus.service.Object): | |
"""DBus object which exports a Notify method. This will be called by Skype for all | |
notifications with the notification string as a parameter. The Notify method of this | |
class calls in turn the callable passed to the constructor. | |
""" | |
def __init__(self, bus): | |
dbus.service.Object.__init__(self, bus, '/com/Skype/Client') | |
print 'Skype notify init done' | |
@dbus.service.method(dbus_interface='com.Skype.API.Client') | |
def Notify(self, com): | |
print 'it works, that s what I got from Skype:' | |
print com | |
class My_Skype(Thread): | |
def __init__(self): | |
remote_bus = dbus.SessionBus(mainloop=DBusGMainLoop(set_as_default=True)) | |
system_service_list = remote_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames() | |
skype_api_found = 0 | |
print 'testInit2' | |
for service in system_service_list: | |
if service == 'com.Skype.API': | |
skype_api_found = 1 | |
break | |
if not skype_api_found: | |
sys.exit('No running API-capable Skype found') | |
self.skype_api_object = remote_bus.get_object('com.Skype.API', '/com/Skype') | |
answer = self.send_dbus_message('NAME SkypeApiPythonTestClient') | |
if answer != 'OK': | |
sys.exit('Could not bind to Skype client') | |
print "OK:", answer | |
answer = self.send_dbus_message('PROTOCOL 7') | |
print "PROTOCOL 7:", answer | |
if answer != 'PROTOCOL 7': | |
sys.exit('This test program only supports Skype API protocol version 7') | |
print 'TestInit3' | |
self.skype_in = SkypeNotify(remote_bus) | |
gobject.threads_init() | |
Thread.__init__(self) | |
def run(self): | |
mainloop = gobject.MainLoop() | |
context = mainloop.get_context() | |
while True: | |
context.iteration(False) | |
time.sleep(0.2) | |
# Client -> Skype | |
def send_dbus_message(self, message): | |
response = self.skype_api_object.Invoke(message) | |
return response | |
if __name__ == "__main__": | |
t = My_Skype() | |
t.start(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment