Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 25 Jul 2014, 11:26
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to improve fluxbox shutdown? solved
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
oldyeller


Joined: 15 Nov 2011
Posts: 772
Location: Mishawaka IN

PostPosted: Mon 15 Oct 2012, 23:53    Post subject:  How to improve fluxbox shutdown? solved
Subject description: 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
shutdown.png
 Description   
 Filesize   10.79 KB
 Viewed   554 Time(s)

shutdown.png


Last edited by oldyeller on Tue 16 Oct 2012, 16:41; edited 1 time in total
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1039

PostPosted: 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" 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:
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
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3953
Location: Kiel,Germany

PostPosted: Tue 16 Oct 2012, 13:26    Post subject:  

Quote:
MYNAME="$0"

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 Razz
Back to top
View user's profile Send private message Visit poster's website 
oldyeller


Joined: 15 Nov 2011
Posts: 772
Location: Mishawaka IN

PostPosted: 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" 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:
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
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1039

PostPosted: 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
View user's profile Send private message 
oldyeller


Joined: 15 Nov 2011
Posts: 772
Location: Mishawaka IN

PostPosted: 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
View user's profile Send private message 
dejan555


Joined: 30 Nov 2008
Posts: 2646
Location: Montenegro

PostPosted: 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.
fluxbox-shutdown.tar.gz
Description 
gz

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

_________________


Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
oldyeller


Joined: 15 Nov 2011
Posts: 772
Location: Mishawaka IN

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.5062s ][ Queries: 13 (0.1087s) ][ GZIP on ]