IUP deb and pet packages for use with small Lua interpreter
IUP documentation is quite reasonable. Here are just a few useful function reference links (you can search for others). A bit technical but not hard to understand if you've done some programming before. But best way into it all is just to try things... Often it is actually quite simple and understanding comes from just "doing it" - getting it to 'work' as intended.
This first hint/tip link is quite well illustrated:
https://www.fhug.org.uk/wiki/wiki/doku. ... s_and_tips
A good starting point tutorial, though some of the info may be out-of-date:
https://webserver2.tecgraf.puc-rio.br/i ... index.html
https://webserver2.tecgraf.puc-rio.br/iup/en/guide.html
https://webserver2.tecgraf.puc-rio.br/i ... uplua.html
Some tecgraf manual pages:
Most of the official tecgraf docs can be accessed from the left hand menu here:
http://webserver2.tecgraf.puc-rio.br/iup/
For example: http://webserver2.tecgraf.puc-rio.br/iu ... alogs.html
Some pages from the IUP manual:
https://webserver2.tecgraf.puc-rio.br/i ... ialog.html
The following tutorials are for C with IUP, but much of the IUP control discussion remains relevant to Lua with IUP:
https://webserver2.tecgraf.puc-rio.br/i ... orial.html
It's also worth noting that Tables are the only container type in Lua (so just that to learn!):
http://lua-users.org/wiki/TablesTutorial
Note that there are several ways to access the contents of tables, but check out the LuaRocks style guide near foot of this post for preferred way.
Yes, you can refresh/re-draw a dialog easily it seems:
https://webserver2.tecgraf.puc-rio.br/i ... fresh.html
and create popups:
https://webserver2.tecgraf.puc-rio.br/i ... popup.html
and a probably very useful function for developers to check out the hierarch of elements in their designed dialog:
https://webserver2.tecgraf.puc-rio.br/i ... ialog.html
and a bit info on how it all hangs together:
https://webserver2.tecgraf.puc-rio.br/i ... guide.html
There is not a lot of difference in understanding how to build GUIs with IUP if you use FreeBASIC 'talking to' Lua/IUP via a stack, so worth looking at dialog examples there too:
https://www.freebasic.net/forum/viewtopic.php?t=14869
And a consistent coding style is always important:
https://github.com/luarocks/lua-style-guide
Lua books and manual:
http://nova-fusion.com/2012/08/27/lua-f ... rs-part-1/
https://www.lua.org/pil/contents.html
https://www.lua.org/manual/5.3/
Lua WIKI IS GREAT FOR CODE PATTERN HOWTO DO STUFF IN LUA:
http://lua-users.org/wiki/
http://lua-users.org/wiki/OsLibraryTutorial
Lua unofficial FAQ:
http://www.luafaq.org/
Lua quick reference card (again):
http://www.capgo.com/Resources/Software ... tRef51.pdf
Lua in 15 minutes (again):
http://tylerneylon.com/a/learn-lua/
There is a lot of info above, but truth is I haven't read hardly any of it yet and, per usual, find easier to just to copy a few exemplars and pick things up on the way. Bottom line is that , if there is something you want in your GUI, menu, tabs, popups, there is probably some existing control/function that easily allows you to do it in IUP with Lua, and in terms of portability it is generally cross-platform usable (in most all UNIXes and in Windoze).
Like most 'languages', the key to learning IUP with Lua is just to use the controls you need for the purpose you want (hence me starting with very versatile iup.GetParam() control (along with iup.Message()) , since its use reminded me so much of yad-type dialogs).
wiak
This first hint/tip link is quite well illustrated:
https://www.fhug.org.uk/wiki/wiki/doku. ... s_and_tips
A good starting point tutorial, though some of the info may be out-of-date:
https://webserver2.tecgraf.puc-rio.br/i ... index.html
https://webserver2.tecgraf.puc-rio.br/iup/en/guide.html
https://webserver2.tecgraf.puc-rio.br/i ... uplua.html
Some tecgraf manual pages:
Most of the official tecgraf docs can be accessed from the left hand menu here:
http://webserver2.tecgraf.puc-rio.br/iup/
For example: http://webserver2.tecgraf.puc-rio.br/iu ... alogs.html
Some pages from the IUP manual:
https://webserver2.tecgraf.puc-rio.br/i ... ialog.html
The following tutorials are for C with IUP, but much of the IUP control discussion remains relevant to Lua with IUP:
https://webserver2.tecgraf.puc-rio.br/i ... orial.html
It's also worth noting that Tables are the only container type in Lua (so just that to learn!):
http://lua-users.org/wiki/TablesTutorial
Note that there are several ways to access the contents of tables, but check out the LuaRocks style guide near foot of this post for preferred way.
Yes, you can refresh/re-draw a dialog easily it seems:
https://webserver2.tecgraf.puc-rio.br/i ... fresh.html
and create popups:
https://webserver2.tecgraf.puc-rio.br/i ... popup.html
and a probably very useful function for developers to check out the hierarch of elements in their designed dialog:
https://webserver2.tecgraf.puc-rio.br/i ... ialog.html
and a bit info on how it all hangs together:
https://webserver2.tecgraf.puc-rio.br/i ... guide.html
There is not a lot of difference in understanding how to build GUIs with IUP if you use FreeBASIC 'talking to' Lua/IUP via a stack, so worth looking at dialog examples there too:
https://www.freebasic.net/forum/viewtopic.php?t=14869
And a consistent coding style is always important:
https://github.com/luarocks/lua-style-guide
Lua books and manual:
http://nova-fusion.com/2012/08/27/lua-f ... rs-part-1/
https://www.lua.org/pil/contents.html
https://www.lua.org/manual/5.3/
Lua WIKI IS GREAT FOR CODE PATTERN HOWTO DO STUFF IN LUA:
http://lua-users.org/wiki/
http://lua-users.org/wiki/OsLibraryTutorial
Lua unofficial FAQ:
http://www.luafaq.org/
Lua quick reference card (again):
http://www.capgo.com/Resources/Software ... tRef51.pdf
Lua in 15 minutes (again):
http://tylerneylon.com/a/learn-lua/
There is a lot of info above, but truth is I haven't read hardly any of it yet and, per usual, find easier to just to copy a few exemplars and pick things up on the way. Bottom line is that , if there is something you want in your GUI, menu, tabs, popups, there is probably some existing control/function that easily allows you to do it in IUP with Lua, and in terms of portability it is generally cross-platform usable (in most all UNIXes and in Windoze).
Like most 'languages', the key to learning IUP with Lua is just to use the controls you need for the purpose you want (hence me starting with very versatile iup.GetParam() control (along with iup.Message()) , since its use reminded me so much of yad-type dialogs).
wiak
Last edited by wiak on Sun 15 Apr 2018, 12:07, edited 2 times in total.
Lua to shell commands
Now that I have GUI constructed for fredx181's gifenc program, I need to appropriately execute ffmpeg program to finish the job... Aside from the iuplua GUI, the following is actually my first Lua program, to find out how easy it is to run shell commands from Lua using os.execute() function. Run the following Lua program and you should immediately realise how easy it is:
IT IS WORTH BEARING IN MIND, HOWEVER:
That a lot of stuff we typically use shell commands for can better (and faster) be done by Lua functions instead... But, if it 'works', it works...
Note how I've used semicolons in the above for the sake of bash (as you know a semicolon is used to tell bash where the end of a commandline is, assuming all commands written on same line). I used grep for capital letter P, but you can grep whatever you like...
Now I want to find out how io.open() can be used instead (hopefully) since I feel that might be even more useful (?). Note that os.execute() is like system() call in C.
EDIT: Okay here is a small Lua script example of using io.popen() that seems to work (you can call the variables, such as wiak_control, anything you like of course - as long as not Lua keywords I suppose). I've just hacked this together so best you check proper Lua style guide on how such code should better be written...:
So above should give me enough control to finish off that gifenc-iup.lua program... If I need more powerful shell command control, I suspect adding LuaPosix module would probably give a lot more functionality. Or maybe luash (see previous post for links to LuaPosix and luash optional extras). But for now, I doubt I'll need these extra 'batteries' (I think they call modules 'batteries' in Lua, which you load in with the 'require' keyword).
I'm using zerobrane IDE to enter and run these code snippets, by the way, though you can just use leafpad or geany if you like. Zerobrane gives lots of useful diagnostic messages though. If you use it, remember to Edit -> Preferences - Settings:System to contain the PATH to your lua execuatable. For example:
Otherwise, just put the code sample in a text file, say test.lua, and run it from a terminal with: lua5.3 test.lua. Alternatively, in test.lua, you could add header line telling script where your Lua binary is. For example: #!/usr/bin/lua5.3, and then just run with. for example: ./test.lua. Zerobrane is great though and very helpful.
If you can already script in bash, you can be up and running programming Lua in minutes. Easiest, I've found, is just to read whatever you need from here:
http://lua-users.org/wiki/
In particular, you can find how to do most things you are used to doing in bash but in Lua in "LuaDirectory":
http://lua-users.org/wiki/LuaDirectory
You are likely to definitely find the following useful:
http://lua-users.org/wiki/OsLibraryTutorial
http://lua-users.org/wiki/IoLibraryTutorial
http://lua-users.org/wiki/FileSystemOperations
http://lua-users.org/wiki/StringsTutorial
wiak
Code: Select all
Lua_arg1 = "echo Hello World; "
Lua_arg2 = "ls -al /root | grep 'P'; "
any_name_will_do = "ls -al /root | wc"
commandstring = Lua_arg1 .. Lua_arg2 .. any_name_will_do --concatenating the strings with Lua .. syntax
runstatus = os.execute(commandstring)
print(runstatus)
That a lot of stuff we typically use shell commands for can better (and faster) be done by Lua functions instead... But, if it 'works', it works...
Note how I've used semicolons in the above for the sake of bash (as you know a semicolon is used to tell bash where the end of a commandline is, assuming all commands written on same line). I used grep for capital letter P, but you can grep whatever you like...
Now I want to find out how io.open() can be used instead (hopefully) since I feel that might be even more useful (?). Note that os.execute() is like system() call in C.
EDIT: Okay here is a small Lua script example of using io.popen() that seems to work (you can call the variables, such as wiak_control, anything you like of course - as long as not Lua keywords I suppose). I've just hacked this together so best you check proper Lua style guide on how such code should better be written...:
Code: Select all
wiak_command = "ls -al | wc -l;"
wiak_command2 = 'echo This seems to work!'
wiak_command = wiak_command .. "date;" .. wiak_command2
-- above concatenates the strings with Lua .. syntax
wiak_filepointer1 = assert (io.popen (wiak_command))
for line in wiak_filepointer1:lines() do
print(line)
end -- for loop
wiak_filepointer1:close()
I'm using zerobrane IDE to enter and run these code snippets, by the way, though you can just use leafpad or geany if you like. Zerobrane gives lots of useful diagnostic messages though. If you use it, remember to Edit -> Preferences - Settings:System to contain the PATH to your lua execuatable. For example:
Code: Select all
path.lua = '/usr/bin/lua5.3'
If you can already script in bash, you can be up and running programming Lua in minutes. Easiest, I've found, is just to read whatever you need from here:
http://lua-users.org/wiki/
In particular, you can find how to do most things you are used to doing in bash but in Lua in "LuaDirectory":
http://lua-users.org/wiki/LuaDirectory
You are likely to definitely find the following useful:
http://lua-users.org/wiki/OsLibraryTutorial
http://lua-users.org/wiki/IoLibraryTutorial
http://lua-users.org/wiki/FileSystemOperations
http://lua-users.org/wiki/StringsTutorial
wiak
gifenc-iup.lua translation of early version of gifenc-yad
The following is no more than an exemplar for Puppy/Dog developers on how to write small GUI utility apps using IUP/Lua.
The code below is for a working 'not quite exact' IUP/Lua translation of an early version of fredx181's gifenc-yad animated gif maker (code for Fred's original is also attached for code-writing comparison purposes).
To run gifenc-iup.lua, simply make it executable with chmod +x and then run it from the directory it is in with command:
Note that the Lua code function param_action() is not actually required here, but I left it in to illustrate how it can be used for additional logic.
In this version, I'm simply using system call via os.execute() to run the appropriate commandline utils (such as ffmpeg). Could instead have used io.popen() command to allow reading of command output into Lua.
Please note that I do not intend improving this gifenc version. If you want to use gifenc you should in practice therefore use the latest bash/yad version from Fred since it has additional functionality. Fred's latest is gifenc-sel, which you can download in first link below:
http://murga-linux.com/puppy/viewtopic. ... 724#948724
http://murga-linux.com/puppy/viewtopic. ... 267#981267
Note: Please do not think of the following code as good Lua programming style! You should definitely refer to the following for appropriate guidance with that:
https://github.com/luarocks/lua-style-guide
fredx181's original early version:
wiak
The code below is for a working 'not quite exact' IUP/Lua translation of an early version of fredx181's gifenc-yad animated gif maker (code for Fred's original is also attached for code-writing comparison purposes).
To run gifenc-iup.lua, simply make it executable with chmod +x and then run it from the directory it is in with command:
Code: Select all
./gifenc-iup.lua <path_to_video_to_convert_to_gif>
In this version, I'm simply using system call via os.execute() to run the appropriate commandline utils (such as ffmpeg). Could instead have used io.popen() command to allow reading of command output into Lua.
Please note that I do not intend improving this gifenc version. If you want to use gifenc you should in practice therefore use the latest bash/yad version from Fred since it has additional functionality. Fred's latest is gifenc-sel, which you can download in first link below:
http://murga-linux.com/puppy/viewtopic. ... 724#948724
http://murga-linux.com/puppy/viewtopic. ... 267#981267
IUP/Lua version:fredx181 wrote:Also here (weX thread), see EDIT5 (and attached scripts):
http://murga-linux.com/puppy/viewtopic. ... 724#948724
Note: Please do not think of the following code as good Lua programming style! You should definitely refer to the following for appropriate guidance with that:
https://github.com/luarocks/lua-style-guide
Code: Select all
#!/usr/bin/lua5.3
-- gifenc-iup.lua: translated by wiak from fredx181's early gifenc-yad version
require( "iuplua" )
-- set initial values
assert(os.setlocale('C'))
vid = arg[1]; SIZE = 100; START = 0; DUR = 0; NUM = 1
if os.execute("command -v ffmpeg >/dev/null")~=true then
iup.Message("gifenc-iup.lua", "No ffmpeg found, please install ffmpeg")
os.exit(1)
end
if (arg[1] == nil) then
iup.Message("gifenc-iup.lua", "USAGE: ./gifenc-iup.lua path_to_video_file")
os.exit(2)
end
function do_convert()
palette = "/tmp/palette.png"
filters = "fps=10,scale="..SIZE..":-1:flags=lanczos"
ffmpeg_args1 = "-ss "..START.." -t "..DUR.." -v warning -i "..vid.." -loop "..NUM.." -vf ""..filters..",palettegen" -y "..palette
result = os.execute("ffmpeg "..ffmpeg_args1)
ffmpeg_args2 = "-ss "..START.." -t "..DUR.." -v warning -i "..vid.." -i "..palette.." -loop "..NUM.." -lavfi ""..filters.." [x]; [x][1:v] paletteuse" -y "..vid:match("(.+)%..+")..".gif"
result = os.execute("ffmpeg "..ffmpeg_args2)
os.execute("xterm -T 'PLEASE WAIT FOR GIF ENCODE' -e sleep 3")
end
function param_action(dialog, param_index) --this function not actually required for gifenc
if (param_index == iup.GETPARAM_OK) then
print("OK pressed")
elseif (param_index == iup.GETPARAM_CANCEL) then
print("Cancel pressed")
os.exit(3)
end
return 1
end
ret, SIZE, START, DUR, NUM =
iup.GetParam("GifenC-iuplua", param_action,
"Convert (portion of) short video to animated gif%t\n"..
"The new .gif will be in the same folder as the video%t\n"..
" Please set the desired .gif size%t\n"..
"Size: %i[0,2000,10]\n"..
" Set start time and duration: %t\n"..
"Start at (seconds): %r[0,20000,.01]\n"..
"Duration (seconds) (0=all): %r[0,20000,.01]\n"..
"Do not loop (just once): %b\n",
SIZE, START, DUR, NUM)
result = do_convert()
iup.Message("gifenc-iup.lua", vid:match("(.+)%..+")..".gif has been created")
os.exit(0)
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end
Code: Select all
#!/bin/bash
export LC_ALL=C
if [ -z "$(which ffmpeg)" ]; then
yad --width=300 --title "No ffmpeg found" --center --text " No ffmpeg found, please install ffmpeg \n Press Close to exit " --button="gtk-close:0"
exit
fi
# ffmpeg -i try.mkv -vf "setpts=(1/6)*PTS" output.mp4
SETUP=`yad --width=400 --title="GifenC" --center --text=" Convert (portion of) short video to animated gif \n The new .gif will be in the same folder as the video \n \tPlease set the desired .gif size" \
--window-icon="folder-system" --form \
--field=" Size: :NUM" "100!20..2000!10" \
--field=" \tSet start time and duration: :LBL" "" \
--field=" Start at (seconds): :NUM" "0!0..20000!0.010!3" \
--field=" Duration (seconds) (0=all): :NUM" "0!0..20000!0.010!3" \
--field=" Do not loop (just once):CHK" "FALSE" \
--button="gtk-cancel:1" --button="gtk-ok:0"`
ret=$?
[[ $ret -ne 0 ]] && exit 1
echo $SETUP
export SIZE=$(echo $SETUP | cut -d "|" -f 1 | cut -f1 -d".")
export START=$(echo $SETUP | cut -d "|" -f 3)
export DUR=$(echo $SETUP | cut -d "|" -f 4)
export LOOP=$(echo $SETUP | cut -d "|" -f 5)
echo $SIZE
echo $START
echo $DUR
echo $LOOP
if [ "$LOOP" = "TRUE" ]; then
export NUM=1
else
export NUM=0
fi
echo $1
if [ -z "$1" ]; then
yad --title "No Input" --center --text " No input video provided \n Press Close to exit " --button="gtk-close:0"
exit
fi
export vid=$1
run_xterm () {
palette="/tmp/palette.png"
filters="fps=10,scale=$SIZE:-1:flags=lanczos"
ffmpeg -ss $START -t $DUR -v warning -i $vid -loop $NUM -vf "$filters,palettegen" -y $palette
ffmpeg -ss $START -t $DUR -v warning -i $vid -i $palette -loop $NUM -lavfi "$filters [x]; [x][1:v] paletteuse" -y ${vid%.*}.gif
sleep 3
}
export -f run_xterm
xterm -T "GifenC" -e /bin/bash -c run_xterm
- Attachments
-
- Screenshot_gifenc_iuplua.jpg
- Screenshot of UIP/Lua version
- (28.05 KiB) Downloaded 530 times
Last edited by wiak on Mon 16 Apr 2018, 23:12, edited 4 times in total.
Hi wiak, works well your new gifenc lua script, lots of progress you made !
Only when I tested on my system with locale set to dutch it failed (can't remember why that happens exactly atm, something to with dot changed to comma in numeric value output).
I solved that in newer gifenc-yad by putting " export LC_ALL=C" on top of script (but maybe there's better way).
Fred
Only when I tested on my system with locale set to dutch it failed (can't remember why that happens exactly atm, something to with dot changed to comma in numeric value output).
I solved that in newer gifenc-yad by putting " export LC_ALL=C" on top of script (but maybe there's better way).
Fred
Thanks for testing, Fred. I've added an os.setlocale() call to the top of the program I posted. Could you test it in dutch with that inserted.fredx181 wrote: Only when I tested on my system with locale set to dutch it failed (can't remember why that happens exactly atm, something to with dot changed to comma in numeric value output).
I solved that in newer gifenc-yad by putting " export LC_ALL=C" on top of script (but maybe there's better way).
Code: Select all
assert(os.setlocale('C'))
http://lua-users.org/wiki/LuaLocales
As far as possible gettext support is concerned, all I've found is:
https://www.gnu.org/software/gettext/ma ... e/Lua.html
https://www.gnu.org/software/gettext/ma ... 002dformat
https://gitlab.com/sukhichev/lua-gettex ... ADME.us.md
https://launchpad.net/~sukhichev/+archi ... ua-gettext
https://github.com/LubomirR/gettext-lua
The following i18n module from kikito seems to be used in some Lua projects:
https://luarocks.org/modules/kikito/i18n
https://github.com/kikito/i18n.lua
https://stackoverflow.com/questions/413 ... nalization
https://github.com/kaishiqi/I18N-Gettext-Supported
Another alternative?
https://luarocks.org/modules/damvgn/babel
Basically, I know nothing about this. Hopefully some of the Internationalisation experts on this forum can look into this?
wiak
Last edited by wiak on Mon 16 Apr 2018, 22:59, edited 14 times in total.
IUP/Lua translation of gifenc-sel
Sorry, I couldn't resist... Just for practice I made an IUP/Lua close copy version of Fred's gifenc-sel more advanced version from here:
http://murga-linux.com/puppy/viewtopic. ... 724#948724
I haven't tested either version much, but seems to be working as intended. Also works if video file given as first commandline argument.
You just need to copy this code into a text file called gifenc-iup.lua and make it executable with:
Well, you also need to install a copy of Lua version 5.3 on your system (say in /usr/bin/lua5.3 and install the iuplua-core dotpet or deb package found in the first post of this thread (Lua and iupluacore come to less than 1MB download, so not a big install...). Once you have that installed you can use Lua with IUP for all sort of other apps too. Lua with IUP is just as easy to program as yad (I'd say slightly easier actually), much easier than bash/gtkdialog and much more powerful than both:
http://www.murga-linux.com/puppy/viewto ... 611#987611
wiak
http://murga-linux.com/puppy/viewtopic. ... 724#948724
I haven't tested either version much, but seems to be working as intended. Also works if video file given as first commandline argument.
You just need to copy this code into a text file called gifenc-iup.lua and make it executable with:
Code: Select all
chmod +x gifenc-iup.lua
http://www.murga-linux.com/puppy/viewto ... 611#987611
wiak
Code: Select all
#!/usr/bin/lua5.3
-- gifenc-iup.lua: translated by wiak from fredx181's gifenc-sel yad code
require( "iuplua" )
-- set initial values
assert(os.setlocale('C'))
VIDFILE = arg[1] or ""; SIZE = 100; START = 0; DUR = 0; NUM = 0; LOWQUAL = 0
if os.execute("command -v ffmpeg >/dev/null")~=true then
iup.Message("gifenc-iup.lua", "No ffmpeg found, please install ffmpeg")
os.exit(1)
end
function do_convert()
print("LOWQUAL", LOWQUAL)
if LOWQUAL == 1 then
print("Low quality selected...")
filters="fps=4,scale="..SIZE..":-1"
result = os.execute("ffmpeg -ss "..START.." -t "..DUR.." -v warning -i "..VIDFILE.." -loop "..NUM.." -vf \""..filters.."\" -y "..VIDFILE:match("(.+)%..+")..".gif")
else
palette = "/tmp/palette.png"
filters = "fps=10,scale="..SIZE..":-1:flags=lanczos"
ffmpeg_args1 = "-ss "..START.." -t "..DUR.." -v warning -i "..VIDFILE.." -loop "..NUM.." -vf \""..filters..",palettegen\" -y "..palette
result = os.execute("ffmpeg "..ffmpeg_args1)
ffmpeg_args2 = "-ss "..START.." -t "..DUR.." -v warning -i "..VIDFILE.." -i "..palette.." -loop "..NUM.." -lavfi \""..filters.." [x]; [x][1:v] paletteuse\" -y "..VIDFILE:match("(.+)%..+")..".gif"
result = os.execute("ffmpeg "..ffmpeg_args2)
end
os.execute("xterm -T 'PLEASE WAIT FOR GIF ENCODE' -e sleep 3")
end
function param_action(dialog, param_index) --this function not actually required for gifenc
if (param_index == iup.GETPARAM_OK) then
print("OK pressed")
elseif (param_index == iup.GETPARAM_CANCEL) then
print("Cancel pressed")
os.exit(3)
end
return 1
end
ret, VIDFILE, SIZE, START, DUR, NUM, LOWQUAL =
iup.GetParam("GifenC-iuplua", param_action,
"Convert (portion of) short video to animated gif%t\n"..
"The new .gif will be in the same folder as the video%t\n"..
"Select video: %f\n"..
" Please set the desired .gif size%t\n"..
"Size: %i[0,2000,10]\n"..
" Set start time and duration: %t\n"..
"Start at (seconds): %r[0,20000,.01]\n"..
"Duration (seconds) (0=all): %r[0,20000,.01]\n"..
"Do not loop (just once): %b\n"..
"Low quality (much smaller gif size): %b\n",
VIDFILE, SIZE, START, DUR, NUM, LOWQUAL)
result = do_convert()
iup.Message("gifenc-iup.lua", VIDFILE:match("(.+)%..+")..".gif has been created")
os.exit(0)
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end
- Attachments
-
- Screenshot gifenc_sel_iuplua.jpg
- Screenshot gifenc-sel IUP/Lua version
- (33.38 KiB) Downloaded 406 times
1. To create a GUI dialog with IUPLua you can use one of the pre-defined dialogs, such as the very versatile yad-like dialog created using iup.GetParam(), or some other pop-up dialog such iup.filedlg for selecting files or directories. An exemplar for this yad-like dialog method, using iup.GetParam() function is given via the link below:
http://www.murga-linux.com/puppy/viewto ... 818#988818
with more sophisticated version here:
http://www.murga-linux.com/puppy/viewto ... 877#988877
As described, the above is an IUPLua translation of fredx181's gifenc-sel bash/yad program.
----------
2. Alternatively, you can build your own dialogs from scratch (in similar, but easier fashion, to Puppy's favourite gtkdialog), using 'Reference' dialog widgets such as iup.dialog, which you can fill with, for example, iup.tabs{}, iup.frame{}, iup.vbox{}, iup.hbox{} containers and fill these with components of type iup.button{}, iup.label{}, iup.radio{}, iup.toggle{}, iup.text{} and so on.
What follows is an exemplar showing the creation of a IUPLua dialog that has the look and feel of the GUI dialog used in makepup bash/gtkdialog program. Note that the example below only creates the GUI dialog; for makepup functionality the additional code required to process and use the woof-CE scripts would have to be added. First I show the gtkdialog code extract from original bash/gtkdialog makeput, then the IUPLua code translation, followed by an alternative IUPLua code translation (which illustrates how to break dialogs up in IUPLua).
IUPLua dialogs are much easier to put together than the equivalent gtkdialog pseudo-xml constructs, I find, and have the advantage of being able to be easily broken up using that second bottom-up piecemeal build approach. As you can see, you can also insert comments directly into IUP constructs, which makes documentation and debugging significantly easier.
Owing to the amount of illustrative code, this is a very long post. I suggest opening it up in two browser tabs so that you can compare the gtkdialog version more easily with that of IUPLua. Hope this example is helpful to others who would like to enjoy developing GUI apps with IUPLua, which is as simple as using yad, but with all the power (and much more) of gtkdialog scripting (in addition to providing the speed, power, clean coding style, and flexibility of Lua programming, which means there is no limit to the simplicity or sophistication of the apps you can write with IUPLua):
This is gtkdialog dialog-creation code used in makepup programme of http://www.murga-linux.com/puppy/viewto ... 541#965541 where you can find a screenshot of the result:
There follows an almost exact IUPLua translation of the above, which you can try by putting it in a text file, making that executable with chmod +x and then executing it with lua5.3:
IUPLua (unlike gtkdialog) can be very easily broken down into smaller parts in bottom-up design fashion, which makes debugging easier in larger dialog creations. Here is the above partially re-written in that bottom-up coding fashion, which is a IUP recommended approach:
You can find the reference for all the containers and controls you can use to produce IUP GUI dialogs in the left-most panel here, which also gives you all the attribute information you can add for each control:
http://webserver2.tecgraf.puc-rio.br/iup/
A summary of some of the available controls can be found here:
http://www.allbasic.info/forum/index.ph ... 35#msg2435
and examples for most of the widget/controls here:
https://webserver2.tecgraf.puc-rio.br/iup/examples/Lua/
Note that I haven't manage to get label alignment working quite as I'd like (I tried alignment="ACENTER:ACENTER" attribute). It's a minor issue in practice, but please let me know if you find how to do that, or any other improvements (or other example code) that I and others might find useful.
wiak
http://www.murga-linux.com/puppy/viewto ... 818#988818
with more sophisticated version here:
http://www.murga-linux.com/puppy/viewto ... 877#988877
As described, the above is an IUPLua translation of fredx181's gifenc-sel bash/yad program.
----------
2. Alternatively, you can build your own dialogs from scratch (in similar, but easier fashion, to Puppy's favourite gtkdialog), using 'Reference' dialog widgets such as iup.dialog, which you can fill with, for example, iup.tabs{}, iup.frame{}, iup.vbox{}, iup.hbox{} containers and fill these with components of type iup.button{}, iup.label{}, iup.radio{}, iup.toggle{}, iup.text{} and so on.
What follows is an exemplar showing the creation of a IUPLua dialog that has the look and feel of the GUI dialog used in makepup bash/gtkdialog program. Note that the example below only creates the GUI dialog; for makepup functionality the additional code required to process and use the woof-CE scripts would have to be added. First I show the gtkdialog code extract from original bash/gtkdialog makeput, then the IUPLua code translation, followed by an alternative IUPLua code translation (which illustrates how to break dialogs up in IUPLua).
IUPLua dialogs are much easier to put together than the equivalent gtkdialog pseudo-xml constructs, I find, and have the advantage of being able to be easily broken up using that second bottom-up piecemeal build approach. As you can see, you can also insert comments directly into IUP constructs, which makes documentation and debugging significantly easier.
Owing to the amount of illustrative code, this is a very long post. I suggest opening it up in two browser tabs so that you can compare the gtkdialog version more easily with that of IUPLua. Hope this example is helpful to others who would like to enjoy developing GUI apps with IUPLua, which is as simple as using yad, but with all the power (and much more) of gtkdialog scripting (in addition to providing the speed, power, clean coding style, and flexibility of Lua programming, which means there is no limit to the simplicity or sophistication of the apps you can write with IUPLua):
This is gtkdialog dialog-creation code used in makepup programme of http://www.murga-linux.com/puppy/viewto ... 541#965541 where you can find a screenshot of the result:
Code: Select all
simplegui () {
export SIMPLEGUI="
<window title=\"makepup $programversion\">
<vbox>
<notebook labels=\"$(gettext 'Basic|Advanced')\">
<vbox>
<frame $(gettext 'Settings')>
<hbox>
<text><label>$(gettext 'woof-CE-branch [-w]: ')</label></text>
<combobox>
<variable>WOOFBRANCH</variable>
$(combobox_list woof-CE-testing woof-CE-rationalise)
</combobox>
</hbox>
<hbox>
<text><label>$(gettext 'target architecture [-t]: ')</label></text>
<combobox>
<variable>TARGETARCH</variable>
$(combobox_list 2:x86 1:arm 2:x86 3:x86_64)
</combobox>
</hbox>
<hbox>
<text><label>$(gettext 'distro base [-d]: ')</label></text>
<combobox>
<variable>COMPATDISTRO</variable>
$(combobox_list 3:slackware 1:debian 2:devuan 3:slackware 4:trisquel 5:ubuntu)
</combobox>
</hbox>
<hbox>
<text><label>$(gettext 'release version [-r]: ')</label></text>
<combobox>
<variable>COMPATVERSION</variable>
$(combobox_list 3:Slackware14.2 1:DebianStretch 1:DevuanAscii 1:Slackware14.0 1:UbuntuArtful32 1:UbuntuTahr64 1:TrisquelBelenos 2:Slackware14.1 2:UbuntuTahr32 2:UbuntuXenial64 3:Slackware14.2 3:UbuntuXenial32)
</combobox>
</hbox>
<hbox>
<text><label>$(gettext 'Huge kernel [-H]: ')</label></text>
<combobox>
<variable>HUGEKERNEL</variable>
${HKERNEL_ITEMS}
</combobox>
</hbox>
</frame>
<hbox>
<text><label>$(gettext 'Check your settings and then:')</label></text>
<button>
<label>$(gettext 'Build your Pup!')</label>
<action type=\"exit\">BUILD</action>
</button>
</hbox>
</vbox>
<vbox>
<frame $(gettext 'makepup optional switches')>
<checkbox>
<label>$(gettext '[-D] also build devx')</label>
<variable>DEVX</variable>
</checkbox>
<checkbox>
<label>$(gettext '[-k] keep previous woof-CE branch')</label>
<variable>KEEPBRANCH</variable>
<default>$KEEPBRANCH</default>
</checkbox>
<checkbox>
<label>$(gettext '[-R] REBUILD ALL_PACKAGES (post-install scripts etc)')</label>
<variable>REBUILDALL</variable>
</checkbox>
<checkbox>
<label>$(gettext '[-T] allow pop-up "choose-THEMES" gui during build')</label>
<variable>POPUPTHEMES</variable>
</checkbox>
<checkbox>
<label>$(gettext '[-p] pause makepup soon after 0setup routine')</label>
<variable>PAUSE</variable>
</checkbox>
<checkbox>
<label>$(gettext '[-a] adds pets from local-repositories/pets2add/')</label>
<variable>ADDPETS</variable>
</checkbox>
<checkbox>
<label>$(gettext '[-A] adds packages from local-repositories/pkgs2add/')</label>
<variable>ADDPKGS</variable>
</checkbox>
<checkbox>
<label>$(gettext '[-i] interactive mode (like woof-CE manual build)')</label>
<variable>INTERACTIVE</variable>
</checkbox>
<radiobutton>
<label>$(gettext 'Use woof-CE default extra rootfs-packages')</label>
<variable>DEFAULTEXTRA</variable>
</radiobutton>
<radiobutton>
<label>$(gettext 'Use makepup_extra.conf for extra rootfs-packages')</label>
<variable>EXTRACONF</variable>
</radiobutton>
<radiobutton>
<label>$(gettext 'allow pop-up "choose extra rootfs-packages" gui')</label>
<variable>POPUPEXTRA</variable>
</radiobutton>
</frame>
<hbox>
<text><label>$(gettext 'Check your settings and then:') </label></text>
<button>
<label>$(gettext 'Build your Pup!')</label>
<action type=\"exit\">BUILD</action>
</button>
</hbox>
</vbox>
</notebook>
<hbox>
<button tooltip-text=\"$(gettext 'Opens filemanager at local-repositories/pets2add directory')\">
<label>$(gettext 'pets2add')</label>
<action>$FMANAGER local-repositories/pets2add</action>
</button>
<button tooltip-text=\"$(gettext 'Opens filemanager at local-repositories/pkgs2add directory')\">
<label>$(gettext 'pkgs2add')</label>
<action>$FMANAGER local-repositories/pkgs2add</action>
</button>
<button tooltip-text=\"$(gettext 'Opens filemanager at local-repositories/huge_kernels directory')\">
<label>$(gettext 'kernel2add')</label>
<action>$FMANAGER local-repositories/kernel2add</action>
</button>
<button><label>$(gettext 'QUIT')</label></button>
</hbox>
</vbox>
</window>
"
Code: Select all
-- Program: makepup-iup.lua (GUI part as iuplua exemplar)
-- Version 1.0a: one big dialog...
-- Author: wiak (https://github.com/wiake). Licence: MIT
require( "iuplua" )
programversion = "1.0a"
-- Creates dialog
simplegui = iup.dialog{
iup.vbox -- start of outermost container
{
iup.tabs -- start of tabs
{
iup.frame -- start of main frame1
{
iup.vbox -- start of main vbox1
{
iup.hbox
{
iup.fill{},
-- note that I haven't managed to get label to align with dropdown list
-- alignment="ARIGHT:ACENTER" didn't work (nor did ":ACENTER")
iup.label{title="woof-CE-branch [-w]: "},
iup.list {"woof-CE testing", "woof-CE rationalise"; dropdown="YES", value=1, bgcolor="255 255 0", size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="target architecture [-t]: "},
iup.list {"1:arm", "2:x86", "3x86_64"; dropdown="YES", value=2, size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="distro base [-d]: "},
iup.list {"1:debian", "2:devuan", "3:slackware", "4:trisquel", "5:ubuntu"; dropdown="YES", value=3, size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="release version [-r]: "},
iup.list {"1:DebianStretch", "1:DevuanAscii", "1:Slackware14.0", "1:UbuntuArtful32", "1:UbuntuTahr64", "1:TrisquelBelenos", "2:Slackware14.1", "2:UbuntuTahr32", "2:UbuntuXenial64", "3:Slackware14.2", "3:UbuntuXenial32"; dropdown="YES", bgcolor="255 0 128", fgcolor="255 0 128", value=10, size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="Huge kernel [-H]: "},
iup.list {"hugekernel_list"; dropdown="YES", value=1, size="80x"}
},
iup.fill{},
iup.frame
{
iup.hbox{
iup.fill{},
iup.label{title="Check your settings and then: "},
iup.button{title="Build your Pup!"}
}
}
}; -- end of main vbox1
title = "Settings", -- attribute of main frame1
tabtitle = "Basic"
}, -- end of main frame1
iup.frame -- start of main frame2
{
iup.vbox -- start of main vbox2
{
iup.toggle{title = "[-D] also build devx"},
iup.toggle{title = "[-k] keep previous woof-CE branch", value="ON"},
iup.toggle{title = "[-R] REBUILD ALL_PACKAGES (post-install scripts etc)"},
iup.toggle{title = '[-T] allow pop-up "choose-THEMES" gui during build'},
iup.toggle{title = "[-p] pause makepup soon after 0setup routine"},
iup.toggle{title = "[-a] adds pets from local-repositories/pets2add/"},
iup.toggle{title = "[-A] adds packages from local-repositories/pkgs2add/"},
iup.toggle{title = "[-i] interactive mode (like woof-CE manual build)"},
iup.radio
{
iup.vbox
{
iup.toggle{title="Use woof-CE default extra rootfs-packages"},
iup.toggle{title="Use makepup_extra.conf for extra rootfs-packages"},
iup.toggle{title='allow pop-up "choose extra rootfs-packages" gui'}
};
value=1
},
iup.fill{},
iup.frame
{
iup.hbox{
iup.fill{},
iup.label{title="Check options and then: "},
iup.button{title="Build your advanced Pup!"}
}
}
}; -- end of main vbox2
title = "makepup optional switches", -- attribute of main frame2
tabtitle = "Advanced",
fgcolor = "0 0 255"
} -- end of main frame2
}, -- end of tabs
iup.vbox
{
iup.hbox{
iup.fill{},
iup.button{title="pets2add", tip='Opens filemanager at local-repositories/pets2add directory'},
iup.button{title="pkgs2add", tip='Opens filemanager at local-repositories/pkgs2add directory'},
iup.button{title="kernel2add", tip='Opens filemanager at local-repositories/huge_kernels directory'},
iup.button{title="QUIT"}
}
}
}; -- end of outermost container
title="makepup-iuplua " .. programversion
}
-- Shows dialog in the center of the screen
simplegui:showxy(iup.CENTER, iup.CENTER)
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end
Code: Select all
-- Program: makepup-iup.lua (GUI part as iuplua exemplar)
-- Version 1.0b: partially broken into bottom-up design pieces
-- Author: wiak (https://github.com/wiake). Licence: MIT
require( "iuplua" )
programversion = "1.0b"
-- Create main frames
frame1_bottom = iup.frame
{
iup.hbox
{
iup.fill{},
iup.label{title="Check your settings and then: "},
iup.button{title="Build your Pup!"}
}
}
frame2_bottom = iup.frame
{
iup.hbox
{
iup.fill{},
iup.label{title="Check options and then: "},
iup.button{title="Build your advanced Pup!"}
}
}
frame1 = iup.frame{
iup.vbox -- start of main vbox1
{
iup.hbox
{
iup.fill{},
-- note that I haven't managed to get label to align with dropdown list
-- alignment="ARIGHT:ACENTER" didn't work (nor did ":ACENTER")
iup.label{title="woof-CE-branch [-w]: "},
iup.list {"woof-CE testing", "woof-CE rationalise"; dropdown="YES", value=1, bgcolor="255 255 0", size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="target architecture [-t]: "},
iup.list {"1:arm", "2:x86", "3x86_64"; dropdown="YES", value=2, size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="distro base [-d]: "},
iup.list {"1:debian", "2:devuan", "3:slackware", "4:trisquel", "5:ubuntu"; dropdown="YES", value=3, size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="release version [-r]: "},
iup.list {"1:DebianStretch", "1:DevuanAscii", "1:Slackware14.0", "1:UbuntuArtful32", "1:UbuntuTahr64", "1:TrisquelBelenos", "2:Slackware14.1", "2:UbuntuTahr32", "2:UbuntuXenial64", "3:Slackware14.2", "3:UbuntuXenial32"; dropdown="YES", bgcolor="255 0 128", fgcolor="255 0 128", value=10, size="80x"}
},
iup.hbox
{
iup.fill{},
iup.label{title="Huge kernel [-H]: "},
iup.list {"hugekernel_list"; dropdown="YES", value=1, size="80x"}
},
iup.fill{},
frame1_bottom
}; -- end of main vbox1
title = "Settings", -- attribute of main frame1
tabtitle = "Basic"
}
--[[ or after frame1 already defined, could here instead now use:
frame1.title = "Settings"
frame1.tabtitle = "Basic"
]]
frame2 = iup.frame{
iup.vbox -- start of main vbox2
{
iup.toggle{title = "[-D] also build devx"},
iup.toggle{title = "[-k] keep previous woof-CE branch", value="ON"},
iup.toggle{title = "[-R] REBUILD ALL_PACKAGES (post-install scripts etc)"},
iup.toggle{title = '[-T] allow pop-up "choose-THEMES" gui during build'},
iup.toggle{title = "[-p] pause makepup soon after 0setup routine"},
iup.toggle{title = "[-a] adds pets from local-repositories/pets2add/"},
iup.toggle{title = "[-A] adds packages from local-repositories/pkgs2add/"},
iup.toggle{title = "[-i] interactive mode (like woof-CE manual build)"},
iup.radio
{
iup.vbox
{
iup.toggle{title="Use woof-CE default extra rootfs-packages"},
iup.toggle{title="Use makepup_extra.conf for extra rootfs-packages"},
iup.toggle{title='allow pop-up "choose extra rootfs-packages" gui'}
};
value=1
},
iup.fill{},
frame2_bottom
}; -- end of main vbox2
title = "makepup optional switches", -- attribute of main frame2
tabtitle = "Advanced",
fgcolor = "0 0 255"
}
--[[ or after frame2 is already defined, could here instead now use:
frame2.title = "makepup optional switches"
frame2.tabtitle = "Advanced"
frame2.fgcolor = "0 0 255"
]]
-- Creates tabs
tabs = iup.vbox{iup.tabs{frame1, frame2}}
-- Creates dialog
makepup_dlg = iup.dialog{
iup.vbox -- start of outermost container
{
tabs,
iup.hbox{ -- this horizontal panel will be identical in both tabs
iup.fill{},
iup.button{title="pets2add", tip='Opens filemanager at local-repositories/pets2add directory'},
iup.button{title="pkgs2add", tip='Opens filemanager at local-repositories/pkgs2add directory'},
iup.button{title="kernel2add", tip='Opens filemanager at local-repositories/huge_kernels directory'},
iup.button{title="QUIT"}
}
}; -- end of outermost container
title="makepup-iuplua " .. programversion
}
-- Shows dialog in the center of the screen
makepup_dlg:showxy(iup.CENTER, iup.CENTER)
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end
http://webserver2.tecgraf.puc-rio.br/iup/
A summary of some of the available controls can be found here:
http://www.allbasic.info/forum/index.ph ... 35#msg2435
and examples for most of the widget/controls here:
https://webserver2.tecgraf.puc-rio.br/iup/examples/Lua/
Note that I haven't manage to get label alignment working quite as I'd like (I tried alignment="ACENTER:ACENTER" attribute). It's a minor issue in practice, but please let me know if you find how to do that, or any other improvements (or other example code) that I and others might find useful.
wiak
- Attachments
-
- screenshot_tab1.jpg
- screenshot tab1 - makepup Basic Settings tab
- (28.67 KiB) Downloaded 372 times
-
- screenshot_tab2.jpg
- screenshot tab2 - makepup advanced options tab
- (48.66 KiB) Downloaded 376 times
Tecgraf released a new version (3.25) of IUP on 28 May 2018 so I'm busy compiling a GTK2 version of that now (all now successfully compiled - just need to package before trying it out). IupLua offers far more than just GUI dialog capability of course - can program more or less anything with it including OpenGL graphics (with its OpenGL Controls library), general drawing with IupCanvas, graph plotting with IupPlot, image processing and whatever including full power of Lua. If you want to get into a bit 'real' programming and away from rather weird bash manipulations, IupLua is a relatively easy way to do it without also having to master complex Graphics toolkits like Qt, WxWidgets, or GTK itself.
http://webserver2.tecgraf.puc-rio.br/iu ... tory3.html
https://sourceforge.net/p/iup/iup/4962/
My old compile notes helped alot, but these were far from perfect so I'm refining them a bit too since IUP needs a few tricks to compile it correctly (and I had to relearn some of these tricks despite my previous 'very' rough notes...).
Actually there has been quite a lot of very recent development activity on IUP (ongoing apparently) so I'm compiling the latest from SVN trunk, which contains a new container called IUPMultiBox which should help with complex layouts I imagine.
The previous downloads are fine just now though so I'll probably not upload new version until development work on the latest version has settled down a bit (last commit was just a dozen hours or so ago...).
Following my recent work on gtkwialog and more recently wiagit, I'm really keen to focus for a bit on IUPLua programming now since I see a lot of promise in it for future DebianDog/Puppy programming and more. (Pity it uses an SVN repo rather that Git since I need some more practice with wiagit and Git more generally...).
Main thing with IupLua will be to learn a bit Lua, but I'm also interested to see how well I could integrate IUP use with bash or shell programming generally. Can use IUP with straight C of course, and there are bindings for various other programming languages, not just Lua (though IupLua is the principal one continually developed). I'm not imagining a bash binding per se - just want to see how well I could use IupLua itself alongside shells scripting - might well be possible to pass dialogs onto child IupLua program via environment variable or some other mechanism. But it may be well be better to program more in Lua and less in shell...
I already know that it is easier to program nice dialogs with IUPLua than with GtkDialog, and one of its pre-defined controls (iupGetParam) is at least as easy as YAD with --fields etc (and iupGetParam is more powerful), as I demonstrated at following link:
http://murga-linux.com/puppy/viewtopic. ... 818#988818
wiak
http://webserver2.tecgraf.puc-rio.br/iu ... tory3.html
https://sourceforge.net/p/iup/iup/4962/
My old compile notes helped alot, but these were far from perfect so I'm refining them a bit too since IUP needs a few tricks to compile it correctly (and I had to relearn some of these tricks despite my previous 'very' rough notes...).
Actually there has been quite a lot of very recent development activity on IUP (ongoing apparently) so I'm compiling the latest from SVN trunk, which contains a new container called IUPMultiBox which should help with complex layouts I imagine.
The previous downloads are fine just now though so I'll probably not upload new version until development work on the latest version has settled down a bit (last commit was just a dozen hours or so ago...).
Following my recent work on gtkwialog and more recently wiagit, I'm really keen to focus for a bit on IUPLua programming now since I see a lot of promise in it for future DebianDog/Puppy programming and more. (Pity it uses an SVN repo rather that Git since I need some more practice with wiagit and Git more generally...).
Main thing with IupLua will be to learn a bit Lua, but I'm also interested to see how well I could integrate IUP use with bash or shell programming generally. Can use IUP with straight C of course, and there are bindings for various other programming languages, not just Lua (though IupLua is the principal one continually developed). I'm not imagining a bash binding per se - just want to see how well I could use IupLua itself alongside shells scripting - might well be possible to pass dialogs onto child IupLua program via environment variable or some other mechanism. But it may be well be better to program more in Lua and less in shell...
I already know that it is easier to program nice dialogs with IUPLua than with GtkDialog, and one of its pre-defined controls (iupGetParam) is at least as easy as YAD with --fields etc (and iupGetParam is more powerful), as I demonstrated at following link:
http://murga-linux.com/puppy/viewtopic. ... 818#988818
wiak