I might be missing something obvious here. I am building a palette for constructing code to make certain graphics. The idea is that my colleagues can click buttons instead of having to know the right commands. So PasteButton[]
is an obvious help. Where I have gotten stuck is in color definition. What I want is for the user to be able to select a color on a ColorSlider
, and then click a button to paste the RGBColor[]
value selected in that ColorSlider
at the notebook insertion point. I do not want the code pasted in this way to update subsequently when the user chooses a different color in the ColorSlider
This is what I have so far, but the resulting pasted code does not pick up when the user has selected a different color in the slider. Pasting Dynamic[col]
instead of Setting[col]
results in a piece of code that changes when a different color is selected in the slider, which as I mentioned is not the desired behaviour.
Grid[{{PasteButton[
Graphics[{Dynamic[col], Rectangle[]}, ImageSize -> 26],
Setting@col, ImageSize -> 26, ImageMargins -> 0, FrameMargins -> 0],
ColorSlider[Dynamic[col], ImageSize -> {75, 25},
AppearanceElements -> "Spectrum"]}}, Spacings -> 0, Alignment -> Bottom]
The idea is that the user clicks on a color in the spectrum zone, and then clicks the button on the left that looks like a swatch.
How do I modify / rewrite this code to achieve the desired behaviour?
Answer
If you wrap your entire widget (as currently shown in your code), in Dynamic
, it will work. The reason is that without it, changes is col
are not propagated to PasteButton
.
Comments
Post a Comment