Esempio n. 1
0
    def box_type_1(self, X, Y, name, ident, box_width, box_height):
        """ Draw a rectangular box of box_width and box_height
            with name and ident,
            on sheet with (X,Y) as its center on the canvas
            Return midpts = N(x,y), S(x,y), E(x,y), W(x,y).
        """
        boxW2 = box_width / 2
        boxH2 = box_height / 2
        x0, y0 = X - boxW2, Y - boxH2  # Top_left of box
        x1, y1 = X + boxW2, Y + boxH2  # Bottom_right of box
        width = x1 - x0
        height = y1 - y0

        box = gui.SvgRectangle(x0, y0, width, height)
        box.set_stroke(width=2, color='black')
        box.set_fill(color='yellow')
        box_name = gui.SvgText(X, Y, name)
        box_name.attributes['text-anchor'] = 'middle'
        box_id = gui.SvgText(X, Y + 15, str(ident))
        box_id.attributes['text-anchor'] = 'middle'
        self.sheet.append([box, box_name, box_id])

        mid_north = [X, Y - boxH2]
        mid_south = [X, Y + boxH2]
        mid_east = [X + boxW2, Y]
        mid_west = [X - boxW2, Y]

        return mid_north, mid_south, mid_east, mid_west
    def box_type_1(self, X, Y, name):
        """ Draw a box with name on sheet around (X,Y) = Xcenter and Ycenter
            Return midpts = N(x,y), S(x,y), E(x,y), W(x,y)
            (X,Y) = center of box on canvas
        """
        x0, y0 = X - self.boxW2, Y - self.boxH2  # TopLeft of box
        x1, y1 = X + self.boxW2, Y + self.boxH2  # BottomRight of box
        width = x1 - x0
        height = y1 - y0

        box = gui.SvgRectangle(x0, y0, width, height)
        box.set_stroke(width=2, color='black')
        box.set_fill(color='yellow')
        box_name = gui.SvgText(X, Y, name)
        box_name.attributes['text-anchor'] = 'middle'
        box_id = gui.SvgText(X, Y + 15, str(self.boxID))
        box_id.attributes['text-anchor'] = 'middle'
        self.sheets[self.sheet_nr].append([box, box_name, box_id])

        mid_north = [X, Y - self.boxH2]
        mid_south = [X, Y + self.boxH2]
        mid_east = [X + self.boxW2, Y]
        mid_west = [X - self.boxW2, Y]

        return mid_north, mid_south, mid_east, mid_west
Esempio n. 3
0
 def __init__(self, width, height):
     super(SvgPlot, self).__init__(width, height)
     self.width = width
     self.height = height
     self.polyList = []
     self.font_size = 15
     self.plot_inner_border = self.font_size
     self.textYMin = gui.SvgText(0, self.height + self.font_size, "min")
     self.textYMax = gui.SvgText(0, 0, "max")
     self.textYMin.style['font-size'] = gui.to_pix(self.font_size)
     self.textYMax.style['font-size'] = gui.to_pix(self.font_size)
     self.append([self.textYMin, self.textYMax])
Esempio n. 4
0
    def append_poly(self, polys):
        for poly in polys:
            self.append(poly)
            self.polyList.append(poly)
            poly.textXMin = gui.SvgText(0, 0, "actualValue")
            poly.textXMax = gui.SvgText(0, 0, "actualValue")
            poly.textYVal = gui.SvgText(0, 0, "actualValue")
            poly.textYVal.style['font-size'] = gui.to_pix(self.font_size)

            poly.lineYValIndicator = gui.SvgLine(0, 0, 0, 0)
            poly.lineXMinIndicator = gui.SvgLine(0, 0, 0, 0)
            poly.lineXMaxIndicator = gui.SvgLine(0, 0, 0, 0)
            self.append([poly.textXMin, poly.textXMax, poly.textYVal, poly.lineYValIndicator, 
                poly.lineXMinIndicator, poly.lineXMaxIndicator])
    def RhombusPolygon(self, X, Y, strID, hor_size, vert_size):
        """ Draw a rhombus polygon with its center on position X,Y
            with its strID as text in the middle on sheet.
        """
        x0, y0 = X - hor_size, Y  # mid_west
        x1, y1 = X, Y - vert_size  # mid_north
        x2, y2 = X + hor_size, Y  # mid_east
        x3, y3 = X, Y + vert_size  # mid_south

        ##        sheet.create_polygon(x0, y0, x1, y1, x2, y2, x3, y3,
        ##                             fill='#dfd', smooth=0, outline='black')
        ##        sheet.create_text(X, Y, justify=CENTER, text=strID)
        polygon = SvgPolygon(4)
        polygon.set_stroke(width=2, color='black')
        poly_name = gui.SvgText(X, Y + 5, strID)
        poly_name.attributes['text-anchor'] = 'middle'
        self.sheets[self.sheet_nr].append([polygon, poly_name])

        mid_north = [x1, y1]
        mid_south = [x3, y3]
        mid_east = [x2, y2]
        mid_west = [x0, y0]

        polygon.add_coord(*mid_north)
        polygon.add_coord(*mid_east)
        polygon.add_coord(*mid_south)
        polygon.add_coord(*mid_west)

        return mid_north, mid_south, mid_east, mid_west
Esempio n. 6
0
    def rhombus_polygon(self, X, Y, str_id, hor_size, vert_size):
        """ Draw a rhombus polygon.
            Horizontal size (-hor_size, +hor_size) and
            vertical size (-vert_size, +vert_size).
            with its center on position X,Y
            and with its str_id as text in the middle.
        """
        x0, y0 = X - hor_size, Y  # mid_west
        x1, y1 = X, Y - vert_size  # mid_north
        x2, y2 = X + hor_size, Y  # mid_east
        x3, y3 = X, Y + vert_size  # mid_south

        polygon = SvgPolygon(4)
        polygon.set_stroke(width=2, color='black')
        poly_name = gui.SvgText(X, Y + 5, str_id)
        poly_name.attributes['text-anchor'] = 'middle'
        self.sheet.append([polygon, poly_name])

        mid_north = [x1, y1]
        mid_south = [x3, y3]
        mid_east = [x2, y2]
        mid_west = [x0, y0]

        polygon.add_coord(*mid_north)
        polygon.add_coord(*mid_east)
        polygon.add_coord(*mid_south)
        polygon.add_coord(*mid_west)

        return mid_north, mid_south, mid_east, mid_west
Esempio n. 7
0
    def __init__(self, x_pos, y_pos, wide, high, *args, **kwargs):
        """ x_pos and y_pos are coordinates indicated by the pointer, generally at the center of the shown tape
        """
        gui.SvgGroup.__init__(self, *args, **kwargs)

        self.wide = wide
        self.high = high

        self.attributes['transform'] = 'translate(%s %s)' % (x_pos, y_pos)

        #it is used a subcontainer in order to show only a part of the entire tape
        self.subcontainer = gui.SvgSubcontainer(-self.wide, -self.high / 2,
                                                wide, high)
        self.subcontainer.set_viewbox(-self.wide / 2, -self.high / 2, wide,
                                      self.high)
        self.append(self.subcontainer)

        vertical_line_width = self.wide / 20
        scale_vertical_line = gui.SvgLine(-self.wide / 2, -self.high / 2,
                                          -self.wide / 2, self.high)
        scale_vertical_line.set_stroke(vertical_line_width, 'lightgray')
        self.subcontainer.append(scale_vertical_line)

        self.pointer_line = gui.SvgLine(self.wide / 2, 0, -self.wide / 2,
                                        self.value * (self.high / 2))
        self.pointer_line.set_stroke(self.wide / 14, 'lightgray')
        self.subcontainer.append(self.pointer_line)

        self.value_max = gui.SvgText(-self.wide / 2 + vertical_line_width,
                                     -self.high / 2, "10")
        self.value_max.attr_dominant_baseline = 'hanging'
        self.value_max.attr_text_anchor = 'start'
        self.value_max.set_fill('white')
        self.value_max.css_font_size = gui.to_pix(0.3 * self.wide)
        self.value_max.css_font_weight = 'bolder'
        #self.value_max.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)
        self.subcontainer.append(self.value_max)

        self.value_min = gui.SvgText(-self.wide / 2 + vertical_line_width,
                                     self.high / 2, "-10")
        self.value_min.attr_dominant_baseline = 'ideographic'
        self.value_min.attr_text_anchor = 'start'
        self.value_min.set_fill('white')
        self.value_min.css_font_size = gui.to_pix(0.3 * self.wide)
        self.value_min.css_font_weight = 'bolder'
        #self.value_min.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)
        self.subcontainer.append(self.value_min)
Esempio n. 8
0
 def set_value(self, value):
     if not self.get_app_instance():
         return
     with self.get_app_instance().update_lock:
         self.values.add_coord(time.clock(), float(value))
         try:
             plot = pygal.XY()
             pairs = []
             for i in range(0, len(self.values.coordsX)):
                 pairs.append([self.values.coordsX[i], self.values.coordsY[i]])
             plot.add(self.epics_pv_name, pairs)
             self.add_child("chart", plot.render())
         except Exception:
             self.style['overflow'] = "visible"
             self.add_child("chart", gui.SvgText(10,10, "Install pygal to use this widget"))
Esempio n. 9
0
def default_icon(name, view_w=2, view_h=0.6):
    """
    A simple function to make a default svg icon for the widgets
      such icons can be replaced later with a good one
    """
    icon = gui.Svg(width=100,height=30)
    icon.set_viewbox(-view_w/2,-view_h/2,view_w,view_h)
    text = gui.SvgText(0,0,name)
    text.style['font-size'] = "0.2px"
    text.style['text-anchor'] = "middle"
    stroke_width = 0.01
    rect = gui.SvgRectangle(-view_w/2+stroke_width,-view_h/2+stroke_width,view_w-stroke_width*2,view_h-stroke_width*2)
    rect.set_fill("none")
    rect.set_stroke(0.01,'black')
    icon.append([rect, text])
    return icon
Esempio n. 10
0
 def test_init(self):
     widget = gui.SvgText(x=10, y=10, text='hello world')
     assertValidHTML(widget.repr())
Esempio n. 11
0
    def __init__(self, width, height, _min, _max):
        super(Gauge, self).__init__(width, height)
        self.width = width
        self.height = height
        self.min = _min
        self.max = _max
        self.scale_angle_range = math.pi * 2 - 1.0
        self.scale_value_range = _max - _min
        self.base_angle = 0  #-self.scale_angle_range/2.0

        self.radius = min(width, height) / 2.0
        circle = gui.SvgCircle(width / 2.0, height / 2.0, self.radius)
        self.append(circle)
        circle.set_fill('gray')
        circle.set_stroke(1, 'lightgray')

        circle = gui.SvgCircle(width / 2.0, height / 2.0,
                               self.radius * 92.0 / 100.0)
        self.append(circle)
        circle.set_fill('lightgray')
        circle.set_stroke(1, 'lightgray')

        font_size = self.radius * 10.0 / 100.0
        xy = self.value_to_xy_tuple(_min, self.radius * 90.0 / 100.0)
        textMin = gui.SvgText(xy[0], xy[1], str(_min))
        xy = self.value_to_xy_tuple(_max, self.radius * 90.0 / 100.0)
        textMax = gui.SvgText(xy[0], xy[1], str(_max))
        textMin.style['font-size'] = gui.to_pix(font_size)
        textMax.style['font-size'] = gui.to_pix(font_size)
        textMin.style['text-anchor'] = "end"
        textMax.style['text-anchor'] = "end"
        textMin.set_fill('red')
        textMax.set_fill('green')

        for i in range(0, 11):
            xy1 = self.value_to_xy_tuple(
                self.min + self.scale_value_range / 10 * i,
                self.radius * 92.0 / 100.0)
            xy2 = self.value_to_xy_tuple(
                self.min + self.scale_value_range / 10 * i, self.radius)
            tick = gui.SvgLine(xy1[0], xy1[1], xy2[0], xy2[1])
            tick.set_stroke(2, 'white')
            self.append(tick)

        self.append(textMin)
        self.append(textMax)

        self.arrow = gui.SvgPolyline()
        self.arrow.add_coord(-self.radius * 20.0 / 100.0, 0)
        self.arrow.add_coord(-self.radius * 23.0 / 100.0,
                             self.radius * 10.0 / 100.0)
        self.arrow.add_coord(0, 0)
        self.arrow.add_coord(-self.radius * 23.0 / 100.0,
                             -self.radius * 10.0 / 100.0)
        self.arrow.add_coord(-self.radius * 20.0 / 100.0, 0)
        self.arrow.style['fill'] = 'white'
        self.arrow.set_stroke(1.0, 'white')
        self.append(self.arrow)

        self.arrow_preview = gui.SvgPolyline()
        self.arrow_preview.add_coord(-self.radius * 10.0 / 100.0, 0)
        self.arrow_preview.add_coord(-self.radius * 13.0 / 100.0,
                                     self.radius * 5.0 / 100.0)
        self.arrow_preview.add_coord(0, 0)
        self.arrow_preview.add_coord(-self.radius * 13.0 / 100.0,
                                     -self.radius * 5.0 / 100.0)
        self.arrow_preview.add_coord(-self.radius * 10.0 / 100.0, 0)
        self.arrow_preview.style['fill'] = 'beige'
        self.arrow_preview.set_stroke(1.0, 'beige')
        self.append(self.arrow_preview)

        self.set_value(_min)
