Help - Search - Members - Calendar
Full Version: DBUS API, Python Trouble
Skype Community > English > Development, Betas and Skype Garage > Archive > Skype for Linux 1.4 Alpha
heshamwhwaf
Hi,
I know I've been asking a lot of questions. This time its with regards to the python API. I've actually had this problem for a while and I'm sure its that I have a newer version of the dbus library installed. The problem is that as far as I can tell the newer api only returns proxies to objects not the actual objects themselves so I'm not quite sure how to override the Invoke method so I can receive callbacks from skype. I don't seem to be receiving any signals either. I'm not sure if I'm doing something wrong or how long I have to wait for the updated API, but its just much easier to use python than the X11 api for example. Another idea is maybe there is a way to decorate the Notify method from my application somehow so that it sends signals that anyone can listen to? Just ideas, but it would be nice to play with this soon. Thanks for your time. If you have any updated examples that work with newer dbus and python versions that I'm unaware of I would be much obliged.

Regards,
Hesham
jaegermeister
Btw, what's the purpose of this API we find in options mask and how do we use it?
THX
heshamwhwaf
QUOTE(jaegermeister @ Sun Jun 10 2007, 22:59) [snapback]404791[/snapback]

Btw, what's the purpose of this API we find in options mask and how do we use it?
THX

The purpose is to let you script the skype application through code rather than having to do stuff manually. One possibility would be to allow one to integrate skype in to another IM application like kopete or something.

Also to add more details to my previous post, the objects I'm getting back when I get the services are now: dbus.proxies.ProxyObject and from it I can get dbus.proxies._ProxyMethod which I don't think help me in terms of getting callbacks hooked up. Signals seem to be the way to go though I'm not really familiar with dbus. If anyone has any ideas or has dealt with this in previous versions of skype I'd be much obliged.
jaegermeister
Oh, thanks. And for people like me, who are not into coding, does already exist some useful stuff?
bye
Ryan Hunt
QUOTE(jaegermeister @ Mon Jun 11 2007, 08:59) [snapback]404901[/snapback]

Oh, thanks. And for people like me, who are not into coding, does already exist some useful stuff?
bye

Yes, there are some hardware devices out there that inter-op with Skype on Mac and Windows, and if some company decided to do so, they could release a hardware phone that worked with Skype for Linux also.
heshamwhwaf
Quick update. This is where I stand. It seems I was more confused than I thought and please ignore my earlier comments. I'm still trying to get callbacks to work but neither using the SystemBus nor the SessionBus am I able to. I've tried using the @dbus.service.method annotation and without, as well as not passing in the [self.Notify] to the constructor. Nothing seems to produce any results. Invoke works fine, but the Notify fails. Is there anything obviously wrong with what I am doing? Does anyone have any hints or advice? I'm using python 2.4.4. Thanks in advance for any help.

Regards,
Hesham

CODE

import sys
import traceback

import gobject

import dbus
import dbus.service
import dbus.mainloop.glib

def input_handler(fd, io_condition):
    print 'INPUT> '
    sys.stdout.flush()
    
    input = fd.readline()
    if len(input) == 0:     # EOF
        loop.quit()
        return 0
    print out_connection.Invoke(input)
    return 1

class Callback_obj(dbus.service.Object):
    def __init__(self, bus, object_path):
        dbus.service.Object.__init__(self, bus, object_path, [self.Notify])
    
    @dbus.service.method(dbus_interface='com.Skype.API')
    def Notify(self, message, message_text):
        print 'hello'
        print message_text

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

remote_bus = dbus.SessionBus()

out_connection = remote_bus.get_object('com.Skype.API', '/com/Skype')

print out_connection.Invoke('NAME mytestapp')
print out_connection.Invoke('PROTOCOL 5')

callback_obj = Callback_obj(remote_bus, '/com/Skype/Client')
#callback_obj = Callback_obj(dbus.SessionBus(), '/com/Skype/Client')
#callback_obj2 = Callback_obj(dbus.SystemBus(), '/com/Skype/Client')
#callback_obj3 = Callback_obj(dbus.SessionBus(), '/com/Skype/Client')

gobject.io_add_watch(sys.stdin, gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP, input_handler)
loop = gobject.MainLoop()
loop.run()
heshamwhwaf
Final update. I finally got the connection working. I was afraid I'd have to use the C++ X11 or DBUS APIs which I fear are overkill for the kind of scripting I'd like to do. Below I've posted my sample skeleton framework that lets me connect to skype and then post commands to it and see whatever I get back. The next question that I have is if there is a headless mode available or coming with the 1.4 release so that one needn't have X11 running to connect to skype? I could always use Xvfb or something similar to run it but if there is a headless mode that would be best. Thanks in advance for your help once again smile.png

Regards,
Hesham

CODE

import sys
import traceback

import gobject

import dbus
import dbus.service
import dbus.mainloop.glib

def input_handler(fd, io_condition):
    input = fd.readline()
    if len(input) == 0:     # EOF
        loop.quit()
        return 0
    print out_connection.Invoke(input)
    return 1

class Callback_obj(dbus.service.Object):
    def __init__(self, bus, object_path):
        dbus.service.Object.__init__(self, bus, object_path, bus_name='com.Skype.API')

    @dbus.service.method(dbus_interface='com.Skype.API')
    def Notify(self, message_text):
        print message_text

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

remote_bus = dbus.SessionBus()

out_connection = remote_bus.get_object('com.Skype.API', '/com/Skype')

print out_connection.Invoke('NAME myapp')
print out_connection.Invoke('PROTOCOL 5')

callback_obj = Callback_obj(remote_bus, '/com/Skype/Client')

gobject.io_add_watch(sys.stdin, gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP, input_handler)
loop = gobject.MainLoop()
loop.run()
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.