There is a promissing new function EvaluationBox[]
and a nice last example in documentation section for it:
Button["date", NotebookWrite[EvaluationBox[], ToBoxes @ DateString[]]]
(Click)
The problem is that this string is in an "Input" cell now! Why was it converted?
Quite a problem because it is not easy to change cell style.
I was trying:
Button["date", NotebookWrite[EvaluationBox[],
Cell[#, "Output"] & @ BoxData @ ToBoxes @ DateString[]]]
but the problem remains. On the other hand we can see that it is not a problem of NotebookWrite
itself but of EvaluationBox[]
because EvaluationCell
replaced by the code above gives correct output:
Button["date", NotebookWrite[EvaluationCell[],
Cell[#, "Output"] & @ BoxData @ ToBoxes @ DateString[]]]
Any thougts? Quick work arounds?
I've introduced one, ugly but working here: Getting the Box of a Button . I was trying to improve it with EvluationBox[]
but the I've faced this issue.
Answer
Using NotebookWrite
in this manner is really no different from manually modifying the content of an Output cell.
The FrontEnd converts the cell to Input, since it anticipates the user would be interested in evaluating it afterwards.
What style is used is determined by DefaultDuplicateCellStyle
.
Comments
Post a Comment