Esempio n. 12
0
    def __init__(self, *args, **kwargs):

        gui.SvgSubcontainer.__init__(self, -self.vw / 2, -self.vh / 2, self.vw,
                                     self.vh, *args, **kwargs)

        self.attr_viewBox = "%s %s %s %s" % (-self.vw / 2, -self.vh / 2,
                                             self.vw, self.vh)

        self.group_pitch = gui.SvgGroup()
        self.group_pitch.css_transform = "rotate(0deg), translate(0, 0)"
        self.group_pitch.css_transform_box = "fill-box"
        self.group_pitch.css_transform_origin = "center"

        self.group_roll = gui.SvgGroup()
        self.group_roll.css_transform = "rotate(0deg), translate(0, 0)"
        self.group_roll.css_transform_box = "fill-box"
        self.group_roll.css_transform_origin = "50% 20%"
        self.group_roll.append(self.group_pitch)

        #horizon
        #background is static and occupy the entire attidute indicator
        self.horizon_background = gui.SvgRectangle(-self.vw / 2, -self.vh / 2,
                                                   self.vw, self.vh)
        self.horizon_background.set_fill("rgb(0,100,255)")
        self.append(self.horizon_background)

        self.group_horizon_terrain = gui.SvgGroup()
        self.horizon_terrain = gui.SvgRectangle(-self.vw, 0, self.vw * 2,
                                                self.vh * 2)
        self.horizon_terrain.set_fill("rgb(53, 151, 0)")
        self.horizon_terrain.set_stroke(self.vh / 1000.0, "lightgray")
        self.group_horizon_terrain.append(self.horizon_terrain)
        self.append(self.group_horizon_terrain)

        #pitch angle indication
        self.group_pitch_indicator = gui.SvgGroup()
        self.group_pitch.append(self.group_pitch_indicator)
        self.generate_pitch_indicator()

        self.append(self.group_roll)

        #roll angle indication
        min_radius = self.vw * 0.45
        mid_radius = self.vw * 0.48
        max_radius = self.vw * 0.5
        angle_min = -60
        angle_max = 60
        angle_step = 20  # was 5
        for angle in range(angle_min, angle_max + angle_step, angle_step):
            r = min_radius if (angle % 10) == 0 else mid_radius
            x_min = math.cos(math.radians(angle + 90)) * r
            y_min = -math.sin(math.radians(angle + 90)) * r
            x_max = math.cos(math.radians(angle + 90)) * max_radius
            y_max = -math.sin(math.radians(angle + 90)) * max_radius

            hide_scale = abs(int(angle)) > self.pitch_roll_scale_limit

            line = gui.SvgLine(x_min, y_min, x_max, y_max)
            line.set_stroke(self.vw * 0.005,
                            'white' if not hide_scale else 'transparent')
            self.append(line)
            if (angle % 10) == 0:
                x_txt = math.cos(
                    math.radians(angle + 90)) * (min_radius - 0.025 * self.vw)
                y_txt = -math.sin(math.radians(angle + 90)) * (min_radius -
                                                               0.025 * self.vw)
                txt = gui.SvgText(x_txt, y_txt, str(abs(int(angle))))
                txt.attr_dominant_baseline = 'hanging'
                txt.attr_text_anchor = 'middle'
                txt.set_fill('white' if not hide_scale else 'transparent')
                txt.css_font_size = gui.to_pix(self.vw * 0.04)
                txt.css_font_weight = 'bolder'
                self.append(txt)

        self.group_roll_indicator = gui.SvgGroup()
        self.group_roll_indicator.css_visibility = 'visible'
        self.append(self.group_roll_indicator)

        #roll and bank indicator
        self.group_roll_and_bank_angle_indicator = gui.SvgGroup()
        self.roll_indicator = gui.SvgPolygon(3)
        self.roll_indicator.set_fill('red')
        self.roll_indicator.set_stroke(1, 'black')
        self.roll_indicator.add_coord(-0.04 * self.vw, -0.06 * self.vw)
        self.roll_indicator.add_coord(0.0 * self.vw, (-0.06 - 0.03) * self.vw)
        self.roll_indicator.add_coord(0.04 * self.vw, -0.06 * self.vw)
        self.group_roll_and_bank_angle_indicator.append(self.roll_indicator)
        self.bank_indicator = gui.SvgPolygon(4)
        self.bank_indicator.set_fill('transparent')
        self.bank_indicator.set_stroke(1, 'black')
        self.bank_indicator_width = 0.08
        self.bank_indicator.add_coord(
            -(self.bank_indicator_width / 2.0) * self.vw,
            (-0.06 + 0.005) * self.vw)
        self.bank_indicator.add_coord(
            (self.bank_indicator_width / 2.0) * self.vw,
            (-0.06 + 0.005) * self.vw)
        self.bank_indicator.add_coord(
            (self.bank_indicator_width / 2.0) * self.vw,
            (-0.06 + 0.025) * self.vw)
        self.bank_indicator.add_coord(
            -(self.bank_indicator_width / 2.0) * self.vw,
            (-0.06 + 0.025) * self.vw)
        self.group_roll_and_bank_angle_indicator.append(self.bank_indicator)
        self.group_roll_and_bank_angle_indicator.attributes[
            'transform'] = "translate(0 %s)" % (-0.3 * self.vh)
        self.group_roll_indicator.append(
            self.group_roll_and_bank_angle_indicator)

        #airplaine indicator is steady
        thick = 0.02 * self.vw
        self.airplane_svg_left = gui.SvgPolygon(8)
        self.airplane_svg_left.set_fill('gray')
        self.airplane_svg_left.set_stroke(0.005 * self.vw, 'black')
        self.airplane_svg_left.add_coord(-0.2 * self.vw, 0 * self.vw)  #25x8
        self.airplane_svg_left.add_coord(-0.40 * self.vw, 0 * self.vw)
        self.airplane_svg_left.add_coord(-0.40 * self.vw, thick)
        self.airplane_svg_left.add_coord(-0.2 * self.vw - thick, thick)
        self.airplane_svg_left.add_coord(-0.2 * self.vw - thick,
                                         thick + 0.08 * self.vw)
        self.airplane_svg_left.add_coord(-0.2 * self.vw,
                                         thick + 0.08 * self.vw)
        self.airplane_svg_left.add_coord(-0.2 * self.vw, 0.08 * self.vw)

        self.airplane_svg_right = gui.SvgPolygon(8)
        self.airplane_svg_right.set_fill('gray')
        self.airplane_svg_right.set_stroke(0.005 * self.vw, 'black')
        self.airplane_svg_right.add_coord(0.2 * self.vw, 0 * self.vw)  #25x8
        self.airplane_svg_right.add_coord(0.40 * self.vw, 0 * self.vw)
        self.airplane_svg_right.add_coord(0.40 * self.vw, thick)
        self.airplane_svg_right.add_coord(0.2 * self.vw + thick, thick)
        self.airplane_svg_right.add_coord(0.2 * self.vw + thick,
                                          thick + 0.08 * self.vw)
        self.airplane_svg_right.add_coord(0.2 * self.vw,
                                          thick + 0.08 * self.vw)
        self.airplane_svg_right.add_coord(0.2 * self.vw, 0.08 * self.vw)

        self.airplane_svg_center = gui.SvgRectangle(-0.02 * self.vw,
                                                    -0.02 * self.vw,
                                                    0.04 * self.vw,
                                                    0.04 * self.vw)
        self.airplane_svg_center.set_fill('white')
        self.airplane_svg_center.set_stroke(0.005 * self.vw, 'lightgray')

        self.append([
            self.airplane_svg_left, self.airplane_svg_right,
            self.airplane_svg_center
        ])

        #self.generate_orientation_indicator()
        self.orientation_tape = OrientationTapeHorizontal(
            0, 0.4 * self.vh, 0.8 * self.vw, 1.0 * self.vh)
        self.append(self.orientation_tape)

        self.set_skid_slip(0)
