OBP60v/pages/battery2.py

91 lines
2.6 KiB
Python

"""
Komplexe Batterieübersichtsseite
"""
import cairo
from .page import Page
class Battery2(Page):
def draw_battery(self, ctx, x, y, w, h, level):
'''
Das Rechteck ist das komplett umschließende
Level ist der prozentuale Füllstand
'''
pass
'''
// Battery graphic with fill level
void batteryGraphic(uint x, uint y, float percent, int pcolor, int bcolor){
// Show battery
int xb = x; // X position
int yb = y; // Y position
int t = 4; // Line thickness
// Percent limits
if(percent < 0){
percent = 0;
}
if(percent > 99){
percent = 99;
}
// Battery corpus 100x80 with fill level
int level = int((100.0 - percent) * (80-(2*t)) / 100.0);
getdisplay().fillRect(xb, yb, 100, 80, pcolor);
if(percent < 99){
getdisplay().fillRect(xb+t, yb+t, 100-(2*t), level, bcolor);
}
// Plus pol 20x15
int xp = xb + 20;
int yp = yb - 15 + t;
getdisplay().fillRect(xp, yp, 20, 15, pcolor);
getdisplay().fillRect(xp+t, yp+t, 20-(2*t), 15-(2*t), bcolor);
// Minus pol 20x15
int xm = xb + 60;
int ym = yb -15 + t;
getdisplay().fillRect(xm, ym, 20, 15, pcolor);
getdisplay().fillRect(xm+t, ym+t, 20-(2*t), 15-(2*t), bcolor);
'''
def draw(self, ctx):
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
ctx.set_font_size(40)
ctx.move_to(10, 65)
ctx.show_text("Bat.")
# Batterietyp
ctx.move_to(90, 65)
ctx.show_text("AGM")
# Kapazität
ctx.move_to(10, 200)
ctx.select_font_face("DSEG7 Classic")
ctx.set_font_size(40)
ctx.show_text("12")
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
ctx.set_font_size(16)
ctx.show_text("Ah")
ctx.move_to(10, 235)
ctx.show_text("Installed")
ctx.move_to(10, 255)
ctx.show_text("Battery Type")
# Batteriegraphik
# Rechteck mit Füllstand 100x80, oben zwei Pole
ctx.rectangle(150, 100, 100, 80)
ctx.stroke()
# Füllstand
# Pole
'''
ctx.line_to(2.5, 1.5)
ctx.set_line_width(0.06)
'''