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
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#1051 Post by zigbert »

step
<vbox> and <hbox> has a default margin of 5 pixels. This can be overwritten by

<vbox margin="0">

If this didn't help you, give a note...

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

#1052 Post by don570 »

a guess...
Do your testing with resizable="true"

Code: Select all

<window name="filmstripWindow" resizable="true"> 
_______________________________

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

#1053 Post by step »

Hi, thanks for helping me.
I added margin="0" to all vbox and hbox tags: no visible change.
I changed resizable to false (but I need it true in the final code): no visible change.
Still unresolved.
[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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1054 Post by MochiMoppel »

For debugging I took the liberty to make the code simpler. Here is how far I got:
To eliminate the horizontal border between the eventbox and the edit widget you have set spacing="0" for the vbox (vboxes have a default spacing of 5px).
However this is not sufficient to remove the border. You also have to place the vbox inside the frame. Looks OK to me now.

Code: Select all

<window name="filmstripWindow" resizable="false"> 
<vbox> 
 <hbox> 
   <frame Frametitle> 
   <vbox spacing="0">
	   <eventbox name="filmstripPictureFrame"> 
			<pixmap yalign="0"> 
				<variable export="false">y0x1</variable> 
				<width>180</width> 
				<height>120</height> 
				<input file>/tmp/test.png</input> 
			</pixmap> 
			<action signal="button-press-event">echo >&2 pressed y0x1</action> 
	   </eventbox> 
	   <edit margin="0" name="filmstripCaption" cursor-visible="false" editable="false" accepts-tab="false" wrap-mode="2" hscrollbar-policy="2" vscrollbar-policy="2"> 
		 <variable export="false">y0x1c</variable> 
		 <input file>/tmp/test.txt</input> 
		 <width>200</width> 
		 <height>60</height> 
	   </edit>
   </vbox> 
	</frame> 
 </hbox> 
 <hbox space-fill="false" space-expand="false"> 
   <text space-fill="true" space-expand="true"><label>""</label></text> 
   <button tooltip-text="Help" stock-icon-size="1"> 
	 <input file stock="gtk-about"></input> 
	 <action>launch:GUI_ABOUT</action> 
   </button> 
   <button tooltip-text="Help" stock-icon-size="1"> 
	 <input file stock="gtk-about"></input> 
	 <action>launch:GUI_ABOUT</action> 
   </button> 
   <button tooltip-text="Exit" stock-icon-size="1"> 
	 <input file stock="gtk-quit"></input> 
	 <action>exit:EXIT</action> 
   </button> 
 </hbox> 
</vbox> 
</window>
Attachments
testoutput.png
(13.72 KiB) Downloaded 592 times

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

#1055 Post by step »

Thanks MochiMoppel for helping me, this is good!
Left: no margin and frame inside vbox (adding spacing="0" makes no difference)
Center: spacing="0" and frame outside, as you pointed out
Right: spacing="0" and no frame.

edit 2015-1-13 margin->spacing
Attachments
xscreenshot00001.png
(4.89 KiB) Downloaded 517 times
Last edited by step on Wed 13 Jan 2016, 22:06, edited 1 time in total.
[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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1056 Post by MochiMoppel »

You mean spacing="0"? margin="0" didn't work for me. The one used for the edit widget is a leftover of my testing. It had no effect. The only time when I could see a difference is when I used it as a <window> tag attribute. In this case the outer margin (still visible in your right example) is removed.

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1057 Post by recobayu »

Code: Select all

#!/bin/sh
mkdir muks
grep "<Menu label" /root/.jwmrc|cut -d'"' -f2 > main
#~ grep "<Program label" /root/.jwmrc|cut -d'"' -f2>muks/submain
m=(`grep "<Menu label" /root/.jwmrc|cut -d\" -f2`)
icon=(`grep "<Menu label" /root/.jwmrc|cut -d\" -f4`)

#~ echo ${a[*]}
#indeks
for i in ${!m[*]};do
   #~ sed -e '/"'${a[$i]}'"/,/"'${a[$((i+1))]}'"/!d' /root/.jwmrc|grep "Program label"|cut -d '"' -f2>"muks/$i${a[$i]}.txt"
   sed -e '/"'${m[$i]}'"/,/"'${m[$((i+1))]}'"/!d' /root/.jwmrc|grep "Program label"|cut -d '"' -f2>"muks/$i"
done

buatmenu(){
	for i in ${!m[*]};do
	echo '<button relief="2">
		<label>'${m[$i]}'</label>
		<input file>/root/puppy-reference/midi-icons/'${icon[$i]}'</input>
		<action signal="enter-notify-event">echo "'$i'">muks/sub</action>
		<action signal="focus-in-event">echo "'$i'">muks/sub</action>
		<action signal="enter-notify-event">refresh:notesub</action>
		<action signal="focus-in-event">refresh:notesub</action>
		<width>16</width>
	</button>'
	done
}

buatsub(){
	for i in ${!m[*]};do
		echo '<vbox scrollable="true">'
		cat muks/$i|while read line;do
			exe=`grep "$line" /root/.jwmrc|cut -d '>' -f2|cut -d '<' -f1`
			echo '<button>
				<label>'$line'</label>
				<action>'$exe'</action>
			</button>'
		done
		echo '</vbox>'
	done
}


export mainw='
<window>
	<notebook show-tabs="false" show-border="false">
		<hbox>
			<vbox scrollable="true" height="450">
				 '"`buatmenu`"'
			</vbox>
			<notebook show-tabs="false" show-border="false">
				'"`buatsub`"'
				<variable>notesub</variable>
				<input file>muks/sub</input>
			</notebook>
		</hbox>
	</notebook>
</window>'
echo $mainw>muks/gui
gtkdialog -p mainw
Hi All. I have a problem about size of window. When I just use <notebook>, or i use show-tabs="true", The size of notebook is so wide. Then I think, by use show-tabs="false", it can be fixed. But no. Anybody know how to normal it?
Thank you.
Attachments
widenotebook.png
(52.46 KiB) Downloaded 263 times

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

#1058 Post by step »

MochiMoppel wrote:You mean spacing="0"? margin="0" didn't work for me.
Yes, I meant spacing. I often say margin but mean spacing, my bad. Typo fixed in previous post. Thanks.
[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]

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

#1059 Post by seaside »

recobayu wrote: Hi All. I have a problem about size of window. When I just use <notebook>, or i use show-tabs="true", The size of notebook is so wide. Then I think, by use show-tabs="false", it can be fixed. But no. Anybody know how to normal it?
Thank you.
recobayu,

You might specify the window width like this-

Code: Select all

export mainw='
<window width_request="350">
This will also shrink the right side, but allow scrolling.

Cheers,
s

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#1060 Post by recobayu »

Thank you seaside, I implement it on mukstart 4.3.1 here:
http://murga-linux.com/puppy/viewtopic. ... 689#881689
Now, my problem is my gui slow on start. Actually, I save the script (<window> ... </window>) in /tmp/mukstart/gui. How to start gtkdialog by cat a file? Can we make it start faster? Thank you.

Edit: Fixed by if
:D

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]

Post Reply