/usr/lib/gtkdialog/box_splash and animated gif icons?

Please post any bugs you have found
Message
Author
wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#41 Post by wiak »

Yeah, seems to be that any value for <width> or <height> other than -1 prevents gif animation (or of course leaving width and height values out altogether). I'm using the following simple test program (this is with gtkwialog, which accepts the preserve-aspect-ratio tag, which can of course be omitted if using gtkdialog instead).

Code: Select all

#! /bin/sh
# Needs test.gif image in script start directory

export MAIN_DIALOG='
<window>
  <vbox>
    <pixmap preserve-aspect-ratio="false">
      <variable>IMAGEN</variable>
      <height>300</height>
      <input file>./try.gif</input>
    </pixmap>
  </vbox>
</window>'
gtkwialog  -p MAIN_DIALOG
I haven't actually tried my new code yet and also a couple of other things I'll try. For example, there is a break statement in current gtkwialog and gtkwialog and gtkdialog4 code to load only one image into pixbuf (different code altogether in gtkdialog3 for pixbuf stuff - no such break); I will try removing that break in the gtkwialog pixbuf loading loop... - not sure how that effects animated gif type file (I don't know animated gif format, except number of images in the file, so suspicious if that break statement is the problem in gtkdialog4).

gtkdialog3 uses GtkImageMenuItem [EDIT: No - that's just for menu stock/icons] functions (deprecated), gtkwialog4 on the other hand uses straight GtkImage functions.

I'm just documenting these points here to remind me when I look into it further tomorrow.

wiak
Last edited by wiak on Mon 15 Oct 2018, 23:46, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#42 Post by MochiMoppel »

Here my proposal for a fixed box_splash.
IMO more fixed and efficient code is needed, but I tried to keep my changes to a minimum. Changes are marked in the code so they are easy to remove if you don't like them.

Animated GIFs support
This was the easiest part. Just changed ICON_WIDTH=32 to ICON_WIDTH=-1
By default icons are now displayed in their original size. Since the user is free to use the -icon_width option if resizing is required, a 32px default made no sense anyway.

Mouse cursor kills dialog
This bug drives me nuts as long as I can remember. It occurs when the mouse cursor happens to be at the same position as the opening dialog. Example: Mouse cursor near the center, box_splash (or gtkdialog-splash) opens with its default -placement (center) and -close (mouseover) options. In this case box_splash closes immediately before the user has a chance to read the message. Surely a "splash", but a useless one.
I tried to fix this idiotic behavior by adding a 150 ms grace period during which an exit is not possible. This gives the dialog the necessary time to load the image and "settle down" and prevents a phony premature "mouseover" event.

-deco
This option now works. A variable assignment was missing.

Always on top
This forces the message to pop up on top of any other window, e.g. a fullscreen youtube window. IMO should be standard for such info/alert dialogs. Note: This will not work when the -deco option is used (actually I've never seen it being used, so probably not a problem)
Attachments
box_splash_fixed.gz
This is a gzipped script and the extension is NOT a fake extension ;-)
(4.24 KiB) Downloaded 238 times

wiak
Posts: 2040
Joined: Tue 11 Dec 2007, 05:12
Location: not Bulgaria

#43 Post by wiak »

wiak wrote:My own assumption is that all will be fine if <width> is not used or set perhaps to -1 when animated gif the image
...
I'm saying that based on the C code in gtkdialog4 where, by default, width and height default to -1).
Okay, I've taken time to look at the pixmap code now and none of my previous thoughts are particularly relevant (except my quoted comment above).

It seems to me quite simply that in gtkdialog (any version) unscaled images can include animations whereas scaled images cannot.

In gtkdialog3 or in gtkdialog4 (where width and height are default -1), the GtkImage is created by the Gtk convenience function:

Code: Select all

gtk_image_new_from_file
which has result, according to Gtk docs:
If the file isn't found or can't be loaded, the resulting GtkImage will display a "broken image" icon. This function never returns NULL, it always returns a valid GtkImage widget.

If the file contains an animation, the image will contain an animation.
Scaled images are an enhancement of gtkdialog4 (identified by width and height not equal to default -1). For this capability, Gtk function gtk_image_new_from_file is not used since it does not include size/scaling capability built in. Rather, the image is first loaded into a pixbuf using a Gdk function:

Code: Select all

gdk_pixbuf_new_from_file_at_size
(the result is just a re-scaled pixbuf - no animation)

followed by creating the GtkImage from the pixbuf using Gtk function:

Code: Select all

gtk_image_new_from_pixbuf
So no animation capability for re-sized/scaled image.

So, as I said in earlier post, if you need animation with gtkdialog4, make sure width and height are set to -1 (or not set at all in which case they default to -1), which is value the gtkdialog4 code uses to determine whether or not to use animation-capable function gtk_image_new_from_file.

wiak

EDIT: This thread should really be in 'Programming' section since not actually any bug per se (well, I suppose box_splash wasn't able to animate gifs when expected, so a sort of a simple bug in that not using -1 for width for default case...). If the facility to scale gif animations was wanted, maybe it could be done by using gdk_pixbuf_animation_new_from_file, than maybe getting static frames from that (gdk_pixbuf_animation_get_static_image?) and scaling them and then iterating to next frame (gdk_pixbuf_animation_iter_advance???), each time creating a GtkImage of the frame using gtk_image_new_from_pixbuf. But I'm just guessing and clearly that is complicated. For example - the following library details seem relevant for those into doing this:

https://github.com/GNOME/gdk-pixbuf/blo ... led-anim.c

Also: https://github.com/GNOME/gdk-pixbuf/blo ... f-loader.c

Does anyone know an easy way in C/GTK+? Can be done in Python apparently, which internally may do something like I suggest. See the one Answer:

https://stackoverflow.com/questions/248 ... with-pygtk

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#44 Post by fredx181 »

MochiMoppel wrote:Here my proposal for a fixed box_splash.
....
....
Thanks for the fixes !

There's still one (small) thing that annoys me, it is that sometimes the dialog turns out much wider than intended.
For example when I use variable for $msg to get two lines, e.g.

Code: Select all

msg=`echo -e "Processing\nThis may take a while . . ."`
./box_splash_fixed -icon ./prefs.png -icon_width 48 -placement center -bg blue -fg white -text "$msg" -close never -timeout 5
See first pic.

I think a good "fix" would be changing line 183:

Code: Select all

#NR_CHARS="$((${#text}+1))"
# fredx181, commented out above, in case multiple lines, find the longest line for NR_CHARS
NR_CHARS="$(echo -e "$text" | awk '{ print length }' | sort -n | tail -1)"
See second pic, gives less width.

Fred
Attachments
more-width.png
Much wider than intended.
(12.51 KiB) Downloaded 298 times
less-width.png
Less width, used modified box_splash as described above
(11.26 KiB) Downloaded 300 times

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#45 Post by Argolance »

Bonjour,
fredx181 wrote:There's still one (small) thing that annoys me, it is that sometimes the dialog turns out much wider than intended
Sometimes very much more than intended to the point of filling almost the entire desktop (see picture at the beginning of this thread).
I'll add another small annoying thing: the icon is not centered horizontally (:arrow: reported in this thread).

[EDIT]: something else, just as a suggestion.
I wonder if it would not be interesting to disable automatic wraping to avoid words or expressions being cut in half (as shown in the images below) or allow to get the text in a single line. Both versions, the old and the new one have this defect.

Cordialement.
Attachments
181006_160413_442x62_easyshot.jpg
box_splash
(4.24 KiB) Downloaded 292 times
181006_144715_272x55_easyshot.jpg
&quot;Old&quot; gtkdialog-splash
(4.63 KiB) Downloaded 283 times

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#46 Post by MochiMoppel »

fredx181 wrote:There's still one (small) thing that annoys me, it is that sometimes the dialog turns out much wider than intended.
One of the small things I meant when I wrote "more fixed and efficient code is needed".
I wanted to fix the same line, but for a different reason.
As you can still see from the comments in the script, this line is a modified and more efficient version of

Code: Select all

NR_CHARS="`echo "$text" | wc -c`"
Of course this is wrong as echo without the -n option will add a linefeed character and a text containing 6 characters will have a character count of 7. Not a big deal, but with an image-only splash box, this will create an ugly. empty space at the right edge for 1 useless linefeed character.

The modified version attempts to produce the same (wrong) result. A case of bug emulation :lol:

Like you I also wondered why all characters and not just those of the longest line were counted but I didn't dig deeper. It seems that you are right and that different counting gives better results. Your code could be made shorter though. Instead of

Code: Select all

NR_CHARS="$(echo -e "$text" | awk '{ print length }' | sort -n | tail -1)"
the wc command can return the length of the longest line:

Code: Select all

NR_CHARS="$(echo "$text"| wc -L )"
(I removed the -e option to make it backward compatible
Argolance wrote:I'll add another small annoying thing: the icon is not centered horizontally
You mean vertically? That's intentional, I guess. A spacer is added below the icon to keep it in the upper left corner
I wonder if it would not be interesting to disable automatic wraping
Just do it! Set -wrap to "false" and see what happens :lol: Can have surprising and not always pleasant effects.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#47 Post by Argolance »

Bonjour,
MochiMoppel wrote:You mean vertically?
Yes I do! :?
That's intentional, I guess. A spacer is added below the icon to keep it in the upper left corner
Intentional, but still ugly. :)
Just do it! Set -wrap to "false" and see what happens :lol: Can have surprising and not always pleasant effects.
It is what I did with gtk-splash...
On the one hand, I only think that it can sometimes be useful to display a text on a single line and on the other hand, to put the line breaks exactly where you want them and no longer let the program put them a little randomly in the middle of a word or expression (please, see attached pictures).

Cordialement.
Attachments
181019_124247_400x68_easyshot.jpg
(7.33 KiB) Downloaded 533 times
181019_125138_373x68_easyshot.jpg
(7.34 KiB) Downloaded 533 times

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#48 Post by fredx181 »

Hi, here's attached modified box_splash_fixed

Changes:
- Find the longest line (if given multiple lines of text), more info here:
http://murga-linux.com/puppy/viewtopic. ... 81#1007581
- Center the icon vertically

@MochiMoppel

Code: Select all

NR_CHARS="$(echo "$text"| wc -L )"
Ok, thanks, works fine also

@Argolance, yes, I like it also when the icon is vertically centered.
To try making the icon display vertically centered, I first removed this line in the main dialog:

Code: Select all

<text space-expand="true" space-fill="true"><label>""</label></text>
That worked ok for the centered icon, but not when using only text (no icon).
So moved it to this section and works fine for me (with or without icon):

Code: Select all

 if [ "$ICON" ]; then
....
....
# fredx181, in case only text, no icon. Moved from the main dialog below to here
else
	icon="<text space-expand=\"true\" space-fill=\"true\"><label>\"\"</label></text>"
fi
Added comments with my name for the changes, but I'm not very good with that.

Fred
Attachments
box_splash_fixed_mod.tar.gz
Modified box_splash_fixed
(4.59 KiB) Downloaded 253 times
Last edited by fredx181 on Fri 19 Oct 2018, 15:04, edited 1 time in total.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#49 Post by Argolance »

Thanks fredx181, works fine for me. :D
Ultimately text attributes should be simply configurable in the same way as the font size and color...
Attachments
181019_135906_260x202_easyshot.jpg
gtk-splash
(5.97 KiB) Downloaded 514 times

ITSMERSH

#50 Post by ITSMERSH »

That seems to be funny, though, I think it doesn't make any sense to have angled text in a SPLASH info box. :wink:

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#51 Post by Argolance »

Bonjour,
ITSMERSH wrote:That seems to be funny, though, I think it doesn't make any sense to have angled text in a SPLASH info box.
... Totally agree with you, it was truly for fun, although it may be exceptionally useful! :roll:
As popular wisdom tells us: who can do the most can also do the least! :wink:

Cordialement.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#52 Post by fredx181 »

Hi, again about the icon centered vertically.
I found that if you give multiple lines of text, then the icon is still not centered.
(but depends on the size of the icon)
Fixed it by setting space-expand to true in the if [ "$ICON" ]; section:

Code: Select all

if [ "$ICON" ]; then
	icon="<pixmap width-request=\"$ICON_WIDTH\" space-expand=\"true\" space-fill=\"false\">
....
....
	*) icon="<pixmap width-request=\"$ICON_WIDTH\" space-expand=\"true\" space-fill=\"false\">
....
From what I tested it doesn't give unwanted side-effects.

Fred
Attachments
box_splash_fixed_mod.tar.gz
Small change to get the icon centered in all cases
(4.66 KiB) Downloaded 234 times

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#53 Post by Argolance »

Thanks!

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#54 Post by fredx181 »

Hi all, after more testing and experimenting (mostly focused on using multiple lines and icon fitting in display) I made some more changes.
When using "-placement -center" all is okay, but when using any other, e.g. top, bottom, bottom-right or top-right, the dialog showed too small (multiple lines and icon not fitting)
See first pic.
The second pic is with new attached box_splash_fixed_mod.

I've used it now in my new redshift-portable app:
http://murga-linux.com/puppy/viewtopic. ... 48#1009548

EDIT: Forgot to mention: Also added options info for -placement 'bottom-right' and 'top-right' to the help text.
(these are supported, but seems to be forgotten to add to usage help).

EDIT2 : I found that I made mistake, removed box_splash_fixed_mod attachment, get back about it later.
EDIT 2018-11-10 fixed mistake and added more calculations for setting the height correctly.
Tested lots of option combinations, should be pretty flexible now, may be a little slower because of more complex code.

Fred
Attachments
box_splash_fixed_mod-2018-11-10.tar.gz
2018-11-10 new box_splash_fixed_mod
(5.01 KiB) Downloaded 195 times
2018-11-09-154914_428x278_scrot.png
Mmmm... something's wrong... :)
(138.72 KiB) Downloaded 241 times
2018-11-09-155012_424x273_scrot.png
Multiple lines and icon correctly displayed
(116.57 KiB) Downloaded 241 times

Post Reply