You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal is to have a script open a local file, then manipulate the layers. Issue I am facing here is that I cannot find a way to tell script "wait until the file is loaded and only then continue execute the remaining tasks". As a result layer count is not updated in the code below:
Jython:
from javax.swing import JOptionPane
from org.openstreetmap.josm.gui import MainApplication
from org.openstreetmap.josm.actions import OpenFileAction
import java.io.File as File
from java.lang import Thread
# JOSM is started, no layer is opened
layerManager = MainApplication.getLayerManager()
all_layers = layerManager.getLayers()
JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 'Layer count: {}'.format(len(all_layers)))
# Layer count: 0
# async open of a single file, we now (should) have 1 layer opened
# but we need this task to finish first
open_file_action = OpenFileAction.openFiles([File('/path/to/local/file.osm')])
'''
# this blocks forever:
while True:
if open_file_action.isDone():
break
Thread.sleep(300);
# this blocks forever too:
open_file_action.get()
'''
# this works but a user must click [OK] to continue
JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 'wait for open')
all_layers = layerManager.getLayers()
JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 'Layer count: {}'.format(len(all_layers)))
# Layer count: 1
The goal is to have a script open a local file, then manipulate the layers. Issue I am facing here is that I cannot find a way to tell script "wait until the file is loaded and only then continue execute the remaining tasks". As a result layer count is not updated in the code below:
Jython:
JS (courtesy of @zdila)
The text was updated successfully, but these errors were encountered: