Exemplo n.º 1
0
    def pre_compute(self, painter):
        w = self.width()
        h = self.height()

        s = scale(
            self.config["min"], self.config["max"],
            float(self.config["max"] - self.config["min"]) /
            (self.config["w"] / 4))

        self.angles = map_scale(s, 0, self.config["w"])
        self.str_scale, self.multiplier = str_scale(s,
                                                    self.config["scale_mult"])
        self.red_angle = self.config["w"]
        if self.config["redline"] is not None:
            self.red_angle = map_value(self.config["redline"],
                                       self.config["min"], self.config["max"],
                                       0, self.config["w"])

        # recompute new values
        self.l = 2  # left X value
        self.r = w - self.l  # right X value
        self.t_height = self.config["font_size"] + 8
        self.bar_height = max(0, h - self.t_height) - self.l
        self.value_offset = map_value(self.value, self.config["min"],
                                      self.config["max"], self.l, self.r)
        self.red_offset = w
        if self.config["redline"] is not None:
            self.red_offset = map_value(self.config["redline"],
                                        self.config["min"], self.config["max"],
                                        self.l, self.r)
Exemplo n.º 2
0
    def pre_compute(self, painter):

        painter.rotate(-90)
        painter.translate(-self.height(), 0)

        # swap the X vs Y
        h = self.width()
        w = self.height()

        # recompute new values
        self.l = 2          # left X value
        self.r = w - self.l # right X value
        self.t_height = self.config["font_size"] + 8
        self.bar_height = max(0, h - self.t_height) - self.l
        self.value_offset = map_value(self.value,
                                      self.config["min"],
                                      self.config["max"],
                                      self.l,
                                      self.r)
        self.red_offset = w
        if self.config["redline"] is not None:
            self.red_offset = map_value(self.config["redline"],
                                        self.config["min"],
                                        self.config["max"],
                                        self.l,
                                        self.r)
Exemplo n.º 3
0
    def __init__(self, parent, config):
        super(Gauge, self).__init__(parent)

        self.config = config
        self.value = config["min"]

        self.font      = QFont()
        self.note_font = QFont()
        self.color     = QColor(config["color"])
        self.red_color = QColor(config["redline_color"])
        self.brush     = QBrush(self.color)
        self.pen       = QPen(self.color)
        self.red_pen   = QPen(self.red_color)

        self.font.setPixelSize(self.config["font_size"])
        self.note_font.setPixelSize(self.config["note_font_size"])
        self.pen.setWidth(3)
        self.red_pen.setWidth(3)

        s = scale(config["min"], config["max"], config["scale_step"])

        self.angles = map_scale(s, 0, 270)
        self.str_scale, self.multiplier = str_scale(s, config["scale_mult"])

        self.red_angle = 270
        if config["redline"] is not None:
            self.red_angle  = map_value(config["redline"], config["min"], config["max"], 0, 270)
Exemplo n.º 4
0
    def __init__(self, parent, config):
        super(Gauge2, self).__init__(parent)

        self.config = config
        self.value = config["min"]

        self.font      = QFont()
        self.note_font = QFont()
        self.color     = QColor(config["color"])
        self.red_color = QColor(config["redline_color"])
        self.brush     = QBrush(self.color)
        self.pen       = QPen(self.color)
        self.red_pen   = QPen(self.red_color)

        self.font.setPixelSize(self.config["font_size"])
        self.note_font.setPixelSize(self.config["note_font_size"])
        self.pen.setWidth(4)
        self.red_pen.setWidth(4)

        s = scale(config["min"], config["max"], config["scale_step"])
        ss = scale(config["min"] + config["scale_step"], config["max"] - config["scale_step"], config["scale_step"])

        self.angles = map_scale(s, 0, 180)
        self.str_scale, self.multiplier = str_scale(s, config["scale_mult"])
        self.sub_angles = map_scale(ss, 22.5, 157.5)

        self.red_angle = 180
        if config["redline"] is not None:
            self.red_angle  = map_value(config["redline"], config["min"], config["max"], 0, 180)
