diff --git a/doc/common/conf.py b/doc/common/conf.py index 69688c4..1645573 100644 --- a/doc/common/conf.py +++ b/doc/common/conf.py @@ -193,8 +193,6 @@ htmlhelp_basename = "Pybricksdoc" exclude_patterns = [ - "hubs/ev3brick.rst", - "media.rst", "messaging.rst", "tools/datalog.rst", "*.rst.txt", diff --git a/doc/main/hubs/ev3brick.rst b/doc/main/hubs/ev3brick.rst index ace417f..2a6d494 100644 --- a/doc/main/hubs/ev3brick.rst +++ b/doc/main/hubs/ev3brick.rst @@ -1,4 +1,4 @@ -MINDSTORMS EV3 Brick +EV3 Brick ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. figure:: ../../main/cad/output/ev3device-ev3.png @@ -17,20 +17,18 @@ MINDSTORMS EV3 Brick .. automethod:: pybricks.hubs::EV3Brick.light.off + .. automethod:: pybricks.hubs::EV3Brick.light.blink + + .. automethod:: pybricks.hubs::EV3Brick.light.animate + .. rubric:: Using the speaker + .. automethod:: pybricks.hubs::EV3Brick.speaker.volume + .. automethod:: pybricks.hubs::EV3Brick.speaker.beep .. automethod:: pybricks.hubs::EV3Brick.speaker.play_notes - .. automethod:: pybricks.hubs::EV3Brick.speaker.play_file - - .. automethod:: pybricks.hubs::EV3Brick.speaker.say - - .. automethod:: pybricks.hubs::EV3Brick.speaker.set_speech_options - - .. automethod:: pybricks.hubs::EV3Brick.speaker.set_volume - .. rubric:: Using the screen .. |this image| replace:: the screen @@ -60,10 +58,10 @@ MINDSTORMS EV3 Brick .. automethod:: pybricks.hubs::EV3Brick.screen.draw_circle .. autoattribute:: pybricks.hubs::EV3Brick.screen.width + :annotation: = 178 .. autoattribute:: pybricks.hubs::EV3Brick.screen.height - - .. automethod:: pybricks.hubs::EV3Brick.screen.save + :annotation: = 128 .. rubric:: Using the battery @@ -83,122 +81,8 @@ Turn the light on and change the color Screen examples --------------------- -Show an image on the screen -*************************** - -.. literalinclude:: - ../../../examples/ev3/screen_image/main.py - Drawing shapes on the screen **************************** .. literalinclude:: ../../../examples/ev3/screen_draw/main.py - -Using different fonts -********************* - -.. raw:: latex - - \begin{CJK}{UTF8}{gbsn} - -.. literalinclude:: - ../../../examples/ev3/screen_print/main.py - -.. raw:: latex - - \end{CJK} - -.. rubric:: Available languages and voices for speech - -.. [#espeak_lang] - - You can choose the following languages: - - - ``'af'``: Afrikaans - - ``'an'``: Aragonese - - ``'bg'``: Bulgarian - - ``'bs'``: Bosnian - - ``'ca'``: Catalan - - ``'cs'``: Czech - - ``'cy'``: Welsh - - ``'da'``: Danish - - ``'de'``: German - - ``'el'``: Greek - - ``'en'``: English (default) - - ``'en-gb'``: English (United Kingdom) - - ``'en-sc'``: English (Scotland) - - ``'en-uk-north'``: English (United Kingdom, Northern) - - ``'en-uk-rp'``: English (United Kingdom, Received Pronunciation) - - ``'en-uk-wmids'``: English (United Kingdom, West Midlands) - - ``'en-us'``: English (United States) - - ``'en-wi'``: English (West Indies) - - ``'eo'``: Esperanto - - ``'es'``: Spanish - - ``'es-la'``: Spanish (Latin America) - - ``'et'``: Estonian - - ``'fa'``: Persian - - ``'fa-pin'``: Persian - - ``'fi'``: Finnish - - ``'fr-be'``: French (Belgium) - - ``'fr-fr'``: French (France) - - ``'ga'``: Irish - - ``'grc'``: Greek - - ``'hi'``: Hindi - - ``'hr'``: Croatian - - ``'hu'``: Hungarian - - ``'hy'``: Armenian - - ``'hy-west'``: Armenian (Western) - - ``'id'``: Indonesian - - ``'is'``: Icelandic - - ``'it'``: Italian - - ``'jbo'``: Lojban - - ``'ka'``: Georgian - - ``'kn'``: Kannada - - ``'ku'``: Kurdish - - ``'la'``: Latin - - ``'lfn'``: Lingua Franca Nova - - ``'lt'``: Lithuanian - - ``'lv'``: Latvian - - ``'mk'``: Macedonian - - ``'ml'``: Malayalam - - ``'ms'``: Malay - - ``'ne'``: Nepali - - ``'nl'``: Dutch - - ``'no'``: Norwegian - - ``'pa'``: Punjabi - - ``'pl'``: Polish - - ``'pt-br'``: Portuguese (Brazil) - - ``'pt-pt'``: Portuguese (Portugal) - - ``'ro'``: Romanian - - ``'ru'``: Russian - - ``'sk'``: Slovak - - ``'sq'``: Albanian - - ``'sr'``: Serbian - - ``'sv'``: Swedish - - ``'sw'``: Swahili - - ``'ta'``: Tamil - - ``'tr'``: Turkish - - ``'vi'``: Vietnamese - - ``'vi-hue'``: Vietnamese (Hue) - - ``'vi-sgn'``: Vietnamese (Saigon) - - ``'zh'``: Mandarin Chinese - - ``'zh-yue'``: Cantonese Chinese - - You can choose the following voices: - - - ``'f1'``: female variant 1 - - ``'f2'``: female variant 2 - - ``'f3'``: female variant 3 - - ``'f4'``: female variant 4 - - ``'f5'``: female variant 5 - - ``'m1'``: male variant 1 - - ``'m2'``: male variant 2 - - ``'m3'``: male variant 3 - - ``'m4'``: male variant 4 - - ``'m5'``: male variant 5 - - ``'m6'``: male variant 6 - - ``'m7'``: male variant 7 - - ``'croak'``: croak - - ``'whisper'``: whisper - - ``'whisperf'``: female whisper diff --git a/doc/main/hubs/index.rst b/doc/main/hubs/index.rst index 4ed30f8..424718c 100644 --- a/doc/main/hubs/index.rst +++ b/doc/main/hubs/index.rst @@ -14,6 +14,7 @@ technichub primehub essentialhub + ev3brick .. pybricks-classlink:: MoveHub @@ -50,3 +51,11 @@ .. figure:: ../../main/cad/output/hub-essential.png :width: 25% :target: essentialhub.html + +.. pybricks-classlink:: EV3Brick + +.. figure:: ../../main/cad/output/ev3device-ev3.png + :width: 25% + :target: ev3brick.html + + diff --git a/doc/main/media.rst b/doc/main/media.rst deleted file mode 100644 index 5472354..0000000 --- a/doc/main/media.rst +++ /dev/null @@ -1,1679 +0,0 @@ -:mod:`media ` -- Sounds and images -================================================== - -.. module:: pybricks.media - -This module describes media such as sound and images that you can use in your -projects. Media are divided into submodules that indicate on which platform -they are available. - -:mod:`media.ev3dev ` -- Sounds and Images ---------------------------------------------------------------------- - -.. module:: pybricks.media.ev3dev - -EV3 MicroPython is built on top of ev3dev, which comes with a variety of image -and sound files. You can access them using the classes below. - -You can also use your own sound and image files by placing them in your project -folder. - -Image files -^^^^^^^^^^^ - -.. autoclass:: pybricks.media.ev3dev.ImageFile - :no-members: - - .. rubric:: **Information** - - .. data:: ACCEPT - - .. image:: ../../media/ev3dev-media/images/mono/information/accept.png - :width: 15 % - - .. data:: BACKWARD - - .. image:: ../../media/ev3dev-media/images/mono/information/backward.png - :width: 15 % - - .. data:: DECLINE - - .. image:: ../../media/ev3dev-media/images/mono/information/decline.png - :width: 15 % - - .. data:: FORWARD - - .. image:: ../../media/ev3dev-media/images/mono/information/forward.png - :width: 15 % - - .. data:: LEFT - - .. image:: ../../media/ev3dev-media/images/mono/information/left.png - :width: 15 % - - .. data:: NO_GO - - .. image:: ../../media/ev3dev-media/images/mono/information/no_go.png - :width: 15 % - - .. data:: QUESTION_MARK - - .. image:: ../../media/ev3dev-media/images/mono/information/question_mark.png - :width: 15 % - - .. data:: RIGHT - - .. image:: ../../media/ev3dev-media/images/mono/information/right.png - :width: 15 % - - .. data:: STOP_1 - - .. image:: ../../media/ev3dev-media/images/mono/information/stop_1.png - :width: 15 % - - .. data:: STOP_2 - - .. image:: ../../media/ev3dev-media/images/mono/information/stop_2.png - :width: 15 % - - .. data:: THUMBS_DOWN - - .. image:: ../../media/ev3dev-media/images/mono/information/thumbs_down.png - :width: 15 % - - .. data:: THUMBS_UP - - .. image:: ../../media/ev3dev-media/images/mono/information/thumbs_up.png - :width: 15 % - - .. data:: WARNING - - .. image:: ../../media/ev3dev-media/images/mono/information/warning.png - :width: 15 % - - .. rubric:: **LEGO** - - .. data:: EV3 - - .. image:: ../../media/ev3dev-media/images/mono/lego/ev3.png - :width: 15 % - - .. data:: EV3_ICON - - .. image:: ../../media/ev3dev-media/images/mono/lego/ev3_icon.png - :width: 15 % - - .. rubric:: **Objects** - - .. data:: TARGET - - .. image:: ../../media/ev3dev-media/images/mono/objects/target.png - :width: 15 % - - .. rubric:: **Eyes** - - .. data:: ANGRY - - .. image:: ../../media/ev3dev-media/images/mono/eyes/angry.png - :width: 15 % - - .. data:: AWAKE - - .. image:: ../../media/ev3dev-media/images/mono/eyes/awake.png - :width: 15 % - - .. data:: BOTTOM_LEFT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/bottom_left.png - :width: 15 % - - - .. data:: BOTTOM_RIGHT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/bottom_right.png - :width: 15 % - - .. data:: CRAZY_1 - - .. image:: ../../media/ev3dev-media/images/mono/eyes/crazy_1.png - :width: 15 % - - .. data:: CRAZY_2 - - .. image:: ../../media/ev3dev-media/images/mono/eyes/crazy_2.png - :width: 15 % - - .. data:: DIZZY - - .. image:: ../../media/ev3dev-media/images/mono/eyes/dizzy.png - :width: 15 % - - .. data:: DOWN - - .. image:: ../../media/ev3dev-media/images/mono/eyes/down.png - :width: 15 % - - .. data:: EVIL - - .. image:: ../../media/ev3dev-media/images/mono/eyes/evil.png - :width: 15 % - - .. data:: KNOCKED_OUT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/knocked_out.png - :width: 15 % - - .. data:: MIDDLE_LEFT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/middle_left.png - :width: 15 % - - .. data:: MIDDLE_RIGHT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/middle_right.png - :width: 15 % - - .. data:: NEUTRAL - - .. image:: ../../media/ev3dev-media/images/mono/eyes/neutral.png - :width: 15 % - - .. data:: PINCHED_LEFT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/pinched_left.png - :width: 15 % - - .. data:: PINCHED_MIDDLE - - .. image:: ../../media/ev3dev-media/images/mono/eyes/pinched_middle.png - :width: 15 % - - .. data:: PINCHED_RIGHT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/pinched_right.png - :width: 15 % - - .. data:: SLEEPING - - .. image:: ../../media/ev3dev-media/images/mono/eyes/sleeping.png - :width: 15 % - - .. data:: TIRED_LEFT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/tired_left.png - :width: 15 % - - .. data:: TIRED_MIDDLE - - .. image:: ../../media/ev3dev-media/images/mono/eyes/tired_middle.png - :width: 15 % - - .. data:: TIRED_RIGHT - - .. image:: ../../media/ev3dev-media/images/mono/eyes/tired_right.png - :width: 15 % - - .. data:: UP - - .. image:: ../../media/ev3dev-media/images/mono/eyes/up.png - :width: 15 % - - .. data:: WINKING - - .. image:: ../../media/ev3dev-media/images/mono/eyes/winking.png - :width: 15 % - -Sound files -^^^^^^^^^^^ - -.. autoclass:: pybricks.media.ev3dev.SoundFile - :no-members: - - .. rubric:: **Expressions** - - .. data:: BOING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/boing.wav>` - - .. data:: BOO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/boo.wav>` - - .. data:: CHEERING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/cheering.wav>` - - .. data:: CRUNCHING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/crunching.wav>` - - .. data:: CRYING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/crying.wav>` - - .. data:: FANFARE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/fanfare.wav>` - - .. data:: KUNG_FU - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/kung_fu.wav>` - - .. data:: LAUGHING_1 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/laughing_1.wav>` - - .. data:: LAUGHING_2 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/laughing_2.wav>` - - .. data:: MAGIC_WAND - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/magic_wand.wav>` - - .. data:: OUCH - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/ouch.wav>` - - .. data:: SHOUTING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/shouting.wav>` - - .. data:: SMACK - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/smack.wav>` - - .. data:: SNEEZING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/sneezing.wav>` - - .. data:: SNORING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/snoring.wav>` - - .. data:: UH_OH - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/expressions/uh-oh.wav>` - - - .. rubric:: **Information** - - .. data:: ACTIVATE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/activate.wav>` - - .. data:: ANALYZE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/analyze.wav>` - - .. data:: BACKWARDS - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/backwards.wav>` - - .. data:: COLOR - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/color.wav>` - - .. data:: DETECTED - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/detected.wav>` - - .. data:: DOWN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/down.wav>` - - .. data:: ERROR - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/error.wav>` - - .. data:: ERROR_ALARM - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/error_alarm.wav>` - - - .. data:: FLASHING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/flashing.wav>` - - .. data:: FORWARD - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/forward.wav>` - - .. data:: LEFT - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/left.wav>` - - .. data:: OBJECT - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/object.wav>` - - .. data:: RIGHT - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/right.wav>` - - .. data:: SEARCHING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/searching.wav>` - - .. data:: START - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/start.wav>` - - .. data:: STOP - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/stop.wav>` - - .. data:: TOUCH - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/touch.wav>` - - .. data:: TURN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/turn.wav>` - - .. data:: UP - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/information/up.wav>` - - .. rubric:: **Communication** - - .. data:: BRAVO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/bravo.wav>` - - .. data:: EV3 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/ev3.wav>` - - .. data:: FANTASTIC - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/fantastic.wav>` - - .. data:: GAME_OVER - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/game_over.wav>` - - .. data:: GO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/go.wav>` - - .. data:: GOOD_JOB - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/good_job.wav>` - - .. data:: GOOD - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/good.wav>` - - .. data:: GOODBYE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/goodbye.wav>` - - .. data:: HELLO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/hello.wav>` - - .. data:: HI - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/hi.wav>` - - .. data:: LEGO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/lego.wav>` - - .. data:: MINDSTORMS - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/mindstorms.wav>` - - .. data:: MORNING - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/morning.wav>` - - .. data:: NO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/no.wav>` - - .. data:: OKAY - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/okay.wav>` - - .. data:: OKEY_DOKEY - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/okey-dokey.wav>` - - .. data:: SORRY - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/sorry.wav>` - - .. data:: THANK_YOU - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/thank_you.wav>` - - .. data:: YES - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/communication/yes.wav>` - - - .. rubric:: **Movement sounds** - - .. data:: SPEED_DOWN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/movements/speed_down.wav>` - - .. data:: SPEED_IDLE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/movements/speed_idle.wav>` - - .. data:: SPEED_UP - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/movements/speed_up.wav>` - - .. rubric:: **Colors** - - .. data:: BLACK - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/black.wav>` - - .. data:: BLUE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/blue.wav>` - - .. data:: BROWN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/brown.wav>` - - .. data:: GREEN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/green.wav>` - - .. data:: RED - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/red.wav>` - - .. data:: WHITE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/white.wav>` - - .. data:: YELLOW - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/colors/yellow.wav>` - - - .. rubric:: **Mechanical** - - .. data:: AIR_RELEASE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/air_release.wav>` - - .. data:: AIRBRAKE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/airbrake.wav>` - - .. data:: BACKING_ALERT - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/backing_alert.wav>` - - .. data:: HORN_1 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/horn_1.wav>` - - .. data:: HORN_2 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/horn_2.wav>` - - .. data:: LASER - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/laser.wav>` - - .. data:: MOTOR_IDLE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/motor_idle.wav>` - - .. data:: MOTOR_START - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/motor_start.wav>` - - .. data:: MOTOR_STOP - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/motor_stop.wav>` - - .. data:: RATCHET - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/ratchet.wav>` - - .. data:: SONAR - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/sonar.wav>` - - .. data:: TICK_TACK - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/mechanical/tick_tack.wav>` - - - .. rubric:: **Animal sounds** - - .. data:: CAT_PURR - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/cat_purr.wav>` - - .. data:: DOG_BARK_1 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/dog_bark_1.wav>` - - .. data:: DOG_BARK_2 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/dog_bark_2.wav>` - - .. data:: DOG_GROWL - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/dog_growl.wav>` - - .. data:: DOG_SNIFF - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/dog_sniff.wav>` - - .. data:: DOG_WHINE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/dog_whine.wav>` - - .. data:: ELEPHANT_CALL - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/elephant_call.wav>` - - .. data:: INSECT_BUZZ_1 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/insect_buzz_1.wav>` - - .. data:: INSECT_BUZZ_2 - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/insect_buzz_2.wav>` - - .. data:: INSECT_CHIRP - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/insect_chirp.wav>` - - .. data:: SNAKE_HISS - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/snake_hiss.wav>` - - .. data:: SNAKE_RATTLE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/snake_rattle.wav>` - - .. data:: T_REX_ROAR - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/animals/t-rex_roar.wav>` - - - - .. rubric:: **Numbers** - - .. data:: ZERO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/zero.wav>` - - .. data:: ONE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/one.wav>` - - .. data:: TWO - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/two.wav>` - - .. data:: THREE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/three.wav>` - - .. data:: FOUR - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/four.wav>` - - .. data:: FIVE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/five.wav>` - - .. data:: SIX - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/six.wav>` - - .. data:: SEVEN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/seven.wav>` - - .. data:: EIGHT - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/eight.wav>` - - .. data:: NINE - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/nine.wav>` - - .. data:: TEN - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/numbers/ten.wav>` - - - .. rubric:: **System sounds** - - .. data:: CLICK - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/system/click.wav>` - - .. data:: CONFIRM - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/system/confirm.wav>` - - .. data:: GENERAL_ALERT - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/system/general_alert.wav>` - - .. data:: OVERPOWER - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/system/overpower.wav>` - - .. data:: READY - - .. raw:: html - - - - :download:`Download <../../media/ev3dev-media/sounds/system/ready.wav>` - -Fonts -^^^^^ - -.. autoclass:: pybricks.media.ev3dev.Font - :no-members: - - .. autoattribute:: pybricks.media.ev3dev.Font.DEFAULT - :annotation: = Font('Lucida', 12) - - .. autoattribute:: pybricks.media.ev3dev.Font.family - - .. autoattribute:: pybricks.media.ev3dev.Font.style - - .. autoattribute:: pybricks.media.ev3dev.Font.width - - .. autoattribute:: pybricks.media.ev3dev.Font.height - - .. automethod:: pybricks.media.ev3dev.Font.text_width - - .. automethod:: pybricks.media.ev3dev.Font.text_height - - **Exploring more fonts** - - Behind the scenes, Pybricks uses Fontconfig_ for fonts. The Fontconfig - command line tools can be used to explore available fonts in more - detail. To do so, go to the ev3dev device browser, - right click on your EV3 brick, and click *Open SSH Terminal*. Then you can - enter one of these commands:: - - # List available font families. - fc-list :scalable=false family - # Perform lookup similar to Font.DEFAULT - fc-match :scalable=false:dpi=119:family=Lucida:size=12 - # Perform lookup similar to Font(size=24,lang=zh-cn) - fc-match :scalable=false:dpi=119:size=24:lang=zh-cn - - Pybricks only allows the use of bitmap fonts (``scalable=false``) - and the screen on the EV3 has 119 pixels per inch (``dpi=119``). - -.. _FontConfig: https://www.freedesktop.org/wiki/Software/fontconfig/ - - -Image manipulation -^^^^^^^^^^^^^^^^^^ - -Instead of drawing directly on the EV3 screen, you can make and interact -with image files using the ``Image`` class given below. - -.. |this image| replace:: this image - -.. autoclass:: pybricks.media.ev3dev.Image - :no-members: - - .. automethod:: pybricks.media.ev3dev.Image.empty - - .. rubric:: Drawing text - - There are two ways to draw text on images. :meth:`draw_text` lets text be - placed precisely on the image or :meth:`print` can be used to automatically - print text on a new line. - - .. automethod:: pybricks.media.ev3dev.Image.draw_text - - .. automethod:: pybricks.media.ev3dev.Image.print - - .. automethod:: pybricks.media.ev3dev.Image.set_font - - - .. rubric:: Drawing images - - A copy of another image can be drawn on an image. Also consider using - sub-images to copy part of an image. - - .. automethod:: pybricks.media.ev3dev.Image.draw_image - - - .. rubric:: Drawing shapes - - These are the methods to draw basic shapes, including points, lines, - rectangles and circles. - - .. automethod:: pybricks.media.ev3dev.Image.draw_pixel - - .. automethod:: pybricks.media.ev3dev.Image.draw_line - - .. automethod:: pybricks.media.ev3dev.Image.draw_box - - .. automethod:: pybricks.media.ev3dev.Image.draw_circle - - - .. rubric:: Image properties - - .. autoattribute:: pybricks.media.ev3dev.Image.width - - .. autoattribute:: pybricks.media.ev3dev.Image.height - - - .. rubric:: Replacing the entire image - - .. automethod:: pybricks.media.ev3dev.Image.clear - - .. automethod:: pybricks.media.ev3dev.Image.load_image - - - .. rubric:: Saving the image - - .. automethod:: pybricks.media.ev3dev.Image.save - -.. rubric:: Available languages for fonts - -.. [#font_lang] - - Note: Languages depend on installed fonts. Additional language - codes are possible and some listed language codes may not have - a satisfactory font. - - - ``'aa'``: Afar - - ``'af'``: Afrikaans - - ``'an'``: Aragonese - - ``'av'``: Avaric - - ``'ay'``: Aymara - - ``'az-az'``: Azerbaijani - - ``'be'``: Belarusian - - ``'bg'``: Bulgarian - - ``'bi'``: Bislama - - ``'bm'``: Bambara - - ``'br'``: Breton - - ``'bs'``: Bosnian - - ``'bua'``: Buriat - - ``'ca'``: Catalan - - ``'ce'``: Chechen - - ``'ch'``: Chamorro - - ``'co'``: Corsican - - ``'crh'``: Crimean - - ``'cs'``: Czech - - ``'csb'``: Kashubian - - ``'cy'``: Welsh - - ``'da'``: Danish - - ``'de'``: German - - ``'ee'``: Ewe - - ``'el'``: Greek - - ``'en'``: English - - ``'eo'``: Esperanto - - ``'es'``: Spanish - - ``'et'``: Estonian - - ``'eu'``: Basque - - ``'ff'``: Fulah - - ``'fi'``: Finnish - - ``'fil'``: Filipino - - ``'fj'``: Fijian - - ``'fo'``: Faroese - - ``'fr'``: French - - ``'fur'``: Friulian - - ``'fy'``: Western Frisian - - ``'ga'``: Irish - - ``'gd'``: Gaelic - - ``'gl'``: Galician - - ``'gv'``: Manx - - ``'ha'``: Hausa - - ``'haw'``: Hawaiian - - ``'he'``: Hebrew - - ``'ho'``: Hiri Motu - - ``'hr'``: Croatian - - ``'hsb'``: Upper Sorbian - - ``'ht'``: Haitian - - ``'hu'``: Hungarian - - ``'ia'``: Interlingua - - ``'id'``: Indonesian - - ``'ie'``: Interlingue - - ``'ik'``: Inupiaq - - ``'io'``: Ido - - ``'is'``: Icelandic - - ``'it'``: Italian - - ``'ja'``: Japanese - - ``'jv'``: Javanese - - ``'ki'``: Kikuyu - - ``'kj'``: Kuanyama - - ``'kl'``: Kalaallisut - - ``'ko'``: Korean - - ``'ku-tr'``: Kurdish - - ``'kum'``: Kumyk - - ``'kw'``: Cornish - - ``'kwm'``: Kwambi - - ``'la'``: Latin - - ``'lb'``: Luxembourgish - - ``'lez'``: Lezghian - - ``'lg'``: Ganda - - ``'li'``: Limburgan - - ``'ln'``: Lingala - - ``'lt'``: Lithuanian - - ``'lv'``: Latvian - - ``'mg'``: Malagasy - - ``'mh'``: Marshallese - - ``'mi'``: Maori - - ``'mk'``: Macedonian - - ``'mn-mn'``: Mongolian - - ``'mo'``: Moldavian - - ``'ms'``: Malay - - ``'mt'``: Maltese - - ``'na'``: Nauru - - ``'nb'``: Norwegian Bokmål - - ``'nds'``: Low German - - ``'ng'``: Ndonga - - ``'nl'``: Dutch - - ``'nn'``: Norwegian Nynorsk - - ``'no'``: Norwegian - - ``'nr'``: South Ndebele - - ``'nso'``: Northern Sotho - - ``'nv'``: Navajo - - ``'ny'``: Chichewa - - ``'oc'``: Occitan - - ``'om'``: Oromo - - ``'os'``: Ossetian - - ``'pap-an'``: Papiamento, Netherlands Antilles - - ``'pap-aw'``: Papiamento, Aruba - - ``'pl'``: Polish - - ``'pt'``: Portuguese - - ``'qu'``: Quechua - - ``'quz'``: Cusco Quechua - - ``'rm'``: Romansh - - ``'rn'``: Rundi - - ``'ro'``: Romanian - - ``'ru'``: Russian - - ``'rw'``: Kinyarwanda - - ``'sc'``: Sardinian - - ``'sco'``: Scots - - ``'se'``: Northern Sami - - ``'sel'``: Selkup - - ``'sg'``: Sango - - ``'sk'``: Slovak - - ``'sl'``: Slovenian - - ``'sm'``: Samoan - - ``'sma'``: Southern Sami - - ``'smj'``: Lule Sami - - ``'smn'``: Inari Sami - - ``'sms'``: Skolt Sami - - ``'sn'``: Shona - - ``'so'``: Somali - - ``'sq'``: Albanian - - ``'sr'``: Serbian - - ``'ss'``: Swati - - ``'st'``: Southern Sotho - - ``'su'``: Sundanese - - ``'sv'``: Swedish - - ``'sw'``: Swahili - - ``'tk'``: Turkmen - - ``'tl'``: Tagalog - - ``'tn'``: Tswana - - ``'to'``: Tonga - - ``'tr'``: Turkish - - ``'ts'``: Tsonga - - ``'ty'``: Tahitian - - ``'uk'``: Ukrainian - - ``'uz'``: Uzbek - - ``'vo'``: Volapük - - ``'vot'``: Votic - - ``'wa'``: Walloon - - ``'wen'``: Sorbian - - ``'wo'``: Wolof - - ``'xh'``: Xhosa - - ``'yap'``: Yapese - - ``'yi'``: Yiddish - - ``'za'``: Zhuang - - ``'zh-cn'``: Chinese, China - - ``'zh-sg'``: Chinese, Singapore - - ``'zh-tw'``: Chinese, Taiwan - - ``'zu'``: Zulu diff --git a/doc/main/parameters/font.rst b/doc/main/parameters/font.rst new file mode 100644 index 0000000..2c4a210 --- /dev/null +++ b/doc/main/parameters/font.rst @@ -0,0 +1,31 @@ +.. pybricks-requirements:: ev3 + +Font +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: pybricks.parameters.Font + :no-members: + + .. autoattribute:: pybricks.parameters.Font.DEFAULT + :annotation: + + .. autoattribute:: pybricks.parameters.Font.TERMINUS_16 + :annotation: + + .. autoattribute:: pybricks.parameters.Font.LIBERATIONSANS_14 + :annotation: + + .. autoattribute:: pybricks.parameters.Font.MONO_8X5_8 + :annotation: + + .. autoattribute:: pybricks.parameters.Font.family + + .. autoattribute:: pybricks.parameters.Font.style + + .. autoattribute:: pybricks.parameters.Font.width + + .. autoattribute:: pybricks.parameters.Font.height + + .. automethod:: pybricks.parameters.Font.text_width + + .. automethod:: pybricks.parameters.Font.text_height diff --git a/doc/main/parameters/image.rst b/doc/main/parameters/image.rst new file mode 100644 index 0000000..1028359 --- /dev/null +++ b/doc/main/parameters/image.rst @@ -0,0 +1,59 @@ +.. pybricks-requirements:: ev3 + +Image +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. |this image| replace:: this image + +.. autoclass:: pybricks.parameters.Image + :no-members: + + .. automethod:: pybricks.parameters.Image.empty + + .. rubric:: Drawing text + + There are two ways to draw text on images. :meth:`draw_text` lets text be + placed precisely on the image or :meth:`print` can be used to automatically + print text on a new line. + + .. automethod:: pybricks.parameters.Image.draw_text + + .. automethod:: pybricks.parameters.Image.print + + .. automethod:: pybricks.parameters.Image.set_font + + + .. rubric:: Drawing images + + A copy of another image can be drawn on an image. Also consider using + sub-images to copy part of an image. + + .. automethod:: pybricks.parameters.Image.draw_image + + + .. rubric:: Drawing shapes + + These are the methods to draw basic shapes, including points, lines, + rectangles and circles. + + .. automethod:: pybricks.parameters.Image.draw_pixel + + .. automethod:: pybricks.parameters.Image.draw_line + + .. automethod:: pybricks.parameters.Image.draw_box + + .. automethod:: pybricks.parameters.Image.draw_circle + + + .. rubric:: Image properties + + .. autoattribute:: pybricks.parameters.Image.width + + .. autoattribute:: pybricks.parameters.Image.height + + + .. rubric:: Replacing the entire image + + .. automethod:: pybricks.parameters.Image.clear + + .. automethod:: pybricks.parameters.Image.load_image diff --git a/doc/main/parameters/imagefile.rst b/doc/main/parameters/imagefile.rst new file mode 100644 index 0000000..7218f8a --- /dev/null +++ b/doc/main/parameters/imagefile.rst @@ -0,0 +1,209 @@ +.. pybricks-requirements:: ev3 + +ImageFile +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Note: Not all images are included in the firmware yet. This is a work in progress. + +.. currentmodule:: pybricks.parameters + +.. class:: ImageFile + + .. rubric:: **Information** + + .. data:: ACCEPT + + .. image:: ../../../media/ev3dev-media/images/mono/information/accept.png + :width: 15 % + + .. data:: BACKWARD + + .. image:: ../../../media/ev3dev-media/images/mono/information/backward.png + :width: 15 % + + .. data:: DECLINE + + .. image:: ../../../media/ev3dev-media/images/mono/information/decline.png + :width: 15 % + + .. data:: FORWARD + + .. image:: ../../../media/ev3dev-media/images/mono/information/forward.png + :width: 15 % + + .. data:: LEFT + + .. image:: ../../../media/ev3dev-media/images/mono/information/left.png + :width: 15 % + + .. data:: NO_GO + + .. image:: ../../../media/ev3dev-media/images/mono/information/no_go.png + :width: 15 % + + .. data:: QUESTION_MARK + + .. image:: ../../../media/ev3dev-media/images/mono/information/question_mark.png + :width: 15 % + + .. data:: RIGHT + + .. image:: ../../../media/ev3dev-media/images/mono/information/right.png + :width: 15 % + + .. data:: STOP_1 + + .. image:: ../../../media/ev3dev-media/images/mono/information/stop_1.png + :width: 15 % + + .. data:: STOP_2 + + .. image:: ../../../media/ev3dev-media/images/mono/information/stop_2.png + :width: 15 % + + .. data:: THUMBS_DOWN + + .. image:: ../../../media/ev3dev-media/images/mono/information/thumbs_down.png + :width: 15 % + + .. data:: THUMBS_UP + + .. image:: ../../../media/ev3dev-media/images/mono/information/thumbs_up.png + :width: 15 % + + .. data:: WARNING + + .. image:: ../../../media/ev3dev-media/images/mono/information/warning.png + :width: 15 % + + .. rubric:: **LEGO** + + .. data:: EV3 + + .. image:: ../../../media/ev3dev-media/images/mono/lego/ev3.png + :width: 15 % + + .. data:: EV3_ICON + + .. image:: ../../../media/ev3dev-media/images/mono/lego/ev3_icon.png + :width: 15 % + + .. rubric:: **Objects** + + .. data:: TARGET + + .. image:: ../../../media/ev3dev-media/images/mono/objects/target.png + :width: 15 % + + .. rubric:: **Eyes** + + .. data:: ANGRY + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/angry.png + :width: 15 % + + .. data:: AWAKE + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/awake.png + :width: 15 % + + .. data:: BOTTOM_LEFT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/bottom_left.png + :width: 15 % + + + .. data:: BOTTOM_RIGHT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/bottom_right.png + :width: 15 % + + .. data:: CRAZY_1 + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/crazy_1.png + :width: 15 % + + .. data:: CRAZY_2 + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/crazy_2.png + :width: 15 % + + .. data:: DIZZY + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/dizzy.png + :width: 15 % + + .. data:: DOWN + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/down.png + :width: 15 % + + .. data:: EVIL + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/evil.png + :width: 15 % + + .. data:: KNOCKED_OUT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/knocked_out.png + :width: 15 % + + .. data:: MIDDLE_LEFT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/middle_left.png + :width: 15 % + + .. data:: MIDDLE_RIGHT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/middle_right.png + :width: 15 % + + .. data:: NEUTRAL + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/neutral.png + :width: 15 % + + .. data:: PINCHED_LEFT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/pinched_left.png + :width: 15 % + + .. data:: PINCHED_MIDDLE + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/pinched_middle.png + :width: 15 % + + .. data:: PINCHED_RIGHT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/pinched_right.png + :width: 15 % + + .. data:: SLEEPING + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/sleeping.png + :width: 15 % + + .. data:: TIRED_LEFT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/tired_left.png + :width: 15 % + + .. data:: TIRED_MIDDLE + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/tired_middle.png + :width: 15 % + + .. data:: TIRED_RIGHT + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/tired_right.png + :width: 15 % + + .. data:: UP + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/up.png + :width: 15 % + + .. data:: WINKING + + .. image:: ../../../media/ev3dev-media/images/mono/eyes/winking.png + :width: 15 % diff --git a/doc/main/parameters/index.rst b/doc/main/parameters/index.rst index 16532fd..7f4987d 100644 --- a/doc/main/parameters/index.rst +++ b/doc/main/parameters/index.rst @@ -14,7 +14,10 @@ button color direction + font icon + image + imagefile port side stop @@ -27,8 +30,14 @@ .. pybricks-classlink:: Direction +.. pybricks-classlink:: Font + .. pybricks-classlink:: Icon +.. pybricks-classlink:: Image + +.. pybricks-classlink:: ImageFile + .. pybricks-classlink:: Port .. pybricks-classlink:: Side diff --git a/examples/ev3/bluetooth_client/client.py b/examples/ev3/bluetooth_client/client.py index bf851b6..6b06713 100644 --- a/examples/ev3/bluetooth_client/client.py +++ b/examples/ev3/bluetooth_client/client.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - # Before running this program, make sure the client and server EV3 bricks are # paired using Bluetooth, but do NOT connect them. The program will take care # of establishing the connection. diff --git a/examples/ev3/bluetooth_read_spike/main.py b/examples/ev3/bluetooth_read_spike/main.py index 81375f8..7c50749 100644 --- a/examples/ev3/bluetooth_read_spike/main.py +++ b/examples/ev3/bluetooth_read_spike/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.tools import wait diff --git a/examples/ev3/bluetooth_read_spike/rover.py b/examples/ev3/bluetooth_read_spike/rover.py index 6c477a8..24e5726 100644 --- a/examples/ev3/bluetooth_read_spike/rover.py +++ b/examples/ev3/bluetooth_read_spike/rover.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.tools import wait from pybricks.ev3devices import Motor diff --git a/examples/ev3/bluetooth_server/server.py b/examples/ev3/bluetooth_server/server.py index ed73bd1..cc792e1 100644 --- a/examples/ev3/bluetooth_server/server.py +++ b/examples/ev3/bluetooth_server/server.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - # Before running this program, make sure the client and server EV3 bricks are # paired using Bluetooth, but do NOT connect them. The program will take care # of establishing the connection. diff --git a/examples/ev3/buttons/main.py b/examples/ev3/buttons/main.py index 5174985..9084471 100644 --- a/examples/ev3/buttons/main.py +++ b/examples/ev3/buttons/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.tools import wait from pybricks.parameters import Button diff --git a/examples/ev3/buttons_quickstart/main.py b/examples/ev3/buttons_quickstart/main.py index 23116fe..5034453 100644 --- a/examples/ev3/buttons_quickstart/main.py +++ b/examples/ev3/buttons_quickstart/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.parameters import Button diff --git a/examples/ev3/datalog/main.py b/examples/ev3/datalog/main.py index 7658124..df6c380 100644 --- a/examples/ev3/datalog/main.py +++ b/examples/ev3/datalog/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.ev3devices import Motor from pybricks.parameters import Port from pybricks.tools import DataLog, StopWatch, wait diff --git a/examples/ev3/datalog_extra/main.py b/examples/ev3/datalog_extra/main.py index 649a411..035f519 100644 --- a/examples/ev3/datalog_extra/main.py +++ b/examples/ev3/datalog_extra/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.parameters import Color from pybricks.tools import DataLog diff --git a/examples/ev3/ev3devsensor/.gitignore b/examples/ev3/ev3devsensor/.gitignore deleted file mode 100644 index 9b5f630..0000000 --- a/examples/ev3/ev3devsensor/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -__pycache__/ -*.pyc -venv/ diff --git a/examples/ev3/ev3devsensor/.vscode/extensions.json b/examples/ev3/ev3devsensor/.vscode/extensions.json deleted file mode 100644 index f8f1a44..0000000 --- a/examples/ev3/ev3devsensor/.vscode/extensions.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "lego-education.ev3-micropython" - ], - // List of extensions recommended by VS Code that should not be recommended for users of this workspace. - "unwantedRecommendations": [ - "ms-python.python" - ] -} \ No newline at end of file diff --git a/examples/ev3/ev3devsensor/.vscode/launch.json b/examples/ev3/ev3devsensor/.vscode/launch.json deleted file mode 100644 index 7dc1149..0000000 --- a/examples/ev3/ev3devsensor/.vscode/launch.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Main Example", - "type": "ev3devBrowser", - "request": "launch", - "program": "/home/robot/${workspaceRootFolderName}/main.py" - }, - { - "name": "Class Example", - "type": "ev3devBrowser", - "request": "launch", - "program": "/home/robot/${workspaceRootFolderName}/class_example.py" - } - ] -} diff --git a/examples/ev3/ev3devsensor/.vscode/settings.json b/examples/ev3/ev3devsensor/.vscode/settings.json deleted file mode 100644 index 37c9a5d..0000000 --- a/examples/ev3/ev3devsensor/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ - "files.eol": "\n", - "debug.openDebug": "neverOpen", - "python.linting.enabled": false -} diff --git a/examples/ev3/ev3devsensor/class_example.py b/examples/ev3/ev3devsensor/class_example.py deleted file mode 100644 index 11525e7..0000000 --- a/examples/ev3/ev3devsensor/class_example.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env pybricks-micropython -from pybricks.parameters import Port -from pybricks.iodevices import Ev3devSensor - - -class MySensor(Ev3devSensor): - """Example of extending the Ev3devSensor class.""" - - def __init__(self, port): - """Initialize the sensor.""" - - # Initialize the parent class. - super().__init__(port) - - # Get the sysfs path. - self.path = "/sys/class/lego-sensor/sensor" + str(self.sensor_index) - - def get_modes(self): - """Get a list of mode strings so we don't have to look them up.""" - - # The path of the modes file. - modes_path = self.path + "/modes" - - # Open the modes file. - with open(modes_path, "r") as m: - # Read the contents. - contents = m.read() - - # Strip the newline symbol, and split at every space symbol. - return contents.strip().split(" ") - - -# Initialize the sensor -sensor = MySensor(Port.S3) - -# Show where this sensor can be found -print(sensor.path) - -# Print the available modes -modes = sensor.get_modes() -print(modes) - -# Read mode 0 of this sensor -val = sensor.read(modes[0]) -print(val) diff --git a/examples/ev3/ev3devsensor/main.py b/examples/ev3/ev3devsensor/main.py deleted file mode 100644 index 4d3d52e..0000000 --- a/examples/ev3/ev3devsensor/main.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env pybricks-micropython -from pybricks.parameters import Port -from pybricks.tools import wait -from pybricks.iodevices import Ev3devSensor - -# Initialize an Ev3devSensor. -# In this example we use the -# LEGO MINDSTORMS EV3 Color Sensor. -sensor = Ev3devSensor(Port.S3) - -while True: - # Read the raw RGB values - r, g, b = sensor.read("RGB-RAW") - - # Print results - print("R: {0}\t G: {1}\t B: {2}".format(r, g, b)) - - # Wait - wait(200) diff --git a/examples/ev3/getting_started/main.py b/examples/ev3/getting_started/main.py index 05e48c3..49cc36f 100644 --- a/examples/ev3/getting_started/main.py +++ b/examples/ev3/getting_started/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import Motor from pybricks.parameters import Port diff --git a/examples/ev3/i2c_basics/main.py b/examples/ev3/i2c_basics/main.py index bf728da..492c9ee 100644 --- a/examples/ev3/i2c_basics/main.py +++ b/examples/ev3/i2c_basics/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.iodevices import I2CDevice from pybricks.parameters import Port diff --git a/examples/ev3/i2c_extra/main.py b/examples/ev3/i2c_extra/main.py index 50e8a43..bd89147 100644 --- a/examples/ev3/i2c_extra/main.py +++ b/examples/ev3/i2c_extra/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.iodevices import I2CDevice from pybricks.parameters import Port diff --git a/examples/ev3/light_color/main.py b/examples/ev3/light_color/main.py index 69f3351..2df2c82 100644 --- a/examples/ev3/light_color/main.py +++ b/examples/ev3/light_color/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.tools import wait from pybricks.parameters import Color diff --git a/examples/ev3/ps4/main.py b/examples/ev3/ps4/main.py index 0f5dd44..ffcfb07 100644 --- a/examples/ev3/ps4/main.py +++ b/examples/ev3/ps4/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.ev3devices import Motor from pybricks.parameters import Port diff --git a/examples/ev3/rcx_touch/main.py b/examples/ev3/rcx_touch/main.py index 0c0ed2f..da77030 100644 --- a/examples/ev3/rcx_touch/main.py +++ b/examples/ev3/rcx_touch/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.iodevices import AnalogSensor from pybricks.parameters import Port, Color diff --git a/examples/ev3/screen_draw/main.py b/examples/ev3/screen_draw/main.py index ab98c0a..47b2572 100644 --- a/examples/ev3/screen_draw/main.py +++ b/examples/ev3/screen_draw/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.tools import wait diff --git a/examples/ev3/screen_extra/main.py b/examples/ev3/screen_extra/main.py index 0652b4b..eb99e96 100644 --- a/examples/ev3/screen_extra/main.py +++ b/examples/ev3/screen_extra/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - import math from pybricks.hubs import EV3Brick diff --git a/examples/ev3/screen_image/main.py b/examples/ev3/screen_image/main.py index 2d6870c..aee84e4 100644 --- a/examples/ev3/screen_image/main.py +++ b/examples/ev3/screen_image/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.tools import wait from pybricks.media.ev3dev import Image, ImageFile diff --git a/examples/ev3/screen_print/main.py b/examples/ev3/screen_print/main.py index a345ea1..9aa6a0c 100644 --- a/examples/ev3/screen_print/main.py +++ b/examples/ev3/screen_print/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.tools import wait from pybricks.media.ev3dev import Font diff --git a/examples/ev3/speaker_basics/main.py b/examples/ev3/speaker_basics/main.py index ac50e4c..e729883 100644 --- a/examples/ev3/speaker_basics/main.py +++ b/examples/ev3/speaker_basics/main.py @@ -1,5 +1,3 @@ -#!/usr/bin/env pybricks-micropython - from pybricks.hubs import EV3Brick from pybricks.tools import wait from pybricks.media.ev3dev import SoundFile diff --git a/examples/ev3/uart_basics/main.py b/examples/ev3/uart_basics/main.py index aaa273c..15da4a5 100644 --- a/examples/ev3/uart_basics/main.py +++ b/examples/ev3/uart_basics/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.iodevices import UARTDevice from pybricks.parameters import Port diff --git a/examples/ev3/vernier_surface_temperature/main.py b/examples/ev3/vernier_surface_temperature/main.py index 3eed263..58b6e02 100644 --- a/examples/ev3/vernier_surface_temperature/main.py +++ b/examples/ev3/vernier_surface_temperature/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env pybricks-micropython from pybricks.parameters import Port from pybricks.nxtdevices import VernierAdapter diff --git a/src/pybricks/ev3dev/_speaker.py b/src/pybricks/ev3dev/_speaker.py deleted file mode 100644 index 38f2738..0000000 --- a/src/pybricks/ev3dev/_speaker.py +++ /dev/null @@ -1,126 +0,0 @@ -# SPDX-License-Identifier: MIT -# Copyright (c) 2018-2021 The Pybricks Authors - -from typing import Iterable, Union, Optional - -from ..media.ev3dev import SoundFile - - -class Speaker: - """Plays beeps and sounds using a speaker.""" - - def beep(self, frequency: int = 500, duration: int = 100) -> None: - """beep(frequency=500, duration=100) - - Play a beep/tone. - - Arguments: - frequency (Number, Hz): - Frequency of the beep. Frequencies below 100 Hz are treated as - 100 Hz. - duration (Number, ms): - Duration of the beep. If the duration is less than 0, then the - method returns immediately and the frequency play continues to - play indefinitely. - """ - - def play_notes(self, notes: Iterable[str], tempo: int = 120) -> None: - """play_notes(notes, tempo=120) - - Plays a sequence of musical notes. For example: - ``['C4/4', 'C4/4', 'G4/4', 'G4/4']``. - - Each note is a string with the following format: - - - The first character is the name of the note, ``A`` to ``G`` - or ``R`` for a rest. - - Note names can also include an accidental ``#`` (sharp) or - ``b`` (flat). ``B#``/``Cb`` and ``E#``/``Fb`` are not - allowed. - - The note name is followed by the octave number ``2`` - to ``8``. For example ``C4`` is middle C. The octave changes - to the next number at the note C, for example, ``B3`` is the - note below middle C (``C4``). - - The octave is followed by ``/`` and a number that indicates - the size of the note. For example ``/4`` is a quarter note, - ``/8`` is an eighth note and so on. - - This can optionally followed by a ``.`` to make a dotted - note. Dotted notes are 1-1/2 times as long as notes without a - dot. - - The note can optionally end with a ``_`` which is a tie or a - slur. This causes there to be no pause between this note and - the next note. - - Arguments: - notes (iter): - A sequence of notes to be played. - tempo (int): - Beats per minute. A quarter note is one beat. - """ - - def play_file(self, file_name: Union[SoundFile, str]) -> None: - """play_file(file_name) - - Plays a sound file. - - Arguments: - file (str): - Path to the sound file, including the file extension. - """ - - def say(self, text: str) -> None: - """say(text) - - Says a given text string. - - You can configure the language and voice of the text using - :meth:`.set_speech_options`. - - Arguments: - text (str): What to say. - """ - - def set_speech_options( - self, - language: Optional[str] = None, - voice: Optional[str] = None, - speed: Optional[int] = None, - pitch: Optional[int] = None, - ): - """set_speech_options(language, voice, speed, pitch) - - Configures speech settings used by the :meth:`.say` method. - - Any option that is set to ``None`` will not be changed. If an option - is set to an invalid value :meth:`.say` will use the default value - instead. - - Arguments: - language (str): - Language of the text. For example, you can choose ``'en'`` - (English) or ``'de'`` (German). [#espeak_lang]_ - voice (str): - The voice to use. For example, you can choose ``'f1'`` (female - voice variant 1) or ``'m3'`` (male voice variant 3). - [#espeak_lang]_ - speed (int): - Number of words per minute. - pitch (int): - Pitch (0 to 99). Higher numbers make the voice higher pitched - and lower numbers make the voice lower pitched. - """ - - def set_volume(self, volume: int, which: str = "_all_") -> None: - """set_volume(volume, which="_all_") - - Sets the speaker volume. - - Arguments: - volume (Number, %): - Volume of the speaker. - which (str): - Which volume to set. ``'Beep'`` sets the volume for - `beep` and `play_notes`. ``'PCM'`` sets the - volume for :meth:`.play_file` and :meth:`.say`. ``'_all_'`` - sets both at the same time. - """ diff --git a/src/pybricks/hubs.py b/src/pybricks/hubs.py index 6930664..ff83c19 100644 --- a/src/pybricks/hubs.py +++ b/src/pybricks/hubs.py @@ -8,9 +8,7 @@ from __future__ import annotations from typing import TYPE_CHECKING from . import _common -from .ev3dev import _speaker -from .media.ev3dev import Image as _Image -from .parameters import Axis, Button as _Button +from .parameters import Axis, Button as _Button, Image as _Image class EV3Brick: @@ -28,7 +26,7 @@ class EV3Brick: ] ) screen = _Image("_screen_") - speaker = _speaker.Speaker() + speaker = _common.Speaker() battery = _common.Battery() light = _common.ColorLight() diff --git a/src/pybricks/media/__init__.py b/src/pybricks/media/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/pybricks/media/ev3dev.py b/src/pybricks/media/ev3dev.py deleted file mode 100644 index 6271cdc..0000000 --- a/src/pybricks/media/ev3dev.py +++ /dev/null @@ -1,545 +0,0 @@ -# SPDX-License-Identifier: MIT -# Copyright (c) 2018-2020 The Pybricks Authors - -"""Images and Sounds for Pybricks on ev3dev.""" - -from __future__ import annotations - -from typing import Union, Literal, overload, Optional, Any - -from ..parameters import Color - - -class Image: - """Object representing a graphics image. This can either be an in-memory - copy of an image or the image displayed on a screen.""" - - # Documentation note: This class is also treated as the `screen` object - # on EV3 so we use |this image| when it would make sense to say "the screen" - # in that context and it is automatically replaced when the documentation - # is generated. - - @overload - def __init__(self, /, source: Union[Image, ImageFile, str]): ... - - @overload - def __init__( - self, /, source: Image, sub: Literal[False], x1: int, y1: int, x2: int, y2: int - ): ... - - def __init__(self, *args): - """Image(source, sub=False) - - - Arguments: - source (str or Image): - The source of the image. - - If ``source`` is a string, then the image will be loaded from - the file path given by the string. Only ``.png`` files are - supported. As a special case, if the string is ``_screen_``, - the image will be configured to draw directly on the screen. - - If an :class:`Image` is given, the new object will contain a - copy of the ``source`` image object. - - sub (bool): - If ``sub`` is ``True``, then the image object will act as a - sub-image of the ``source`` image (this only works if the type - of ``source`` is :class:`Image` and not when it is a ``str``). - - Additional keyword arguments ``x1``, ``y1``, ``x2``, ``y2`` are - needed when ``sub=True``. These specify the top-left and - bottom-right coordinates in the ``source`` image that will be - used as the bounds for the sub-image. - """ - - @property - def width(self) -> int: - """Gets the width of |this image| in pixels.""" - return 0 - - @property - def height(self) -> int: - """Gets the height of |this image| in pixels.""" - return 0 - - def clear(self) -> None: - """clear() - - Clears |this image|. All pixels on |this image| will be set to - :attr:`Color.WHITE `. - """ - - def draw_pixel(self, x: int, y: int, color: Color = Color.BLACK) -> None: - """draw_pixel(x, y, color=Color.BLACK) - - Draws a single pixel on |this image|. - - Arguments: - x (int): The x coordinate of the pixel. - y (int): The y coordinate of the pixel. - color (Color): The color of the pixel. - """ - - def draw_line( - self, - x1: int, - y1: int, - x2: int, - y2: int, - width: int = 1, - color: Color = Color.BLACK, - ) -> None: - """draw_line(x1, y1, x2, y2, width=1, color=Color.BLACK) - - Draws a line on |this image|. - - Arguments: - x1 (int): The x coordinate of the starting point of the line. - y1 (int): The y coordinate of the starting point of the line. - x2 (int): The x coordinate of the ending point of the line. - y2 (int): The y coordinate of the ending point of the line. - width (int): The width of the line in pixels. - color (Color): The color of the line. - """ - - def draw_box( - self, - x1: int, - y1: int, - x2: int, - y2: int, - r: int = 0, - fill: bool = False, - color: Color = Color.BLACK, - ) -> None: - """draw_box(x1, y1, x2, y2, r=0, fill=False, color=Color.BLACK) - - Draws a box on |this image|. - - Arguments: - x1 (int): The x coordinate of the left side of the box. - y1 (int): The y coordinate of the top of the box. - 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. - 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. - """ - - def draw_circle( - self, x: int, y: int, r: int, fill: bool = False, color: Color = Color.BLACK - ) -> None: - """draw_circle(x, y, r, fill=False, color=Color.BLACK) - - Draws a circle on |this 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. - 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. - """ - - def draw_image( - self, - x: int, - y: int, - source: Union[Image, ImageFile, str], - transparent: Optional[Color] = None, - ) -> None: - """draw_image(x, y, source, transparent=None) - - Draws the ``source`` image on |this image|. - - Arguments: - x (int): - The x-axis value where the left side of the image will start. - y (int): - The y-axis value where the top of the image will start. - source (Image or str): - The source :class:`Image `. If - the argument is a string, then the ``source`` image is loaded - from file. - transparent (Color): - The color of ``image`` to treat as transparent or ``None`` for - no transparency. - """ - - def load_image(self, source: Union[Image, ImageFile, str]) -> None: - """load_image(source) - - Clears this image, then draws the ``source`` image 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: int, - y: int, - text: str, - text_color: Color = Color.BLACK, - background_color: Optional[Color] = None, - ) -> None: - """draw_text(x, y, text, text_color=Color.BLACK, background_color=None) - - Draws text on |this image|. - - The most recent font set using :meth:`.set_font` will be used or - :data:`Font.DEFAULT ` if no font - has been set yet. - - Arguments: - x (int): - The x-axis value where the left side of the text will start. - y (int): - The y-axis value where the top of the text will start. - text (str): - The text to draw. - text_color (Color): - The color used for drawing the text. - background_color (Color): - The color used to fill the rectangle behind the text or - ``None`` for transparent background. - """ - - def print(self, *args: Any, sep: str = " ", end: str = "\n") -> None: - """print(*args, sep=" ", end="\\n") - - Prints a line of text on |this image|. - - This method works like the builtin ``print()`` function, but it writes - on |this image| instead. - - You can set the font using :meth:`.set_font`. If no font has been set, - :data:`Font.DEFAULT ` will be - used. The text is always printed used black text with a white - background. - - Unlike the builtin ``print()``, the text does not wrap if it is too - wide to fit on |this image|. It just gets cut off. But if the text - would go off of the bottom of |this image|, the entire image is - scrolled up and the text is printed in the new blank area at the - bottom of |this image|. - - Arguments: - args (Any): Zero or more objects to print. - sep (str): Separator that will be placed between each object that - is printed. - end (str): End of line that will be printed after the last object. - """ - - def set_font(self, font: Font) -> None: - """set_font(font) - - Sets the font used for writing on |this image|. - - The font is used for both :meth:`.draw_text` and :meth:`.print`. - - Arguments: - font (Font): - The font to use. - """ - - @staticmethod - def empty(width: int = 178, height: int = 128) -> Image: - """empty(width=178, height=128) -> Image - - Creates a new empty :class:`Image` object. - - Arguments: - width (int): - The width of the image in pixels. - height (int): - The height of the image in pixels. - - Returns: - A new image with all pixels set - to :attr:`Color.WHITE `. - - Raises: - TypeError: - If ``width`` or ``height`` is not a number. - ValueError: - If ``width`` or ``height`` is less than 1. - RuntimeError: - If there was a problem allocating a new image. - """ - - def save(self, filename: str) -> None: - """save(filename) - - Saves |this image| as a ``.png`` file. - - Arguments: - filename (str): - The path to the file to be saved. - - Raises: - TypeError: - ``filename`` is not a string. - OSError: - There was a problem saving the file. - """ - - -class Font: - """Object that represents a font for writing text.""" - - DEFAULT: Font = None # assigned later since we can't use Font() here - """The default font.""" - - def __init__( - self, - family: Optional[str] = None, - size: int = 12, - bold: bool = False, - monospace: bool = False, - lang: Optional[str] = None, - script: Optional[str] = None, - ): - """Font(family=None, size=12, bold=False, monospace=False, lang=None, script=None) - - The font object will be a font that is the "best" match based on the - parameters given and available fonts installed. - - Arguments: - family (str): - The preferred font family or ``None`` to use the default value. - size (int): - The preferred font size. Most fonts have sizes between 6 and 24. - This is the "point" size and not the same as :attr:`height`. - bold (bool): - When ``True``, prefer bold fonts. - monospace (bool): - When ``True`` prefer monospaced fonts. This is useful for - aligning multiple rows of text. - lang (str): - A language code, such as ``'en'`` or ``'zh-cn'`` or ``None`` to - use the default language. [#font_lang]_ - script (str): - A unicode script identifier such as ``'Runr'`` or ``None``. - """ - - @property - def family(self) -> str: - """Gets the family name of the font.""" - return "Lucida" - - @property - def style(self) -> str: - """style -> str - - Gets a string describing the font style. - - Can be "Regular" or "Bold". - """ - return "Regular" - - @property - def width(self) -> int: - """Gets the width of the widest character of the font.""" - return 0 - - @property - def height(self) -> int: - """Gets the height of the font.""" - return 0 - - def text_width(self, text: str) -> int: - """text_width(text) - - Gets the width of the text when the text is drawn using this font. - - Arguments: - text (str): - The text. - - Returns: - int: - The width in pixels. - """ - return 0 - - def text_height(self, text: str) -> int: - """text_height(text) - - Gets the height of the text when the text is drawn using this font. - - Arguments: - text (str): - The text. - - Returns: - int: - The height in pixels. - """ - return 0 - - -Font.DEFAULT = Font("Lucida", 12) - - -class SoundFile: - """Paths to standard EV3 sounds.""" - - _BASE_PATH: str = "/usr/share/sounds/ev3dev/" - SHOUTING: str = _BASE_PATH + "expressions/shouting.wav" - CHEERING: str = _BASE_PATH + "expressions/cheering.wav" - CRYING: str = _BASE_PATH + "expressions/crying.wav" - OUCH: str = _BASE_PATH + "expressions/ouch.wav" - LAUGHING_2: str = _BASE_PATH + "expressions/laughing_2.wav" - SNEEZING: str = _BASE_PATH + "expressions/sneezing.wav" - SMACK: str = _BASE_PATH + "expressions/smack.wav" - BOING: str = _BASE_PATH + "expressions/boing.wav" - BOO: str = _BASE_PATH + "expressions/boo.wav" - UH_OH: str = _BASE_PATH + "expressions/uh-oh.wav" - SNORING: str = _BASE_PATH + "expressions/snoring.wav" - KUNG_FU: str = _BASE_PATH + "expressions/kung_fu.wav" - FANFARE: str = _BASE_PATH + "expressions/fanfare.wav" - CRUNCHING: str = _BASE_PATH + "expressions/crunching.wav" - MAGIC_WAND: str = _BASE_PATH + "expressions/magic_wand.wav" - LAUGHING_1: str = _BASE_PATH + "expressions/laughing_1.wav" - LEFT: str = _BASE_PATH + "information/left.wav" - BACKWARDS: str = _BASE_PATH + "information/backwards.wav" - RIGHT: str = _BASE_PATH + "information/right.wav" - OBJECT: str = _BASE_PATH + "information/object.wav" - COLOR: str = _BASE_PATH + "information/color.wav" - FLASHING: str = _BASE_PATH + "information/flashing.wav" - ERROR: str = _BASE_PATH + "information/error.wav" - ERROR_ALARM: str = _BASE_PATH + "information/error_alarm.wav" - DOWN: str = _BASE_PATH + "information/down.wav" - FORWARD: str = _BASE_PATH + "information/forward.wav" - ACTIVATE: str = _BASE_PATH + "information/activate.wav" - SEARCHING: str = _BASE_PATH + "information/searching.wav" - TOUCH: str = _BASE_PATH + "information/touch.wav" - UP: str = _BASE_PATH + "information/up.wav" - ANALYZE: str = _BASE_PATH + "information/analyze.wav" - STOP: str = _BASE_PATH + "information/stop.wav" - DETECTED: str = _BASE_PATH + "information/detected.wav" - TURN: str = _BASE_PATH + "information/turn.wav" - START: str = _BASE_PATH + "information/start.wav" - MORNING: str = _BASE_PATH + "communication/morning.wav" - EV3: str = _BASE_PATH + "communication/ev3.wav" - GO: str = _BASE_PATH + "communication/go.wav" - GOOD_JOB: str = _BASE_PATH + "communication/good_job.wav" - OKEY_DOKEY: str = _BASE_PATH + "communication/okey-dokey.wav" - GOOD: str = _BASE_PATH + "communication/good.wav" - NO: str = _BASE_PATH + "communication/no.wav" - THANK_YOU: str = _BASE_PATH + "communication/thank_you.wav" - YES: str = _BASE_PATH + "communication/yes.wav" - GAME_OVER: str = _BASE_PATH + "communication/game_over.wav" - OKAY: str = _BASE_PATH + "communication/okay.wav" - SORRY: str = _BASE_PATH + "communication/sorry.wav" - BRAVO: str = _BASE_PATH + "communication/bravo.wav" - GOODBYE: str = _BASE_PATH + "communication/goodbye.wav" - HI: str = _BASE_PATH + "communication/hi.wav" - HELLO: str = _BASE_PATH + "communication/hello.wav" - MINDSTORMS: str = _BASE_PATH + "communication/mindstorms.wav" - LEGO: str = _BASE_PATH + "communication/lego.wav" - FANTASTIC: str = _BASE_PATH + "communication/fantastic.wav" - SPEED_IDLE: str = _BASE_PATH + "movements/speed_idle.wav" - SPEED_DOWN: str = _BASE_PATH + "movements/speed_down.wav" - SPEED_UP: str = _BASE_PATH + "movements/speed_up.wav" - BROWN: str = _BASE_PATH + "colors/brown.wav" - GREEN: str = _BASE_PATH + "colors/green.wav" - BLACK: str = _BASE_PATH + "colors/black.wav" - WHITE: str = _BASE_PATH + "colors/white.wav" - RED: str = _BASE_PATH + "colors/red.wav" - BLUE: str = _BASE_PATH + "colors/blue.wav" - YELLOW: str = _BASE_PATH + "colors/yellow.wav" - TICK_TACK: str = _BASE_PATH + "mechanical/tick_tack.wav" - HORN_1: str = _BASE_PATH + "mechanical/horn_1.wav" - BACKING_ALERT: str = _BASE_PATH + "mechanical/backing_alert.wav" - MOTOR_IDLE: str = _BASE_PATH + "mechanical/motor_idle.wav" - AIR_RELEASE: str = _BASE_PATH + "mechanical/air_release.wav" - AIRBRAKE: str = _BASE_PATH + "mechanical/airbrake.wav" - RATCHET: str = _BASE_PATH + "mechanical/ratchet.wav" - MOTOR_STOP: str = _BASE_PATH + "mechanical/motor_stop.wav" - HORN_2: str = _BASE_PATH + "mechanical/horn_2.wav" - LASER: str = _BASE_PATH + "mechanical/laser.wav" - SONAR: str = _BASE_PATH + "mechanical/sonar.wav" - MOTOR_START: str = _BASE_PATH + "mechanical/motor_start.wav" - INSECT_BUZZ_2: str = _BASE_PATH + "animals/insect_buzz_2.wav" - ELEPHANT_CALL: str = _BASE_PATH + "animals/elephant_call.wav" - SNAKE_HISS: str = _BASE_PATH + "animals/snake_hiss.wav" - DOG_BARK_2: str = _BASE_PATH + "animals/dog_bark_2.wav" - DOG_WHINE: str = _BASE_PATH + "animals/dog_whine.wav" - INSECT_BUZZ_1: str = _BASE_PATH + "animals/insect_buzz_1.wav" - DOG_SNIFF: str = _BASE_PATH + "animals/dog_sniff.wav" - T_REX_ROAR: str = _BASE_PATH + "animals/t-rex_roar.wav" - INSECT_CHIRP: str = _BASE_PATH + "animals/insect_chirp.wav" - DOG_GROWL: str = _BASE_PATH + "animals/dog_growl.wav" - SNAKE_RATTLE: str = _BASE_PATH + "animals/snake_rattle.wav" - DOG_BARK_1: str = _BASE_PATH + "animals/dog_bark_1.wav" - CAT_PURR: str = _BASE_PATH + "animals/cat_purr.wav" - EIGHT: str = _BASE_PATH + "numbers/eight.wav" - SEVEN: str = _BASE_PATH + "numbers/seven.wav" - SIX: str = _BASE_PATH + "numbers/six.wav" - FOUR: str = _BASE_PATH + "numbers/four.wav" - TEN: str = _BASE_PATH + "numbers/ten.wav" - ONE: str = _BASE_PATH + "numbers/one.wav" - TWO: str = _BASE_PATH + "numbers/two.wav" - THREE: str = _BASE_PATH + "numbers/three.wav" - ZERO: str = _BASE_PATH + "numbers/zero.wav" - FIVE: str = _BASE_PATH + "numbers/five.wav" - NINE: str = _BASE_PATH + "numbers/nine.wav" - READY: str = _BASE_PATH + "system/ready.wav" - CONFIRM: str = _BASE_PATH + "system/confirm.wav" - GENERAL_ALERT: str = _BASE_PATH + "system/general_alert.wav" - CLICK: str = _BASE_PATH + "system/click.wav" - OVERPOWER: str = _BASE_PATH + "system/overpower.wav" - - -class ImageFile: - """Paths to standard EV3 images.""" - - _BASE_PATH: str = "/usr/share/images/ev3dev/mono/" - RIGHT: str = _BASE_PATH + "information/right.png" - FORWARD: str = _BASE_PATH + "information/forward.png" - ACCEPT: str = _BASE_PATH + "information/accept.png" - QUESTION_MARK: str = _BASE_PATH + "information/question_mark.png" - STOP_1: str = _BASE_PATH + "information/stop_1.png" - LEFT: str = _BASE_PATH + "information/left.png" - DECLINE: str = _BASE_PATH + "information/decline.png" - THUMBS_DOWN: str = _BASE_PATH + "information/thumbs_down.png" - BACKWARD: str = _BASE_PATH + "information/backward.png" - NO_GO: str = _BASE_PATH + "information/no_go.png" - WARNING: str = _BASE_PATH + "information/warning.png" - STOP_2: str = _BASE_PATH + "information/stop_2.png" - THUMBS_UP: str = _BASE_PATH + "information/thumbs_up.png" - EV3: str = _BASE_PATH + "lego/ev3.png" - EV3_ICON: str = _BASE_PATH + "lego/ev3_icon.png" - TARGET: str = _BASE_PATH + "objects/target.png" - BOTTOM_RIGHT: str = _BASE_PATH + "eyes/bottom_right.png" - BOTTOM_LEFT: str = _BASE_PATH + "eyes/bottom_left.png" - EVIL: str = _BASE_PATH + "eyes/evil.png" - CRAZY_2: str = _BASE_PATH + "eyes/crazy_2.png" - KNOCKED_OUT: str = _BASE_PATH + "eyes/knocked_out.png" - PINCHED_RIGHT: str = _BASE_PATH + "eyes/pinched_right.png" - WINKING: str = _BASE_PATH + "eyes/winking.png" - DIZZY: str = _BASE_PATH + "eyes/dizzy.png" - DOWN: str = _BASE_PATH + "eyes/down.png" - TIRED_MIDDLE: str = _BASE_PATH + "eyes/tired_middle.png" - MIDDLE_RIGHT: str = _BASE_PATH + "eyes/middle_right.png" - SLEEPING: str = _BASE_PATH + "eyes/sleeping.png" - MIDDLE_LEFT: str = _BASE_PATH + "eyes/middle_left.png" - TIRED_RIGHT: str = _BASE_PATH + "eyes/tired_right.png" - PINCHED_LEFT: str = _BASE_PATH + "eyes/pinched_left.png" - PINCHED_MIDDLE: str = _BASE_PATH + "eyes/pinched_middle.png" - CRAZY_1: str = _BASE_PATH + "eyes/crazy_1.png" - NEUTRAL: str = _BASE_PATH + "eyes/neutral.png" - AWAKE: str = _BASE_PATH + "eyes/awake.png" - UP: str = _BASE_PATH + "eyes/up.png" - TIRED_LEFT: str = _BASE_PATH + "eyes/tired_left.png" - ANGRY: str = _BASE_PATH + "eyes/angry.png" diff --git a/src/pybricks/media/py.typed b/src/pybricks/media/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/src/pybricks/parameters.py b/src/pybricks/parameters.py index ca0d45d..25d4930 100644 --- a/src/pybricks/parameters.py +++ b/src/pybricks/parameters.py @@ -7,10 +7,13 @@ from __future__ import annotations import os from enum import Enum -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, overload from .tools import Matrix as _Matrix, vector as _vector +if TYPE_CHECKING: + from typing import Any, Literal, Optional, Union + if TYPE_CHECKING or os.environ.get("SPHINX_BUILD") == "True": Number = int | float """ @@ -562,3 +565,373 @@ class Icon: | ⬜🟨⬜🟨⬜ | 🟨⬜⬜⬜🟨 """ + + +class Image: + """Object representing a graphics image. This can either be an in-memory + copy of an image or the image displayed on a screen.""" + + # Documentation note: This class is also treated as the `screen` object + # on EV3 so we use |this image| when it would make sense to say "the screen" + # in that context and it is automatically replaced when the documentation + # is generated. + + @overload + def __init__(self, /, source: Union[Image, ImageFile]): ... + + @overload + def __init__( + self, /, source: Image, sub: Literal[False], x1: int, y1: int, x2: int, y2: int + ): ... + + def __init__(self, *args): + """Image(source, sub=False) + + + Arguments: + source (Image): + The source image. The new object will contain a copy of + the ``source`` image object. + + sub (bool): + If ``sub`` is ``True``, then the image object will act as a + sub-image of the ``source`` image. + + Additional keyword arguments ``x1``, ``y1``, ``x2``, ``y2`` are + needed when ``sub=True``. These specify the top-left and + bottom-right coordinates in the ``source`` image that will be + used as the bounds for the sub-image. + """ + + @property + def width(self) -> int: + """Gets the width of |this image| in pixels.""" + return 0 + + @property + def height(self) -> int: + """Gets the height of |this image| in pixels.""" + return 0 + + def clear(self) -> None: + """clear() + + Clears |this image|. All pixels on |this image| will be set to + :attr:`Color.WHITE `. + """ + + def draw_pixel(self, x: int, y: int, color: Color = Color.BLACK) -> None: + """draw_pixel(x, y, color=Color.BLACK) + + Draws a single pixel on |this image|. + + Arguments: + x (int): The x coordinate of the pixel. + y (int): The y coordinate of the pixel. + color (Color): The color of the pixel. + """ + + def draw_line( + self, + x1: int, + y1: int, + x2: int, + y2: int, + width: int = 1, + color: Color = Color.BLACK, + ) -> None: + """draw_line(x1, y1, x2, y2, width=1, color=Color.BLACK) + + Draws a line on |this image|. + + Arguments: + x1 (int): The x coordinate of the starting point of the line. + y1 (int): The y coordinate of the starting point of the line. + x2 (int): The x coordinate of the ending point of the line. + y2 (int): The y coordinate of the ending point of the line. + width (int): The width of the line in pixels. + color (Color): The color of the line. + """ + + def draw_box( + self, + x1: int, + y1: int, + x2: int, + y2: int, + r: int = 0, + fill: bool = False, + color: Color = Color.BLACK, + ) -> None: + """draw_box(x1, y1, x2, y2, r=0, fill=False, color=Color.BLACK) + + Draws a box on |this image|. + + Arguments: + x1 (int): The x coordinate of the left side of the box. + y1 (int): The y coordinate of the top of the box. + 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. + 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. + """ + + def draw_circle( + self, x: int, y: int, r: int, fill: bool = False, color: Color = Color.BLACK + ) -> None: + """draw_circle(x, y, r, fill=False, color=Color.BLACK) + + Draws a circle on |this 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. + 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. + """ + + def draw_image( + self, + x: int, + y: int, + source: Union[Image, ImageFile], + transparent: Optional[Color] = None, + ) -> None: + """draw_image(x, y, source, transparent=None) + + Draws the ``source`` image on |this image|. + + Arguments: + x (int): + The x-axis value where the left side of the image will start. + y (int): + The y-axis value where the top of the image will start. + source (Image): + The source :class:`Image `. + transparent (Color): + The color of ``image`` to treat as transparent or ``None`` for + no transparency. + """ + + def load_image(self, source: Union[Image, ImageFile]) -> None: + """load_image(source) + + Clears this image, then draws the ``source`` image centered in + |this image|. + + Arguments: + source (Image): + The source :class:`Image `. + """ + + def draw_text( + self, + x: int, + y: int, + text: str, + text_color: Color = Color.BLACK, + background_color: Optional[Color] = None, + ) -> None: + """draw_text(x, y, text, text_color=Color.BLACK, background_color=None) + + Draws text on |this image|. + + The most recent font set using :meth:`.set_font` will be used or + :data:`Font.DEFAULT ` if no font + has been set yet. + + Arguments: + x (int): + The x-axis value where the left side of the text will start. + y (int): + The y-axis value where the top of the text will start. + text (str): + The text to draw. + text_color (Color): + The color used for drawing the text. + background_color (Color): + The color used to fill the rectangle behind the text or + ``None`` for transparent background. + """ + + def print(self, *args: Any, sep: str = " ", end: str = "\n") -> None: + """print(*args, sep=" ", end="\\n") + + Prints a line of text on |this image|. + + This method works like the builtin ``print()`` function, but it writes + on |this image| instead. + + You can set the font using :meth:`.set_font`. If no font has been set, + :data:`Font.DEFAULT ` will be + used. The text is always printed used black text with a white + background. + + Unlike the builtin ``print()``, the text does not wrap if it is too + wide to fit on |this image|. It just gets cut off. But if the text + would go off of the bottom of |this image|, the entire image is + scrolled up and the text is printed in the new blank area at the + bottom of |this image|. + + Arguments: + args (Any): Zero or more objects to print. + sep (str): Separator that will be placed between each object that + is printed. + end (str): End of line that will be printed after the last object. + """ + + def set_font(self, font: Font) -> None: + """set_font(font) + + Sets the font used for writing on |this image|. + + The font is used for both :meth:`.draw_text` and :meth:`.print`. + + Arguments: + font (Font): + The font to use. + """ + + @staticmethod + def empty(width: int = 178, height: int = 128) -> Image: + """empty(width=178, height=128) -> Image + + Creates a new empty :class:`Image` object. + + Arguments: + width (int): + The width of the image in pixels. + height (int): + The height of the image in pixels. + + Returns: + A new image with all pixels set + to :attr:`Color.WHITE `. + + Raises: + TypeError: + If ``width`` or ``height`` is not a number. + ValueError: + If ``width`` or ``height`` is less than 1. + RuntimeError: + If there was a problem allocating a new image. + """ + + +class Font: + """Object that represents a font for writing text.""" + + DEFAULT: Font = ... + """The default font.""" + + TERMINUS_16: Font = ... + """The Terminus font with a height of 16 pixels.""" + + LIBERATIONSANS_14: Font = ... + """The Liberation Sans regular font with a height of 14 pixels.""" + + MONO_8X5_8: Font = ... + """A monospaced font with a height of 8 pixels and a width of 5 pixels.""" + + @property + def family(self) -> str: + """Gets the family name of the font.""" + return "Lucida" + + @property + def style(self) -> str: + """style -> str + + Gets a string describing the font style. + + Can be "Regular" or "Bold". + """ + return "Regular" + + @property + def width(self) -> int: + """Gets the width of the widest character of the font.""" + return 0 + + @property + def height(self) -> int: + """Gets the height of the font.""" + return 0 + + def text_width(self, text: str) -> int: + """text_width(text) + + Gets the width of the text when the text is drawn using this font. + + Arguments: + text (str): + The text. + + Returns: + int: + The width in pixels. + """ + return 0 + + def text_height(self, text: str) -> int: + """text_height(text) + + Gets the height of the text when the text is drawn using this font. + + Arguments: + text (str): + The text. + + Returns: + int: + The height in pixels. + """ + return 0 + + +class ImageFile: + """Paths to standard EV3 images.""" + + _BASE_PATH: str = "/usr/share/images/ev3dev/mono/" + RIGHT: str = _BASE_PATH + "information/right.png" + FORWARD: str = _BASE_PATH + "information/forward.png" + ACCEPT: str = _BASE_PATH + "information/accept.png" + QUESTION_MARK: str = _BASE_PATH + "information/question_mark.png" + STOP_1: str = _BASE_PATH + "information/stop_1.png" + LEFT: str = _BASE_PATH + "information/left.png" + DECLINE: str = _BASE_PATH + "information/decline.png" + THUMBS_DOWN: str = _BASE_PATH + "information/thumbs_down.png" + BACKWARD: str = _BASE_PATH + "information/backward.png" + NO_GO: str = _BASE_PATH + "information/no_go.png" + WARNING: str = _BASE_PATH + "information/warning.png" + STOP_2: str = _BASE_PATH + "information/stop_2.png" + THUMBS_UP: str = _BASE_PATH + "information/thumbs_up.png" + EV3: str = _BASE_PATH + "lego/ev3.png" + EV3_ICON: str = _BASE_PATH + "lego/ev3_icon.png" + TARGET: str = _BASE_PATH + "objects/target.png" + BOTTOM_RIGHT: str = _BASE_PATH + "eyes/bottom_right.png" + BOTTOM_LEFT: str = _BASE_PATH + "eyes/bottom_left.png" + EVIL: str = _BASE_PATH + "eyes/evil.png" + CRAZY_2: str = _BASE_PATH + "eyes/crazy_2.png" + KNOCKED_OUT: str = _BASE_PATH + "eyes/knocked_out.png" + PINCHED_RIGHT: str = _BASE_PATH + "eyes/pinched_right.png" + WINKING: str = _BASE_PATH + "eyes/winking.png" + DIZZY: str = _BASE_PATH + "eyes/dizzy.png" + DOWN: str = _BASE_PATH + "eyes/down.png" + TIRED_MIDDLE: str = _BASE_PATH + "eyes/tired_middle.png" + MIDDLE_RIGHT: str = _BASE_PATH + "eyes/middle_right.png" + SLEEPING: str = _BASE_PATH + "eyes/sleeping.png" + MIDDLE_LEFT: str = _BASE_PATH + "eyes/middle_left.png" + TIRED_RIGHT: str = _BASE_PATH + "eyes/tired_right.png" + PINCHED_LEFT: str = _BASE_PATH + "eyes/pinched_left.png" + PINCHED_MIDDLE: str = _BASE_PATH + "eyes/pinched_middle.png" + CRAZY_1: str = _BASE_PATH + "eyes/crazy_1.png" + NEUTRAL: str = _BASE_PATH + "eyes/neutral.png" + AWAKE: str = _BASE_PATH + "eyes/awake.png" + UP: str = _BASE_PATH + "eyes/up.png" + TIRED_LEFT: str = _BASE_PATH + "eyes/tired_left.png" + ANGRY: str = _BASE_PATH + "eyes/angry.png"