Пример #1
0
    def __init__(self, parent=None, view=None):
        super(AirdataDockwidget, self).__init__(parent)
        self.setupUi(self)
        self.view = view
        self.view.redrawn.connect(self.redraw_map)

        code_to_name = {
            country.alpha_2.lower(): country.name
            for country in pycountry.countries
        }
        self.cbAirspaces.addItems([
            f"{code_to_name.get(airspace[0].split('_')[0], 'Unknown')} "
            f"{airspace[0].split('_')[0]}" for airspace in _airspace_cache
        ])
        self.cbAirportType.addItems([
            "small_airport", "medium_airport", "large_airport", "heliport",
            "balloonport", "seaplane_base", "closed"
        ])

        self.settings_tag = "airdatadock"
        settings = load_settings_qsettings(
            self.settings_tag, {
                "draw_airports": False,
                "draw_airspaces": False,
                "airspaces": [],
                "airport_type": [],
                "filter_airspaces": False,
                "filter_from": 0,
                "filter_to": 100
            })

        self.btDownload.clicked.connect(lambda: get_airports(True))
        self.btDownloadAsp.clicked.connect(
            lambda: update_airspace(True, [
                airspace.split(" ")[-1]
                for airspace in self.cbAirspaces.currentData()
            ]))
        self.btApply.clicked.connect(self.redraw_map)

        self.cbDrawAirports.setChecked(settings["draw_airports"])
        self.cbDrawAirspaces.setChecked(settings["draw_airspaces"])
        for airspace in settings["airspaces"]:
            i = self.cbAirspaces.findText(airspace)
            if i != -1:
                self.cbAirspaces.model().item(i).setCheckState(
                    QtCore.Qt.Checked)
        for airport in settings["airport_type"]:
            i = self.cbAirportType.findText(airport)
            if i != -1:
                self.cbAirportType.model().item(i).setCheckState(
                    QtCore.Qt.Checked)
        self.cbAirspaces.updateText()
        self.cbFilterAirspaces.setChecked(settings["filter_airspaces"])
        self.sbFrom.setValue(settings["filter_from"])
        self.sbTo.setValue(settings["filter_to"])
Пример #2
0
    def draw_airports(self, port_type):
        """
        Load and draw airports and their respective name on hover
        """
        if not self.airports:
            airports = get_airports()
            if not airports:
                logging.error("Tried to draw airports but none were found. Try redownloading.")
                return

            lons, lats = self.projtran(*zip(*[(float(airport["longitude_deg"]),
                                            float(airport["latitude_deg"])) for airport in airports]))
            for i, airport in enumerate(airports):
                airports[i]["longitude_deg"] = lons[i]
                airports[i]["latitude_deg"] = lats[i]

            airports = [airport for airport in airports if airport["type"] in port_type and
                        self.llcrnrx <= float(airport["longitude_deg"]) <= self.urcrnrx and
                        self.llcrnry <= float(airport["latitude_deg"]) <= self.urcrnry]
            lons = [float(airport["longitude_deg"]) for airport in airports]
            lats = [float(airport["latitude_deg"]) for airport in airports]
            annotations = [airport["name"] for airport in airports]
            if not airports:
                return

            if OURAIRPORTS_NOTICE not in self.crs_text.get_text():
                self.crs_text.set_text(f"{OURAIRPORTS_NOTICE}\n" + self.crs_text.get_text())

            self.airports = self.ax.scatter(lons, lats, marker="o", color="r", linewidth=1, s=9, edgecolor="black",
                                            zorder=6)
            self.airports.set_pickradius(1)
            self.airtext = self.ax.annotate(annotations[0], xy=(lons[0], lats[0]), xycoords="data",
                                            bbox={"boxstyle": "round", "facecolor": "w",
                                                  "edgecolor": "0.5", "alpha": 0.9}, zorder=8)
            self.airtext.set_visible(False)

            def update_text(index):
                pos = self.airports.get_offsets()[index["ind"][0]]
                self.airtext.xy = pos
                self.airtext.set_position(pos)
                self.airtext.set_text("\n".join([annotations[i] for i in index["ind"]]))

            def on_move(event):
                if self.airports and event.inaxes == self.ax:
                    cont, ind = self.airports.contains(event)
                    if cont:
                        update_text(ind)
                        self.airtext.set_visible(True)
                        self.ax.figure.canvas.draw_idle()
                    elif self.airtext.get_visible():
                        self.airtext.set_visible(False)
                        self.ax.figure.canvas.draw_idle()

            self.airports_event = self.ax.figure.canvas.mpl_connect('motion_notify_event', on_move)