pybricks/resources/image: add show_image() method

This commit is contained in:
David Lechner
2020-01-13 20:12:50 -06:00
parent c3e74273d2
commit 0398d04af9
5 changed files with 21 additions and 4 deletions
+2
View File
@@ -47,6 +47,8 @@
.. automethod:: pybricks.hubs::EV3Brick.screen.set_font
.. automethod:: pybricks.hubs::EV3Brick.screen.show_image
.. automethod:: pybricks.hubs::EV3Brick.screen.draw_image
.. automethod:: pybricks.hubs::EV3Brick.screen.draw_pixel
+7 -3
View File
@@ -10,9 +10,6 @@ Graphical Images
.. autoclass:: pybricks.resources.Image
:no-members:
.. automethod:: pybricks.resources.Image.clear
.. rubric:: Drawing Text
There are two ways to draw text on images. :meth:`draw_text` lets text be
@@ -55,6 +52,13 @@ Graphical Images
.. autoattribute:: pybricks.resources.Image.height
.. rubric:: Replacing the Entire Image
.. automethod:: pybricks.resources.Image.clear
.. automethod:: pybricks.resources.Image.show_image
Fonts
^^^^^
+2
View File
@@ -288,6 +288,8 @@ def find_obj(self, env, modname, classname, name, type, searchmode=0):
if classname == 'screen':
if name.startswith('Font.') or name == 'Font':
modname = 'pybricks.resources'
elif name.startswith('Image.') or name == 'Image':
modname = 'pybricks.resources'
else:
classname = 'EV3Brick.screen'
elif classname == 'speaker':
+9
View File
@@ -114,6 +114,15 @@ class Image:
no transparency.
"""
def show_image(self, source):
"""Clears this image, then draws ``source`` centered in this image.
Arguments:
source (Image or str):
The source :class:`Image`. If the argument is a string, then
the ``source`` image is loaded from file.
"""
def draw_text(self, x, y, text, color=Color.BLACK):
"""Draws text on the image.