Skip to content

Commit

Permalink
fix custom provider (#103), better handling for no API key (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsnolde committed May 2, 2019
1 parent 7dd46b4 commit 4559068
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 64 deletions.
58 changes: 39 additions & 19 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ def on_help_click():
webbrowser.open(__help__)


def on_about_click(parent):
"""Slot for click event of About button/menu entry."""

info = '<b>ORS Tools</b> provides access to <a href="https://openrouteservice.org" style="color: {0}">openrouteservice</a> routing functionalities.<br><br>' \
'<center><a href=\"https://gis-ops.com\"><img src=\":/plugins/ORStools/img/logo_gisops_300.png\"/></a> <br><br></center>' \
'Author: Nils Nolde<br>' \
'Email: <a href="mailto:Nils Nolde <{1}>">{1}</a><br>' \
'Web: <a href="{2}">{2}</a><br>' \
'Repo: <a href="https://github.com/nilsnolde/ORStools">github.com/nilsnolde/ORStools</a><br>' \
'Version: {3}'.format(DEFAULT_COLOR, __email__, __web__, __version__)

QMessageBox.information(
parent,
'About {}'.format(PLUGIN_NAME),
info
)


class ORStoolsDialogMain:
"""Defines all mandatory QGIS things about dialog."""

Expand Down Expand Up @@ -150,8 +168,8 @@ def create_icon(f):
# Connect slots to events
self.actions[0].triggered.connect(self._init_gui_control)
self.actions[1].triggered.connect(lambda: on_config_click(parent=self.iface.mainWindow()))
self.actions[2].triggered.connect(on_help_click)
self.actions[3].triggered.connect(self._on_about_click)
self.actions[2].triggered.connect(lambda: on_about_click(parent=self.iface.mainWindow()))
self.actions[3].triggered.connect(on_help_click)

def unload(self):
"""Called when QGIS closes or plugin is deactivated in Plugin Manager"""
Expand All @@ -162,23 +180,6 @@ def unload(self):
del self.dlg
del self.advanced

def _on_about_click(self):
"""Slot for click event of About button/menu entry."""

info = '<b>ORS Tools</b> provides access to <a href="https://openrouteservice.org" style="color: {0}">openrouteservice</a> routing functionalities.<br><br>' \
'<center><a href=\"https://gis-ops.com\"><img src=\":/plugins/ORStools/img/logo_gisops_300.png\"/></a> <br><br></center>' \
'Author: Nils Nolde<br>' \
'Email: <a href="mailto:Nils Nolde <{1}>">{1}</a><br>' \
'Web: <a href="{2}">{2}</a><br>' \
'Repo: <a href="https://github.com/nilsnolde/ORStools">github.com/nilsnolde/ORStools</a><br>' \
'Version: {3}'.format(DEFAULT_COLOR, __email__, __web__, __version__)

QMessageBox.information(
self.iface.mainWindow(),
'About {}'.format(PLUGIN_NAME),
info
)

def _on_advanced_click(self):
"""Slot for click event of advanced dialog button."""

Expand Down Expand Up @@ -232,6 +233,21 @@ def run_gui_control(self):

provider_id = self.dlg.provider_combo.currentIndex()
provider = configmanager.read_config()['providers'][provider_id]

# Check if API key was set when using ORS
if provider['key'] is None:
QMessageBox.critical(
self.dlg,
"Missing API key",
"""
Did you forget to set an <b>API key</b> for openrouteservice?<br><br>
If you don't have an API key, please visit https://openrouteservice.org/sign-up to get one. <br><br>
Then enter the API key for openrouteservice provider in Web ► ORS Tools ► Provider Settings or the settings symbol in the main ORS Tools GUI, next to the provider dropdown.
"""
)
return

clnt = client.Client(provider)
clnt_msg = ''

Expand Down Expand Up @@ -274,6 +290,7 @@ def run_gui_control(self):
msg = "The connection has timed out!"
logger.log(msg, 2)
self.dlg.debug_text.setText(msg)
return

except (exceptions.ApiError,
exceptions.InvalidKey,
Expand All @@ -283,6 +300,7 @@ def run_gui_control(self):

logger.log("{}: {}".format(*msg), 2)
clnt_msg += "<b>{}</b>: ({})<br>".format(*msg)
return

except Exception as e:
msg = [e.__class__.__name__ ,
Expand All @@ -295,6 +313,7 @@ def run_gui_control(self):
# Set URL in debug window
clnt_msg += '<a href="{0}">{0}</a><br>'.format(clnt.url)
self.dlg.debug_text.setHtml(clnt_msg)
return


class ORStoolsDialog(QDialog, Ui_ORStoolsDialogBase):
Expand Down Expand Up @@ -337,6 +356,7 @@ def __init__(self, iface, parent=None):
# Config/Help dialogs
self.provider_config.clicked.connect(lambda: on_config_click(self))
self.help_button.clicked.connect(on_help_click)
self.about_button.clicked.connect(lambda: on_about_click(parent=self._iface.mainWindow()))
self.provider_refresh.clicked.connect(self._on_prov_refresh_click)

# Routing tab
Expand Down
21 changes: 5 additions & 16 deletions ORStools/gui/ORStoolsDialogAdvancedUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setupUi(self, ORStoolsDialogAdvancedBase):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.routing_avoid_tags_group.sizePolicy().hasHeightForWidth())
self.routing_avoid_tags_group.setSizePolicy(sizePolicy)
self.routing_avoid_tags_group.setCheckable(True)
self.routing_avoid_tags_group.setObjectName("routing_avoid_tags_group")
self.gridLayout = QtWidgets.QGridLayout(self.routing_avoid_tags_group)
self.gridLayout.setObjectName("gridLayout")
Expand All @@ -35,24 +36,15 @@ def setupUi(self, ORStoolsDialogAdvancedBase):
self.routing_avoid_toll = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_toll.setObjectName("routing_avoid_toll")
self.gridLayout.addWidget(self.routing_avoid_toll, 0, 1, 1, 1)
self.routing_avoid_tunnels = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_tunnels.setObjectName("routing_avoid_tunnels")
self.gridLayout.addWidget(self.routing_avoid_tunnels, 1, 0, 1, 1)
self.routing_avoid_ferries = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_ferries.setObjectName("routing_avoid_ferries")
self.gridLayout.addWidget(self.routing_avoid_ferries, 1, 1, 1, 1)
self.gridLayout.addWidget(self.routing_avoid_ferries, 1, 0, 1, 1)
self.routing_avoid_fords = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_fords.setObjectName("routing_avoid_fords")
self.gridLayout.addWidget(self.routing_avoid_fords, 2, 0, 1, 1)
self.gridLayout.addWidget(self.routing_avoid_fords, 1, 1, 1, 1)
self.routing_avoid_tracks = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_tracks.setObjectName("routing_avoid_tracks")
self.gridLayout.addWidget(self.routing_avoid_tracks, 2, 1, 1, 1)
self.routing_avoid_paved = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_paved.setObjectName("routing_avoid_paved")
self.gridLayout.addWidget(self.routing_avoid_paved, 3, 0, 1, 1)
self.routing_avoid_unpaved = QtWidgets.QCheckBox(self.routing_avoid_tags_group)
self.routing_avoid_unpaved.setObjectName("routing_avoid_unpaved")
self.gridLayout.addWidget(self.routing_avoid_unpaved, 3, 1, 1, 1)
self.gridLayout.addWidget(self.routing_avoid_tracks, 2, 0, 1, 1)
self.verticalLayout.addWidget(self.routing_avoid_tags_group)
self.buttonBox = QtWidgets.QDialogButtonBox(ORStoolsDialogAdvancedBase)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
Expand All @@ -71,11 +63,8 @@ def retranslateUi(self, ORStoolsDialogAdvancedBase):
self.routing_avoid_tags_group.setTitle(_translate("ORStoolsDialogAdvancedBase", "Avoid tags"))
self.routing_avoid_highways.setText(_translate("ORStoolsDialogAdvancedBase", "highways"))
self.routing_avoid_toll.setText(_translate("ORStoolsDialogAdvancedBase", "tollways"))
self.routing_avoid_tunnels.setText(_translate("ORStoolsDialogAdvancedBase", "tunnels"))
self.routing_avoid_ferries.setText(_translate("ORStoolsDialogAdvancedBase", "ferries"))
self.routing_avoid_fords.setText(_translate("ORStoolsDialogAdvancedBase", "fords"))
self.routing_avoid_tracks.setText(_translate("ORStoolsDialogAdvancedBase", "tracks"))
self.routing_avoid_paved.setText(_translate("ORStoolsDialogAdvancedBase", "pavedroads"))
self.routing_avoid_unpaved.setText(_translate("ORStoolsDialogAdvancedBase", "unpavedroads"))
self.routing_avoid_tracks.setText(_translate("ORStoolsDialogAdvancedBase", "steps"))

from qgscollapsiblegroupbox import QgsCollapsibleGroupBox
27 changes: 3 additions & 24 deletions ORStools/gui/ORStoolsDialogAdvancedUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,23 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="routing_avoid_tunnels">
<property name="text">
<string>tunnels</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="routing_avoid_ferries">
<property name="text">
<string>ferries</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="1">
<widget class="QCheckBox" name="routing_avoid_fords">
<property name="text">
<string>fords</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="0">
<widget class="QCheckBox" name="routing_avoid_tracks">
<property name="text">
<string>tracks</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="routing_avoid_paved">
<property name="text">
<string>pavedroads</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="routing_avoid_unpaved">
<property name="text">
<string>unpavedroads</string>
<string>steps</string>
</property>
</widget>
</item>
Expand Down
4 changes: 1 addition & 3 deletions ORStools/gui/ORStoolsDialogConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _add_provider(self):

self._collapse_boxes()
# Show quick user input dialog
provider_name, ok = QInputDialog.getText(self, "New Pelias provider", "Enter a name for the provider")
provider_name, ok = QInputDialog.getText(self, "New ORS provider", "Enter a name for the provider")
if ok:
self._add_box(provider_name, 'https://', '', new=True)

Expand Down Expand Up @@ -146,8 +146,6 @@ def _add_box(self,
name=name,
base_url=url,
key=key,
limit=limit,
unit=unit,
endpoints={
"directions": "/directions",
"isochrones": "/isochrones",
Expand Down
7 changes: 7 additions & 0 deletions ORStools/gui/ORStoolsDialogUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ def setupUi(self, ORStoolsDialogBase):
self.help_button.setIcon(icon4)
self.help_button.setObjectName("help_button")
self.horizontalLayout_8.addWidget(self.help_button)
self.about_button = QtWidgets.QPushButton(self.widget_2)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_about.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.about_button.setIcon(icon5)
self.about_button.setObjectName("about_button")
self.horizontalLayout_8.addWidget(self.about_button)
self.global_buttons = QtWidgets.QDialogButtonBox(self.widget_2)
self.global_buttons.setOrientation(QtCore.Qt.Horizontal)
self.global_buttons.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
Expand Down Expand Up @@ -436,6 +442,7 @@ def retranslateUi(self, ORStoolsDialogBase):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.batch_tab), _translate("ORStoolsDialogBase", "Batch Jobs"))
self.debug_text.setPlaceholderText(_translate("ORStoolsDialogBase", "Queries and errors will be printed here."))
self.help_button.setText(_translate("ORStoolsDialogBase", " Help"))
self.about_button.setText(_translate("ORStoolsDialogBase", "About"))

from qgsfilterlineedit import QgsFilterLineEdit
from . import resources_rc
11 changes: 11 additions & 0 deletions ORStools/gui/ORStoolsDialogUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,17 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="about_button">
<property name="text">
<string>About</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/plugins/ORStools/img/icon_about.png</normaloff>:/plugins/ORStools/img/icon_about.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="global_buttons">
<property name="orientation">
Expand Down
5 changes: 3 additions & 2 deletions ORStools/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ name=ORS Tools
qgisMinimumVersion=3.0
description=openrouteservice routing, isochrones and matrix calculations for QGIS

version=1.0.4
version=1.0.5
author=GIS • OPS UG
email=nils@gis-ops.com

about=ORS Tools provides access to most of the functions of openrouteservice.org, based on OpenStreetMap. The tool set includes routing, isochrones and matrix calculations, either interactive in the map canvas or from point files within the processing framework. Extensive attributes are set for output files, incl. duration, length and start/end locations.

changelog=2019/04/17 v1.0.4 POSTing doesn't want dicts as parameter (#100)
changelog=2019/05/02 v1.0.5 Custom provider didn't work (#103), better handling when no API key set (#101)
2019/04/17 v1.0.4 POSTing doesn't want dicts as parameter (#100)
2019/04/15 v1.0.3 Drop requests module and implement NetworkAccessManager to leverage QGIS Proxy settings (#98); no more user defined rate limits (#97)
2019/03/14 v1.0.2 Fix mixup of source and destination layer in matrix algo (#92), UTF-8 encoding issues for Mac OSX (#91)
2019/03/01 v1.0.1 Provide default for isochrone layer ID field (#90)
Expand Down

0 comments on commit 4559068

Please sign in to comment.