From 4e998ad2bd64744a8fc4861591c01356b43bb7cd Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Fri, 6 Nov 2020 09:17:15 +0000 Subject: [PATCH] writer.py: fast_mode optional relative import. --- writer/writer.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/writer/writer.py b/writer/writer.py index 9d11189..0486764 100644 --- a/writer/writer.py +++ b/writer/writer.py @@ -19,17 +19,22 @@ # Slow method 2700μs typical, up to 11ms on larger fonts import framebuf -fast_mode = False -try: - from framebuf_utils import render - fast_mode = True -except ImportError: - pass -except ValueError: - print('Ignoring framebuf_utils.mpy: it was compiled for an incorrect architecture.') - from uctypes import bytearray_at, addressof +fast_mode = True +try: + try: + from framebuf_utils import render + except ImportError: # May be running in GUI. Try relative import. + try: + from .framebuf_utils import render + except ImportError: + fast_mode = False +except ValueError: + fast_mode = False + print('Ignoring framebuf_utils.mpy: compiled for incorrect architecture.') + + class DisplayState(): def __init__(self): self.text_row = 0