opensim-org / opensim-gui

SimTK OpenSim graphical user interface and distribution.
Apache License 2.0
62 stars 33 forks source link

Exception when using utils.FileUtils.getInstance().browseForFolder() #869

Closed jimmyDunne closed 6 years ago

jimmyDunne commented 6 years ago

Jen: Scripts in the GUI commonly ask users to browse for a folder. Need an example on Mac +Windows of how to do this.

Use code in GUI script: resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with CMC Results")

Returns an exception;

>>> Traceback (most recent call last):
  File "/Users/jimmy/repository/opensim-models/Tutorials/Design_to_Reduce_Metabolic_Cost/Scripts/CMC_EvaluateResults.py", line 8, in <module>
    resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with CMC Results");
TypeError: browseForFolder(): expected 0 or 2-3 args; got 1

I suppose the method has changed. how is the new version written?

tkuchida commented 6 years ago

Perhaps utils.FileUtils.getInstance().browseForFolder(0, "blah blah")? https://msdn.microsoft.com/en-us/library/windows/desktop/bb774065(v=vs.85).aspx

jimmyDunne commented 6 years ago

Thanks, Tom. Still something funky going on.

resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with CMC Results",0); opens a dialogue, but when a folder is selected an exception is returned;

    at org.opensim.utils.FileUtils.browseForFolder(FileUtils.java:286)
    at org.opensim.utils.FileUtils.browseForFolder(FileUtils.java:253)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

java.lang.NullPointerException: java.lang.NullPointerException

I am doing this on a Mac. This seems to be an issue with the custom functions here. @aymanhab, please let me know what the call should be or if it requires a fix on the GUI side. Thanks.

tkuchida commented 6 years ago

resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with CMC Results",0); opens a dialogue, but when a folder is selected an exception is returned;

I recommended passing 0 as the first argument, not the second. Regardless, I was just guessing; Ayman will know.

aymanhab commented 6 years ago

@jimmyDunne the code suggests all these signatures are supported `` public String browseForFolder()

public String browseForFolder(String description, boolean allowCreate)

public String browseForFolder(Frame parent, String description, boolean allowCreate)

`` Can you provide a full snippet as I don't know what classes/packages are imported in your environment. And does the same code work on Windows? Thanks

jimmyDunne commented 6 years ago
import org.opensim.utils as utils

# Obtain Directory containing CMC results
resultsFolderCMC = utils.FileUtils.getInstance().browseForFolder("Select the folder with CMC Results",0);

The code is in the GUI repo here. You will be able to test it pretty easily.

aymanhab commented 6 years ago

Same code ran on Windows without issue, will try on an osx machine with debugger.

aymanhab commented 6 years ago

On iMacPro works like a charm, and brings a dialog to browse for folder. anything specific to your environment @jimmyDunne ? Anybody else to try the two lines above?

jenhicks commented 6 years ago

@jimmyDunne Can I close this issue now?

jimmyDunne commented 6 years ago

browseForFolder() is still not working in the GUI on Mac.


trcDataFolder = utils.FileUtils.getInstance().browseForFolder("Select the folder")

returns

Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: browseForFolder(): expected 0 or 2-3 args; got 1

trcDataFolder = utils.FileUtils.getInstance().browseForFolder("Select the folder",0);

Opens a dialogue but once you select a folder it returns

>>> trcDataFolder = utils.FileUtils.getInstance().browseForFolder("Select the folder",0);
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    at org.opensim.utils.FileUtils.browseForFolder(FileUtils.java:286)
    at org.opensim.utils.FileUtils.browseForFolder(FileUtils.java:253)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

java.lang.NullPointerException: java.lang.NullPointerException

trcDataFolder = utils.FileUtils.getInstance().browseForFolder();

Opens a dialogue but once you select a folder it returns

>>> trcDataFolder = utils.FileUtils.getInstance().browseForFolder();
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    at org.opensim.utils.FileUtils.browseForFolder(FileUtils.java:286)
    at org.opensim.utils.FileUtils.browseForFolder(FileUtils.java:248)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

java.lang.NullPointerException: java.lang.NullPointerException