3

I can have a script that calls a window, but when I try to raise a dialogue with parent = None, I get:

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

What parent can I map this this to? It seems I can map it to a dummy parent, but will this cause things to break and people to die?


Code from http://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html#messagedialog where it is called from a parent window... but I want to be able to pop this up as I'm running through a terminal script.

Edit: Some poking around (and also provide by an answer below) yielded that using Gtk.Window() as the first argument below (instead of none) does get rid of the message...

def on_question():
    dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.QUESTION,
        Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")
    dialog.format_secondary_text(
        "And this is the secondary text that explains things.")
    response = dialog.run()
    if response == Gtk.ResponseType.YES:
        print("QUESTION dialog closed by clicking YES button")
    elif response == Gtk.ResponseType.NO:
        print("QUESTION dialog closed by clicking NO button")

    dialog.destroy()
Trees4theForest
  • 1,267
  • 2
  • 18
  • 48
  • Possible duplicate of [GtkDialog mapped without a transient parent](http://stackoverflow.com/questions/29883211/gtkdialog-mapped-without-a-transient-parent) – Aran-Fey Jul 16 '16 at 04:33
  • Possible -- but that asker has a window to set it the child of. I don't. Maybe it's a misuse of the GtkMessagDialog class -- it just seemed much tighter than building windows that do the same thing... – Trees4theForest Jul 16 '16 at 04:37
  • if you put print(dialog.get_parent()) before dialog.destroy(), a „None” will be printed. Not any None, but the one that you passed as parent. The first „None” in the constructor is the parent of dialog – cox Jul 16 '16 at 05:12
  • @cox - copy that -- but it's expecting an argument for parent -- and in this case I don't have one. I'm calling ti straight from a script running in the terminal -- mostly cause they are convenient, and I can't make a regular window look as good :O – Trees4theForest Jul 16 '16 at 05:26

1 Answers1

3

I will made the above comment an answer. You may have a w = Gtk.Window() somewhere in your code (it may be inside function body) and pass that w to on_question:

def on_question(parent=None):
    dialog = Gtk.MessageDialog(parent, 0, Gtk.MessageType.QUESTION,
        Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")
....
w = Gtk.Window()
on_question(w)

or

def on_question():
    dialog = Gtk.MessageDialog(Gtk.Window(), 0, Gtk.MessageType.QUESTION,
        Gtk.ButtonsType.YES_NO, "This is an QUESTION MessageDialog")

The Gtk-message it's gone, if that is the only problem.

cox
  • 731
  • 5
  • 12
  • I just came here to post that I found that solution out myself just now. It no longer throws an error... Is this BAD PRACTICE? – Trees4theForest Jul 16 '16 at 05:42
  • 1
    I hope my comment did help. And no, when you find solution by yourself, it is a sign of goooood and long „practice”! – cox Jul 16 '16 at 05:47
  • Ha! I guess I meant, is using a dummy parent window bad code ;) – Trees4theForest Jul 16 '16 at 05:50
  • You will use some extra RAM, but nothing to worry. It will be destroyed at first GC call. And from a script(from terminal), you won't abuse this function – cox Jul 16 '16 at 06:01