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

#1041 Post by don570 »

To make two buttons appear in the middle of a column --->

Here's a simple example...

width-request="300" is needed to make the column wide so space
will show.
#!/bin/sh
export MAIN='
<window resizable="true">

<hbox width-request="300" homogeneous="true"> <hbox>

<button cancel></button>
<button>
<label>"Set"</label>
<input file stock="gtk-ok"></input>

<action>EXIT:exit</action>
</button>
</hbox> </hbox>
</window>

'

gtkdialog -c -p MAIN

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

export variable to dialog

#1042 Post by mavrothal »

In a script a have a function that exports a viariable, say test_func() that exports TEST_VAR. Then in then gtkdialog gui I have

Code: Select all

<action>test_func</action>
<action>echo $TEST_VAR</action>
and TEST_VAR is empty.
If I run test_func before I call gtkdialog then TEST_VAR is there.
I guess I need some way to tell to a running dialog to import this newly generated variable.
How could I do that?
Thanks.
== [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
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#1043 Post by SFR »

Hey Mavrothal

As far as I know everything enclosed by a single <action>...</action> tags is executed in a seaparate subshell, so any changes made to variables won't get back to a parent shell.
Well, taking your example, this would work:

Code: Select all

<action>test_func; echo $TEST_VAR</action>
since it's still in boundaries of the very same subshell, but not much beyond that; $TEST_VAR's value will be lost in next line...

The only way I know to freely share data between subshells is to use some kind of IPC, e.g. a temp file or named pipe.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#1044 Post by mavrothal »

SFR wrote:The only way I know to freely share data between subshells is to use some kind of IPC, e.g. a temp file or named pipe.
Thanks. I'll try this then.
== [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] ==

tele1234567891
Posts: 13
Joined: Sat 15 Nov 2014, 20:53

#1045 Post by tele1234567891 »

https://code.google.com/p/gtkdialog/w/list

web page is in read only,
exist newer version with newer code and updated tutorial?

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

#1046 Post by don570 »

If you're looking for source code....

http://ftp.nl.freebsd.org/pub/pub/ibibl ... 8.4.tar.xz

____________________________________

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

#1047 Post by don570 »

Tip:

If you're using a button to close the window and then initiate some processing
of the data.....

your button should assign the exit variable to a word,
if you don't ----> the exit variable will be the label text. If you use
gettext it could be a foreign word.

EXAMPLE:

Code: Select all

<button>
<input file stock="gtk-ok"></input>
<label>"'"$(gettext 'Apply')"'"</label>
<action>exit:CLICKED</action>
</button>

Without the line <action>exit:CLICKED</action>
the exit variable would be assigned the foreign word for 'Apply'

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

#1048 Post by don570 »

Tip :

In a situation where you have two text widgets that you want to be horizontal , I found a situation where 'echo -n' is important.

Here's an example. The second text widget is simply loading a number
from a text file, but I found that the number needs a line ending.

Code: Select all

echo -n  "5" >  /tmp/pcount 
provides that line ending

Code: Select all

 <hbox>
         <text>
            <variable>TEXTFLD</variable>
            <label>Times Button pressed: </label>
         </text>
         
         <text>
            <variable>TEXTWD</variable>
            <input>cat /tmp/pcount</input>
         </text>
      </hbox> 
Look at the difference between a line ending(the top image) and no line ending(the bottom image)

Image

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

#1049 Post by zigbert »

This was a great tip. I used echo -n to fix 2 vertical alignment issues in pMusic.

Thank you

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

#1050 Post by step »

The code below displays two side-by-side pictures with editable captions.
Image #1 in the attached screenshot shows the right side of the window.
I can't get it to look right. I want it to look like Image #2. Basically I want to eliminate the bleeding window color from inside the <frame> so that picture background and text background blend. I added some styles to ease the task, but still I can't get image #1 to look like image #2. Help me please.

You need to place a test image in /tmp/test.png, save this code as /tmp/test.xml, save the styles to /tmp/test.rc, write some caption text to /tmp/test.txt, and run with

Code: Select all

gtkdialog --space-expand=true --space-fill=true --styles /tmp/test.rc -s < /tmp/test.xml
Thanks in advance.

Code: Select all

<window name="filmstripWindow" resizable="false">
  <vbox>
    <hbox>
      <vbox>
        <frame>
          <eventbox name="filmstripPictureFrame">
            <pixmap yalign="0">
              <variable export="false">y0x0</variable>
              <width>180</width>
              <height>120</height>
              <input>/tmp/test.png</input>
            </pixmap>
	    <action signal="button-press-event">echo >&2 pressed y0x0</action>
          </eventbox>
          <edit name="filmstripCaption" cursor-visible="false" editable="false" accepts-tab="false" wrap-mode="2" hscrollbar-policy="2" vscrollbar-policy="2">
            <variable export="false">y0x0c</variable>
            <input file>/tmp/test.txt</input>
            <width>200</width>
            <height>60</height>
          </edit>
        </frame>
      </vbox>
      <vbox>
        <frame>
          <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 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>
        </frame>
      </vbox>
    </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>

Code: Select all

style "styleWindow" {
	bg[NORMAL] = "#DCDAD5"
}
style "stylePictureFrame" {
	bg[NORMAL] = "#fff"
}
style "styleCaption" {
	bg[NORMAL] = "#fff"
}

widget "*filmstripWindow" style "styleWindow"
widget "*filmstripPictureFrame" style "stylePictureFrame"
widget "*filmstripCaption" style "styleCaption"
Attachments
2016-01-11_185341_J.png
(17.42 KiB) Downloaded 260 times
[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
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

Post Reply