Page 1 of 1

Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 12:44 am
by bbrraayyaann
Hi I am using OpenFile and when I call the function it opens the file explorer with the last default path.
Is there any way to use OpenFile,
to open a specific path?

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 1:50 am
by synthsin75
No, all of Moho defaults to the last directory.

The CurrentDirectory is stored in the user.settings file in AppData, but even changing that doesn't change where Moho opens the dialog.
That only changes when you actually open something in Moho. So Moho must have some internal, inaccessible place it stores the last directory.

I've even tried opening files using other scripting commands, like FileOpen, FileImport, SetSourceImage. But none change the current directory.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 1:58 am
by bbrraayyaann
synthsin75 wrote: Sun Jan 29, 2023 1:50 am A I see, thanks for the answer.
I will try to look for some external lua code on the web to see if I can find something.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 2:53 am
by SimplSam
The other thing I wish it had - is the ability to specify the listed file spec. i.e. *.jpg,*.png

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 8:25 am
by synthsin75
Depending on what you want to do, you could basically create your own open dialog.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.

Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..

So maybe not too bad a workaround.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 11:09 am
by bbrraayyaann
It would be great to create a custom directory.
I have seen your Switch Icons script, would it be something like this ?
Put images in a dialog box and select according to moho:GetNextFile().

Or perhaps a file explorer could be created.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 3:00 pm
by SimplSam
synthsin75 wrote: Sun Jan 29, 2023 8:25 am Depending on what you want to do, you could basically create your own open dialog.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.
Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..
So maybe not too bad a workaround.
That would not work for general any user file browsing, as it requires the path to be known. I would also have to contend with the lack of sorting, additional filtering, file info etc. and the inability to preview thumbnails etc.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 3:17 pm
by hayasidist
bbrraayyaann wrote: Sun Jan 29, 2023 12:44 am Hi I am using OpenFile and when I call the function it opens the file explorer with the last default path.
Is there any way to use OpenFile,
to open a specific path?
at the risk of sounding dumb -- are you opening a file using LM.GUI.OpenFile(caption) or ScriptInterface:FileOpen(path) or Lua's io.open (filename [, mode]) .. and would a different call give you what you want?

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 3:49 pm
by bbrraayyaann
hayasidist wrote: Sun Jan 29, 2023 3:17 pm
Yes, I am using LM.GUI.OpenFile(caption),
I am creating a script for a switch layer, and I have added an option to directly import an image or moho file directly to the switch, and when using that function I would need a specific path to save time.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 6:21 pm
by Rai López
bbrraayyaann wrote: Sun Jan 29, 2023 12:44 am Hi I am using OpenFile and when I call the function it opens the file explorer with the last default path.
Is there any way to use OpenFile,
to open a specific path?
Something like "moho:SetLastDir()" or "moho:SetOpenDir()" sounds to me like a perfectly reasonable feature request that I'm sure would have been added if someone had thought about it (I wish!) when the other ones (AppDir, UserAppDir, etc) was added. But it's never too late, I guess...

SimplSam wrote: Sun Jan 29, 2023 2:53 am The other thing I wish it had - is the ability to specify the listed file spec. i.e. *.jpg,*.png
And that would be definitely like the icing on the cake.

So the only workaround (to call it something :roll:) for the moment that I can think is to pass the desired path to clipboard, e. g. like this:

Code: Select all

moho:CopyText("D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu")
Just before calling LM.GUI.OpenFile(), so that you can then simply paste it manually into the open file window's address bar and that way can go directly to there. A little convoluted solution and you have to take into account it overwrites anything in clipboard of course, but could save you some time and steps to get there if that's not too much a problem...

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 7:21 pm
by bbrraayyaann
Ramón López wrote: Sun Jan 29, 2023 6:21 pm Yes, that's exactly what I was thinking ...
Before calling Open file copy the path to the clipboard, although you could also put a quick access in Windows. But if the quick access is full it would be useful to copy the path to the clipboard first.
It would still be good to put that function, I think it is not so difficult and also as SimplSam says, the option to only specify what type of files are allowed would be more complete.
Pd: I just saw the CopyText() thing, I thought it did not exist.

Re: Custom path for LM.GUI.OpenFile?

Posted: Sun Jan 29, 2023 9:28 pm
by synthsin75
SimplSam wrote: Sun Jan 29, 2023 3:00 pm
synthsin75 wrote: Sun Jan 29, 2023 8:25 am Depending on what you want to do, you could basically create your own open dialog.
You'd start by using moho:BeginFileListing(dir, listHiddenAndSystemFiles), so you could specify the directory.
You'd do a loop of moho:GetNextFile() to make a list of files, which you could then edit for one or more specific extensions.
Then you'd have to present those choices to the user and open the selected one/s using FileOpen, FileImport, SetSourceImage, etc..
So maybe not too bad a workaround.
That would not work for general any user file browsing, as it requires the path to be known. I would also have to contend with the lack of sorting, additional filtering, file info etc. and the inability to preview thumbnails etc.
Yeah, the OP needed to open a specific directory.
You could sort the results, like when you edit for extensions, before offering them to the user.

Re: Custom path for LM.GUI.OpenFile?

Posted: Mon Jan 30, 2023 10:37 am
by hayasidist
try this (windows):

Code: Select all

	local path = "D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu\\"
	local sOut = io.popen( "dir /B " .. path .. "*.png", "r" )
	local sData = sOut:read "*a"
--	print sData 
that will give you all the .pngs in that directory in a string with each entry delimited by new line; or use *l in a loop to get each line (nil on EoF). see http://www.lua.org/manual/5.2/manual.html#6.8

you could then use the filenames in a drop down to choose which one(s) to include or whatever....

Re: Custom path for LM.GUI.OpenFile?

Posted: Mon Jan 30, 2023 12:09 pm
by bbrraayyaann
hayasidist wrote: Mon Jan 30, 2023 10:37 am try this (windows):

Code: Select all

	local path = "D:\\Projects\\Moho\\Moho Pro\\Scripts\\Menu\\"
	local sOut = io.popen( "dir /B " .. path .. "*.png", "r" )
	local sData = sOut:read "*a"
--	print sData 
that will give you all the .pngs in that directory in a string with each entry delimited by new line; or use *l in a loop to get each line (nil on EoF). see http://www.lua.org/manual/5.2/manual.html#6.8

you could then use the filenames in a drop down to choose which one(s) to include or whatever....
How would it work exactly?
Does sOut return a path or string?

Re: Custom path for LM.GUI.OpenFile?

Posted: Mon Jan 30, 2023 12:30 pm
by hayasidist
if you read using "*a" you get it all in one go as a string of the form of abc.png <newline> def.png <newline> etc. ;

if you read in a loop using "*l" you get each filename as a string on each call

if you want to use the names in ImageLayer:SetSourceImage(path) - concatenate filepath and filename