LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how to design progress meter with dialog mox (http://www.linuxquestions.org/questions/programming-9/how-to-design-progress-meter-with-dialog-mox-586887/)

Joydeep Bakshi 09-24-2007 04:07 AM

how to design progress meter with dialog mox
 
Dear all,

I am writing a shell-script which will be a frontend of cdrecord and mkisofs. I am at the end of the script but I can't really solve one typical issue.

I like to make a progress indicator which will show the progress level during the burning process. I really can't under stand how to do it.
Could any kind soul please help me ?
thanks in advanced.

Joydeep Bakshi 09-24-2007 04:12 AM

Sorry for type mistake :-(
it would be "dialog box" not "dialog mox"
Sorry

gnashley 09-24-2007 10:30 AM

Have a look at this thread where we discussed this not long ago:
http://www.linuxquestions.org/questi...t=progress+bar

There are several similar solutions there.

Joydeep Bakshi 09-25-2007 01:43 AM

THANKS a lot for pointing out. Thanks once more for your kind response.

Joydeep Bakshi 09-25-2007 03:47 AM

I have visited the links. I must admit that programmers has done some good job by desiging progress bar with shell script. But I am looking a solution which allow me to use the gauge option of dialog box to design progress bar. could any one show me the way of doing that for say cdrecord ?
thanks for your time

gnashley 09-25-2007 05:15 AM

Which dialog box?
Search this forum for answers as this has also been discussed -using dialog, Xdialog , zenity and others. The trouble is that for most you will need a way to estimate how long a process is going to take so that you can feed the percentage already completed into the dialog progress bar. Notice that some of these tools have a similar function called a gauge which doesn't work the same way. Most methods for determining the time needed to do a job will consume more CPU cycles than the work itself, so a simple bar that just fills the space and then starts over, or goes back and forth from one side to the other is gonna be the simplest (like the one suggested by /bin/bash in the thread I linked to).
You should be able to use some of the code given in the thread to make the job easier -once you figure out which dialog-box tool you are going to use.

Joydeep Bakshi 09-25-2007 05:45 AM

Thanks for you clarification. I am talking about the dialog command available in linux. Generally you can find that shell scripts use "dialog" to make CLI frontend. I have designed a shell script which is based on cdrecord and msinfo to do a number of cd writing/erasing.. etc.
Now I like to make a simple progress bar with the gauge option already available in "dialog" box command in linux. But I really don't know how to implement it. where the linked mentioned by tou are really helpful. Specially the "bar" script is doing the job which I like to implement with the help of "dialog --gauge.." but "bar" script has the option to work with a command. For example I have tried

bar -c "cdrecord -dev=ATAPI:0,0,0 blank=all -speed=42 2>/dev/null 1>/dev/null"

and it is showing a clean pregress bar :-) I am trying to do the same with gauge option of "dialog" command but not succeeded yet :-( If you need any more clarification please ask me.

gnashley 09-25-2007 11:30 AM

If you are using dialog, the best examples are available from the Xdialog program which uses nearly exactly the same syntax. There are also good examples of using dialog from any of the Slackware utilities or installer.
Here's an example from the Xdialog program for using the gauge widget. You should be able to use it with dialog by just changing the Xdialog to dialog:

Code:

#!/bin/sh
DIALOG=Xdialog

(
echo "10" ; sleep 1
echo "XXX" ; echo "The new" ; echo "\\n" ; echo "message"; echo "XXX"
echo "20" ; sleep 1
echo "50" ; sleep 1
echo "75" ; sleep 1
echo "100" ; sleep 1
) |
$DIALOG --title "GAUGE" --gauge "Hi, this is a gauge widget" 8 30

if [ "$?" = 255 ] ; then
        echo ""
        echo "Box closed !"
fi

Hopefully, the exampleso of shell-only progress bars from the thread will help you to find a way to measure and pace the progress of the process. My example of using a while loop gives a chance to check the amount of work completed, or when you reach 100 percent in the above example just reset to 10 and let the gauge run that way until finished.
As I said, finding a way to estimate the time needed to do the job and scaling that to percentages is really the hard part -you must take into account differing screen or terminal widths and differing process speeds(what takes 30 seconds on your machine might take a minute on mine...)
Notice that first part of this example is where the percentage gets set and then it is piped into dialog itself.

Here's another example from Xdialog which uses the progress bar:

Code:

#!/bin/sh

# Formats a 1440Kb DOS floppy disk.

TITLE="HD floppy DOS format"

# Change the following variable to suit your system:
DEVICE="/dev/fd0u1440"
MAX_TRACK=79
# This changes depending on your language...
FDFORMAT_MSG_LENGTH=87

fdformat -n $DEVICE | \
Xdialog --title "$TITLE" --no-close \
        --progress "Please wait while low-level formatting...\n\n" 0 0 \
        $MAX_TRACK $FDFORMAT_MSG_LENGTH

( mkdosfs $DEVICE 2>/dev/null ; echo "XXXX" ) |
Xdialog --title "$TITLE" --no-close --no-buttons \
        --infobox "Making the DOS filesystem..." 0 0 0

Xdialog --title "$TITLE" --msgbox "All done !" 0 0

Note that for the progress bar to work, it needs input which prints a character at intervals -like programs which print out dots until finished, so you have to include some code which will generate these characters, if the program you are tracking does not do so.

Joydeep Bakshi 09-26-2007 01:09 AM

Thanks for the codes. As I can understand that the first code which is showing the progressbar after some intervals initiated by sleep command is for demo purpose. The second one for formatting a floppy is a real life example for showing the purpose of dialog --gauge.
But as you have also indicated that a program is required to show the dots or any other character to actually show the progress. I think "bar" command is the most efficient tool for progress bar. It also has the option to work with commands. Like I have successfully used

bar -c "cdrecord -dev=ATAPI:0,0,0 blank=all -speed=42 2>/dev/null 1>/dev/null"

Is there any way around to use bar with dialog command to design a progress bar ?
obviously in this case we don't need the -gauge option any more. But how to display the output of bar command through a nice looking dialog window ?

thanks so far for pointing out "bar" and the codes and your kind response.

gnashley 09-26-2007 03:41 AM

Have a look at the code for bar and figure out how to pipe the output of it's timing mechanism into dialog.


All times are GMT -5. The time now is 10:57 PM.