SliTaz SliTaz Forum

You are not logged in.

#1 2011-12-13 05:54:04

Guest
Guest

Howto Write Simple User Input GUI

Want to create a GUI to query user for username and password and mount using sshfs. Here is the BASH script which does this:

===

echo "input username:"

read username

sshfs $username@<ip address>:/home/$username /home/tux/Documents

===

Can someone point me in the right direction.

#2 2011-12-13 15:15:27

llev
Member
Registered: 2011-12-09
Posts: 568

Re: Howto Write Simple User Input GUI

Use zenity?

Offline

#3 2011-12-13 15:58:52

babaorum
Moderator
Registered: 2011-03-29
Posts: 109

Re: Howto Write Simple User Input GUI

zenity, yad, xdialog, dialog (not real GUI, pretty much console-emulated pseudo-GUI), gtkdialog, Tcl/Tk... much of them are packaged for SliTaz.

Offline

#4 2011-12-13 18:41:15

compostela
Member
Registered: 2011-06-27
Posts: 44

Re: Howto Write Simple User Input GUI

Stay with shell programming. Use xdialog. It's very simple and powerful. If you go with zenity the learning curve is much longer. With zenity you need to know the basic language. Not so with xdialog or similar ones that goes very handy with the shell. If you know some shell programming, expant on it.

Try it. You will see what I mean immediately.

Offline

#5 2011-12-14 10:47:46

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Howto Write Simple User Input GUI

I would recommend yad over xdialog or gtkdialog.

Offline

#6 2011-12-14 16:06:00

babaorum
Moderator
Registered: 2011-03-29
Posts: 109

Re: Howto Write Simple User Input GUI

Huu ? zenity and yad are even simplier than Xdialog. dialog is then console ancestor of Xdialog.

There is NO language for zenity and yad, same as Xdialog, you may have been confused by these ones.

gtkdialog is the only one to be more complicated.

[c]local username=$(zenity --entry --text="Username"); echo "username = $username"[/c]

[c]local username=$(yad --entry --text="Username"); echo "username = $username"[/c]

Can it be more simple ? (probably lol, but it is already *very* simple ;-} )

Regards,

--Babaorum

Offline

#7 2011-12-14 18:10:01

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Howto Write Simple User Input GUI

I like how easy yad is and how many of the options are assumed like pressing the return key equals the OK or yes button and closing the window equals the cancel or no button. It's small thing like that, that's useful. Most of the new boxes used in cooking use yad as it's base now.

Offline

#8 2011-12-14 22:08:34

Guest
Guest

Re: Howto Write Simple User Input GUI

Good suggestions all and I looked at yad and zenity. Somebody's also posted some code on usernames and password inputs. Slitaz, however, is throwing an error not recognizing 2inputsbox.

Now I am not a programmer, so please bear with me here:

a.  Able to get a username and password done in Xdialog - written to variables

b.  Can pass the username to the next command, sshfs $USERNAME@blah blah blah

c.  How is the password given at the "Password:" prompt?

#9 2011-12-15 01:30:47

Guest
Guest

Re: Howto Write Simple User Input GUI

Trixar, I like yad also. I have it running and can do the script described above. I just cannot find any documentation on how to use it to pass passwords for login.

#10 2011-12-15 01:31:59

Guest
Guest

Re: Howto Write Simple User Input GUI

I see this post at http://library.gnome.org/users/zenity/stable/zenity-text-entry-options.html.en

   #!/bin/sh

        if zenity --entry \

        --title="Add an Entry" \

        --text="Enter your _password:" \

        --entry-text "password" \

        --hide-text

          then echo $?

          else echo "No password entered"

        fi

So, we can capture the password, but how to pass it on?

#11 2011-12-15 01:38:13

babaorum
Moderator
Registered: 2011-03-29
Posts: 109

Re: Howto Write Simple User Input GUI

Did you read my answer Sidhu ? I've given an example just for you, answers are put into variables.

You may read the output of built-in help: [c]yad --help[/c], all is very clear there.

Do it sequentially, it is best because you just have to wait the GUI to display, type the answer and press ENTER. No need at all to press TAB to go to the next answer field.

[c]local username=$(yad --entry --text="Username")
local pword=$(yad --entry --text="Password" --hide-text)
sshfs $username $pword [etc.]  #or whatever the sshfs command wants you to enter[/c]
Type this in a shell script, inserting "#!/bin/sh" at the very first line, alone, get it executable and you are done.

Offline

#12 2011-12-15 01:48:09

Trixar_za
Administrator
Registered: 2011-03-29
Posts: 1,506

Re: Howto Write Simple User Input GUI

The example you gave tests if you entered a password and then echos it back to you. It does this by using echo $? - $? being the captured password. You could probably use $@ too.

Not that it matters. Both should work. The trick is to use --hide-text to hide text entry. Learning a bit of bash scripting and syntax help too wink

Offline

#13 2011-12-15 03:28:02

Guest
Guest

Re: Howto Write Simple User Input GUI

Thanks Babaorum!

This is what I have and it works!

#!/bin/sh

local username=$(yad --entry --text="Username")

local pword=$(yad --entry --text="Password" --hide-text)

echo "$pword"|sshfs -o password_stdin $username@192.168.100.20:/home/$username /home/tux/Documents

a.  I realized the use of "-o password_stdin"

b.  Although the above script works, I want to do both username and password input in one screen, not two

So, stay tuned...

#14 2011-12-15 05:01:09

Guest
Guest

Re: Howto Write Simple User Input GUI

So, this is one screen with username and password inputs. And password input is hidden. Obviously you can further generalize the script by making the IP address a variable and asking for it in a third user input.

#!/bin/sh

frmdata=$(yad --title "Mount file server" --form --field="username" --field="Password:H")

frmusername=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $1 }')

frmpassword=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $2 }')

echo "$frmpassword"|sshfs -o password_stdin $frmusername@192.168.100.20:/home/$frmusername /home/tux/Documents

#15 2011-12-15 05:27:29

Guest
Guest

Re: Howto Write Simple User Input GUI

Here is what it looks like

[attachment=4730,253]

#16 2011-12-15 09:36:55

babaorum
Moderator
Registered: 2011-03-29
Posts: 109

Re: Howto Write Simple User Input GUI

Here you are ! \o/

Just know that yad has enhanced features (like "form") compared to zenity (it is one of its forks), but that it is not completely implemented on SliTaz stable (3.0), rather than cooking where everything is working flawlessly.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.035 seconds, 7 queries executed - Memory usage: 1.56 MiB (Peak: 1.77 MiB) ]