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
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#1061 Post by don570 »

Bug report:
Gtkdialog 0.8.3 using wheezy on Raspberry pi arm machine

While testing gtkdialog using arm version of wheezy
on my raspberry pi I noticed the following bug...

The following lines won't work --> a variable name error

Code: Select all

<window  name="BgYellow" title="'$(gettext 'SET DATE')' v'$VERSION'">
<window  name="BgYellow" title="'Set DATE'">
<window  name="BgYellow" title="'$(gettext 'SET DATE')'">
<window  name="BgYellow" title="$(gettext 'SET DATE')">
whereas the following lines will work..

Code: Select all

<window  name="BgYellow" title="Set DATE">
<label>"'"$(gettext 'SET DATE')"'"</label>
<frame Set date>
Conclusion:

1) fatdog arm distro doesn't display this bug
2) The bug involves whitespace in the window widget.
3) Only window widget shows this bug
4) It is possible to avoid the bug . Perhaps use eval_gettext instead
and substitute a variable holding desired text??
such as

Code: Select all

 "'"$(eval_gettext "$MESSAGE")"'"
______________________________________________

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#1062 Post by step »

don570 wrote: The following lines won't work --> a variable name error

Code: Select all

<window  name="BgYellow" title="'$(gettext 'SET DATE')' v'$VERSION'">
whereas the following lines will work..

Code: Select all

<window  name="BgYellow" title="Set DATE">
<label>"'"$(gettext 'SET DATE')"'"</label>
<frame Set date>
Conclusion:

1) fatdog arm distro doesn't display this bug
2) The bug involves whitespace in the window widget.
3) Only window widget shows this bug
4) It is possible to avoid the bug . Perhaps use eval_gettext instead
and substitute a variable holding desired text??
such as

Code: Select all

 "'"$(eval_gettext "$MESSAGE")"'"
As regards your last question, you can set a variable to gettext output and use that variable along the widget code. For example:

Code: Select all

VERSION=1.0
MSG_SET_DATE=$(gettext 'SET DATE')
...

set dialog='
<window  name="BgYellow" title="'"$MSG_SET_DATE"' v'"$VERSION"'">'
I have a defensive programming habit of always putting "" around shell variable references.

I don't have Fatdog arm, so I can't reproduce this issue, but...

What exact SHELL command is using that code fragment as a parameter?
I ask because this could be an issue with nested quotes, and without knowing the exterior nesting of that code fragment I can't tell if anything's wrong.

I can think of another cause for this issue to occur on FD arm but not on FD64, the shell that runs the script. What's the first line of your script? #!/sh most likely. On FD64 that means /bin/bash. Does it mean the same on FD arm? I know for a fact that /bin/dash quoting fails subtly on complex quote nesting unlike bash or ash.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#1063 Post by don570 »

I did more testing . Just as I thought :lol: eval_gettext will work


Code: Select all

MESSAGE="SET DATE"
...
...
...
<window  name="BgYellow" title="'"$(eval_gettext "$MESSAGE")"'">
Note that eval_gettext uses soft quoting around $MESSAGE
__________________________________________________________
but I discovered that soft quoting around SET DATE will work as well.

Code: Select all

<window  name="BgYellow" title="'"$(gettext "SET DATE")"'">
__________________________________________________________

The version of gettext doesn't seem to matter since the arm versions are using gettext (GNU gettext-runtime) 0.18.1

If anyone wants to test the script...
http://murga-linux.com/puppy/viewtopic. ... 938#875938

__________________________________________


My conclusion is that it's just a strange thing about
how hard quoting works in the wheezy arm OS

__________________________________________

EDIT: MESSAGE needs to be gettext'd --->

Code: Select all

MESSAGE=$(gettext "SET DATE")
_________________________________________
Last edited by don570 on Sat 30 Jan 2016, 18:34, edited 1 time in total.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#1064 Post by don570 »

to step...

Code: Select all

VERSION=1.0
MSG_SET_DATE=$(gettext 'SET DATE')
...

set dialog='
<window  name="BgYellow" title="'"$MSG_SET_DATE"' v'"$VERSION"'">'

I'll test this when I'm back home.

______________________________________

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#1065 Post by step »

don570 wrote: If anyone wants to test the script...
http://murga-linux.com/puppy/viewtopic. ... 938#875938

__________________________________________

My conclusion is that it's just a strange thing about
how hard quoting works in the wheezy arm OS
__________________________________________
I did test the script on Fatdog64

Code: Select all

# ls -l
total 12
-rwxr-xr-x 1 spot spot 9030 Dec 12 05:00 raspi-date-time

# /bin/bash ./raspi-date-time 
Program has finished
exit= Cancel
Cancel button has been clicked.

# /bin/busybox ash ./raspi-date-time 
Program has finished
exit= Cancel
Cancel button has been clicked.

# /bin/dash ./raspi-date-time 
./raspi-date-time: 51: export: DATE v1.1"  icon-name: bad variable name
So you see that dash doesn't like your script, while bash and ash do. That's what I was trying to explain yesterday: some syntax errors occur only when a specific shell is involved.

Now I don't know if that is the error message you're getting. It could be something entirely different. But make sure that dash isn't used to execute your script - or test your script with dash.

My point is that no script is 100% portable, because versions and flavors of the shell vary from system to system. When we write #/bin/sh in a script we're being very generic, so we lower portability, IMO, because we don't state clearly the shell host for our script. /bin/sh is generic because it's often linked to another shell, maybe one that is incompatible with our script or that we never even tested. For example, on Debian systems /bin/sh is linked to /bin/dash. On Puppy and Fatdog systems it's linked to /bin/bash. On embedded systems it could be linked to busybox ash. Those are three different shells, with many similarities and also lots of differences.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#1066 Post by don570 »

I checked my version of Raspian wheezy OS
and you're right. The shell is the problem.

...but it only occurs in window widget so the window manager may have
something to do with it too.

When I ran the script with /bin/bash the script behaved like puppy linux.

So I will warn all raspberry pi users to start their scripts with

Code: Select all

#!/bin/bash
_________________________________

I made a debain version of gtkdialog 0.8.4 for the raspberry pi 2
Raspian wheezy OS and so far it's working . 8)
_____________________________________

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

one question.

#1067 Post by mister_electronico »

Hi I have one question to see if this is possible.

I know that the following code does not work, but I wonder if there is some method to resfresh and change the file name of the pixmap...

Something like.

Code: Select all

  <frame Pixmap with gif>
    <pixmap>
      <variable>MSG</variable> 
      <input file>/tmp/panel/img/img${j}.gif</input>
    </pixmap>
  </frame>

    <timer milliseconds="true" interval="100" visible="false">

       '`let "j=$j+1" ;if [ $j -eq 57 ];  then j=0 ;  fi    `' 
      <action type="refresh">MSG</action>  
    </timer>
Thanks

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

Re: one question.

#1068 Post by step »

mister_electronico wrote:Hi I have one question to see if this is possible.

I know that the following code does not work, but I wonder if there is some method to resfresh and change the file name of the pixmap...

Something like.

Code: Select all

  <frame Pixmap with gif>
    <pixmap>
      <variable>MSG</variable> 
      <input file>/tmp/panel/img/img${j}.gif</input>
    </pixmap>
  </frame>

    <timer milliseconds="true" interval="100" visible="false">

       '`let "j=$j+1" ;if [ $j -eq 57 ];  then j=0 ;  fi    `' 
      <action type="refresh">MSG</action>  
    </timer>
Thanks
Usually my pixmap input file name is a symlink to the actual image file. When I want to change the picture I relink the same link file to the new picture and refresh the pixmap widget variable.

in your case something like this could probably do (untested):

Code: Select all

<pixmap><variable>MSG<...
  <input file>/tmp/link<...
...
</pixmap>
<timer ...>
  <action>ln -sf /.../new-image-$j /tmp/link<...
  <action>refresh:MSG<...
</timer>
It's very sketchy, I hope you get the idea. You'll need to think about how to best handle $j, since it needs to keep its value across activations of the timer. For instance, you could write j's value at the end of the timer activation and re-read it back from temp file at the next invocation, use it, increment it, write it to temp file again, and so on.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Hi step.

#1069 Post by mister_electronico »

Hi step , yes I have other program with external script control the pixmap.

http://www.murga-linux.com/puppy/viewto ... 333#792333

this external script is:
#!/bin/sh
while true
do
let N=N+1
cp S$N.gif /dev/shm/sim.gif
sleep 0.2
if [ $N -eq 28 ]; then
N=0;
fi

done

Is a gif in gtkdialog form, but I don't like this now.


In this case I need increase the value of variable J inside of the timer and create the link with the image.

But this I don't know how do it.

The link work good, but this is not the problem.


Regards.

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

Re: Hi step.

#1070 Post by step »

mister_electronico wrote:Hi step , yes I have other program with external script control the pixmap.

http://www.murga-linux.com/puppy/viewto ... 333#792333

this external script is:
#!/bin/sh
while true
do
let N=N+1
cp S$N.gif /dev/shm/sim.gif
sleep 0.2
if [ $N -eq 28 ]; then
N=0;
fi

done

Is a gif in gtkdialog form, but I don't like this now.


In this case I need increase the value of variable J inside of the timer and create the link with the image.

But this I don't know how do it.
So, if I understand you correctly, essentially you want to put the script inside the timer. And this we will do now.

The idea is that we move the body of the script loop into the script action. Then the timer is equivalent to the script loop when you set a recurring timer interval of 0.2 s. And you know how to do that already. Let'ss refine the dialog code step by step.

The body of the loop is simply cp S$N.gif /dev/shm/sim.gif. But you said you don't like that and prefer something like '`let "j=$j+1" ;if [ $j -eq 57 ]; then j=0 ; fi `'
In your code $j appears to have usable values from 0 to 56 with wrap around, that is modulo 57.
Variable $j needs to become a gtkdialog variable, we'll call it J and use an invisible entry widget to hold it. The timer will refresh J, which will increment itself.

Code: Select all

<entry visible="false">
  <variable export="false">J</variable>
  <default>-1</default>          this might need to be 0 instead of -1, test it
  <input>echo $((++J % 57))</input>     increments J modulo 57
</entry>
Then the timer to keep J alive, I'm going to call it CLOCK

Code: Select all

<timer milliseconds="true" interval="200" visible="false">
  <variable>CLOCK</variable>
  <action>refresh:J</action>
</timer>
Now CLOCK refreshes J every 200 ms and J keeps running in [0..56]. We need to connect the message, which is a pixmap whose input is a link to image files named after J.

Code: Select all

<pixmap>
  <variable>MSG</variable>
  <input file>/tmp/link-to-J-files</input>
</pixmap>
It is imperative that /tmp/link-to-J-files exist BEFORE gtkdialog runs, otherwise this won't work at all. So you need to set the FIRST link outside of gtkdialog code. In your shell script:

Code: Select all

ln -s /tmp/panel/img/img0.gif /tmp/link-to-J-files
gtkdialog ...
Now we need to relink the image file each CLOCK tick. The shell command goes inside dialog, either as J's action or as CLOCK's action. Let's keep it with J. After the new link is in place, we can tell MSG to display the image file.

Code: Select all

<entry visible="false">
  <variable export="false">J</variable>
  <default>-1</default>          this might need to be 0 instead of -1, test it
  <input>echo $((++J % 57))</input>     increments J modulo 57
  <action>ln -s /tmp/img/img$J.gif /tmp/link-to-J-files</action>
  <action>refresh:MSG</action>
</entry>
That's it, putting it all together

Code: Select all


export DIALOG='

<timer milliseconds="true" interval="200" visible="false">
  <variable>CLOCK</variable>
  <action>refresh:J</action>
</timer>

<entry visible="false">
  <variable>J</variable>
  <default>-1</default>
  <input>echo $((++J % 57))</input>
  <action>ln -s /tmp/img/img$J.gif /tmp/link-to-J-files</action>
  <action>refresh:MSG</action>
</entry>

<pixmap>
  <variable>MSG</variable>
  <input file>/tmp/link-to-J-files</input>
</pixmap>'

ln -s /tmp/panel/img/img0.gif /tmp/link-to-J-files
gtkdialog -p DIALOG
This code assumes an external image pump, something that creates the image files before - or while - gtkdialog is running. Some remarks:

- 200 ms, or five frames a second, is fairly quick. start with small images to make sure gtkdialog can keep up. My concern is not so much the time it takes to redraw the pixmap, but the overall time spent going in and out of the shell to relink each file.

- are you sure <pixmap> supports the gif format? If not use jpg, or png for small enough images.

- if possible try to have the pump create all images before - rather than while - gtkdialog is running. it makes debugging easier.

- don't forget to test which is the correct default value for J, 0 or -1, and...

- this code is totally untested by me :), have fun!
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#1071 Post by LazY Puppy »

Hi.

Just want to mention: I've tested the above code and had to change a little to get it working.

Changed ln -s to ln -s -f. Smallest value for timer I could use was 60.

Checked in tahr 6.0.2.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Yes is working...

#1072 Post by mister_electronico »

Hi step , yes working perfect.

I use this coden in the matrix of led and get running faster.

http://www.murga-linux.com/puppy/viewto ... 471#883471

The code is like you did it.

Code: Select all


export DIALOG='
<pixmap>
  <variable>MSG</variable>
  <input file>/tmp/panel/imgA.svg</input>
</pixmap>

<timer milliseconds="true" interval="100" visible="false">
  <variable>CLOCK</variable>
  <action>refresh:J</action>
</timer>

<entry visible="false">
  <variable>J</variable>
  <default>-1</default>
  <input>echo $((++J % 92))</input>
  <action>rm /tmp/panel/imgA.svg</action>
  <action>ln -s /tmp/panel/img/img$J.svg /tmp/panel/imgA.svg</action>
  <action>refresh:MSG</action>
</entry>

 <hbox>
  
   <button><label>  Exit  </label>
	 <action>"killall script_01"</action>
     <action>exit:Exit</action>
   </button>
  </hbox>
 '

gtkdialog -p DIALOG 
Is with svg images, but works with gif to.

ok wait I send you 2 script...

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

This scripts works

#1073 Post by mister_electronico »

This scripts works with gif images.
Attachments
pixmap.tar.gz
(17.99 KiB) Downloaded 145 times

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

And with you code too.

#1074 Post by mister_electronico »

And with you code working too...

Creates a new image S0.gif

cp S1.gif S0.gif

Code: Select all

#! /bin/bash

export DIALOG='
<frame Pixmap with gif>
  <pixmap>
    <variable>MSG</variable>
    <input file>imgA.gif</input>
  </pixmap>
</frame>
  
<timer milliseconds="true" interval="200" visible="false">
  <variable>CLOCK</variable>
  <action>refresh:J</action>
</timer>

<entry visible="false">
  <variable>J</variable>
  <default>-1</default>
  <input>echo $((++J % 28))</input>
  <action>rm imgA.gif</action>
  <action>ln -s S$J.gif imgA.gif</action>
  <action>refresh:MSG</action>
</entry>

 <hbox>
  
   <button><label>  Exit  </label>
	 <action>"killall script_01"</action>
     <action>exit:Exit</action>
   </button>
  </hbox>
 '

gtkdialog -p DIALOG 

Thanks for you Help step.

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

Re: And with you code too.

#1075 Post by step »

I'm glad it worked for you.
mister_electronico wrote:

Code: Select all

  <action>rm imgA.gif</action>
  <action>ln -s S$J.gif imgA.gif</action>
It really is better to combine those two actions into a single one, see also LazY Puppy's comment

Code: Select all

  <action>ln -fs S$J.gif imgA.gif</action>
For this to work imgA.gif must be created as a link.

Some time later:
I looked at the script in your main thread, I think you can simplify function rotate a bit to make it faster, which might give you a few extra milliseconds to play with.

Code: Select all

rotate() 
{ 
 local val
 read val < /tmp/panel/val.dat &&
 ln -fs /tmp/panel/img/img${val}.svg $IMG &&
 echo $((++val % 93)) > /tmp/panel/val.dat 
} 
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Thanks step.

#1076 Post by mister_electronico »

Thanks for you help.

I'm not a programmer but sometimes I like to play with the idea that I am so. Well it has fun.

Thanks people like you I'm learning.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

tutorial for beginners in programming

#1077 Post by don570 »

I have written a much needed tutorial for beginners in programming.
People can add their comments...

http://murga-linux.com/puppy/viewtopic. ... 420#885420


I posted this tutorial on the raspberry pi forum as well.
I hope to stimulate interest there.

________________________________________________________

ebisu
Posts: 176
Joined: Wed 25 Sep 2013, 05:06

Re: tutorial for beginners in programming

#1078 Post by ebisu »

Last edited by ebisu on Mon 01 Aug 2016, 08:09, edited 1 time in total.

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

click'able progressbar

#1079 Post by mavrothal »

I was wondering if there is a way to make a progress bar clickable.
PPM has

Code: Select all

  <hbox space-expand="false" space-fill="false">
    <progressbar height-request="25" space-expand="true" space-fill="true">
      <input>while [ -s /tmp/petget/install_status -a "$(ps aux|grep PPM_GUI|grep gtkdialog|wc -l)" -gt 2 ]; do cat /tmp/petget/install_status_percent; cat /tmp/petget/install_status; sleep 0.5; done</input>
      <action>enable:VBOX_MAIN</action>
      <action>disable:BUTTON_INSTALL</action>
      <action>rm /tmp/pkgs_to_install</action>
      <action>refresh:TREE_INSTALL</action>
      <action>/usr/local/petget/filterpkgs.sh</action>
      <action>refresh:TREE1</action>
      <action>/usr/local/petget/finduserinstalledpkgs.sh</action>
      <action>refresh:TREE2</action>
      <action>echo 0 > /tmp/petget/install_status_percent</action>
      <action>echo "" > /tmp/petget/install_status</action>
    </progressbar>
    '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  </hbox>
and I would like to add an

Code: Select all

<action signal="button-release-event">do_something</action>
or equivalent (to actually show the dependency list), but I do not seam to be able to find a way to do it.
Would this be possible or it would be better to try in a different way? (maybe a right-click menu in the install tree?)
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

Re: click'able progressbar

#1080 Post by Geoffrey »

mavrothal wrote:I was wondering if there is a way to make a progress bar clickable.
Try wrapping the progressbar with an eventbox, that should work.

Code: Select all

  <hbox space-expand="false" space-fill="false">
    <eventbox>
    <progressbar height-request="25" space-expand="true" space-fill="true">
      <input>while [ -s /tmp/petget/install_status -a "$(ps aux|grep PPM_GUI|grep gtkdialog|wc -l)" -gt 2 ]; do cat /tmp/petget/install_status_percent; cat /tmp/petget/install_status; sleep 0.5; done</input>
      <action>enable:VBOX_MAIN</action>
      <action>disable:BUTTON_INSTALL</action>
      <action>rm /tmp/pkgs_to_install</action>
      <action>refresh:TREE_INSTALL</action>
      <action>/usr/local/petget/filterpkgs.sh</action>
      <action>refresh:TREE1</action>
      <action>/usr/local/petget/finduserinstalledpkgs.sh</action>
      <action>refresh:TREE2</action>
      <action>echo 0 > /tmp/petget/install_status_percent</action>
      <action>echo "" > /tmp/petget/install_status</action>
    </progressbar>
    <action signal="button-release-event">do_something</action>
    </eventbox>
    '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  </hbox>
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

Post Reply