Author Topic: repair-database (My first zenity script)  (Read 8795 times)

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: My first zenity/yad script
« Reply #45 on: January 14, 2011, 09:43:26 AM »
This example might give you an idea

Code: [Select]
#!/bin/bash
my_test() {
zenity --question --width 500 --text "    Select <b>Yes</b> to Continue or <b>No</b> to repeat the question" --title "Loop Test"
# If user selects "No" then ask again
if [ "$?" != 0 ]
then
my_test
fi
}
# Main Programme
my_test
exit 0

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: My first zenity/yad script
« Reply #46 on: January 14, 2011, 06:05:38 PM »
This example might give you an idea

Code: [Select]
#!/bin/bash
my_test() {
zenity --question --width 500 --text "    Select <b>Yes</b> to Continue or <b>No</b> to repeat the question" --title "Loop Test"
# If user selects "No" then ask again
if [ "$?" != 0 ]
then
my_test
fi
}
# Main Programme
my_test
exit 0

oh I see this actually helped me thanks.

EDIT:
rereading this almost sounds like I'm saying Neal didn't help and I don't mean that.
« Last Edit: January 14, 2011, 08:15:39 PM by glamdering »

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: My first zenity/yad script
« Reply #47 on: January 14, 2011, 09:01:49 PM »
Added a retry button to check super user - thanks just19 (Did not update the zenity version yet)

I can't seem to fined any answer to the cancel buttons. They work just very delayed.

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: My first zenity/yad script
« Reply #48 on: September 05, 2011, 09:19:44 PM »
So I put the whole script back together today, looked at my cancel button problem. I have got everything working great.

The script continues to finish rebuilding or cleaning out the database when hitting cancel, but to my knowledge there is no way to stop this operation in it's tracks. If someone knows a way that would be awesome, if not I'm going to just assume this script is complete for now. I will add the information on the first post if you want to put this in your own menu.

I'm starting to script something new, so this will most likly be the extent that I will persue this unless something comes up or I disscover something while learning how to script better.

-Thank You for all the help and I hope this is helpful to someone at some point, other than myself.
« Last Edit: September 05, 2011, 10:48:22 PM by glamdring »

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: My first zenity/yad script
« Reply #49 on: September 05, 2011, 11:48:17 PM »
I had forgotten about this - age, too busy or something. Any road, I have a question, glamdring. Does your cancel call for the process to be killed or does it call for the process to stop? I'm thinking to call 'kill' would be better for canceling.     

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: My first zenity/yad script
« Reply #50 on: September 06, 2011, 03:20:59 AM »
Use you know YAD or ZENITY?

I move to YAD, and this works great:

Code: [Select]
...snip
echo "20" ; sleep 1
echo "15" ; sleep 1
echo "10" ; sleep 1
echo "5" ; sleep 1
echo "1" ; sleep 1 ) |
        yad --progress \
  --window-icon=$ICON \
          --title $"$TITLE""$VERSION" \
          --text=$"Your system will shutdown in 20 seconds.\n<b>To abort click on cancel!</b>" \
          --percentage=0 \
  --auto-close \
#   --auto-kill
if [ "$?" = 1 ] ; then
                 yad --title $"$TITLE""$VERSION" \
                 --button="gtk-ok:0" \
                 --width 300 \
                 --window-icon=$ICON \
                 --text=$"Aborted by user!"
                 exit
         fi
snip...

If you can see, i disable --auto-kill function.
Good luck.

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: My first zenity/yad script
« Reply #51 on: September 06, 2011, 07:50:27 AM »
Well I know it dose exit correctly, because it dose this $RXURD. I'm just still getting a decent delay between pressing the button and the next box appearing. Do you think perhaps it is working, just taking that long to kill it? It dose kill it much faster on my new computer, but maybe that's just the database being rebuilt that much faster?

I tried removing --auto-kill and the speed/results seemed the same, which also makes me think --auto-kill isn't doing anything. I believe Synaptic has been updated to the version that has the bug fix for --auto-kill, I will go check.

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: My first zenity/yad script
« Reply #52 on: September 06, 2011, 08:43:06 AM »
I had forgotten about this - age, too busy or something. Any road, I have a question, glamdring. Does your cancel call for the process to be killed or does it call for the process to stop? I'm thinking to call 'kill' would be better for canceling.     

