GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#136 Post by zigbert »

Patriot
The only way I know to update an entry without actually click on something in the gui is to include a progressbar. At the time the progressbar reach 100% it runs the <actions> defined. This works just fine, but it uses more cpu-power than we want. If there exist a better approach, both Pburn and Pmusic would benefit of it.

Code: Select all

#!/bin/sh

export box="
 <vbox>
  <progressbar>
   <input>"'while [ A != B ]; do sleep 0.5; P=`cat /tmp/p`;	echo $P; echo 100 > /tmp/p; done'"</input>
   <action>refresh:ENTRY</action>
   <action>echo 99 > /tmp/p</action>
  </progressbar>
  <entry>
   <variable>ENTRY</variable>
   <input>date +%H:%M:%S</input>
  </entry>
 </vbox>"

gtkdialog3 -p box

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

#137 Post by zigbert »

How can I know which key(s) user press?

Code: Select all

<window>
  <action signal="key-press-event">echo Window: key-press-event</action>
</window>

Sigmund

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#138 Post by Patriot »

Hmmm .....
zigbert wrote:How can I know which key(s) user press? .....
I was wondering about that too ... but haven't figured out how yet ...
zigbert wrote:........ If there exist a better approach, both Pburn and Pmusic would benefit of it.
Ok, see if my klutz method can be of any use to you (xsendkey is in the archive) ...

Code: Select all

#!/bin/sh

borgdir=$(pwd)
export BORG_DIALOG='
<window title="Selfupdate" icon-name="gtk-info">
<vbox>
  <text><label>""</label></text>
  <entry can-focus="no" width-request="200">
	<variable>UPDATE</variable><input>date</input>
  </entry>
  <text><label>""</label></text>

  <hbox>
	<button>
	  <label>Update</label>
	  <variable>bUpdate</variable>
	  <action>refresh:UPDATE</action>
	</button>
	<button>
	  <label>Exit</label>
	  <action>exit:Exit</action>
	</button>
  </hbox>
</vbox>
<action signal="key-press-event">refresh:UPDATE</action>
</window>
'
gtkdialog3 -p BORG_DIALOG -c >$borgdir/borg.$$ &
i=0
while [ $i -le 5 ]
do
  sleep 1
  GtkWID=$(xwininfo -name Selfupdate | grep id: | cut -f4 -d' ')
  [ $GtkWID ] && break
  ((i++))
done
unset BORG_DIALOG

while [ 1 ]
do
  [ "$GtkWID" ] && $borgdir/xsendkey -window $GtkWID A &>/dev/null
  [ "$(cat $borgdir/borg.$$)" ] && break
  sleep 1
done
rm -f $borgdir/borg.$$

Rgds
Attachments
gtk_selfupdate.tar.gz
(6.02 KiB) Downloaded 443 times

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

gettext

#139 Post by ljfr »

Hi,
I made an example on xorgwizarg on how to use gettext in scripts,
this is not directly link to GtkDialog, but it works for GtkDialog text too,
see:
http://www.murga-linux.com/puppy/viewtopic.php?t=46829
regards,

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

#140 Post by zigbert »

Patriot
This is interesting! :D
Your example is maybe a bit inflexible, but you show a creative gtkdialog/bash code structure. I am sure we will see more of this.....


Thanks for sharing
Sigmund

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

#141 Post by zigbert »

>> How to store window size/placement
This example shows how we can save settings for window size and placement for next startup. Be also aware that this solution makes it possible to let user rescale gui smaller than the default size. Normally you define the size of ie. a <tree>, and the user can only resize the gui larger, but when using <window default_height="$HEIGHT" default_width="$WIDTH">, you don't need to define <height> and <width> for the tree widget.

Code: Select all

#! /bin/bash

save_geometry (){
	XWININFO=`xwininfo -stats -name SizeMe`
	HEIGHT=`echo "$XWININFO" | grep 'Height:' | awk '{print $2}'`
	WIDTH=`echo "$XWININFO" | grep 'Width:' | awk '{print $2}'`
	X1=`echo "$XWININFO" | grep 'Absolute upper-left X' | awk '{print $4}'`
	Y1=`echo "$XWININFO" | grep 'Absolute upper-left Y' | awk '{print $4}'`
	X2=`echo "$XWININFO" | grep 'Relative upper-left X' | awk '{print $4}'`
	Y2=`echo "$XWININFO" | grep 'Relative upper-left Y' | awk '{print $4}'`
	X=$(($X1-$X2))
	Y=$(($Y1-$Y2))
	echo "export HEIGHT=$HEIGHT"	> /tmp/geometry
	echo "export WIDTH=$WIDTH"		>> /tmp/geometry
	echo "export X=$X"				>> /tmp/geometry
	echo "export Y=$Y"				>> /tmp/geometry
	chmod 700 /tmp/geometry
}

export -f save_geometry
[ -f /tmp/geometry ] && . /tmp/geometry

export DIALOG="
<window title=\"SizeMe\" default_height=\"$HEIGHT\" default_width=\"$WIDTH\">
  <vbox>
    <frame>
      <text>
        <label>If you resize or move this window, it will be remembered for next time.</label>
      </text>
    </frame>
    <hbox>
      <button ok>
      </button>
    </hbox>
  </vbox>
  <action signal=\"hide\">save_geometry</action>
</window>"
gtkdialog3 --program=DIALOG --geometry +"$X"+"$Y"

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#142 Post by Patriot »

Hmmm .....
zigbert wrote: ..... Your example is maybe a bit inflexible .....
Yes, it seems not flexible at all ... it's only to show logic flow ... The one I was working on updates about a dozen widgets on different timers all self-contained ... and it runs another dozen different threads ... not a simple example to show ...


Rgds

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

#143 Post by zigbert »

With Patriots new gtkdialog it is possible to close a launched window from the main window. I wonder how it would be possible to click on a button to launch a new window......and at next click close the launched window?


Sigmund

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

#144 Post by zigbert »

....and, is it possible to place the launched window somewhere else than the main window.....

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#145 Post by Patriot »

Hmmm .....

zigbert,

Haaa ... you're gonna love this ... I thought of flip-flop switch when you asked about open+close button ... so, I thought of checkboxes but it didn't occur to me that I can whack it like this ... So, we now have a method to store flip-flops within gtkdialog ...

I believe launched windows uses the same main parameters, so if -c is specified then it gets centered and etc .....

An example to illustrate a) open+close window from a single button b) flip-flop vars

Code: Select all

#!/bin/sh
# Requires the fixed gtkdialog3-pe1

export CHILD_DIALOG='
<window title="Child Dialog">
  <vbox width-request="180">
   <frame>
     <text><label> I am coming </label></text>
     <text><label> out to play. </label></text>
     <text><label> Own PID, cant act on parent </label></text>
   </frame>
   <button><label>increase number</label>
     <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
     <action>refresh:TEXT</action>
   </button>
  </vbox>
</window>
'

export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
  <vbox>
    <text>
      <label>This is an other dialog window.</label>
    </text>
    <button><label>increase number</label>
      <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
      <action>refresh:TEXT</action>
    </button>
    <button>
      <label>Close me</label>
      <action type="closewindow">LAUNCHED_DIALOG</action>
    </button>
  </vbox>
'

export MAIN_DIALOG='
<window title="Main Dialog" tooltip-text="Copyleft by Patriot and zigbert">
  <vbox width-request="240">
  <text width-chars="40"><label>"Clickity click to open"</label></text>
  <text width-chars="40"><label>"Clickity click to close"</label></text>
  <text width-chars="40"><label>"Clickity click to exit"</label></text>
   <frame>
   <text width-chars="40" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
   </frame>
	<checkbox visible="false">
	  <label>"OPENCLOSE1"</label>
	  <variable>OPENCLOSE1</variable>
	  <input>if [ "$OPENCLOSE1" = "false" ]; then echo "true"; else echo "false"; fi</input>
	  <action>if true gtkdialog3 -p CHILD_DIALOG -G +60+60 &</action>
	  <action>if true echo $(ps ax|awk '"'"'{if (match($7, "CHILD_DIALOG")) print $1}'"'"')>/tmp/child.pid</action>
	  <action>if false [ -f /tmp/child.pid ] && p=$(cat /tmp/child.pid) && kill $p</action>
	</checkbox>
   <button><label>Open/Close 1</label>
     <action>refresh:OPENCLOSE1</action>
   </button>

	<checkbox visible="false">
	  <label>"OPENCLOSE2"</label>
	  <variable>OPENCLOSE2</variable>
	  <input>if [ "$OPENCLOSE2" = "false" ]; then echo "true"; else echo "false"; fi</input>
	  <action>if true launch:LAUNCHED_DIALOG</action>
	  <action>if false closewindow:LAUNCHED_DIALOG</action>
	</checkbox>
   <button><label>"Open/Close 2"</label>
	  <action>refresh:OPENCLOSE2</action>
   </button>

   <button tooltip-text=" Exit? Really? "><label>Exit </label>
   <action>exit:Exit</action>
   </button>
  </vbox>
