From d255ebe15b6de4548bf11f6dbd2e0e810ebe84a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Sat, 29 Apr 2017 15:47:37 +0200 Subject: [PATCH] cs --- gfxlcd/demos/ili_image.py | 4 ++-- gfxlcd/demos/nju_image.py | 4 ++-- gfxlcd/demos/ssd_image.py | 4 ++-- gfxlcd/drawing/area.py | 26 +++++++++++++++++++------- gfxlcd/drawing/page.py | 9 ++++++--- gfxlcd/driver/ssd1306/__init__.py | 2 +- tox.ini | 2 +- 7 files changed, 33 insertions(+), 18 deletions(-) diff --git a/gfxlcd/demos/ili_image.py b/gfxlcd/demos/ili_image.py index 057e9d6..93afdc0 100644 --- a/gfxlcd/demos/ili_image.py +++ b/gfxlcd/demos/ili_image.py @@ -1,11 +1,11 @@ import RPi.GPIO import sys +from PIL import Image sys.path.append("../../") from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO from gfxlcd.driver.ili9325.ili9325 import ILI9325 RPi.GPIO.setmode(RPi.GPIO.BCM) -from PIL import Image lcd_tft = ILI9325(240, 320, ILIGPIO()) lcd_tft.init() @@ -20,4 +20,4 @@ lcd_tft.draw_image(0, 0, image_file) numbers_image = Image.open("assets/dsp2017_101_64.png") lcd_tft.transparency_color = (0, 0, 0) -lcd_tft.draw_image(10, 10, numbers_image) \ No newline at end of file +lcd_tft.draw_image(10, 10, numbers_image) diff --git a/gfxlcd/demos/nju_image.py b/gfxlcd/demos/nju_image.py index 08ea118..fb348aa 100644 --- a/gfxlcd/demos/nju_image.py +++ b/gfxlcd/demos/nju_image.py @@ -1,12 +1,12 @@ import RPi.GPIO import sys import random +from PIL import Image sys.path.append("../../") from gfxlcd.driver.nju6450.gpio import GPIO from gfxlcd.driver.nju6450.nju6450 import NJU6450 RPi.GPIO.setmode(RPi.GPIO.BCM) -from PIL import Image lcd_nju = NJU6450(122, 32, GPIO()) lcd_nju.init() @@ -17,4 +17,4 @@ image_file = Image.open("assets/dsp2017_122_29.png") # lcd_nju.transparency_color = [110, 57] lcd_nju.draw_image(0, 0, image_file) -lcd_nju.flush(True) \ No newline at end of file +lcd_nju.flush(True) diff --git a/gfxlcd/demos/ssd_image.py b/gfxlcd/demos/ssd_image.py index 5e83d9b..011aff0 100644 --- a/gfxlcd/demos/ssd_image.py +++ b/gfxlcd/demos/ssd_image.py @@ -1,10 +1,10 @@ import RPi.GPIO import sys +from PIL import Image sys.path.append("../../") from gfxlcd.driver.ssd1306.spi import SPI from gfxlcd.driver.ssd1306.ssd1306 import SSD1306 RPi.GPIO.setmode(RPi.GPIO.BCM) -from PIL import Image lcd_oled = SSD1306(128, 64, SPI()) lcd_oled.init() @@ -20,4 +20,4 @@ lcd_oled.threshold = 0 lcd_oled.draw_image(10, 0, image_file) -lcd_oled.flush(True) \ No newline at end of file +lcd_oled.flush(True) diff --git a/gfxlcd/drawing/area.py b/gfxlcd/drawing/area.py index f631c69..7c2daac 100644 --- a/gfxlcd/drawing/area.py +++ b/gfxlcd/drawing/area.py @@ -138,8 +138,18 @@ class Area(Pixel): temporary_area = None for red, green, blue in list(image_file.getdata()): if self._is_transparent((red, green, blue)): - area = (pos_x, pos_y + row + 1, pos_x + width - 1, pos_y + height - 1) - temporary_area = (pos_x + col + 1, pos_y + row, pos_x + width - 1, pos_y + row) + area = ( + pos_x, + pos_y + row + 1, + pos_x + width - 1, + pos_y + height - 1 + ) + temporary_area = ( + pos_x + col + 1, + pos_y + row, + pos_x + width - 1, + pos_y + row + ) else: if temporary_area is not None: self._set_area(*temporary_area) @@ -159,9 +169,11 @@ class Area(Pixel): """check if color is a transparency color""" if self.options['transparency_color'] is None: return False - elif type(self.options['transparency_color'][0]) == int and color == self.options['transparency_color']: - return True - elif type(self.options['transparency_color'][0]) == list and color in self.options['transparency_color']: - return True + elif type(self.options['transparency_color'][0]) == int \ + and color == self.options['transparency_color']: + return True + elif type(self.options['transparency_color'][0]) == list \ + and color in self.options['transparency_color']: + return True - return False \ No newline at end of file + return False diff --git a/gfxlcd/drawing/page.py b/gfxlcd/drawing/page.py index b5bf4c6..d9c899c 100644 --- a/gfxlcd/drawing/page.py +++ b/gfxlcd/drawing/page.py @@ -121,7 +121,8 @@ class Page(Pixel, metaclass=abc.ABCMeta): offset_x = 0 offset_y = 0 for stream in list(image_file.getdata()): - if stream > self.options['threshold'] and not self._is_transparent(stream): + if stream > self.options['threshold'] \ + and not self._is_transparent(stream): self.draw_pixel(pos_x + offset_x, pos_y + offset_y) offset_x += 1 if offset_x > width - 1: @@ -130,9 +131,11 @@ class Page(Pixel, metaclass=abc.ABCMeta): def _is_transparent(self, color): """check if color is a transparency color""" - if type(self.options['transparency_color']) == int and color == self.options['transparency_color']: + if type(self.options['transparency_color']) == int \ + and color == self.options['transparency_color']: return True - elif type(self.options['transparency_color']) == list and color in self.options['transparency_color']: + elif type(self.options['transparency_color']) == list \ + and color in self.options['transparency_color']: return True return False diff --git a/gfxlcd/driver/ssd1306/__init__.py b/gfxlcd/driver/ssd1306/__init__.py index 31c4620..a9428b5 100644 --- a/gfxlcd/driver/ssd1306/__init__.py +++ b/gfxlcd/driver/ssd1306/__init__.py @@ -1,2 +1,2 @@ """driver/ssd1306 module""" -__author__ = 'Bartosz Kosciow' \ No newline at end of file +__author__ = 'Bartosz Kosciow' diff --git a/tox.ini b/tox.ini index 41710dd..0ad5206 100644 --- a/tox.ini +++ b/tox.ini @@ -16,5 +16,5 @@ commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml gfxlcd/tests /bin/bash -c "pylint gfxlcd > pylint-{envname}.log || :" [flake8] show-source = True -exclude = .git,.venv,.tox,dist,doc,build,*egg,*/tests/* +exclude = .git,.venv,.tox,dist,doc,build,*egg,*/tests/*,*/demos/*