-
Notifications
You must be signed in to change notification settings - Fork 80
Open new window inside callback and yield control to the new window #592
Comments
So I found a way to get what I want by setting the first window to insensitive when the second one is created. When the "destroy"-signal for the second window is triggered, the first window is made sensitive again. I also included a print callback to detect the sensitive -> insensitive switch (and the other way around) from a callback of the first window. The full code can be found below. If there is a more elegant way to achieve this, I'm always eager to learn, but for now this works for me. @tknopp @timholy : Do you think this is interesting enough to create a corresponding example file? If yes, I'm happy to fill in a PR. using Gtk
using Gtk.ShortNames
function create_first_window()
win = GtkWindow("First window", 400, 200)
b = GtkButton("Click to open second window")
push!(win,b)
signal_connect(cb_first_window, b, "clicked", Nothing, (), false, win)
showall(win)
signal_connect(cb_return_control, win, "state-flags-changed", Nothing, (), false, win)
# Wait with programm progression until the window is closed
c = Condition()
signal_connect(win, :destroy) do widget
notify(c)
end
@async Gtk.gtk_main()
wait(c)
end
@guarded (nothing) function cb_return_control(widget::Ptr, user_data)
win = convert(GtkWindow, widget)
# Get the state flags
sf = GAccessor.state_flags(win)
# Detect a "rising edge" of the sensitivity
if get_gtk_property(win, :sensitive, Bool) && sf == 192
println("Returning control to the first window")
# Detect a "falling edge" of the sensitivity
elseif sf == 200
println("Yielding control to the second window")
end
return nothing
end
@guarded (nothing) function cb_first_window(widget::Ptr, user_data)
create_second_window(user_data)
return nothing
end
function create_second_window(first_win)
win = GtkWindow("Second window", 400, 200)
b = GtkButton("Click to close this window")
push!(win,b)
showall(win)
id = signal_connect(b, "clicked") do widget, others...
destroy(win)
return nothing
end
# Deactive the caller window for the time being
set_gtk_property!(first_win, :sensitive, false)
# Reactivate the caller window when this window is destroyed
signal_connect(win, :destroy) do widget
set_gtk_property!(first_win, :sensitive, true)
end
end
create_first_window() |
I do not fully understand what you are aiming for here but isn't that what a |
Thank you very much for the hint regarding the |
In my point of view this scenario is much easier done with a If you have your custom dialog you can call it like this:
and here is how you implement
|
Hello,
I have the following question: I have a window with a button. When the button is clicked, another window opens. Now the new window should be active and the first window should wait until the second one has been closed. Also, it should be possible to create new tasks etc. in the second window while it is active. How do I achieve that?
Below you find a MWE which is almost working except for the detail that the second window doesn't "block" the first one:
The text was updated successfully, but these errors were encountered: