Skip to content

Commit 8aa554d

Browse files
author
wonder
committed
OSM: small usability improvements in download dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk@12517 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f7542e0 commit 8aa554d

File tree

1 file changed

+19
-43
lines changed

1 file changed

+19
-43
lines changed

python/plugins/osm/OsmDownloadDlg.py

+19-43
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""@package OsmDownloadDlg
23
Module provides simple way how to download OSM data.
34
First user is asked to choose download region, output file etc.
@@ -54,7 +55,6 @@ def __init__(self, plugin):
5455
self.urlPathPrefix="/api/0.6/map?bbox="
5556

5657
self.downloadButton.setDefault(True)
57-
self.downloadButton.setEnabled(False)
5858

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

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

122-
if self.finished:
123-
return
124-
125-
self.downloadButton.setEnabled(False)
126-
self.disconnectDlgSignals()
127-
128121
# finding out which area should be downloaded, and to where
129122
urlPath = self.urlPathPrefix + self.lonFromLineEdit.text() + "," + self.latFromLineEdit.text() + "," + self.lonToLineEdit.text() + "," + self.latToLineEdit.text()
130123
fileName = self.destdirLineEdit.text()
@@ -141,15 +134,16 @@ def downloadFile(self):
141134
self.outFile = None
142135
return
143136

137+
self.setEnabled(False)
138+
self.finished = False
139+
144140
# creating progress dialog for download
145141
self.progressDialog=QProgressDialog(self)
146142
# !!! don't set progress dialog modal !!! it would cause serious problems!
147143
self.progressDialog.setAutoClose(False)
148144
self.progressDialog.setWindowTitle(self.tr("OSM Download"))
149145
self.connect(self.progressDialog,SIGNAL("canceled()"), self.progressDlgCanceled)
150146

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

251+
self.progressDialog.close()
252+
self.setEnabled(True)
253+
257254
# request was not aborted
258255
if error:
259256
self.httpSuccess=False
@@ -263,17 +260,18 @@ def httpDone(self,error):
263260
del self.outFile
264261
self.outFile=None
265262

266-
# and tell user
267-
if self.errMessage==None:
268-
self.errMessage="Check your internet connection"
269-
QMessageBox.information(self, self.tr("OSM Download Error")
270-
,self.tr("Download failed: %1.").arg(self.errMessage))
271-
else:
272-
self.httpSuccess=True
263+
# and tell user (if the download wasn't cancelled by user)
264+
if self.errMessage != "__cancel__":
265+
if self.errMessage==None:
266+
self.errMessage="Check your internet connection"
267+
QMessageBox.information(self, self.tr("OSM Download Error")
268+
,self.tr("Download failed: %1.").arg(self.errMessage))
269+
return
270+
271+
self.httpSuccess=True
273272

274273
# well, download process has finished successfully;
275-
# close progress dialog and the whole download dialog
276-
self.progressDialog.close()
274+
# close the whole download dialog
277275
self.close()
278276

279277

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

307-
if self.finished:
308-
return
309-
310305
# display file open dialog and get absolute path to selected directory
311306
fileSelected = QFileDialog.getSaveFileName(self, "Choose file to save","download.osm", "OSM Files (*.osm)");
312307
# insert selected directory path into line edit control
313308
if not fileSelected.isNull():
314309
self.destdirLineEdit.setText(fileSelected)
315-
self.downloadButton.setEnabled(True)
316310

317311

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

325-
if self.finished:
326-
return
327-
328319
prefix=QDir.tempPath() + "/"
329320
if self.dbm.currentKey:
330321
key=QString(self.dbm.currentKey)
@@ -339,9 +330,6 @@ def autoLoadClicked(self):
339330
"""Function is called after clicking on AutoLoad checkbox.
340331
"""
341332

342-
if self.finished:
343-
return
344-
345333
if not self.autoLoadCheckBox.isChecked():
346334
self.chkCustomRenderer.setEnabled(False)
347335
self.chkReplaceData.setEnabled(False)
@@ -355,9 +343,6 @@ def showExtentHelp(self):
355343
It shows basic information on downloading.
356344
"""
357345

358-
if self.finished:
359-
return
360-
361346
mb=QMessageBox()
362347
mb.setMinimumWidth(390)
363348
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):
370355
Result of checking is displayed on dialog.
371356
"""
372357

373-
if self.finished:
374-
return
375-
376358
lim = 0.25 # download limitations of openstreetmap server in degrees
377359

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

409-
if self.finished:
410-
return
411-
412-
# cancel download with no message for user
413-
self.cancelDownload()
391+
# cancel download with a special message
392+
self.cancelDownload("__cancel__")
414393

415394

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

423-
if self.finished:
424-
return
425-
426402
# getting and setting proxy information
427403
settings=QSettings()
428404
proxyHost=QString()

0 commit comments

Comments
 (0)