Esempio n. 1
0
    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""

        PlanetClient.getInstance().log_out()
        self.provider.updateLayerWidgets()

        removeSettingsMenu(P_E, self.iface.removePluginWebMenu)
        # removeHelpMenu(P_E, self.iface.removePluginWebMenu)
        removeAboutMenu(P_E, self.iface.removePluginWebMenu)

        for action in self.actions:
            self.iface.removePluginWebMenu(
                self.tr('&{0}'.format(P_E)), action)
            self.iface.removeToolBarIcon(action)

        # remove the toolbar
        if self.toolbar is not None:
            del self.toolbar

        remove_inspector()
        remove_explorer()
        remove_orders_monitor()
        remove_tasking_widget()

        sys.excepthook = self.qgis_hook

        QgsProject.instance().projectSaved.disconnect(self.project_saved)
        QgsProject.instance().layersAdded.disconnect(self.layers_added)
        QgsProject.instance().layerRemoved.disconnect(self.layer_removed)
Esempio n. 2
0
 def resave():
     path = QgsProject.instance().absoluteFilePath()
     if path.lower().endswith(".qgs"):
         with open(path) as f:
             s = f.read()
         with open(path, "w") as f:
             f.write(
                 s.replace(PlanetClient.getInstance().api_key(),
                           ""))
     else:
         tmpfilename = path + ".temp"
         qgsfilename = os.path.splitext(
             os.path.basename(path))[0] + ".qgs"
         with zipfile.ZipFile(path, 'r') as zin:
             with zipfile.ZipFile(tmpfilename, 'w') as zout:
                 zout.comment = zin.comment
                 for item in zin.infolist():
                     if not item.filename.lower().endswith(".qgs"):
                         zout.writestr(item,
                                       zin.read(item.filename))
                     else:
                         s = zin.read(item.filename).decode("utf-8")
                         s = s.replace(
                             PlanetClient.getInstance().api_key(),
                             "")
                         qgsfilename = item.filename
         os.remove(path)
         os.rename(tmpfilename, path)
         with zipfile.ZipFile(
                 path, mode='a',
                 compression=zipfile.ZIP_DEFLATED) as zf:
             zf.writestr(qgsfilename, s)
Esempio n. 3
0
 def test_explorer_reacts_to_login(self):
     self.dockwidget.chkBxSaveCreds.setChecked(False)
     current = self.dockwidget.stckdWidgetViews.currentIndex()
     assert current == 0
     user, password = get_testing_credentials()
     PlanetClient.getInstance().log_in(user, password)
     current = self.dockwidget.stckdWidgetViews.currentIndex()
     assert current == 1
Esempio n. 4
0
 def test_can_search_daily_images(self):
     user, password = get_testing_credentials()
     PlanetClient.getInstance().log_in(user, password)
     current = self.dockwidget.stckdWidgetViews.currentIndex()
     assert current == 1
     self.dockwidget.daily_images_widget._main_filters.leAOI.setText(
         test_aoi())
     self.dockwidget.daily_images_widget.perform_search()
     assert (self.dockwidget.daily_images_widget.searchResultsWidget.tree.
             topLevelItemCount() == 80)
Esempio n. 5
0
 def test_basemaps_are_shown(self):
     user, password = get_testing_credentials()
     PlanetClient.getInstance().log_in(user, password)
     current = self.dockwidget.stckdWidgetViews.currentIndex()
     assert current == 1
     self.dockwidget.show_mosaics_panel()
     current = self.dockwidget.tabWidgetResourceType.currentIndex()
     assert current == 1
     assert self.dockwidget.basemaps_widget.mosaicsList.count() == 0
     assert self.dockwidget.basemaps_widget.comboSeriesName.count() > 1
     self.dockwidget.basemaps_widget.comboSeriesName.setCurrentIndex(1)
     assert self.dockwidget.basemaps_widget.mosaicsList.count() > 0
