[josm-dev] downloading referrers and incomplete relation members from a script

Jo winfixit at gmail.com
Tue Oct 4 06:21:57 BST 2011


Hi,

I'm using the following code to download referrers and incomplete relation
members:

from javax.swing import JOptionPanefrom org.openstreetmap.josm import
Mainimport org.openstreetmap.josm.actions.DownloadReferrersAction as
DownloadReferrersActiondef getMapView():
    if Main.main and Main.main.map:
        return Main.main.map.mapView
    else:
        return None

mv = getMapView()if mv and mv.editLayer and mv.editLayer.data:
    selectedElements = mv.editLayer.data.getSelected()

    if not(selectedElements):
        JOptionPane.showMessageDialog(Main.parent, "Please select an element")
    else:
        DownloadReferrersAction.downloadReferrers(mv.editLayer,
selectedElements)

Download missing relation members:

#!/bin/jython
'''

This code is released under the GNU General
Public License v2 or later.

The GPL v3 is accessible here:http://www.gnu.org/licenses/gpl.html

The GPL v2 is accessible
here:http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

It comes with no warranty whatsoever.

This code illustrates how to use Jython to:
* Download all missing members of a relation

'''
from javax.swing import JOptionPane
from org.openstreetmap.josm import Main
import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask
as DownloadRelationMemberTask

def getMapView():
    if Main.main and Main.main.map:
        return Main.main.map.mapView
    else:
        return None

mv = getMapView()
if mv and mv.editLayer and mv.editLayer.data:
    selectedRelations = mv.editLayer.data.getSelectedRelations()

    if not(selectedRelations):
        JOptionPane.showMessageDialog(Main.parent, "Please select a node")
    else:
        for relation in selectedRelations:
            if relation.hasIncompleteMembers():
                #print dir(relation)
                print dir(DownloadRelationMemberTask)

DownloadRelationMemberTask.run(DownloadRelationMemberTask(relation,
relation.getIncompleteMembers(), mv.editLayer ))


And it works... asynchronously. If I use this code in a larger script, the
code following it gets executed before the download is ready. This, of
course, creates problems since the rest of the code depends on what was
being downloaded.

Is there a way to make it wait? I've been trying countless scenarios All to
no avail.

Many thanks for your help.

Jo


More information about the josm-dev mailing list