Trac is being migrated to new services! Issues can be found in our new YouTrack instance and WIKI pages can be found on our website.

Changes between Version 8 and Version 9 of DbusHowto


Ignore:
Timestamp:
Feb 29, 2016, 8:54:47 AM (8 years ago)
Author:
lew21
Comment:

Update to pydbus and Python 3.

Legend:

Unmodified
Added
Removed
Modified
  • DbusHowto

    v8 v9  
    1313You do the listening and calling; Pidgin does the emitting and replying.
    1414
     15== Setup ==
     16
     17To interact with Pidgin you need to get a reference to Pidgin's D-Bus interface.
     18
     19{{{
     20#!python
     21from pydbus import SessionBus
     22
     23bus = SessionBus()
     24purple = bus.get("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
     25}}}
    1526== Listening to signals ==
    1627
     
    2031{{{
    2132#!python
    22 bus.add_signal_receiver(my_func,
    23                         dbus_interface="im.pidgin.purple.PurpleInterface",
    24                         signal_name="ReceivedImMsg")
     33purple.ReceivedImMsg.connect(my_func)
    2534}}}
    2635
     
    3039{{{
    3140#!python
    32    def my_func(account, sender, message, conversation, flags):
    33        print sender, "said:", message
     41def my_func(account, sender, message, conversation, flags):
     42    print(sender, "said:", message)
    3443}}}
    3544
     
    4049
    4150def my_func(account, sender, message, conversation, flags):
    42     print sender, "said:", message
    43 
    44 import dbus, gobject
    45 from dbus.mainloop.glib import DBusGMainLoop
    46 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    47 bus = dbus.SessionBus()
    48 
    49 bus.add_signal_receiver(my_func,
    50                         dbus_interface="im.pidgin.purple.PurpleInterface",
    51                         signal_name="ReceivedImMsg")
    52 
    53 loop = gobject.MainLoop()
    54 loop.run()
     51    print(sender, "said:", message)
     52
     53from pydbus import SessionBus
     54from gi.repository import GObject
     55
     56bus = SessionBus()
     57purple = bus.get("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
     58purple.ReceivedImMsg.connect(my_func)
     59
     60GObject.MainLoop().run()
    5561}}}
    5662
     
    142148Most of Pidgin's functions can be called through the D-Bus interface. The D-Bus functions have similar names as the C functions, and this is not unlike writing actual Pidgin plugins in C or Perl or Tcl instead.
    143149
    144 To start calling Pidgin functions, you need to get a reference to Pidgin's D-Bus interface. This is in Python:
    145 {{{
    146 #!python
    147 bus = dbus.SessionBus()
    148 obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
    149 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
    150 }}}
    151 
    152 Now you can call Pidgin functions as if they were members of the `purple` object. For example, to send a message to all your IM windows, you can do:
    153 {{{
    154 #!python
    155 for conv in purple.PurpleGetIms():
    156     purple.PurpleConvImSend(purple.PurpleConvIm(conv), "Ignore.")
     150For example, to send a message to all your IM windows, you can do:
     151{{{
     152#!python
     153for conv in purple.PurpleGetIms()[0]:
     154    purple.PurpleConvImSend(purple.PurpleConvIm(conv)[0], "Ignore.")
    157155}}}
    158156
     
    162160def set_message(message):
    163161    # Get current status type (Available/Away/etc.)
    164     current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent())
     162    current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent()[0])[0]
    165163    # Create new transient status and activate it
    166     status = purple.PurpleSavedstatusNew("", current)
     164    status = purple.PurpleSavedstatusNew("", current)[0]
    167165    purple.PurpleSavedstatusSetMessage(status, message)
    168166    purple.PurpleSavedstatusActivate(status)
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!