Esempio n. 13
0
    def __init__(self, x_pos, y_pos, wide, high, *args, **kwargs):
        """ x_pos and y_pos are coordinates indicated by the pointer, generally at the center of the shown tape
        """
        gui.SvgGroup.__init__(self, *args, **kwargs)

        self.wide = wide
        self.high = high

        self.attributes['transform'] = 'translate(%s %s)' % (x_pos, y_pos)

        #it is used a subcontainer in order to show only a part of the entire tape
        self.subcontainer = gui.SvgSubcontainer(-wide / 2, 0, wide, high)
        self.subcontainer.set_viewbox(-self.scale_length_visible / 2, 0,
                                      self.scale_length_visible,
                                      high * (high / wide))
        self.append(self.subcontainer)

        #horizontal line along all the tape size
        self.group_orientation_indicator = gui.SvgGroup()
        line = gui.SvgLine(-self.scale_length / 2, 0, self.scale_length / 2, 0)
        line.set_stroke(0.005 * high, 'white')
        self.group_orientation_indicator.append(line)

        #creating labels
        labels = {0: 'N', 90: 'E', 180: 'S', 270: 'W'}
        labels_size = {0: 1.0, 90: 1.0, 180: 1.0, 270: 1.0}
        for i in range(0, 36 + 1, 2):
            if not (i * 10) in labels.keys():
                labels[i * 10] = "%02d" % i
                labels_size[i * 10] = 0.7

        for angle in range(int(-self.scale_length / 2),
                           int(self.scale_length / 2) + 1):
            if angle % 360 in labels.keys():
                x = angle
                y = 0.05 * self.high * labels_size[angle % 360]
                line = gui.SvgLine(x, 0, x, y)
                line.set_stroke(1, 'white')
                self.group_orientation_indicator.append(line)

                txt = gui.SvgText(x, y, labels.get(angle % 360, ''))
                txt.attr_dominant_baseline = 'hanging'
                txt.attr_text_anchor = 'middle'
                txt.set_fill('white')
                txt.css_font_size = gui.to_pix(7 * labels_size[angle % 360])
                txt.css_font_weight = 'bolder'
                self.group_orientation_indicator.append(txt)
        self.subcontainer.append(self.group_orientation_indicator)
        #self.group_orientation_indicator.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)

        self.orientation_pointer = gui.SvgPolygon(3)
        self.orientation_pointer.set_fill('red')
        self.orientation_pointer.set_stroke(0.005 * self.scale_length_visible,
                                            'black')
        self.orientation_pointer.add_coord(-0.01 * self.scale_length_visible,
                                           -0.02 * self.high)
        self.orientation_pointer.add_coord(0.0 * self.scale_length_visible,
                                           0.0 * self.high)
        self.orientation_pointer.add_coord(0.01 * self.scale_length_visible,
                                           -0.02 * self.high)
        #self.orientation_pointer.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)
        self.append(self.orientation_pointer)

        self.orientation_value = gui.SvgText(0, -0.03 * high,
                                             "%d" % (self.orientation % 360))
        self.orientation_value.attr_dominant_baseline = 'auto'
        self.orientation_value.attr_text_anchor = 'middle'
        self.orientation_value.set_fill('white')
        self.orientation_value.css_font_size = gui.to_pix(
            0.03 * self.scale_length_visible)
        self.orientation_value.css_font_weight = 'bolder'
        #orientation_value.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)
        self.append(self.orientation_value)
Esempio n. 14
0
    def __init__(self,
                 x_pos,
                 y_pos,
                 wide,
                 high,
                 left_side,
                 scale_length,
                 scale_length_visible,
                 tape_white_min=0,
                 tape_white_max=0,
                 tape_green_min=0,
                 tape_green_max=0,
                 *args,
                 **kwargs):
        """ x_pos and y_pos are coordinates indicated by the pointer, generally at the center of the shown tape
        """
        gui.SvgGroup.__init__(self, *args, **kwargs)

        self.scale_length = scale_length
        self.scale_length_visible = scale_length_visible

        self.wide = wide
        self.high = high

        self.indicator_size = self.wide * 0.2
        self.left_side = left_side

        self.tape_white_min = tape_white_min
        self.tape_white_max = tape_white_max

        self.tape_green_min = tape_green_min
        self.tape_green_max = tape_green_max

        self.attributes['transform'] = 'translate(%s %s)' % (x_pos, y_pos)

        #it is used a subcontainer in order to show only a part of the entire tape
        self.subcontainer = gui.SvgSubcontainer(-wide if self.left_side else 0,
                                                -self.high / 2, wide, high)
        self.subcontainer.set_viewbox(-self.wide / 2,
                                      -self.scale_length_visible / 2, wide,
                                      self.scale_length_visible)
        self.append(self.subcontainer)

        self.group_indicator = gui.SvgGroup()

        self.group_scale = gui.SvgGroup()
        self.build_scale()

        self.group_indicator.append(self.group_scale)

        self.subcontainer.append(self.group_indicator)

        #self.group_indicator.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)

        self.pointer = gui.SvgPolygon(5)
        self.pointer.set_fill('black')
        self.pointer.set_stroke(0.02 * self.scale_length_visible, 'red')
        direction = (-1 if self.left_side else 1)
        pointer_x = 0  #(-self.wide if self.left_side else 0)
        pointer_width = self.wide
        self.pointer.add_coord(pointer_x, 0)
        self.pointer.add_coord(pointer_x + ((0.2 * self.wide) * direction),
                               0.2 * self.wide)
        self.pointer.add_coord(pointer_x + pointer_width * direction,
                               0.2 * self.wide)
        self.pointer.add_coord(pointer_x + pointer_width * direction,
                               -0.2 * self.wide)
        self.pointer.add_coord(pointer_x + ((0.2 * self.wide) * direction),
                               -0.2 * self.wide)
        #self.pointer.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)
        self.append(self.pointer)

        self.pointer_value = gui.SvgText(
            ((0 - self.indicator_size) if self.left_side else
             (self.wide - 0.05 * self.wide)), 0, "%d" % (self.value % 360))
        self.pointer_value.attr_dominant_baseline = 'middle'
        self.pointer_value.attr_text_anchor = 'end' if self.left_side else 'end'
        self.pointer_value.set_fill('lime')
        self.pointer_value.css_font_size = gui.to_pix(0.3 * self.wide)
        self.pointer_value.css_font_weight = 'bolder'
        #self.pointer_value.attributes['transform'] = 'translate(0 %s)'%(self.vh/2-0.11*self.vh)
        self.append(self.pointer_value)

        if self.tape_green_max > 0:
            green_and_red_tape_width = self.wide
            white_tape_width = 3
            tape_green = gui.SvgRectangle(
                -self.wide / 2, -self.tape_green_max, green_and_red_tape_width,
                (self.tape_green_max - self.tape_green_min))
            tape_green.set_fill('green')
            self.group_scale.add_child('tape_green', tape_green)
        if self.tape_white_max > 0:
            tape_white = gui.SvgRectangle(
                (self.wide / 2 -
                 white_tape_width if self.left_side else -self.wide / 2),
                -self.tape_white_max, white_tape_width,
                (self.tape_white_max - self.tape_white_min))
            tape_white.set_fill('white')
            self.group_scale.add_child('tape_white', tape_white)
        if self.tape_green_max > 0:
            tape_red = gui.SvgRectangle(
                -self.wide / 2, -self.scale_length, green_and_red_tape_width,
                (self.scale_length - self.tape_green_max))
            tape_red.set_fill('red')
            self.group_scale.add_child('tape_red', tape_red)
Esempio n. 15
0
    def __init__(self,
                 epics_pv_name='',
                 min_value=0,
                 max_value=100,
                 *args,
                 **kwargs):
        w = kwargs.get("style", {}).get("width", kwargs.get("width", 100))
        h = kwargs.get("style", {}).get("height", kwargs.get("height", 100))
        if 'width' in kwargs.keys():
            del kwargs["width"]
        if 'height' in kwargs.keys():
            del kwargs["height"]
        default_style = {'position': 'absolute', 'left': '10px', 'top': '10px'}
        default_style.update(kwargs.get('style', {}))
        kwargs['style'] = default_style
        super(EPICSValueGaugeWidget, self).__init__(w, h, *args, **kwargs)
        self.epics_pv_name = epics_pv_name

        #the indicator
        self.indicator = gui.SvgPolygon(_maxlen=4)
        self.indicator.set_stroke(width=0.001, color='red')
        self.indicator.set_fill('red')

        indicator_pin_radius = 0.05
        self.indicator_pin = gui.SvgCircle(0, 0.5, indicator_pin_radius)
        self.indicator_pin.set_fill('black')

        #the value signs
        scale = max_value - min_value
        radius_min = 0.4
        radius_max = 0.5
        for i in range(0, 10):
            angle = math.pi / 9 * i
            #sign = gui.SvgLine(math.cos(angle)*radius_min, radius_max-math.sin(angle)*radius_min, math.cos(angle)*radius_max, radius_max-math.sin(angle)*radius_max)
            sign = gui.SvgLine(
                math.cos(angle) * (radius_min - 0.01 + 0.1 * (i + 1) / 10),
                radius_max - math.sin(angle) * (radius_min - 0.01 + 0.1 *
                                                (i + 1) / 10),
                math.cos(angle) * radius_max,
                radius_max - math.sin(angle) * radius_max)
            sign.set_stroke(0.01, 'black')
            self.append(sign)

        #subindicators value signs
        scale = max_value - min_value
        radius_min = 0.4
        radius_max = 0.5
        for i in range(0, 100):
            angle = math.pi / 99 * i
            #sign = gui.SvgLine(math.cos(angle)*radius_min, radius_max-math.sin(angle)*radius_min, math.cos(angle)*radius_max, radius_max-math.sin(angle)*radius_max)
            sign = gui.SvgLine(
                math.cos(angle) * (radius_min - 0.01 + 0.1 * (i + 10) / 100),
                radius_max - math.sin(angle) * (radius_min - 0.01 + 0.1 *
                                                (i + 10) / 100),
                math.cos(angle) * radius_max,
                radius_max - math.sin(angle) * radius_max)
            sign.set_stroke(0.002, 'black')
            self.append(sign)

        font_size = 0.1
        self.text_min_value = gui.SvgText(-radius_max, 0.5 + font_size + 0.01,
                                          str(min_value))
        self.text_min_value.style['font-size'] = gui.to_pix(font_size)
        self.text_min_value.style['text-anchor'] = "start"

        self.text_max_value = gui.SvgText(radius_max, 0.5 + font_size + 0.01,
                                          str(max_value))
        self.text_max_value.style['font-size'] = gui.to_pix(font_size)
        self.text_max_value.style['text-anchor'] = "end"

        self.text_actual_value = gui.SvgText(
            0, 0.5 + indicator_pin_radius + font_size + 0.01, str(max_value))
        self.text_actual_value.style['font-size'] = gui.to_pix(font_size)
        self.text_actual_value.style['text-anchor'] = "middle"
        self.text_actual_value.style['font-weight'] = 'bold'

        self.min_value = min_value
        self.max_value = max_value

        self.append([
            self.indicator, self.indicator_pin, self.text_min_value,
            self.text_max_value, self.text_actual_value
        ])

        self.set_viewbox(-0.5, 0, 1, 0.70)
        self.value = self.min_value