1849614 Members
6491 Online
104044 Solutions
New Discussion

Help with dtksh

 
SOLVED
Go to solution
Robert Gamble
Respected Contributor

Help with dtksh

I am hoping someone else has tried this before me and can share what they learned.

I am not familar with dtksh, so it appears a very scary thing to me. =)

I am hoping to find/create a dtksh script that creates a static GUI widget with buttons that can change color based on the state of file/flags.

Example: a gui widget pops up with 3 buttons. one button labeled "process A" is red, other button labeled "process B" is yellow, and button "process C" is green. processA's button is red because the script read in a flag_state from a file...

Any ideas or script alreay out there similar to this logic ?

Thanks In Advance for Any/All Help !
4 REPLIES 4
Frederic Soriano
Honored Contributor

Re: Help with dtksh

Hi Rob,

I once looked at dtksh to see how it worked, and wrote a very little script that displays 3 buttons and exits when pressing on them, but I prefer perl/Tk :o) :

--snip--
#!/usr/dt/bin/dtksh

alias BUTTON_1_CB=exit
alias BUTTON_2_CB=exit
alias BUTTON_3_CB=exit

XtInitialize TOPLEVEL my_form "My form" "$@"
XmCreateForm FORM $TOPLEVEL main_form width:320 height:150

XmCreatePushButton BUTTON_1 $FORM button_1 labelString:"Process 1" x:10 y:100 width:100 height:40
XtAddCallback $BUTTON_1 activateCallback BUTTON_1_CB

XmCreatePushButton BUTTON_2 $FORM button_2 labelString:"Process 2" x:110 y:100 width:100 height:40
XtAddCallback $BUTTON_2 activateCallback BUTTON_2_CB

XmCreatePushButton BUTTON_3 $FORM button_3 labelString:"Process 3" x:210 y:100 width:100 height:40
XtAddCallback $BUTTON_3 activateCallback BUTTON_3_CB

XtManageChildren $BUTTON_1 $BUTTON_2 $BUTTON_3
XtManageChildren $FORM
XtRealizeWidget $TOPLEVEL
XtMainLoop
--snip--

I found an example script (font_chooser.dtksh - see in attachment) that may help you (about different widgets that can be created and so on). If you know the X API, then dtksh shouldn't be a problem for you.

Wishing you luck,

Best regards.

Fred.
Mike Stroyan
Honored Contributor

Re: Help with dtksh

It is easy to set widget colors from dtksh. If you are just displaying a color coded status then you should probably be using label widgets instead of pushbutton wigets. A label widget does not imply that it will do something when you click on it.
I have attached an example that reads values from a file and sets different widget colors for different value ranges.
Robert Gamble
Respected Contributor

Re: Help with dtksh

Thanks for help.

Mike,
In dtksh, how would I re-read the input file automatically in the script, say every 300 seconds, and force the values to be revaluated, and change colors if values changed ?

Or should I reference the *.dtksh file from a normal shell script that is in a loop, destroying and remaking the window every 5 min ?
Mike Stroyan
Honored Contributor
Solution

Re: Help with dtksh

You can use XtAddTimeOut to make a dtksh script run a command after an interval. You can chain one timeout after another to perform a repeating operation. I have attached an example that rereads the status file every 5 minutes. (There is a small memory leak of about 84 bytes per timeout callback, so a rapid timeout can lead to a shell process that gets too big.)
The example uses an associative array to keep track of which label widget represents each name from the status file. That is a nice ksh93 feature that uses a string as an array index. You can read more about that and other ksh93 features using "man ksh93" on HP-UX 10.20 or "man -M /usr/dt/share/man ksh" on HP-UX 11.00.
The example only accumulates widgets, so a status name that is removed from the file will continue to have a label. You could use XtDestroyWidget to remove names that no longer appear in the status file.