Xdialog: here's how to create a color message

interpretive language scripts


Moderator: Forum moderators

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

Xdialog: here's how to create a color message

Post 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 2584 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 2584 times

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

User avatar
MochiMoppel
Posts: 1249
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 448 times

Re: Xdialog color message

Post 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 2554 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 2554 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 2539 times
User avatar
Sofiya
Posts: 2313
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1492 times
Been thanked: 1562 times

Re: Xdialog color message

Post by Sofiya »

in KLA-OT2 Arch works and so and so GTK3

Attachments
Снимок экрана(1).png
Снимок экрана(1).png (6.54 KiB) Viewed 2331 times
Снимок экрана.png
Снимок экрана.png (10.78 KiB) Viewed 2338 times
2023-07-22_750x422-thumb.png
2023-07-22_750x422-thumb.png (179.62 KiB) Viewed 2535 times
Last edited by Sofiya on Sat Jul 22, 2023 10:27 pm, edited 3 times in total.

KL-Linux
KL LINUX Simple fast free

jamesbond
Posts: 720
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 403 times

Re: Xdialog color message

Post 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.

dimkr
Posts: 2444
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1208 times

Re: Xdialog color message

Post by dimkr »

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

or VanillaPup.

10.0.21 (next Saturday) will include Xdialog 2.3.4 :)

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

Re: Xdialog color message

Post 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?

jamesbond
Posts: 720
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 403 times

Re: Xdialog color message

Post 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.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: Xdialog color message

Post 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

Last edited by rcrsn51 on Sat Jul 22, 2023 9:52 pm, edited 1 time in total.
User avatar
rockedge
Site Admin
Posts: 6636
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2828 times
Been thanked: 2693 times
Contact:

Re: Xdialog color message

Post 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.

User avatar
fredx181
Posts: 3149
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 383 times
Been thanked: 1341 times
Contact:

Re: Xdialog color message

Post 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 )

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

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

Post 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 2394 times
User avatar
fredx181
Posts: 3149
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 383 times
Been thanked: 1341 times
Contact:

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

Post by fredx181 »

Thanks.
And @jamesbond Thanks.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post 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.

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

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

Post by don570 »

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

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post 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.

Last edited by rcrsn51 on Sun Jul 23, 2023 2:08 am, edited 2 times in total.
jamesbond
Posts: 720
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 403 times

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

Post by jamesbond »

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

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post 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?

User avatar
MochiMoppel
Posts: 1249
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 448 times

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

Post 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 2275 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
jamesbond
Posts: 720
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 403 times

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

Post 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.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post by rcrsn51 »

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

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

User avatar
MochiMoppel
Posts: 1249
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 448 times

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

Post 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.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post 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.

User avatar
MochiMoppel
Posts: 1249
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 448 times

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

Post 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.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post 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.

dimkr
Posts: 2444
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1208 times

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

Post by dimkr »

The future is GTK+ 4 and beyond :)

User avatar
fredx181
Posts: 3149
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 383 times
Been thanked: 1341 times
Contact:

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

Post 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.

dimkr
Posts: 2444
Joined: Wed Dec 30, 2020 6:14 pm
Has thanked: 53 times
Been thanked: 1208 times

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

Post 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 :)

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

Gtk 5

Post 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/
___________________________________

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

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

Post 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.

Last edited by rcrsn51 on Tue Jul 25, 2023 12:57 pm, edited 2 times in total.
Post Reply

Return to “Scripts”