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.

Leo Simon
  • 1,549

4 Answers4

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
Byte Commander
  • 110,243
12

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) )
Dave Rove
  • 301
4

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

splaisan
  • 153
  • 6