I am developing an ImageJ plugin and I ran into this problem.
I am using GenericDialog with a text field, so the user can input a file system path. On windows, the path contains backslashes. When I am recording a macro for this plugin, I get this result: run("Import results", "path=C:\results.txt") The backslash is not escaped and when i try to run the recorded command, the backslash is interpreted as an escape character and obviously, the file can't be found. Can I use GenericDialog in a way that it correctly records text fields containing backslashes? Or I can't use GenericDialog and have to implement macro recording functionality myself? Wouldn't it be better if the recorded value from String field had backslashes replaced with double backslashes? Josef Borkovec -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Wayne, dear all,
I have observed the same in Fiji on Mac and Windows (although on Mac, you rarely need to use backslashes). Apparently, escape characters are correctly resolved when building a GenericDialog: gd.addStringField("path", "C:\\results.txt"); // gets displayed in the text field as "C:\results.txt" and the same when run from a macro: run("Example ", "path=C:\\results.txt"); // path contains "C:\results.txt" However, the recorder just records the plain string value instead of escaping the characters in it, so the former GenericDialog gets recorded as: run("Example ", "path=C:\results.txt"); // resulting in path containing "C:esults.txt" May I suggest to add an escaping routine to ij.plugin.frame.Recorder's recordOption method? https://github.com/fiji/imagej1/blob/master/ij/plugin/frame/Recorder.java#L319 Cheers, Jan On 05.06.2013 4:00 PM, Josef Borkovec wrote: > I am developing an ImageJ plugin and I ran into this problem. > > I am using GenericDialog with a text field, so the user can input a > file system path. On windows, the path contains backslashes. When I am > recording a macro for this plugin, I get this result: > > run("Import results", "path=C:\results.txt") > > The backslash is not escaped and when i try to run the recorded > command, the backslash is interpreted as an escape character and > obviously, the file can't be found. > > Can I use GenericDialog in a way that it correctly records text fields > containing backslashes? Or I can't use GenericDialog and have to > implement macro recording functionality myself? Wouldn't it be better > if the recorded value from String field had backslashes replaced with > double backslashes? > > Josef Borkovec > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Josef,
Could you simply replace the backslashes input by the user with the system file separator? Maybe something like below? gd.addStringField("path","C:\results.txt"); pathToFile=gd.getNextString(); pathToFile=pathToFile.replace("\\", File.separator); In this case I don't think your users will need to do anything other than copy and paste the file path into the text field. George On Jun 6, 2013, at 6:25 AM, Jan Eglinger wrote: > Dear Wayne, dear all, > > I have observed the same in Fiji on Mac and Windows (although on Mac, > you rarely need to use backslashes). Apparently, escape characters are > correctly resolved when building a GenericDialog: > > gd.addStringField("path", "C:\\results.txt"); > // gets displayed in the text field as "C:\results.txt" > > and the same when run from a macro: > > run("Example ", "path=C:\\results.txt"); > // path contains "C:\results.txt" > > > However, the recorder just records the plain string value instead of > escaping the characters in it, so the former GenericDialog gets recorded as: > > run("Example ", "path=C:\results.txt"); > // resulting in path containing "C:esults.txt" > > May I suggest to add an escaping routine to ij.plugin.frame.Recorder's > recordOption method? > https://github.com/fiji/imagej1/blob/master/ij/plugin/frame/Recorder.java#L319 > > Cheers, > Jan > > > > > On 05.06.2013 4:00 PM, Josef Borkovec wrote: >> I am developing an ImageJ plugin and I ran into this problem. >> >> I am using GenericDialog with a text field, so the user can input a >> file system path. On windows, the path contains backslashes. When I am >> recording a macro for this plugin, I get this result: >> >> run("Import results", "path=C:\results.txt") >> >> The backslash is not escaped and when i try to run the recorded >> command, the backslash is interpreted as an escape character and >> obviously, the file can't be found. >> >> Can I use GenericDialog in a way that it correctly records text fields >> containing backslashes? Or I can't use GenericDialog and have to >> implement macro recording functionality myself? Wouldn't it be better >> if the recorded value from String field had backslashes replaced with >> double backslashes? >> >> Josef Borkovec >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html George H. Patterson Building 13 3E33 13 South Drive Biophotonics Section National Institute of Biomedical Imaging and Bioengineering National Institutes of Health Bethesda, MD 20892 Office: 301-443-0241 Fax: 301-496-6608 [hidden email] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Josef Borkovec
On Jun 5, 2013, at 10:00 AM, Josef Borkovec wrote:
> I am developing an ImageJ plugin and I ran into this problem. > > I am using GenericDialog with a text field, so the user can input a > file system path. On windows, the path contains backslashes. When I am > recording a macro for this plugin, I get this result: > > run("Import results", "path=C:\results.txt") > > The backslash is not escaped and when i try to run the recorded > command, the backslash is interpreted as an escape character and > obviously, the file can't be found. > > Can I use GenericDialog in a way that it correctly records text fields > containing backslashes? Or I can't use GenericDialog and have to > implement macro recording functionality myself? Wouldn't it be better > if the recorded value from String field had backslashes replaced with > double backslashes? This bug is fixed in the ImageJ 1.47t daily build. This code String path = "C:\\path\\to\\results.txt"; GenericDialog gd = new GenericDialog("Path Test"); gd.addStringField("Path:", path, 30); gd.showDialog(); path = gd.getNextString(); now records as run("Import Results", "path=C:\\path\\to\\results.txt"); -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |