Page 1 of 2

Xdialog: here's how to create a color message

Posted: Fri Jul 21, 2023 8:36 pm
by don570

A simple way to create a color message is to use Xdialog
This is explained at the website supporting Xdialog
http://xdialog.free.fr/doc/common.html#RCFILE

The example they give is

Code: Select all

 Xdialog --rc-file bluebox.rc --msgbox "--rc-file demonstration." 0 0

bluebox.rc file contents:

Code: Select all

        style 'blue_background' {
                bg[NORMAL] = { 0.0, 0.3, 0.8 }
                fg[NORMAL] = { 1.0, 1.0, 1.0 }
        }
        widget '*' style 'blue_background'

The result is blue background and white text.

rcfile.png
rcfile.png (4.28 KiB) Viewed 3072 times

________________________________________________

Here is a more detailed example based on what I used in baconrecorder...
I gave the path to find the rc file as /root/.config/pclock/yellowbox.rc
So this file must exist!!! Hide it somewhere in /root.

Code: Select all

  Xdialog --title "$(gettext 'Recording')"  --rc-file /root/.config/pclock/yellowbox.rc  --wrap --left  --center  --ok-label "$(gettext 'Close')" --msgbox "\n$(gettext 'You are ready to make a new recording.')\n$(gettext 'Enter new settings.')\n"    0 0 100  &

Here is the contents of the rc-file

Code: Select all

style 'yellow_background' {
                bg[NORMAL] = { 0.99, 0.99, 0.50 }
                fg[NORMAL] = { 0, 0, 0 }
}
widget '*' style 'yellow_background'

The result is yellow background and black text.

screenshot-warning.png
screenshot-warning.png (13.61 KiB) Viewed 3072 times

For more examples look at the script for baconrecorder or ptmtimer
baconrecorder download
ptmtimer download


Re: Xdialog color message

Posted: Sat Jul 22, 2023 2:07 am
by MochiMoppel
don570 wrote: Fri Jul 21, 2023 8:36 pm

The result is yellow background and black text.

Maybe not.
Apparently doesn't work in GTK3 environments like in Bookworm64 or VanillaPup. Also default dimensions differ in GTK2 and GTK3. Don't know if a GTK3 compliant stylesheet would help.

XdialogGTK3.png
XdialogGTK3.png (10.17 KiB) Viewed 3042 times



If it has to be a colored message dialog then IMHO gxmessage is a better and much simpler choice. No extra files required.

Code: Select all

gxmessage -title "$(gettext 'Recording')" -bg yellow -wrap -center -button "$(gettext 'Close')" -default "$(gettext 'Close')"   "
	$(gettext 'You are ready to make a new recording.')
	$(gettext 'Enter new settings.')
"
gxdialogGTK3.png
gxdialogGTK3.png (10.01 KiB) Viewed 3042 times



Using more options can make the result even prettier, here without borders (window decorations):

Code: Select all

gxmessage -bo -fn "bold 14" -bg \#900 -fg white -c -but "$(gettext 'Close')" -de "$(gettext 'Close')"   "
	$(gettext 'You are ready to make a new recording.')
	$(gettext 'Enter new settings.')
"
gxdialogGTK3_borderless.png
gxdialogGTK3_borderless.png (13.67 KiB) Viewed 3027 times

Re: Xdialog color message

Posted: Sat Jul 22, 2023 5:01 am
by Sofiya

in KLA-OT2 Arch works and so and so GTK3


Re: Xdialog color message

Posted: Sat Jul 22, 2023 8:43 am
by jamesbond

Xdialog maintainer here.

MochiMoppel wrote: Sat Jul 22, 2023 2:07 am

Apparently doesn't work in GTK3 environments like in Bookworm64 or VanillaPup.

You are right it doesn't. That's one of the last item I've put off the table during Xdialog's migration to GTK3. I have now implemented it in version 2.3.4, you'll just need to wait until it gets included in the next Puppy builds.

Code: Select all

window {
background-color: #0000ff;
color: #ffffff;
}

Xdialog --rc-file bluebox.css --msgbox "test" 0 0
should work by then for version 2.3.4.

Or you can of course, use the GTK2 version of Xdialog.


Re: Xdialog color message

Posted: Sat Jul 22, 2023 10:23 am
by dimkr
MochiMoppel wrote: Sat Jul 22, 2023 2:07 am

or VanillaPup.

10.0.21 (next Saturday) will include Xdialog 2.3.4 :)


Re: Xdialog color message

Posted: Sat Jul 22, 2023 11:26 am
by step

@jamesbond, for backward compatibility wouldn't it be better to add a new option --style-file file.css, ignored in GTK2 builds, similarly ignoring --rc-file in GTK3 builds?


Re: Xdialog color message

Posted: Sat Jul 22, 2023 1:13 pm
by jamesbond

@step, I did consider that, however, I was under the impression that Xdialog will blow up if we pass ian unknown option to it. So that's why I stuck using the same --rc-file for both GTK2 and GTK3. But I just tested, it in fact does not do that, so passing an unknown option is safe (and is ignored). I will modify Xdialog and good thing dimkr doesn't rush to build it yet :)

Updated 2.3.4 coming along, be back shortly ...

EDIT: 2.3.4 is re-released. Please compile ahead. When compiled with GTK2, it will support --rc-file and ignore --style-file. When built with GTK3, --style-file and ignore --rc-file, so you can specify both options for both versions and whichever one sticks will be used.

For forward compatibility, I have also added --feature-check.


Re: Xdialog color message

Posted: Sat Jul 22, 2023 3:09 pm
by rcrsn51

@jamesbond: Is there a "git clone" command for downloading this? That's the only way I know how to get sources from github.

Edit: found the tarball


Re: Xdialog color message

Posted: Sat Jul 22, 2023 5:07 pm
by rockedge

@rcrsn51 There should be a download option for a zip file of the source on the main code page on the top right of the page.


Re: Xdialog color message

Posted: Sat Jul 22, 2023 5:44 pm
by fredx181
rockedge wrote: Sat Jul 22, 2023 5:07 pm

@rcrsn51 There should be a download option for a zip file of the source on the main code page on the top right of the page.

And which page is that ? (or is it top-secret ? :D )


Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 7:59 pm
by rockedge

@fredx181 Here is the github page (I think) -> https://github.com/wdlkmpx/Xdialog

Screenshot(8).jpg
Screenshot(8).jpg (36.9 KiB) Viewed 2882 times

Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 8:19 pm
by rcrsn51

Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 8:24 pm
by fredx181

Thanks.
And @jamesbond Thanks.


Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 8:32 pm
by rcrsn51

OK. I logged in as anonymous and found the tarball.

[Update] It compiled easily against gtk3 and works in some quick tests.

But the numbers that define the size of a box work differently, especially "0 0".

They would need to be recoded. It might be better to switch them to the "WxH" format.


Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 10:06 pm
by don570

Have those size numbers ever worked??
In puppy linux users leave the numbers as 0 0
and the code does the magic.
_________________________________


Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 10:16 pm
by rcrsn51

Have those size numbers ever worked??

In the gtk2 version, "0 0" auto-sizes the box to fit the stuff inside. But you can explicitly set the size with other numbers. The Xdialog help explains how.

In the gtk3 version, "0 0" creates a much larger box. You can control the size with "width x height" in pixels.


Re: Xdialog: here's how to create a color message

Posted: Sat Jul 22, 2023 11:07 pm
by jamesbond

You can also find them here: https://github.com/puppylinux-woof-CE/Xdialog
Might be easier for someone who prefers git/github.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 2:11 am
by rcrsn51
jamesbond wrote: Sat Jul 22, 2023 11:07 pm

Might be easier for someone who prefers git/github.

Thanks. It is a great relief to see that Xdialog will survive into gtk3.

Is there any chance that the "0 0" issue can be resolved?


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 3:00 am
by MochiMoppel

Regarding the size issue I noticed that Xdialog in GTK3 specifies a minimum size of 176x80, and the window manager honors it, so the following settings have the same result. 1px windows are not possible anymore.

Code: Select all

Xdialog -y A 1 1        #GTK2:7x14 GTK3:176x80 
Xdialog -y A 1x1        #GTK2:1x1  GTK3:176x80
Xdialog -y A 176x80     #GTK2/GTK3:     176x80
XdialogGTK3minimum.png
XdialogGTK3minimum.png (5 KiB) Viewed 2763 times

In GTK2 there is no window minimum size specified. Could it be that in GTK3 values like '0 0' or '0x0' are interpreted by the window manager as invalid values, resulting in this strange default (?) of 206x206?

Code: Select all

Xdialog -y A 0 0        #GTK2:176x67 GTK3:206x206 
Xdialog -y A 0x0        #GTK2:176x67 GTK3:206x206 
Xdialog -y A x          #GTK2:176x67 GTK3:206x206
Xdialog -y A 206x206    #GTK2/GTK3:       206x206

Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 4:06 am
by jamesbond

The problem is GTK3 doesn't autoshrink windows to fit content by default, like GTK2 did.

Please try the following, and especially, see if there is any **bad** unforeseen side effects. I remember I already tried this before and I remember I had problems with it, although I couldn't recall what exactly was the problem. But I maybe wrong. If it really works well I'll merge it.

Code: Select all

diff -ur Xdialog-orig/src/interface.c Xdialog/src/interface.c
--- Xdialog-orig/src/interface.c	2023-07-22 17:00:02.712644132 +1000
+++ Xdialog/src/interface.c	2023-07-23 13:57:13.024231904 +1000
@@ -221,6 +221,13 @@
 						    Xdialog.xsize*xmult,
 						    Xdialog.ysize*ymult);
 	}
+#ifdef USE_GTK3
+	else
+	{
+		// GTK3 does not auto-shrink, so we do it ourselvs, to simulate GTK2 behaviour
+		gtk_window_set_default_size(GTK_WINDOW(Xdialog.window), 1, 1);
+	}		
+#endif
 
 	/* Allow the window to grow, shrink and auto-shrink */
 	gtk_window_set_resizable(GTK_WINDOW(Xdialog.window), TRUE);

Though personally, I like the GTK3 version (without autoshrink) better, as it is more attention-grabbing as a dialog should. I always find that the GTK2's version cramped window is a bit underwhelming.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 5:32 am
by rcrsn51

If I replace "0 0" with "100x50", it appears to auto-size.

If you prefer a bigger message box, increase the numbers.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 5:49 am
by MochiMoppel
rcrsn51 wrote: Sun Jul 23, 2023 5:32 am

If I replace "0 0" with "100x50", it appears to auto-size.

Yes, in GTK3 auto-expands to 176x80 (or larger, depending on contents), but not in GTK2.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 6:25 am
by rcrsn51
MochiMoppel wrote: Sun Jul 23, 2023 5:49 am

Yes, in GTK3 auto-expands to 176x80 (or larger, depending on contents).

This is good. If I have a gtkdialog app with lots of Xdialog pop-up messages, I just need a global search-and-replace of "0 0" to "100x50".

This should convert the app to gtk3.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 6:48 am
by MochiMoppel
rcrsn51 wrote: Sun Jul 23, 2023 6:25 am
MochiMoppel wrote: Sun Jul 23, 2023 5:49 am

Yes, in GTK3 auto-expands to 176x80 (or larger, depending on contents).

This is good. If I have a gtkdialog app with lots of Xdialog pop-up messages, I just need a global search-and-replace of "0 0" to "100x50".

This should convert the app to gtk3.

But then they become unusable in GTK2. Characters would be unreadable because 50 is an insufficient height, apart from the fact that text exceeding a few characters would be truncated.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 9:44 am
by rcrsn51
MochiMoppel wrote: Sun Jul 23, 2023 6:48 am

But then they become unusable in GTK2. Characters would be unreadable because 50 is an insufficient height, apart from the fact that text exceeding a few characters would be truncated.

My objective is to make a SECOND version of the app that works in an all-gtk3 platform. That's the future.

If someone is still using a gtk2 platform, they can get the gtk2 version from that platform's repo.


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 12:34 pm
by dimkr

The future is GTK+ 4 and beyond :)


Re: Xdialog: here's how to create a color message

Posted: Sun Jul 23, 2023 6:43 pm
by fredx181
dimkr wrote: Sun Jul 23, 2023 12:34 pm

The future is GTK+ 4 and beyond :)

So.. it seems I'm always behind, just learned a bit how to modify gtkdialog/Xdialog scripts for GTK3, then must learn for GTK4, but... then GTK5... GTK6..., it's becoming disheartening altogether.
I'm would vote trying to keep full support for GTK2 (and GTK3 too, ok), easy to say for me though , but: question: does anyone think that can be possible ? (e.g. for supporting the existence of typical Puppy programs e.g. using gtkdialog, Xdialog or yad in scripts).
Needs energy and time to focus on that, but perhaps worth it (not only going with the flow of "new is often better") and I think it's not realistic to expect that all contributors want to follow all the changes everytime.

Just some thoughts.


Re: Xdialog: here's how to create a color message

Posted: Mon Jul 24, 2023 6:49 am
by dimkr
fredx181 wrote: Sun Jul 23, 2023 6:43 pm

follow all the changes everytime

Correct me if I'm wrong, but GTK+ 4.0 was released 9 years after GTK+ 3.0, which was released 9 years after GTK+ 2.0.

I think a decade is enough to fix a small bunch of scripts :)


Gtk 5

Posted: Mon Jul 24, 2023 7:35 pm
by don570

Gtk 5 might drop X11 support, says GNOME dev
Linux's Wayland-only future takes a tentative step closer
One of the GNOME developers has suggested that the next major release of Gtk could drop support for the X window system.

https://www.theregister.com/2022/07/05/ ... _drop_x11/
___________________________________


Re: Xdialog: here's how to create a color message

Posted: Tue Jul 25, 2023 11:48 am
by rcrsn51

@jamesbond I cannot get the --default-item option to work with a menubox widget in the new gtk3 Xdialog.

This is not a big problem - I replaced the menubox with a radiolist.

All my other conversions are going well.

In places where I have used "height width" numbers other than "0 0" , I just replace them with pixel values like "600x400".

Thanks.