3

如何创建一个仅在某些全局 FrontEnd 设置的值是并且将自毁并在按下它后将其设置为的整行Button时才显示的内容?FalseColumnTrue

我需要这样的东西:

Column[{"Item 1", "Item 2", 
  Dynamic[If[
    Last@Last@Options[$FrontEnd, "VersionedPreferences"] === False, 
    Button["Press me!", 
     SetOptions[$FrontEnd, "VersionedPreferences" -> True]], 
    Sequence @@ {}]]}]

但是使用此代码,Button按下后不会消失。有没有可能让它自毁?


最终解决方案基于belisariusmikuszefski的想法:

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]]

关键点是:

  • 引入附加Dynamic变量b并将其与 的值绑定Options[$FrontEnd, "VersionedPreferences"]
  • 用而不是使用 inside包装整个Column构造。DynamicDynamicColumn
4

2 回答 2

6

也许

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"]]}]

编辑

回答你的评论。请尝试以下方法。包含Column[ ]withDynamic[ ]允许调整它的大小:

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 @@ {}]}]]
于 2011-06-17T15:01:58.053 回答
4

嗯,不知道我是否做对了,但也许是这样:

x = 真;

动态[Column[{Button["reset", x = True], If[x, Button["Press me", x = False]]}] ]

于 2011-06-17T14:53:18.773 回答