GtkDialog - tips
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
generate basic xpm images on the fly
http://www.murga-linux.com/puppy/viewtopic.php?t=54661
I just finished writing two scripts for generating percent bars as xpm images (horizontal or vertical bar). It is pretty basic but its bash so adapt it how you like.
usage "$0" XX% name=filename fgcolor=XXX bgcolor=XXX height=XXX width=XXX
colors can be 3 or 6 digit hexadecimal or None
@mrelectronico - try removing the default tags - probably not needed since you have them blank anyways... or put a "\" before your inner quotes
http://www.murga-linux.com/puppy/viewtopic.php?t=54661
I just finished writing two scripts for generating percent bars as xpm images (horizontal or vertical bar). It is pretty basic but its bash so adapt it how you like.
usage "$0" XX% name=filename fgcolor=XXX bgcolor=XXX height=XXX width=XXX
colors can be 3 or 6 digit hexadecimal or None
@mrelectronico - try removing the default tags - probably not needed since you have them blank anyways... or put a "\" before your inner quotes
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Sunburnt, I decided to take a look at the source code forsunburnt wrote:seaside; I tried all the codes in the ASCII chart for ESC with "read" and nothing.
But more than that, for the gtkdialog key-press-event, what variable would you test?
gtkdialog3-0.7.20-pe-1 and I could not find any evidence that it returns the actual key pressed - it's seems it's a simple boolean return only.
As far as bash goes this only "sort of" works-
Code: Select all
read -sn 1 Key
case "$Key" in
$'\e') echo "Escape Key!";;
esac
Any other key it fails - EXCEPT for function keys. They will
return the "esc" plus additional characters. I have no idea how to get around that.
Cheers,
s
Not really. The bash read function is a built-in, that reads an entire line up to an EOL. Filtering F-keys is a matter of parsing the line.sunburnt wrote:seaside; That`s what I figured for gtkdialog, no key returned ( too much to hope for...).
The Bash example`s the same one I was working with! And yeah, no way to filter out the function keys...
That kinda leaves us programmers up the creek without a paddle as it were... ( whata surprise! )
One filter would be to test the length of the string returned by read. If it's an F-Key, it will be longer than one character. F-Keys and arrow keys all use a subset of the ANSI 3.64 specification, where special keys send a string beginning with Esc[. For instance, up arrow probably sends Esc[A.
______
Dennis
I thought of that, but this code returns 2 for all characters typed:
And "wc -l", "wc -L", and "wc -w" put out the same count no matter what also....
Code: Select all
read -sn 1 Key ; echo $Key |wc -c
"-sn 1" discards everything after the first character. Take "n 1" out of the equation and see if you get different results.sunburnt wrote:I thought of that, but this code returns 2 for all characters typed:And "wc -l", "wc -L", and "wc -w" put out the same count no matter what also....Code: Select all
read -sn 1 Key ; echo $Key |wc -c
______
Dennis
Yep... That returns a 0 for Esc. and 1 for everything else.
Problem as usual, now without -n you must press the Enter key for it to return.
With -n 1 they all return 0. I thought of using "-n 0", but it doesn`t work either.
This of course isn`t typical Esc. key behavior to exit a popup GUI.
It just won`t give me the output I need, press Esc. only.
For Bash to be very useful you`d think it`d have to be able to filter keyboard input...
Problem as usual, now without -n you must press the Enter key for it to return.
With -n 1 they all return 0. I thought of using "-n 0", but it doesn`t work either.
This of course isn`t typical Esc. key behavior to exit a popup GUI.
It just won`t give me the output I need, press Esc. only.
For Bash to be very useful you`d think it`d have to be able to filter keyboard input...
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
will this work for you?
Code: Select all
#!/bin/bash
TIMEOUT=999
echo press ESC to exit
if read -n 1 -s -t $TIMEOUT KEY ; then
KEY=$( echo $KEY | od -t x1 | awk '{ print $2}' )
if [ "$KEY" == '1b' ]; then
echo BAILOUT: nothing changed
exit 0
fi
echo Do something useful here...
else
echo TIMEOUT: nothing changed
exit 0
fi
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
I found this document in French which may have been written by the gtkdialog author.
This file was on an old usb stick and I've no idea of the source.
HTH
Potong
p.s. Apologies if this is a repost
This file was on an old usb stick and I've no idea of the source.
HTH
Potong
p.s. Apologies if this is a repost
- Attachments
-
- gtkdialog.tar.gz
- (127.31 KiB) Downloaded 416 times
Progressbars used as gauges
technosaurus:
Progressbars can be used as gauges and with a little jiggery-pokery can be colouful too.
Here's a an example using BK's partview as a basis:
There is a proviso here
I think that progressbars in gtkdialog3 may cause problems with threads and in particular errors in Xlib. The unscientific rule of thumb is use a few and you'll be OK, use too many and you won't.
HTH
Potong
Progressbars can be used as gauges and with a little jiggery-pokery can be colouful too.
Here's a an example using BK's partview as a basis:
Code: Select all
#!/bin/bash -a
trap 'rm -rf $tmp' EXIT
tmp=$(mktemp -d) title=PartFree gig=1048576
bar_red=$tmp/bar_red.ppm bar_green=$tmp/bar_green.ppm trough=$tmp/trough.ppm
tmp_gui=$tmp/gui tmp_gtkrc=$tmp/gtkrc df=$(df -k)
ptag='height-request="17" width-request="100" show-text="true"'
free_advice=' tune2fs -m 0 <device>
recovers reserved filesystem space
USE AT OWN RISK! '
format(){
(($1>gig*99)) && printf "%dG" $(bc <<<"$1/$gig") && return
(($1>gig)) && printf "%.1fG" $(bc -l <<<"$1/$gig") && return
(($1>99)) && printf "%dM" $(bc <<<"$1/1024") ||
printf "%.1fM" $(bc -l <<<"$1/1024")
}
ppmrough -fg red >$bar_red
ppmrough -fg green >$bar_green
ppmrough -fg grey75 >$trough
cat <<EOF >$tmp_gtkrc
style "mono"{ font_name="Fixed Bold 12" }
style "pb_red" { engine "pixmap" {
image { function = BOX detail = "bar" file = "${bar_red##*/}" }
image { function = BOX detail = "trough" file = "${trough##*/}" } } }
style "pb_green" { engine "pixmap" {
image { function = BOX detail = "bar" file = "${bar_green##*/}" }
image { function = BOX detail = "trough" file = "${trough##*/}" } } }
widget "*mono*" style "mono"
widget "*pb_red*" style "pb_red"
widget "*pb_green*" style "pb_green"
EOF
export GTK2_RC_FILES=/root/.gtkrc-2.0:$tmp_gtkrc
for line in $(probepart -k|sed '/none\|swap/d')
do
#((++count>5)) && break
IFS="|" read device fstype size <<<"$line"
pb_colour=pb_green drive=${device##*/} # now /dev/sda1 becomes sda1
used_available=$(awk -v device=$device '$1==device{print $3"|"$4}' <<<"$df")
used=${used_available%%|*} available=${used_available##*|}
[ "$used" ] || { # mount/umount device to get 'used' value
pb_colour=pb_red
mkdir -p ${device/dev/mnt}
mount -t $fstype $device ${device/dev/mnt} > /dev/null 2>&1 && {
used_available=$(df -k $device | awk -v device=$device '$1==device{print $3"|"$4}')
used=${used_available%%|*} available=${used_available##*|}
umount $device
}
}
((free=size-used, reserved=size-used-available, nused=100*used/size))
free_text=$(format $free) size_text=$(format $size)
used_text=$(format $used) available_text=$(format $available)
reserved_text=$(format $reserved)
text="$(printf "%s %5s" $drive $free_text)"
tt=" Type: $fstype Size: $size_text Used: $used_text
Available: $available_text Reserved: $reserved_text "
cat <<EOV >>$tmp_gui
<hbox>
<text name="mono" label="$text" tooltip-text="$tt"></text>
<progressbar name="$pb_colour" $ptag tooltip-text="$tt">
<input>echo $nused</input>
</progressbar>
</hbox>
EOV
echo "XXX" # infobox msg delimiters
echo "Processing: $device ..."
echo "XXX" # infobox msg delimiters
sync
done | Xdialog --title "$title" --infobox "Please wait ..." 5 30 0 || exit
gui=$(cat <<EOV|sed 's/#.*//'
<window title="$title" allow-grow="false" icon-name="gtk-harddisk">
<vbox>
<hbox>
<text label="Free" tooltip-text="$free_advice"></text>
<progressbar $ptag>
<input>echo Used</input>
</progressbar>
</hbox>
$(<$tmp_gui)
<hbox homogeneous="true">
<button cancel></button>
</hbox>
</vbox>
</window>
EOV)
gtkdialog3 --g-fatal-warnings -p gui
I think that progressbars in gtkdialog3 may cause problems with threads and in particular errors in Xlib. The unscientific rule of thumb is use a few and you'll be OK, use too many and you won't.
HTH
Potong
>> Mave has made an attempt to replace yaf-splash using gtkdialog. Yaf-splash is not supporting UTF-8, and has given some issues when translation to some languages. Read more here
hello,
i have two buttons side by side but the 'small' button is not as wide as the 'longer button' button, is it possible to set a size to buttons to make both buttons the same size so they look uniformed?
<button>
<label>small</label>
<input file>/mnt/sda2/images/127319499.png</input>
<action>exec some file </action>
</button>
<button>
<label>longer button</label>
<input file>/mnt/sda2/images/127319499.png</input>
<action>exec some file</action>
</button>
i have two buttons side by side but the 'small' button is not as wide as the 'longer button' button, is it possible to set a size to buttons to make both buttons the same size so they look uniformed?
<button>
<label>small</label>
<input file>/mnt/sda2/images/127319499.png</input>
<action>exec some file </action>
</button>
<button>
<label>longer button</label>
<input file>/mnt/sda2/images/127319499.png</input>
<action>exec some file</action>
</button>
Code: Select all
<button width-request="100">
<label>small</label>
<input file>/mnt/sda2/images/127319499.png</input>
<action>exec some file </action>
</button>
<button width-request="100">
<label>longer button</label>
<input file>/mnt/sda2/images/127319499.png</input>
<action>exec some file</action>
</button>
Sigmund
-
- Posts: 37
- Joined: Fri 29 Jan 2010, 16:09
Dynamic pixmaps
Here is the issue:
I did lots of testing using 8-bit's pixmap example in this thread.
It seems that only hard coded stock icons and images can be displayed using pixmap.
I can't find any type of work around for this and I'm guessing it is just a limitation of gtkdialog.
I'm really hoping someone can find a flaw with my attempt.
Here is the test code I modified from the pixmap example and an screenshot of the results:
I did lots of testing using 8-bit's pixmap example in this thread.
It seems that only hard coded stock icons and images can be displayed using pixmap.
I can't find any type of work around for this and I'm guessing it is just a limitation of gtkdialog.
I'm really hoping someone can find a flaw with my attempt.
Here is the test code I modified from the pixmap example and an screenshot of the results:
Code: Select all
#!/bin/bash
get_Pic() {
echo foldger.jpg
}
export -f get_Pic
export MAIN_DIALOG="
<vbox>
<frame Static File Name>
<text>
<label>foldger.jpg</label>
</text>
</frame>
<frame Static Picture>
<pixmap>
<input file>\"folgers.jpg\"</input>
</pixmap>
</frame>
<frame Dynamic File Name>
<text>
<input>get_Pic</input>
</text>
</frame>
<frame Dynamic Picture>
<pixmap>
<input file>get_Pic</input>
</pixmap>
</frame>
<hbox>
<button cancel></button>
<button ok></button>
</hbox>
</vbox>
"
gtkdialog3 --program=MAIN_DIALOG
- Attachments
-
- pixmap-test.png
- (39.87 KiB) Downloaded 967 times
Re: Dynamic pixmaps
afishe2000,afishe2000 wrote: Here is the test code I modified from the pixmap example and an screenshot of the results:
Code: Select all
#!/bin/bash get_Pic() { echo foldger.jpg } export -f get_Pic export MAIN_DIALOG=" <vbox> <frame Static File Name> <text> <label>foldger.jpg</label> </text> </frame> <frame Static Picture> <pixmap> <input file>"folgers.jpg"</input> </pixmap> </frame> <frame Dynamic File Name> <text> <input>get_Pic</input> </text> </frame> <frame Dynamic Picture> <pixmap> <input file>get_Pic</input> </pixmap> </frame> <hbox> <button cancel></button> <button ok></button> </hbox> </vbox> " gtkdialog3 --program=MAIN_DIALOG
If your question is "why doesn't the Dynamic Picture work?"
Two reasons-
Code: Select all
get_Pic() {
echo foldger.jpg
}
2. This code -
Code: Select all
<frame Dynamic Picture>
<pixmap>
<input file>get_Pic</input>
</pixmap>
</frame>
Code: Select all
<input file>$(get_Pic)</input>
Regards,
s
-
- Posts: 37
- Joined: Fri 29 Jan 2010, 16:09
Thanks so much,
I'm surprised that <text> works with get_Pic ($(get_Pic) doesn't though) but <pixmap> needs $(get_Pic).
I thought the function was returning a string and both widgets just required a sting input.
I'm surprised that <text> works with get_Pic ($(get_Pic) doesn't though) but <pixmap> needs $(get_Pic).
I thought the function was returning a string and both widgets just required a sting input.
Code: Select all
<text>
<input>get_Pic</input>
</text>
<pixmap>
<input file>$(get_Pic)</input>
</pixmap>
afishe2000,afishe2000 wrote:Thanks so much,
I'm surprised that <text> works with get_Pic ($(get_Pic) doesn't though) but <pixmap> needs $(get_Pic).
The pixmap <input file> does not accept a variable for a filename, so $(get_Pic) is used as a subshell command.
$(get_Pic) doesn't work in text and other inputs because it IS a subshell (Subshell process variables are not visible to parents)
This may be useful-
http://tldp.org/LDP/abs/html/subshells. ... BSHELLSREF
Cheers,
s
I'm using Glade Interface Designer to build up a little gui using libglade.
My problem is using signal to open an internet page: it escapes "&" char in urls to &#.38 (remove the ".", otherwise the forum re-escapes "&#.38" to "&" ) breaking the url, for example the link
http://www.google.com/search?hl=en&q=glade
executes on click:
which is incorrect, so we have
& => & => & tha is "&" escaped!!!
Any tips?
My problem is using signal to open an internet page: it escapes "&" char in urls to &#.38 (remove the ".", otherwise the forum re-escapes "&#.38" to "&" ) breaking the url, for example the link
http://www.google.com/search?hl=en&q=glade
Code: Select all
...
<signal name=\"clicked\" handler=\"defaultbrowser "http://www.google.com/search?hl=en&q=glade"\"/>
...
Code: Select all
defaultbrowser "http://www.google.com/search?hl=en&#.38;q=glade"
& => & => & tha is "&" escaped!!!
Any tips?
Try
http://htmlhelp.com/tools/validator/problems.html
Aitch
http://htmlhelp.com/tools/validator/problems.html
HTHTo avoid problems with both validators and browsers, always use & in place of & when writing URLs in HTML:
<a href="foo.cgi?chapter=1§ion=2©=3&lang=en">...</a>
Note that replacing & with & is only done when writing the URL in HTML, where "&" is a special character (along with "<" and ">"). When writing the same URL in a plain text email message or in the location bar of your browser, you would use "&" and not "&". With HTML, the browser translates "&" to "&" so the Web server would only see "&" and not "&" in the query string of the request.
Incorrect Nesting of Elements
Aitch