So I'd say something like this for setting the font name the same for GTK3 and GTK2 in every system: (for me it's "DejaVu Sans") SYSTEM_UI=$(fc-match system-ui | awk '/:/' | cut -d\" -f2) # get default font name
And in the stylesheet blocks e.g. font: 10pt "'$SYSTEM_UI'"; (GTK3) and font_name="'$SYSTEM_UI' Bold Italic 10" (GTK2)
I don't understand the purpose of this exercise.
Yes, not me either (on second thought, the next day ).
I was mistaken from my previous post .
In Bookwormpup
GTKDIALOGVERS is 3 not 2
___________________________________
I checked script in Easy OS Scarthgap 6.6.2
GTKDIALOGVERS is 2 but the script is still useful.
I wrote report.... viewtopic.php?p=146720#p146720
__________________________________________
Yes, not me either (on second thought, the next day ).
Never mind
Now that this thread reeled sufficiently off-topic it might be OK if I throw in some CSS variations. Instead of setting the background etc. for all text widgets or even the whole window, the following code sets the style for each text container individually. I prefer to use the box widget because it allows some room around the text. Works only for GTK3 (I'm too lazy to search for the appropriate parameters in GTK2).
#!/bin/sh
GTKDIALOG=gtkdialog
# uncomment this line to test with gtk2dialog (if exist)
#[ $(command -v gtk2dialog) ] && GTKDIALOG=gtk2dialog || exit 0
GTKDIALOGVERS=$($GTKDIALOG -v | grep -o "GTK+.*" | awk '{print $2}' | tr -d ,)
TEXTOPTS='visible="false" width-chars="49"'
TEXTVAR='<variable>VBOX</variable>'
TEXTSHOW='<action signal="map-event">show:VBOX</action>'
if [ "$GTKDIALOGVERS" = "3" ]; then # GTK3
# create stylesheet /tmp/gtkdialog-test
echo 'box * {
font: 10pt system-ui;
font-style: normal;
font-weight: normal;
padding: 0;
margin: 1px;
border-radius: 8px;
border-color: DarkViolet;
}
label {
/*color: lightgoldenrodyellow;*/
background-image: linear-gradient(to top right, blue 20%, #000000 80%);
}
button {
/* color: #000000; */
border-color: #cbd6ee;
border-radius: 40px;
padding-left: 5px;
padding-right: 5px;
background: linear-gradient(to bottom, #00acee, #0072e0);
}
button:hover {
transition: .4s;
box-shadow: 0 0 0 1px #cbd6ee;
}
button:focus{
outline: none;
}
' > /tmp/gtkdialog-test
else # GTK2
# create stylesheet /tmp/gtkdialog-test
echo 'style "gtkdialog-splash" { bg[NORMAL] = "#ffaa7f" } class "GtkWindow" style "gtkdialog-splash" style "notebook" { bg[NORMAL] = "#59290f" xthickness = 1 ythickness = 1 } class "GtkNotebook" style "notebook" style "font" { font_name="DejaVu Sans Bold Italic 11" text[NORMAL]="#ffc91c" fg[NORMAL]="#000000" } class "GtkLabel" style "font"
' > /tmp/gtkdialog-test
fi
export TEST='
<window title="Test size">
<vbox>
<vbox>
<text '$TEXTOPTS' align="0.5"><label>"Lorem ipsum Morbi erat ex, lacinia nec efficitur eget, sagittis ut orci. Etiam in dolor placerat, pharetra ligula et, bibendum neque. Vestibulum vitae congue lectus, sed ultricies augue. Nam iaculis elit nec velit luctus, vitae rutrum nunc imperdiet. Nunc vel turpis sit amet lectus pellentesque tincidunt. Proin commodo tincidunt enim, at sodales mi dictum ac. Maecenas molestie, metus quis malesuada dictum, leo erat egestas lacus, sit amet tristique urna magna a diam. Donec ultricies dui sit amet mi ornare egestas. Phasellus ultricies lectus non interdum pellentesque. Cras nisi tellus, feugiat sed enim quis, tristique interdum lacus. Sed vel pharetra arcu, ac fermentum neque. Morbi mollis sollicitudin varius. Ut sit amet vulputate velit.
Mauris semper neque quis lacinia volutpat. Aenean vestibulum diam ex, sit amet posuere dolor luctus non. Ut consectetur felis blandit ipsum convallis, non lobortis justo facilisis. Ut vitae velit pulvinar, pharetra libero semper, dignissim urna. Nullam quam quam, viverra eget feugiat a, interdum et erat. Morbi fringilla, eros et consequat iaculis, ligula nunc hendrerit neque, ac tincidunt massa sem vitae tortor. Nunc volutpat massa at dapibus pulvinar. Etiam risus sem, dignissim vel blandit eget, maximus lacinia purus.
"</label>'$TEXTVAR'</text>
</vbox>
<hbox>
<button ok>
<action>EXIT:ok</action>
</button>
</hbox>
</vbox>
'$TEXTSHOW'
</window>'
$GTKDIALOG -cp TEST --styles=/tmp/gtkdialog-test >/dev/null
Attachments
2025-04-13_03-46.png (140.12 KiB) Viewed 579 times
I think that I like the method from @MochiMoppel the most (without --geometry and with width-chars=..)
This may not always be the best solution. Especially when dealing with text of unknown length it is advisable to restrict the dimension to sensible values. Making the text scrollable will not only force gtkdialog and gtk2dialog to honor dimension settings, it will also avoid the need for the hacks we discussed (unless you see this as just another hack ).
Based on your original code here is a variant to play with. Using the <text> widget produces 2 same size windows, but the content format varies due to the different line wrap policies of GTK3 and GTK2. See also what happens when you run it without --dimension or with scrollable="false".
The content becomes identical when you replace <text> with <edit>. The <edit> widget seems more "stable" and provides a lot of formatting options and can be formatted to mimic a <text> widget. The only drawback is that it can't be pangofied.
I found a interesting effect with a button (see gif image)
using my work I published here
I made a modification to the script of Sofiya by changing the button to a SVG image.
I am using BookwormPup - ( gtkdialog not gtk2dialog ) viewtopic.php?p=146809#p146809