Skip to content

Commit

Permalink
fix and polish save callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Nov 7, 2023
1 parent 96f788c commit bd269ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
name = "Gtk4Makie"
uuid = "478199e7-b407-4926-87ea-7196203a28d8"
version = "0.1.5"
version = "0.1.6"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
Gtk4 = "9db2cae5-386f-4011-9d63-a5602296539b"
GtkObservables = "8710efd8-4ad6-11eb-33ea-2d5ceb25a41c"
ModernGL = "66fc600b-dfda-50eb-8b99-91cfa97b1301"
ShaderAbstractions = "65257c39-d410-5151-9873-9b3e5be5013e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
GtkObservables = "8710efd8-4ad6-11eb-33ea-2d5ceb25a41c"
ShaderAbstractions = "65257c39-d410-5151-9873-9b3e5be5013e"

[compat]
Colors = "0.11, 0.12"
FileIO = "1.6"
GLMakie = "0.8"
GeometryBasics = "0.4.1"
Gtk4 = "0.4, 0.5"
GtkObservables = "2"
ModernGL = "1"
ShaderAbstractions = "0.3, 0.4"
PrecompileTools = "1"
ShaderAbstractions = "0.3, 0.4"
julia = "1.6"
1 change: 1 addition & 0 deletions src/Gtk4Makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Gtk4Makie

using Gtk4, GtkObservables
using ModernGL, GLMakie, Colors, GeometryBasics, ShaderAbstractions
import FileIO
using GLMakie.GLAbstraction
using GLMakie.Makie
using GLMakie: empty_postprocessor, fxaa_postprocessor, OIT_postprocessor,
Expand Down
28 changes: 16 additions & 12 deletions src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,26 @@ function save_cb(::Ptr,par,screen)
dlg = convert(GtkFileDialog, obj)
leaftype = Gtk4.GLib.find_leaf_type(res)
resobj = convert(leaftype, res)
#try
try
gfile = Gtk4.G_.save_finish(dlg, Gtk4.GLib.GAsyncResult(resobj))
filepath=Gtk4.GLib.path(Gtk4.GLib.GFile(gfile))
if endswith(filepath,".png")
GLMakie.save(filepath,screen.root_scene; backend=GLMakie)
elseif endswith(filepath,".pdf") || endswith(filepath,".svg")
if endswith(filepath,".png") || endswith(filepath,".jpg")
img = colorbuffer(screen)
fo = endswith(filepath,".png") ? FileIO.format"PNG" : FileIO.format"JPEG"
open(filepath, "w") do io
FileIO.save(FileIO.Stream{fo}(Makie.raw_io(io)), img)
end
else
info_dialog("Only .png and .jpg extensions are supported.", window(screen)) do
end
#elseif endswith(filepath,".pdf") || endswith(filepath,".svg")
# if we imported CairoMakie we could use that to save to these formats
end
#catch e
# error("failed to save")
# return nothing
#end
catch e
error_dialog("Failed to save: $e") do
end
end
return nothing
end
Gtk4.G_.save(dlg, window(screen), nothing, file_save_cb)
nothing
Expand Down Expand Up @@ -291,10 +299,6 @@ function add_window_shortcuts(w)
add_shortcut(sc,Sys.isapple() ? "<Meta><Shift>F" : "F11", "win.fullscreen")
end

function Makie.backend_show(win::GtkWindow, io::IO, m::MIME"image/png", scene::Scene)
invoke(Makie.backend_show, Tuple{MakieScreen, IO, MIME"image/png", Scene}, screens[Ptr{Gtk4.GtkGLArea}(win2glarea[win].handle)], io, m, scene)
end

mutable struct ScreenConfig
title::String
fullscreen::Bool
Expand Down

0 comments on commit bd269ec

Please sign in to comment.