GForm , zenity like gui maker for shell scripts using pipe to talk to script.

So you have written that new, must have program. Let us see it here.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Pre Note...
All uploads except the latest version of this app i uploaded to this thread i've deleted.
for one i was having a problem with my executable files being too large because of things i had in the source dir so they were wasting Gambas ones storage space.
Plus i think people may download the older versions by mistake.
Scroll down the thread to find the latest version :)


GForm (was thinking of calling it Genity)

zenity like form maker using a pipe for shell interaction

Work in progress. (Started it 2 days ago)


With this app you can simply (kind of) create GUI's in a shell script and
monitor/react to the actions in the script using a pipe.

The goal is to be able to make functional GUI apps simply just with scripting in bash.

It currently lacks lots of features but is still useable.

It creates a form/window and currently only adds objects to it vertically.
you can create a HBox and add objects to that horizontally.
currently supported objects are Button, ToggleButton, TextBox, ComboBox, Label, HBox (more to come)

Arguments are....

title="Title for window top"
box , makes a Horizontal box, subsequent objects go in the box until unboxed
unbox , finishes the box
button="name|text|close" , makes a button (close makes button close the window)
tbutton="name|text|on or off" , makes a ToggleButton, use 'on' to make it down
input="name|text" , makes a TextBox
checkbox="name|text|on or off" , makes a CheckBox , use 'on' for ticked
combobox="name|comma,seperated,list|index" , makes a read-only combobox, index is selected number
label="text" , makes a label.

pipe="path/to/pipe" , name of the pipe file (Usually /tmp/fifo1)

Provided is a demo bash script.

The GForm.gambas program is run from within the script with a few args to make a GUI.
The pipe=/tmp/fifo1 argument makes the app create a pipe that the script then opens and
waits for messages from the GUI.
The GForm.gambas command is finished with '&sleep 1' this is important as the & makes the app
run in the background while the script continues. the 'Sleep 1' part gives the app a second to
load and make the pipe before the script tries to read the messages.

Messages come in the form of name|text or name|text|value depending on the calling object

A Snapshot.png image is in the folder. the arguments for this were...
tbutton="B1|Hello|on" input="Inp3|some text" box tbutton="B2|Goodbye" button="B3|oooh" unbox button="b4|well then" box label="This box" input="I3|more txt" label="another label" input="I4|will 2 be ok" unbox box checkbox="cb1|Check box this|on" combobox="cmb1|l1,list 2,the third|2" unbox button="BQ|Quit|close" pipe=/tmp/fifo1
Snapshot.png
Like i said, lots to add to this.
Vertical layout features/objects are missing (like vbox and multi-line labels,textareas,lists,etc)
because i've not written the routines yet to work out the apps height.
currently it's working things out simply.
also plan to provide a way for the script to talk to the app.
also plan to make it useable like zenity where it doesn't create the pipe and just
gives all the data when closed.

Could have some potential this app, who knows?


Bruce

Edit ...
Above is the original old version , Find the Latest version here..
GitHub https://github.com/BruceSteers/GForm
Last edited by BruceSteers on Friday 25th September 2020 5:34pm, edited 3 times in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by cogier »

Hi Bruce,

I got this to work using your example. It does what it says on the tin! What purpose have you for it?
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Hi
Cool.
I've made some additions already like now it also has an incoming pipe.
So the gui can talk to the script about events and the script can send command to the gui too.

I've got a working example here that the script can change text fields and list indexes and stuff.

Like I say it's a way to get a half decent gui app just by using bash.

Will upload the updates later 😊
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Here's an update...

Arguments are....
(Runtime args when launching GForm)

title="Title for window top"
width=<n> , manually define a window width

box , makes a Horizontal box, subsequent objects go in the box until unboxed
unbox , finishes the box
button="name|text|close" , makes a button (close makes button close the window)
tbutton="name|text|on or off" , makes a ToggleButton, use 'on' to make it down
input="name|text" , makes a TextBox
checkbox="name|text|on or off" , makes a CheckBox , use 'on' for ticked
dirbox="name|path" , makes a dirbox derectory chooser
combobox="name|comma,seperated,list|index" , makes a read-only combobox, index is selected number
listbox="name|comma,seperated,list|index" , makes a list box, index is selected number
label="text" , makes a label.
spring , adds a spring, place to push objects, eg. "box spring button unbox" will push button to the right.

pipe="path/to/pipe" , name of the pipe file (Eg. /tmp/fifo1) GForms way of talking to your script
listen="path/to/pipe", name of listening pipe file (Eg. /tmp/fifo2) your scripts way to control GForm

