【问题标题】:Dialog manipulation对话框操作
【发布时间】:2011-09-28 15:12:05
【问题描述】:

我想创建一个对话框窗口,用户可以在其中执行各种任务,并希望他通过用鼠标单击“取消”按钮(即不按 Enter)从对话框中返回。因此我不想使用 CreateDialog。但是,通过 CreateWindow 创建一个不太具体的对话框窗口,所有字符串都显示为未格式化。

expr = Column[{
   Row@{"set variable to: ", InputField["value", String]},
   "Try to hit Enter in any of the dialogs: it closes #2 but not #1.",
   CancelButton[]
   }];

CreateWindow[DialogNotebook[expr], WindowSize -> All, WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, WindowTitle -> "1. CreateWindow & DialogNotebook"];
CreateDialog[expr, WindowTitle -> "2. CreateDialog"];

有什么聪明的方法可以让第二个对话框窗口看起来像第一个对话框窗口的按钮行为?当然,expr 这里是一个简单的例子,但在现实中它可能相当复杂,因此不能将每个字符串都包装成Cell[string, "Text"],而将所有其他表达式包装成一些不起眼的盒子形式。

【问题讨论】:

  • “取消”按钮通常用于取消(即忽略)您的输入...

标签: user-interface interface dialog wolfram-mathematica


【解决方案1】:

这将在按下 Enter 时停止关闭对话窗口:

CreateDialog[expr, WindowTitle -> "2. CreateDialog", NotebookEventActions -> {}];

它会覆盖默认对话框 NotebookEventActions。

【讨论】:

    【解决方案2】:

    另一种选择:

    expr = Style[
       Column[{Row@{"set variable to: ", InputField["value", String]}, 
         "Try to hit Enter in any of the dialogs: it closes #2 but not \
    #1.", CancelButton[]}], ShowStringCharacters -> False];
    

    【讨论】:

    • 这很有用,我总是忘记这个选项,谢谢!但是在这种情况下,我必须手动设置字体样式选项以匹配使用 CreateDialog 创建的其他对话框元素的默认样式。
    【解决方案3】:

    也许使用TextCell

    expr = Column[{Row@{TextCell@"set variable to: ", 
                        InputField["value", String]}, 
                   TextCell@"Try to hit Enter in any of the dialogs: \
                             it closes #2 but not #1.", 
                   CancelButton[]}];
    
    CreateWindow[
     DialogNotebook[expr], WindowSize -> All, 
     WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, 
     WindowTitle -> "1. CreateWindow & DialogNotebook"]
    

    编辑

    使用

     TextCell@Style[" ... blah blah ...", style_opt ]
    

    用于格式化。

    【讨论】:

    • 我已经尝试过这种方法,但是它要求每个表达式都包装在 TextCell 或 Style 中,当您有一个复杂的对话框窗口时,这有点乏味。此外,正如我在上面对 ragfield 的解决方案所述,必须找出要重现的对话框的默认样式,这不是一项简单的任务。
    【解决方案4】:

    有很多方法可以做到这一点,其他人已经发布了两个很好的方法,但我认为最简单的方法是设置Column 表达式的BaseStyle 以匹配对话框的基本样式,然后使用CreateWindow。有问题的样式是"Panel",所以这会得到你想要的结果:

    expr = Column[{Row@{"set variable to: ", InputField["value", String]},
         "Try to hit Enter in any of the dialogs: it closes #2 but not #1.", 
         CancelButton[]}, BaseStyle -> "Panel"];
    
    CreateWindow[DialogNotebook[expr], WindowSize -> All, 
      WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, 
      WindowTitle -> "1. CreateWindow & DialogNotebook"];
    

    【讨论】:

    • 几乎完美的解决方案,但没有雪茄:在我的机器上,该列以白色背景出现在对话窗口的灰色背景前面。同样,我必须手动设置正确的 GrayLevel,因为即使 Background -> None 似乎也适用于 Column。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    相关资源
    最近更新 更多