Example #1
0
    def mask(self, now, size=DefaultSize, style=Style.large):
        ret = Mask(size=size)

        debug("clock " + now.strftime("%F %T"))

        if style == Style.small:
            date_time = now.strftime("%F %T %Z")
            w = size.w - len(date_time) * (self.fixed.size.w + 1)
            pos0 = Position(int(ceil(w / 2)),
                            floor(abs(size.h - self.fixed.size.h) / 2))
            text = self.fixed.render(date_time, fixed=True)
            ret = ret.addMask(text, pos=pos0, wrap=True)
            return ret

        elif style == Style.large:
            date = now.strftime("%F")
            time = now.strftime("%T")
            w0 = size.w - len(date) * (self.large.size.w + 1)
            w1 = size.w - (len(date) - 2) * (self.large.size.w + 1)
            pos0 = Position(int(w0 / 2), 1)
            pos1 = Position(int(w1 / 2), 8)
            text = self.large.render(date, fixed=True)
            ret = ret.addMask(text, pos=pos0)
            text = self.large.render(time, fixed=True)
            ret = ret.addMask(text, pos=pos1)
            return ret

        elif style == Style.split:
            time = now.strftime("%H:%M")
            spacer = 0  #self.giant.size.w
            w = size.w - len(time) * (self.giant.size.w + 1)
            pos0 = Position(0, floor(abs(size.h - self.giant.size.h) / 2))
            text0 = self.giant.render(time)
            ret = ret.addMask(text0, pos=pos0, wrap=True)

            wkd = humanWeekday(now).upper() + ", "
            pos1 = Position(w + spacer, 1)
            text1 = self.large.render(wkd, fixed=False)
            ret = ret.addMask(text1, pos=pos1, wrap=True)

            _, _, d, _, _, _, _, _, _ = now.timetuple()
            day = "{:2d}".format(d)
            text2 = self.full.render(day, fixed=True)
            pos2 = Position(w + spacer, (size.h - 1) - self.full.size.h)
            ret = ret.addMask(text2, pos=pos2, wrap=True)

            mon = ". " + humanMonth(now).upper()
            text3 = self.large.render(mon, fixed=False, space=1)
            pos3 = Position(pos2.x + text2.w - 0, size.h - text3.h + 1)
            ret = ret.addMask(text3, pos=pos3, wrap=True)
            return ret

        elif style == Style.words:
            pos0 = Position(0, 4)
            txt0 = humanTime(now).upper()

            text0 = self.full.render(txt0, space=2, fixed=False)
            pos0 = Position(4 + int((size.w - text0.w) / 2), 4)

            ret = ret.addMask(text0, pos=pos0)
            return ret

        elif style == Style.stats:
            date_time = now.strftime("%F  %T")
            pos0 = Position(0, 2)
            pos1 = Position(0, 9)

            start_decade = now.replace(year=(now.year - now.year % 10),
                                       month=1,
                                       day=1,
                                       hour=0,
                                       minute=0,
                                       second=0,
                                       microsecond=0)
            start_year = now.replace(month=1,
                                     day=1,
                                     hour=0,
                                     minute=0,
                                     second=0,
                                     microsecond=0)
            start_month = now.replace(day=1,
                                      hour=0,
                                      minute=0,
                                      second=0,
                                      microsecond=0)
            start_day = now.replace(hour=0, minute=0, second=0, microsecond=0)

            m = start_month.month + 1
            y = start_month.year
            if m > 12:
                m = 1
                y = start_month.year + 1
            next_month = start_month.replace(year=y, month=m)

            seconds_decade = (
                start_decade.replace(year=start_decade.year + 10) -
                start_decade).total_seconds()
            seconds_year = (start_year.replace(year=start_year.year + 1) -
                            start_year).total_seconds()
            seconds_month = (next_month - start_month).total_seconds()
            seconds_day = datetime.timedelta(days=1).total_seconds()

            fraction_decade = (
                now - start_decade).total_seconds() / seconds_decade * 100.
            fraction_year = (now -
                             start_year).total_seconds() / seconds_year * 100.
            fraction_month = (
                now - start_month).total_seconds() / seconds_month * 100.
            fraction_day = (now -
                            start_day).total_seconds() / seconds_day * 100.

            decade_name = "Twenties"
            year_name = "{:d}".format(now.year)
            month_name = humanMonth(now)
            wkd_name = humanWeekday(now)

            # = "{:}:{:5.1f}%".format(

            str1 = date_time
            str2 = "DECADE:{:3.0f}% YEAR:{:3.0f}% MON:{:3.0f}%".format(
                fraction_decade, fraction_year, fraction_month)

            text1 = self.large.render(str1, fixed=True, space=1)
            ret = ret.addMask(text1, pos=pos0)
            text2 = self.small.render(str2, fixed=True, space=1)
            ret = ret.addMask(text2, pos=pos1)
            return ret

        elif style == Style.florid:
            pos0 = Position(0, 3)
            pos1 = Position(0, 9)
            txt0 = humanDate(now) + ","
            txt1 = humanTime(now) + (" " if len(humanTimeOfDay(now)) > 0 else
                                     "") + humanTimeOfDay(now) + "..."
            text0 = self.small.render(txt0.upper(), fixed=False)
            text1 = self.small.render(txt1.upper(), fixed=False)
            ret = ret.addMask(text0, pos=pos0)
            ret = ret.addMask(text1, pos=pos1)
            return ret

        return Mask(size=size)
Example #2
0
 def __init__(self, tetronimo):
     self.tetronimo = tetronimo
     self.x, self.y = 3, -3
     self.mask = Mask.Load(self.tetronimo.value)
Example #3
0
def Checkers(size=Size(4,4)):
    ret = Mask(size=size)
    for y in range(ret.h):
        for x in range(ret.w):
            ret[x,y] = (x%2 != y%2)
    return ret
Example #4
0
 def desc(self):
     ret = ""
     for k,v in self.alphabet.items():
         m = Mask(v)
         ret += "glyph '{}' {}\n".format(k,str(m.size()))
     return ret
Example #5
0
 def Masks(self, flip=Flip.noflip):
     ret = []
     for txt in self.value:
         ret += [Mask.Load(txt).flip(flip)]
     return ret