24

Under ubuntu 16.04 I get the following message

 Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged

when I open zenity with the command

  zenity --text-info --filename=<filename>

This didn't happen under 14.04. I presume that the answer is related to this post but the post doesn't explain how to implement the proposed solution. Could somebody please explain which file I should add the suggested lines to?

You fix this warning by giving the GtkDialog a parent to be modal to. The relevant functions are gtk_window_set_transient_for() (which sets this window to always be on top of, or transient for, another one) and optionally gtk_window_set_modal() to make it a modal dialog. This is ultimately what the various GtkDialog constructors do.

5
  • zenity --help-general gives --attach=WINDOW Set the parent window to attach to but I'm not sure how to use it (what is Window?), perhaps it will solve your problem.
    – Al.G.
    Dec 27, 2016 at 10:55
  • Thanks, @Al.G. I was able to recover the WINDOW id with the line WINDOW_ID=$(xprop -name echo $TITLE` | grep WM_CLIENT_LEADER | cut -d"#" -f2 | cut -c2-20)` and I then tried zenity --attach=$WINDOW_ID --text-info --filename=<filename> but sadly I still got the warning. Too bad, but it may come in handy one day to know how to get the window id!
    – Leo Simon
    Dec 27, 2016 at 17:16
  • Actually if you search the source of zenity for gtk_window_set_transient_for you'll get no results.
    – Al.G.
    Dec 27, 2016 at 17:23
  • Yup. If you search for gtk_window_set_modal you get lots of results, but I don't know how to set it in a way that silences the message.
    – Leo Simon
    Dec 27, 2016 at 21:07
  • 1
    According to the docs you give it a window and a parent window. I suppose it should be called somewhere after the window creation with parent window set to NULL. However I couldn't make install zenity locally (I couldn't find docs or something on how to configure install) so I finaly gave up. Will have to use the dirty 2>/dev/null.
    – Al.G.
    Dec 27, 2016 at 22:19

4 Answers 4

26

Ignore it.

It's a warning, not an error. The application works, it's just not coded with best practices in mind, as it seems. You would have to modify zenity's source code to implement the fix described in your linked question and then compile it yourself, but... it works anyway, so why should you bother?

If you just want to get rid of the output in your terminal, you could simply redirect STDERR (standard error stream, that's where the warning gets printed to) to /dev/null (virtual character device that swallows data) by appending 2> /dev/null to the end of the command, like this:

zenity --text-info --filename=<filename> 2> /dev/null
4
  • 1
    Thanks! Unfortunately for some reason 2> /dev/null doesn't have the desired effect, the warning still persists. I know it's only a nuisance, but I would love to be able to suppress warnings like this.
    – Leo Simon
    Nov 1, 2016 at 20:11
  • 4
    I still think the people from zenity should fix this. Its very annoying. Jan 25, 2020 at 17:33
  • 3
    It clutters the output and makes it hard to notice new errors. Even worse, if we redirect stderr to /dev/null. Errors should be fixed, not covered. Jan 30, 2020 at 10:53
  • OMG!! I'm too late to this party!!! Works like a charm!!!! Besides it IS just warning not error and as long is not popping up on my dialogues I'm content! THAAAAANKS!!! Oct 26, 2022 at 9:40
11

It seems that the Gtk devs decided to add this warning which affects a number of packages. We just have to wait for the Zenity dev to catch up and fix Zenity.

With the bash shell (this is not Posix-compliant) it's relatively simple to suppress specific error messages while allowing other messages through to stderr:

zenity --info --text "hello" 2> >(grep -v 'GtkDialog' >&2)

This does not interfere with stdout, so that may be piped or used in command substitution as normal:

echo message: $(zenity --entry  2> >(grep -v 'GtkDialog' >&2) )
1
  • 1
    I just have to say, Dave: that's a pretty nifty use of redirection. Bravo.
    – Mike Diehn
    Jul 1, 2020 at 17:29
3

zenity ... 2>/dev/null works for me. The only problem I see is that other (important) errors messages will also be suppressed so better build error capture somehow in your code

1
  • 5
    Indeed, this looks like a dangerous solution. Better not use it. Aug 14, 2018 at 8:40
3

Building on Dave Rove's answer, if you have many prompts, you could clean this up by creating a function such as

function zenityNoWarn() {
    zenity "$@" 2> >(grep -v 'GtkDialog' >&2)
}

then use it like this:

zenityNoWarn --question --text "Are you sure?"

This makes things a little easier to read when combining with other logic:

if [[ `zenityNoWarn --question --text "Are you sure?"; echo $?` -eq 0 ]]; then
    echo "Yes!"
else
    echo "No..."
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .