Skip to content

Commit

Permalink
IJulia/Jupyter notebook display (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed May 2, 2017
1 parent f7dc0b6 commit 23927e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/src/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Drawing

To finish a drawing and close the file, use `finish()`, and, to launch an external application to view it, use `preview()`.

If you're using Jupyter (IJulia), `preview()` displays PNG files in the notebook.
If you're using Jupyter (IJulia), `preview()` tries to display PNG and SVG files in the next notebook cell.

![jupyter](assets/figures/jupyter.png)

Expand Down
18 changes: 14 additions & 4 deletions src/Luxor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,24 @@ end
"""
preview()
If working in Jupyter (IJUlia), display a PNG file in the notebook.
On macOS, open the file, which probably uses the default, Preview.app.
If working in Jupyter (IJulia), display a PNG or SVG file in the notebook.
On macOS, open the file in the default application, which is probably
the Preview.app for PNG and PDF, and Safari for SVG.
On Unix, open the file with `xdg-open`.
On Windows, pass the filename to `explorer`.
"""
function preview()
if isdefined(Main, :IJulia) && Main.IJulia.inited && currentdrawing.surfacetype == "png"
display(load(currentdrawing.filename))
if (isdefined(Main, :IJulia) && Main.IJulia.inited)
if currentdrawing.surfacetype == "png"
display("image/png", load(currentdrawing.filename))
elseif currentdrawing.surfacetype == "svg"
open(currentdrawing.filename) do f
display("image/svg+xml", readstring(f))
end
end
elseif @compat is_apple()
run(`open $(currentdrawing.filename)`)
elseif @compat is_windows()
Expand Down
4 changes: 2 additions & 2 deletions src/animate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function animate(movie::Movie, scenelist::Array{Scene, 1};
pathname="")
tempdirectory = mktempdir()
info("Frames for animation \"$(movie.movietitle)\" are being stored in directory: \n\t $(tempdirectory)")
filecounter = 0
filecounter = 1
rangelist = 0:-1
for scene in scenelist
rangelist = vcat(rangelist, collect(scene.framerange))
Expand All @@ -90,7 +90,7 @@ function animate(movie::Movie, scenelist::Array{Scene, 1};
finish()
filecounter += 1
end
info("... $(filecounter) frames saved in directory:\n\t $(tempdirectory)")
info("... $(filecounter-1) frames saved in directory:\n\t $(tempdirectory)")
if creategif == true
# these two commands create a palette and then create animated GIF from the resulting images
run(`ffmpeg -loglevel panic -f image2 -i $(tempdirectory)/%10d.png -vf palettegen -y $(tempdirectory)/$(movie.movietitle)-palette.png`)
Expand Down

0 comments on commit 23927e6

Please sign in to comment.