1
$\begingroup$

When coding in notebook, I'm trying to show result(s) in a Single Notbook Dialog by this,

fPreview[content_,opts : OptionsPattern[]] :=
    CreateDialog[
    Pane[content, 
        ImageSize -> {500-10, 600-20},
        Scrollbars -> True, 
        AppearanceElements -> None, 
        Alignment -> Center],
        WindowTitle -> "Preview" <> " " <> ToString@Head@content,
        WindowSize -> {500, 600},opts]

i.e.

 fPreview@Plot[Sin[x],{x,-4,4}]
 fPreview@Plot3D[Sin[x y],{x,-4,4},{x,-4,4}]

but once fPreview applied, there be a new Notebook Dialog, so I wonder how to modify the upper codes so that there be only One Notebook Dialog instance displaying the latest content(s)? Thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

There are many additional features one could need here but let's address exactly what you have asked for:

  (* I will skip styling options for clarity*)

fPreview[content_, opts : OptionsPattern[]] := With[
  { nb = CreateDialog[ content, opts] }
, ClearAll[fPreview]
; fPreview[new_, nvm___] := NotebookWrite[
    First @ Cells[nb], 
    Cell @ BoxData @ ToBoxes @ new
  ]
]

In general you may need to do something based on this pattern: how to generate repeatable Unique streams?, just instead of i++& it should return a log function you can use to log your results. And this way you can have many notebooks at once.

$\endgroup$
1
  • $\begingroup$ Thanks! It comes $Failed when fPreview executed a second time if the Notebook Dialog created at the first time was closed, I try to fix it but get failure. $\endgroup$
    – Jerry
    Commented Jan 29, 2019 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.