i3pyblocks.blocks.dbus

Blocks related to D-Bus, based on dbus-next.

To inspect and debug a D-Bus protocol, DFeet can help.

Module Contents

Classes

DbusBlock

D-Bus Block.

KbddBlock

Block that shows X11 keyboard layout based on kbdd daemon.

MediaPlayerBlock

Block that shows media player that support MPRIS2 specification.

class i3pyblocks.blocks.dbus.DbusBlock(bus_name: str, object_path: str, interface_name: str, dbus_conn_sleep: int = 1, **kwargs)

Bases: i3pyblocks.blocks.Block

D-Bus Block.

This Block extends the i3pyblocks.blocks.base.Block by offering some helper methods to work with D-Bus.

You must not instantiate this class directly, instead you should subclass it and implement start() method first.

Parameters
  • bus_name – The D-Bus bus name to introspect, i.e.: org.mpris.MediaPlayer2.spotify.

  • object_name – The D-Bus object to introspect, i.e.: /org/mpris/MediaPlayer2.

  • interface_name – The D-Bus interface to introspect, i.e.: org.mpris.MediaPlayer2.

  • dbus_conn_sleep – Used only before the initial connection, as a sleep between the calls in loop before the connection is successful. After the connection between the interface is made, this value is not used anymore.

  • **kwargs – Extra arguments to be passed to Block class.

async setup(self, queue: Optional[asyncio.Queue] = None) None
async get_object_via_introspection(self, bus_name: str, object_path: str) dbus_next.aio.ProxyObject
async get_interface_via_introspection(self, bus_name: str, object_path: str, interface_name: str) dbus_next.aio.ProxyInterface
async wait_interface(self) None
async safe_method_call(self, method: str, *args) Any

Safely call a D-Bus method from interface.

Parameters
  • property – Name of a D-Bus method, just in snake_case form instead of camelCase.

  • *args – Positional arguments to be passed to the method.

async safe_property_set(self, property: str, value: Any) None

Safely set a D-Bus property from interface.

Parameters
  • property – Name of a D-Bus property, just in snake_case form instead of camelCase.

  • value – Value to set the property.

async safe_property_get(self, property: str) Any

Safely get a D-Bus property from interface.

Parameters

property – Name of a D-Bus property, just in snake_case form instead of camelCase.

safe_signal_call(self, signal: str, callback: Callable[Ellipsis, None]) None

Safely listen a D-Bus signal from interface.

Parameters
  • signal – Name of a D-Bus signal, just in snake_case form instead of camelCase.

  • callback – Callback function to be run when the signal is received.

class i3pyblocks.blocks.dbus.KbddBlock(format: str = '{full_layout}', **kwargs)

Bases: DbusBlock

Block that shows X11 keyboard layout based on kbdd daemon.

Provisional block subject to changes/removal.

Needs kbdd daemon installed and running. In i3wm, add this to your $HOME/.config/i3/config file:

# keyboard layout daemon
exec --no-startup-id kbdd
Parameters

format

Format string to shown. Supports the following placeholders:

  • {full_layout}: Full layout name. Quite verbose, i.e.: ‘English (US, intl., with dead keys)’

bus_name = ru.gentoo.KbddService
object_path = /ru/gentoo/KbddService
interface_name = ru.gentoo.kbdd
async click_handler(self, button: int, **_kwargs) None
async update_layout(self) None
update_callback(self, layout_name: str) None
async start(self) None
class i3pyblocks.blocks.dbus.MediaPlayerBlock(player: str = 'spotify', format: str = '{artist} - {track_number}. {title}', color_playing: Optional[str] = None, background_playing: Optional[str] = None, **kwargs)

Bases: DbusBlock

Block that shows media player that support MPRIS2 specification.

Parameters
  • format

    Format string to shown. Supports the following placeholders:

    • {artist}: Artist name. If more than one, it will be joined using ‘, ‘ as separator

    • {title}: Title name.

    • {track_number}: Track number.

  • color_playing – Color to display when media is “Playing”

  • background_playing – Background to display when media is “Playing”

bus_name = org.mpris.MediaPlayer2.{player}
object_path = /org/mpris/MediaPlayer2
interface_name = org.freedesktop.DBus.Properties
update_properties(self, properties: Dict[str, dbus_next.Variant]) None
update_callback(self, interface_name: str, changed_properties: Dict[str, dbus_next.Variant], invalidated_properties: List[dbus_next.Variant]) None
async start(self) None