def _update_grid(self):
        # Horizontal
        helper.unlink_node_list(self._x_grid)
        self._x_grid = []

        if self._x_axis:
            tick_posns = self._x_axis.get_tick_posns()
            y_max = self._data_div.height
            for x in tick_posns:
                node = avg.LineNode(pos1=(x, 0),
                                    pos2=(x, y_max),
                                    color=global_values.COLOR_BACKGROUND,
                                    parent=self._grid_div)
                self._x_grid.append(node)

        # Vertical
        helper.unlink_node_list(self._y_grid)
        self._y_grid = []

        if self._y_axis:
            tick_posns = self._y_axis.get_tick_posns()
            x_max = self._data_div.width
            for y in tick_posns:
                node = avg.LineNode(pos1=(0, y),
                                    pos2=(x_max, y),
                                    color=global_values.COLOR_BACKGROUND,
                                    parent=self._grid_div)
                self._y_grid.append(node)
Beispiel #2
0
    def _draw_vertical_aid_line(self, pos, with_outer=True):
        """
        Draws a vertical aid line.

        :param pos: The position of the cursor.
        :type pos: tuple[float, float]
        :param with_outer: If the outer part of the line should be drawn.
        :type with_outer: bool
        :return: The created aid line.
        :rtype: InteractiveDivNode
        """
        aid_line = InteractiveDivNode(parent=self._aid_lines_div,
                                      pos=(pos[0], 0))
        if with_outer:
            avg.LineNode(parent=aid_line,
                         pos1=(0, self._aid_line_area[1] -
                               self._aid_line_config.extra_length),
                         pos2=(0, self._aid_line_area[3] +
                               self._aid_line_config.extra_length),
                         color=self._aid_line_config.color,
                         opacity=self._aid_line_config.outer_line_opacity,
                         strokewidth=self._aid_line_config.outer_line_width)
        avg.LineNode(
            parent=aid_line,
            pos1=(0,
                  self._aid_line_area[1] - self._aid_line_config.extra_length),
            pos2=(0,
                  self._aid_line_area[3] + self._aid_line_config.extra_length),
            color=self._aid_line_config.color,
            strokewidth=self._aid_line_config.inner_line_width)

        return aid_line
Beispiel #3
0
    def __init__(self, event, **kwargs):
        BaseTouchVisualization.__init__(self, event, **kwargs)
        self.positions = [event.pos]

        if event.source == avg.Event.TOUCH:
            color = 'e5d8d8'
        elif event.source == avg.Event.TANGIBLE:
            color = 'ffe0e0'
        else:
            color = 'd8e5e5'
            self.opacity = 0.5

        self.__transparentCircle = avg.CircleNode(r=self._radius + 20,
                                                  fillcolor=color,
                                                  fillopacity=0.2,
                                                  opacity=0.0,
                                                  strokewidth=1,
                                                  sensitive=False,
                                                  parent=self)
        self.__pulsecircle = avg.CircleNode(r=self._radius,
                                            fillcolor=color,
                                            color=color,
                                            fillopacity=0.5,
                                            opacity=0.5,
                                            strokewidth=1,
                                            sensitive=False,
                                            parent=self)
        if event.source in [avg.Event.TOUCH, avg.Event.TRACK]:
            self.__majorAxis = avg.LineNode(pos1=(0, 0),
                                            pos2=event.majoraxis,
                                            color='FFFFFF',
                                            sensitive=False,
                                            parent=self)
            self.__minorAxis = avg.LineNode(pos1=(0, 0),
                                            pos2=event.minoraxis,
                                            color='FFFFFF',
                                            sensitive=False,
                                            parent=self)
        if event.source == avg.Event.TOUCH:
            self.__handAxis = avg.LineNode(pos1=(0, 0),
                                           pos2=self.__getHandVector(event),
                                           opacity=0.5,
                                           color='A0FFA0',
                                           sensitive=False,
                                           parent=self)
        fontPos = avg.Point2D(self.__pulsecircle.r, 0)

        self.__textNode = avg.WordsNode(pos=fontPos, fontsize=9, parent=self)
        self.motionPath = avg.PolyLineNode(pos=self.positions,
                                           opacity=0.7,
                                           color=color,
                                           parent=kwargs['parent'])
        self.motionVector = avg.LineNode(pos1=(0, 0),
                                         pos2=-event.contact.motionvec,
                                         opacity=0.4,
                                         parent=self)
        pulseCircleAnim = avg.LinearAnim(self.__pulsecircle, 'r', 200, 50,
                                         self._radius)
        pulseCircleAnim.start()
    def __init__(self, parent=None, **kwargs):
        super(CrossCursor, self).__init__(**kwargs)
        self.registerInstance(self, parent)

        color = self.colors['Healthy']
        if 'Bumpy' in self._device.rui_proxy_name:
            color = self.colors['Bumpy']

        if 'Bumpy' not in self._device.rui_proxy_name:
            avg.CircleNode(parent=self,
                           r=self.circle_size,
                           strokewidth=self.circle_bg_width,
                           fillopacity=0,
                           color=color['bg'],
                           opacity=self.bg_opacity)
            avg.CircleNode(parent=self,
                           r=self.circle_size,
                           strokewidth=self.circle_width,
                           fillopacity=0,
                           color=self.circle_color)
        else:
            w = self.circle_size * 1.75
            hW = w * .5
            avg.RectNode(parent=self,
                         size=(w, w),
                         pos=(-hW, -hW),
                         strokewidth=self.circle_bg_width,
                         fillopacity=0,
                         color=color['bg'],
                         opacity=self.bg_opacity)
            avg.RectNode(parent=self,
                         size=(w, w),
                         pos=(-hW, -hW),
                         strokewidth=self.circle_width,
                         fillopacity=0,
                         color=self.circle_color)

        # draw cross
        diff = (self.cross_bg_width - self.cross_width) * .5
        avg.LineNode(parent=self,
                     pos1=(-self.cross_half_length + diff, 0),
                     pos2=(-self.cross_center_offset - diff, 0),
                     strokewidth=self.cross_width,
                     color=color['fc'])
        avg.LineNode(parent=self,
                     pos1=(self.cross_half_length - diff, 0),
                     pos2=(self.cross_center_offset + diff, 0),
                     strokewidth=self.cross_width,
                     color=color['fc'])
        avg.LineNode(parent=self,
                     pos1=(0, -self.cross_half_length + diff),
                     pos2=(0, -self.cross_center_offset - diff),
                     strokewidth=self.cross_width,
                     color=color['fc'])
        avg.LineNode(parent=self,
                     pos1=(0, self.cross_half_length - diff),
                     pos2=(0, self.cross_center_offset + diff),
                     strokewidth=self.cross_width,
                     color=color['fc'])