I'm using --auto-kill, which should kill it. Is there a way to make the program echo what it's PID is, so I can kill the PID?

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: repair-database (My first zenity script)
« Reply #53 on: September 06, 2011, 11:58:55 AM »
Perhaps a check of the PID man page will reveal a way to do that.     

Offline Just17

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 11058
  • MLUs Forever!
Re: My first zenity/yad script
« Reply #54 on: September 06, 2011, 12:05:42 PM »
I had forgotten about this - age, too busy or something. Any road, I have a question, glamdring. Does your cancel call for the process to be killed or does it call for the process to stop? I'm thinking to call 'kill' would be better for canceling.    

I'm using --auto-kill, which should kill it. Is there a way to make the program echo what it's PID is, so I can kill the PID?

Code: [Select]
pkill <script name>    might do what you need

else

Code: [Select]
mypid=$$  within the script, will get the PID of the script

Code: [Select]
kill $mypid   will delete it

« Last Edit: September 06, 2011, 12:07:21 PM by Just19 »
MLUs rule the roost!

Linux XPS 3.4.48-pclos1.bfs  64 bit
Intel Core2 Quad CPU Q9450 @ 2.66GHz
4 GB RAM
MCP51 High Def Audio
GeForce GTX 550 Ti
PHILIPS  ‎DVD+-RW DVD8701
‎Logitech ‎BT Mini-Receiver
Afatech DTT

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: repair-database (My first zenity script)
« Reply #55 on: September 06, 2011, 01:03:26 PM »
Perhaps a check of the PID man page will reveal a way to do that.     

I will give it a look later tonight and I will try out your suggestion Just19.

I have to actually get some work done today. ::) When do you guys guess the new version of yad will hit the repos? Is it already in the test repos?

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: repair-database (My first zenity script)
« Reply #56 on: September 06, 2011, 01:15:39 PM »
Leiche has already packaged the update. It should not be too long now.     

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: repair-database (My first zenity script)
« Reply #57 on: September 06, 2011, 05:41:23 PM »
Great, by the way while playing around and learning how to take advantage of user inputs and made  a fun little script that makes shortcuts for you. Of course it's most likely quicker to make them in the terminal, I found it to entertain me today.

Code: [Select]
#!/bin/sh
#This is a fun little script I made, glamdring


#variables
#=========
#WICON='/usr/share/icons/sc-maker.png' && TITLE="Shortcut Maker"
TITLE="Shortcut Maker"
YAD2="yad"


#export
#======
export TEXTDOMAIN=shortcut-maker
export TEXTDOMAINDIR="/usr/share/locale"


#Creat a shortcut?
#================
MSG="No changes were made to your system."
MSG2="Do you want to creat a shurtcut?"
$YAD2 --form --title="$TITLE" --text="$MSG2" --button="gtk-yes:0" --button="gtk-no:1" --sticky --fixed ret=$?
if [ "$?" = "1" ]; then
  $YAD2 --title="$TITLE" --form --notification --text="$MSG" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
  if  [ "$?" = "1" ]; then
  "/usr/bin/shortcut-maker"
  fi
  exit 0
fi


