How to improve fluxbox shutdown? solved

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

How to improve fluxbox shutdown? solved

#1 Post by oldyeller »

Hello everyone,

I would like to improve on my fluxbox shutdown gui.

I would like to have the option for each of my chooses to have a yes to continue or cancel if they forgot something and start all over.

How would I be able to do this?
#!/bin/sh
#MODES are poweroff reboot exit
## FUNCTIONS
set -a #export all functions
fluxexit () {
echo -n "$1" > /tmp/wmexitmode.txt
KCNT=0
PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`"
while [ "$PSPEFD" != "" ];do
sleep 0.5
KCNT=`expr $KCNT + 1`
[ $KCNT -gt 60 ] && break #30 secs.
PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`"
done
sleep 0.2
sync
#CURRENTWM="`cat /etc/windowmanager`"
#if [ "$CURRENTWM" = "startxfce4" ];then
#CURRENTWM="xfce4-session"
#fi
#kill -9 `pidof $CURRENTWM`
kill -9 `pidof fluxbox`
}

export MAIN_DIALOG='
<window title="Shutdown" icon-name="shutdown24" resizable="false" decorated="true" height-request="0" width-request="250">
<vbox>

<hseparator></hseparator>
<text wrap="false" xalign="0.5" selectable="false">

<label>Options</label>

</text>
<hseparator></hseparator>

<hbox>
<frame>
<vbox>
<button height-request="0" width-request="125">
<label>Power-Off</label>
<input file stock="gtk-disconnect"></input>
<action>fluxexit poweroff &</action>
<action type="exit">exiting completed</action>
</button>

<button height-request="0" width-request="125">
<label>Reboot</label>
<input file stock="gtk-connect"></input>
<action>fluxexit reboot &</action>
<action type="exit">exiting completed</action>
</button>
</vbox>
</frame>
<frame>
<vbox>
<button height-request="0" width-request="125">
<label>Restart X</label>
<input file stock="gtk-refresh"></input>
<action>fluxexit restartwm &</action>
<action type="exit">exiting completed</action>
</button>

<button height-request="0" width-request="125">
<label>Log-Out</label>
<input file stock="gtk-ok"></input>
<action>fluxexit exit &</action>
<action type="exit">exiting completed</action>
</button>

</vbox>
</frame>
</hbox>

<vbox>
<hseparator></hseparator>
<button cancel></button>
<hseparator></hseparator>
</vbox>
</vbox>
</window>
'

gtkdialog --center --program=MAIN_DIALOG
Attachments
shutdown.png
(10.79 KiB) Downloaded 740 times
Last edited by oldyeller on Tue 16 Oct 2012, 20:41, edited 1 time in total.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

Hey Oldyeller
[...]yes to continue or cancel[...]
If you don't mind to use "No" instead of "Cancel" :wink: , Xdialog would the simpliest way I can think about at the moment.
Add these two lines in the beginning of the "fluxexit" function:

Code: Select all

fluxexit () {
Xdialog --title "Confirmation" --yesno "Are you sure you want to $1?" 5 40
[ "$?" -ne 0 ] && exit
$? return codes are 0=yes, 1=no, 255=window_closed

But, if you'd like to return to the main window when user presses "No", try this:

Code: Select all

set -a #export all functions
MYNAME="$0"

fluxexit () {
Xdialog --title "Confirmation" --yesno "Are you sure you want to $1?" 5 40
[ "$?" -ne 0 ] && exec "$MYNAME"
exec "$MYNAME" will simply restart the script.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

MYNAME="$0"
This is common practice but i think it should be

Code: Select all

MYNAME=`readlink -e "$0"`
in case you have the script in a folder something like /usr/local/shutdown and link to it from somewhere in the PATH .
This is for the case you have several scripts in that directory and forget to cd into it .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#4 Post by oldyeller »

SFR wrote:Hey Oldyeller
[...]yes to continue or cancel[...]
If you don't mind to use "No" instead of "Cancel" :wink: , Xdialog would the simpliest way I can think about at the moment.
Add these two lines in the beginning of the "fluxexit" function:

Code: Select all

fluxexit () {
Xdialog --title "Confirmation" --yesno "Are you sure you want to $1?" 5 40
[ "$?" -ne 0 ] && exit
$? return codes are 0=yes, 1=no, 255=window_closed

But, if you'd like to return to the main window when user presses "No", try this:

Code: Select all

set -a #export all functions
MYNAME="$0"

fluxexit () {
Xdialog --title "Confirmation" --yesno "Are you sure you want to $1?" 5 40
[ "$?" -ne 0 ] && exec "$MYNAME"
exec "$MYNAME" will simply restart the script.

Greetings!
Edit=I have done both they work just fine. will see which when I like the best and use it. Thanks again

Thanks this does the job, but could you give me an explanation of the script so I can better understand what it does.

Like
$1?" 5 40
[ "$?" -ne 0 ] && exec "$MYNAME"[/code]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#5 Post by SFR »

oldyeller wrote:Thanks this does the job, but could you give me an explanation of the script so I can better understand what it does.

Like
$1?" 5 40
[ "$?" -ne 0 ] && exec "$MYNAME"[/code]
Sure!

$1 is the parameter passed from, eg. <action>fluxexit restartwm &</action> to fluxexit function (in this case $1=restartwm).

5 40 are dimensions of the window (height and width respectively).
More info: Xdialog --help

[ "$?" -ne 0 ] && exec "$MYNAME"
Simply: if the return code from Xdialog window is not equal 0 then restart the script, else - continue.

MYNAME="$0" - $0 is the variable that holds the filename of the script.

Additonaly you can also "humanize" the confirmation questions by adding something like this:

Code: Select all

set -a #export all functions
MYNAME=`readlink -e "$0"`

fluxexit () {
case "$1" in
  "poweroff" ) MESSAGE="turn off computer" ;;	
  "reboot" ) MESSAGE="reboot computer" ;;
  "restartwm" ) MESSAGE="restart window manager" ;;
  "exit" ) MESSAGE="exit to prompt";;
esac	

Xdialog --title "Confirmation" --yesno "Are you sure you want to $MESSAGE?" 5 50
[ "$?" -ne 0 ] && exec "$MYNAME"
BTW, Karl's suggestion makes that MYNAME variable will contain the full path to the actual script, not a path to a symlink (in case it's launched through a symlink, of course).

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#6 Post by oldyeller »

Thanks,

this helps to learn when things get explained.

Now I off for to study bash


thanks again

Cheers.

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#7 Post by dejan555 »

Hey oldyeller, here I attach shutdown script/dialog from my fluxbox package for lupu with icons included if you want to inspect

My full fluxbox lupu package is here: fluxbox-1.1.1-i486-lupu.pet

Beside the compiled files included in it are menu generation binary and scripts/files, shutdown dialog and other menu tweaks.
Attachments
fluxbox-shutdown.tar.gz
(21.11 KiB) Downloaded 624 times
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#8 Post by oldyeller »

Hi dejan555,

Thanks, this is were I got some of the things I needed to start with. will look again at your work and take what I might still need.

Cheers

Post Reply