Gtkdialog Examples

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Gtkdialog Examples

Post by don570 »

Gtkdialog Examples

Here is an example to show the placement of two buttons .....

right-side
center
left-side

screenshot-button-example.png
screenshot-button-example.png (22.14 KiB) Viewed 2809 times

Notes:

1) I create some text for log window to launch at button click.
2) I create a SVG icon to be used by one button.
3) I make a second window (called log_window ) to be closed at same time as main window.
EDIT: To close both windows at the same time an extra button is needed

Code: Select all

<button cancel>  </button>

4) To control the width of window and also some vertical empty space I used ...

Code: Select all

<hbox width-request="300">
	<text height-request="10"><label>""</label></text>	
    </hbox> 

Here is script - It must be executable. Run it in terminal.

Code: Select all

#! /bin/bash

echo  "This is text"  > /tmp/example_text
echo ' <svg version="1.1" width="150" height="150" id="svg1">
    id="svg1854"
  
  <defs
     id="defs1856" />

     id="base" />
  <g
     id="g863"
     transform="matrix(2.548887,0.000000,0.000000,2.401153,-1219.592,-402.1428)"
     style="font-size:12;">
    <path
       fill="#333333"
       d="M516.791,176.799l-3.211,6.996c6.373,1.846,11.049,7.724,11.049,14.683    c0,8.435-6.861,15.296-15.294,15.296c-7.314,0-13.438-5.163-14.938-12.034l-7.119,3c2.729,9.624,11.559,16.682,22.057,16.682    c12.669,0,22.942-10.272,22.942-22.944C532.277,188.421,525.797,179.897,516.791,176.799z"
       id="path865" />
    <g
       id="g867">
      <path
         fill="#333333"
         d="M515.889,206.126c-0.555,0-1.111-0.211-1.539-0.633l-7.075-7.015h-16.514     c-1.207,0-2.185-0.978-2.185-2.185c0-1.207,0.978-2.185,2.185-2.185h18.313l8.354,8.281c0.857,0.85,0.863,2.233,0.014,3.091     C517.014,205.911,516.451,206.126,515.889,206.126L515.889,206.126z"
         id="path869" />
    </g>
  </g>
</svg>
' >  /root/baconrecorder.svg

#make a second window that closes at same time as main window
log_window='
	<window title="Example">
	
	<frame>
	
	<vbox>
	<hbox width-request="300">
	<text height-request="10"><label>""</label></text>	
    </hbox> 	
    </vbox>

<text>       <label>This is a static text.</label>
       <input file>"/tmp/example_text"</input>
</text>

     <hbox>
     <button>
      <label>"'$LOC303'"</label>
      <action function="closewindow">log_window</action>
    </button>    
    </hbox>
    
	 </frame>
	<variable>log_window</variable>
	</window>'	
export log_window




###############################################
#                                             #
#               M A I N   G U I               #
#                                             #
###############################################


 export DIALOG='<window title="Example">
  
  <vbox>
 <frame>   

	<text height-request="20"><label>""</label></text>	
   
   
    <hbox>  
 <hbox>
      <button tooltip-text="A record of the entries"><label>"Log"</label> 
         <input file stock="gtk-info"></input>
        <action>tail_function</action>
        <action function="launch">log_window</action>
     </button>   
       <button>
        <width>40</width>
        <height>30</height>
        <input file>"'/root/baconrecorder.svg'"</input>
         <label>"Start the alarm clock"</label> 
         <action type="exit">Exit by button</action>
      </button>
  </hbox>    
</hbox>   
     
   
   
  <hbox>  
 <hbox>
      <button tooltip-text="A record of the entries"><label>"Log"</label> 
         <input file stock="gtk-info"></input>
        <action>tail_function</action>
        <action function="launch">log_window</action>
     </button>   
       <button>
        <width>40</width>
        <height>30</height>
        <input file>"'/root/baconrecorder.svg'"</input>
         <label>"Start the alarm clock"</label> 
         <action type="exit">Exit by button</action>
      </button>
  </hbox>    
       <text space-expand="true" space-fill="true">
            <label>""</label> 
       </text> 
</hbox>   
    
 <hbox homogeneous="true">  
 <hbox>
      <button tooltip-text="A record of the entries is here."><label>"Log"</label> 
         <input file stock="gtk-info"></input>
        <action function="launch">log_window</action>
     </button>   
       <button>
        <width>40</width>
        <height>30</height>
        <input file>"'/root/baconrecorder.svg'"</input>
         <label>"Start the alarm clock"</label> 
         <action type="exit">Exit by button</action>
      </button>
  </hbox>    
       <text space-expand="true" space-fill="true">
            <label>""</label> 
       </text> 
</hbox>
	<text height-request="20"><label>""</label></text>
 </frame>
 
 </vbox>
  </window>
'
     I=$IFS; IFS=""
     for STATEMENTS in  $(gtkdialog --program=DIALOG); do
       eval $STATEMENTS        
     done
     

   

Last edited by don570 on Tue Jan 17, 2023 7:50 pm, edited 2 times in total.
User avatar
Sofiya
Posts: 2283
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1477 times
Been thanked: 1531 times

Re: Gtkdialog Examples

Post by Sofiya »

in #! /bin/bash skip

KL
PUPPY LINUX Simple fast free

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: Gtkdialog Examples

Post by don570 »

I like bash scripts so I can see any errors in the terminal

williwaw
Posts: 1957
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 370 times

Re: Gtkdialog Examples

Post by williwaw »

try
# bash your_script_name

it does not need a shebang or even need to be executable

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: Gtkdialog Examples

Post by don570 »

I checked in fatdog linux.

When there is no shebang
Case 1 : sh extension ---> Clicking will open the gtkdialog example
Case 2 : no extension ---> viewnior opens with blank window
_____________________________________________

williwaw
Posts: 1957
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 370 times

Re: Gtkdialog Examples

Post by williwaw »

don570 wrote: Fri Jan 20, 2023 10:57 pm

I checked in fatdog linux.

When there is no shebang
Case 1 : sh extension ---> Clicking will open the gtkdialog example
Case 2 : no extension ---> viewnior opens with blank window
_____________________________________________

i did notice an anomoly when the shebang was removed, that the os sees the file with as a .svg when there is no extension on the filename.

I think that is something to do with the content of the first few lines, but it doesn't seem to affect the operation of the script itself.

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 439 times

Re: Gtkdialog Examples

Post by MochiMoppel »

don570 wrote: Fri Jan 20, 2023 10:57 pm

I checked in fatdog linux.

When there is no shebang
Case 1 : sh extension ---> Clicking will open the gtkdialog example
Case 2 : no extension ---> viewnior opens with blank window
_____________________________________________

And did you check what happens when there is a shebang?
Judging from your code I expect that exactly the same happens.

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: Gtkdialog Examples

Post by don570 »

User avatar
glene77is
Posts: 62
Joined: Thu Aug 13, 2020 7:44 pm
Location: Univ of TN, Memphis,TN,USA
Has thanked: 49 times
Been thanked: 7 times
Contact:

Re: Gtkdialog Examples

Post by glene77is »

to DonWhite570
Main gtk window pops up OK.

Interesting second window technique, which 'returns' back inside the first gtk window. :thumbup:
I am aware of limits to this 'self-referencing' approach in gtkdialog, as a simple limitation of gtkdialog binary code.
So, I always use an old fashioned method from the 80's (where I come from) with Korn shell (ha!).:
I use a 'fall-thru' method to some "if [ $EXIT = "XXX" ] ; then "
and then write standard subroutine calls to "function()" at top of code
and always return/restore to window via a "restart" call to "${0}".
I like the tried-n-sure method, as one of my projects was 8K lines,
and I do not like chasing a little bash bug all day long.

to: Don,
So cool to read an imaginative gtk window code. Thanks. :thumbup2:
Interesting use of self-generated "svg" icon. cool !
:thumbup2: .
I like your 'self-contained' icon approach.
Your code formatting is very good/readable.

I set-up this "gtk example" , per instructions.
Your 'shebang' format is slightly different from the format I have been using. Mine has "!/bin/bash" .
However, I have noticed, over the years, that "rc.sysinit" and "rc.shutdown" and other system scripts
have alternated between "!/bin/sh" and "!bin/bash".
I have found an 'alias' statement, equating 'sh' and 'bash' , which should throw all interpretations to the 'bash' code in this OS.

Your code:
geany xterm with "! /bin/bash" : results "sh: line 1: tail_function: command not found"
geany xterm with "!/bin/bash" : results "sh: line 1: tail_function: command not found"
Tried the alternative 'shebang' format on one of my other scripts, and all worked ok.

So, I wonder about the error flag "sh: line 1: tail_function: command not found" sent back by xterm.
I will look into this small problem with the little pop-up windows.
BTW, I use uPupJammy , mainly,
#(: 2.36 Ubuntu 22.04 LTS (Jammy Jellyfish) iso_JammyPup32-22.04+8_22123-0700

===