Exemplo n.º 5
0
    def __init__(self, parent, config):
        super(DigitalBoost, self).__init__(parent)

        self.config = config
        config.update({'min' : -30, 
            'max' : 20, 
            'color' : '#2e3fcc', 
            'redline_color' : '#ff0000', 
            'scale_multi': 1, 
            'scale_step': 10, 
            'redline' : 14, 
            'font_size' : 18, 
            'title' : 'Highest Trip Boost',
            'x': 0,
            'y': 5,
            'w': 200,
            'h': 200,
            'numerals': 'false',
            'sensor': 'Boost'})
        self.value = config["min"]
        self.highest = config['min']

        self.font_db  = QFontDatabase()
        self.font_id  = self.font_db.addApplicationFont("fonts/DS-DIGI.TTF")
        self.families = self.font_db.applicationFontFamilies(self.font_id)
        #print [str(f) for f in self.families] #DS-Digital

        self.font         = QFont("DS-Digital")
        self.note_font    = QFont("DS-Digital")
        self.title_font   = QFont("DS-Digital")
        self.color        = QColor(config["color"])
        self.pen_color    = QColor(Qt.black)
        self.red_color    = QColor(config["redline_color"])
        self.brush        = QBrush(self.color)
        self.brush_bg     = QBrush(QColor("#555555"))
        self.brush_red    = QBrush(self.red_color)
        self.brush_red_bg = QBrush(self.red_color)
        self.pen          = QPen(self.pen_color)
        self.red_pen      = QPen(self.red_color)
        self.text_pen     = QPen(self.color)

        self.font.setPixelSize(self.config["font_size"])
        
        self.pen.setWidth(1)
        self.red_pen.setWidth(1)
        
        # TODO: make 80 configurable
        s = scale(config["min"], config["max"], float(config["max"] - config["min"])/80)

        self.angles = map_scale(s, 0, 270)
        self.str_scale, self.multiplier = str_scale(s, config["scale_multi"])

        self.red_angle = 270
        if config["redline"] is not None:
            self.red_angle  = map_value(config["redline"], config["min"], config["max"], 0, 270)
Exemplo n.º 6
0
    def __init__(self, parent, config):
        super(GL_DigitalGauge, self).__init__(parent)

        self.config = config
        self.value = config["min"]

        self.font_db  = QFontDatabase()
        self.font_id  = self.font_db.addApplicationFont("fonts/DS-DIGI.TTF")
        self.families = self.font_db.applicationFontFamilies(self.font_id)
        #print [str(f) for f in self.families] #DS-Digital

        self.font         = QFont("DS-Digital")
        self.note_font    = QFont("DS-Digital")
        self.title_font   = QFont("DS-Digital")
        self.color        = QColor(config["color"])
        self.pen_color    = QColor(Qt.black)
        self.red_color    = QColor(config["redline_color"])
        self.brush        = QBrush(self.color)
        self.brush_bg     = QBrush(QColor("#555555"))
        self.brush_red    = QBrush(self.red_color)
        self.brush_red_bg = QBrush(self.red_color)
        self.pen          = QPen(self.pen_color)
        self.red_pen      = QPen(self.red_color)
        self.indicator_color = QColor(config["indicator_color"])
        self.text_pen     = QPen(self.color)
        self.indicator_pen     = QPen(self.indicator_color)



        self.font.setPixelSize(self.config["font_size"])
        
        self.pen.setWidth(1)
        self.red_pen.setWidth(1)
        
        # TODO: make 80 configurable
        s = scale(config["min"], config["max"], float(config["max"] - config["min"])/80)

        self.angles = map_scale(s, 0, 270)
        self.str_scale, self.multiplier = str_scale(s, config["scale_mult"])

        self.red_angle = 270
        if config["redline"] is not None:
            self.red_angle  = map_value(config["redline"], config["min"], config["max"], 0, 270)
Exemplo n.º 7
0
    def draw_marks(self, painter):
        painter.save()

        painter.translate(self.width() / 2, self.height() / 2)

        # draw the ticks

        end = self.__tick_r - self.__tick_l
        yTopOffset = int(2 * self.__tick_r *
                         math.sin(math.radians(self.angles[1] / 2)) / 2)  #- 1
        yBottomOffset = int(
            2 * end * math.sin(math.radians(self.angles[1] / 2)) / 2)  #- 1

        angle = map_value(self.value, self.config["min"], self.config["max"],
                          0, 270)
        angle = min(angle, 270)

        for a in self.angles:
            painter.save()
            painter.rotate(90 + 45 + a)

            if a > self.red_angle and a <= angle:
                painter.setBrush(self.brush_red)
            elif a <= angle:
                painter.setBrush(self.brush)
            elif a > self.red_angle:
                painter.setBrush(self.brush_red_bg)
            else:
                painter.setBrush(self.brush_bg)

            path = QPainterPath()
            path.moveTo(end, -yBottomOffset)
            path.lineTo(self.__tick_r, -yTopOffset)
            path.lineTo(self.__tick_r, yTopOffset)
            path.lineTo(end, yBottomOffset)
            path.lineTo(end, -yBottomOffset)

            painter.drawPath(path)

            painter.restore()
        painter.restore()
