Guest User

3.1

a guest
Aug 7th, 2013
65
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. Cell[BoxData[___], ___, CellTags -> "MyCode", ___], {1}][[
  53. 1, 1]]
  54. ]
  55. ], "Input", CellTags -> "MyGraphic"]];
  56. (* NotebookWrite[EvaluationNotebook[],
  57. Cell[BoxData[
  58. ToBoxes@ReleaseHold@MakeExpression@First@First@Quiet[
  59. Cases[NotebookGet[EvaluationNotebook[]][[1]],Cell[___,CellTags->
  60. "MyCode",___],{1}],First::first]
  61. ],"Input",CellTags->"MyGraphic"]
  62. ]; *)
  63. ]
  64. ];
  65. CellPrint@GetCode[];
  66. (* CellPrint@Cell[BoxData[
  67. DynamicBox[ToBoxes[
  68. Refresh[
  69.  
  70. ToBoxes@@MakeExpression@First@First@Cases[NotebookGet[\
  71. EvaluationNotebook[]][[1]],Cell[___,CellTags->"MyGraphic",___],\
  72. Infinity]
  73.  
  74. , UpdateInterval -> 1], StandardForm],
  75. ImageSizeCache->{7., {0., 7.}}]], "Input",
  76. CellChangeTimes->{3.5839336357137146`*^9}]; *)
RAW Paste Data