Beispiel #5
0
 def testParaWords(self):
     root = self.loadEmptyScene()
     avg.LineNode(pos1=(0.5, 0),
                  pos2=(0.5, 50),
                  color="FF0000",
                  parent=root)
     avg.LineNode(pos1=(119.5, 0.5),
                  pos2=(119.5, 50),
                  color="FF0000",
                  parent=root)
     avg.LineNode(pos1=(74.5, 60),
                  pos2=(74.5, 110),
                  color="FF0000",
                  parent=root)
     avg.WordsNode(id="para",
                   pos=(1, 1),
                   fontsize=12,
                   width=70,
                   font="Bitstream Vera Sans",
                   variant="Roman",
                   text="Left-justified paragraph.",
                   parent=root)
     avg.WordsNode(id="paracenter",
                   pos=(120, 1),
                   fontsize=12,
                   width=70,
                   font="Bitstream Vera Sans",
                   variant="Roman",
                   text="Centered paragraph",
                   alignment="center",
                   parent=root)
     avg.WordsNode(id="pararight",
                   pos=(75, 60),
                   fontsize=12,
                   width=70,
                   font="Bitstream Vera Sans",
                   variant="Roman",
                   alignment="right",
                   text="Right-justified paragraph.<i>l</i>",
                   parent=root)
     avg.WordsNode(id="paralinespacing",
                   pos=(80, 60),
                   fontsize=12,
                   width=70,
                   font="Bitstream Vera Sans",
                   variant="Roman",
                   linespacing=-4,
                   text="Paragraph with custom line spacing.",
                   parent=root)
     self.start(True, [lambda: self.compareImage("testParaWords")])
    def __create_display_borders(self):
        parent = self.__plot_div
        for i in range(1, 3):
            y = i / 3. * parent.height
            avg.LineNode(pos1=(0, y),
                         pos2=(parent.width, y),
                         color=global_values.COLOR_BACKGROUND,
                         parent=parent)

        for i in range(1, 4):
            x = i / 4. * parent.width
            avg.LineNode(pos1=(x, 0),
                         pos2=(x, parent.height),
                         color=global_values.COLOR_BACKGROUND,
                         parent=parent)
Beispiel #7
0
    def __create_phase_lines(self, session):
        """
        Create lines for the different phases in the session. Green ones for the start of a phase and red ones for the
        end.

        :param session: The session this phase lines should represent.
        :type session: Session
        """
        config = helper.get_config(session.session_num)
        if config is None:
            return

        # Get all the times of all phases and creates a line for each one.
        for start, end in config.phase_timestamps.itervalues():
            start = helper.csvtime_to_float(session.date,
                                            start) - session.start_time
            end = helper.csvtime_to_float(session.date,
                                          end) - session.start_time

            for time, color in [(start, global_values.COLOR_PHASE_GREEN),
                                (end, global_values.COLOR_PHASE_RED)]:
                pos_x = (time / self.__duration) * self.__time_slider.width
                line_node = avg.LineNode(color=color,
                                         pos1=(pos_x, 25),
                                         pos2=(pos_x, 48),
                                         strokewidth=2,
                                         opacity=0.8,
                                         active=True,
                                         parent=self.__time_bar)
                self.__phase_lines[time] = line_node
Beispiel #8
0
    def __init__(self,
                 cfg,
                 width=0,
                 range=(0., 1.),
                 thumbPos=0.0,
                 parent=None,
                 **kwargs):
        super(IntervalSliderBase, self).__init__(**kwargs)
        self.registerInstance(self, parent)

        self.__i_line = avg.LineNode(strokewidth=3,
                                     color=global_values.COLOR_SECONDARY,
                                     parent=self,
                                     pos1=(0, 16),
                                     pos2=(width, 16))

        self.publish(IntervalSliderBase.THUMB_POS_CHANGED)
        self.publish(IntervalSliderBase.PRESSED)
        self.publish(IntervalSliderBase.RELEASED)

        self._initThumb(cfg)

        self._range = range
        self._thumbPos = thumbPos

        self.subscribe(self.SIZE_CHANGED,
                       lambda newSize: self._positionNodes())
        self.size = (width, 20)

        self.__recognizer = gesture.DragRecognizer(
            self._thumbNode,
            friction=-1,
            detectedHandler=self.__onDragStart,
            moveHandler=self.__onDrag,
            upHandler=self.__onUp)
Beispiel #9
0
    def __init__(self, userid, pos, viewpt, parent, **kwargs):
        super(UserNode, self).__init__(**kwargs)
        self.registerInstance(self, parent)

        color = vis_params.VisParams.get_user_color(userid)

        end_pos = avg.Point2D(viewpt)
        if (end_pos-pos).getNorm() > 200:
            dir = (end_pos-pos).getNormalized()
            end_pos = pos + dir*200
        avg.LineNode(
            pos1=pos,
            pos2=end_pos,
            color=color,
            parent=self,
            strokewidth=2
        )
        avg.CircleNode(
            pos=pos,
            r=6,
            fillopacity=1,
            color=color,
            fillcolor="000000",
            parent=self
        )
        avg.WordsNode(
            parent=self,
            pos=(pos[0], pos[1] + 6 + 2),
            fontsize=11,
            color=color,
            rawtextmode=True,
            text=str(userid),
            alignment='center'
        )
    def _draw_grid_lines(self, axis):
        """
        Draws the grid lines in this chart.

        :param axis: The axis the grid lines are connected with.
        :type axis: ChartAxis
        """
        if axis.show_grid_lines is GridLines.Nothing:
            return

        positions = axis.tick_positions if axis.show_grid_lines is GridLines.Ticks else axis.marking_positions
        for pos in positions:
            if axis.orientation is Orientation.Horizontal:
                y_axis = self.vertical_axis_views.values()[0]
                pos1 = pos + self._chart_config.padding_left, y_axis.pos[1]
                pos2 = pos + self._chart_config.padding_left, axis.pos[
                    1] - self._axis_cross_offset
            else:
                x_axis = self.horizontal_axis_views.values()[0]
                pos1 = x_axis.pos[
                    0] + self._axis_cross_offset, pos + self._chart_config.padding_top
                pos2 = x_axis.pos[
                    0] + x_axis.axis_length - self._axis_cross_offset, pos + self._chart_config.padding_top

            avg.LineNode(parent=self._grid_lines_div,
                         strokewidth=TwoAxisChartDefaults.GRID_LINE_WIDTH,
                         color=TwoAxisChartDefaults.GRID_LINE_COLOR,
                         opacity=TwoAxisChartDefaults.GRID_LINE_OPACITY,
                         pos1=pos1,
                         pos2=pos2)
Beispiel #11
0
    def testColorParse(self):
        def setColor(colorName):
            node.color = colorName

        node = avg.LineNode(pos1=(0.5, 0), pos2=(0.5, 50), color="FF0000")
        setColor("ff00ff")
        self.assertRaises(avg.Exception, lambda: setColor("foo"))
        self.assertRaises(avg.Exception, lambda: setColor("ff00f"))
        self.assertRaises(avg.Exception, lambda: setColor("ff00ffx"))
        self.assertRaises(avg.Exception, lambda: setColor("ff00fx"))
Beispiel #12
0
    def _create_ticks_view(self):
        """
        Creates the view for all ticks with possible markings.
        """
        tick_positions = self._calc_tick_positions()
        left_overhang = self._axis_config.tick_overhang if self._axis_config.tick_side is not TickSide.Right else 0
        right_overhang = self._axis_config.tick_overhang if self._axis_config.tick_side is not TickSide.Left else 0

        # Variables to calculate the size of the whole axis.
        max_marking_size = float('-inf'), float('-inf')

        count = 0
        for pos_value, marking in tick_positions:
            # Check in which direction the axis should go:
            # Decide where a line starts and ends.
            if self._axis_config.axis_orientation is Orientation.Vertical:
                pos1 = -left_overhang, pos_value
                pos2 = right_overhang, pos_value
            else:
                pos_value = self._axis_length - pos_value
                pos1 = pos_value, -left_overhang
                pos2 = pos_value, right_overhang

            # Create the tick.
            avg.LineNode(parent=self._axis_and_tick_div,
                         pos1=pos1,
                         pos2=pos2,
                         color=self._axis_config.axis_color,
                         strokewidth=self._axis_config.tick_width)

            if marking:
                value = self._generate_axis_marking_value(count)
                marking = self._create_marking_view(pos1, pos2, value)
                max_marking_size = (
                    marking.size[0] if marking.size[0] > max_marking_size[0]
                    else max_marking_size[0],
                    marking.size[1] if marking.size[1] > max_marking_size[1]
                    else max_marking_size[1])
                self._marking_positions.append(pos_value)
                self._markings[value] = marking

            self._tick_positions.append(pos_value)
            count += 1
        self._tick_positions = sorted(self._tick_positions)
        self._marking_positions = sorted(self._marking_positions)

        # Set the size for this axis.
        if self._axis_config.axis_orientation is Orientation.Vertical:
            self.__axis_size = (self.__axis_size[0] + max_marking_size[0] + 2 *
                                (self._axis_config.tick_overhang - 1),
                                self.__axis_size[1])
        else:
            self.__axis_size = (self.__axis_size[0],
                                self.__axis_size[1] + max_marking_size[1] + 2 *
                                (self._axis_config.tick_overhang - 1))
Beispiel #13
0
 def setupPlayground(self):
     # libavg setup        
     self.display = avg.DivNode(parent=self._parentNode, size=self._parentNode.size)
     self.renderer = Renderer()     
     background = avg.ImageNode(parent=self.display)
     background.setBitmap(self.backgroundpic) 
     self.display.player = None
     (displayWidth, displayHeight) = self.display.size
     widthThird = (int)(displayWidth / 3)
     fieldSize = (widthThird, displayHeight)
     self.field1 = avg.DivNode(parent=self.display, size=fieldSize)
     self.field2 = avg.DivNode(parent=self.display, size=fieldSize, pos=(displayWidth - widthThird, 0))
     avg.LineNode(parent=self.display, pos1=(0, 1), pos2=(displayWidth, 1))
     avg.LineNode(parent=self.display, pos1=(0, displayHeight), pos2=(displayWidth, displayHeight))   
     self.lines.createImageNode('layer1', dict(parent=self.display, pos=(widthThird, 0)), (2, displayHeight))
     self.lines.createImageNode('layer1', dict(parent=self.display, pos=(displayWidth - widthThird, 0)), (2, displayHeight))  
     # pybox2d setup
     self.world = b2World(gravity=(0, 0), doSleep=True)
     self.hitset = set()
     self.listener = ContactListener(self.hitset)
     self.world.contactListener = self.listener
     self.running = True
     pointsToWin = 999 if self.tutorialMode else config.pointsToWin
     self.leftPlayer, self.rightPlayer = Player(self, self.field1, pointsToWin), Player(self, self.field2, pointsToWin)
     self.leftPlayer.other, self.rightPlayer.other = self.rightPlayer, self.leftPlayer    
     # horizontal lines
     BorderLine(self.world, a2w((0, 1)), a2w((displayWidth, 1)), 1, False, 'redball')
     BorderLine(self.world, a2w((0, displayHeight)), a2w((displayWidth, displayHeight)), 1, False, 'redball')
     # vertical ghost lines
     maxWallHeight = brickSize * brickLines * PPM
     BorderLine(self.world, a2w((maxWallHeight, 0)), a2w((maxWallHeight, displayHeight)), 1, False, 'redball', 'ball') 
     BorderLine(self.world, a2w((displayWidth - maxWallHeight - 1, 0)), a2w((displayWidth - maxWallHeight - 1, displayHeight)), 1, False, 'redball', 'ball')
     self.middleX, self.middleY = self.display.size / 2
     self.middle = a2w((self.middleX, self.middleY))
     BatManager(self.field1, self.world, self.renderer)
     BatManager(self.field2, self.world, self.renderer)
     self.bonus = None
     self.balls = []
     self.redballs = []
     self.towers = []
     self.ghosts = []
     self.mainLoop = g_player.setOnFrameHandler(self.step)
Beispiel #14
0
    def _create_axis_view(self):
        """
        Creates the view for the axis and the touch able background.
        """
        if self._axis_config.axis_background_side is TickSide.Left:
            left_overhang = self._axis_config.axis_background_size
            right_overhang = 0
        elif self._axis_config.axis_background_side is TickSide.Right:
            left_overhang = 0
            right_overhang = self._axis_config.axis_background_size
        else:
            left_overhang = self._axis_config.axis_background_size / 2
            right_overhang = self._axis_config.axis_background_size / 2

        # # Check in which direction the axis should go:
        # # Set the end position of the axis.
        if self._axis_config.axis_orientation is Orientation.Vertical:
            axis_pos2 = 0, self._axis_length
            background_pos1 = (right_overhang - left_overhang) / 2, 0
            background_pos2 = (right_overhang -
                               left_overhang) / 2, self.axis_length
        else:
            axis_pos2 = self._axis_length, 0
            background_pos1 = 0, (right_overhang - left_overhang) / 2
            background_pos2 = self._axis_length, (right_overhang -
                                                  left_overhang) / 2

        avg.LineNode(parent=self._axis_and_tick_div,
                     pos1=background_pos1,
                     pos2=background_pos2,
                     color="fff",
                     opacity=0,
                     strokewidth=self._axis_config.axis_width + left_overhang +
                     right_overhang)
        avg.LineNode(parent=self._axis_and_tick_div,
                     pos1=(0, 0),
                     pos2=axis_pos2,
                     color=self._axis_config.axis_color,
                     strokewidth=self._axis_config.axis_width)
        self.__axis_size = axis_pos2
