Пример #1
0
 def onInit(self):
     self.rect = TextRect(text="Hello World",
                          pos=(20, 20),
                          size=(200, 120),
                          parent=self)
     self.__recognizer = gesture.TapRecognizer(node=self.rect,
                                               detectedHandler=self.onTap)
    def __create_reload_overlay(self):
        if not self.__use_reload_overlay:
            return

        self.__reload_overlay = avg.DivNode(parent=self._data_div,
                                            size=self._data_div.size,
                                            active=False)
        avg.RectNode(parent=self.__reload_overlay,
                     size=self._data_div.size,
                     strokewidth=0,
                     fillopacity=0.75,
                     fillcolor=global_values.COLOR_DARK_GREY)
        text = avg.WordsNode(parent=self.__reload_overlay,
                             text="Click to\nreload",
                             fontsize=global_values.FONT_SIZE * 2,
                             color=global_values.COLOR_FOREGROUND,
                             alignment="center",
                             rawtextmode=True,
                             pos=(self._data_div.size[0] / 2,
                                  self._data_div.size[1] / 2))
        text.pos = text.pos[
            0], text.pos[1] - 2 * global_values.FONT_SIZE + text.linespacing
        self.__reload_tap_recognizer = gesture.TapRecognizer(
            node=self.__reload_overlay,
            detectedHandler=self.__on_reload_overlay_tapped,
            maxDist=5,
            maxTime=500)
Пример #3
0
    def __init__(self, text, **kwargs):
        super(TapButton, self).__init__(text, **kwargs)

        self.recognizer = gesture.TapRecognizer(
            node=self,
            possibleHandler=self._onPossible,
            detectedHandler=self._onDetected,
            failHandler=self._onFail)
Пример #4
0
    def __init__(self, point_model, geo_coord_mapper, detail_parent=None, parent=None, **kwargs):
        """
        :param point_model: The point this view should represent.
        :type point_model: MapPoint
        :param scale_factor: The factor the point position should be scaled in the view.
        :type scale_factor: tuple
        :param parent: The parent node this point is embedded in.
        :type parent: DivNode
        """
        super(MapPointView, self).__init__(**kwargs)
        self.registerInstance(self, parent)
        self.subscribe(avg.Node.KILLED, self.__on_self_killed)

        self.__detail_parent = detail_parent or parent

        self.__label_rect_node = None
        self.__label_words_node = None
        self.__detail_view = None
        self.__detail_view_active = False

        self.__point_model = point_model
        self.__point_model.start_listening(
            level_of_detail_changed=self.__on_level_of_detail_changed,
            size_changed=self.__on_model_size_changed,
            visible_changed=self.__on_model_visible_changed,
            texture_changed=self.__on_model_texture_changed,
            opacity_val_changed=self.__on_model_opacity_changed,
            color_changed=self.__on_model_color_changed,
            selection_state_changed=self.__on_model_state_changed
        )
        self.__visual = ColoredCircleView(point_model=point_model, parent=self)
        if self.__point_model.texture is not None:
            self.__additional_texture_visual = avg.ImageNode(
                parent=self,
                href=self.__point_model.texture,
                size=(self.__point_model.width, self.__point_model.height),
                opacity=self.__point_model.color_opacity
            )
        else:
            self.__additional_texture_visual = None

        self.__geo_coord_mapper = geo_coord_mapper
        self.update_position(geo_coord_mapper)

        self.__was_tap_before = False
        self.__tap_recognizer = gesture.TapRecognizer(
            node=self,
            maxTime=CommonRecognizerDefaults.TAP_MAX_TIME,
            maxDist=CommonRecognizerDefaults.TAP_MAX_DIST,
            detectedHandler=self.__on_tap
        )
        self.__double_tap_recognizer = gesture.DoubletapRecognizer(
            node=self,
            maxTime=CommonRecognizerDefaults.DOUBLE_TAP_MAX_TIME,
            maxDist=CommonRecognizerDefaults.DOUBLE_TAP_MAX_DIST,
            failHandler=self.__on_double_tap_failed,
            detectedHandler=self.__on_double_tap
        )
Пример #5
0
    def __init__(self, text, isDoubleTap, **kwargs):
        super(TapNode, self).__init__(text, **kwargs)

        if isDoubleTap:
            self.recognizer = gesture.DoubletapRecognizer(
                node=self,
                possibleHandler=self.__onPossible,
                detectedHandler=self.__onDetected,
                failHandler=self.__onFail)
        else:
            self.recognizer = gesture.TapRecognizer(
                node=self,
                possibleHandler=self.__onPossible,
                detectedHandler=self.__onDetected,
                failHandler=self.__onFail)
Пример #6
0
 def _create_data_objects_for_base(self):
     """
     Creates data objects visualisations for all data objects in this chart. Should always be called at the end of
     the child implementation.
     """
     for key, node in self._data_object_nodes.iteritems():
         self._data_objects[key].start_listening(
             color_changed=self._on_data_object_color_changed,
             selection_state_changed=self.
             _on_data_object_selection_state_changed)
         self._data_objects[key].start_listening(
             selection_state_changed=self._on_data_object_highlighted)
         self._data_object_tap_recognizer[key] = gesture.TapRecognizer(
             node=node,
             maxTime=CommonRecognizerDefaults.TAP_MAX_TIME,
             maxDist=CommonRecognizerDefaults.TAP_MAX_DIST,
             detectedHandler=(
                 lambda sender_id=key: self._on_data_objects_selected_tap(
                     sender_id=sender_id)))
Пример #7
0
    def _setActiveArea(self, upNode, activeAreaNode, fatFingerEnlarge):
        if fatFingerEnlarge:
            if activeAreaNode:
                raise (RuntimeError(
                    "Button: Can't specify both fatFingerEnlarge and activeAreaNode"
                ))
            size = upNode.size
            minSize = 20 * player.getPixelsPerMM()
            size = avg.Point2D(max(minSize, size.x), max(minSize, size.y))
            activeAreaNode = avg.RectNode(size=size, opacity=0, parent=self)
            #Here we need to store a 'hard' reference to the active area node
            #because the tap recognizer won't keep it
            self.__activeAreaNode = activeAreaNode
        else:
            if activeAreaNode is None:
                activeAreaNode = self
            else:
                self.appendChild(activeAreaNode)

        self._tapRecognizer = gesture.TapRecognizer(
            activeAreaNode,
            possibleHandler=self._onDown,
            detectedHandler=self._onTap,
            failHandler=self._onTapFail)
    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
        )