Implemented RGB color in design

This commit is contained in:
Maximilian Giller 2019-02-28 22:19:33 +01:00
parent 6af80788e8
commit b28341ada5
5 changed files with 17 additions and 24 deletions

View file

@ -8,16 +8,16 @@ path = ''
wpath = path+'weather-icons/'
opath = path+'other/'
weekday = im_open(opath+'weekday.bmp').convert('L')
eventicon = im_open(opath+'event.bmp').convert('L')
dateicon = im_open(opath+'today.bmp').convert('L')
weekday = im_open(opath+'weekday.bmp').convert('RGB')
eventicon = im_open(opath+'event.bmp').convert('RGB')
dateicon = im_open(opath+'today.bmp').convert('RGB')
tempicon = im_open(opath+'temperature.jpeg')
humicon = im_open(opath+'humidity.jpeg')
seperator = im_open(opath+'seperator.jpeg').convert('L')
seperator = im_open(opath+'seperator.jpeg').convert('RGB')
no_response= im_open(opath+'cloud-no-response.jpeg')
sunriseicon = im_open(opath+'wi-sunrise.jpeg')
sunseticon = im_open(opath+'wi-sunset.jpeg')
windicon = im_open(opath+'wi-strong-wind.jpeg')#
windicon = im_open(opath+'wi-strong-wind.jpeg')
datetime_locals = {
"de" : "de_DE.UTF-8",

View file

@ -4,13 +4,12 @@ from PIL import ImageDraw, ImageOps
class BoxDesign (DesignEntity):
"""Redefinition of ImageDraw.Draw.Rectangle"""
def __init__(self, size, fill=None, outline=None, width=0):
super(BoxDesign, self).__init__((size[0]+1, size[1]+1))
super(BoxDesign, self).__init__((size[0]+1, size[1]+1), mask=True)
self.size = size
self.__define_corners__()
self.fill = fill
self.outline = outline
self.width = width
self.is_bitmap = True
def __define_corners__(self):
topleft = (0,0)
@ -22,7 +21,6 @@ class BoxDesign (DesignEntity):
def __finish_image__ (self):
for i in range(self.width):
ImageDraw.Draw(self.__image__).polygon(self.__get_reduced_corners__(i), fill=self.fill, outline=self.outline)
self.__image__ = ImageOps.invert(self.__image__)
def __get_reduced_corners__(self, reducer):
topleft = (reducer, reducer)

View file

@ -3,30 +3,27 @@ from PIL import Image, ImageOps, ImageDraw
class DesignEntity (object):
"""General entity that can be drawn on to a panel design or
other design entities."""
def __init__ (self, size):
def __init__ (self, size, mask=False):
self.size = size
self.pos = (0, 0)
self.mask = mask
self.__init_image__()
self.is_bitmap = False
def __init_image__ (self, color = 'white'):
self.__image__ = Image.new('L', self.size, color=color)
self.__image__ = Image.new('RGB', self.size, color=color)
def get_image (self):
self.__finish_image__()
return self.__image__
def draw (self, subimage, pos):
self.__image__.paste(subimage, pos)
def draw_bitmap (self, subimage, pos):
ImageDraw.Draw(self.__image__).bitmap(pos, subimage)
def draw (self, subimage, pos, mask=False):
img_mask = None
if mask:
img_mask = ImageOps.invert(subimage.convert('L'))
self.__image__.paste(subimage, pos, mask=img_mask)
def draw_design (self, entity):
if entity.is_bitmap:
self.draw_bitmap(entity.get_image(), entity.pos)
else:
self.draw(entity.get_image(), entity.pos)
self.draw(entity.get_image(), entity.pos, entity.mask)
def draw_image (self, path, pos):
self.draw(Image.open(path), pos)

View file

@ -109,7 +109,7 @@ class MonthOvPanel (PanelDesign):
def __get_today_box_pos__ (self):
x, y = self.__get_day_pos__(int(datetime.now().day / 7), datetime.now().weekday())
return (x, y + (self.__abs_pos__(daynumberboxsize)[1] - self.__abs_pos__(dayhighlightboxsize)[1]) / 2)
return (x, int(y + (self.__abs_pos__(daynumberboxsize)[1] - self.__abs_pos__(dayhighlightboxsize)[1]) / 2))
def __draw_highlight_box__ (self, size, pos, color='black', width=1):
design = BoxDesign(size, outline=color, width = width)

View file

@ -8,20 +8,18 @@ class TextDesign (DesignEntity):
"""Object that manages all information relevant to text
and prints it to an image"""
def __init__ (self, size, font = "Assistant-Regular.ttf", fontsize = 12, text = "", horizontalalignment = "left", verticalalignment = "top"):
super(TextDesign, self).__init__(size)
super(TextDesign, self).__init__(size, mask = True)
self.font_family = font
self.font_size = fontsize
self.text = text
self.horizontal_alignment = horizontalalignment
self.vertical_alignment = verticalalignment
self.is_bitmap = True
def __finish_image__ (self):
self.__init_image__()
self.__font__ = ImageFont.truetype(path + self.font_family, self.font_size)
pos = self.__pos_from_alignment__()
ImageDraw.Draw(self.__image__).text(pos, self.text, fill=0, font=self.__font__)
self.__image__ = ImageOps.invert(self.__image__)
def __pos_from_alignment__ (self):
width, height = self.__font__.getsize(self.text)