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¶
D-Bus Block. |
|
Block that shows X11 keyboard layout based on kbdd daemon. |
|
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.BlockD-Bus Block.
This Block extends the
i3pyblocks.blocks.base.Blockby 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
Blockclass.
-
async
setup(self, queue: Optional[asyncio.Queue] = None) → None¶ Setup a Block.
This method is called just before
start()to setup some things necessary to make the Block work.If you want to do some kinda of async initialization, override this function and put your code here. However, do not forget to call
await super().setup(queue=queue)after your code to prepare your Block for updates.- Parameters
queue – asyncio.Queue instance that will be used to notify updates from this Block.
-
async
get_object_via_introspection(self, bus_name: str, object_path: str) → dbus_aio.ProxyObject¶
-
async
get_interface_via_introspection(self, bus_name: str, object_path: str, interface_name: str) → dbus_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_caseform instead ofcamelCase.*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_caseform instead ofcamelCase.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_caseform instead ofcamelCase.
-
safe_signal_call(self, signal: str, callback: Callable[…, None]) → None¶ Safely listen a D-Bus signal from interface.
- Parameters
signal – Name of a D-Bus signal, just in
snake_caseform instead ofcamelCase.callback – Callback function to be run when the signal is received.
-
class
i3pyblocks.blocks.dbus.KbddBlock(format: str = '{full_layout}', **kwargs)¶ Bases:
i3pyblocks.blocks.dbus.DbusBlockBlock that shows X11 keyboard layout based on kbdd daemon.
Provisional block subject to changes/removal.
Needs
kbdddaemon installed and running. In i3wm, add this to your$HOME/.config/i3/configfile:# 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¶ Callback called when a click event happens to this Block.
Each of this method arguments is from click events in i3bar protocol since they’re mapped directly (so a
{"x": 1}results in ax=1).- Parameters
x – X11 root window coordinates where the click occurred.
y – X11 root window coordinates where the click occurred.
button – X11 button ID (for example 1 to 3 for left/middle/right mouse button).
relative_x – Coordinates where the click occurred, with respect to the top left corner of the block.
relative_y – Coordinates where the click occurred, with respect to the top left corner of the block.
width – Width (in px) of the block.
height – Height (in px) of the block.
modifier – A list of the modifiers active when the click occurred. The order in which modifiers are listed is not guaranteed.
See also
i3pyblocks.types.MouseButtonhas the mapping of the available mouse button IDs.i3pyblocks.types.KeyModifierhas the mapping of the available modifiers.
-
async
update_layout(self) → None¶
-
update_callback(self, layout_name: str) → None¶
-
async
start(self) → None¶ Starts a Block.
This is an abstract method, so it should be overriden.
This method is where you generally wants to put your main loop to update the state of the Block. This loop can either be triggered by events or can be an infinity loop. It can even be a single call to
update(), but in this case your Block will only be updated once.
-
class
i3pyblocks.blocks.dbus.MediaPlayerBlock(player: str = 'spotify', format: str = '{artist} - {track_number}. {title}', **kwargs)¶ Bases:
i3pyblocks.blocks.dbus.DbusBlockBlock 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.
-
bus_name= org.mpris.MediaPlayer2.{player}¶
-
object_path= /org/mpris/MediaPlayer2¶
-
interface_name= org.freedesktop.DBus.Properties¶
-
update_callback(self, interface_name: str, changed_properties: Dict[str, Variant], invalidated_properties: List[Variant]) → None¶
-
async
start(self) → None¶ Starts a Block.
This is an abstract method, so it should be overriden.
This method is where you generally wants to put your main loop to update the state of the Block. This loop can either be triggered by events or can be an infinity loop. It can even be a single call to
update(), but in this case your Block will only be updated once.