Esempio n. 6
0
 def enable_buttons(self, loggedin):
     self.btnLogin.setVisible(not loggedin)
     labelText = (f"<b>Welcome to Planet</b>" if not loggedin else "<b>Planet</b>")
     self.labelLoggedIn.setText(labelText)
     self.showdailyimages_act.setEnabled(loggedin)
     self.showbasemaps_act.setEnabled(loggedin)
     self.showinspector_act.setEnabled(loggedin)
     self.showorders_act.setEnabled(loggedin)
     self.showtasking_act.setEnabled(loggedin)
     self.user_button.setEnabled(loggedin)
     self.user_button.setText(
         PlanetClient.getInstance().user()['user_name']
         if loggedin else "")
     if loggedin:
         self.showdailyimages_act.setToolTip("Show / Hide the Planet Imagery Search Panel")
         self.showbasemaps_act.setToolTip("Show / Hide the Planet Basemaps Search Panel")
         self.showorders_act.setToolTip("Show / Hide the Order Status Panel")
         self.showinspector_act.setToolTip("Show / Hide the Planet Inspector Panel")
         self.showtasking_act.setToolTip("Show / Hide the Tasking Panel")
     else:
         self.showdailyimages_act.setToolTip("Login to access Imagery Search")
         self.showbasemaps_act.setToolTip("Login to access Basemaps Search")
         self.showorders_act.setToolTip("Login to access Order Status")
         self.showinspector_act.setToolTip("Login to access Planet Inspector")
         self.showtasking_act.setToolTip("Login to access Tasking Panel")
Esempio n. 7
0
    def initGui(self):

        icon_path = ':/plugins/planet_explorer/planet-logo-p.svg'
        self.toolbar = self.iface.addToolBar(P_E)
        self.toolbar.setObjectName(P_E)

        self.add_action(icon_path,
                        text=self.tr(P_E),
                        callback=self.run,
                        add_to_menu=True,
                        add_to_toolbar=True,
                        parent=self.iface.mainWindow())

        addSettingsMenu(P_E, self.iface.addPluginToWebMenu)
        # addHelpMenu(P_E, self.iface.addPluginToWebMenu)
        addAboutMenu(P_E, self.iface.addPluginToWebMenu)

        # Register helper function for dealing with PlanetLabs catalog
        # metadata
        # registerFunctions()

        # noinspection PyBroadException
        # try:
        #     from lessons import addLessonsFolder, addGroup
        #     folder = os.path.join(os.path.dirname(__file__), "_lessons")
        #     addLessonsFolder(folder, "imagediscovery")
        #     group_description = os.path.join(folder, "group.md")
        #     addGroup("Planet Explorer plugin", group_description)
        # except:
        #     pass

        self.run()
        last_shown = bool(
            pluginSetting(DOCK_SHOWN_STATE,
                          namespace=SETTINGS_NAMESPACE,
                          typ='bool'))
        if self.dock_widget is not None:
            self.dock_widget.setVisible(last_shown)

        self.provider = MosaicLayerWidgetProvider()
        QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(self.provider)

        QgsProject.instance().projectSaved.connect(self.project_saved)

        PlanetClient.getInstance().loginChanged.connect(replace_apikeys)
Esempio n. 8
0
 def resave():
     try:
         path = QgsProject.instance().absoluteFilePath()
         if path.lower().endswith(".qgs"):
             with open(path, encoding='utf-8') as f:
                 s = f.read()
             with open(path, "w", encoding='utf-8') as f:
                 f.write(
                     s.replace(PlanetClient.getInstance().api_key(),
                               ""))
         else:
             tmpfilename = path + ".temp"
             qgsfilename = os.path.splitext(
                 os.path.basename(path))[0] + ".qgs"
             with zipfile.ZipFile(path, 'r') as zin:
                 with zipfile.ZipFile(tmpfilename, 'w') as zout:
                     zout.comment = zin.comment
                     for item in zin.infolist():
                         if not item.filename.lower().endswith(
                                 ".qgs"):
                             zout.writestr(item,
                                           zin.read(item.filename))
                         else:
                             s = zin.read(
                                 item.filename).decode("utf-8")
                             s = s.replace(
                                 PlanetClient.getInstance().api_key(
                                 ), "")
                             qgsfilename = item.filename
             os.remove(path)
             os.rename(tmpfilename, path)
             with zipfile.ZipFile(
                     path, mode='a',
                     compression=zipfile.ZIP_DEFLATED) as zf:
                 zf.writestr(qgsfilename, s)
     except Exception:
         QMessageBox.warning(
             self.iface.mainWindow(
                 "Error saving project",
                 "There was an error while removing API keys from QGIS project file.\n"
                 "The project that you have just saved might contain Planet API keys in plain text."
             ))
