3

Please, consider the following code:

ColorSlider[
  Dynamic[x], ImageSize -> {800, 100}, AppearanceElements -> "Spectrum"
]

Button["get color",
 MessageDialog @ Dynamic[x];
 CopyToClipboard @ funct @ Dynamic[x];
]

Graphics[{Dynamic[x], Disk[]}, Frame -> True, FrameLabel -> Dynamic[x]]

To get the value of RGBColor in a string form, I have changed, in turn, the above funct with OutputForm, StringForm etc. obtaining always one of two results:

Dynamic[x] (* or *)

StandardForm !(*DynamicBox[ToBoxes[Global`x, StandardForm], ImageSizeCache->{380., {2., 8.}}])

To track the issue I tried

 Slider[Dynamic[z]]

 Print @ Dynamic[z];

 Button["copy",
     MessageDialog @ Dynamic[z];
     CopyToClipboard  @ Dynamic[z];
 ]

 Button["paste",
     Paste  @ Dynamic @ z;
 ]

and understood that CopyToClipboard get the whole DynamicBox, not its 'current content'. How can I get rid of the "wrapper" ?

Addendum

I just have realized taht the color value can be read by means of

InputField[Dynamic[x]]

but it's evidently an expedient and doesn' enlighten the broader subject.

Kuba
  • 136,707
  • 13
  • 279
  • 740
mitochondrial
  • 1,843
  • 10
  • 16

1 Answers1

2

I haven't found better duplicate so here's what you need to know:

from Mr. Wizard's answer to Question about MapThread and Dynamic.

In short, Dynamic doesn't do anything until it is actually displayed on screen. Therefore, you are essentially doing this (note the String):

See also the linked topic.

Moreover, in your case Dynamic[x] takes the tour: Button -> Clipboard -> final destination. If you final destination is e.g. a MMA notebook, then the FrontEnd can handle this and will show you colored rectangle.

However, if you copy to let's say Notepad, you will get Dynamic[x], with no info about x because Dynamic is HoldAll.

As I've mentioned the workaround is to use Setting @ Dynamic @ x [1] or just x, the Button is HoldRest so you will copy the current value of x.

[1]: How to extract the numerical value of a dynamical variable

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • Thanks for the reply! I'm studying the sources you pointed at. Now I undestend the behaviour of this code: Row @ {Slider[Dynamic[x]], Dynamic[x], Button["raw", Dynamic[x] >>> "deleteme.txt"], Button["value", Setting @ Dynamic[x] >>> "deleteme.txt"] } – mitochondrial Feb 25 '16 at 16:19