示例#1
0
    def build(self):
        layout = BoxLayout(orientation='vertical')

        header = build_header('Header')
        header.size_hint = 1, 1
        layout.add_widget(header)

        toolbar = build_toolbar(options)
        toolbar.size_hint = 1, .2
        #toolbar.pos_hint = {'top':1}
        layout.add_widget(toolbar)

        sizer1 = FloatLayout()
        s0 = Scatter(do_scale=False, do_rotation=False)
        s0.size_hint = (None, None)
        b1 = Label(text='New Sink')
        s0.add_widget(b1)
        sizer1.add_widget(s0)

        layout.add_widget(sizer1)

        return layout
示例#2
0
    def build(self):
        """Builds the GUI.
        """
        resource_add_path(
            os.path.join(os.path.dirname(distopia.__file__), 'data', 'media'))
        self.load_config()

        mat = None
        if self.alignment_filename:
            fname = os.path.join(os.path.dirname(distopia.__file__), 'data',
                                 self.alignment_filename)
            try:
                mat = np.loadtxt(fname, delimiter=',', skiprows=3)
            except Exception as e:
                logging.exception("Not using alignment: {}".format(e))

        self.load_data_create_voronoi()
        self.metric_data = self.geo_data.load_metrics(self.metrics,
                                                      self.precincts)
        self.voronoi_mapping.verify_adjacency = \
            self.geo_data.set_precinct_adjacency(self.precincts)
        self.geo_data.load_landmarks()

        widget = VoronoiWidget(
            voronoi_mapping=self.voronoi_mapping,
            table_mode=self.table_mode,
            align_mat=mat,
            screen_offset=list(map(dp, self.screen_offset)),
            ros_bridge=self.ros_bridge,
            district_blocks_fid=self.district_blocks_fid,
            focus_block_fid=self.focus_block_fid,
            focus_block_logical_id=self.focus_block_logical_id,
            district_metrics_fn=self.metric_data.compute_district_metrics,
            state_metrics_fn=self.metric_data.create_state_metrics,
            show_voronoi_boundaries=self.show_voronoi_boundaries,
            focus_metrics=self.focus_metrics,
            screen_size=list(map(dp, self.screen_size)),
            focus_metric_height=dp(self.focus_metric_height),
            focus_metric_width=dp(self.focus_metric_width),
            max_fiducials_per_district=self.max_fiducials_per_district,
            visualize_metric_data=self.visualize_metric_data)

        if self.use_ros:
            box = BoxLayout()
            voronoi_widget = widget
            err = Label(text='No ROS bridge. Please set use_ros to False')
            widget = box
            box.add_widget(err)

            def enable_widget(*largs):
                box.remove_widget(err)
                box.add_widget(voronoi_widget)
                voronoi_widget.ros_bridge = self.ros_bridge
                if self.show_precinct_id:
                    self.show_precinct_labels(voronoi_widget)
                self.show_landmarks(voronoi_widget)

            self.ros_bridge = RosBridge(
                host=self.ros_host,
                port=self.ros_port,
                ready_callback=Clock.create_trigger(enable_widget),
                log_data=self.log_data)
        else:
            if self.show_precinct_id:
                self.show_precinct_labels(widget)
            self.show_landmarks(widget)

        size = list(map(dp, self.screen_size))
        size = [v / self.scale for v in size]

        scatter = Scatter(do_rotation=False,
                          do_scale=False,
                          do_translation_y=False,
                          do_translation_x=False,
                          scale=self.scale,
                          do_collide_after_children=False)
        scatter.add_widget(widget)

        widget.size_hint = None, None
        scatter.size_hint = None, None
        scatter.fbind('pos', lambda *l: setattr(scatter, 'pos', (0, 0)))
        scatter.pos = 0, 0
        scatter.size = size
        widget.size = size
        return scatter