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

#1231 Post by don570 »

It basically just needs to be a small window with buttons that I can run programs from.
People on the forum have already written this...

http://murga-linux.com/puppy/viewtopic.php?t=61962
http://murga-linux.com/puppy/viewtopic.php?t=76713

____________________________________________

To make a quick launcher yourself...

Put links to the desktop files in one folder,
then you can open this folder with the command

Code: Select all

rox -d /path/to/folder
__________________________________________

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

Launch pmusic in a script

#1232 Post by don570 »

Launch pmusic in a script
I have found that it is difficult to launch pmusic inside a script.

Here is method that works reliably even when pmusic has an option.
First of all , choose pmusic from other apps

Code: Select all

for P in mpg123 mpg321  pmusic parole vlc  xine defaultaudioplayer ; do
  MUSIC_APP=$(which $P) && break
done
Now replace pmusic with 'pmusic -B' if you want background music.
Put the command in a file and make executable.

Code: Select all

[ $MUSIC_APP = /usr/local/bin/pmusic ] && MUSIC_APP="pmusic -B"
echo "$MUSIC_APP" \""${snd}"\" > /tmp/pmusic_launch
chmod +x /tmp/pmusic_launch
/tmp/pmusic_launch 2>/dev/null &
_________________________________________________________

I used this method in PTM timer
http://murga-linux.com/puppy/viewtopic.php?t=112410
_________________________

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

Re: Launch pmusic in a script

#1233 Post by MochiMoppel »

don570 wrote:Here is method that works reliably even when pmusic has an option.
First of all , choose pmusic from other apps

Code: Select all

for P in mpg123 mpg321  pmusic parole vlc  xine defaultaudioplayer ; do
  MUSIC_APP=$(which $P) && break
done
Now replace pmusic with 'pmusic -B' if you want background music.
Put the command in a file and make executable.

Code: Select all

[ $MUSIC_APP = /usr/local/bin/pmusic ] && MUSIC_APP="pmusic -B"
echo "$MUSIC_APP" ""${snd}"" > /tmp/pmusic_launch
chmod +x /tmp/pmusic_launch
/tmp/pmusic_launch 2>/dev/null &
Try

Code: Select all

for MUSIC_APP in mpg123 mpg321  pmusic parole vlc  xine defaultaudioplayer ; do 
   which $MUSIC_APP && break 
done 
[ $MUSIC_APP = pmusic ] && OPTION="-B" 
exec $MUSIC_APP $OPTION "$snd"

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

#1234 Post by don570 »

[ $MUSIC_APP = pmusic ] && OPTION="-B"
exec $MUSIC_APP $OPTION "$snd"
I hadn't thought of that. I was trying to do it all as one variable
MUSIC_APP="pmusic -B"
________________________________

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

#1235 Post by MochiMoppel »

don570 wrote:I hadn't thought of that. I was trying to do it all as one variable
MUSIC_APP="pmusic -B"
...which would work perfectly - unless you have unintentionally changed your IFS assignment :wink:

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

#1236 Post by don570 »

I noticed that someone has put up a good page with examples to
explain gtkdialog
http://xpt.sourceforge.net/techdocs/lan ... gExamples/
__________________________________________________

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

Example to show opening a second window

#1237 Post by don570 »

Thunor has given us examples of gtkdialog in action.
http://murga-linux.com/puppy/viewtopic.php?t=82059
In the miscelaneous section there is an example showing the launch of
a second window. I wanted the second window to close at the same time
as the main window. Check this by clicking on 'Quit' button' in main window.

I find this is good for a system of help or a logging function which
uses the second window. As an example see my PTM timer
where the 'Log' button keeps track of previous events.

Thunor's script is rather complicated so I have simplified it.

Code: Select all

#!/bin/sh
#example to show launching of second window

# Please note that the name of the exported shell variable matches the
# window widget's variable directive which is a requirement. Not doing
# this will result in the launching of duplicate windows none of which
# can be closed and a warning message being sent to the terminal.




winMain='
<window title="winMain" width-request="250">
	<vbox>
		<frame>		<button>
				<label>launch winLaunch1</label>
				<action function="launch">winLaunch1</action>
			</button>
			<button>
				<label>closewindow winLaunch1</label>
				<action function="closewindow">winLaunch1</action>
			</button>
		</frame>
		
		
		<hbox homogeneous="true">
			<button use-stock="true" label="gtk-quit"></button>
		</hbox>
	</vbox>
	<variable>winMain</variable>
</window>
'
export winMain

winLaunch1='
<window title="winLaunch1" width-request="250">
	<vbox>
		<text><label>text label</label></text>
		<hbox homogeneous="true">
		<button>
				<label>closewindow</label>
				<action function="closewindow">winLaunch1</action>
			</button>
		
			<button use-stock="true" label="gtk-quit"></button>
		</hbox>
	</vbox>
	<variable>winLaunch1</variable>
</window>
'
export winLaunch1
 I=$IFS; IFS=""
     for STATEMENTS in  $(gtkdialog -p winMain); do
       eval $STATEMENTS        
     done
#gtkdialog --program=winMain
xmessage  "I am here"