(Arguments sent to GForm via listening pipe)
settext=object_name=text , sets text field of named object
setindex=object_name=number , selects the numbered item in either a listbox or combobox
setlist=object_name=comma,seperated,list , changes the whole item list in either listbox or combobox
setlistitem=object_name=text=number , changes a single numbered item text in either listbox or combobox

setswitch=object_name=on or off or blank for toggle
quit or close , closes the GUI

Included is a medium advanced bash script that manages the gui.
selecting list items changes a text box and selects the combobox item.
changing combobox index does the same.
Changing the text box field changes the items in list and combo.
clicking the button toggles the checkbox

What's important to know is all these routines/functions happening in the GUI when clicking stuff are not being controlled by the gambas app at all they are being controlled entirely by the bash script.
all the gambas app does is create a gui, send messages and receive commands

i could now potentially re-write my pkAppMan app to be a bash script but using GForm to make the GUI.
(I actually have a bash version that uses zenity but zenity has to close and be relaunched to show any changes making things a bit slow and clunky. it'd be much smoother using GForm.
Last edited by BruceSteers on Friday 25th September 2020 5:35pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Source code is getting more complex now. :roll:
Added lots of new features.
Gave it a home on git. https://github.com/BruceSteers/GForm

Here's the current arg list , my how it's grown.....

currently supported objects are...
Button, ToggleButton, TextBox (InputBox), CheckBox, ListBox,
DirBox, FontBox, ComboBox, Label, HBox, Spring

Arguments are....
(Runtime args when launching GForm)

title="Title for window top"
width=<n> , manually define a window width
font=font name , Sets the main form font Eg 'Carlito,14,Italic'
noresize , makes form non resizable
topmost or toponly , forces window to stay above others.

box , makes a Horizontal box, subsequent objects go in the box horizontally until unboxed
unbox , finishes the box

button="name|text|flags" , makes a button (close makes button close the window)
tbutton="name|text|flags" , makes a ToggleButton, use 'on' to make it down
input="name|text|flags" , makes a TextBox
checkbox="name|text|flags" , makes a CheckBox , use 'on' for ticked
fontbox="name|FontName|flags"
dirbox="name|path|flags" , makes a dirbox derectory chooser
combobox="name|comma,seperated,list|index|flags" , makes a read-only combobox, index is selected number
listbox="name|comma,seperated,list|index|flags" , makes a list box, index is selected number
label="text" , makes a label.

For all above objects, 'flags' can be..
'on' for toggle button or checkbox state on load,
'disabled' disables object,
'hidden' hides the object, 'stretch' or 'nostretch' forces object resizing
'close' or 'quit' makes button close GUI after pressed

spring , adds a spring, place to push objects, eg. "box spring button unbox" will push button to the right.

pipe="path/to/pipe" , name of the pipe file (Eg. /tmp/fifo1) GForms way of talking to your script
listen="path/to/pipe", name of listening pipe file (Eg. /tmp/fifo2) your scripts way to control GForm

quiet , suppresses any stdout messages (not pipe messages)

(Arguments sent to GForm via listening pipe)
settext=object_name=text , sets text field of named object
setindex=object_name=number , selects the numbered item in either a listbox or combobox
setlist=object_name=comma,seperated,list , changes the whole item list in either listbox or combobox
setlistitem=object_name=text=number , changes a single numbered item text in either listbox or combobox
hide=object_name , hides named object, use 'hide' alone to hide main wiindow
show=object name, opposite of hide
disable=object_name , disables named object, use 'disable' alone to disable main wiindow
enable=object_name , opposite of disable
setfont=object_name|font , sets font for an object
getfont=object_name , gets font name for an object
setfocus=object_name , make object active
setvalue=object_name=on or off or blank for toggle (checkbox or togglebutton)
getinfo=object_name , get info on an object (text,index,value,etc)
move=x,y,w,h , moves or resizes window, numbers can be absolute or relative +- or absent
Eg. 'move=20,20,,' moves window to position 'move=,,+20,' grows width by 20

mainfont=font name , changes GUI main font

dialoge=type|default|flags , opens a requester dialog
type can be openfile, opendir, savefile, color, font (title sets the title)
flags can be showhidden or multi
Eg.
dialog=title|Select folder to open...
dialog=opendir|/home/|showhidden

message="Message text" , pops open a message window
stop or start , pauses the gui sending your script messages while you alter objects.

quit or close , closes the GUI
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Further Updated now...
Lots of tweaking , more options added.

Big change in the pipe reading routine.
I found using the timer method to echo the pipe was occasionally missing messages somehow so was looking into it.
then finally i figured out the pipes 'Watch' option and using the File_Read() event and did away with the timer.
It's much much more stable and does not miss messages now.

added even more features.
it now has an option to use it like zenity and pop open a question box (a label and buttons) and return the button press result to the CLI, only with GForm you can have multiple rows of buttons if you like. it can return the buttons text or it's name or both , have made an example to show this.

And you know how i said i could well make a version of pkAppMan using GForm? well i did.
Included as the advanced example is a fully working pkAppMan that's a shell script using GForm. (must be run via terminal to save any changes as will ask for root pw)
pkAppMan.png
https://github.com/BruceSteers/GForm/raw/master/GForm GForm application
https://github.com/BruceSteers/GForm


Still to do...
Add a "data collector" mode type of option. like zenity --forms
with this mode you could add any object to the GUI like text boxes comboboxes etc,but it wont send any messages until the GUI is closed then it will return all fields to stdout for you to process.

May change the monitored textbox event to TextBox_Change() it currently reacts to TextBox_Activate() or TextBox_LostFocus().
Textbox_change will create more events but i've discovered if for example you change the text then click a listbox item before pressing return the GUI sends the listbox click message before the textbox event. i've added an echo event called 'check' to get around this. sending the text 'check' to the gui makes it echo 'check' back to you so if you send 'check' then read the pipe text straight back and it's not 'check' it's another command in the process. (also sending 'marco' to the gui will make it reply 'polo ;) lol why not eh?')
Last edited by BruceSteers on Friday 25th September 2020 5:26pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

I need to get a life and stop working on this lol :)

