Files
pybricks-api/pybricks/_instances.py
T
Laurens Valk f12c579159 doc: move Motor to dedicated page.
Instead, show shorter, simpler Motor docs platform-devices pages. For the moment, this just means deleting the advanced methods section from those pages, but we may choose to simplify further.

This change makes it easier to navigate the ev3devices/pupdevices pages because the motor sections aren't overly long.

Details will still be available on the Motor pages for those who wish to use the more advanced motor capabilities such as adjusting the PID settings.
2019-11-11 13:22:08 +01:00

45 lines
1.1 KiB
Python

"""Sphinx workaround to document instance attributes such as self.light"""
from .builtins import (Motor, Speaker, Display, Battery, ColorLight,
KeyPad, LightArray)
from .parameters import Direction
from types import ModuleType
def make_instance(classdef):
"""Make a class instance to look like a module so Sphinx can parse it."""
name = ''
mod = ModuleType(name)
for m in classdef.__dict__.values():
if callable(m):
setattr(mod, m.__name__, m)
return mod
light = make_instance(ColorLight)
lights = make_instance(LightArray)
buttons = make_instance(KeyPad)
battery = make_instance(Battery)
speaker = make_instance(Speaker)
display = make_instance(Display)
class Motor(Motor):
def __init__(self, port, direction=Direction.CLOCKWISE):
"""Motor(port, direction=Direction.CLOCKWISE)
Create a motor instance.
Arguments:
port (Port): Port to which the motor is connected.
direction (Direction): Positive speed direction
(*Default*: `Direction.CLOCKWISE`).
"""
pass