Exemplo n.º 8
0
    def draw_needle(self, painter):

        painter.setBrush(self.indicator_brush)
        painter.setPen(self.indicator_pen)

        painter.save()
        painter.translate(self.width() / 2, self.height() / 2)
        angle = map_value(self.value, self.config["min"], self.config["max"],
                          0, 270)
        angle = min(angle, 270)
        angle -= 90 + 45
        painter.rotate(angle)
        painter.drawEllipse(QPoint(0, 0), 5, 5)
        painter.drawPolygon(
            QPolygon([
                QPoint(-5, 0),
                QPoint(0, -self.__needle_l),
                QPoint(5, 0),
                QPoint(-5, 0)
            ]))
        painter.restore()
Exemplo n.º 9
0
    def draw_bars(self, painter):
        painter.save()
        painter.translate(0, self.t_height)
        painter.setPen(self.no_pen)
        painter.setBrush(self.brush)

        self.t_height = self.config["font_size"] + 8
        self.bar_height = max(0, self.height() - self.t_height) - self.l
        #end = self.__tick_r - self.__tick_l
        #yTopOffset = int(2 * self.__tick_r * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1
        #yBottomOffset = int(2 * end * math.sin(math.radians(self.angles[1] / 2)) / 2) #- 1

        angle = map_value(self.value, self.config["min"], self.config["max"],
                          0, self.config["w"])
        angle = min(angle, self.config["w"])

        for a in self.angles:
            painter.save()
            #painter.rotate(90 + 45 + a)

            if a > self.red_angle and a <= angle:
                painter.setBrush(self.brush_red)
            elif a <= angle:
                painter.setBrush(self.brush)
            elif a > self.red_angle:
                painter.setBrush(self.brush_red_bg)
            else:
                painter.setBrush(self.brush_bg)

            path = QPainterPath()
            path.moveTo(0, 0 + a)
            path.lineTo(self.bar_height, 0 + a)
            path.lineTo(self.bar_height, 2 + a)
            path.lineTo(0, 2 + a)
            path.lineTo(0, 0 + a)

            painter.drawPath(path)
            painter.restore()

        painter.restore()
Exemplo n.º 10
0
    def __init__(self, parent, config):
        super(GL_Gauge, self).__init__(parent)

        self.config = config

        self.value = config["min"]

        self.font = QFont()
        self.note_font = QFont()
        self.color = QColor(config["color"])
        self.red_color = QColor(config["redline_color"])
        self.indicator_color = QColor(config["indicator_color"])

        self.brush = QBrush(self.color)
        self.indicator_brush = QBrush(self.indicator_color)

        self.pen = QPen(self.color)
        self.red_pen = QPen(self.red_color)
        self.indicator_pen = QPen(self.indicator_color)

        self.font.setPixelSize(self.config["font_size"])
        self.note_font.setPixelSize(self.config["note_font_size"])

        self.pen.setWidth(3)
        self.red_pen.setWidth(3)
        self.indicator_pen.setWidth(3)

        s = scale(config["min"], config["max"], config["scale_step"])

        self.angles = map_scale(s, 0, 270)
        self.str_scale, self.multiplier = str_scale(s, config["scale_mult"])

        self.red_angle = 270
        if config["redline"] is not None:
            self.red_angle = map_value(config["redline"], config["min"],
                                       config["max"], 0, 270)

        #self.initializeGL()
        self.resizeGL(config['w'], config['h'])
Exemplo n.º 11
0
    def draw_needle(self, painter):
        painter.save()

        painter.translate(self.width() / 2, self.height() / 2)
        angle = map_value(self.value, self.config["min"], self.config["max"], 0, 270)
        angle = min(angle, 270)
        angle -= 90 + 45
        painter.rotate(angle)


        painter.drawEllipse(QPoint(0,0), 5, 5)

        painter.drawPolygon(
            QPolygon([
                QPoint(-5, 0),
                QPoint(0,   -self.__needle_l),
                QPoint(5,  0),
                QPoint(-5, 0)
            ])
        )

        painter.restore()
Exemplo n.º 12
0
    def draw_needle(self, painter):
        painter.save()

        painter.translate(self.width() / 2, self.height() / 2)
        angle = map_value(self.value, self.config["min"], self.config["max"], 0, 180)
        angle = min(angle, 180)
        angle -= 90 + 0
        painter.rotate(angle)


#        painter.drawEllipse(QPoint(0,0), 5, 5)

        painter.drawPolygon(
            QPolygon([
                QPoint(-5,  -self.__needle_l - 5),   #start point, 5 px off left flank
                QPoint(0,   -self.__needle_r),       #tip of needle
                QPoint(5,   -self.__needle_l - 5),   #5 px off right flank
                QPoint(0,   -self.__needle_l),       #tail point of needle,
                QPoint(-5,  -self.__needle_l - 5)    #return to start point
            ])
        )

        painter.restore()