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

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

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

Re: click'able progressbar

#1081 Post by mavrothal »

Geoffrey wrote:
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.
Thank you!
That did it. :D
== [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
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#1082 Post by don570 »

Quick tip to avoid bad entries :

If entry widget accepts a positive integer, then check it
with a test...

Code: Select all

ENTRY=8;[ $ENTRY -gt 0 ] && xmessage true

If the time of day is entered then here is a quick check
by eliminating colon with the sed command
and then testing...

Code: Select all

ENTRY=`echo "9:00:09" | sed 's/://g'`;[ $ENTRY -ge 0 ] && xmessage true
Note that an error is passed to shell if variable is ordinary text

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1083 Post by MochiMoppel »

don570 wrote:Note that an error is passed to shell if variable is ordinary text
Wouldn't it be easier to eliminate everything that is not a digit?

Anyway, time entry can be tricky. You would need more tests to catch invalid times like 25:11:22 or 22:1:122.
I think I once wrote me a pretty bullet proof time entry widget. I'll post it - provided I can find it :lol:

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

#1084 Post by seaside »

MochiMoppel wrote:
don570 wrote:
Anyway, time entry can be tricky. You would need more tests to catch invalid times like 25:11:22 or 22:1:122.
Perhaps adapting this approach-

Code: Select all

 [[ $time_entry =~ ^[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]$ ]] && echo yes 
Cheers,
s

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1085 Post by MochiMoppel »

seaside wrote:Perhaps adapting this approach-

Code: Select all

 [[ $time_entry =~ ^[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]$ ]] && echo yes 
Would still allow 25:11:22 :cry:

Maybe this way:

Code: Select all

[[ $time_entry =~ ^([0-1]?[0-9]|2[0-3])(:[0-5]?[0-9]){0,2}$ ]] && echo true
This would allow entries like 5 and 9:30 and 9:9:9, all perfectly legal time formats.

If you want to make sure that these values are written as 05:00:00 and 09:30:00 and 09:09:09 try

Code: Select all

[[ $time_entry =~ ^([0-1][0-9]|2[0-3])(:[0-5][0-9]){2}$ ]] && echo true

Post Reply