35 lines
926 B
Python
35 lines
926 B
Python
import enum
|
|
import math
|
|
import cairo
|
|
|
|
from hexagram.cluster import Dial
|
|
|
|
class SpeedUnits(enum.Enum):
|
|
KPH = 0
|
|
MPH = 1
|
|
|
|
class Speedo(Dial):
|
|
__slots__ = 'units',
|
|
|
|
MIN_ANGLE = 232.0 * (math.pi / 180.0)
|
|
MAX_ANGLE = 488.0 * (math.pi / 180.0)
|
|
|
|
FONT_FACE = "Muli"
|
|
|
|
def __init__(self, x: float, y: float, radius: float, max_value: float, units: SpeedUnits=SpeedUnits.KPH):
|
|
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, max_value)
|
|
|
|
self.units = units
|
|
|
|
def draw_bg(self, cr: cairo.Context):
|
|
super().draw_bg(cr)
|
|
|
|
cr.select_font_face(self.FONT_FACE,
|
|
cairo.FontSlant.ITALIC,
|
|
cairo.FontWeight.BOLD)
|
|
|
|
cr.set_font_size(self.radius * 0.1)
|
|
cr.set_source_rgb(1, 1, 1)
|
|
|
|
for speed in range(0, int(self.max_value)+1, 20):
|
|
self.draw_number(cr, 0.75, speed, "%d" % int(speed))
|