i3pyblocks.blocks.shell¶
Blocks based on asyncio.subprocess
This is a collection of Blocks based on asyncio.subprocess, allowing you
to run an external program, parse its output and show it in i3pyblocks.
All Blocks in this module are based on PollingBlock, since it is more
difficult to have proper event based updates when coordinating subprocess.
There is some alternatives that to try in the future, for example using inotify
or dbus based approaches.
Module Contents¶
Classes¶
Block that shows the result of a command running in shell. |
|
Block that shows a toggle on or off accordingly to command’s output. |
-
class
i3pyblocks.blocks.shell.ShellBlock(command: models.CommandArgs, format: str = '{output}', command_on_click: Mapping[int, Optional[str]] = {types.MouseButton.LEFT_BUTTON: None, types.MouseButton.MIDDLE_BUTTON: None, types.MouseButton.RIGHT_BUTTON: None, types.MouseButton.SCROLL_UP: None, types.MouseButton.SCROLL_DOWN: None}, color_by_returncode: Mapping[int, Optional[str]] = {}, sleep: int = 1, **kwargs)¶ Bases:
i3pyblocks.blocks.PollingBlockBlock that shows the result of a command running in shell.
- Parameters
command_state – Command to be run. By default this will be parsed by shell, so it can also be multiple arbitrary commands separated by newlines, or multiple commands connected by pipes.
format – Format string to shown. Supports both
{output}(stdout) and{output_err}(stderr) placeholders.command_on_click – Mapping with commands to be called when the user interacts with mouse inside this block. After running this Block will be updated. Can be useful to change the keyboard layout for example.
sleep – Sleep in seconds between each call to
run().**kwargs – Extra arguments to be passed to
PollingBlockclass.
-
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
run(self) → None¶ Main loop in PollingBlock.
This is the method that will be run at each X
sleepseconds.Since this is an abstract method, it should be overriden before usage.
-
class
i3pyblocks.blocks.shell.ToggleBlock(command_state: models.CommandArgs, command_on: models.CommandArgs, command_off: models.CommandArgs, format_on: str = 'ON', format_off: str = 'OFF', sleep: int = 1, shell: bool = True, **kwargs)¶ Bases:
i3pyblocks.blocks.PollingBlockBlock that shows a toggle on or off accordingly to command’s output.
This block output is determined by
command_state. When the command outputs something in stdout, this is interpreted as ON, while when the command outputs nothing in stdout, this is interpreted as OFF.- Parameters
command_state – Command to be run to determine state. By default this will be parsed by shell, so it can also be multiple arbitrary commands separated by newlines, or multiple commands connected by pipes.
command_on – Command to be called when the current state is OFF, so it can be turned to ON.
command_off – Command to be called when the current state is ON, so it can be turned to OFF.
format_on – Format string to be shown when state is ON.
format_off – Format string to be shown when state is OFF.
sleep – Sleep in seconds between each call to
run().**kwargs – Extra arguments to be passed to
PollingBlockclass.
-
async
get_state(self) → bool¶
-
async
click_handler(self, **_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
run(self) → None¶ Main loop in PollingBlock.
This is the method that will be run at each X
sleepseconds.Since this is an abstract method, it should be overriden before usage.