-
Notifications
You must be signed in to change notification settings - Fork 80
Set cursor on Glade-based GUI #587
Comments
It seems that
is wrong. In the linked code this was used to extract the window from the canvas. In your example you are directly passing the window. What the window function does in case you pass a window to it is unclear to me. |
When I remove this line and pass the LoadError: MethodError: no method matching unsafe_convert(::Type{Ptr{Nothing}}, ::Gtk.GtkWindowLeaf) If I understand correctly, this means that |
Okay, I found an explanation here: However, accounting for that, a new problem arised: GLib-GObject-CRITICAL **: 14:22:12.660: g_object_ref: assertion 'G_IS_OBJECT (object)' failed So the search continues ;-) EDIT: This error is due to the line mentioned by @tknopp. Simply passing |
Best would be to put a small minimal working example so that I can test this. You can also past the glade file into a string and load that string with the builder object. In that way the file is self-contained. |
Ok, I will cook up a MWE including glade later on and post it here. |
Okay, so this is a strange one ... I created the following MWE: Glade-file (save this in a text file MWE.glade)
Julia-File: module MWE
using Gtk
using Gtk.ShortNames
export buildGUI
# Utility function to change the mouse cursor (see https://github.com/JuliaGraphics/Gtk.jl/issues/516)
function gdk_cursor_new(id::String)
d = ccall((:gdk_display_get_default,Gtk.libgdk),Ptr{Nothing},(Cstring,),id)
return ccall((:gdk_cursor_new_from_name,Gtk.libgdk),Ptr{Nothing},(Ptr{Nothing}, Cstring), d, id)
end
function gdk_window_set_cursor(wnd, cursor::Ptr{Nothing})
wptr = Gtk.GAccessor.window(wnd)
ccall((:gdk_window_set_cursor, Gtk.libgdk), Nothing, (Ptr{Nothing}, Ptr{Nothing}), wptr, cursor)
return Cint(false) # Return value for Gtk
end
const CURSOR_WAIT = gdk_cursor_new("wait")
const CURSOR_DEFAULT = gdk_cursor_new("default")
const CURSOR_CROSSHAIR = gdk_cursor_new("crosshair")
# ==============================================================================
# Struct for the winding GUI
mutable struct GUIContainer
GtkBuilder::GtkBuilder
end
function buildGUI()
filename_UI = Base.Filesystem.joinpath(@__DIR__, "MWE.glade")
builder = GtkBuilder(filename=filename_UI)
win = builder["main_window"]
obj = GUIContainer(builder)
showall(win)
# Callback
id = signal_connect(cb_waiting, builder["button_waiting"], "clicked", Nothing, (), false, obj)
id = signal_connect(cb_default, builder["button_default"], "clicked", Nothing, (), false, obj)
# 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_waiting(widget, obj)
gdk_window_set_cursor(obj.GtkBuilder["main_window"], CURSOR_WAIT)
return nothing # This is important to fit with the return type
end
@guarded (nothing) function cb_default(widget, obj)
gdk_window_set_cursor(obj.GtkBuilder["main_window"], CURSOR_DEFAULT)
return nothing # This is important to fit with the return type
end
end # Module
using .MWE
buildGUI() The good (or bad thing) is that this MWE works flawlessly. I tried stripping my real-world example down to the MWE, but the error persists. When I use my real-world glade file in the MWE, it works as well. So I doubt this is a problem with Gtk.jl and I think I hit a very strange corner case. So this is on me to find out. Anyway, I thought I'd leave the code for the working MWE here as documentation. |
So I found the error :-) The problem is not the builder, the problem is here: # Utility function to change the mouse cursor (see https://github.com/JuliaGraphics/Gtk.jl/issues/516)
function gdk_cursor_new(id::String)
d = ccall((:gdk_display_get_default,Gtk.libgdk),Ptr{Nothing},(Cstring,),id)
return ccall((:gdk_cursor_new_from_name,Gtk.libgdk),Ptr{Nothing},(Ptr{Nothing}, Cstring), d, id)
end
function gdk_window_set_cursor(wnd, cursor::Ptr{Nothing})
wptr = Gtk.GAccessor.window(wnd)
ccall((:gdk_window_set_cursor, Gtk.libgdk), Nothing, (Ptr{Nothing}, Ptr{Nothing}), wptr, cursor)
return Cint(false) # Return value for Gtk
end
const CURSOR_WAIT = gdk_cursor_new("wait")
const CURSOR_DEFAULT = gdk_cursor_new("default")
const CURSOR_CROSSHAIR = gdk_cursor_new("crosshair") The last part where the cursor pointers are created "in advance" doesn't work in my use case because the pointer is not identified as a GObject. Anyway, the fix is simple: Create the pointer anew each time a cursor change is needed: # Utility function to change the mouse cursor (see https://github.com/JuliaGraphics/Gtk.jl/issues/516)
function gdk_cursor_new(id::String)
d = ccall((:gdk_display_get_default,Gtk.libgdk),Ptr{Nothing},(Cstring,),id)
return ccall((:gdk_cursor_new_from_name,Gtk.libgdk),Ptr{Nothing},(Ptr{Nothing}, Cstring), d, id)
end
function gdk_window_set_cursor(wnd, id::String)
cursor = gdk_cursor_new(id)
wptr = Gtk.GAccessor.window(wnd)
ccall((:gdk_window_set_cursor, Gtk.libgdk), Nothing, (Ptr{Nothing}, Ptr{Nothing}), wptr, cursor)
return Cint(false) # Return value for Gtk
end I hope this helps in case someone else stumbles upon this. As I said, this is certainly not an Gtk.jl issue, so no further action is necessary. |
great that you found the error. Although it is not obvious to me why curser needs to be created again and again. |
Well, to me it isn't either ;-) Especially because it works for my MWE. Perhaps I'll have a look at it again when I'm feeling bored ;-) Anyway, thank you very much for your support! |
Hello,
this is probably a very simple problem, but I can't figure out how to set the mouse cursor type (e.g. waiting, crosshair and so on) in a GUI window created by Glade. For a non-Glade UI, I found the following issue: #516.
I tried to apply this to a Glade-based window:
This leads to the following warning:
I found that the type of
win
in the example above isGtk.GtkWindowLeaf
, while the type ofwin
in the linked thread isGtkWindowLeaf
. So i suspect there is some difference here ...If necessary, I can gladly provide a sample Glade-file to get the MWE above to run.
Thanks for your help in advance!
The text was updated successfully, but these errors were encountered: