Exemplo n.º 1
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        time_str = data['time'].strftime(self._time_format)
        date_str = data['time'].strftime(self._date_format)

        bg1 = (0, 0)
        bg2 = (self._buf.width, self._buf.height)

        textx = self._buf.width / 2
        timey = self._buf.height / 2
        datey = self._buf.height / 2 + self._buf.height / 8

        draw.rectangle((bg1, bg2), fill=self._bgcolor)
        draw.ctext((textx, timey),
                   time_str,
                   font=self._timefont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_BOTH)
        draw.ctext((textx, datey),
                   date_str,
                   font=self._datefont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_BOTH)

        self.changed()
Exemplo n.º 2
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        width, height = self._buf.size

        # Calculations
        centerw = width / 2
        centerh = height / 2

        # Fill background
        bg1 = (0, 0)
        bg2 = (width, height)
        draw.rectangle((bg1, bg2), fill=self._bgcolor)

        # Text
        draw.ctext((centerw, 0),
                   'Currently',
                   font=self._titlefont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((centerw, centerh),
                   unicode(int(data.today['temp'])) + DEGREE_SIGN,
                   font=self._tempfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_BOTH)

        self.changed()
Exemplo n.º 3
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        width, height = self._buf.size

        # Calculations
        centerw = width / 2
        third = height / 3
        highh = third - (third / 2)
        lowh = third * 2 - (third / 2)

        # Strings
        forecast = data.day(self._day)
        high = unicode(int(forecast['high'])) + DEGREE_SIGN
        low = unicode(int(forecast['low'])) + DEGREE_SIGN

        if self._day == 0:
            title = 'Today'
        elif self._day == 1:
            title = 'Tomorrow'
        else:
            title = forecast['date'].strftime('%A')

        # Fill background
        bg1 = (0, 0)
        bg2 = (width, height)
        draw.rectangle((bg1, bg2), fill=self._bgcolor)

        # Title
        draw.ctext((centerw, 0),
                   title,
                   font=self._titlefont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)

        # Today
        draw.ctext((centerw, highh),
                   high,
                   font=self._tempfont,
                   fill=self._highcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((centerw, lowh),
                   low,
                   font=self._tempfont,
                   fill=self._lowcolor,
                   center=graphics.CENTER_HORIZ)

        self.changed()
Exemplo n.º 4
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        year = data['time'].strftime('%Y')

        bg1 = (0, 0)
        bg2 = (self._buf.width, self._buf.height)

        textx = self._buf.width / 2
        texty = self._buf.height / 2

        draw.rectangle((bg1, bg2), fill=self._bgcolor)
        draw.ctext((textx, texty),
                   year,
                   font=self._font,
                   fill=self._fgcolor,
                   center=graphics.CENTER_BOTH)

        self.changed()
Exemplo n.º 5
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        hours = data['time'].strftime('%-I')
        minutes = data['time'].strftime('%M')

        bg1 = (0, 0)
        bg2 = (self._buf.width, self._buf.height)

        textx = self._buf.width / 2

        draw.rectangle((bg1, bg2), fill=self._bgcolor)
        draw.ctext((textx, 0),
                   hours,
                   font=self._font,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((textx, self._buf.height / 2),
                   minutes,
                   font=self._font,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)

        self.changed()
Exemplo n.º 6
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        # Text
        dayname = data['time'].strftime('%A')
        day = data['time'].strftime('%-d')
        monthname = data['time'].strftime('%B')

        # Calculations
        bg1 = (0, 0)
        bg2 = (self._buf.width, self._buf.height)

        textx = self._buf.width / 2
        daynamey = self._buf.height / 8
        dayy = self._buf.height / 2
        monthnamey = self._buf.height - (self._buf.height / 4)

        # Drawing
        draw.rectangle((bg1, bg2), fill=self._bgcolor)
        draw.ctext((textx, daynamey),
                   dayname,
                   font=self._wordfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((textx, dayy),
                   day,
                   font=self._numfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_BOTH)
        draw.ctext((textx, monthnamey),
                   monthname,
                   font=self._wordfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)

        self.changed()
Exemplo n.º 7
0
    def draw(self, data):
        draw = graphics.TheoriaDraw(self._buf)

        width, height = self._buf.size

        # Calculations
        centerw = width / 2
        loww = centerw - centerw / 2
        highw = centerw + centerw / 2

        # Fill background
        bg1 = (0, 0)
        bg2 = (width, height)
        draw.rectangle((bg1, bg2), fill=self._bgcolor)

        # Title
        draw.ctext((centerw, 0),
                   data.title,
                   font=self._titlefont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)

        # Today
        draw.ctext((centerw, 40),
                   'Today',
                   font=self._headerfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((loww, 140),
                   str(int(data.today['low'])),
                   font=self._tempfont,
                   fill=self._lowcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((centerw, 140),
                   str(int(data.today['temp'])),
                   font=self._tempfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((highw, 140),
                   str(int(data.today['high'])),
                   font=self._tempfont,
                   fill=self._highcolor,
                   center=graphics.CENTER_HORIZ)

        # Tomorrow
        draw.ctext((centerw, 280),
                   'Today',
                   font=self._headerfont,
                   fill=self._fgcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((loww, 360),
                   str(int(data.tomorrow['low'])),
                   font=self._tempfont,
                   fill=self._lowcolor,
                   center=graphics.CENTER_HORIZ)
        draw.ctext((highw, 360),
                   str(int(data.tomorrow['high'])),
                   font=self._tempfont,
                   fill=self._highcolor,
                   center=graphics.CENTER_HORIZ)

        self.changed()
Exemplo n.º 8
0
    def draw(self, data):
        one_gb = 1024 * 1024 * 1024

        # Gather data
        anytime = []
        uploads = []
        freezone = []
        dates = []
        for entry in data['usage']['data']:
            dates.append(datetime.strptime(str(entry['period']), '%Y%m%d'))
            for t in entry['types']:
                if t['type'] == 'anytime':
                    anytime.append(t['value'])
                elif t['type'] == 'uploads':
                    uploads.append(t['value'])
                elif t['type'] == 'freezone':
                    freezone.append(t['value'])

        # Draw the chart
        draw = graphics.TheoriaDraw(self._buf)
        width, height = self._buf.size

        ind = np.arange(len(dates))  # the x locations for the groups
        bar_width = 0.8

        fig, ax = plt.subplots()

        # Set size
        dpi = 70.0
        fig.set_size_inches(width / dpi, height / dpi)
        fig.set_dpi(dpi)

        # Load data
        anytime = np.array(anytime)
        uploads = np.array(uploads)
        freezone = np.array(freezone)

        p1 = plt.bar(dates, anytime, bar_width, color='r')
        p2 = plt.bar(dates, freezone, bar_width, color='g', bottom=anytime)
        p3 = plt.bar(dates,
                     uploads,
                     bar_width,
                     color='b',
                     bottom=anytime + freezone)

        # Legend
        plt.legend((p1[0], p2[0], p3[0]), ('Downloads', 'Freezone', 'Uploads'))

        # Chart Labels
        plt.ylabel('Gigabytes')
        plt.title('Download Usage')

        # X Labels
        somedays = mdates.DayLocator(interval=int(1024 / width))
        days = mdates.DayLocator()
        daysFmt = mdates.DateFormatter('%-d %b')
        ax.xaxis.set_major_locator(somedays)
        ax.xaxis.set_minor_locator(days)
        ax.xaxis.set_major_formatter(daysFmt)

        # Y Labels
        gb = ticker.IndexLocator(one_gb, 0)
        fivegb = ticker.IndexLocator(one_gb * 5, 0)
        gbFmt = ticker.FuncFormatter(lambda x, p: str(int(x / one_gb)) + ' GB')
        ax.yaxis.set_major_locator(fivegb)
        ax.yaxis.set_minor_locator(gb)
        ax.yaxis.set_major_formatter(gbFmt)

        # Auto format the dates
        fig.autofmt_xdate()
        canvas = plt.get_current_fig_manager().canvas
        canvas.draw()

        # Add Graph
        plot_img = Image.fromstring('RGB', canvas.get_width_height(),
                                    canvas.tostring_rgb())
        draw.cpaste(plot_img, (width / 2, height / 2),
                    center=graphics.CENTER_BOTH)

        self.changed()