Beispiel #15
0
    def __init__(self, session, vis_params, max_users, parent, **kwargs):
        """
        :param session: The session this panel should show.
        :type session: Session
        :param vis_params: The state/parameter for this whole application.
        :type vis_params: VisParams
        :param max_users: The number of user that should be maximal shown in this view.
        :type max_users: int
        :param parent: The parent for this panel.
        :type parent: avg.DivNode
        :param kwargs: Other parameters that are used for the VisPanel.
        """
        super(TouchTimePanel, self).__init__("Touches", vis_params, (60, 25), True, parent=parent, **kwargs)

        self.__duration = session.duration
        self.__users = session.users
        self.__max_users = max_users
        self.__user_count = len(self.__users) if len(self.__users) < self.__max_users else self.__max_users
        self.__time_interval = [None, None]
        self.__user_visibility = [True for _ in range(len(self.__users))]
        self.__user_rect_nodes = None

        self._create_x_axis(
            data_range=[0, session.duration],
            unit="s"
        )
        self._create_y_axis(
            data_range=[-0.5, self.__user_count - 0.5],
            unit="own",
            tick_positions=[i for i in range(self.__user_count)],
            tick_labels=["" for _ in range(self.__user_count)],
            hide_rims=True
        )
        self._create_data_div()

        self._create_all_rect_nodes(vis_params)

        # Create the highlight line
        self.__highlight_line = avg.LineNode(
            color=global_values.COLOR_SECONDARY,
            pos1=(0, 0),
            pos2=(0, self._data_div.height),
            active=False,
            parent=self._data_div
        )
Beispiel #16
0
    def __init_time_bar(self, duration, interval):
        pos = avg.Point2D(58, 0)
        size = avg.Point2D(self.width - pos.x - 10, 60)
        self.__time_bar = avg.DivNode(pos=pos, size=size, parent=self)

        avg.WordsNode(pos=(0, 0),
                      color=global_values.COLOR_FOREGROUND,
                      fontsize=global_values.FONT_SIZE,
                      text="Time range",
                      parent=self.__time_bar)

        self.__time_slider = custom_slider.IntervalScrollBar(
            pos=(0, 27),
            width=size.x,
            range=(0, duration),
            thumbExtent=duration,
            parent=self.__time_bar)
        self.__time_slider.subscribe(
            custom_slider.IntervalScrollBar.THUMB_POS_CHANGED,
            self.__on_scroll)

        self.__start_label = avg.WordsNode(
            pos=(0, 48),
            color=global_values.COLOR_FOREGROUND,
            text="0:00 ({})".format(helper.format_time(interval[0], False)),
            fontsize=global_values.FONT_SIZE,
            parent=self.__time_bar)
        self.__end_label = avg.WordsNode(
            pos=(size.x, 48),
            color=global_values.COLOR_FOREGROUND,
            text="({}) {}".format(helper.format_time(interval[1], False),
                                  helper.format_time(self.__duration, False)),
            alignment="right",
            fontsize=global_values.FONT_SIZE,
            parent=self.__time_bar)
        self.__cur_time_line = avg.LineNode(color=global_values.COLOR_WHITE,
                                            sensitive=False,
                                            parent=self.__time_bar)
        self.__duration_time_label = avg.WordsNode(
            pos=(size.x, 0),
            color=global_values.COLOR_FOREGROUND,
            alignment="right",
            fontsize=global_values.FONT_SIZE,
            parent=self.__time_bar)
Beispiel #17
0
    def _draw_vertical_selection_line(self, pos):
        """
        Draws a vertical selection line.

        :param pos: The position of the line.
        :type pos: tuple[int, int]
        :return: The created selection line.
        :rtype: DivNode
        """
        selection_line = avg.DivNode(
            parent=self._aid_lines_div,
            pos=(pos[0], 0)
        )
        avg.LineNode(
            parent=selection_line,
            pos1=(0, self._aid_line_area[1] - self._selection_line_config.extra_length),
            pos2=(0, self._aid_line_area[3] + self._selection_line_config.extra_length),
            color=self._selection_line_config.color,
            strokewidth=self._selection_line_config.width,
            sensitive=False
        )
        return selection_line
    def __init__(self, session, vis_params, csv_path, parent, **kwargs):
        super(TaskTimePanel, self).__init__("App Events",
                                            vis_params, (60, 25),
                                            True,
                                            parent=parent,
                                            **kwargs)
        self.crop = False

        self.__task_data = {}
        self._read_csv_file(csv_path)
        self.__session_start_time = session.start_time
        self.__duration = session.duration
        self.__time_interval = [None, None]
        self.__rect_nodes = None

        self._create_x_axis(data_range=[0, session.duration],
                            unit="s",
                            hide_rims=True)
        self._create_y_axis(
            data_range=[-0.5, len(self.__axis_names) - 0.5],
            tick_positions=[i for i in range(len(self.__axis_names))],
            tick_labels=self.__axis_names,
            unit="own",
            hide_rims=True,
            label_fontsize=global_values.FONT_SIZE_SMALLER)
        self._create_data_div()

        self._create_all_rect_nodes()

        # Create the highlight line
        self.__highlight_line = avg.LineNode(
            color=global_values.COLOR_SECONDARY,
            pos1=(0, 0),
            pos2=(0, self._data_div.height),
            active=False,
            parent=self._data_div)
Beispiel #19
0
    def __init__(self, disableMouseFocus=False, 
            moveCoursorOnTouch=True, textBackgroundNode=None, loupeBackgroundNode=None,
            parent=None, **kwargs):
        """
        @param parent: parent of the node
        @param disableMouseFocus: boolean, prevents that mouse can set focus for
            this instance
        @param moveCoursorOnTouch: boolean, activate the coursor motion on touch events
        """
        super(TextArea, self).__init__(**kwargs)
        self.registerInstance(self, parent)

        self.__blurOpacity = DEFAULT_BLUR_OPACITY
        self.__border = 0
        self.__data = []
        self.__cursorPosition = 0

        textNode = avg.WordsNode(rawtextmode=True)

        if textBackgroundNode is not None:
            self.appendChild(textBackgroundNode)

        if not disableMouseFocus:
            self.setEventHandler(avg.Event.CURSOR_UP, avg.Event.MOUSE, self.__onClick)
            self.setEventHandler(avg.Event.CURSOR_UP, avg.Event.TOUCH, self.__onClick)

        self.appendChild(textNode)

        cursorContainer = avg.DivNode()
        cursorNode = avg.LineNode(color='000000')
        self.appendChild(cursorContainer)
        cursorContainer.appendChild(cursorNode)
        self.__flashingCursor = False
        
        self.__cursorContainer = cursorContainer
        self.__cursorNode = cursorNode
        self.__textNode = textNode

        self.__loupe = None

        self.setFocus(True)

        player.setInterval(CURSOR_FLASHING_DELAY, self.__tickFlashCursor)
        
        self.__lastActivity = 0

        if moveCoursorOnTouch:
            self.__recognizer = gesture.DragRecognizer(eventNode=self, friction=-1,
                    moveHandler=self.__moveHandler, 
                    detectedHandler=self.__detectedHandler,
                    upHandler=self.__upHandler)
            self.__loupeZoomFactor = 0.5
            self.__loupe = avg.DivNode(parent=self, crop=True)

            if loupeBackgroundNode is not None:
                self.__loupe.appendChild(loupeBackgroundNode)
                self.__loupe.size = loupeBackgroundNode.size
            else:
                self.__loupe.size = (50,50)
                avg.RectNode(fillopacity=1, fillcolor="f5f5f5", color="ffffff",
                        size=self.__loupe.size, parent=self.__loupe)
            self.__loupeOffset = (self.__loupe.size[0]/2.0, self.__loupe.size[1]+20)
            self.__loupe.unlink()
            self.__zoomedImage = avg.DivNode(parent=self.__loupe)
            self.__loupeTextNode = avg.WordsNode(rawtextmode=True, 
                    parent=self.__zoomedImage)

            self.__loupeCursorContainer = avg.DivNode(parent=self.__zoomedImage)
            self.__loupeCursorNode = avg.LineNode(color='000000', 
                    parent=self.__loupeCursorContainer)
        self.setStyle()
 def onInit(self):
     self.__line = avg.LineNode(color='FFFFFF', parent=self)
     self.__x = 0
Beispiel #21
0
 def addLine():
     line = avg.LineNode(pos1=(2, 20), pos2=(100, 20), texhref="rgb24-64x64.png",
             strokewidth=30)
     canvas.appendChild(line)
Beispiel #22
0
 def addLines():
     for i in xrange(500):
         y = i+2.5
         line = avg.LineNode(pos1=(2, y), pos2=(10, y))
         canvas.appendChild(line)
Beispiel #23
0
 def addVectorNode():
     node = avg.LineNode(pos1=(2, 2), pos2=(50, 2), strokewidth=2)
     canvas.appendChild(node)
     return node
Beispiel #24
0
 def addLine():
     line = avg.LineNode(pos1=(2, 2.5), pos2=(158, 2.5), opacity=0.5)
     canvas.appendChild(line)
    def __init__(self, map_point_view, parent=None, **kwargs):
        """
        :param map_point_view: The view this detail view is connected with.
        :type map_point_view: MapPointView
        :type parent: DivNode
        :param kwargs: Other parameters for the div node.
        """
        super(MapPointDetailView, self).__init__(size=(Defaults.SIZE_CM[0] * config_app.pixel_per_cm,
                                                       Defaults.SIZE_CM[1] * config_app.pixel_per_cm),
                                                 **kwargs)
        self.registerInstance(self, parent)

        self.__map_point_view = map_point_view

        self.__tap_recognizers = gesture.TapRecognizer(
            node=self,
            maxTime=CommonRecognizerDefaults.TAP_MAX_TIME,
            maxDist=CommonRecognizerDefaults.TAP_MAX_DIST,
            detectedHandler=self.__on_tap
        )

        self.__triangle_div = avg.DivNode(
            parent=self,
            size=(self.size[0] / 24, self.size[0] / (24 * 1.4)),
            crop=True
        )
        self.__triangle_rect = avg.RectNode(
            parent=self.__triangle_div,
            strokewidth=0,
            fillcolor=colors.GREY,
            fillopacity=1,
            angle=pi/4,
            size=(self.size[0] / Defaults.TRIANGLE_RATIO, self.size[0] / Defaults.TRIANGLE_RATIO),
            pos=(0, -self.size[0] / (Defaults.TRIANGLE_RATIO * 2))
        )
        self.__triangle_div.pos = (self.size[0] - self.__triangle_rect.size[0]) / 2, self.size[1] - 1
        self.__background_rect = avg.RectNode(
            parent=self,
            strokewidth=Defaults.BORDER_WIDTH,
            color=colors.GREY,
            fillcolor=Defaults.BACKGROUND_COLOR,
            fillopacity=Defaults.BACKGROUND_OPACITY,
            size=self.size
        )

        values = zip(self.__map_point_view.point_model.attribute_dict["crime_types"], self.__map_point_view.point_model.attribute_dict["crime_types_count"])
        data_objects = [DataObject(ctn, [Attribute("crime_type_name", DataType.String, [ctn]), Attribute("crimes_count", DataType.Integer, [ctc])]) for ctn, ctc in values]
        x_data_desc = DataDescription.generate_from_data_objects(data_objects=data_objects, description_name="crimes_count")
        x_data_desc.data = [0, x_data_desc.data[1]]
        y_data_desc = DataDescription.generate_from_data_objects(data_objects=data_objects, description_name="crime_type_name")
        # TODO: Use default values.
        self.__crime_types_view = BarChart(
            parent=self,
            size=(self.size[0], self.size[1] * Defaults.CHART_RATIO / Defaults.CHART_TEXT_RATIO),
            data=data_objects,
            data_keys_for_selection=["crime_type_name"],
            label=T.tl("Crimes / Types") + "           ",
            orientation=Orientation.Horizontal,
            axis_cross_offset=0,
            bar_spacing=2,
            x_axis_data=x_data_desc,
            x_axis_config=ChartAxisConfiguration(data_steps=5, bottom_offset=0,
                                                 marking_text_config=TextChartLabelConfiguration(font_size=Defaults.MARKING_FONT_SIZE, offset_to_other_element=Defaults.OFFSET_TO_OTHER),
                                                 label_text_config=TextChartLabelConfiguration(font_size=Defaults.LABEL_FONT_SIZE, offset_to_other_element=Defaults.OFFSET_TO_OTHER)),
            y_axis_data=y_data_desc,
            y_axis_config=ChartAxisConfiguration(show_label=False, bottom_offset=10, top_offset=10,
                                                 marking_text_config=TextChartLabelConfiguration(font_size=Defaults.MARKING_FONT_SIZE, offset_to_other_element=Defaults.OFFSET_TO_OTHER),
                                                 label_text_config=TextChartLabelConfiguration(font_size=Defaults.LABEL_FONT_SIZE, offset_to_other_element=Defaults.OFFSET_TO_OTHER)),
            chart_config=ChartConfiguration(padding_left=Defaults.CHART_P_LEFT, padding_top=Defaults.CHART_P_TOP, padding_right=Defaults.CHART_P_RIGHT, padding_bottom=Defaults.CHART_P_BOTTOM,
                                            label_text_config=TextChartLabelConfiguration(font_size=Defaults.TITLE_FONT_SIZE, offset_to_other_element=Defaults.OFFSET_TO_OTHER))
        )
        self.__crime_types_view.draw_chart()

        self.__districts_view = avg.DivNode(
            parent=self,
            pos=(0, self.size[1] * Defaults.CHART_RATIO / Defaults.CHART_TEXT_RATIO),
            size=(self.size[0], self.size[1] / Defaults.CHART_TEXT_RATIO)
        )
        self.__district_label_node = avg.WordsNode(
            parent=self.__districts_view,
            text="{}:".format(T.tl("Districts")),
            alignment="left",
            rawtextmode=True,
            fontsize=Defaults.TITLE_FONT_SIZE,
            color=TextChartLabelDefaults.COLOR
        )
        self.__district_label_node.pos = Defaults.OFFSET_TO_OTHER * 2, (self.__districts_view.size[1] - self.__district_label_node.size[1]) / 2
        self.__districts_node = avg.WordsNode(
            parent=self.__districts_view,
            text=", ".join(self.__map_point_view.point_model.attribute_dict["districts"]),
            alignment="left",
            rawtextmode=True,
            fontsize=Defaults.MARKING_FONT_SIZE,
            color=TextChartLabelDefaults.COLOR
        )
        self.__districts_node.pos = (self.__district_label_node.pos[0] + self.__district_label_node.size[0] + Defaults.OFFSET_TO_OTHER * 2,
                                     self.__district_label_node.pos[1] + float(self.__district_label_node.size[1] - self.__districts_node.size[1]) / 2)

        close_size = self.size[0] / Defaults.CLOSE_BUTTON_RATIO
        self.__close_div = avg.DivNode(
            parent=self,
            pos=(self.size[0] - close_size - Defaults.BORDER_WIDTH, Defaults.BORDER_WIDTH),
            size=(close_size, close_size),
            crop=True
        )
        avg.LineNode(
            parent=self.__close_div,
            pos1=(0, 0),
            pos2=(close_size, close_size),
            strokewidth=Defaults.CLOSE_BUTTON_STROKE_WIDTH,
            color=Defaults.CLOSE_BUTTON_COLOR
        )
        avg.LineNode(
            parent=self.__close_div,
            pos1=(close_size, 0),
            pos2=(0, close_size),
            strokewidth=Defaults.CLOSE_BUTTON_STROKE_WIDTH,
            color=Defaults.CLOSE_BUTTON_COLOR
        )

        self.__close_button_recognizer = gesture.TapRecognizer(
            node=self.__close_div,
            maxTime=CommonRecognizerDefaults.TAP_MAX_TIME,
            maxDist=CommonRecognizerDefaults.TAP_MAX_DIST,
            detectedHandler=self.__on_close_button_clicked
        )
Beispiel #26
0
    def testPositioning(self):
        def click(pos):
            self.fakeClick(int(pos[0]), int(pos[1]))

        def testInside(bInside):
            ok = bInside == self.clicked
            self.clicked = False
            return ok

        def onMouse(event):
            self.clicked = True

        root = self.loadEmptyScene()
        avg.LineNode(pos1=(4, 20.5),
                     pos2=(157, 20.5),
                     color="FF0000",
                     parent=root)
        avg.LineNode(pos1=(4.5, 20.5),
                     pos2=(4.5, 110),
                     color="FF0000",
                     parent=root)
        avg.LineNode(pos1=(156.5, 20.5),
                     pos2=(156.5, 110),
                     color="FF0000",
                     parent=root)
        avg.LineNode(pos1=(80.5, 20.5),
                     pos2=(80.5, 110),
                     color="FF0000",
                     parent=root)
        avg.WordsNode(id="left",
                      pos=(4, 20),
                      fontsize=12,
                      font="Bitstream Vera Sans",
                      variant="roman",
                      text="Norm",
                      parent=root)
        avg.WordsNode(pos=(45, 20),
                      fontsize=12,
                      font="Bitstream Vera Sans",
                      variant="roman",
                      text="orm",
                      parent=root)
        avg.WordsNode(pos=(75, 20),
                      fontsize=12,
                      font="Bitstream Vera Sans",
                      variant="roman",
                      text="ÖÄÜ",
                      parent=root)
        avg.WordsNode(pos=(4, 40),
                      fontsize=12,
                      font="Bitstream Vera Sans",
                      variant="oblique",
                      text="Jtalic",
                      parent=root)
        avg.WordsNode(id="right",
                      pos=(156, 60),
                      fontsize=12,
                      alignment="right",
                      font="Bitstream Vera Sans",
                      variant="roman",
                      text="Right-aligned",
                      parent=root)
        avg.WordsNode(id="center",
                      pos=(80, 80),
                      fontsize=12,
                      alignment="center",
                      font="Bitstream Vera Sans",
                      variant="roman",
                      text="Centered",
                      parent=root)
        for id in ["left", "center", "right"]:
            player.getElementByID(id).subscribe(avg.Node.CURSOR_DOWN, onMouse)
        self.clicked = False
        leftWidth = player.getElementByID("left").getMediaSize()[0]
        centerWidth = player.getElementByID("center").getMediaSize()[0]
        rightWidth = player.getElementByID("right").getMediaSize()[0]

        self.start(True, (
            lambda: self.compareImage("testPositioning"),
            lambda: click((4, 20)),
            lambda: self.assert_(testInside(True)),
            lambda: click((3, 20)),
            lambda: self.assert_(testInside(False)),
            lambda: click((3 + leftWidth, 20)),
            lambda: self.assert_(testInside(True)),
            lambda: click((4 + leftWidth, 20)),
            lambda: self.assert_(testInside(False)),
            lambda: click((81 - centerWidth / 2, 80)),
            lambda: self.assert_(testInside(True)),
            lambda: click((80 - centerWidth / 2, 80)),
            lambda: self.assert_(testInside(False)),
            lambda: click((80 + centerWidth / 2, 80)),
            lambda: self.assert_(testInside(True)),
            lambda: click((81 + centerWidth / 2, 80)),
            lambda: self.assert_(testInside(False)),
            lambda: click((156 - rightWidth, 60)),
            lambda: self.assert_(testInside(True)),
            lambda: click((155 - rightWidth, 60)),
            lambda: self.assert_(testInside(False)),
            lambda: click((155, 60)),
            lambda: self.assert_(testInside(True)),
            lambda: click((156, 60)),
            lambda: self.assert_(testInside(False)),
        ))