Difference between revisions of "Zenity"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
m
m
 
(9 intermediate revisions by one user not shown)
Line 2: Line 2:
  
 
{{lowercase}}
 
{{lowercase}}
 +
 +
=== sample scripts ===
 +
 +
Basic example
 +
#!/bin/bash
 +
first=$(zenity --title="First Name" --text "What is your first name?" --entry)
 +
zenity --info --title="Welcome" --text="Mr./Ms. $first"
 +
last=$(zenity --title="Last Name" --text "$first what is your last name?" --entry)
 +
zenity --info --title="Nice Meeting You" --text="Mr./Ms. $first $last"
 +
 +
Size and Font control
 +
zenity --info --text="This is an information box." --width=600 --height=400
 +
<nowiki>zenity --info --text '<span foreground="blue" font="32">Some\nbig text</span>\n\n<i>(it is also blue)</i>'</nowiki>
 +
<nowiki>zenity --info --text 'Normal <big>Big <big>Bigger</big></big>'</nowiki>
 +
 +
Functional dialog for media player
 +
#!/bin/bash
 +
<nowiki>#zenity --list --title "Video Type?" --column="FPS" NTSC PAL</nowiki>
 +
<nowiki></nowiki>
 +
<nowiki>strPlayer="$1"</nowiki>
 +
<nowiki>strPlayer=${strPlayer/"myth://user@192.168.254.88:6000"/"/mnt/mythtv/videos"}</nowiki>
 +
<nowiki>echo $strPlayer >> /tmp/altplayer.log</nowiki>
 +
<nowiki></nowiki>
 +
<nowiki></nowiki>
 +
<nowiki>varName1=$(zenity --list --title "$strPlayer" --column="FPS" NTSC PAL);</nowiki>
 +
<nowiki>varName2=$(echo $varName1 | sed 's/[^a-zA-Z0-9]//g')</nowiki>
 +
<nowiki></nowiki>
 +
<nowiki>#zenity --error</nowiki>
 +
<nowiki></nowiki>
 +
<nowiki>#zenity --info --text="You selected $varName2";</nowiki>
 +
<nowiki></nowiki>
 +
<nowiki>case "${varName2}" in</nowiki>
 +
<nowiki>        NTSC )</nowiki>
 +
<nowiki>                zenity --info --text="Play standard NTSC video"</nowiki>
 +
<nowiki>                vlc -f "$strPlayer" --no-embedded-video --no-sub-autodetect-file vlc://quit</nowiki>
 +
<nowiki>                ;;</nowiki>
 +
<nowiki>        PAL )</nowiki>
 +
<nowiki>                zenity --info --text="Play at 96 percent for PAL"</nowiki>
 +
<nowiki>                vlc -f "$strPlayer" --no-audio-time-stretch --rate=0.96 --no-embedded-video --no-sub-autodetect-file vlc://quit</nowiki>
 +
<nowiki>                ;;</nowiki>
 +
<nowiki>        * )</nowiki>
 +
<nowiki>                zenity --error</nowiki>
 +
<nowiki>                ;;</nowiki>
 +
<nowiki>esac</nowiki>
 +
<nowiki></nowiki>
 +
<nowiki>exit 0</nowiki>
 +
 +
prompt user from remote shell on remote desktop
 +
<nowiki>zenity --info --text "stop playing video games and do your homework" --display=:0</nowiki>
 +
''Note:  You must be ssh into the remote system as the same user that is using the xdisplay locally.''
 +
 +
Suppress annoying GTK errors
 +
zenity --info --text "Hello World" 2>/dev/null
 +
<small>note: <nowiki>Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.</nowiki> ''is the result of a suggested requirement in the GTK Toolkit that the programmer using GTK should specify a parent window for the one being used in the dialog.  This apparently has been suggested as a future requirement and is for the purpose of aiding the window manager in keeping track of window state, however, is completely unnecessary and the error can be safely ignored.''</small>
 +
 +
 +
 
[[Category:Computer_Technology]]
 
[[Category:Computer_Technology]]
 
[[Category:Linux]]
 
[[Category:Linux]]

Latest revision as of 20:50, 21 February 2021

zenity (lower-case z) / formerly gdialog - have graphical GTK+ dialog boxes in command-line and shell scripts. Zenity adds graphical interfaces to shell scripts with a single command. Zenity is an open source and a cross-platform application

sample scripts

Basic example

#!/bin/bash 
first=$(zenity --title="First Name" --text "What is your first name?" --entry) 
zenity --info --title="Welcome" --text="Mr./Ms. $first" 
last=$(zenity --title="Last Name" --text "$first what is your last name?" --entry) 
zenity --info --title="Nice Meeting You" --text="Mr./Ms. $first $last"

Size and Font control

zenity --info --text="This is an information box." --width=600 --height=400
zenity --info --text '<span foreground="blue" font="32">Some\nbig text</span>\n\n<i>(it is also blue)</i>'
zenity --info --text 'Normal <big>Big <big>Bigger</big></big>'

Functional dialog for media player

#!/bin/bash 
#zenity --list --title "Video Type?" --column="FPS" NTSC PAL

strPlayer="$1"
strPlayer=${strPlayer/"myth://user@192.168.254.88:6000"/"/mnt/mythtv/videos"}
echo $strPlayer >> /tmp/altplayer.log


varName1=$(zenity --list --title "$strPlayer" --column="FPS" NTSC PAL);
varName2=$(echo $varName1 | sed 's/[^a-zA-Z0-9]//g')

#zenity --error

#zenity --info --text="You selected $varName2";

case "${varName2}" in
        NTSC )
                zenity --info --text="Play standard NTSC video"
                vlc -f "$strPlayer" --no-embedded-video --no-sub-autodetect-file vlc://quit
                ;;
        PAL )
                zenity --info --text="Play at 96 percent for PAL"
                vlc -f "$strPlayer" --no-audio-time-stretch --rate=0.96 --no-embedded-video --no-sub-autodetect-file vlc://quit
                ;;
        * )
                zenity --error
                ;;
esac

exit 0

prompt user from remote shell on remote desktop

zenity --info --text "stop playing video games and do your homework" --display=:0

Note: You must be ssh into the remote system as the same user that is using the xdisplay locally.

Suppress annoying GTK errors

zenity --info --text "Hello World" 2>/dev/null

note: Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged. is the result of a suggested requirement in the GTK Toolkit that the programmer using GTK should specify a parent window for the one being used in the dialog. This apparently has been suggested as a future requirement and is for the purpose of aiding the window manager in keeping track of window state, however, is completely unnecessary and the error can be safely ignored.