-
Notifications
You must be signed in to change notification settings - Fork 11
CPython compatibility fix #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
30c0988
b197cd6
0161017
cf9a11a
8c32679
017591b
5acb2d0
c146d6b
87ee248
12e4ec2
47f94f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||
# SPDX-FileCopyrightText: 2006-2010 Gregor Lingl for Adafruit Industries | ||||
# SPDX-FileCopyrightText: 2019 LadyAda for Adafruit Industries | ||||
# SPDX-FileCopyrightText: 2021 Dave Astels for Adafruit Industries | ||||
# SPDX-FileCopyrightText: 2022 Carsten Thue-Bludworth for Adafruit Industries | ||||
# | ||||
# SPDX-License-Identifier: MIT | ||||
|
||||
|
@@ -30,9 +31,13 @@ | |||
import gc | ||||
import math | ||||
import time | ||||
import board | ||||
import displayio | ||||
|
||||
try: | ||||
import board | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an usual import to mask with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @tekktrik, the reason I catch that exception is so that I can run this module on systems that don't have the I suppose another approach could be to remove the import all together, and then in the Let me know what you think! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was written before the generic x86 computer implementation was added, hence why it currently only catches There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes there is! @FoamyGuy has one here, and I've included that code in my project here. It's fun because you can incorporate I've been using this to demonstrate the power of abstraction/modularity to some of my students at University of Florida, where we can run (almost) identical code on laptops, RPis (either with HDMI or a PiTFT), and on microcontrollers with an embedded display -- just by changing the I worked on this pull request because I want to be able to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks! I'll get to this in the next few days, but that helps but the change into context! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another potential option is to move the import down to inside the if statement so that it will only try to import board. if the user has not passed a display object. |
||||
except NotImplementedError: | ||||
print("[adafruit-turtle.py]: Couldn't import board module.") | ||||
|
||||
__version__ = "0.0.0+auto.0" | ||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_turtle.git" | ||||
|
||||
|
@@ -80,7 +85,7 @@ def __init__(self): | |||
pass | ||||
|
||||
|
||||
class Vec2D(tuple): | ||||
class Vec2D: | ||||
"""A 2 dimensional vector class, used as a helper class | ||||
for implementing turtle graphics. | ||||
May be useful for turtle graphics programs also. | ||||
|
@@ -94,8 +99,11 @@ class Vec2D(tuple): | |||
# k*a and a*k multiplication with scalar | ||||
# |a| absolute value of a | ||||
# a.rotate(angle) rotation | ||||
def __init__(self, x, y): | ||||
super().__init__((x, y)) | ||||
def __new__(cls, x, y): | ||||
return (x, y) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get this error using this version on a PyPortal running the simpletest script in this repo:
The simpletest is trying to subtract positions here:
Which turns out not to work because tuple doesn't have support for minus operator. This was odd to me at first because I ended up trying this version with CPython using PyGameDisplay and got the same error from the simpletest where it crashes due to trying to subtract the Vec2D's which are actually tuples instead. Some of the functionality does work properly though because you can see it draw the first line of the star in the simpletest before crashing. It seems only if you try to utilize some of the other Vec2D functions it will have trouble. |
||||
|
||||
def __getitem__(self, index): | ||||
return getattr(self, index) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way you overrode |
||||
|
||||
def __add__(self, other): | ||||
return Vec2D(self[0] + other[0], self[1] + other[1]) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the intention is to only use
for Adafruit Industiries
if you were paid by them for the development work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, ok I understand (I wish I was working for Adafruit!). I added it because I was trying to follow all of the proper protocols for contributing according to this guide.