Skip to content

Commit

Permalink
QA: Examples: Apply cherry-picked Black suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Nov 20, 2023
1 parent b8635c0 commit 532e306
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/7color/advanced/dither.py
Expand Up @@ -43,7 +43,7 @@
if len(sys.argv) > 2:
saturation = float(sys.argv[2])

palette = hitherdither.palette.Palette(inky._palette_blend(saturation, dtype='uint24'))
palette = hitherdither.palette.Palette(inky._palette_blend(saturation, dtype="uint24"))

image = Image.open(sys.argv[1]).convert("RGB")
image_resized = image.resize(inky.resolution)
Expand Down
2 changes: 1 addition & 1 deletion examples/7color/buttons.py
Expand Up @@ -18,7 +18,7 @@
BUTTONS = [5, 6, 16, 24]

# These correspond to buttons A, B, C and D respectively
LABELS = ['A', 'B', 'C', 'D']
LABELS = ["A", "B", "C", "D"]

# Set up RPi.GPIO with the "BCM" numbering scheme
GPIO.setmode(GPIO.BCM)
Expand Down
36 changes: 18 additions & 18 deletions examples/7color/colour-palette.py
Expand Up @@ -9,15 +9,15 @@

parser = argparse.ArgumentParser()

parser.add_argument('--type', '-t', choices=['css', 'act', 'raw', 'pal', 'gpl'], help='Type of palette to output')
parser.add_argument('--saturation', '-s', type=float, default=0.5, help='Colour palette saturation')
parser.add_argument('--file', '-f', type=pathlib.Path, help='Output file')
parser.add_argument("--type", "-t", choices=["css", "act", "raw", "pal", "gpl"], help="Type of palette to output")
parser.add_argument("--saturation", "-s", type=float, default=0.5, help="Colour palette saturation")
parser.add_argument("--file", "-f", type=pathlib.Path, help="Output file")

args = parser.parse_args()

inky = Inky()

names = ['black', 'white', 'green', 'blue', 'red', 'yellow', 'orange']
names = ["black", "white", "green", "blue", "red", "yellow", "orange"]

if args.file is None:
print("You must specify an output palette file.")
Expand All @@ -26,41 +26,41 @@

def raw_palette():
palette = bytearray(768)
palette[0:8 * 3] = inky._palette_blend(args.saturation, dtype='uint8')
palette[0 : 8 * 3] = inky._palette_blend(args.saturation, dtype="uint8")
return palette


if args.type == 'css':
palette = inky._palette_blend(args.saturation, dtype='uint24')
with open(args.file, 'w+') as f:
if args.type == "css":
palette = inky._palette_blend(args.saturation, dtype="uint24")
with open(args.file, "w+") as f:
for i in range(7):
name = names[i]
colour = palette[i]
f.write(""".{name}_fg {{font-color:#{colour:06x}}}
.{name}_bg {{background-color:#{colour:06x}}}
""".format(name=name, colour=colour))

if args.type == 'gpl':
palette = inky._palette_blend(args.saturation, dtype='uint24')
with open(args.file, 'w+') as f:
if args.type == "gpl":
palette = inky._palette_blend(args.saturation, dtype="uint24")
with open(args.file, "w+") as f:
f.write("GIMP Palette\n")
f.write("Name: InkyImpressions\n")
f.write("Columns: 7\n")
for i in range(7):
name = names[i]
colour = palette[i]
r = (colour & 0xff0000) >> 16
g = (colour & 0x00ff00) >> 8
b = (colour & 0x0000ff)
r = (colour & 0xFF0000) >> 16
g = (colour & 0x00FF00) >> 8
b = (colour & 0x0000FF)
f.write("{r} {g} {b} Index {i} # {name}\n".format(r=r, g=g, b=b, i=i, name=name))

if args.type in ('pal', 'raw'):
if args.type in ("pal", "raw"):
palette = raw_palette()
with open(args.file, 'wb+') as f:
with open(args.file, "wb+") as f:
f.write(palette)

if args.type == 'act':
if args.type == "act":
palette = raw_palette()
palette += struct.pack(">HH", 7, 0xFFFF)
with open(args.file, 'wb+') as f:
with open(args.file, "wb+") as f:
f.write(palette)
2 changes: 1 addition & 1 deletion examples/7color/cycle.py
Expand Up @@ -5,7 +5,7 @@

inky = auto(ask_user=True, verbose=True)

colors = ['Black', 'White', 'Green', 'Blue', 'Red', 'Yellow', 'Orange']
colors = ["Black", "White", "Green", "Blue", "Red", "Yellow", "Orange"]

for color in range(7):
print("Color: {}".format(colors[color]))
Expand Down
2 changes: 1 addition & 1 deletion examples/clean.py
Expand Up @@ -19,7 +19,7 @@

# Command line arguments to determine number of cycles to run
parser = argparse.ArgumentParser()
parser.add_argument('--number', '-n', type=int, required=False, help="number of cycles")
parser.add_argument("--number", "-n", type=int, required=False, help="number of cycles")
args, _ = parser.parse_known_args()

# The number of red / black / white refreshes to run
Expand Down
10 changes: 5 additions & 5 deletions examples/logo.py
Expand Up @@ -30,24 +30,24 @@

if inky_display.resolution in ((212, 104), (250, 122)):
if inky_display.resolution == (250, 122):
if inky_display.colour == 'black':
if inky_display.colour == "black":
img = Image.open(os.path.join(PATH, "phat/resources/InkypHAT-250x122-bw.png"))
else:
img = Image.open(os.path.join(PATH, "phat/resources/InkypHAT-250x122.png"))

else:
if inky_display.colour == 'black':
if inky_display.colour == "black":
img = Image.open(os.path.join(PATH, "phat/resources/InkypHAT-212x104-bw.png"))
else:
img = Image.open(os.path.join(PATH, "phat/resources/InkypHAT-212x104.png"))

elif inky_display.resolution in ((400, 300), ):
if inky_display.colour == 'black':
elif inky_display.resolution in ((400, 300),):
if inky_display.colour == "black":
img = Image.open(os.path.join(PATH, "what/resources/InkywHAT-400x300-bw.png"))
else:
img = Image.open(os.path.join(PATH, "what/resources/InkywHAT-400x300.png"))

elif inky_display.resolution in ((600, 448), ):
elif inky_display.resolution in ((600, 448),):
img = Image.open(os.path.join(PATH, "what/resources/InkywHAT-400x300.png"))
img = img.resize(inky_display.resolution)

Expand Down
2 changes: 1 addition & 1 deletion examples/name-badge.py
Expand Up @@ -24,7 +24,7 @@ def getsize(font, text):
raise TypeError("You need to update the Inky library to >= v1.1.0")

parser = argparse.ArgumentParser()
parser.add_argument('--name', '-n', type=str, required=True, help="Your name")
parser.add_argument("--name", "-n", type=str, required=True, help="Your name")
args, _ = parser.parse_known_args()

# inky_display.set_rotation(180)
Expand Down
2 changes: 1 addition & 1 deletion examples/phat/calendar-phat.py
Expand Up @@ -160,7 +160,7 @@ def print_number(position, number, colour):
crop_x = 2 + (16 * x)

# Crop the relevant day name from our text image
crop_region = ((crop_x, 0, crop_x + 16, 9))
crop_region = (crop_x, 0, crop_x + 16, 9)
day_mask = text_mask.crop(crop_region)
img.paste(inky_display.WHITE, (o_x + 4, cal_y + 2), day_mask)

Expand Down
14 changes: 7 additions & 7 deletions examples/tests/border.py
Expand Up @@ -11,14 +11,14 @@
if len(sys.argv) > 1:
INKY_COLOUR = sys.argv[1]

if INKY_COLOUR not in ['red', 'yellow', 'black']:
if INKY_COLOUR not in ["red", "yellow", "black"]:
print("Usage: {} <red, yellow, black>".format(sys.argv[0]))
sys.exit(1)

phat = InkyPHAT(INKY_COLOUR)

white = Image.new('P', (212, 104), phat.WHITE)
black = Image.new('P', (212, 104), phat.BLACK)
white = Image.new("P", (212, 104), phat.WHITE)
black = Image.new("P", (212, 104), phat.BLACK)

while True:
print("White")
Expand All @@ -27,14 +27,14 @@
phat.show()
time.sleep(1)

if INKY_COLOUR == 'red':
if INKY_COLOUR == "red":
print("Red")
phat.set_border(phat.RED)
phat.set_image(white)
phat.show()
time.sleep(1)

if INKY_COLOUR == 'yellow':
if INKY_COLOUR == "yellow":
print("Yellow")
phat.set_border(phat.YELLOW)
phat.set_image(white)
Expand All @@ -47,14 +47,14 @@
phat.show()
time.sleep(1)

if INKY_COLOUR == 'red':
if INKY_COLOUR == "red":
print("Red")
phat.set_border(phat.RED)
phat.set_image(white)
phat.show()
time.sleep(1)

if INKY_COLOUR == 'yellow':
if INKY_COLOUR == "yellow":
print("Yellow")
phat.set_border(phat.YELLOW)
phat.set_image(white)
Expand Down
2 changes: 1 addition & 1 deletion examples/what/dither-image-what.py
Expand Up @@ -19,7 +19,7 @@
# Grab the image argument from the command line

parser = argparse.ArgumentParser()
parser.add_argument('--image', '-i', type=str, required=True, help="Input image to be converted/displayed")
parser.add_argument("--image", "-i", type=str, required=True, help="Input image to be converted/displayed")
args, _ = parser.parse_known_args()

img_file = args.image
Expand Down
2 changes: 1 addition & 1 deletion examples/what/quotes-what.py
Expand Up @@ -96,7 +96,7 @@ def reflow_quote(quote, width, font):
"Niels Bohr",
"Nikola Tesla",
"Rosalind Franklin",
"Stephen Hawking"
"Stephen Hawking",
]

# The amount of padding around the quote. Note that
Expand Down

0 comments on commit 532e306

Please sign in to comment.