Page 1 of 1
Gtkdialog Examples
Posted: Mon Jan 16, 2023 10:35 pm
by don570
Gtkdialog Examples
Here is an example to show the placement of two buttons .....
right-side
center
left-side
![screenshot-button-example.png](./download/file.php?id=13485&sid=d000314a74df4419cb7a07c763da348b)
- screenshot-button-example.png (22.14 KiB) Viewed 2473 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
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
Re: Gtkdialog Examples
Posted: Tue Jan 17, 2023 7:24 am
by Sofiya
Re: Gtkdialog Examples
Posted: Tue Jan 17, 2023 7:47 pm
by don570
I like bash scripts so I can see any errors in the terminal
Re: Gtkdialog Examples
Posted: Wed Jan 18, 2023 12:18 am
by williwaw
try
# bash your_script_name
it does not need a shebang or even need to be executable
Re: Gtkdialog Examples
Posted: Fri Jan 20, 2023 10:57 pm
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
_____________________________________________
Re: Gtkdialog Examples
Posted: Sat Jan 21, 2023 12:00 am
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.
Re: Gtkdialog Examples
Posted: Sat Jan 21, 2023 2:50 am
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.
Re: Gtkdialog Examples
Posted: Sat Jan 21, 2023 9:46 pm
by don570
Re: Gtkdialog Examples
Posted: Sun Jan 22, 2023 4:22 pm
by glene77is
to DonWhite570
Main gtk window pops up OK.
Interesting second window technique, which 'returns' back inside the first gtk window.
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.
Interesting use of self-generated "svg" icon. cool !
.
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
===
Re: Gtkdialog Examples
Posted: Sun Jan 22, 2023 6:33 pm
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.
===
Re: Gtkdialog Examples
Posted: Sun Jan 22, 2023 9:16 pm
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.
Re: Gtkdialog Examples
Posted: Mon Jan 23, 2023 10:30 pm
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](./download/file.php?id=13662&sid=d000314a74df4419cb7a07c763da348b)
- screenshot-gtkdialog.png (26.79 KiB) Viewed 2318 times
Re: Gtkdialog Examples
Posted: Fri Jan 27, 2023 2:58 pm
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](https://i.postimg.cc/L597rsFg/Screenshot-6.jpg)
Re: Gtkdialog Examples
Posted: Fri Jan 27, 2023 3:49 pm
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.
Re: Gtkdialog Examples
Posted: Fri Jan 27, 2023 4:06 pm
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
Re: Gtkdialog Examples
Posted: Fri Jan 27, 2023 4:55 pm
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.
Re: Gtkdialog Examples
Posted: Fri Jan 27, 2023 4:59 pm
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.
Re: Gtkdialog Examples
Posted: Fri Jan 27, 2023 8:26 pm
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" ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 12:11 am
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" ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
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
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 2:11 am
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" ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
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
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 4:11 am
by MochiMoppel
rockedge wrote: ↑Fri Jan 27, 2023 3:49 pmI 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.
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 6:23 am
by rockedge
@MochiMoppel Using a SVG version of just the background is what I am intending.
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 8:42 am
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 42 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](./download/file.php?id=13773&sid=d000314a74df4419cb7a07c763da348b)
- 431-dark_new.jpg (8.51 KiB) Viewed 2441 times
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 2:15 pm
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
Re: Gtkdialog Examples
Posted: Sat Jan 28, 2023 9:42 pm
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)
Re: Gtkdialog Examples
Posted: Mon Feb 13, 2023 6:59 pm
by glene77is
to Don570
Thanks for the idea .
.
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](./download/file.php?id=14264&sid=d000314a74df4419cb7a07c763da348b)
- Double-Click Buttons and Embeded Graphics.sh screen shot
- CDW-DC_Txn_230212-1942-57-sh.JPEG (91.63 KiB) Viewed 2305 times
Re: Gtkdialog Examples
Posted: Tue Feb 14, 2023 10:09 pm
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.
____________________________________________-
Custom color buttons for Gtkdialog
Posted: Sat Feb 25, 2023 8:24 pm
by don570
I developed a system for creating custom color buttons for Gtkdialog.
Code writers are welcome to use it in scripts.
(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](./download/file.php?id=14514&sid=d000314a74df4419cb7a07c763da348b)
- xscreenshot-labels.png (27.12 KiB) Viewed 2207 times