tps

Main module for thinkpad-scripts.

class tps.Direction(xrandr, xsetwacom, subpixel, physically_closed, rot_mat)

Holds the direction names of different tools.

xrandr and xsetwacom use different names for the rotations. To avoid proliferation of various names, this class holds the differing names. The module provides constants which have to be used within tps.

physically_closed

Alias for field number 3

rot_mat

Alias for field number 4

subpixel

Alias for field number 2

xrandr

Alias for field number 0

xsetwacom

Alias for field number 1

tps.INVERTED = Direction(xrandr='inverted', xsetwacom='half', subpixel='bgr', physically_closed=True, rot_mat=[-1, 0, 1, 0, -1, 1, 0, 0, 1])

Inverted

tps.LEFT = Direction(xrandr='left', xsetwacom='ccw', subpixel='vrgb', physically_closed=True, rot_mat=[0, -1, 1, 1, 0, 0, 0, 0, 1])

Left

tps.NORMAL = Direction(xrandr='normal', xsetwacom='none', subpixel='rgb', physically_closed=False, rot_mat=[1, 0, 0, 0, 1, 0, 0, 0, 1])

Normal

tps.RIGHT = Direction(xrandr='right', xsetwacom='cw', subpixel='vbgr', physically_closed=True, rot_mat=[0, 1, 0, -1, 0, 1, 0, 0, 1])

Right

tps.TABLET_NORMAL = Direction(xrandr='normal', xsetwacom='none', subpixel='rgb', physically_closed=True, rot_mat=[1, 0, 0, 0, 1, 0, 0, 0, 1])

Tablet normal

exception tps.UnknownDirectionException

Unknown direction given at the command line.

tps.assert_python3()

Asserts that this is running with Python 3

tps.has_program(command)

Checks whether given program is installed on this computer.

Parameters:command (str) – Name of command
Returns:Whether program is installed
Return type:bool
tps.print_command_decorate(function)

Decorates a func from the subprocess module to log the command parameter.

Note that the wrapper adds an additional local_logger parameter following the command parameter that is used for the logging. All other parameters are passed to the wrapped function.

Parameters:function – Function to wrap
Returns:Decorated function
tps.static_vars(**kwargs)

Attach static variables to a function.

Python does not have static variables. There is a workaround since all Python functions are objects really. Therefore one can attach attributes to it. This decorator conveniently does that.

Taken from a Stack Overflow answer by Claudiu and ony.

tps.translate_direction(direction)
Parameters:direction (str) – Direction string
Returns:Direction object
Return type:tps.Direction
Raises:tps.UnknownDirectionException