From b4cd9113b551d0bbcd4f59402c439f9d27cf730e Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 9 Jan 2020 11:17:04 -0600 Subject: [PATCH] doc/api/hubs_ev3brick: add Image class as EV3Brick.screen This duplicates the Image class documentation In pybricks.ev3devices as EV3Bricks.screen. --- doc/api/hubs_ev3brick.inc | 26 +++++++++++++++++++++++--- doc/common/conf.py | 30 +++++++++++++++++++++++++++++- pybricks/hubs.py | 4 +++- pybricks/resources.py | 8 ++++---- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/doc/api/hubs_ev3brick.inc b/doc/api/hubs_ev3brick.inc index cbe74b0..0efff07 100644 --- a/doc/api/hubs_ev3brick.inc +++ b/doc/api/hubs_ev3brick.inc @@ -34,11 +34,31 @@ .. automethod:: pybricks._instances.speaker.set_voice_settings -.. todo:: This functionality is not yet implemented -.. rubric:: Using the screen + .. rubric:: Using the screen + + .. automethod:: pybricks.hubs::EV3Brick.screen.clear + + .. automethod:: pybricks.hubs::EV3Brick.screen.draw_text + + .. automethod:: pybricks.hubs::EV3Brick.screen.print + + .. automethod:: pybricks.hubs::EV3Brick.screen.set_font + + .. automethod:: pybricks.hubs::EV3Brick.screen.draw_image + + .. automethod:: pybricks.hubs::EV3Brick.screen.draw_pixel + + .. automethod:: pybricks.hubs::EV3Brick.screen.draw_line + + .. automethod:: pybricks.hubs::EV3Brick.screen.draw_box + + .. automethod:: pybricks.hubs::EV3Brick.screen.draw_circle + + .. autoattribute:: pybricks.hubs::EV3Brick.screen.width + + .. autoattribute:: pybricks.hubs::EV3Brick.screen.height -.. todo:: This functionality is not yet implemented .. :: diff --git a/doc/common/conf.py b/doc/common/conf.py index 286cd54..d847131 100644 --- a/doc/common/conf.py +++ b/doc/common/conf.py @@ -19,10 +19,12 @@ # import os import sys -from sphinx.domains.python import PyClassmember +from sphinx.domains.python import PyClassmember, PythonDomain sys.path.insert(0, os.path.abspath('../..')) from pybricks import _version # noqa E402 +from pybricks.hubs import EV3Brick # noqa E402 +from pybricks.resources import Image # noqa E402 # ON_RTD is whether we are on readthedocs.org # this line of code grabbed from docs.readthedocs.org @@ -261,8 +263,34 @@ texinfo_documents = [ ] +# -- Python domain hacks --------------------------------------------------- + def get_signature_prefix_none(self, sig): return '' PyClassmember.get_signature_prefix = get_signature_prefix_none + + +# HACK: For certain hub attributes, we list the class members of the attributes +# class as if the attribute was a nested class so that readers don't have to +# skip around the docs as much. To make this work, we replace the attribute +# values with the type and override PythonDomain.find_obj so that references +# still work. + +base_find_obj = PythonDomain.find_obj + + +def find_obj(self, env, modname, classname, name, type, searchmode=0): + if modname == 'pybricks.hubs': + if classname == 'screen': + if name.startswith('Font.') or name == 'Font': + modname = 'pybricks.resources' + else: + classname = 'EV3Brick.screen' + return base_find_obj(self, env, modname, classname, name, type, searchmode) + + +PythonDomain.find_obj = find_obj + +EV3Brick.screen = Image diff --git a/pybricks/hubs.py b/pybricks/hubs.py index e180ecf..7c608fa 100644 --- a/pybricks/hubs.py +++ b/pybricks/hubs.py @@ -1,11 +1,13 @@ """LEGO® Programmable Hubs.""" from enum import Enum from .builtins import Speaker, Display, Battery, ColorLight, KeyPad +from .resources import Image -class EV3Brick(): +class EV3Brick: """LEGO® MINDSTORMS® EV3 Brick.""" Port = Enum('Port', ['A', 'B', 'C', 'D', 'S1', 'S2', 'S3', 'S4']) + screen = Image('_screen_') speaker = Speaker() display = Display() battery = Battery() diff --git a/pybricks/resources.py b/pybricks/resources.py index a38172b..c287308 100644 --- a/pybricks/resources.py +++ b/pybricks/resources.py @@ -71,7 +71,7 @@ class Image: """ pass - def draw_box(self, x1, y1, x2, y2, r=0, filled=False, color=Color.BLACK): + def draw_box(self, x1, y1, x2, y2, r=0, fill=False, color=Color.BLACK): """Draws a box on the image. Arguments: @@ -80,20 +80,20 @@ class Image: x2 (int): The x coordinate of the right side of the box. y2 (int): The y coordinate of the bottom of the box. r (int): The radius of the corners of the box. - filled (bool): If ``True``, the box will be filled with ``color``, + fill (bool): If ``True``, the box will be filled with ``color``, otherwise only the outline of the box will be drawn. color (Color): The color of the box. """ pass - def draw_circle(self, x, y, r=0, filled=False, color=Color.BLACK): + def draw_circle(self, x, y, r=0, fill=False, color=Color.BLACK): """Draws a circle on the image. Arguments: x (int): The x coordinate of the center of the circle. y (int): The y coordinate of the center of the circle. r (int): The radius of the circle. - filled (bool): If ``True``, the circle will be filled with + fill (bool): If ``True``, the circle will be filled with ``color``, otherwise only the circumference will be drawn. color (Color): The color of the circle. """