*Just an old Apprentice caught Tinkering in the Master's WorkShop. *
Glen Ellis ( ͡° ͜ʖ ͡° ) K4KKQ , Electronic Engineering :ugeek:
Website: http://www.GeoCities.WS/glene77is :thumbup2:
Electrical Science , Memphis, TN

User avatar
glene77is
Posts: 62
Joined: Thu Aug 13, 2020 7:44 pm
Location: Univ of TN, Memphis,TN,USA
Has thanked: 49 times
Been thanked: 7 times
Contact:

Re: Gtkdialog Examples

Post by glene77is »

to don570

don570 wrote: Tue Jan 17, 2023 7:47 pm

I like bash scripts so I can see any errors in the terminal

Also a reason I use xterm on everything. ( Not as good as the IDE tools I used for many years. )
However, I have had bash errors that could not be found via "set -x -e"
and I spent hours chasing some little bash bug.
I have always wished for easy single stepping, with system results/errors splashed into a second window.
===

*Just an old Apprentice caught Tinkering in the Master's WorkShop. *
Glen Ellis ( ͡° ͜ʖ ͡° ) K4KKQ , Electronic Engineering :ugeek:
Website: http://www.GeoCities.WS/glene77is :thumbup2:
Electrical Science , Memphis, TN

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: Gtkdialog Examples

Post by step »

glene77is wrote:

I have always wished for easy single stepping, with system results/errors splashed into a second window.

Do you know

. Does single stepping and breakpoints but no second window I think.

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: Gtkdialog Examples

Post by don570 »

I change width and height just for the middle row
from...

Code: Select all

  <width>40</width>
        <height>30</height>

to ...

Code: Select all

  <width>70</width>
        <height>70</height>

I noticed that the entire row takes on bigger height.
The other rows stay the same as expected.

screenshot-gtkdialog.png
screenshot-gtkdialog.png (26.79 KiB) Viewed 2664 times
geo_c
Posts: 2881
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2205 times
Been thanked: 878 times

Re: Gtkdialog Examples

Post by geo_c »

I modified @MochiMoppel's desktop clock script to display a text window. I did it for the purpose of displaying the distro name which can be moved around. It does the job but the only drawback is the background color of the window is set by the current gtk theme and so it looks a little primitive if the background doesn't blend well. My searches for how to set gtk window colors all look complicated beyond my comprehension at this point.

Here's the script:

Code: Select all

#!/bin/sh
function make_me_pretty {
	printf "<span font='book 24'><b><i>KLV-airedale</i></b></span>"
};export -f make_me_pretty

echo '<window decorated="false" border-width="0">
<text use-markup="true">
  <input>make_me_pretty</input>
</text>
</window>'|gtkdialog -sG +1655+960

At the bottom right corner:
Image

geo_c
Old School Hipster, and Such

User avatar
rockedge
Site Admin
Posts: 6551
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2757 times
Been thanked: 2627 times
Contact:

Re: Gtkdialog Examples

Post by rockedge »

so the current background color needs to be identified and that value used by the script?

I am playing around with it and setting up the background in a similar way with the transparent Airedale silhouette. Looks great and will be a candidate for the default wallpaper/background and for it's minimal system impact.

User avatar
Sofiya
Posts: 2283
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1477 times
Been thanked: 1531 times

Re: Gtkdialog Examples

Post by Sofiya »

geo_c wrote: Fri Jan 27, 2023 2:58 pm

I modified @MochiMoppel's desktop clock script to display a text window. I did it for the purpose of displaying the distro name which can be moved around. It does the job but the only drawback is the background color of the window is set by the current gtk theme and so it looks a little primitive if the background doesn't blend well. My searches for how to set gtk window colors all look complicated beyond my comprehension at this point.

so that the color of the text can be changed

Code: Select all

#!/bin/sh
function make_me_pretty {
	printf "<span font='book 24' color='blue'><b><i>KLV-airedale</i></b></span>"
};export -f make_me_pretty

echo '<window decorated="false" border-width="0">
<text use-markup="true">
  <input>make_me_pretty</input>
</text>
</window>'|gtkdialog -sG +1550+960
Attachments
Screenshot.png
Screenshot.png (3.68 KiB) Viewed 2585 times

KL
PUPPY LINUX Simple fast free

geo_c
Posts: 2881
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2205 times
Been thanked: 878 times

Re: Gtkdialog Examples

Post by geo_c »

Sofiya wrote: Fri Jan 27, 2023 4:06 pm

so that the color of the text can be changed

Code: Select all

#!/bin/sh
function make_me_pretty {
	printf "<span font='book 24' color='blue'><b><i>KLV-airedale</i></b></span>"
};export -f make_me_pretty

echo '<window decorated="false" border-width="0">
<text use-markup="true">
  <input>make_me_pretty</input>
</text>
</window>'|gtkdialog -sG +1550+960

Oh man! I fooled around with that basic concept for a couple hours. What I was doing wrong was putting another tag <color='blue'> inside the <span> tag.

geo_c
Old School Hipster, and Such

geo_c
Posts: 2881
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2205 times
Been thanked: 878 times

Re: Gtkdialog Examples

Post by geo_c »

rockedge wrote: Fri Jan 27, 2023 3:49 pm

so the current background color needs to be identified and that value used by the script?

I am playing around with it and setting up the background in a similar way with the transparent Airedale silhouette. Looks great and will be a candidate for the default wallpaper/background and for it's minimal system impact.

If it could be made to read the desktop background color (or make the window background transparent), that would be amazing. Sounds complicated.

I like the simplicity of having the logo text and jpg graphic separate from the background and each other. It gives a lot of versatility in placement and color configuration by only adding one png and one script.

geo_c
Old School Hipster, and Such

User avatar
Sofiya
Posts: 2283
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1477 times
Been thanked: 1531 times

Re: Gtkdialog Examples

Post by Sofiya »

geo_c wrote: Fri Jan 27, 2023 4:59 pm
rockedge wrote: Fri Jan 27, 2023 3:49 pm

so the current background color needs to be identified and that value used by the script?

I am playing around with it and setting up the background in a similar way with the transparent Airedale silhouette. Looks great and will be a candidate for the default wallpaper/background and for it's minimal system impact.

If it could be made to read the desktop background color (or make the window background transparent), that would be amazing. Sounds complicated.

I like the simplicity of having the logo text and jpg graphic separate from the background and each other. It gives a lot of versatility in placement and color configuration by only adding one png and one script.

I understand your idea, the script in C ++ most likely should be written, I'm not strong in "C" :D

KL
PUPPY LINUX Simple fast free

geo_c
Posts: 2881
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2205 times
Been thanked: 878 times

Re: Gtkdialog Examples

Post by geo_c »

Sofiya wrote: Fri Jan 27, 2023 8:26 pm

I understand your idea, the script is in C ++, I'm not strong in "C" :D

The KLV sclock script is a binary in C++, but this gtk dialog shell script isn't. Maybe it should be though. If it the C++ sclock program was modified to prompt a text input instead of the time function, I would imagine it to work. Any text could be displayed on the desktop. Sclock can be passed parameters to change text colors. I have an sclock start script located in /root/startup that looks like this:

Code: Select all

root# cat sclock-start
sClock --font=22 --color=lightblue --keep-above --stick

geo_c
Old School Hipster, and Such

User avatar
Sofiya
Posts: 2283
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1477 times
Been thanked: 1531 times

Re: Gtkdialog Examples

Post by Sofiya »

geo_c wrote: Sat Jan 28, 2023 12:11 am
Sofiya wrote: Fri Jan 27, 2023 8:26 pm

I understand your idea, the script is in C ++, I'm not strong in "C" :D

Code: Select all

root# cat sclock-start
sClock --font=22 --color=lightblue --keep-above --stick

transparent background in sclock, cairo was most likely used there

KL
PUPPY LINUX Simple fast free

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 439 times

Re: Gtkdialog Examples

Post by MochiMoppel »

rockedge wrote: Fri Jan 27, 2023 3:49 pm

I am playing around with it and setting up the background in a similar way with the transparent Airedale silhouette. Looks great and will be a candidate for the default wallpaper/background and for it's minimal system impact.

This has not minimal system impact. IMHO this is a waste of process resources. If I understand correctly that what you and @geo_c are trying to do is put a gtkdialog or whatever window on top of the pinboard to permanently show some static text.
Commonly Puppy wallpapers have the distro name somewhere imprinted.
If this is a SVG wallpaper, and there are many, this would not only be a very efficient way to display a big image, this would also mean that (colored) text could be added/changed any time at any position. Could be done with a relatively simple script.

User avatar
rockedge
Site Admin
Posts: 6551
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2757 times
Been thanked: 2627 times
Contact:

Re: Gtkdialog Examples

Post by rockedge »

@MochiMoppel Using a SVG version of just the background is what I am intending.

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 439 times

Re: Gtkdialog Examples

Post by MochiMoppel »

@rockedge I played with the image file /usr/share/backgrounds/431-dark.svg, found in your Fossa96-radky.
Most of the SVG files have the text portion neatly added at the end, after <!-- text --> comment.

I changed the <text> tag manually to

Code: Select all

<text style="fill:white;stroke:none;" font-family="sans" font-style="italic" font-weight="bold" font-size="38" x="70%" y="90%">Your text here</text>

, resulting in the image shown in the screenshot. Could certainly be made even fancier.

431-dark.svg.gz
This is the original SVG file, gzipped
(1.4 KiB) Downloaded 50 times

TIP: ROX-Filer can use gzipped SVG files directly as wallpaper. Just gzip any SVG file and give it a .svgz extension. This will reduce the SVG filesize considerably. (I gave the attachment a .svg.gz extension to make unzipping easier. Change to .svgz to make it digestible for ROX)

431-dark_new.jpg
431-dark_new.jpg (8.51 KiB) Viewed 2792 times
geo_c
Posts: 2881
Joined: Fri Jul 31, 2020 3:37 am
Has thanked: 2205 times
Been thanked: 878 times

Re: Gtkdialog Examples

Post by geo_c »

So as not to hi-jack this topic, I'm continuing the .svg bacground image discussion here:
https://forum.puppylinux.com/viewtopic. ... 804#p79804

geo_c
Old School Hipster, and Such

User avatar
rockedge
Site Admin
Posts: 6551
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2757 times
Been thanked: 2627 times
Contact:

Re: Gtkdialog Examples

Post by rockedge »

@MochiMoppel playing around with the information you supplied:

Screenshot(11).jpg

going to set up the background directory with tip in mind.

TIP: ROX-Filer can use gzipped SVG files directly as wallpaper. Just gzip any SVG file and give it a .svgz extension. This will reduce the SVG filesize considerably. (I gave the attachment a .svg.gz extension to make unzipping easier. Change to .svgz to make it digestible for ROX)

User avatar
glene77is
Posts: 62
Joined: Thu Aug 13, 2020 7:44 pm
Location: Univ of TN, Memphis,TN,USA
Has thanked: 49 times
Been thanked: 7 times
Contact:

Re: Gtkdialog Examples

Post by glene77is »

to Don570

Thanks for the idea . :thumbup2: .
I have been tinkering with your script, and came up with the attached script.

Run this via Xterm to watch the workings.

# rc.z_CDW-DoubleClick.sh
# Example of gtkdialog application menu
# Example of Embedded Graphics
# Example of Quit Double-Click button
#
# graphics are gleaned from Linux:
# source: .svg and .xpm are (1) copied as text, (2) modified as text by hand.
# embedded graphics function this way: (1) installed in app, (2) echoed out by app, (3) imported by app gui <button> .

Double-Click Buttons and Embeded Graphics.sh  screen shot
Double-Click Buttons and Embeded Graphics.sh screen shot
CDW-DC_Txn_230212-1942-57-sh.JPEG (91.63 KiB) Viewed 2656 times
Attachments
CDW-DC_Txn_230212-1942-57-sh.zip
Double-Click Buttons and Embeded Graphics.sh executable
(2.73 KiB) Downloaded 65 times

*Just an old Apprentice caught Tinkering in the Master's WorkShop. *
Glen Ellis ( ͡° ͜ʖ ͡° ) K4KKQ , Electronic Engineering :ugeek:
Website: http://www.GeoCities.WS/glene77is :thumbup2:
Electrical Science , Memphis, TN

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: Gtkdialog Examples

Post by don570 »

I didn't know that double click of a button was possible.
Thanks for example.
Zigbert has some recommendations and tips --->
https://oldforum.puppylinux.com/viewtop ... =gtkdialog

Examples: double clicking on list
or double clicking on a thumbnail image will launch image viewer.
____________________________________________-

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Custom color buttons for Gtkdialog

Post by don570 »

I developed a system for creating custom color buttons for Gtkdialog.
Code writers are welcome to use it in scripts.

test-labels.sh.gz
fake gz extension
(4.07 KiB) Downloaded 48 times

(fake gz extension)

Notes: SVG images are stored in /tmp
You can open them with an image editor such as mtpaint.
Colors are the standard ones that SVG recognizes.
A color can have a prefix 'light' or 'dark' . Example ---> lightblue
Width of the button is automatically calculated from label text.

Instructions: Click on 'Proceed' button and then the 'Return' button.

The finished project is still available from old Puppy forum
https://oldforum.puppylinux.com/viewtop ... 41#p760041

Reference:
https://blogs.czapski.id.au/tag/gtkdialog-color

______________________________________________

xscreenshot-labels.png
xscreenshot-labels.png (27.12 KiB) Viewed 2558 times
Post Reply

Return to “Programming”