i3pyblocks.blocks.pulse
Blocks related to PulseAudio, based on pulsectl.
This module contains PulseAudioBlock, that uses pulsectl to show/adjust
volume in systems that runs PulseAudio.
pulsectl uses its own event loop so this module is based on
SyncBlock running it in a separate thread, but this module should be
pretty efficient since it react to events from PulseAudio itself.
Needs PulseAudio installed in your computer, or you will receive the following error when trying to run this module:
OSError: libpulse.so.0: cannot open shared object file: No such file or directory
Module Contents
Classes
Block that shows volume and other info from default PulseAudio sink. |
- class i3pyblocks.blocks.pulse.PulseAudioBlock(format: str = 'V: {volume:.0f}%', format_mute: str = 'V: MUTE', colors: i3pyblocks._internal.models.Threshold = {0: types.Color.URGENT, 10: types.Color.WARN, 25: types.Color.NEUTRAL}, color_mute: Optional[str] = types.Color.URGENT, backgrounds: i3pyblocks._internal.models.Threshold = {}, background_mute: Optional[str] = None, icons: i3pyblocks._internal.models.Threshold = {0.0: '▁', 12.5: '▂', 25.0: '▃', 37.5: '▄', 50.0: '▅', 62.5: '▆', 75.0: '▇', 87.5: '█'}, command: i3pyblocks._internal.models.CommandArgs = ('pavucontrol',), **kwargs)
Bases:
i3pyblocks.blocks.SyncBlockBlock that shows volume and other info from default PulseAudio sink.
This Block shows the volume of the current default PulseAudio sink, and also includes a
click_handler()allowing you to mute the default sink using right button or increase/decrease the volume using scroll up/down. It will also open a program on the left click, by default it calls the pavucontrol but this is configurable.- Parameters
format – Format string showed when the audio sink is not mute. Supports both
{volume}and{icon}placeholders.format_mute – Format string showing when the audio sink is mute. It will be shown with
color_muteset.colors –
A mapping that represents the color that will be shown in each volume interval. For example:
{ 0: "000000", 10: "#FF0000", 50: "#FFFFFF", }
When the volume is between [0, 10) the color is set to “000000”, from [10, 50) is set to “FF0000” and from 50 and beyond it is “#FFFFFF”.
color_mute – Color used when the sound is mute.
backgrounds – Similar to
colors, but for the background.background_mute – Background used when the sound is mute.
icons – Similar to
colors, but for icons. Can be used to create a graphic representation of the volume. Only displayed whenformatincludes{icon}placeholder.command – Program to run when this block is right clicked.
**kwargs – Extra arguments to be passed to
SyncBlockclass.
- find_sink_index(self) None
- update_status(self) None
Update the PulseAudioBlock state.
- toggle_mute(self) None
Toggle mute on/off.
- change_volume(self, volume: float) None
Change volume of the current PulseAudio sink.
- Parameters
volume – Float to be increased/decreased relative to the current volume. To decrease the volume use a negative value.
- signal_handler_sync(self, **_kwargs)
Synchronous version of
signal_handler().
- click_handler_sync(self, button: int, **_kwargs) None
PulseAudioBlock click handlers
On left click it opens the command specified in
commandattribute. On right click it toggles mute. On scroll up it increases the volume. On scroll down it decreases the volume.
- start_sync(self) None
Starts a synchronous 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.