Replies: 19 comments
-
Can you also get the cairo context & surface? |
Beta Was this translation helpful? Give feedback.
-
They're available in Gtk, https://github.com/JuliaGraphics/Gtk.jl/blob/08d802bc8e0ce0c1925f70570539d417f2e910ba/src/cairo.jl#L4 |
Beta Was this translation helpful? Give feedback.
-
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)
|
Beta Was this translation helpful? Give feedback.
-
Cool, I was almost there! This yields:
|
Beta Was this translation helpful? Give feedback.
-
I just merged a fix for this! Checkout master and make sure to call |
Beta Was this translation helpful? Give feedback.
-
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))) |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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
|
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Yes exactly, a bit like Requires but with first class support and precompilation. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
See #2537 |
Beta Was this translation helpful? Give feedback.
-
(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:
Beta Was this translation helpful? Give feedback.
All reactions