Guest User

Untitled

a guest
Aug 7th, 2013
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GetCode[] := Cell[BoxData[StyleBox[
  2. DynamicBox[ToBoxes[Refresh[
  3.  
  4. InputForm @@ MakeExpression@
  5.  
  6. First@First@
  7. Quiet[Cases[NotebookGet[EvaluationNotebook[]][[1]],
  8. Cell[___, CellTags -> "MyGraphic", ___], Infinity]]
  9.  
  10. , UpdateInterval -> 1], StandardForm]
  11. ], StripOnInput -> False, LineColor -> GrayLevel[0.5],
  12. FrontFaceColor -> GrayLevel[0.5],
  13. BackFaceColor -> GrayLevel[0.5], GraphicsColor -> GrayLevel[0.5],
  14. FontColor -> GrayLevel[0.5]]
  15. ], "Output", CellTags -> "MyCode"];
  16.  
  17. DynamicQ[] := (
  18. Length@Cases[
  19. Quiet[
  20. Cases[NotebookGet[EvaluationNotebook[]][[1]],
  21. Cell[___, CellTags -> "MyCode", ___], Infinity], First::first]
  22. , DynamicBox[___]
  23. , Infinity] == 1
  24. );
  25. CellPrint@Cell[BoxData[ToBoxes[
  26. Graphics[{Circle[]}, ImageSize -> {100, Automatic}]
  27. ]], "Output", CellTags -> "MyGraphic"];
  28. Print[Button["Diable/Enable Dynamic",
  29. If[DynamicQ[],
  30. NotebookLocate["MyCode"];
  31. code = InputForm @@ MakeExpression@
  32. First@First@
  33. Quiet[
  34.  
  35. Cases[NotebookGet[EvaluationNotebook[]][[1]],
  36. Cell[___, CellTags -> "MyGraphic", ___], Infinity]];
  37. NotebookWrite[EvaluationNotebook[], Cell[BoxData[
  38. ToBoxes[code]
  39. ], "Input", CellTags -> "MyCode"]
  40. ];
  41. ,
  42. NotebookLocate["MyCode"];
  43. Quiet[
  44. NotebookWrite[EvaluationNotebook[], GetCode[]]
  45. ];
  46. ];
  47. ] Button["Update Graphics",
  48. NotebookLocate["MyGraphic"];
  49. NotebookWrite[EvaluationNotebook[], Cell[BoxData[
  50. ToBoxes@ToExpression[
  51. Cases[NotebookGet[EvaluationNotebook[]][[1]],
  52.  
  53. Cell[BoxData[___], ___,
  54. CellTags -> "MyCode", ___], {1}][[1, 1]]
  55. ]
  56. ], "Input", CellTags -> "MyGraphic"]];
  57. ]
  58. ];
  59. CellPrint@GetCode[];
RAW Paste Data