trivial: whitespace and old leftover code cleanup

This commit is contained in:
Erik Stambaugh 2024-03-28 20:19:12 -07:00
parent e39656686e
commit a41cc89958

View file

@ -23,18 +23,11 @@ class Inkybot:
]
font_size = 60
picpath = '/srv/inkybot/pictures'
saturation = 0.7
exiting = False
skip_img = False
BUTTONS = [5,6,16,24]
LABELS = ['A', 'B', 'C', 'D']
BUTTON_LABELS = ['A', 'B', 'C', 'D']
inky = Inky()
state = None
states = {}
@ -49,7 +42,7 @@ class Inkybot:
def color_similarity(self, color1, color2):
return np.sqrt(np.sum((np.array(color1) - np.array(color2)) ** 2))
def least_similar_color(self, color, palette):
def least_similar_color(self, color):
return max(self.palette, key=lambda ref_color: self.color_similarity(ref_color, color))
def average_outer_perimeter_color(self,image):
@ -114,7 +107,7 @@ class Inkybot:
def handle_button(self,pin):
label = self.LABELS[self.BUTTONS.index(pin)]
label = self.BUTTON_LABELS[self.BUTTONS.index(pin)]
if label == 'A':
self.state.button_a()
@ -142,7 +135,6 @@ class Inkybot:
self.parent = parent
# enter and exit functions can be overridden by the child class
def enter(self):
pass
def exit(self):
@ -169,18 +161,15 @@ class Inkybot:
draw = ImageDraw.Draw(image)
# text colors use the nearest undithered color to what's in the letterbox
color_border = self.parent.least_similar_color(
self.parent.average_outer_perimeter_color(image),
self.parent.palette)
color = self.parent.least_similar_color(
color_border,
self.parent.palette)
color_border = self.parent.least_similar_color(self.parent.average_outer_perimeter_color(image))
color = self.parent.least_similar_color(color_border)
for i in range(4):
txt = self.button_text[i]
x,y = self.button_positions[i]
text_width, text_height = draw.textsize(txt, font=self.parent.font)
dy = int(text_height / 2)
for xx in range(x - 1, x + 2, 1):
for yy in range(y - 1 - dy, y + 2 - dy, 1):
draw.text((xx,yy), txt, fill=color_border, font=self.parent.font)
@ -207,7 +196,7 @@ class Inkybot:
self.state = self.states[state]
self.state.enter()
while self.exiting is not True:
while True:
self.state.loop()
time.sleep(0.1)
@ -284,8 +273,6 @@ class HassMode(inkybot.StateClass):
image = Image.new("RGB", self.parent.inky.resolution, (255,0,0))
self.set_image(image)
if __name__ == "__main__":
inkybot.start('picture')