def __init__(self, *args): super(LaptimeDashlet, self).__init__(*args) self.laptime = "0:00" self.group = canvas.Group() self.text_items = [] def make_text(text): left = self.group.add_text(text=text, baseline=canvas.Baseline.TOP, anchor=canvas.Anchor.SE) right = self.group.add_text(text="{time}", baseline=canvas.Baseline.TOP, anchor=canvas.Anchor.SE) self.text_items.append((left, right)) return left, right self.gfx_current_label, self.gfx_current_time = make_text("Current:") self.gfx_behind_label, self.gfx_behind_time = make_text("Behind:") self.gfx_ahead_label, self.gfx_ahead_time = make_text("Ahead:") self.gfx_best_label, self.gfx_best_time = make_text("Best:") self.gfx_best_driver_, self.gfx_best_driver = make_text("") self.reshape(self.x, self.y, self.w, self.h)
def __init__(self, *args): super(PlacesDashlet, self).__init__(*args) self.group = canvas.Group() self.gfx_track = self.group.add_rectangle() self.gfx_vehicles = [] self.lap_dist = 1.0
def test_canvas(self): root = canvas.Group() root.add_text(0, 0, "West", canvas.Anchor.W) root.add_text(0, 0, "East", canvas.Anchor.E) root.add_text(0, 0, "North", canvas.Anchor.N) root.add_text(0, 0, "South", canvas.Anchor.S) root.add_rectangle(-8, -8, 16, 16)
def update_state(self, state): # create new graphics, if number of vehicles changed if len(self.gfx_vehicles) != len(state.vehicles): self.group = canvas.Group() self.gfx_track = self.group.add_rectangle(fill_color=self.lcd_style.shadow_color, stroke_color=None) self.gfx_vehicles = [] for veh in state.vehicles: self.gfx_vehicles.append((self.group.add_rectangle(anchor=canvas.Anchor.CENTER, stroke_color=(0, 0, 0)), self.group.add_text(anchor=canvas.Anchor.S, baseline=canvas.Baseline.MIDDLE, fill_color=(0, 0, 0)))) self.gfx_track.x = 0 self.gfx_track.y = self.h/2 - 2 self.gfx_track.w = self.w self.gfx_track.h = 4 # update graphics for i, veh in enumerate(state.vehicles): p = veh.lap_dist / state.lap_dist rect, text = self.gfx_vehicles[i] text.x = rect.x = p * self.w text.y = rect.y = self.h / 2 rect.w = self.h/2 rect.h = self.h/2 text.font_size = self.h / 2.5 text.text = str(veh.place) if veh.is_player: rect.style.fill_color = (0, 1.0, 0) elif veh.place == 1: rect.style.fill_color = (1.0, 1.0, 1.0) else: rect.style.fill_color = self.lcd_style.highlight_color self.queue_draw()
def __init__(self): gtk.DrawingArea.__init__(self) self.connect("expose-event", self.on_expose_event) self.canvas = canvas.Group() self.set_size_request(640, 480) fsize = 32.0 x, y = (320, 100) self.canvas.add_text(x, y, "Center", fill_color=(0, 0, 0), anchor=canvas.Anchor.S, baseline=canvas.Baseline.MIDDLE, font_size=fsize) self.canvas.add_rectangle(x - 4, y - 4, 9, 9, fill_color=(1, 0, 0), stroke_color=(0, 0, 0)) x, y = (320, 200) self.canvas.add_text(x, y, "North", fill_color=(0, 0, 0), anchor=canvas.Anchor.N, font_size=fsize) self.canvas.add_text(x, y, "South", fill_color=(0, 0, 0), anchor=canvas.Anchor.S, font_size=fsize) self.canvas.add_text(x, y, "West", fill_color=(0, 0, 0), anchor=canvas.Anchor.W, font_size=fsize) self.canvas.add_text(x, y, "East", fill_color=(0, 0, 0), anchor=canvas.Anchor.E, font_size=fsize) self.canvas.add_rectangle(x - 4, y - 4, 9, 9, fill_color=(1, 0, 0), stroke_color=(0, 0, 0)) x, y = (320, 300) self.canvas.add_text(x, y, "norwes", fill_color=(0, 0, 0), anchor=canvas.Anchor.NW, font_size=fsize) self.canvas.add_text(x, y, "NorthEast", fill_color=(0, 0, 0), anchor=canvas.Anchor.NE, font_size=fsize) self.canvas.add_text(x, y, "SouthWest", fill_color=(0, 0, 0), anchor=canvas.Anchor.SW, font_size=fsize) self.canvas.add_text(x, y, "SouthEast", fill_color=(0, 0, 0), anchor=canvas.Anchor.SE, font_size=fsize) self.canvas.add_rectangle(x - 4, y - 4, 9, 9, fill_color=(1, 0, 0), stroke_color=(0, 0, 0)) x, y = (120, 430) self.canvas.add_rectangle(x, y, 400, 1, fill_color=(0, 0, 0)) self.canvas.add_text(x + 0, y, "Alpyt", fill_color=(0, 0, 0), anchor=canvas.Anchor.SW, baseline=canvas.Baseline.ALPHABETIC, font_size=fsize) self.canvas.add_text(x + 80, y, "Topyt", fill_color=(0, 0, 0), anchor=canvas.Anchor.SW, baseline=canvas.Baseline.TOP, font_size=fsize) self.canvas.add_text(x + 160, y, "Middleyt", fill_color=(0, 0, 0), anchor=canvas.Anchor.SW, baseline=canvas.Baseline.MIDDLE, font_size=fsize) self.canvas.add_text(x + 240, y, "Bottyt", fill_color=(0, 0, 0), anchor=canvas.Anchor.SW, baseline=canvas.Baseline.BOTTOM, font_size=fsize)
def __init__(self, *args): super(CarDashlet, self).__init__(*args) self.dent_severity = [0, 0, 0, 0, 0, 0, 0, 0] self.detached = False self.overheating = False self.wheels = None car_w = self.car_w = 150 car_h = self.car_h = 300 wheel_w = self.wheel_w = 60 wheel_h = self.wheel_h = 80 self.group = canvas.Group() self.gfx_dent = [ # front self.group.add_rectangle(30, -20, car_w - 60, 20, stroke_color=(0, 0, 0), fill_color=self.dent_color(0)), # front/left self.group.add_rounded_rectangle(-20, -20, 60, 80, (32, 0, 0, 0), stroke_color=(0, 0, 0), fill_color=self.dent_color(1)), # left side self.group.add_rectangle(-20, 60, 20, car_h - 120, stroke_color=(0, 0, 0), fill_color=self.dent_color(2)), # back/left self.group.add_rounded_rectangle(-20, car_h - 60, 60, 80, (0, 0, 0, 32), stroke_color=(0, 0, 0), fill_color=self.dent_color(3)), # back self.group.add_rectangle(30, car_h, car_w - 60, 20, stroke_color=(0, 0, 0), fill_color=self.dent_color(4)), # back/right self.group.add_rounded_rectangle(car_w - 40, car_h - 60, 60, 80, (0, 0, 32, 0), stroke_color=(0, 0, 0), fill_color=self.dent_color(5)), # right side self.group.add_rectangle(car_w, 60, 20, car_h - 120, stroke_color=(0, 0, 0), fill_color=self.dent_color(6)), # front/right self.group.add_rounded_rectangle(car_w - 40, -20, 60, 80, (0, 32, 0, 0), stroke_color=(0, 0, 0), fill_color=self.dent_color(7)), ] # car body self.gfx_body = self.group.add_rounded_rectangle( 0, 0, car_w, car_h, (32, 32, 32, 32), line_width=3.0, stroke_color=(0, 0, 0), fill_color=self.lcd_style.shadow_color) def make_wheel(root, wheel): if wheel in (0, 1): w_y = 0 else: w_y = car_h - wheel_h if wheel in (0, 2): w_x = -wheel_w * 1.3 else: w_x = car_w + wheel_w * 0.3 rounding = [(12.0, 0.0, 0.0, 12.0), (0.0, 0.0, 0.0, 0.0), (0.0, 12.0, 12.0, 0.0)] group = root.add_group() parts = [] for i in range(0, 3): offset = -8 if wheel in (0, 2) else 8 parts.append( (group.add_rounded_rectangle(w_x + i * wheel_w / 3 + offset, w_y, wheel_w / 3, wheel_h, rounding[i], stroke_color=None, fill_color=(1, 1, 1)), group.add_text( w_x + wheel_w / 2 + offset * 1.5 + (i - 1) * 32, w_y - (15 if wheel in (0, 1) else -wheel_h - 25), "Temp", anchor=canvas.Anchor.S, font_size=16, fill_color=self.lcd_style.foreground_color))) flat = group.add_rounded_rectangle(w_x + offset, w_y, wheel_w, wheel_h, (12.0, 12.0, 12.0, 12.0), stroke_color=(0.0, 1.0, 1.0), line_width=8.0) flat.visible = False status = group.add_text(w_x + wheel_w / 2 + (-85 if wheel in (0, 2) else 85), w_y + wheel_h / 2 - 8, "-#-", anchor=canvas.Anchor.S, font_size=14, fill_color=self.lcd_style.foreground_color) group.add_text(w_x + wheel_w / 2 + (-85 if wheel in (0, 2) else 85), w_y + wheel_h / 2 + 8, "kPa", anchor=canvas.Anchor.S, font_size=14, fill_color=self.lcd_style.foreground_color) group.add_rectangle(w_x + wheel_w / 2 + (-55 if wheel in (0, 2) else 55) - 8, w_y + wheel_h, 16, wheel_h, anchor=canvas.Anchor.SW, stroke_color=self.lcd_style.shadow_color, fill_color=None) wear = group.add_rectangle(w_x + wheel_w / 2 + (-55 if wheel in (0, 2) else 55) - 8, w_y + wheel_h, 16, wheel_h, anchor=canvas.Anchor.SW, stroke_color=None, fill_color=(1, 0, 0)) brake = group.add_text(w_x + wheel_w / 2, w_y + wheel_h / 2 + 8 + (60 if wheel in (0, 1) else -60), "99°", anchor=canvas.Anchor.S, font_size=16, fill_color=self.lcd_style.foreground_color) return (parts, flat, wear, brake, status) self.gfx_wheels = [ make_wheel(self.group, 0), make_wheel(self.group, 1), make_wheel(self.group, 2), make_wheel(self.group, 3) ] self.gfx_engine = self.group.add_rectangle(car_w / 2 - 30, 30, 60, 60, line_width=3.0, stroke_color=(0, 0, 0)) self.group.add_text(-100, car_h / 2 - 12, "Water", anchor=canvas.Anchor.S, font_size=16) self.gfx_water = self.group.add_text(-100, car_h / 2 + 8, "Temp", anchor=canvas.Anchor.S, font_size=16) self.group.add_text(car_w + 100, car_h / 2 - 12, "Oil", anchor=canvas.Anchor.S, font_size=16) self.gfx_oil = self.group.add_text(car_w + 100, car_h / 2 + 8, "Temp", anchor=canvas.Anchor.S, font_size=16) self.group.add_rectangle(car_w / 2, car_h - 80 + 4, 80, 60, anchor=canvas.Anchor.CENTER, stroke_color=None, fill_color=(0, 0, 0)) self.group.add_text(car_w / 2, car_h - 80, "Fuel", anchor=canvas.Anchor.S, font_size=16) self.gfx_fuel = self.group.add_text(car_w / 2, car_h - 62, "0L", anchor=canvas.Anchor.S, font_size=16)