major bugfix.
I found a bug in the listening pipe routine where multiple lines of text were not being processed correctly.
Trying to get my head around how to access the Eof(hFile) call or the hFile.EndOffile without locking up the app was
driving me crazy ,,, then i discovered the hFile.Blocking mode. Setting this to false suddenly let me check the EndOfFile property without lock ups , i was so happy , you should have been there ;) lol :D

This was causing issues when sending multiple commands at once using \n , i was using multiple calls instead to the GUI to operate things and wondering why some stuff wasn't working without a few sleep 0.1 calls and stuff to stop messages getting lost.

That combined with realising my messages going to the GUI from the script were only using one > sign to redirect thus not appending the pipe file but overwriting it, all good if there are no messages in the queue but not otherwise.
addressing both these issues has sped things right up and negated the need for any sleep calls and now it seems seamlessly responsive.
also in the example script i've made it not use the sleep command after launching the app to wait for it to load (could be hit and miss) but made it wait for the pipe file to appear, so it won't wait too long and won't wait too little :)

And now it has a GridView with many functions :) (I do like the GridView)
pkAppMan (GridView).png
It's possibly got more features than i've listed but you gambasers can just check out the code to find the arg and command processing routines :)

I've added some help files.
https://github.com/BruceSteers/GForm
Programs now so big i can't upload the complete package with source lol
Wait.... omg i had the default icons component added making it huge !!
Now it's tiny again . went from 26mb to about 370k , wow

Noo, looking again , the file size shot up to 1.2mb and was climbing with each compile???
i saved the code , closed gambas IDE and deleted the exe.
then opened the IDE again compiled and now it's 380k.
what's that all about?
Last edited by BruceSteers on Friday 25th September 2020 5:35pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

I could be showing my age here but i used to do AREXX scripting on an Amiga1200 , waaay back in the day lol.

one day i discovered a tool called the AWNPipe.handler
This was a simple tool made by Bill Parker one of the co-writers of AWeb a popular browser that he made to be able to easily knock together some simple GUI's for using AwebNews (hence AWNPipe) it worked a lot like GForm does and is where i got the idea.
It was so easy to make functional GUI apps just with cli scripting i made quite a few.
I also wrote an online tutorial about AREXX and AWNPipe. Bill was impressed at what i'd been able to to with what he thought was just a simple tool and didn't expect anyone to get some serious functionality out of it.. that impressed that he included some of my apps in the AWeb distribution. :)

