Skip to content
Permalink
Browse files

OSM: small usability improvements in download dialog

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12517 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 19, 2009
1 parent 501d9a5 commit b4a7fe3a30982b1307abd1306d916e1d1c4e4607
Showing with 19 additions and 43 deletions.
  1. +19 −43 python/plugins/osm/OsmDownloadDlg.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""@package OsmDownloadDlg
Module provides simple way how to download OSM data.
First user is asked to choose download region, output file etc.
@@ -54,7 +55,6 @@ def __init__(self, plugin):
self.urlPathPrefix="/api/0.6/map?bbox="

self.downloadButton.setDefault(True)
self.downloadButton.setEnabled(False)

# determining default area for download
if QgsMapLayerRegistry.instance().count()>0:
@@ -99,7 +99,6 @@ def __init__(self, plugin):
defaultFileName=self.generateDefFileName()
self.destdirLineEdit.setText(defaultFileName)
self.destdirLineEdit.setEnabled(True)
self.downloadButton.setEnabled(True)

# check default extent
self.checkExtent()
@@ -119,12 +118,6 @@ def downloadFile(self):
It's called after click() signal is emitted on Download button.
"""

if self.finished:
return

self.downloadButton.setEnabled(False)
self.disconnectDlgSignals()

# finding out which area should be downloaded, and to where
urlPath = self.urlPathPrefix + self.lonFromLineEdit.text() + "," + self.latFromLineEdit.text() + "," + self.lonToLineEdit.text() + "," + self.latToLineEdit.text()
fileName = self.destdirLineEdit.text()
@@ -141,15 +134,16 @@ def downloadFile(self):
self.outFile = None
return

self.setEnabled(False)
self.finished = False

# creating progress dialog for download
self.progressDialog=QProgressDialog(self)
# !!! don't set progress dialog modal !!! it would cause serious problems!
self.progressDialog.setAutoClose(False)
self.progressDialog.setWindowTitle(self.tr("OSM Download"))
self.connect(self.progressDialog,SIGNAL("canceled()"), self.progressDlgCanceled)

self.setEnabled(False)
self.progressDialog.setEnabled(True)
self.progressDialog.show()
self.progressDialog.setLabelText(self.tr("Waiting for OpenStreetMap server ..."))
self.progressDialog.setMaximum(1)
@@ -254,6 +248,9 @@ def httpDone(self,error):
del self.http
self.http=None

self.progressDialog.close()
self.setEnabled(True)

# request was not aborted
if error:
self.httpSuccess=False
@@ -263,17 +260,18 @@ def httpDone(self,error):
del self.outFile
self.outFile=None

# and tell user
if self.errMessage==None:
self.errMessage="Check your internet connection"
QMessageBox.information(self, self.tr("OSM Download Error")
,self.tr("Download failed: %1.").arg(self.errMessage))
else:
self.httpSuccess=True
# and tell user (if the download wasn't cancelled by user)
if self.errMessage != "__cancel__":
if self.errMessage==None:
self.errMessage="Check your internet connection"
QMessageBox.information(self, self.tr("OSM Download Error")
,self.tr("Download failed: %1.").arg(self.errMessage))
return

self.httpSuccess=True

# well, download process has finished successfully;
# close progress dialog and the whole download dialog
self.progressDialog.close()
# close the whole download dialog
self.close()


@@ -304,15 +302,11 @@ def showChooseDirectoryDialog(self):
Only OSM files can be selected.
"""

if self.finished:
return

# display file open dialog and get absolute path to selected directory
fileSelected = QFileDialog.getSaveFileName(self, "Choose file to save","download.osm", "OSM Files (*.osm)");
# insert selected directory path into line edit control
if not fileSelected.isNull():
self.destdirLineEdit.setText(fileSelected)
self.downloadButton.setEnabled(True)


def generateDefFileName(self):
@@ -322,9 +316,6 @@ def generateDefFileName(self):
Default name is always unique. It consist of current timestamp and a postfix.
"""

if self.finished:
return

prefix=QDir.tempPath() + "/"
if self.dbm.currentKey:
key=QString(self.dbm.currentKey)
@@ -339,9 +330,6 @@ def autoLoadClicked(self):
"""Function is called after clicking on AutoLoad checkbox.
"""

if self.finished:
return

if not self.autoLoadCheckBox.isChecked():
self.chkCustomRenderer.setEnabled(False)
self.chkReplaceData.setEnabled(False)
@@ -355,9 +343,6 @@ def showExtentHelp(self):
It shows basic information on downloading.
"""

if self.finished:
return

mb=QMessageBox()
mb.setMinimumWidth(390)
mb.information(self, self.tr("Getting data"),self.tr("The OpenStreetMap server you are downloading OSM data from (~ api.openstreetmap.org) has fixed limitations of how much data you can get. As written at <http://wiki.openstreetmap.org/wiki/Getting_Data> neither latitude nor longitude extent of downloaded region can be larger than 0.25 degrees. Note that Quantum GIS allows you to specify any extent you want, but OpenStreetMap server will reject all request that won't satisfy downloading limitations."))
@@ -370,9 +355,6 @@ def checkExtent(self):
Result of checking is displayed on dialog.
"""

if self.finished:
return

lim = 0.25 # download limitations of openstreetmap server in degrees

# get coordinates that are currently set
@@ -406,11 +388,8 @@ def progressDlgCanceled(self):
It aborts HTTP connection.
"""

if self.finished:
return

# cancel download with no message for user
self.cancelDownload()
# cancel download with a special message
self.cancelDownload("__cancel__")


def setProxy(self):
@@ -420,9 +399,6 @@ def setProxy(self):
because it's global - accessible for the whole downloader.
"""

if self.finished:
return

# getting and setting proxy information
settings=QSettings()
proxyHost=QString()

0 comments on commit b4a7fe3

Please sign in to comment.
You can’t perform that action at this time.