I am using Gtk to display on a canvas images which are plots/figures produced in Plots via GR. The workflow I use is to save the figure to a png, and then load it in the draw function for Gtk where the canvas surface is then updated. This incurs a large delay and the png filesize is not large.
How can I channel the figure production in plots directly to Gtk’s canvas t reduce the latency? (part of cairo.jl I assume)
using Gtk
function drawSys(widget)
ctx = Gtk.getgc(widget)
c = CairoRGBSurface(400,20);
cr = CairoContext(c);
set_source_rgb(cr,0.8,0.8,0.8); # light gray
rectangle(cr,0.0,0.0,800.0,650.0); # background
fill(cr);
image = read_from_png("dog.png")
set_source_surface(ctx, image, 0, 0)
paint(ctx)
end
Regarding maintenance: I am using Winston in a Gtk /Winston System in production and was the one that brought Winston from 0.5 to 1.0. That does not mean that I develop features but its likely that this package will work as is, for the next Julia versions.
Winston is somewhat lightweight, although it has some inference issues, which make the time to first plot a little bit slow. I usually wait 3-5 seconds. Still my impression is that Gadfly is more heavy but has more functionality.
using Gtk.ShortNames
using Random
using Winston
c = Canvas()
w = Window(c, "Test Winston")
Gtk.showall(w)
p = Winston.plot(randn(50), "b-", linewidth=7);
display(c, p)
I have been trying to adapt your example provided in https://github.com/jheinen/GR.jl/blob/master/examples/gtk_ex.jl, but encounter errors frequently when trying to modify the code. Eg. Trying to use the plot function within the example:
function plot(ctx, w, h)
global sl
ENV["GKS_WSTYPE"] = "142"
ENV["GKSconid"] = @sprintf("%lu", UInt64(ctx.ptr))
plt = gcf()
plt[:size] = (w, h)
nbins = Int64(Gtk.GAccessor.value(sl))
plot(1:10,rand(10))#hexbin(x, y, nbins=nbins)
end
errors:
julia> FATAL ERROR: Gtk state corrupted by error thrown in a callback:
ERROR: MethodError: no method matching plot(::UnitRange{Int64}, ::Array{Float64,1})
Closest candidates are:
plot(::Any, ::Any, !Matched::Any) at /home/xel/tmp/try.jl:10
Stacktrace:
[1] plot(::Cairo.CairoContext, ::Int32, ::Int32) at /home/xel/tmp/try.jl:19
[2] draw(::Gtk.GtkCanvas) at /home/xel/tmp/try.jl:31
[3] draw(::Gtk.GtkCanvas, ::Bool) at /home/xel/.julia/packages/Gtk/aP55V/src/cairo.jl:90
[4] notify_resize(::Ptr{GObject}, ::Ptr{Gtk.GdkRectangle}, ::Gtk.GtkCanvas) at /home/xel/.julia/packages/Gtk/aP55V/src/cairo.jl:67
[5] (::getfield(Gtk, Symbol("##237#238")))() at /home/xel/.julia/packages/Gtk/aP55V/src/events.jl:2
[6] g_sigatom(::Any) at /home/xel/.julia/packages/Gtk/aP55V/src/GLib/signals.jl:167
[7] gtk_main() at /home/xel/.julia/packages/Gtk/aP55V/src/events.jl:1
Killed
this works with GR at the REPL where a GR window open up and shows the plot. Is there a problem with my system set up maybe?
I see the click example, do you know if it’s possible to click on some element in the plot and redraw other parts of the plot? For example, drag a point and re-fit the underlying curve
@tobias.knopp and @jheinen, would it be possible to create the image file, but not write it to disk with save and then use pipes or streams to directly write it as an already created file on the canvas?