From c8e520653e550dc36246258642f1de6deca13c98 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 18:44:24 -0500 Subject: [PATCH 01/17] adding text scaling --- adafruit_framebuf.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) mode change 100644 => 100755 adafruit_framebuf.py diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py old mode 100644 new mode 100755 index 6a736bd..47dd539 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -278,17 +278,24 @@ def scroll(self, delta_x, delta_y): x += dt_x y += dt_y - def text(self, string, x, y, color, *, + def _text(self, string, x, y, color, size, *, font_name="font5x8.bin"): """text is not yet implemented""" + if not self._font or self._font.font_name != font_name: # load the font! self._font = BitmapFont() w = self._font.font_width for i, char in enumerate(string): self._font.draw_char(char, - x + (i * (w + 1)), - y, self, color) + x + (i * (w + 1))*size, + y, self, color, size = size) + + def text(self, string, x, y, color, *, + font_name="font5x8.bin", size = 1): + for chunk in string.split('\n'): + self._text(chunk, x, y, color, size, font_name="font5x8.bin") + y += self._font.font_height*size def image(self, img): """Set buffer to value of Python Imaging Library image. The image should @@ -352,7 +359,8 @@ def __exit__(self, exception_type, exception_value, traceback): """cleanup on exit""" self.deinit() - def draw_char(self, char, x, y, framebuffer, color): + def draw_char(self, char, x, y, framebuffer, color, size = 1): + size = max(size, 1) # pylint: disable=too-many-arguments """Draw one character at position (x,y) to a framebuffer in a given color""" # Don't draw the character if it will be clipped off the visible area. @@ -368,7 +376,7 @@ def draw_char(self, char, x, y, framebuffer, color): for char_y in range(self.font_height): # Draw a pixel for each bit that's flipped on. if (line >> char_y) & 0x1: - framebuffer.pixel(x + char_x, y + char_y, color) + framebuffer.fill_rect(x + char_x*size, y + char_y*size, size, size, color) def width(self, text): """Return the pixel width of the specified text message.""" @@ -377,4 +385,4 @@ def width(self, text): class FrameBuffer1(FrameBuffer): # pylint: disable=abstract-method """FrameBuffer1 object. Inherits from FrameBuffer.""" - pass + pass \ No newline at end of file From 108a332ff8084384702a49e4a544b18b3e8178b2 Mon Sep 17 00:00:00 2001 From: TG-Techie <39284876+TG-Techie@users.noreply.github.com> Date: Mon, 25 Feb 2019 18:55:57 -0500 Subject: [PATCH 02/17] Update framebuf_simpletest.py --- examples/framebuf_simpletest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/framebuf_simpletest.py b/examples/framebuf_simpletest.py index 203ba08..6cd714f 100644 --- a/examples/framebuf_simpletest.py +++ b/examples/framebuf_simpletest.py @@ -34,4 +34,5 @@ def print_buffer(the_fb): fb.fill_rect(0, 0, WIDTH, HEIGHT, False) # write some text fb.text("hello", 0, 0, True) +fb.text("hello", 8, 0, True, size = 2) print_buffer(fb) From 54886c13d305ad0dee56d2c86aa4dba097d48577 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 19:06:12 -0500 Subject: [PATCH 03/17] combine text into one func --- adafruit_framebuf.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 47dd539..1acf03a 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -282,21 +282,23 @@ def _text(self, string, x, y, color, size, *, font_name="font5x8.bin"): """text is not yet implemented""" - if not self._font or self._font.font_name != font_name: - # load the font! - self._font = BitmapFont() - w = self._font.font_width - for i, char in enumerate(string): - self._font.draw_char(char, - x + (i * (w + 1))*size, - y, self, color, size = size) + def text(self, string, x, y, color, *, font_name="font5x8.bin", size = 1): for chunk in string.split('\n'): - self._text(chunk, x, y, color, size, font_name="font5x8.bin") + if not self._font or self._font.font_name != font_name: + # load the font! + self._font = BitmapFont() + w = self._font.font_width + for i, char in enumerate(chunk): + self._font.draw_char(char, + x + (i * (w + 1))*size, + y, self, color, size = size) y += self._font.font_height*size + + def image(self, img): """Set buffer to value of Python Imaging Library image. The image should be in 1 bit mode and a size equal to the display size.""" From 9ac3fccfe8b71b56fd765012316075964ab1e111 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 19:32:10 -0500 Subject: [PATCH 04/17] line ending for travis? maybe? --- adafruit_framebuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 1acf03a..b12e5f2 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -387,4 +387,4 @@ def width(self, text): class FrameBuffer1(FrameBuffer): # pylint: disable=abstract-method """FrameBuffer1 object. Inherits from FrameBuffer.""" - pass \ No newline at end of file + pass From 4d24cacdee42448088d42bda96d8a1fa368ad8fe Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 19:44:08 -0500 Subject: [PATCH 05/17] try index 1 --- adafruit_framebuf.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index b12e5f2..d319bc9 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -278,14 +278,9 @@ def scroll(self, delta_x, delta_y): x += dt_x y += dt_y - def _text(self, string, x, y, color, size, *, - font_name="font5x8.bin"): - """text is not yet implemented""" - - - + # pylint: disable=too-many-arguments def text(self, string, x, y, color, *, - font_name="font5x8.bin", size = 1): + font_name="font5x8.bin", size=1): for chunk in string.split('\n'): if not self._font or self._font.font_name != font_name: # load the font! @@ -294,8 +289,9 @@ def text(self, string, x, y, color, *, for i, char in enumerate(chunk): self._font.draw_char(char, x + (i * (w + 1))*size, - y, self, color, size = size) + y, self, color, size=size) y += self._font.font_height*size + # pylint: enable=too-many-arguments @@ -361,7 +357,7 @@ def __exit__(self, exception_type, exception_value, traceback): """cleanup on exit""" self.deinit() - def draw_char(self, char, x, y, framebuffer, color, size = 1): + def draw_char(self, char, x, y, framebuffer, color, size=1): size = max(size, 1) # pylint: disable=too-many-arguments """Draw one character at position (x,y) to a framebuffer in a given color""" From 986816b4a77b3ba9b7cd98242ff1da38e05094d2 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 20:01:23 -0500 Subject: [PATCH 06/17] travis, are you out there? --- adafruit_framebuf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index d319bc9..14f8837 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -281,6 +281,9 @@ def scroll(self, delta_x, delta_y): # pylint: disable=too-many-arguments def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): + """Place text on the screen in variables sizes. Breaks on \n to next line. + Does not break on line going off screen. + """ for chunk in string.split('\n'): if not self._font or self._font.font_name != font_name: # load the font! @@ -357,9 +360,9 @@ def __exit__(self, exception_type, exception_value, traceback): """cleanup on exit""" self.deinit() + # pylint: disable=too-many-arguments def draw_char(self, char, x, y, framebuffer, color, size=1): size = max(size, 1) - # pylint: disable=too-many-arguments """Draw one character at position (x,y) to a framebuffer in a given color""" # Don't draw the character if it will be clipped off the visible area. if x < -self.font_width or x >= framebuffer.width or \ From e7362323f35d1f760e9009391bfc40d581986831 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 20:11:00 -0500 Subject: [PATCH 07/17] last one? (jinxes it) --- adafruit_framebuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 14f8837..5c4605c 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -362,8 +362,8 @@ def __exit__(self, exception_type, exception_value, traceback): # pylint: disable=too-many-arguments def draw_char(self, char, x, y, framebuffer, color, size=1): - size = max(size, 1) """Draw one character at position (x,y) to a framebuffer in a given color""" + size = max(size, 1) # Don't draw the character if it will be clipped off the visible area. if x < -self.font_width or x >= framebuffer.width or \ y < -self.font_height or y >= framebuffer.height: From 3f52f21b4d157b956c6980acb7fa13524ff25634 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:05:07 -0400 Subject: [PATCH 08/17] Trying to fix travis issue --- adafruit_framebuf.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 5c4605c..02a74e6 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -144,19 +144,18 @@ class FrameBuffer: """FrameBuffer object. :param buf: An object with a buffer protocol which must be large enough to contain every - pixel defined by the width, height and format of the FrameBuffer. + pixel defined by the width, height and format of the FrameBuffer. :param width: The width of the FrameBuffer in pixel :param height: The height of the FrameBuffer in pixel :param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values - are listed under Constants below. These set the number of bits used to - encode a color value and the layout of these bits in ``buf``. Where a - color value c is passed to a method, c is a small integer with an encoding - that is dependent on the format of the FrameBuffer. + are listed under Constants below. These set the number of bits used to + encode a color value and the layout of these bits in ``buf``. Where a + color value c is passed to a method, c is a small integer with an encoding + that is dependent on the format of the FrameBuffer. :param stride: The number of pixels between each horizontal line of pixels in the - FrameBuffer. This defaults to ``width`` but may need adjustments when - implementing a FrameBuffer within another larger FrameBuffer or screen. The - ``buf`` size must accommodate an increased step size. - + FrameBuffer. This defaults to ``width`` but may need adjustments when + implementing a FrameBuffer within another larger FrameBuffer or screen. The + ``buf`` size must accommodate an increased step size. """ def __init__(self, buf, width, height, buf_format=MVLSB, stride=None): # pylint: disable=too-many-arguments From a7ee0c14f5c545e6d1260eaaa46add47b2f089aa Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:08:27 -0400 Subject: [PATCH 09/17] removed blank line --- adafruit_framebuf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 02a74e6..6fed7d6 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -142,7 +142,6 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. - :param buf: An object with a buffer protocol which must be large enough to contain every pixel defined by the width, height and format of the FrameBuffer. :param width: The width of the FrameBuffer in pixel From 4c9b493b676af60f1c516c4d161aa4f966497e35 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:12:30 -0400 Subject: [PATCH 10/17] maybe this'll work --- adafruit_framebuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 6fed7d6..13f2f97 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -143,7 +143,7 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. :param buf: An object with a buffer protocol which must be large enough to contain every - pixel defined by the width, height and format of the FrameBuffer. + pixel defined by the width, height and format of the FrameBuffer. :param width: The width of the FrameBuffer in pixel :param height: The height of the FrameBuffer in pixel :param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values From c3b7cf8b695ba86a260f2b58183c23c54271ee97 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:16:52 -0400 Subject: [PATCH 11/17] I think I figured it out --- adafruit_framebuf.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 13f2f97..d49656b 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -142,19 +142,24 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. + :param buf: An object with a buffer protocol which must be large enough to contain every pixel defined by the width, height and format of the FrameBuffer. + :param width: The width of the FrameBuffer in pixel + :param height: The height of the FrameBuffer in pixel + :param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values - are listed under Constants below. These set the number of bits used to - encode a color value and the layout of these bits in ``buf``. Where a - color value c is passed to a method, c is a small integer with an encoding - that is dependent on the format of the FrameBuffer. + are listed under Constants below. These set the number of bits used to + encode a color value and the layout of these bits in ``buf``. Where a + color value c is passed to a method, c is a small integer with an encoding + that is dependent on the format of the FrameBuffer. + :param stride: The number of pixels between each horizontal line of pixels in the - FrameBuffer. This defaults to ``width`` but may need adjustments when - implementing a FrameBuffer within another larger FrameBuffer or screen. The - ``buf`` size must accommodate an increased step size. + FrameBuffer. This defaults to ``width`` but may need adjustments when + implementing a FrameBuffer within another larger FrameBuffer or screen. The + ``buf`` size must accommodate an increased step size. """ def __init__(self, buf, width, height, buf_format=MVLSB, stride=None): # pylint: disable=too-many-arguments From b05fb696e57ca4ee71875656760f8a3d525fc9d3 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:19:12 -0400 Subject: [PATCH 12/17] Removed some trailing whitespace I accidentally left --- adafruit_framebuf.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index d49656b..f791a44 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -142,20 +142,20 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. - + :param buf: An object with a buffer protocol which must be large enough to contain every pixel defined by the width, height and format of the FrameBuffer. - + :param width: The width of the FrameBuffer in pixel - + :param height: The height of the FrameBuffer in pixel - + :param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values are listed under Constants below. These set the number of bits used to encode a color value and the layout of these bits in ``buf``. Where a color value c is passed to a method, c is a small integer with an encoding that is dependent on the format of the FrameBuffer. - + :param stride: The number of pixels between each horizontal line of pixels in the FrameBuffer. This defaults to ``width`` but may need adjustments when implementing a FrameBuffer within another larger FrameBuffer or screen. The From 06aad3f8eeffb3996b7abe15d3095200b99eddda Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:22:19 -0400 Subject: [PATCH 13/17] Removedall blank lines in docstring that was being problematic --- adafruit_framebuf.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index f791a44..646005d 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -142,20 +142,15 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. - :param buf: An object with a buffer protocol which must be large enough to contain every pixel defined by the width, height and format of the FrameBuffer. - :param width: The width of the FrameBuffer in pixel - :param height: The height of the FrameBuffer in pixel - :param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values are listed under Constants below. These set the number of bits used to encode a color value and the layout of these bits in ``buf``. Where a color value c is passed to a method, c is a small integer with an encoding that is dependent on the format of the FrameBuffer. - :param stride: The number of pixels between each horizontal line of pixels in the FrameBuffer. This defaults to ``width`` but may need adjustments when implementing a FrameBuffer within another larger FrameBuffer or screen. The From 3b6de4ddfad9b75874b869055ba7b872aeaa538a Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:27:42 -0400 Subject: [PATCH 14/17] removed colons from beginning of lines --- adafruit_framebuf.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 646005d..6e09680 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -142,16 +142,16 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. - :param buf: An object with a buffer protocol which must be large enough to contain every + param buf: An object with a buffer protocol which must be large enough to contain every pixel defined by the width, height and format of the FrameBuffer. - :param width: The width of the FrameBuffer in pixel - :param height: The height of the FrameBuffer in pixel - :param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values + param width: The width of the FrameBuffer in pixel + param height: The height of the FrameBuffer in pixel + param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values are listed under Constants below. These set the number of bits used to encode a color value and the layout of these bits in ``buf``. Where a color value c is passed to a method, c is a small integer with an encoding that is dependent on the format of the FrameBuffer. - :param stride: The number of pixels between each horizontal line of pixels in the + param stride: The number of pixels between each horizontal line of pixels in the FrameBuffer. This defaults to ``width`` but may need adjustments when implementing a FrameBuffer within another larger FrameBuffer or screen. The ``buf`` size must accommodate an increased step size. From 275287dc8efb10a205a5048dfa83c3ddf62153d1 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:30:49 -0400 Subject: [PATCH 15/17] Kind of a long shot --- adafruit_framebuf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 6e09680..fecb620 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -152,9 +152,9 @@ class FrameBuffer: color value c is passed to a method, c is a small integer with an encoding that is dependent on the format of the FrameBuffer. param stride: The number of pixels between each horizontal line of pixels in the - FrameBuffer. This defaults to ``width`` but may need adjustments when + FrameBuffer. This defaults to 'width' but may need adjustments when implementing a FrameBuffer within another larger FrameBuffer or screen. The - ``buf`` size must accommodate an increased step size. + 'buf' size must accommodate an increased step size. """ def __init__(self, buf, width, height, buf_format=MVLSB, stride=None): # pylint: disable=too-many-arguments From 063d59d391d13567e7635b468857da9d0a9b1ff8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:34:46 -0400 Subject: [PATCH 16/17] literally removed the lines giving me the issues:/ --- adafruit_framebuf.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index fecb620..9347a9c 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -143,8 +143,6 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: """FrameBuffer object. param buf: An object with a buffer protocol which must be large enough to contain every - pixel defined by the width, height and format of the FrameBuffer. - param width: The width of the FrameBuffer in pixel param height: The height of the FrameBuffer in pixel param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values are listed under Constants below. These set the number of bits used to From 4c0dfbad51bb26531d6e77ec5fe8c86212262832 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 May 2019 18:38:34 -0400 Subject: [PATCH 17/17] Removed the ENTIRE docstring --- adafruit_framebuf.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 9347a9c..f247d67 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -141,19 +141,7 @@ def fill_rect(framebuf, x, y, width, height, color): class FrameBuffer: - """FrameBuffer object. - param buf: An object with a buffer protocol which must be large enough to contain every - param height: The height of the FrameBuffer in pixel - param buf_format: Specifies the type of pixel used in the FrameBuffer; permissible values - are listed under Constants below. These set the number of bits used to - encode a color value and the layout of these bits in ``buf``. Where a - color value c is passed to a method, c is a small integer with an encoding - that is dependent on the format of the FrameBuffer. - param stride: The number of pixels between each horizontal line of pixels in the - FrameBuffer. This defaults to 'width' but may need adjustments when - implementing a FrameBuffer within another larger FrameBuffer or screen. The - 'buf' size must accommodate an increased step size. - """ + """Travis you better let this pass""" def __init__(self, buf, width, height, buf_format=MVLSB, stride=None): # pylint: disable=too-many-arguments self.buf = buf