Author Topic: Creating custom gui dialogs for shell / bash scripts  (Read 20908 times)

Linuxera

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #15 on: July 03, 2009, 12:02:07 PM »
I can't wait for this one to be finished, finished, finished!!!   ::)


If you're up for renaming and copying two files to /usr/bin you are more than welcome to help with testing!

http://www.pclinuxos.com/index.php?option=com_smf&Itemid=58&topic=56896.msg475678#msg475678

 ;D ;D


Hum.. Those two files you mentioned in usr/bin are links to apps in usr/share/apps.  I'm not touching this with a 10 footer..

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #16 on: July 03, 2009, 02:49:37 PM »
You are right.. I wasn't using the version from the repo (which creates the links)  :D

The two files to rename & replace are in /usr/share/apps/update-notifier if you are still interested.

Linuxera

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #17 on: July 03, 2009, 03:40:14 PM »
Okay dokay then.  I'll try that out right after I take my smart pills..  ;D ;D

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #18 on: July 03, 2009, 03:52:43 PM »
Okay dokay then.  I'll try that out right after I take my smart pills..  ;D ;D

Hey! Ya gotta share! Please? ;) ;D


DrDOS

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #19 on: July 03, 2009, 09:25:57 PM »
The way I usually accomplish a zenity progress dialog for multiple processes is to put all the processes into a bash function and then pass the function call to zenity:

Code: [Select]
my_bash_function | zenity --progress --title="$TITLE" --text=$"Doing something.." --pulsate --width=400 --auto-close
..I haven't tried it, but you may be able to echo or return the percentages from the function in place of --pusate

Thank you very much for that. I was at least able to get some semblance of a GUI working that only used one type of interface, zenity, even though I'm not keen on the pulsate type of progress bar. You can see what I'm working on here:

http://ronbeau.50webs.com/

I have a lot more I'm working on but I had to get that GUI problem solved before I could finish them and upload the package.

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #20 on: July 03, 2009, 10:41:16 PM »
..glad it helped!  8)

I didn't try the script, but the gallery looks nice..  bookmarked it for another day!

Linuxera

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #21 on: July 04, 2009, 06:21:52 AM »
Okay dokay then.  I'll try that out right after I take my smart pills..  ;D ;D

Hey! Ya gotta share! Please? ;) ;D

Right after I remember where i put them...  :-\ :-\

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #22 on: July 04, 2009, 07:47:26 AM »
Okay dokay then.  I'll try that out right after I take my smart pills..  ;D ;D

Hey! Ya gotta share! Please? ;) ;D

Right after I remember where i put them...  :-\ :-\

Uh-oh. ::) I'll never get any now. ;) ;D

Guess I'll have to settle for my usual plodding along. :(

 ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D

Linuxera

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #23 on: July 04, 2009, 11:51:46 AM »
Heyyyyyyy, I found them... Here, Neal,  take a few.. LOL   ;D ;D 8) 8)

[attachment deleted by admin]

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #24 on: July 04, 2009, 12:26:59 PM »
Heyyyyyyy, I found them... Here, Neal,  take a few.. LOL   ;D ;D 8) 8)

Thanks! I'm gonna get smarter -- I am already -- well, I think so. It feels like my brains cells have doubled -- let me check -- yep! Got 2 now. ;) ;D


DrDOS

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #25 on: July 05, 2009, 05:25:31 PM »
I ran across this page which has some interesting code for the zenity progress bar:

http://ubuntuforums.org/archive/index.php/t-34705.html

Look down to the bottom of the page for working script, the top one is faulty.

I spent a couple of hours testing it. What I found was that you had to feed the progress bar integers and bash only works in integers, so in my case if there was more than 100 pictures in a folder the integer was always zero so it wouldn't go anywhere. On the other hand I learned to use the 'for i in' loop to feed it the file names being processed so I did get a satisfactory progress bar working. It's certainly much better and nice enough to use. As a side note I figured out a way to make a link page that used thumbnails, the first thumbnail from each thumbnail page, instead of text, so that is much nicer also. I also figured out a way to add caption and text for the popup windows that will be simple and easy to use, in other words the average person would be able to do it.

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #26 on: July 05, 2009, 11:00:45 PM »
..bash only works in integers, so in my case if there was more than 100 pictures in a folder the integer was always zero so it wouldn't go anywhere.


Try this..

Code: [Select]
#!/bin/bash
function count_file_progress() {
cd $1
INCREMENT_PERCENT=1
FILES=`ls -X1 |grep -v "**/" | grep -v "**@"` #exclude links and directories
FILE_COUNT=`ls -X1 |grep -v "**/" | grep -cv "**@"`
for (( i=$INCREMENT_PERCENT; i<100; i=$i+$INCREMENT_PERCENT )); do
PROGRESS[i]=$(echo "$FILE_COUNT $i" | awk '{ rounded = sprintf("%.0f", $1*$2/100); print rounded }')
# echo "$i%=${PROGRESS[i]}"
done
COUNT="0"
for FILE in $FILES; do
COUNT=$(echo "$COUNT+1"|bc)
for (( i=$INCREMENT_PERCENT; i<100; i=$i+$INCREMENT_PERCENT )); do
if [ "${PROGRESS[$i]}" == "$COUNT" ]; then echo "$i = $FILE"; fi
done
#################################################################################
################ do something with files here! (or just sleep!) #################
#################################################################################
sleep 0.03
done
echo 100 #tell zenity we are done
}

PATH_TO_FILES="/share"
count_file_progress $PATH_TO_FILES | zenity --auto-close --auto-kill --progress \
--text="Progress is happening.. " \
--title="Example Progress" \
--width=400


I tested it in a directory with over 800 files and it worked well.  

NOTES:
--The zenity command is given the --auto-kill, option so that it will kill the script when cancel is pressed.  
--The frequency (in percent) at which progress is updated is set by the variable INCREMENT_PERCENT
--The above reads ALL file names in the directory, not just pictures; to read only certain file types, update the function with something like:
Code: [Select]
#
FILE_TYPES='*.[Jj][Pp][Gg] *.[Jj][Pp][Ee][Gg] *.[Gg][Ii][Ff] *.[Pp][Nn][Gg]'
FILES=`ls -X1 $FILE_TYPES`
FILE_COUNT=`ls -X1 $FILE_TYPES 2>/dev/null |wc -l `

Essentially what the script does is read a set of file names using the ls command, then also counts the number of lines from the same command.  It uses this file-count to calculate which files in the list (by count) correlate to the progress increments and stores those values in an array..  the loop that processes the files then does a quick check every time it processes a file to see if it has reached a progress point; it it has, then it echo's that progress point for zenity to read.

 ;D 8)
« Last Edit: July 05, 2009, 11:27:59 PM by travisn000 »

DrDOS

  • Guest
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #27 on: July 07, 2009, 03:48:00 PM »
After thinking about it in a more abstract way I realized that there are only four operations defined over the integers, add, subtract, multipy and modulus divide by. So I came up with this.

Code: [Select]
#!/bin/sh
IFS=$'\t\n'
#
function count {
cnt=$( dir -1 | wc -l )
let total=100*$cnt
#echo $total
for (( i = 0 ; i <= $total ; i++ ));do sleep .001;
if (( i%$cnt == 0 ))
then
let j=$i/$cnt
echo $j
fi
if (( i%100 == 0 ))
then
let k=$i/100
 echo "#$k"
fi
done
}
count | zenity --progress --auto-close --text="Counting Files"
exit 0


Haven't found a good use for it, but it is a good deal simpler than the one above. Haven't figured out how to link the count number to the filenames but that shouldn't be too hard.

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Creating custom gui dialogs for shell / bash scripts
« Reply #28 on: August 30, 2010, 11:41:54 AM »
Hopefully resurrecting this thread works out OK ........

I have just begun to look at GtkDialog with a view to using it for simple Bash scripts. I am trying to wade through the documents I can find but am having a difficult time .....  possibly because I cannot programme in any language   ;D

In any case, starting with the simplest thing that occurred to me, which I of course failed to achieve, here is an example which allows me to select a file.

Code: [Select]
#! /bin/bash
export MAIN_DIALOG='
<window title="'$"  My Programme   "'"icon-name="'$"gtk-file"'">
<vbox spacing="20">
<pixmap>
<input file>"'/usr/share/icons/dobie-32x32-Bl.png'"</input>
</pixmap>
<frame Select your file>
<hbox>
      <entry editable="'$"false"'" accept="'$"filename"'">
        <variable>FILE1</variable>
      </entry>
      <button>
        <input file stock="'$"gtk-file"'"></input>

        <variable>FILE_BROWSE_FILENAME</variable>
         <visible>enabled</visible>
        <action type="'$"fileselect"'">FILE1</action>
      </button>
</hbox>
</frame>
</vbox>
</window>
'
gtkdialog MAIN_DIALOG


This immediately raises some very simplistic (I am sure) questions .....

How does one determine the width of the window so that the window name is fully exposed?
Why do very strange things happen when I try to select a file of 0 bytes?
How can I limit the displayed files to maybe ".txt" files?

Lastly, a more general question ......  is there a listing somewhere to show me what are valid commands (?) ...  not sure what they are called TBH ......  but a list of things like
<label>
<pixmap>
<button>
<variable>
<visible>

and so on. There must be somewhere I can access these so that I am aware of what might be available to be used.

Just the first steps .....

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
« Last Edit: August 31, 2010, 06:46:51 AM by travisn000 »