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.
- 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
-
|
v8
|
v9
|
|
| 13 | 13 | You do the listening and calling; Pidgin does the emitting and replying. |
| 14 | 14 | |
| | 15 | == Setup == |
| | 16 | |
| | 17 | To interact with Pidgin you need to get a reference to Pidgin's D-Bus interface. |
| | 18 | |
| | 19 | {{{ |
| | 20 | #!python |
| | 21 | from pydbus import SessionBus |
| | 22 | |
| | 23 | bus = SessionBus() |
| | 24 | purple = bus.get("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") |
| | 25 | }}} |
| 15 | 26 | == Listening to signals == |
| 16 | 27 | |
| … |
… |
|
| 20 | 31 | {{{ |
| 21 | 32 | #!python |
| 22 | | bus.add_signal_receiver(my_func, |
| 23 | | dbus_interface="im.pidgin.purple.PurpleInterface", |
| 24 | | signal_name="ReceivedImMsg") |
| | 33 | purple.ReceivedImMsg.connect(my_func) |
| 25 | 34 | }}} |
| 26 | 35 | |
| … |
… |
|
| 30 | 39 | {{{ |
| 31 | 40 | #!python |
| 32 | | def my_func(account, sender, message, conversation, flags): |
| 33 | | print sender, "said:", message |
| | 41 | def my_func(account, sender, message, conversation, flags): |
| | 42 | print(sender, "said:", message) |
| 34 | 43 | }}} |
| 35 | 44 | |
| … |
… |
|
| 40 | 49 | |
| 41 | 50 | def 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 | |
| | 53 | from pydbus import SessionBus |
| | 54 | from gi.repository import GObject |
| | 55 | |
| | 56 | bus = SessionBus() |
| | 57 | purple = bus.get("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") |
| | 58 | purple.ReceivedImMsg.connect(my_func) |
| | 59 | |
| | 60 | GObject.MainLoop().run() |
| 55 | 61 | }}} |
| 56 | 62 | |
| … |
… |
|
| 142 | 148 | Most 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. |
| 143 | 149 | |
| 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.") |
| | 150 | For example, to send a message to all your IM windows, you can do: |
| | 151 | {{{ |
| | 152 | #!python |
| | 153 | for conv in purple.PurpleGetIms()[0]: |
| | 154 | purple.PurpleConvImSend(purple.PurpleConvIm(conv)[0], "Ignore.") |
| 157 | 155 | }}} |
| 158 | 156 | |
| … |
… |
|
| 162 | 160 | def set_message(message): |
| 163 | 161 | # Get current status type (Available/Away/etc.) |
| 164 | | current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent()) |
| | 162 | current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent()[0])[0] |
| 165 | 163 | # Create new transient status and activate it |
| 166 | | status = purple.PurpleSavedstatusNew("", current) |
| | 164 | status = purple.PurpleSavedstatusNew("", current)[0] |
| 167 | 165 | purple.PurpleSavedstatusSetMessage(status, message) |
| 168 | 166 | 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!