#File selection
#==============
MSG="No changes were made to your system."
MSG2="You are going to creat a shortcut for the following directory"
filelist=$($YAD2 --file --title="$TITLE" --button="gtk-ok:0" --width 800 --height 600);
$YAD2 --text "$MSG2 \n $filelist" --title="$TITLE" --button="gtk-ok:0" --button="gtk-cancel:1" ret=$?
if [ "$?" = "1" ]; then
$YAD2 --title="$TITLE" --form --notification --text="$MSG" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
if  [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
fi
exit 0
fi


#File destination
#================
MSG="No changes were made to your system."
MSG2="The shortcut will be made in this directory"
filelist2=$($YAD2 --file --title="$TITLE" --button="gtk-ok:0" --width 800 --height 600);
$YAD2 --text "$MSG2 \n $filelist2" --title="$TITLE" --button="gtk-ok:0" --button="gtk-cancel:1" ret=$?
if [ "$?" = "1" ]; then
$YAD2 --title="$TITLE" --form --notification --text="$MSG" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
if  [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
fi
exit 0
fi


#Confirm user imputs
#===================
MSG="A shortcut for:"
MSG2="Will be made in:"
MSG3="Is this correct?"
MSG4="No changes were made to your system."
$YAD2 --text "$MSG \n $filelist \n \n $MSG2 \n $filelist2 \n \n $MSG3" --button="gtk-yes:0" --button="gtk-no:1" ret=$?
if [ "$?" = "1" ]; then
$YAD2 --title="$TITLE" --form --notification --text="$MSG4" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
if  [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
fi
exit 0
fi



#Symbolic link command
#=====================
ln -s $filelist $filelist2


#Confirmation
#============
MSG="Thank You for using Shortcut Maker, enjoy your new shortcut!"
$YAD2 --text "$MSG" --button="Restart:1" --button="Thank You:0"
if [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
exit 0
fi

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: repair-database (My first zenity script)
« Reply #58 on: September 07, 2011, 08:40:46 AM »
Good from you, that you add

Code: [Select]
export TEXTDOMAIN=shortcut-maker
export TEXTDOMAINDIR="/usr/share/locale"

but you must add a $ for all descriptions

it failed by you

Code: [Select]
MSG="No changes were made to your system."
MSG2="Do you want to creat a shurtcut?"

add it

Code: [Select]
MSG=$"No changes were made to your system."
MSG2=$"Do you want to creat a shurtcut?"

and we can translate your script ;)

a simple way to get a pot file is bash_trans

« Last Edit: September 07, 2011, 08:44:29 AM by Leiche »

Offline glamdring

  • Hero Member
  • *****
  • Posts: 552
Re: repair-database (My first zenity script)
« Reply #59 on: September 07, 2011, 09:06:36 AM »
Like this
Code: [Select]
#!/bin/sh
#This is a fun little script I made, glamdring


#variables
#=========
#WICON='/usr/share/icons/sc-maker.png' && TITLE="Shortcut Maker"
TITLE="Shortcut Maker"
YAD2="yad"


#export
#======
export TEXTDOMAIN=shortcut-maker
export TEXTDOMAINDIR="/usr/share/locale"


#Creat a shortcut?
#================
MSG=$"No changes were made to your system."
MSG2=$"Do you want to creat a shurtcut?"
$YAD2 --form --title="$TITLE" --text="$MSG2" --button="gtk-yes:0" --button="gtk-no:1" --sticky --fixed ret=$?
if [ "$?" = "1" ]; then
  $YAD2 --title="$TITLE" --form --notification --text="$MSG" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
  if  [ "$?" = "1" ]; then
  "/usr/bin/shortcut-maker"
  fi
  exit 0
fi


#File selection
#==============
MSG=$"No changes were made to your system."
MSG2=$"You are going to creat a shortcut for the following directory"
filelist=$($YAD2 --file --title="$TITLE" --button="gtk-ok:0" --width 800 --height 600);
$YAD2 --text "$MSG2 \n $filelist" --title="$TITLE" --button="gtk-ok:0" --button="gtk-cancel:1" ret=$?
if [ "$?" = "1" ]; then
$YAD2 --title="$TITLE" --form --notification --text="$MSG" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
if  [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
fi
exit 0
fi


#File destination
#================
MSG=$"No changes were made to your system."
MSG2=$"The shortcut will be made in this directory"
filelist2=$($YAD2 --file --title="$TITLE" --button="gtk-ok:0" --width 800 --height 600);
$YAD2 --text "$MSG2 \n $filelist2" --title="$TITLE" --button="gtk-ok:0" --button="gtk-cancel:1" ret=$?
if [ "$?" = "1" ]; then
$YAD2 --title="$TITLE" --form --notification --text="$MSG" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
if  [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
fi
exit 0
fi


#Confirm user imputs
#===================
MSG=$"A shortcut for:"
MSG2=$"Will be made in:"
MSG3=$"Is this correct?"
MSG4=$"No changes were made to your system."
$YAD2 --text "$MSG \n $filelist \n \n $MSG2 \n $filelist2 \n \n $MSG3" --button="gtk-yes:0" --button="gtk-no:1" ret=$?
if [ "$?" = "1" ]; then
$YAD2 --title="$TITLE" --form --notification --text="$MSG4" --button="restart:1" --button="gtk-close:0" --sticky --fixed --on-top ret=$?
if  [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
fi
exit 0
fi



#Symbolic link command
#=====================
ln -s $filelist $filelist2


#Confirmation
#============
MSG=$"Thank You for using Shortcut Maker, enjoy your new shortcut!"
$YAD2 --text "$MSG" --button="Restart:1" --button="Thank You:0"
if [ "$?" = "1" ]; then
"/usr/bin/shortcut-maker"
exit 0
fi