GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#361 Post by technosaurus »

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
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].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#362 Post by seaside »

sunburnt 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?
Sunburnt, I decided to take a look at the source code for
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
If you press the "esc" key it returns "Escape Key!" -
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. :D

Cheers,
s

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#363 Post by sunburnt »

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! )

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#364 Post by DMcCunney »

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! )
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.

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

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#365 Post by sunburnt »

I thought of that, but this code returns 2 for all characters typed:

Code: Select all

read -sn 1 Key ; echo $Key |wc -c
And "wc -l", "wc -L", and "wc -w" put out the same count no matter what also....

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#366 Post by DMcCunney »

sunburnt wrote:I thought of that, but this code returns 2 for all characters typed:

Code: Select all

read -sn 1 Key ; echo $Key |wc -c
And "wc -l", "wc -L", and "wc -w" put out the same count no matter what also....
"-sn 1" discards everything after the first character. Take "n 1" out of the equation and see if you get different results.
______
Dennis

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#367 Post by sunburnt »

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...

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#368 Post by technosaurus »

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].

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

#369 Post by potong »

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
Attachments
gtkdialog.tar.gz
(127.31 KiB) Downloaded 416 times

potong
Posts: 88
Joined: Fri 06 Mar 2009, 04:01

Progressbars used as gauges

#370 Post by potong »

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:

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
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

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#371 Post by zigbert »

>> 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

stu90

#372 Post by stu90 »

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>

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#373 Post by zigbert »

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>
read more in chapter 7


Sigmund

stu90

#374 Post by stu90 »

Thanks zigbert 8)

afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

Dynamic pixmaps

#375 Post by afishe2000 »

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:

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

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

Re: Dynamic pixmaps

#376 Post by seaside »

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
afishe2000,

If your question is "why doesn't the Dynamic Picture work?"

Two reasons-

Code: Select all

get_Pic() {
	echo foldger.jpg 
}
1. Should be "folgers.jpg"

2. This code -

Code: Select all

<frame Dynamic Picture>
    <pixmap>
      <input file>get_Pic</input>
    </pixmap>
  </frame>
Command "get_pic" needs to be resolved to the actual filename in place like this -

Code: Select all

 <input file>$(get_Pic)</input>
Great work - keep going :D

Regards,
s

afishe2000
Posts: 37
Joined: Fri 29 Jan 2010, 16:09

#377 Post by afishe2000 »

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.

Code: Select all

<text> 
  <input>get_Pic</input> 
</text> 

<pixmap> 
  <input file>$(get_Pic)</input> 
</pixmap>

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#378 Post by seaside »

afishe2000 wrote:Thanks so much,

I'm surprised that <text> works with get_Pic ($(get_Pic) doesn't though) but <pixmap> needs $(get_Pic).
afishe2000,

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 :D (Subshell process variables are not visible to parents)

This may be useful-

http://tldp.org/LDP/abs/html/subshells. ... BSHELLSREF

Cheers,
s

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#379 Post by neurino »

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 "&" :D ) 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"\"/>
...
executes on click:

Code: Select all

defaultbrowser "http://www.google.com/search?hl=en&#.38;q=glade"
which is incorrect, so we have
& => & => &#38 tha is "&" escaped!!!

Any tips?

User avatar
Aitch
Posts: 6518
Joined: Wed 04 Apr 2007, 15:57
Location: Chatham, Kent, UK

#380 Post by Aitch »

Try

http://htmlhelp.com/tools/validator/problems.html
To avoid problems with both validators and browsers, always use & in place of & when writing URLs in HTML:

<a href="foo.cgi?chapter=1&section=2&copy=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
HTH

Aitch :)

Post Reply