Use syntax highlighting on Python snippets
parent
6eceb0a21b
commit
fdb8556f44
|
@ -97,25 +97,29 @@ See [the MPRIS specifications](MPRIS#The_specifications) for information about t
|
|||
|
||||
It's easy to use the [dbus python module](http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html) to control Clementine from a Python script.
|
||||
|
||||
import dbus
|
||||
|
||||
# Clementine lives on the Session bus
|
||||
session_bus = dbus.SessionBus()
|
||||
|
||||
# Get Clementine's player object, and then get an interface from that object,
|
||||
# otherwise we'd have to type out the full interface name on every method call.
|
||||
player = session_bus.get_object('org.mpris.clementine', '/Player')
|
||||
iface = dbus.Interface(player, dbus_interface='org.freedesktop.MediaPlayer')
|
||||
|
||||
# Call a method on the interface
|
||||
metadata = iface.GetMetadata()
|
||||
print metadata["title"]
|
||||
print metadata["artist"]
|
||||
```python
|
||||
import dbus
|
||||
|
||||
# Clementine lives on the Session bus
|
||||
session_bus = dbus.SessionBus()
|
||||
|
||||
# Get Clementine's player object, and then get an interface from that object,
|
||||
# otherwise we'd have to type out the full interface name on every method call.
|
||||
player = session_bus.get_object('org.mpris.clementine', '/Player')
|
||||
iface = dbus.Interface(player, dbus_interface='org.freedesktop.MediaPlayer')
|
||||
|
||||
# Call a method on the interface
|
||||
metadata = iface.GetMetadata()
|
||||
print metadata["title"]
|
||||
print metadata["artist"]
|
||||
```
|
||||
|
||||
Notice we're calling the same `GetMetadata` method as we did in the section above with the commandline. It gives us back a dictionary that contains the same information that qdbus printed out before.
|
||||
|
||||
Controlling the player is done in the same way, we just call a different method on that interface:
|
||||
|
||||
iface.Play()
|
||||
iface.Pause()
|
||||
iface.VolumeSet(50)
|
||||
```python
|
||||
iface.Play()
|
||||
iface.Pause()
|
||||
iface.VolumeSet(50)
|
||||
```
|
Loading…
Reference in New Issue