</window>>
'
echo 1 > /tmp/tmp

gtkdialog3 -p MAIN_DIALOG -c
unset CHILD_DIALOG
unset MAIN_DIALOG

It's not bulletproof but it's good enough example .....


Rgds

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#146 Post by big_bass »

Hey Patriot

I have an updated version of gtk+-2.12.9-i486-slxr.tgz

running and your test code appears to be working
correctly without patching gtkdialog3 ???


*without using this gtkdialog3-0.7.20-pe1-i486.pet package

so is there something I can do to confirm the original problem
is due to gtkdialog3 or a bad version of gtk+-2.12.
that's pre installed

I will be happy to test any snippet and report back
results


the main reason of concern for me is do I need to run a patched version of gtkdialog3 or just upgrade to of gtk+-2.12.9

nice code snippet keep them coming :D
thanks
Joe
Attachments
gtk.png
(30.17 KiB) Downloaded 1326 times

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#147 Post by Patriot »

Hmmm .....

Hey there big_bass !
big_bass wrote:..... I have an updated version of gtk+-2.12.9-i486-slxr.tgz .....

..... the main reason of concern for me is do I need to run a patched version of gtkdialog3 or just upgrade to of gtk+-2.12.9 .....
I've been using gtk+-2.12.12 since may and just didn't want to bother anyone about it ...

As it is, the "original" gtkdialog3 will run just fine with the above launch dialog script, just that it closes the main window instead of the child dialog. The patch only deals with this issue thus allows closing the correct child dialog. If you feel that your scripts does not rely on this, then its not a big issue ..... The rest as were discussed with zigbert are scripted workarounds .....

To clarify, the first button starts a separate gtkdialog3 "thread" and thus not affected by the bug. The second button opens/closes the child dialog (same thread) and is affected by the bug. (The bug itself was due to a borked window widget ID selection/parsing btw ...)


Rgds

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#148 Post by big_bass »

Hey Patriot
To clarify, the first button starts a separate gtkdialog3 "thread" and thus not affected by the bug. The second button opens/closes the child dialog (same thread) and is affected by the bug. (The bug itself was due to a borked window widget ID selection/parsing btw ...)

thanks for the details

yes,it is confirmed to be a gtkdialog3 error
it doesnt improve this error changing to gtk+-2.12.9

test
without installing gtkdialog3 "patched"
the second button does close after the pressing open/close2
two times then the parent window closes also

after installing the gtkdialog3 "patched"

the parent window remains open
no matter how many times you press open/close2

*if* you patched more than one file could you make a patch.diff
that way we can apply it to to another version easily if needed

this kind of thing gets lost in many threads
a request when you make the patch.diff
could you please update and add it to your original
fixed pet package link

thanks for your quick reply

I found this source and got a huge diff compared to your package
http://puppylinux.com/sources/alphabeti ... ed2.tar.gz

is that the correct link???

Joe

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#149 Post by amigo »

big_bass, I looked into this as I wondered about the changes myself.
One thing to realize is that many changes will show up in diffs which have no effect. I mean that changes to Makefile.in and other such files are usually meaningless.
I downloaded the original sources and compared with the gtkdialog3-0.7.20-patched2 and gtkdialog3-0.7.20-pe-1 sources.

First of all the gtkdialog3 sources originally used for puppy were the original sources *with the debian diff applied*. the debian diff adds *lots* of changes which don't amount to anything. Here's alist of the files it patches:
gtkdialog_0.7.20-4.diff.gz
config.guess
config.sub
debian/changelog
debian/compat
debian/control
debian/copyright
debian/gtkdialog.sgml
debian/info
debian/patches/00list
debian/patches/01_bashism.dpatch
debian/patches/02_documentation_paths.dpatch
debian/patches/03_stdin.dpatch
debian/patches/DPATCH
debian/rules
debian/watch
examples/05.01-progress_bar_closewindow
examples/05.02-progress_bar_test
examples/09.12-tree_one_column


All the files under the debian dir are just files for use with the debian build/packaging system. the last three are just changes to the examples. The other two: config.guess and config.sub are the ones which make the debian patch so long. They always put their own copy of these two files as they are adapted for building on stange arches like mips and arm. Any way, the whole bunch can be ignored.

If you do a full diff between patched2 and pe-1 you may get extra meaningless changes, but I didn't see any this time. The changes you might see could be in Makefile.in files or other files which may be regenerated if someone runs autogen.sh which recreates them -the dates will be different and there may be large differences if the two people didn't use the same version of automake, autoconf and libtool.

Also, most Puppians seem to save the original files with a different name, so if you compare with original sources then you'll see one 'hunk' of the patch which shows the renamed file which can be ignored.

Okay, cut to the chase:
Here'S the diff for patriots changes -nicely commented:

Code: Select all

diff -pru src-patched2/actions.c src-pe1/actions.c
--- src-patched2/actions.c	2007-03-16 15:25:49.000000000 +0100
+++ src-pe1/actions.c	2009-10-25 18:30:32.000000000 +0100
@@ -40,9 +40,31 @@ action_closewindow(GtkWidget *widget, ch
 #ifdef DEBUG
 	g_message("%s(%p, '%s')", __func__, widget, string);
 #endif
-	parent_widget = gtk_widget_get_toplevel(widget);
+
+/**
+ * Patriot Oct 2009: zigbert has been dreaming for this to be fixed.
+ * Issue: closewindow command closes THE window its called from.
+ * Fixed: Workaround applied to point to the correct window.
+ **/
+
+	variable *windowvar;
+	windowvar = variables_get_by_name(string);
+#ifdef DEBUG
+		fprintf(stderr, "%s(): Widget name: %s.\n", __func__, windowvar->Name);
+		fprintf(stderr, "%s(): Widget type: %d.\n", __func__, windowvar->Type);
+		fflush(stderr);
+#endif
+	if (windowvar != NULL && windowvar->Widget != NULL) {
+		parent_widget = gtk_widget_get_toplevel(windowvar->Widget);
+	}
+	else {
+		return (0);
+	}
+
+//	parent_widget = gtk_widget_get_toplevel(widget);  // incorrect pointer
 	variables_drop_by_parent(NULL, parent_widget);
 	gtk_widget_destroy(parent_widget);
+
 	/*
 	 * Now, if this was the last window, we can exit.
 	 */
@@ -62,6 +84,7 @@ action_closewindow(GtkWidget *widget, ch
 */
 int action_launchwindow(GtkWidget * widget, char *string)
 {
+	GtkWidget *parent_widget;
 	variable *existing;
 #ifdef DEBUG
 	fprintf(stderr, "%s(): Window: %s.\n", __func__, string);
@@ -73,7 +96,13 @@ int action_launchwindow(GtkWidget * widg
 	 */
 	existing = variables_get_by_name(string);
 	if (existing != NULL && existing->Widget != NULL) {
-		gtk_window_present(GTK_WINDOW(existing->Widget));
+	/**
+	* Patriot Oct 2009: Fixing the issue above also 
+	* require a minor adjustment to this section.
+ 	**/
+		parent_widget = gtk_widget_get_toplevel(existing->Widget);
+		gtk_window_present(GTK_WINDOW(parent_widget));
+//		gtk_window_present(GTK_WINDOW(existing->Widget)); // incorrect pointer
 		return (0);
 	}
 
Interestingly, here's the changes which Barry had made from the original sources to patched2 (and minus the debian patch):

Code: Select all

diff -pru src.orig/glade_support.c src-patched2/glade_support.c
--- src.orig/glade_support.c	2007-03-16 15:25:49.000000000 +0100
+++ src-patched2/glade_support.c	2009-06-06 17:53:01.000000000 +0200
@@ -37,10 +37,10 @@
  *                                                                       *
  *                                                                       *
  *************************************************************************/
-typedef struct signal {
+typedef struct signal_bk {
 	gchar     *name;
 	GCallback callback;
-} signal;
+} signal_bk;
 
 /*
 ** Signal handler callbascks.
@@ -206,7 +206,7 @@ on_any_widget_almost_any_gdk_event(
 static gboolean
 find_and_connect_handler(
 		GtkWidget *widget,
-		signal *signals,
+		signal_bk *signals,
 		const gchar *signal_name,
 		const gchar *handler_name)
 {
@@ -288,7 +288,7 @@ gtk_entry_signal_handler_connector(
 		gpointer user_data)
 {
 	gint n;
-	signal entry_signals[] = {
+	signal_bk entry_signals[] = {
 		{ "activate",           (GCallback)on_any_entry_almost_any },
 		{ "backspace",          (GCallback)on_any_entry_almost_any },
 		{ "copy-clipboard",     (GCallback)on_any_entry_almost_any },
@@ -319,7 +319,7 @@ gtk_widget_signal_handler_connector(
 		gpointer user_data)
 {
 	variable *var;
-	signal widget_signals[] = {
+	signal_bk widget_signals[] = {
 		{ "accel-closures-changed",    (GCallback)on_any_widget_almost_any },
 		{ "composited-changed",        (GCallback)on_any_widget_almost_any },
 		{ "grab-focus",                (GCallback)on_any_widget_almost_any },
Interesting because the changes are meaningless as far as I can see -unless the name of the struct 'signal' was shadowing some other struct named signal. Anyway, congrats to Patriot for nicely coded and commented changes!

As things go, gtkdialog is fairly simple, so hopefully he and/or others may be able to add some useful functionality. I just wish the thing could be built against gtk-1.2 -I've ported some even more simple apps back to gtk-1.2, but this one is a bit beyond me.

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#150 Post by Patriot »

Hmmm .....

amigo,

Thanks for doing the diffs ... you beat me to it ... :)

If gtkdialog sources seems to be beyond you then imagine me feeling dizzy each time I do a trace for something in it ..... but I have to admit, it sure made scripts do nicer guis easier ...


Rgds

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

#151 Post by zigbert »

Patriot
:D :D :D

Invisible checkboxes.....mmmmm.....

What do you mean by flip-flops?

I think we need to include more info in the main post to explain what your fixed gtkdialog can do. I have here simplified a script to show open/close feature..... Do you think it is enough to explain....

Code: Select all

#!/bin/sh
# Requires the fixed gtkdialog3-pe1

export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
<vbox>
 <text><label>This is a launched window</label></text>
 <button><label>increase number</label>
  <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
  <action>refresh:TEXT</action>
 </button>
</vbox>'

export MAIN_DIALOG='
<vbox>
 <frame>
  <text width-chars="20" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
 </frame>
 <checkbox visible="false">
  <label>"OPENCLOSE"</label>
  <variable>OPENCLOSE</variable>
  <input>if [ "$OPENCLOSE" = "false" ]; then echo "true"; else echo "false"; fi</input>
  <action>if true launch:LAUNCHED_DIALOG</action>
  <action>if false closewindow:LAUNCHED_DIALOG</action>
 </checkbox>
 <button><label>"Open/Close"</label><action>refresh:OPENCLOSE</action></button>
 <button><label>Exit</label></button>
</vbox>'

echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG

Sigmund

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#152 Post by big_bass »

zigbert
What do you mean by flip-flops?
Hey zigbert
in electronics " flip flop" changes from one logic level to another

a changeable state
high to low or low to high
or 1 to 0 or 0 to 1
or yes to no or no to yes in a human readable format


thanks for the shortened code snippet

Joe

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

#153 Post by zigbert »

Joe
Ok, I see. I will write more tips for flip-flops. Both buttons and menus sound logical to me. Pmusic wants this..... :) Thanks for the explanation.

Here is the previous script even more simplified. Since checkbox is a flip-flop itself, we don't need to make make a flip-flop button.

Code: Select all

#!/bin/sh
# Requires the fixed gtkdialog3-pe1

export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
<vbox>
 <text><label>This is a launched window</label></text>
 <button><label>increase number</label>
  <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
  <action>refresh:TEXT</action>
 </button>
</vbox>'

export MAIN_DIALOG='
<vbox>
 <frame>
  <text width-chars="20" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
 </frame>
 <checkbox draw_indicator="false">
  <label>"Open/Close"</label>
  <variable>OPENCLOSE</variable>
  <action>if true launch:LAUNCHED_DIALOG</action>
  <action>if false closewindow:LAUNCHED_DIALOG</action>
 </checkbox>
 <button><label>Exit</label></button>
</vbox>'

echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG
Sigmund

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#154 Post by Patriot »

Hmmm .....

zigbert,

It's up to you which script to use for your examples. A shortened script is fine ...

Well, Joe's spot-on about the flip-flops ... Think of it like a light switch (on/off). I used the hidden checkboxes as flip-flops and link it to a button as per your original question. As I mentioned earlier, I didn't think of using checkboxes like this before ... I think that it's a nicer cosmetics using a button though (depending on the requirements) ...


Rgds

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

#155 Post by zigbert »

I have updated the main post
All credits go to Patriot !!!

#####################################

Flip-flops - make buttons/menus work like checkboxes
>> Flip-flops are swithes (variables) that are turned ON/OFF. - Just like a checkboxes. If you want to manage ON/OFF statements with buttons or menuitems, read on....

You might already have thought that it is possible to echo ON/OFF to a file, and then read content of file to determine if a button/menu should activate ON or OFF. Well, that will work, but not if you want to use the builtin gtkdialog commands enable/disable, launch/closewindow, refresh...

Gtkdialog does only support checkboxes as flip-flops, but the wonder is that they can be invisible. If we link a menu or button to the invisible checkbox, it all feels comfortable. Check the following example:

Code: Select all

#!/bin/sh

export MAIN_DIALOG='
<window title="Flip-Flop">
<vbox>
 <menubar>
  <menu>
   <menuitem icon="gtk-dialog-question">
    <label>Start/Stop clock</label>
    <action>refresh:STARTSTOP</action>
   </menuitem>
   <label>Clock</label>
  </menu>
 </menubar>
 <frame>
  <text><input>cat /tmp/text</input><variable>TEXT</variable></text>
  <entry>
   <variable>ENTRY</variable>
   <input>date +%H:%M:%S</input>
  </entry>
 </frame>
 <checkbox visible="false">
  <variable>STARTSTOP</variable>
  <default>true</default>
  <input>if [ "$STARTSTOP" = "false" ]; then echo "true"; else echo "false"; fi</input>
  <action>if true enable:ENTRY</action>
  <action>if true enable:TEXT</action>
  <action>if true echo 100 > /tmp/progress</action>
  <action>if true echo "I am ON" > /tmp/text</action>
  <action>if false disable:ENTRY</action>
  <action>if false disable:TEXT</action>
  <action>if false echo 0 > /tmp/progress</action>
  <action>if false echo "I am OFF" > /tmp/text</action>
  <action>refresh:TEXT</action>
 </checkbox>
 <progressbar>
   <variable>PROGRESS</variable>
   <input>while [ A = A ]; do sleep 0.5; P=`cat /tmp/percent`;   echo $P; cat /tmp/progress > /tmp/percent; done</input>
   <action>refresh:ENTRY</action>
   <action>echo 0 > /tmp/percent</action>
 </progressbar>
</vbox>
</window>'

echo 100 > /tmp/progress
echo 'I am OFF' > /tmp/text
gtkdialog3 -p MAIN_DIALOG


###################################################################################
7.) Gtkdialog - Patriot edition - More fun
###################################################################################

Download gtkdialog3-0.7.20-pe1-i486.pet (48kb)

Patriot has shipped a gtkdialog version that makes it possible to close launched dialog from main dialog. <action type="closewindow">LAUNCHED_DIALOG</action>

Example of use:

Code: Select all

#!/bin/sh
# Requires the fixed gtkdialog3-pe1

export LAUNCHED_DIALOG='
<variable>LAUNCHED_DIALOG</variable>
<vbox>
 <text><label>This is a launched window</label></text>
 <button><label>increase number</label>
  <action>A=$(cat /tmp/tmp); echo $(($A+1)) > /tmp/tmp</action>
  <action>refresh:TEXT</action>
 </button>
</vbox>'

export MAIN_DIALOG='
<vbox>
 <frame>
  <text width-chars="20" height-request="120"><variable>TEXT</variable><input>cat /tmp/tmp</input></text>
 </frame>
 <checkbox draw_indicator="false">
  <label>"Open/Close"</label>
  <variable>OPENCLOSE</variable>
  <action>if true launch:LAUNCHED_DIALOG</action>
  <action>if false closewindow:LAUNCHED_DIALOG</action>
 </checkbox>
 <button><label>Exit</label></button>
</vbox>'

echo 1 > /tmp/tmp
gtkdialog3 -p MAIN_DIALOG

Post Reply