Reputation: 9425
How to create a Button
which will be displayed only when the value of some global FrontEnd setting is False
and will self-destruct with entire row of the Column
after pressing it setting this value to True
?
I need something like this:
Column[{"Item 1", "Item 2",
Dynamic[If[
Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False,
Button["Press me!",
SetOptions[$FrontEnd, "VersionedPreferences" -> True]],
Sequence @@ {}]]}]
But with this code the Button
does not disappear after pressing it. Is it possible to make it self-destructive?
The final solution based on ideas by belisarius and mikuszefski:
PreemptProtect[SetOptions[$FrontEnd, "VersionedPreferences" -> False];
b = True];
Dynamic[Column[
Join[{"Item 1", "Item 2"},
If[Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False &&
b == True, {Button[
Pane[Style[
"This FrontEnd uses shared preferences file. Press this \
button to set FrontEnd to use versioned preferences file (all the \
FrontEnd settings will be reset to defaults).", Red], 300],
AbortProtect[
SetOptions[$FrontEnd, "VersionedPreferences" -> True];
b = False]]}, {}]], Alignment -> Center],
Initialization :>
If[! Last@Last@Options[$FrontEnd, "VersionedPreferences"], b = True,
b = False]]
The key points are:
Dynamic
variable b
and binding it with the value of Options[$FrontEnd, "VersionedPreferences"]
,Column
construct
with Dynamic
instead of using
Dynamic
inside Column
.Upvotes: 3
Views: 175
Reputation: 61016
Perhaps
PreemptProtect[SetOptions[$FrontEnd, "VersionedPreferences" -> False]; b = True];
Column[{"Item 1", "Item 2", Dynamic[
If[Last@Last@Options[$FrontEnd, "VersionedPreferences"]===False && b == True,
Button["Here!", SetOptions[$FrontEnd, "VersionedPreferences"->True];b=False],
"Done"]]}]
Edit
Answering your comment. Please try the following. Encompassing the Column[ ]
with Dynamic[ ]
allows resizing it:
PreemptProtect[SetOptions[$FrontEnd, "VersionedPreferences" -> False]; b = True];
Dynamic[
Column[{
"Item 1",
"Item 2",
If[Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False && b == True,
Button["Press me!", SetOptions[$FrontEnd, "VersionedPreferences" -> True]; b=False],
Sequence @@ {}]}]]
Upvotes: 6
Reputation: 4043
Hmm, dunno if I get it right, but maybe this:
x = True;
Dynamic[Column[{Button["reset", x = True], If[x, Button["Press me", x = False]]}] ]
Upvotes: 4