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

#946 Post by don570 »

Note to mister_electronico..

If you're learning gtkdialog then I recommend
reading my togglebutton example page. Very neat 8)

http://208.109.22.214/puppy/viewtopic.p ... f714757e5a
_____________________________________________

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Hi don570

#947 Post by mister_electronico »

Hi don570, I like you post like other you did, but I ddn't find the relationship with my two last post.

See you.



______________________________________________________________________
My blog

https://misterelectronicoes.wordpress.com/
Last edited by mister_electronico on Sun 08 Feb 2015, 19:02, edited 1 time in total.

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Display meter-panel.

#948 Post by mister_electronico »

I always look for a display to display data from my electronic circuits, so that I did this program gtkdialog, I think I can be useful and other people.... I hope so

The program would look like.



______________________________________________________________________
My blog

https://misterelectronicoes.wordpress.com/
Attachments
meter_panel.png
(40.24 KiB) Downloaded 1069 times
Last edited by mister_electronico on Sun 08 Feb 2015, 19:03, edited 1 time in total.

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

The program

#949 Post by mister_electronico »

This program can accommodate the needs that we have.

Greetings




______________________________________________________________________
My blog

https://misterelectronicoes.wordpress.com/
Attachments
meter.tar.gz
(62.31 KiB) Downloaded 358 times
Last edited by mister_electronico on Sun 08 Feb 2015, 19:03, edited 1 time in total.

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

Mobile sign

#950 Post by mister_electronico »

One mobile sign:

Code: Select all

#!/bin/bash
[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

export DAT=/dev/shm/var1
echo "800" > $DAT


# Letro movil
funcion1 () {
VAR=( `cat $DAT` )
echo '<svg width="800" height="150" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<text x="'$VAR'" y="46" xml:space="preserve" style="font-family:monospace;font-size:64px;" font-weight="bold" fill="#7F0D0D" opacity="0.8">MOBILE SIGN WORKING</text>
</svg>' > /dev/shm/var2.svg

  VAR=`echo "$VAR - 10" | bc -l`
  echo ${VAR} > $DAT
  NUM=${VAR%%} 
  if [ $NUM -lt -720 ]; then  echo "800" > $DAT; else deci=0; fi      
}  
export -f funcion1

export MAIN='
<window title="Mobile sign" resizable="false">
  <vbox>
    <pixmap>
      <variable>IMG</variable>
      <input file>/dev/shm/var2.svg</input>
    </pixmap>
    <button ok></button>
    <timer visible="false" milliseconds="true" interval="100">
      <action>funcion1</action>
      <action type="refresh">IMG</action>
    </timer>
  </vbox>
</window>
'

case $1 in
	-d | --dump) echo "$MAIN" ;;
	*) $GTKDIALOG -cp MAIN ;;
esac
unset mobile_sign
unset funcion1
killall -9 mobile_sign.sh
Greetings


______________________________________________________________________
My blog

https://misterelectronicoes.wordpress.com/
Last edited by mister_electronico on Sun 08 Feb 2015, 19:03, edited 1 time in total.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

<notebook> tabs height?

#951 Post by Argolance »

Hello,
Is there a way to fix the notebook tabs height when they are right or left of a window to make them entirely fill it? Something like:

Code: Select all

<notebook tab-height=\"xx\"...</notebook>
??
Thank you!
Cordialement.
Attachments
140918_165227_756x494_easyshot.jpg
(38.96 KiB) Downloaded 930 times

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

#952 Post by don570 »

To Argolance..

The space-expand and space-fill set to true are the only way I know how to
change where widgets appear. I got the info from Thunor

Code: Select all

A text widget that has space-expand and space-fill set to true can be used as a spacer to push neighbouring widgets in certain directions.

Here the spacer text is "[]" so you can see it -- drag the window out and watch the button.
	
#!/bin/sh

GTKDIALOG=gtkdialog

Spacer="[]"

MAIN_DIALOG='
<window title="Spacer Test" window-position="1">
   <vbox>
      <hbox>
         <button space-expand="false" space-fill="false">
            <label>This button will stay put</label>
            <input file stock="gtk-about"></input>
         </button>
         <text space-expand="true" space-fill="true">
            <label>"'$Spacer'"</label>
         </text>
      </hbox>
   </vbox>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac	

Regards,
Thunor
__________________________________________

Looking at the info on the notebook widget it says that it supports
space-expand and space-fill but I'm not sure what part of notebook
widget is affected.



gtkdialog wrote: #summary notebook widget reference

= notebook widget =

A [http://developer.gnome.org/gtk2/2.24/GtkNotebook.html GtkNotebook]

----

== Definition ==

{{{
<notebook tag_attr="value"...>
widget...
<variable>varname</variable>
<input>command</input>
<input file>filename</input>
<sensitive>state</sensitive>
<action signal="type">activity</action>...
<output file>filename</output>
</notebook>
}}}

"..." denotes acceptance of multiples of the same thing.

== Tag Attributes ==

See the [http://developer.gnome.org/gtk2/2.24/Gt ... -hierarchy GtkNotebook] widget and ancestor class properties.

The following custom tag attributes are available:

<wiki:comment>ExportTableStart</wiki:comment>
|| *Name* || *Description* || *Value* || *Since* ||
|| space-expand || Pack widget expanding into space || {{{true}}} or {{{false}}} || 0.7.21 ||
|| space-fill || Pack widget filling space || {{{true}}} or {{{false}}} || 0.7.21 ||
|| block-function-signals || Block signal emissions from functions || {{{true}}} or {{{false}}} || 0.7.21 ||
|| file-monitor || Emit signal when input file(s) change || {{{true}}} or {{{false}}} || 0.8.1 ||
|| auto-refresh || Auto refresh when input file(s) change || {{{true}}} or {{{false}}} || 0.8.1 ||
|| tab-base-index || Tab label start page number || Integer || 0.7.21 ||
|| tab-labels || Tab labels || _label0_ {{{|}}} _label1_ {{{|}}} ... || 0.7.21 ||
|| tab-prefix || Tab label prefix || || 0.7.21 ||
|| tab-suffix || Tab label suffix || || 0.7.21 ||
<wiki:comment>ExportTableEnd</wiki:comment>

== Directives ==

Some of these may have tag attribute equivalents.

<wiki:comment>ExportTableStart</wiki:comment>
|| *Name* || *Description* || *Contents* || *Since* ||
|| variable || Variable name || || 0.7.21 ||
|| variable export="false" || Variable name, not exported to shell || || 0.8.3 ||
|| input^[1]^ || Data input source || Shell command || 0.7.21 ||
|| input file^[1]^ || Data input source || Filename || 0.7.21 ||
|| sensitive || Sensitive state || {{{true}}} or {{{false}}} || 0.7.21 ||
|| action signal="_type_" || Execute command on signal || Shell command || ||
|| action signal="_type_" || Perform function on signal || _function_:_parameter_ || ||
|| action signal="_type_" condition="_type_" || Execute command on signal conditionally || Shell command || 0.8.3 ||
|| action signal="_type_" condition="_type_" || Perform function on signal conditionally || _function_:_parameter_ || 0.8.3 ||
|| output file || Data output target || Filename || 0.7.21 ||
<wiki:comment>ExportTableEnd</wiki:comment>

== Signals ==

There is no default signal for this widget.

The "file-changed" signal is emitted if file-monitor is true and the input file being monitored has changed.

The following signals are connected-up for all widgets:

[http://developer.gnome.org/gtk2/2.24/Gt ... ress-event button-press-event], [http://developer.gnome.org/gtk2/2.24/Gt ... ease-event button-release-event], [http://developer.gnome.org/gtk2/2.24/Gt ... gure-event configure-event], [http://developer.gnome.org/gtk2/2.24/Gt ... tify-event enter-notify-event], [http://developer.gnome.org/gtk2/2.24/Gt ... tify-event leave-notify-event], [http://developer.gnome.org/gtk2/2.24/Gt ... s-in-event focus-in-event], [http://developer.gnome.org/gtk2/2.24/Gt ... -out-event focus-out-event], [http://developer.gnome.org/gtk2/2.24/Gt ... idget-hide hide], [http://developer.gnome.org/gtk2/2.24/Gt ... idget-show show], [http://developer.gnome.org/gtk2/2.24/Gt ... et-realize realize], [http://developer.gnome.org/gtk2/2.24/Gt ... ress-event key-press-event], [http://developer.gnome.org/gtk2/2.24/Gt ... ease-event key-release-event], [http://developer.gnome.org/gtk2/2.24/Gt ... -map-event map-event], [http://developer.gnome.org/gtk2/2.24/Gt ... nmap-event unmap-event]

== Functions ==

The following functions can be performed upon this widget by any widget capable of emitting signals:

<wiki:comment>ExportTableStart</wiki:comment>
|| *Type* || *Description* || *Parameter* || *Since* ||
|| enable || Sensitise widget || Variable name || ||
|| disable || Desensitise widget || Variable name || ||
|| show || Show widget || Variable name || 0.8.1 ||
|| hide || Hide widget || Variable name || 0.8.1 ||
|| grabfocus || Grab input focus || Variable name || 0.8.1 ||
|| refresh || Reload input data || Variable name || 0.7.21 ||
|| save || Save widget data || Variable name || 0.7.21 ||
<wiki:comment>ExportTableEnd</wiki:comment>

The following general functions can be performed by any widget capable of emitting signals:

<wiki:comment>ExportTableStart</wiki:comment>
|| *Type* || *Description* || *Parameter* || *Since* ||
|| break || Break out of actions list || None || 0.8.3 ||
|| command || Execute command || Shell command || ||
|| exit || Exit dialog || A value for the {{{EXIT}}} variable || ||
|| closewindow || Close dialog || Variable name || ||
|| launch || Launch dialog || Variable name || ||
|| presentwindow || [http://developer.gnome.org/gtk2/2.24/Gt ... ow-present Present] dialog || Variable name || 0.8.1 ||
<wiki:comment>ExportTableEnd</wiki:comment>

== Conditions ==

The following conditions can be used within the condition attribute of action directives:

<wiki:comment>ExportTableStart</wiki:comment>
|| *Type* || *Description* || *Argument* || *Since* ||
|| active_is_true(_argument_) || Active state of toggle widget || Variable name || 0.8.3 ||
|| active_is_false(_argument_) || Active state of toggle widget || Variable name || 0.8.3 ||
|| command_is_true(_argument_) || Output of shell command || Shell command || 0.8.3 ||
|| command_is_false(_argument_) || Output of shell command || Shell command || 0.8.3 ||
|| file_is_true(_argument_) || Contents of a file || Filename || 0.8.3 ||
|| file_is_false(_argument_) || Contents of a file || Filename || 0.8.3 ||
|| sensitive_is_true(_argument_) || Sensitive state of widget || Variable name || 0.8.3 ||
|| sensitive_is_false(_argument_) || Sensitive state of widget || Variable name || 0.8.3 ||
|| visible_is_true(_argument_) || Visible state of widget || Variable name || 0.8.3 ||
|| visible_is_false(_argument_) || Visible state of widget || Variable name || 0.8.3 ||
<wiki:comment>ExportTableEnd</wiki:comment>

true means "true", "yes" or a non-zero value, false means "false", "no" or zero, therefore the shell command is expected to echo one of these values to stdout.

== Notes ==

1. This widget does not accept setting a default page before being shown (there's a note about it [http://developer.gnome.org/gtk2/2.24/Gt ... rrent-page here]) which will result in input data being discarded at start-up. This issue can be overcome by using the "[http://developer.gnome.org/gtk2/2.24/Gt ... book--page page]" tag attribute which will be applied after the widget is shown.


User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#953 Post by Argolance »

Hello don570,
Sorry, I didn't see your message before (though I asked to be notified when a reply is posted).
Thanks a lot (#summary notebook widget reference very interesting indeed!)
Looking at the info on the notebook widget it says that it supports
space-expand and space-fill but I'm not sure what part of notebook
widget is affected.
All the same... :(

Cordialement.

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

#954 Post by don570 »

Can the frame heading be color?? I guess not, however here is a replacement technique.

Normally widgets flow from right side of a hbox to left side, but Thunor found
a method to modify this behaviour.
Just fill with empty text on right side with this widget....
<text space-expand="true" space-fill="true">

then use

<text space-expand="false">

for the left side of window.

Code: Select all

#!/bin/sh

export MAIN_DIALOG='<window title="Examples" icon-name="gtk-info" resizable="false">

<vbox width-request="200">
    <hbox>
        <text space-expand="false"  use-markup="true"><label>"<u><span size='"'large'"' color='"'red'"'>Heading</span></u>"</label></text>   
        <text space-expand="true" space-fill="true"><label>""</label> </text> 
    </hbox>
    <edit editable="false">
			<variable>EDITOR</variable>
			<height>150</height>
			<width>350</width>
			<default>
"This is the default 
text of the editor."
			</default>
		</edit>
</vbox> 

</window>
'

gtkdialog --program=MAIN_DIALOG


Image
Last edited by don570 on Sat 18 Oct 2014, 19:54, edited 2 times in total.

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

#955 Post by don570 »

This script will change the color of text according to gtk theme.
Certain theme names will trigger the change. Blue turns to orange.

Code: Select all

#!/bin/sh
export COLOUR=3272C0
[ "`egrep "Stardust_dark_mouse|Stardust_dark_touch|Azenis|TerraNova-Aquarius|terminus|Murrina-Black|DarkRoomCompact|PenOSmaster" /root/.gtkrc-2.0`"  ] && COLOUR=FFD900

 export MAIN_DIALOG='
<window title="Example"  window-position="1">
 <vbox>
<text use-markup="true"><label>"<b><span size='"'x-large'"'>p</span><span size='"'x-large'"' color='"'#$COLOUR'"'>Archive</span></b>"</label></text>
</vbox>
</window>' 
 
 gtkdialog -p MAIN_DIALOG 
 
Image

User avatar
trio
Posts: 2076
Joined: Sun 21 Dec 2008, 15:50
Location: अनà¥￾मोदना

#956 Post by trio »

Sigmund,
Override JWM-settings - skip taskbar, sticky, layer, border
This is how to override default settings in your JWM configuration.

Your gtkdialog gui must be called with the --class parameter
Code:
gtkdialog --class=APPLET -f myfile
Then this code must be in your jwm configuration file - $HOME/.jwmrc (to be set permanently, it must be added to /etc/xdg/templates/_root_.jwmrc)
Code:
<Group>
<Class>APPLET</Class>
<Option>nolist</Option>
<Option>sticky</Option>
<Option>noborder</Option>
<Option>layer:12</Option>
</Group>
I tried <window skip-taskbar-hint="true"> and it works.

Regards,

Trio

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

#957 Post by don570 »

Example: Make a destination folder choice so it shows next time the app is run

When the user clicks a button (Save in the example below)
the choice is saved in a secret place

Code: Select all

<action>echo  "$SAVEFOLDER" >  $WORKDIR/destination</action>
Image

Code: Select all

#!/bin/sh
# example to define a destination folder

mkdir -p /root/.config/example
export WORKDIR=/root/.config/example #  export is needed for input directive

[ ! -e  $WORKDIR/destination ]  && echo "/root" > $WORKDIR/destination # set initial

export EXAMPLE='<window>
<vbox width-request="390">
  <frame Destination Folder>
  
              <hbox>
                   <entry accept="directory"  tooltip-text="Choose Directory to save your data">
                   <input>cat $WORKDIR/destination</input>                    
                   <variable>SAVEFOLDER</variable>                   
                   </entry>
                                                      
                   <button tooltip-text="Choose Directory to save your data">
                   <input file stock="gtk-directory"></input>
                   <action type="fileselect">SAVEFOLDER</action>                                                        
                  </button>
              </hbox>
              <hbox>
                   <button use-stock="true" label="gtk-save"> 
                   <action>gxmessage My save folder is now  $SAVEFOLDER</action>                  
                   <action>echo  "$SAVEFOLDER" >  $WORKDIR/destination</action>                                                        
                  </button>
               </hbox>
                  
                     
    </frame>
</vbox>
</window>'
gtkdialog -c --program=EXAMPLE

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

#958 Post by MochiMoppel »

Variation of above example: When the user clicks the Save button, the choice is saved in the script itself. No need to write to /root/.config

Code: Select all

#!/bin/sh

DESTINATION=/root
export SCRIPTPATH="$0"

function  save_folder { sed -i "s|^DESTINATION=.*$|DESTINATION=\"$SAVEFOLDER\"|" "$SCRIPTPATH";} 
export -f save_folder

 export EXAMPLE='<window> 
 <vbox width-request="390"> 
   <frame Destination Folder> 
   
               <hbox> 
                    <entry accept="directory"  tooltip-text="Choose Directory to save your data"> 
                    <default>'$DESTINATION'</default>                    
                    <variable>SAVEFOLDER</variable>                    
                    </entry> 
                                                       
                    <button tooltip-text="Choose Directory to save your data"> 
                    <input file stock="gtk-directory"></input> 
                    <action type="fileselect">SAVEFOLDER</action>                                                        
                   </button> 
               </hbox> 
               <hbox> 
                    <button use-stock="true" label="gtk-save"> 
                    <action>gxmessage My save folder is now  $SAVEFOLDER</action>                  
                    <action>save_folder</action>                                                        
                   </button> 
                </hbox> 
     </frame> 
 </vbox> 
 </window>' 
 gtkdialog -c --program=EXAMPLE

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

#959 Post by don570 »

I think there is a situation that I didn't perceive when writing my script.
i.e. if the file 'destination' exists but somehow the folder has disappeared
I should have a default folder to open when first launching.

Code: Select all

[ ! -d  $WORKDIR/destination ]  && echo "/root" > $WORKDIR/destination

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

#960 Post by MochiMoppel »

don570 wrote:I think there is a situation that I didn't perceive when writing my script.
i.e. if the file 'destination' exists but somehow the folder has disappeared
??? The way you wrote your script the folder and the file is created at each start of the script. How could the folder "disappear" and the file it contains still exist? And how does your new code fit into the original file? The test [ ! -d $WORKDIR/destination ] is always true since a folder $WORKDIR/destination is never created and therefore never exists.
I should have a default folder to open when first launching.
What was wrong with your script? You had that already. It would be even better if the script uses a default path hard coded in the script and creates $WORKDIR/destination only if this default path was actually changed by the user. This way the system keeps clean as long as possible. If the user shortly tests the script and decides not to keep it, no zombie config files are left.

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

#961 Post by don570 »

Here is the way I tested my script.

1) I created a folder in /root called test

2) I ran the script so that the destination folder is /root/test

3) I trashed the folder

4) I ran the script again. I saw that the initial folder choice is /root/test
which may cause confusion. That is why I suggested that there be a
test of the existence of the destination folder
(Note that the file 'destination' holds the folder name including path)

Code: Select all

[ ! -d  $WORKDIR/destination ]  && echo "/root" > $WORKDIR/destination 
______________________________________________________

Your script is very clever. I never thought of doing it that way however
profession programmers prefer to modify configuration files
in case a write-to-disk operation is faulty. With your script the script would be damaged
and the entire app would have to be installed again.

_____________________________________________________

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

#962 Post by don570 »

OOps wrong :oops: I need to read the file with cat command

Code: Select all

[ ! -d  $(cat $WORKDIR/destination) ]  && echo "/root" > $WORKDIR/destination
___________________________________________________

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

#963 Post by don570 »

I came across this Trusty Tahr version of gtkdialog

https://launchpad.net/~geinux/+archive/ ... 4_i386.deb

__________________________________________________

inops
Posts: 1
Joined: Fri 02 Jan 2015, 23:22

#964 Post by inops »

Hi guys.

Any idea how I could get the "X" button in the top right of a window to a run a function, i.e. a confirmation of closing?

I know you can do this:

Code: Select all

for STATEMENTS in  $(gtkdialog --program DIALOG); do
  eval $STATEMENTS
done
if [ "$EXIT" = "abort" ]; then
  echo "You entered: $ENTRY."
fi
but I want the GUI to stay while this is asked, to allow the user to go back to it if they click "no" on "Are you sure you want to close".

Thanks, Inops.

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

#965 Post by don570 »

Any idea how I could get the "X" button in the top right of a window to a run a function
The only app that leaves Xwindows is Zigbert's ptiming
There's a button that the user clicks to leave X windows and put
up a digital clock. I think the user can come back to X windows???

I made an interesting app that doesn't leave X windows.
You might study it. I was learning how to use the togglebutton widget.
http://www.murga-linux.com/puppy/viewtopic.php?t=92152
http://murga-linux.com/puppy/viewtopic.php?t=91989
http://murga-linux.com/puppy/viewtopic. ... 690#756690

Post Reply