Skip to content

Commit

Permalink
Label in the bottom right corner showing the current view (#314)
Browse files Browse the repository at this point in the history
Label shows the current view (only when zoomed in). This is selectable, allowing users to cut and paste into an editor (or the REPL).

Also includes a microoptimization in the hover label setter and a minor fix to the README.

Finally, require Julia 1.10 and bump version.
  • Loading branch information
jwahlstrand authored Dec 30, 2024
1 parent c010e35 commit acaab89
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ['1.6', '1']
version: ['1']
arch: [x64, x86]
include:
- os: ubuntu-latest
Expand All @@ -27,7 +27,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
env:
cache-name: cache-artifacts
with:
Expand Down
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ImageView"
uuid = "86fae568-95e7-573e-a6b2-d8a6b900c9ef"
author = ["Tim Holy <tim.holy@gmail.com"]
version = "0.12.6"
version = "0.13.0"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand Down Expand Up @@ -32,7 +32,8 @@ MultiChannelColors = "0.1.1"
PrecompileTools = "1"
RoundingIntegers = "0.2, 1"
StatsBase = "0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34"
julia = "1.6"
julia = "1.10"
TestImages = "1.9"

[extras]
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,6 @@ manually close it with `CTRL + C`.
If you are opening more than one window you will need to create more
than one `Condition` object, if you wish to wait until the last one is
closed. See
(here)[https://juliagtk.github.io/Gtk4.jl/dev/howto/nonreplusage/] for
[here](https://juliagtk.github.io/Gtk4.jl/dev/howto/nonreplusage/) for
more information.

29 changes: 24 additions & 5 deletions src/ImageView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ Compat.@constprop :none function imshow(@nospecialize(img::AbstractArray), clim,
guidict["hoverinfo"] = on(guidict["canvas"].mouse.motion) do btn
hoverinfo(guidict["status"], btn, img, sd)
end
guidict["zoomregion_info"]=on(zr; update=true) do z
viewinfo(guidict["viewlabel"], z, sd)
end

roidict = imshow(guidict["frame"], guidict["canvas"], img,
wrap_signal(clim), zr, sd, anns)
Expand Down Expand Up @@ -379,12 +382,16 @@ Compat.@constprop :none function imshow_gui(canvassize::Tuple{Int,Int},
g, frames, canvases = canvasgrid(gridsize, aspect)
end
push!(vbox, g)
cbox = GtkCenterBox()
push!(vbox, cbox)
status = GtkLabel("")
set_gtk_property!(status, :halign, Gtk4.Align_START)
push!(vbox, status)
cbox[:start] = status
viewlabel = GtkLabel(""; selectable = true)
Gtk4.ellipsize(viewlabel, Gtk4.Pango.EllipsizeMode_MIDDLE)
cbox[:end] = viewlabel

guidict = Dict("window"=>win, "vbox"=>vbox, "frame"=>frames, "status"=>status,
"canvas"=>canvases)
"canvas"=>canvases, "viewlabel"=>viewlabel)

# Add the player controls
if !isempty(slicedata)
Expand Down Expand Up @@ -526,10 +533,22 @@ function hoverinfo(lbl, btn, img, sd::SliceData{transpose}) where transpose
if checkbounds(Bool, img, axes...)
print(io, '[', y, ',', x, "] ")
show(IOContext(io, :compact=>true), img[axes...])
set_gtk_property!(lbl, :label, String(take!(io)))
Gtk4.label(lbl, String(take!(io)))
else
Gtk4.label(lbl, "")
end
end

function viewinfo(lbl, zr, sd::SliceData{transpose}) where transpose
io = IOBuffer()
if zr.currentview == zr.fullview
print(io, "")
else
set_gtk_property!(lbl, :label, "")
print(io, "view: ")
x, y = transpose ? (zr.currentview.x, zr.currentview.y) : (zr.currentview.y, zr.currentview.x)
print(io, '[', x.left, ':', x.right, ',', y.left, ':', y.right, ']')
end
Gtk4.label(lbl, String(take!(io)))
end

function valuespan(img::AbstractMatrix)
Expand Down

0 comments on commit acaab89

Please sign in to comment.