def __init__(self, width, height):
        super(JoystickWidget, self).__init__(width, height)
        self.width = width
        self.height = height
        # self.maxDragLength = min(width, height)/3.0*2.0
        self.maxDragLength = min(width, height) / 3.0
        self.startPointIndicator = gui.SvgCircle(0, 0, 20)
        self.startPointIndicator.set_fill('rgb(255,200,50)')
        self.startPointIndicator.set_stroke(1, 'white')
        self.endPointIndicator = gui.SvgCircle(0, 0, 10)
        self.endPointIndicator.set_fill('rgb(200,255,50)')
        self.endPointIndicator.set_stroke(1, 'white')
        self.pathLine = gui.SvgLine(0, 0, 0, 0)
        self.startX = 0
        self.startY = 0
        self.append('path_line', self.pathLine)
        self.append('start_point', self.startPointIndicator)
        self.append('end_point', self.endPointIndicator)
        self.drag_state = False
        self.set_on_mouseup_listener(self, 'mouseup')
        self.set_on_mousedown_listener(self, 'mousedown')
        self.set_on_mousemove_listener(self, 'mousemove')
        self.set_on_touchend_listener(self, 'mouseup')
        self.set_on_touchstart_listener(self, 'mousedown')
        self.set_on_touchmove_listener(self, 'mousemove')

        self.EVENT_ONMOVE = "ONJOYSTICKMOVE"
        self.reset_joystick(0, 0)
Beispiel #2
0
    def main(self, game):
        self.game = game
        self.last_known_turn = self.game.turn

        width, height = 800, 600  # Set board width and height

        svg = gui.Svg(width=width, height=height)
        svg.style['background-color'] = 'yellow'
        r = 35  # Set radius of slots
        ys = np.round(np.linspace(2 * r, height - 2 * r,
                                  self.game.dim[0])).astype(int)
        xs = np.round(np.linspace(2 * r, width - 2 * r,
                                  self.game.dim[1])).astype(int)
        self.grid = np.empty(self.game.dim, dtype='object')
        for rowi, y in enumerate(ys):
            for coli, x in enumerate(xs):
                circ = gui.SvgCircle(x=x, y=y, radius=r)  # Create slot
                circ.style['stroke'] = 'black'  # Set color of slot outline
                circ.style['fill'] = 'white'  # Set color of empty slot
                circ.onclick.do(self.on_click, pos=(rowi, coli))
                svg.append(circ)  # Add slot to GUI
                self.grid[rowi, coli] = circ

        self.text = gui.Label('')
        self.reset_button = gui.Button('Reset Game')
        self.reset_button.onclick.connect(self.reset)

        self.ended = False
        threading.Thread(target=self.update_thread).start()

        container = gui.VBox(width=width, height=height)
        container.append(svg)
        container.append(self.text)
        container.append(self.reset_button)
        return container
    def makeField(self, imageURL, drawPoints):
        self.fieldSvg.set_viewbox(0, 0, self.fieldWidth, self.fieldHeight)
        self.fieldSvg.set_size(self.fieldWidth, self.fieldHeight)
        self.fieldSvg.set_on_mousedown_listener(self.mouse_down_listener)

        self.image = gui.SvgImage(imageURL, 0, 0, self.fieldWidth,
                                  self.fieldHeight)
        self.fieldSvg.append(self.image)

        if drawPoints:
            self.targetPoints = coordinates.targetPoints
            for point in self.targetPoints:
                point = fieldToSvgCoordinates(point.x, point.y,
                                              self.fieldWidth,
                                              self.fieldHeight,
                                              self.fieldPixelsPerFoot)
                wp_dot = gui.SvgCircle(point[0], point[1], 5)
                wp_dot.attributes['fill'] = 'green'
                self.fieldSvg.append(wp_dot)

        self.cursorArrow = Arrow('red', self.fieldWidth, self.fieldHeight,
                                 self.fieldPixelsPerFoot)
        self.fieldSvg.append(self.cursorArrow)

        self.robotArrow = Arrow('green', self.fieldWidth, self.fieldHeight,
                                self.fieldPixelsPerFoot)
        self.fieldSvg.append(self.robotArrow)
Beispiel #4
0
    def initFieldMap(self, robot):
        fieldBox = self.sectionBox()

        robotBox = gui.HBox()
        fieldBox.append(robotBox)

        setPositionBtn = gui.Button("Set Robot to Cursor")
        setPositionBtn.onclick.connect(self.c_setRobotPosition)
        robotBox.append(setPositionBtn)

        def setRobotAngle(button, angle):
            pathFollower = self.robot.pathFollower
            pathFollower.setPosition(pathFollower.robotX, pathFollower.robotY,
                                     angle)

        leftBtn = gui.Button('<')
        leftBtn.onclick.connect(setRobotAngle, math.radians(90))
        robotBox.append(leftBtn)
        rightBtn = gui.Button('>')
        rightBtn.onclick.connect(setRobotAngle, math.radians(-90))
        robotBox.append(rightBtn)
        upBtn = gui.Button('^')
        upBtn.onclick.connect(setRobotAngle, 0)
        robotBox.append(upBtn)
        downBtn = gui.Button('v')
        downBtn.onclick.connect(setRobotAngle, math.radians(180))
        robotBox.append(downBtn)

        self.fieldSvg = gui.Svg(CompetitionBotDashboard.FIELD_WIDTH,
                                CompetitionBotDashboard.FIELD_HEIGHT)
        self.fieldSvg.set_on_mousedown_listener(self.mouse_down_listener)
        fieldBox.append(self.fieldSvg)

        self.image = gui.SvgShape(0, 0)
        self.image.type = 'image'
        self.image.attributes['width'] = CompetitionBotDashboard.FIELD_WIDTH
        self.image.attributes['height'] = CompetitionBotDashboard.FIELD_HEIGHT
        self.image.attributes['xlink:href'] = '/res:frcField.PNG'
        self.fieldSvg.append(self.image)

        self.targetPoints = coordinates.targetPoints
        for point in self.targetPoints:
            point = fieldToSvgCoordinates(point.x, point.y)
            wp_dot = gui.SvgCircle(point[0], point[1], 5)
            wp_dot.attributes['fill'] = 'blue'
            self.fieldSvg.append(wp_dot)

        self.cursorArrow = Arrow('red')
        self.fieldSvg.append(self.cursorArrow)

        self.robotArrow = Arrow('green')
        self.fieldSvg.append(self.robotArrow)

        self.robotPathLines = []

        return fieldBox
Beispiel #5
0
 def add_coord(self, x, y):
     """ Adds a coord to the polyline and creates another circle
     """
     x = x * self.x_factor
     y = y * self.y_factor
     self.plotData.add_coord(x, y)
     self.circles_list.append(gui.SvgCircle(x, y, self.circle_radius))
     self.append(self.circles_list[-1])
     if len(self.circles_list) > self.maxlen:
         self.remove_child(self.circles_list[0])
         del self.circles_list[0]
Beispiel #6
0
 def test_init(self):
     widget = gui.SvgCircle(10, 10, 10)
     assertValidHTML(widget.repr())
Beispiel #7
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)
Beispiel #8
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