Esempio n. 9
0
 def test_can_explore_basemaps(self):
     user, password = get_testing_credentials()
     PlanetClient.getInstance().log_in(user, password)
     current = self.dockwidget.stckdWidgetViews.currentIndex()
     assert current == 1
     self.dockwidget.show_mosaics_panel()
     current = self.dockwidget.tabWidgetResourceType.currentIndex()
     assert current == 1
     assert self.dockwidget.basemaps_widget.mosaicsList.count() == 0
     assert self.dockwidget.basemaps_widget.comboSeriesName.count() > 1
     self.dockwidget.basemaps_widget.comboSeriesName.setCurrentIndex(1)
     mosaicsList = self.dockwidget.basemaps_widget.mosaicsList
     assert mosaicsList.count() > 0
     item = mosaicsList.item(0)
     widget = mosaicsList.itemWidget(item)
     widget.checkBox.setChecked(True)
     assert "1 items" in self.dockwidget.basemaps_widget.btnOrder.text()
     QTest.mouseClick(self.dockwidget.basemaps_widget.btnExplore,
                      Qt.LeftButton)
     layers = QgsProject.instance().mapLayers().values()
     assert len(layers) == 1
Esempio n. 10
0
def replace_apikey_for_layer(layer):
    source = layer.source()
    if is_planet_layer(
            source
    ) and not PLANET_CURRENT_MOSAIC in layer.customPropertyKeys():
        client = PlanetClient.getInstance()
        if client.has_api_key():
            newsource = source.split(
                "api_key=")[0] + "api_key=" + client.api_key()
            newsource = newsource.replace(PLANET_ROOT_URL_PLACEHOLDER,
                                          PLANET_ROOT_URL)
        else:
            newsource = source.split("api_key=")[0] + "api_key="
            newsource = newsource.replace(PLANET_ROOT_URL,
                                          PLANET_ROOT_URL_PLACEHOLDER)
        layer.setDataSource(newsource, layer.name(),
                            layer.dataProvider().name(),
                            QgsDataProvider.ProviderOptions())
        layer.triggerRepaint()
Esempio n. 11
0
 def setUp(self):
     self.dockwidget = PlanetExplorerDockWidget(iface.mainWindow())
     self.dockwidget._setup_client()
     PlanetClient.getInstance().log_out()
Esempio n. 12
0
 def test_correctly_handle_wrong_aoi(self):
     user, password = get_testing_credentials()
     PlanetClient.getInstance().log_in(user, password)
     self.dockwidget.daily_images_widget._main_filters.leAOI.setText(
         "wrong")
Esempio n. 13
0
 def logout(self):
     PlanetClient.getInstance().log_out()
Esempio n. 14
0
 def btn_login_clicked(self):
     if PlanetClient.getInstance().has_api_key():
         self.logout()
     else:
         self.login()
Esempio n. 15
0
    def initGui(self):

        self.toolbar = self.iface.addToolBar(P_E)
        self.toolbar.setObjectName(P_E)

        self.showdailyimages_act = self.add_action(
            os.path.join(plugin_path, "resources", "search.svg"),
            text=self.tr(P_E),
            callback=toggle_images_search,
            add_to_menu=True,
            add_to_toolbar=True,
            parent=self.iface.mainWindow())

        self.showbasemaps_act = self.add_action(
            os.path.join(plugin_path, "resources", "basemap.svg"),
            text=self.tr("Show Basemaps Search"),
            callback=toggle_mosaics_search,
            add_to_menu=True,
            add_to_toolbar=True,
            parent=self.iface.mainWindow())

        self.showinspector_act = self.add_action(
            os.path.join(plugin_path, "resources", "inspector.svg"),
            text=self.tr("Show Planet Inspector..."),
            callback=toggle_inspector,
            add_to_menu=False,
            add_to_toolbar=True,
            parent=self.iface.mainWindow())

        self.showtasking_act = self.add_action(
            os.path.join(plugin_path, "resources", "tasking.svg"),
            text=self.tr("Show Tasking..."),
            callback=toggle_tasking_widget,
            add_to_menu=False,
            add_to_toolbar=True,
            parent=self.iface.mainWindow())

        self.add_central_toolbar_button()

        self.showorders_act = self.add_action(
            os.path.join(plugin_path, "resources", "orders.svg"),
            text=self.tr("Show Orders Monitor..."),
            callback=toggle_orders_monitor,
            add_to_menu=False,
            add_to_toolbar=True,
            parent=self.iface.mainWindow())

        self.add_user_button()
        self.add_info_button()

        addSettingsMenu(P_E, self.iface.addPluginToWebMenu)
        addAboutMenu(P_E, self.iface.addPluginToWebMenu)

        self.provider = BasemapLayerWidgetProvider()
        QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(self.provider)

        QgsProject.instance().projectSaved.connect(self.project_saved)
        QgsProject.instance().layersAdded.connect(self.layers_added)
        QgsProject.instance().layerRemoved.connect(self.layer_removed)

        PlanetClient.getInstance().loginChanged.connect(self.login_changed)

        self.enable_buttons(False)