Attachments
screenshot-multiple-windows.png
(29.19 KiB) Downloaded 605 times

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1238 Post by BarryK »

Oh joy, I have just discovered this, to show/hide a hbox or vbox:
How to change the gui without restarting the app
>> Recent Gtkdialog allows to hide/show widgets, To hide many widgets at once, you can hide a <hbox> or <vbox>. This will hide all widgets inside the box.
Works real nice.

I have a question though, about this show and hide. I can click on a button, for example, to show/hide a hbox:

Code: Select all

<hbox>
 ...widgets...
 <variable>BOX1</variable>
</hbox>

<button>
 <label>hide</label>
 <action function="hide">BOX1</action>
</button>
But, how can I have it so that BOX1 is hidden by default when the window starts up?

EDIT:
Ha ha, have answered my own question!
I just experimented, this works:

Code: Select all

<hbox visible="false">
 ...widgets...
 <variable>BOX1</variable>
</hbox>

<button>
 <label>show</label>
 <action function="show">BOX1</action>
</button>
There is a problem with window resizing, after doing a "show" then a "hide" again (with a "hide" button) -- the window stays bigger, with a gap in it.
[url]https://bkhome.org/news/[/url]

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

#1239 Post by MochiMoppel »

BarryK wrote:There is a problem with window resizing, after doing a "show" then a "hide" again (with a "hide" button) -- the window stays bigger, with a gap in it.
May not be obvious, but works:

Code: Select all

<window resizable="false"....
BTW: Another way to hide BOX1 is to add an action to the window widget (instead of adding visible="false" to the hbox):

Code: Select all

<action signal="show">hide:BOX1</action>
This is the only method I know to hide/show a widget at start up conditionally. E.g. you may want to show BOX1 only when a certain application is installed or a flag is set.

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1240 Post by BarryK »

MochiMoppel,
Thanks for the reply.

Setting resizable="false" does not fix it for me.

Thanks for the alternative way of setting default hiding.

I have another little problem with window wrapping around the widgets.

This is pretty simple code;

Code: Select all

<window title="EasyShare" icon-name="gtk-network" resizable="false">
 <vbox>
  <text use-markup="true"><label>"<b>Share files and printers over a local network</b>"</label></text>
  
  <hbox>
   <text width-chars="25"><label>CUPS is enabled in the firewall, so a local printer can be accessed by other computers.</label></text>
   <text width-chars="25"><label>Firewall enabled for sharing local files and remote files.</label></text>
   <vbox>
    <pixmap>
     <width>56</width>
     <input file>/tmp/easyshare-1.svg</input>
    </pixmap>
    <button>
     <label>Firewall Setup</label>
     <action function="exit">firewall</action>
    </button>
   </vbox>
   <variable>BOX_FIREWALL</variable>
  </hbox>
 
  <hseparator></hseparator>
  <hbox>
   <button><label>Exit</label><action function="exit">quit</action></button>
  </hbox>
 </vbox>
</window>
As soon as I inserted that hbox section, the window rendered with a big gap on the left side. See picture.

Has anyone encountered this, and know how to fix it?
Attachments
gtkdialog-test1.png
(12.86 KiB) Downloaded 531 times
[url]https://bkhome.org/news/[/url]

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

#1241 Post by MochiMoppel »

BarryK wrote:Setting resizable="false" does not fix it for me.
Fixes it for me based on your code snippet. Needs a complete demo code to understand/fix your problem. Works also with your BOX_FIREWALL. Since you already added resizable="false" to your window widget, below buttons will hide/show BOX_FIREWALL., causing the window to adapt its size accordingly:

Code: Select all

<hbox> 
	<button label="Hide BOX_FIREWALL"><action>hide:BOX_FIREWALL</action></button> 
	<button label="Show BOX_FIREWALL"><action>show:BOX_FIREWALL</action></button> 
	<button><label>Exit</label><action function="exit">quit</action></button> 
</hbox>
As soon as I inserted that hbox section, the window rendered with a big gap on the left side. See picture.
I only see a "big gap" when I remove resizable="false". The not so big gap in the picture you can eliminate with

Code: Select all

<text xalign="0" width-chars="25">

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1242 Post by BarryK »

MochiMoppel wrote:
BarryK wrote:Setting resizable="false" does not fix it for me.
Fixes it for me based on your code snippet. Needs a complete demo code to understand/fix your problem.
Yes, you are right!

I didn't try it properly. I have modified one of thunar's example scripts, attached. If you click "show" in the second row of show/hide buttons, then "hide', the window resizes to wrap around the widgets precisely.

Thanks for that.
Attachments
button_action_functions2.gz
Remove the false &quot;.gz&quot;
(2.78 KiB) Downloaded 223 times
[url]https://bkhome.org/news/[/url]

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1243 Post by BarryK »

Hey guys,
Does anyone know if it is possible to change the text in a label?
Programmatically that is, without restarting the GUI.

I suppose, one way to do it would be to have two different raster images, and use the <input file>image-name</input>

That is, replace the file "image-name" and refresh the button.

I suppose it could be done with SVG also.

In fact, that is such an obvious way of doing it, so I did a search, and yeah, don570 has posted about using SVG in his tutorial manual:

http://murga-linux.com/puppy/viewtopic.php?t=89045

So, question answered!
[url]https://bkhome.org/news/[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

gtkdialog4 for raspberry pi 3

#1244 Post by Lobster »

I am trying to get GROWL my puppy security program, running on Raspbian for raspberry pi 3.

Is it available as a compiled deb? Anyone know where the source code is? :D
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#1245 Post by vovchik »

Dear Lobster,

The linux version of growl (notification) program is here:

There is source there, so I will download it and see whether/how it compiles on my PI3 and post some results here.

With kind regards,
vovchik
Last edited by vovchik on Tue 23 Jan 2018, 12:30, edited 1 time in total.

User avatar
CatDude
Posts: 1563
Joined: Wed 03 Jan 2007, 17:49
Location: UK

#1246 Post by CatDude »

vovchik wrote:Dear Lobster,

The linux version of growl (notification) program is here: https://github.com/mattn/growl-for-linux. There is source there, so I will download it and see whether/how it compiles on my PI3 and post some results here.

With kind regards,
vovchik
Hi

I think Lobster may be after the gtkdialog4 sources.
They are available here: https://github.com/01micko/gtkdialog
not sure if there are newer ones elsewhere though.

CatDude
.
[img]http://www.smokey01.com/CatDude/.temp/sigs/acer-futile.gif[/img]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#1247 Post by Lobster »

Thanks Vovchik and CatDude :D

Will see how Vovchik gets on and then hopefully have a compiled deb?

I would compile it myself but am not great at compiling. Mind you there is a very nice set of demos on the raspberry pi website ... if it is just "make-c gtkdialog.h" I might be able to manage it . . .
https://projects.raspberrypi.org/en/pro ... o-programs

Meanwhile I am off to find The Blazing World ...
https://en.wikipedia.org/wiki/The_Blazing_World
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

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

#1248 Post by don570 »

BarryK wrote: There is a problem with window resizing, after doing a "show" then a "hide" again (with a "hide" button) -- the window stays bigger, with a gap in it.
I would try putting various widgets ---> text , hbox, hidden buttons
with space-expand="true" space-fill="true" directive to see if that
will change behaviour of gtkdialog resizing

<hbox space-expand="true" space-fill="true">


<text space-expand="true" space-fill="true">
<label>""</label>

_____________________________________________

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#1249 Post by vovchik »

Dear Lobster,

I managed to compile and install that growl in Tahr, but RP3 is proving more difficult. The problem is that the header files for openssl in the Raspbian repository (dev files) do not correspond with the biniaries installed. I am afraid I might bork my PI if I install the "recommended" fix to this problem and am still thinking of how to install the headers so that pkg-config knows about them and does not complain. I will get it to work eventually, I hope. I am not the first person to run into this problem....

With kind regards,
vovchik

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#1250 Post by BarryK »

I'm an occasional user of gtkdialog, have a burst of activity, then leave it for sometime. So I never really get in deep, but I am now trying to learn more.

And, I have just hit something that is contrary to my understanding up until now.

If you have some radiobutton, say:

Code: Select all

<frame Radiobutton example>
	<radiobutton>
		<label>Radiobutton1</label>
		<action>echo Radiobutton1 is clicked.</action>
	</radiobutton>
	<radiobutton>
		<label>Radiobutton2</label>
		<action>echo Radiobutton2 is clicked.</action>
	</radiobutton>
	<radiobutton>
		<label>Radiobutton3</label>
		<action>echo Radiobutton3 is clicked.</action>
	</radiobutton>
</frame>
I always assumed that an action would execute if the radiobutton was clicked on. Yes, but the previously-selected radio button also fires it action.

So, initially Radiobutton1 is selected, then I click on Radiobutton2, and I get two echo messages:

Code: Select all

Radiobutton1 is clicked.
Radiobutton2 is clicked.
I think that I have written some broken code in the past, because I didn't understand this.

To me, the default behaviour should be that only the clicked-on button fires its action. Anyway, how to fix this so that it does work as I want?

Well, this does fix it:

Code: Select all

<frame Radiobutton example>
	<radiobutton>
		<label>Radiobutton1</label>
		<action signal="button-release-event">echo Radiobutton1 is clicked.</action>
		<action signal="button-release-event">echo DITTO Radiobutton1 is clicked.</action>
	</radiobutton>
	<radiobutton>
		<label>Radiobutton2</label>
		<action signal="button-release-event">echo Radiobutton2 is clicked.</action>
		<action signal="button-release-event">echo DITTO Radiobutton2 is clicked.</action>
	</radiobutton>
	<radiobutton>
		<label>Radiobutton3</label>
		<action signal="button-release-event">echo Radiobutton3 is clicked.</action>
		<action signal="button-release-event">echo DITTO Radiobutton3 is clicked.</action>
	</radiobutton>
</frame>
Now, if I click Radiobutton2, just get this:

Code: Select all

Radiobutton2 is clicked.
DITTO Radiobutton2 is clicked.
But, is there any other more proper way to do it?
[url]https://bkhome.org/news/[/url]

Post Reply