Skip to content

Instantly share code, notes, and snippets.

@aquatiko
Last active April 7, 2019 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquatiko/0b08f6b8efcb460bb550fcfeaa00ce30 to your computer and use it in GitHub Desktop.
Save aquatiko/0b08f6b8efcb460bb550fcfeaa00ce30 to your computer and use it in GitHub Desktop.
Gtk initial Interface for AstroImage
# creates a zoom-able window with feature to view coordinate of AstroImage by hovering mouse over it
using AstroImages, GtkReactive, Gtk.ShortNames, Graphics, Gtk, Colors, IntervalSets, Cairo
using AstroImages: render
function ui(img::AstroImage{T,C}) where {T,C}
win = Window("Image")
g = Grid()
push!(win, g)
l1 = Label("X =")
l2 = Label("Y =")
g[1,2] = l1
g[2,2] = l2
c = canvas(UserUnit)
g[1:2,1] = c
map(c.mouse.motion) do btn
xu, yu = btn.position.x.val, btn.position.y.val
GAccessor.text(l1 ,"X = $(round(xu))")
GAccessor.text(l2 ,"Y = $(round(yu))")
end
set_gtk_property!(g, :column_homogeneous, true)
set_gtk_property!(g, :column_spacing, 15)
set_gtk_property!(c, :expand, true)
img = render(img)
img24 = Matrix(UInt32[reinterpret(UInt32, convert(RGB24, img[i,j])) for i = 1:size(img,1), j = size(img,2):-1:1]')
fv = XY(0.0..size(img24,2), 0.0..size(img24,1))
zr = Signal(ZoomRegion(fv, fv))
surf = Cairo.CairoRGBSurface(img24)
draw(c, zr) do widget, r
ctx = getgc(widget)
set_coordinates(ctx, r)
rectangle(ctx, BoundingBox(r.currentview))
set_source(ctx, surf)
fill(ctx)
end
showall(win)
end
ui(AstroImage("euve.fits")) # load your own fits file to try out and make sure of dependencies above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment