Exemplo n.º 1
0
    def draw(self, ui, d):
        weather = ui.forecast.weather
        bitmap = ui.bitmap(1, weather.icon)
        ui.canvas.bitmap(Vect(5, 0), bitmap)

        if weather.rain > 0:
            ui.text(10, '{:.1f} mm/h'.format(weather.rain),
                    Vect(2, self.dim.y - 14), BLACK, WHITE)
Exemplo n.º 2
0
    def draw(self, ui, d):
        ui.canvas.hline(Vect(10, 0), ui.canvas.dim.x - 20)
        ui.connection.ifconfig
        ui.text(10, 'Confugurator URL:', Vect(15, 50))
        ui.text(10, self.url, Vect(45, 65))

        ui.text(10, 'VBAT {:.2f} V'.format(battery.voltage),
                Vect(0, self.dim.y - 10))
Exemplo n.º 3
0
        def drawWindSpeed(w, c):
            ui.canvas.line(Vect(int(d.real), int(d.imag)),
                           Vect(int(d1.real), int(d1.imag)), c, w)

            for i in range(int(weather.speed / 2.5)):
                rr = r - rescale(7) * (i // 2) - rescale(5)
                l = rescale(15 + 10 * (i % 2))
                b = rect(rr, (weather.dir - 90) * pi / 180) + o
                e = rect(l, (weather.dir - 30) * pi / 180) + b
                ui.canvas.line(Vect(int(b.real), int(b.imag)),
                               Vect(int(e.real), int(e.imag)), c, w)
Exemplo n.º 4
0
    def draw(self, ui, d):
        t = ui.forecast.weather.temp

        if t >= temp.outdoor_high:
            hl = YELLOW
        else:
            hl = None

        ui.text(50, '{:.1f}'.format(t), Vect(21, -5), BLACK, hl, 3)

        bitmap = ui.bitmap(1, 'out')
        ui.canvas.bitmap(Vect(0, 30), bitmap)
Exemplo n.º 5
0
    def draw(self, ui, d):
        t = ui.forecast.home.temp
        hl = None

        if not None == t:
            if t >= temp.indoor_high:
                hl = YELLOW

            t = '{:.1f}'.format(t)
        else:
            t = '--'

        ui.text(50, t, Vect(21, -5), BLACK, hl, 3)

        bitmap = ui.bitmap(1, 'in')
        ui.canvas.bitmap(Vect(0, 30), bitmap)
Exemplo n.º 6
0
    def draw(self, ui, d):
        forecast = ui.forecast.forecast
        cnt = len(forecast)

        for i in reversed(range(cnt)):
            x = ui.canvas.dim.x * i // (cnt + 1) + 5
            y = (i % 2) * -7 + 10
            drawWind(ui, Vect(x, y), forecast[i], 4, True)
Exemplo n.º 7
0
 def draw(self, ui, d):
     from uqr import QRCode
     qr = QRCode()
     qr.add_data(self.txt)
     matrix = qr.get_matrix()
     
     for y in range(matrix[1]):
         for x in range(matrix[1]):
             ui.canvas.fill_rect(Vect(x * 3, y * 3),
                                 Vect(    3,     3),
                                 BLACK if matrix[0].pixel(x, y) else WHITE)
     
     l = matrix[1] * 3
     if self.above:
         ui.text_center(10, self.lbl, Vect(l // 2, -12))
     else:
         ui.text_center(10, self.lbl, Vect(l // 2, l))
Exemplo n.º 8
0
    def draw(self, ui, d):
        # Pre-calculates some range values and draw icons bar
        forecast = ui.forecast.forecast
        cnt = len(forecast)
        block = ui.canvas.dim.x / cnt
        temp_max = -273.0
        temp_min = 273.0

        for i in range(cnt):
            x1 = ui.canvas.dim.x * i // (cnt + 1)
            weather = forecast[i]
            temp_max = max(weather.temp, weather.feel, temp_max)
            temp_min = min(weather.temp, weather.feel, temp_min)

        chart_space = const(30)
        chart_min = const(chart_space // 2)
        chart_max = self.dim.y - chart_space
        k_temp = (chart_max - chart_min) / (temp_max - temp_min)

        # Get chart position according to temperature
        def chart_y(temp):
            return int(chart_max - (temp - temp_min) * k_temp)

        for i in range(cnt):
            cmax = cnt - 1
            x1 = int(block * i)

            # Calculate and type peaks
            if (i > 0) and (i < cmax):
                # Draw temperature text
                f = (forecast[i - 1], forecast[i], forecast[i + 1])

                if (f[0].temp < f[1].temp) and (f[1].temp > f[2].temp):
                    ui.text_center(16, '{:.0f}°C'.format(f[1].temp),
                                   Vect(x1,
                                        chart_y(f[1].temp) - 20), BLACK, WHITE)

                if (f[0].temp > f[1].temp) and (f[1].temp < f[2].temp):
                    ui.text_center(16, '{:.0f}°C'.format(f[1].temp),
                                   Vect(x1,
                                        chart_y(f[1].temp) + 4), BLACK, WHITE)
Exemplo n.º 9
0
    def chart_draw(self, ui, w, c, th=None, tl=None):
        forecast = ui.forecast.forecast
        cnt = len(forecast)

        for i1 in range(cnt):
            if i1 > 0:
                x1 = int(self.block * i1)
                x2 = int(x1 - self.block)
                i2 = i1 - 1
                f1 = forecast[i1].feel
                f2 = forecast[i2].feel

                if (th is None):
                    v1 = Vect(x1, self.chart_y(f1))
                    v2 = Vect(x2, self.chart_y(f2))
                    ui.canvas.line(v1, v2, c, w)

                if (th is None) or (f1 > th) or (f2 > th) or (f1 < tl) or (f2 <
                                                                           tl):
                    v1 = Vect(x1, self.chart_y(forecast[i1].temp))
                    v2 = Vect(x2, self.chart_y(forecast[i2].temp))
                    ui.canvas.line(v1, v2, c, w * 2)
Exemplo n.º 10
0
 def draw(self, ui, d):
     # Pre-calculates some range values and draw icons bar
     forecast = ui.forecast.forecast
     cnt      = len(forecast)
     cmax     = cnt - 1
     block    = ui.canvas.dim.x / cnt
     
     ui.canvas.hline(Vect(0, self.dim.y - 1), self.dim.x - 1, BLACK)
     
     for i in range(cnt):
         xx      = int(block * i)
         weather = forecast[i]
         dt      = ui.forecast.time.get_date_time(weather.dt)
         
         # Draw rain chart
         p = max(weather.rain, weather.snow)
         
         if weather.rain > 0 or weather.snow > 0:
             r = int(p * 12)
             _ = self.dim.y // 4
             for h in (_, _ * 2, _ * 3):
                 if r > h:
                     r = h + (r - h) // 2
             v = Vect(xx - int(block // 2) + 1, self.dim.y - r - 1)
             d = Vect(int(block) - 2, r)
             
             if weather.rain > 0:
                 ui.canvas.trect(v, d, BLACK)
             else:
                 ui.canvas.fill_rect(v, d, YELLOW)
             ui.canvas.rect( v, d, BLACK)
         
         # Type rain text
         if (i > 0) and (i < cmax):
             f0 = forecast[i - 1]
             f1 = forecast[i + 1]
             if (max(f0.rain, f0.snow) < p) and (p > max(f1.rain, f1.snow)): 
                 ui.text_center(10, '%.1f' % p, Vect(xx, self.dim.y - 2), BLACK, WHITE)
Exemplo n.º 11
0
    def drawArrow(r, c, w):
        if weather.speed < 5:
            r = r * 2 // 3
        elif weather.speed > 7:
            w += 1

        d1 = d2 + rect(r * 2, (weather.dir - 75) * pi / 180)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(d2.real), int(d2.imag)), c, w)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(o.real), int(o.imag)), c, w)

        d1 = d2 + rect(r * 2, (weather.dir - 105) * pi / 180)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(d2.real), int(d2.imag)), c, w)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(o.real), int(o.imag)), c, w)
Exemplo n.º 12
0
 def draw(self, ui, d):
     # Pre-calculates some range values and draw icons bar
     rows_cnt = const(2)
     forecast = ui.forecast.forecast
     cnt      = len(forecast)
     h_icons  = self.dim.y // rows_cnt
     icon     = {}
     
     for i in range(cnt):
         xx = ui.canvas.dim.x * i // (cnt + 1)
         id = forecast[i].icon
         
         try:
             bitmap = icon[id]
         except KeyError:
             bitmap   = ui.bitmap(5, id)
             icon[id] = bitmap
         
         ui.canvas.bitmap(Vect(xx, i % rows_cnt * h_icons), bitmap)
Exemplo n.º 13
0
 def draw(self, ui, d):
     # Draw wind
     weather = ui.forecast.weather
     drawWind(ui, Vect(260, 35), weather)
     
     # Type celsius symbol
     ui.text(50, '°C', Vect(111, -5))
     
     # Type humidity
     t = '{:.0f}'.format(weather.rh)
     ui.text(25, t, Vect(175, 18))
     l = ui.textLength(25, t) + 6
     ui.text(10, '%',  Vect(175 + l, 31))
     
     # Type wind speed
     ui.text(25, '{:.1f}'.format(weather.speed), Vect(175, -5))
     ui.text(10, 'm/s', Vect(175 + l, 8))
     
     return l
Exemplo n.º 14
0
    def draw(self, ui, args):
        tab, connection = args

        # Type celsius symbol
        ui.text(50, '°C', Vect(111, -5))

        # Type humidity
        if None == ui.forecast.home.rh:
            t = '--'
        else:
            t = '{:.0f}'.format(ui.forecast.home.rh)

        ui.text(25, t, Vect(175, 0))
        ui.text(10, '%', Vect(175 + tab, 11))

        # Type weather details
        ui.text_right(10, ui.forecast.descr, Vect(self.dim.x, 15))
        ui.text_right(10, location[connection.config.location].name,
                      Vect(self.dim.x, 35))
        dt = ui.forecast.time.get_date_time(ui.forecast.weather.dt)
        ui.text_right(
            10, '{:d}.{:d}.{:d} {:d}:{:02d}'.format(dt[2], dt[1], dt[0],
                                                    dt[3], dt[4]),
            Vect(self.dim.x, 25))
Exemplo n.º 15
0
 def draw(self, ui, volt):
     from config import vbat
     
     w = self.dim.x
     h = self.dim.y
     p = min(max((volt - vbat.low_voltage) / (4.2 - vbat.low_voltage), 0), 1)
     l = int(p * w)
     
     if p < 0.2:
         ui.canvas.fill_rect(Vect(-6, -13), Vect(w + 16, h + 18), YELLOW)
     else:
         ui.canvas.fill_rect(Vect(-4, -11), Vect(w + 9, h + 14), WHITE)
     
     ui.canvas.rect(Vect(0, 0), Vect(w + 3, h))
     ui.canvas.fill_rect(Vect(-3, h // 2 - 2), Vect(3, 5))
     ui.canvas.fill_rect(Vect(1 + w - l, 2), Vect(l, h - 4))
     
     if vbat.show_voltage:
         ui.text_center(10, '{:.2}V'.format(volt), Vect(w // 2 + 2, -12))
     else:
         ui.text_center(10, '{:.0%}'.format(p), Vect(w // 2 + 2, -12))
     
     if (volt < vbat.low_voltage):
         ui.canvas.line(Vect(0,0), self.dim, YELLOW, w = 6)
         ui.canvas.line(Vect(0,0), self.dim, BLACK,  w = 2)
Exemplo n.º 16
0
    def draw(self, ui, title):
        if title:
            from lang import day_of_week

        forecast = ui.forecast.forecast
        cnt = len(forecast)
        block = ui.canvas.dim.x / cnt
        h_space = const(4)

        if cfg.variant == VARIANT_2DAYS:
            hpi = 1
            dblock = int(block * 24)
        else:
            hpi = 3
            dblock = int(block * 8)

        # Draw upper horizontal lines
        if title:
            ui.canvas.hline(Vect(0, 0), self.dim.x - 1, BLACK)

        # Find time raleted to next day
        week_day = ui.forecast.time.get_date_time(forecast[0].dt)[6]

        for i in forecast:
            dt = ui.forecast.time.get_date_time(i.dt)
            if not week_day == dt[6]:
                dh = dt[3]
                break

        # Draw all items related to forecast
        for i in range(cnt):
            xx = int(block * i)
            weather = forecast[i]
            dt = ui.forecast.time.get_date_time(weather.dt)
            hour = dt[3] - dh

            # Draw separators
            if title and ((dt[6] == 5) or (dt[6] == 6)):
                if 0 == i:
                    ui.canvas.trect(
                        Vect(int(xx - dt[3] // hpi * hpi * block / hpi), 1),
                        Vect(dblock, 4), BLACK)
                if 0 == hour:
                    ui.canvas.trect(Vect(xx, 1), Vect(dblock, 4), BLACK)

            if 0 == hour:
                if (dt[6] == 5) or (dt[6] == 0):
                    ui.canvas.vline(Vect(xx + 1, 0), self.dim.y - 10 + h_space,
                                    BLACK)

                ui.canvas.vline(Vect(xx, 0), self.dim.y - 10 + h_space, BLACK)

            if title:
                # Draw hours text
                if hour % 6 == 0:
                    ui.text_center(10, str(hour),
                                   Vect(xx, self.dim.y // 2 + h_space + 6))

                # Draw day of week text
                if (hour + 12) % 24 == 0:
                    ui.text_center(16, day_of_week[dt[6]], Vect(xx, h_space))
Exemplo n.º 17
0
 def draw(self, ui, d):
     ui.text(10, 'SSID:', Vect(0, 5))
     ui.text(10, self.hotspot.ssid, Vect(30, 20))
     ui.text(10, 'Password:', Vect(0, 35))
     ui.text(10, self.hotspot.passwd, Vect(30, 50))
Exemplo n.º 18
0
def drawWind(ui, pos, weather, scale=16, arrow=False):
    def rescale(v):
        return v * scale // 16

    if weather.speed < 2.5:
        ui.canvas.fill_rect(
            Vect(rescale(-2), rescale(-2)) + pos, Vect(rescale(4), rescale(4)),
            BLACK)
        return

    from cmath import rect, pi
    r = rescale(30)
    o = pos.x + pos.y * 1j
    d = rect(r, (weather.dir - 90) * pi / 180)

    d2 = o - d

    def drawArrow(r, c, w):
        if weather.speed < 5:
            r = r * 2 // 3
        elif weather.speed > 7:
            w += 1

        d1 = d2 + rect(r * 2, (weather.dir - 75) * pi / 180)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(d2.real), int(d2.imag)), c, w)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(o.real), int(o.imag)), c, w)

        d1 = d2 + rect(r * 2, (weather.dir - 105) * pi / 180)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(d2.real), int(d2.imag)), c, w)
        ui.canvas.line(Vect(int(d1.real), int(d1.imag)),
                       Vect(int(o.real), int(o.imag)), c, w)

    if weather.speed > 10:
        c = YELLOW
    else:
        c = WHITE

    if weather.speed > 16:
        w = 6
    else:
        w = 3

    drawArrow(r, c, w)
    drawArrow(r, BLACK, 1)

    if not arrow:
        d1 = o - 0.4 * d
        d = o + d

        def drawWindSpeed(w, c):
            ui.canvas.line(Vect(int(d.real), int(d.imag)),
                           Vect(int(d1.real), int(d1.imag)), c, w)

            for i in range(int(weather.speed / 2.5)):
                rr = r - rescale(7) * (i // 2) - rescale(5)
                l = rescale(15 + 10 * (i % 2))
                b = rect(rr, (weather.dir - 90) * pi / 180) + o
                e = rect(l, (weather.dir - 30) * pi / 180) + b
                ui.canvas.line(Vect(int(b.real), int(b.imag)),
                               Vect(int(e.real), int(e.imag)), c, w)

        w = rescale(2) + 1
        drawWindSpeed(w + 1, WHITE)
        drawWindSpeed(w, BLACK)