-
-
Notifications
You must be signed in to change notification settings - Fork 327
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Target a Gtk Cairo context #568
Comments
Can you also get the cairo context & surface? |
using Gtk, CairoMakie
c = @GtkCanvas()
win = GtkWindow(c, "Easel", 640, 480)
@guarded draw(c) do widget
ctx = getgc(c)
surf = Gtk.cairo_surface(c)
scene = heatmap(rand(50, 50), resolution=(640, 480))
screen = CairoMakie.CairoScreen(scene, surf, ctx, nothing)
CairoMakie.cairo_draw(screen, scene)
end
showall(win)
|
Cool, I was almost there! This yields:
|
I just merged a fix for this! Checkout master and make sure to call |
Awesome! I wonder if there should be a utility function that passes along resize events to the scene? So that Gtk can manage the canvas size and CairoMakie can respond? Mockup... drawonto(canvas, scene) = @guarded draw(canvas) do _
resize!(scene, width(canvas), height(canvas))
screen = CairoMakie.CairoScreen(scene, Gtk.cairo_surface(canvas), getgc(canvas), nothing)
CairoMakie.cairo_draw(screen, scene)
end usage c = @GtkCanvas()
win = GtkWindow(c, "Easel", 640, 480)
drawonto(c, heatmap(rand(50, 50))) |
You'd need a way to update (a) the Scene's pixel area and (b) the context's pixel area. (a) is as simple as |
I just tried this out, and it works beautifully. https://developer.gnome.org/gtk-tutorial/stable/x182.html could be useful for seeing which events to track and act on. |
I messed around with this a little. The following appears to be a good way to get the context's dynamic pixel area.
Obviously one would create the scene outside of |
I 've been searching for this! Do you think that this can at some point land in the CairoMakie.jl , so you can directly illustrate static figures with such GtkWindows? Currently in REPL you must save in a specific format and open outside the julia kernel to see the figure. |
I had a go at this and I came up with a small example. using Gtk, Makie, CairoMakie
function createMakieCanvas(figure)
c = @GtkCanvas()
@guarded draw(c) do widget
surf = Gtk.cairo_surface(c)
scene = figure.scene
resize!(scene, (surf.width,surf.height))
config = CairoMakie.ScreenConfig(1.0,1.0,:good,true,true)
screen = CairoMakie.Screen(scene, surf, config)
CairoMakie.cairo_draw(screen, scene)
end
return c
end
win = GtkWindow("demo", 640, 480)
box = GtkBox(:v)
push!(win,box)
button = GtkButton("plot")
push!(box,button)
f = Figure()
ax = Axis(f[1,1])
c = createMakieCanvas(f)
push!(box,c)
set_gtk_property!(box,:expand,c,true)
function on_plot(w)
empty!(ax)
heatmap!(ax,rand(100,20))
draw(c)
end
signal_connect(on_plot, button, "clicked")
showall(win)
while true
sleep(1)
end
|
@jkrumbiegel @SimonDanisch: Is there any reason why CairoMakie does not ship with Gtk Window integration for the REPL like for instance Winston.jl does it? The inconvenience to get a quick plot is right now the only reason to prefer other plotting tools for me at the moment. |
We could think about adding that as a weak dependency. So for people with GTK installed, that would give an additional way of showing cairomakie plots. |
What do you mean by weak dependency? JuliaLang/julia#47695? I have not looked at it yet but if that is the proposal I think this would be great. Just „using Gtk, CairoMakie“ and then have plots showing up. |
Yes exactly, a bit like Requires but with first class support and precompilation. |
I just tried this example: ┌ Warning: Error in @guarded callback
│ exception =
│ MethodError: no method matching CairoMakie.Screen(::Scene, ::Cairo.CairoSurfaceBase{UInt32}, ::Cairo.CairoContext, ::Nothing)
│ Closest candidates are:
│ CairoMakie.Screen(::Scene; screen_config...) at ~/.julia/packages/CairoMakie/ihglX/src/screen.jl:239
│ CairoMakie.Screen(::Scene, ::CairoMakie.ScreenConfig) at ~/.julia/packages/CairoMakie/ihglX/src/screen.jl:244
│ CairoMakie.Screen(::Scene, ::CairoMakie.ScreenConfig, ::Cairo.CairoSurface) at ~/.julia/packages/CairoMakie/ihglX/src/screen.jl:270
│ ...
│ Stacktrace:
│ [1] macro expansion
│ @ ./REPL[4]:5 [inlined]
│ [2] (::var"#1#2"{GtkCanvas, Figure})(#unused#::GtkCanvas)
│ @ Main ~/.julia/dev/Gtk/src/base.jl:112
│ [3] draw(widget::GtkCanvas, immediate::Bool)
│ @ Gtk ~/.julia/dev/Gtk/src/cairo.jl:86
│ [4] notify_resize(#unused#::Ptr{GObject}, size::Ptr{Gtk.GdkRectangle}, widget::GtkCanvas)
│ @ Gtk ~/.julia/dev/Gtk/src/cairo.jl:63
│ [5] (::Gtk.var"#253#254")()
│ @ Gtk ~/.julia/dev/Gtk/src/events.jl:2
│ [6] g_sigatom(f::Any)
│ @ Gtk.GLib ~/.julia/dev/Gtk/src/GLib/signals.jl:176
│ [7] gtk_main()
│ @ Gtk ~/.julia/dev/Gtk/src/events.jl:1
└ @ Main ~/.julia/dev/Gtk/src/base.jl:114 |
I can confirm that I am encountering the same error message as @tknopp when running the GTK and Makie code from the README. My stacktrace is the same as Tknopp's as well. I am running Julia 1.8.3 on Ubuntu 20.04, and I also get a popup application window that is completely blank--no controls visible. |
By replacing function drawonto(canvas, figure)
@guarded draw(canvas) do _
scene = figure.scene
resize!(scene, Gtk.width(canvas), Gtk.height(canvas))
config = CairoMakie.ScreenConfig(1.0,1.0,:good,true,true)
screen = CairoMakie.Screen(scene, config, Gtk.cairo_surface(canvas))
CairoMakie.cairo_draw(screen, scene)
end
end I got a working example. |
See #2537 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
(Perhaps I've just missed it)
We should document a way to have CairoMakie paint onto a GtkCanvas from Gtk.jl. Here is an example:
The text was updated successfully, but these errors were encountered: