| Author |
Message |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Mon 15 Oct 2012, 23:53 Post_subject:
How to improve fluxbox shutdown? solved Sub_title: would like to improve |
|
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?
| Quote: | #!/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 |
 |
| Description |
|
| Filesize |
10.79 KB |
| Viewed |
365 Time(s) |

|
Edited_time_total
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 573
|
Posted: Tue 16 Oct 2012, 11:05 Post_subject:
|
|
Hey Oldyeller
| Quote: | | [...]yes to continue or cancel[...] |
If you don't mind to use "No" instead of "Cancel" , Xdialog would the simpliest way I can think about at the moment.
Add these two lines in the beginning of the "fluxexit" function:
| Code: | 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: | 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!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2730 Location: Kiel,Germany
|
Posted: Tue 16 Oct 2012, 13:26 Post_subject:
|
|
This is common practice but i think it should be
| Code: | | 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 
|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Tue 16 Oct 2012, 16:03 Post_subject:
|
|
| SFR wrote: | Hey Oldyeller
| Quote: | | [...]yes to continue or cancel[...] |
If you don't mind to use "No" instead of "Cancel" , Xdialog would the simpliest way I can think about at the moment.
Add these two lines in the beginning of the "fluxexit" function:
| Code: | 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: | 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 | Quote: | $1?" 5 40
[ "$?" -ne 0 ] && exec "$MYNAME"[/code] |
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 573
|
Posted: Tue 16 Oct 2012, 16:29 Post_subject:
|
|
| 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 | Quote: | $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: | 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!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Tue 16 Oct 2012, 16:40 Post_subject:
|
|
Thanks,
this helps to learn when things get explained.
Now I off for to study bash
thanks again
Cheers.
|
|
Back to top
|
|
 |
dejan555

Joined: 30 Nov 2008 Posts: 2407 Location: Montenegro
|
Posted: Tue 16 Oct 2012, 17:24 Post_subject:
|
|
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.
| Description |
|

Download |
| Filename |
fluxbox-shutdown.tar.gz |
| Filesize |
21.11 KB |
| Downloaded |
170 Time(s) |
_________________

|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Tue 16 Oct 2012, 21:33 Post_subject:
|
|
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
|
|
Back to top
|
|
 |
|