Skip to content

Commit

Permalink
add save to file and copy to clipboard to context menu (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand authored Apr 29, 2024
1 parent e54547a commit 88962f1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
10 changes: 5 additions & 5 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', 'nightly']
version: ['1.6', '1']
arch: [x64, x86]
include:
- os: ubuntu-latest
Expand All @@ -23,7 +23,7 @@ jobs:
arch: x86
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand All @@ -37,11 +37,11 @@ jobs:
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
with:
prefix: ${{ matrix.prefix }}
- uses: julia-actions/julia-processcoverage@v1
- uses: julia-actions/julia-processcoverage@latest
- uses: codecov/codecov-action@v3
with:
file: lcov.info
4 changes: 2 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 <[email protected]"]
version = "0.12.1"
version = "0.12.2"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand All @@ -23,7 +23,7 @@ AxisArrays = "0.3, 0.4"
Cairo = "0.6, 0.7, 0.8, 1"
Compat = "3, 4"
Graphics = "0.2, 0.3, 0.4, 1"
GtkObservables = "2"
GtkObservables = "2.1"
Gtk4 = "0.6"
ImageBase = "0.1"
ImageCore = "0.9, 0.10"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ imshow(img, axes=(:S, :P), flipy=true) # a sagittal plane (Superior, Posterior)
| ![photo](readme_images/mri.jpg) | ![photo](readme_images/mri_sagittal.jpg) |


Finally, for grayscale images, right-clicking on the image yields a brightness/contrast GUI:
Finally, right-clicking on the image yields context menu that allows you to save the image shown in the viewer (including annotations) to a PNG file or to the clipboard, and a brightness/contrast GUI:

![Contrast GUI snapshot](readme_images/contrast.jpg)

Expand Down
30 changes: 26 additions & 4 deletions src/ImageView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,19 +696,41 @@ nanz(x) = ifelse(isnan(x), zero(x), x)
nanz(x::FixedPoint) = x
nanz(x::Integer) = x

const menuxml = """
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="context_menu">
<item>
<attribute name="label">Contrast...</attribute>
<attribute name="action">canvas.contrast_gui</attribute>
</item>
<item>
<attribute name="label">Save to file...</attribute>
<attribute name="action">canvas.save</attribute>
</item>
<item>
<attribute name="label">Copy to clipboard</attribute>
<attribute name="action">canvas.copy</attribute>
</item>
</menu>
</interface>
"""

function create_contrast_popup(canvas, enabled, hists, clim)
popupmenu = GtkPopover()
b = GtkBuilder(menuxml, -1)
menumodel = b["context_menu"]::Gtk4.GLib.GMenuLeaf
popupmenu = GtkPopoverMenu(menumodel)
Gtk4.parent(popupmenu, widget(canvas))
contrast = GtkButton("Contrast...")
popupmenu[] = contrast
push!(canvas.preserved, on(canvas.mouse.buttonpress) do btn
if btn.button == 3 && btn.clicktype == BUTTON_PRESS
x,y = GtkObservables.convertunits(DeviceUnit, canvas, btn.position.x, btn.position.y)
Gtk4.G_.set_pointing_to(popupmenu,Ref(Gtk4._GdkRectangle(round(Int32,x.val),round(Int32,y.val),1,1)))
popup(popupmenu)
end
end)
signal_connect(contrast, :clicked) do widget
contrast_gui_action = Gtk4.GLib.GSimpleAction("contrast_gui", Nothing)
push!(Gtk4.GLib.GActionMap(canvas.action_group), Gtk4.GLib.GAction(contrast_gui_action)) # replaces the old one if it exists
signal_connect(contrast_gui_action, :activate) do a, par
enabled[] = true
@idle_add contrast_gui(enabled, hists, clim)
end
Expand Down

0 comments on commit 88962f1

Please sign in to comment.