Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 23 May 2018, 18:54
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
IUP deb and pet packages for use with small Lua interpreter
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 2 [23 Posts]   Goto page: Previous 1, 2
Author Message
wiak

Joined: 11 Dec 2007
Posts: 647
Location: not Bulgaria

PostPosted: Fri 13 Apr 2018, 23:23    Post subject:  

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.php?id=plugins:iup_hints_and_tips

A good starting point tutorial, though some of the info may be out-of-date:

https://webserver2.tecgraf.puc-rio.br/iup/en/basic/index.html

https://webserver2.tecgraf.puc-rio.br/iup/en/guide.html

https://webserver2.tecgraf.puc-rio.br/iup/en/iuplua.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/iup/en/dialogs.html


Some pages from the IUP manual:

https://webserver2.tecgraf.puc-rio.br/iup/en/dlg/iupdialog.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/iup/en/tutorial/tutorial.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/iup/en/func/iuprefresh.html

and create popups:

https://webserver2.tecgraf.puc-rio.br/iup/en/func/iuppopup.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/iup/en/dlg/iuplayoutdialog.html

and a bit info on how it all hangs together:

https://webserver2.tecgraf.puc-rio.br/iup/en/layout_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-for-programmers-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/SoftwareDev/LuaShortRef51.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, 08:07; edited 2 times in total
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 647
Location: not Bulgaria

PostPosted: Sun 15 Apr 2018, 02:20    Post subject: 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:

Code:
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)


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...:

Code:
 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()


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:

Code:
path.lua = '/usr/bin/lua5.3'


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
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 647
Location: not Bulgaria

PostPosted: Mon 16 Apr 2018, 03:28    Post subject: gifenc-iup.lua translation of early version of gifenc-yad
Subject description: As a reasonably complete exemplar of programming in IUP/Lua
 

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:

Code:
./gifenc-iup.lua <path_to_video_to_convert_to_gif>


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.php?p=948724#948724
http://murga-linux.com/puppy/viewtopic.php?p=981267#981267

fredx181 wrote:
Also here (weX thread), see EDIT5 (and attached scripts):
http://murga-linux.com/puppy/viewtopic.php?p=948724#948724


IUP/Lua version:

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:
#!/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


fredx181's original early version:

Code:
#!/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


wiak
Screenshot_gifenc_iuplua.jpg
 Description   Screenshot of UIP/Lua version
 Filesize   28.05 KB
 Viewed   254 Time(s)

Screenshot_gifenc_iuplua.jpg


Last edited by wiak on Mon 16 Apr 2018, 19:12; edited 4 times in total
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2973
Location: holland

PostPosted: Mon 16 Apr 2018, 15:54    Post subject:  

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

_________________
Dog Linux website
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 647
Location: not Bulgaria

PostPosted: Mon 16 Apr 2018, 16:25    Post subject:  

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).


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.

Code:
assert(os.setlocale('C'))


Lua info on locales here:

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/manual/html_node/Lua.html
https://www.gnu.org/software/gettext/manual/gettext.html#lua_002dformat
https://gitlab.com/sukhichev/lua-gettext/blob/master/README.us.md
https://launchpad.net/~sukhichev/+archive/ubuntu/lua-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/41338417/create-a-lua-like-javascript-i18n-internationalization

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, 18:59; edited 14 times in total
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 2973
Location: holland

PostPosted: Mon 16 Apr 2018, 16:54    Post subject:  

wiak wrote:
Could you test it in dutch with that inserted.

assert(os.setlocale('C'))


I've put that on top and works well.

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 647
Location: not Bulgaria

PostPosted: Mon 16 Apr 2018, 20:35    Post subject: IUP/Lua translation of gifenc-sel  

Sorry, I couldn't resist... Wink 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.php?p=948724#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:
chmod +x gifenc-iup.lua


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/viewtopic.php?p=987611#987611

wiak

Code:
#!/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
Screenshot gifenc_sel_iuplua.jpg
 Description   Screenshot gifenc-sel IUP/Lua version
 Filesize   33.38 KB
 Viewed   152 Time(s)

Screenshot gifenc_sel_iuplua.jpg

Back to top
View user's profile Send private message 
wiak

Joined: 11 Dec 2007
Posts: 647
Location: not Bulgaria

PostPosted: Fri 20 Apr 2018, 04:07    Post subject:  

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/viewtopic.php?p=988818#988818

with more sophisticated version here:

http://www.murga-linux.com/puppy/viewtopic.php?p=988877#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/viewtopic.php?p=965541#965541 where you can find a screenshot of the result:

Code:
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>
"


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:

Code:
-- 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


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:

Code:
-- 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


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.php?PHPSESSID=troserr374u98p246bocpq2j01&topic=190.msg2435#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
screenshot_tab1.jpg
 Description   screenshot tab1 - makepup Basic Settings tab
 Filesize   28.67 KB
 Viewed   95 Time(s)

screenshot_tab1.jpg

screenshot_tab2.jpg
 Description   screenshot tab2 - makepup advanced options tab
 Filesize   48.66 KB
 Viewed   98 Time(s)

screenshot_tab2.jpg

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 2 [23 Posts]   Goto page: Previous 1, 2
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1313s ][ Queries: 13 (0.0108s) ][ GZIP on ]