I was well chuffed. my progs were on the official AmigaOS3.9 CD :)
That's like being on a windows disk.
Sadly though Windows took over the world and Amigas became a thing of the past.
I gave up when WinUAE (the windows amiga emulator) introduced JIT , at some point my pc amiga emulator was like 10x faster than the actual amiga :(

Well that's the story behind GForm :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Stock Icons anyone?
So i found my large file size issue was not because of the stock icons component added. Then removed.

So I've added it again :)
Now if you type GForm geticons you get this...
GForm-geticons.png
That shows all the available stock icons and their names.
then knowing the name you can add 'icon=name' to the flags of buttons n stuff.
This is now how the pkAppMan script looks...
pkAppMan (GridView).png
Have also added textarea to the list of controls. gave it commands to add text, add lines or add a file directly.
Have also added background and foreground colour option using R.G.B 0-255 format
Eg, 0,255,0 for green.

I've made a script to list all the help docs in the help folder and load them into the textarea.
Help_Script.png
https://github.com/BruceSteers/GForm
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: GForm , zenity like gui maker for shell scripts using pipe to talk to script.

Post by BruceSteers »

Hi all.
Have made various changes/additions to this.
Most notably the com= or shell= flag you can add to buttons.
setting this flag will make the button run the supplied command without your script having to.

Included in the examples dir is a Button_Command_Requester.sh scrip that shows how to use it to add xdg-open as the command and open dir's URLs with the GUI without any additional scripting.

By running this command from a script...

Code: Select all

WB="icon=link foreground=50,50,255"  # set blue text colour variable for the web links.

../GForm allstretch spacing font="Carlito,14,Italic" bg=150,200,200 topmost quiet width=350 title="GForm command button requester example" \
label="|\nThis is an example of a command button requester.\nPressing any button will run a command so your script\ndoesn't have to.\n(mostly just using xdg-open on a location/URL)\n|center lines=5 background=200,200,200" \
box button="|Run Gambas IDE|com=gambas3|icon=gambas" button="|Open home Dir|com=xdg-open \"$HOME\"|icon=open" unbox \
label="|Web pages..|left nostretch" \
box button="|Gambas wiki|com=xdg-open \"http://gambaswiki.org/wiki\"|$WB" button="|Gambas homepage|com=xdg-open http://gambas.sourceforge.net/|$WB" unbox \
box button="|GForm website|com=xdg-open http://gform.bws.org.uk|$WB" button="|GForm on github|com=xdg-open https://github.com/BruceSteers/GForm|$WB" unbox \
box button="|Gambas one|com=xdg-open http://wordpress.gambas.one/|$WB" button="|GambasOne forums|com=xdg-open https://forum.gambas.one/|$WB" unbox \
box spring button="|Close window|close nostretch icon=quit" 2>/dev/null
I get this window and all the buttons run the commands as per the arguments with nothing else in the script.
Button_commands.png
Other additions include..
Main form background foreground colour setting.
FontBox now has a linkto=obj_name flag that will make it auto change that objects text without any coding
Menus, Now menus can be added :) (and popups can be attached to objects)
ToolTips can now be set.
the return=end or return=collect mode is now available. (works like zenity --forms) no data is sent during use but when closed all the settable fields names and values are printed to the shell.

Read the help texts for a better explanation on how to use all the many many features :)
GForm_dist.zip
GForm_src.zip

I screengrabbed a video of me playing with GForms version of pkAppMan.
I love the responsiveness it shows, considering each time the list selection changes the GUI sends the script a message via the pipe file of the change and the script then send messages to the GUI to fill in the textbox fields, etc. rapido :)


Info from the Version history file....
V1.5.5
Pah, well QT gave less layout warning messages but i found it caused the FontBox to lock up the GUI.
A far worse problem than the gtk one so am now using gb.gui again.
background and foreground colour settings added to main args list.
Added 'collect' mode or return=end. This mode does not give out any messages during use but once
the window is closed returns all the settable fields and their values to the shell at once. Works like
the other return=mode options in that ANY normal button will auto-close the window. to override this action
use the noclose or noquit flag.
Updated help docs to include new flags/commands.

V1.5.4
adding new flag parameters caused a glitch in using "Labels" , Fixed.
Using GTk was not working well, what with all manner of gadget layout warning messages
(All internal GTK errors though not my coding) that and dialogs not showing properly
I've now changed it to use QT instead.
QT still puts out unwanted messages but not so much. recommend using 2>/dev/null at
the end of any GForm launch to suppress stderr messages.
Eg. GForm showicons 2>/dev/null

V1.5.3
Added additional flag parameters shell= (or com=) and tooltip= (or tip=)
tooltip goes without saying.
shell= will execute the supplied command on button click so your script doesn't have to.
(See Flags section of '2 Runtime args.txt' for more info)

V1.5.2
Opps, bugfix , i'd commented out the bit where a button send a message for testing and forgot to
uncomment it again so buttons were not reacting. fixed.

V1.5.1
Some minor edits/additions to help texts.
Now compiled on the latest stable gambas 3.15 , backward compatibility is enabled for it to work on
any gambas version above 3.8 though.

V1.5.0
Added menus , now you can use menu=Name|Parent|Text|Flags to add a menu item, complete menus
can be built using parenting. Also popup menus can be assigned to objects in the objects flags.
The way the pipe was being opened/read was causing a bug in the popup menus so I've corrected for this now.
Wrote instructions/help file on how to make menus and added an example script.

Added fontbox linkto=name flag, use linkto=name to make a fontbox automatically be attached
to any named object, if user changes the font the object font will auto change without any coding.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply