dm-script - 如何在 DM 脚本中更改浮动托盘的宽度
问题描述
现在我正在尝试编写一个 DM 脚本来显示一个浮动调色板,如下面的代码所示。但是,例如,包含在此代码中的长字符串标签会从调色板窗口突出。所以,我想知道如何更改调色板窗口的大小(即在这种情况下为宽度)。实际上,一些 Gatan 的官方调色板窗口,例如“Camera View”、“Camera Acquire”等,似乎比此代码创建的调色板更宽。如果您分享一些智慧,将不胜感激。非常感谢您提前。
Class MyDialog: UIFrame
{
TagGroup createDLGtgs( Object self ){
TagGroup DLGtgs, DLGItems
DLGtgs = DLGCreateDialog( "Test Dialog", DLGItems )
DLGItems.DLGAddElement( DLGCreateLabel( "Test of Gatan DigitalMicrograph scripting" ) )
DLGItems.DLGAddElement( DLGCreatePushButton( "OK", "testOK" ) )
return DLGtgs
}
//
Object Init( Object self ){
self.super.Init( self.createDLGtgs() )
return self
}
//
Void testOK( Object self ){
OKDialog( "Hello!" )
}
}
//
Object DialogOBJ = Alloc( MyDialog ).Init()
String DialogName = "Test Dialog"
String toolName = "Test Tool"
RegisterScriptPalette( DialogOBJ, DialogName, toolName )
OpenGadgetPanel(toolName)
解决方案
请注意,浮动调色板的情况在和之间是不同的
GMS 2.x
GMS 3.x
。从本质上讲,已注册的浮动调色板已在新 UI
中逐步淘汰。GMS 3.x
它们仍然在某种程度上受到支持,但并非所有功能都保留,并且某些行为存在错误。因为GMS 3.x
通常最好将脚本对话框作为模态或非模态对话框启动,而不再将它们安装为调色板。
此答案适用于GMS 2.x
(使用 GMS 2.3.3 测试)
您需要将位置标签添加到对话框描述标签组。通过添加到方法中,您可以在上述问题的示例代码中执行此操作TagGroup createDLGtgs( Object self )
:
TagGroup positionTgs = DLGBuildPositionFromApplication()
positionTgs.TagGroupSetTagAsString( "Width", "Medium" )
DLGtgs.DLGPosition( positionTgs )
接受的字符串值为:
"Small"
就像 GMS 2.x 的左侧工具面板一样。"Medium"
就像 GMS 2.x 的右手工具面板一样"Wide"
超宽
但是,位置标签还有一些附加选项,但它们不适用于浮动调色板,仅适用于常规无模式对话框。您可以使用绝对大小值设置窗口的宽度和高度,也可以让它由内容的大小自动确定。这是一个例子:
class CMyClass : UIFrame
{
void InitAndShow( object self ) {
Taggroup DLG,DLGItems
DLG = DLGCreateDialog("Test",DLGItems)
DLGItems.DLGAddElement( DLGCreateLabel( "Just some long text for extra width" ))
DLGItems.DLGAddElement( DLGCreateLabel( "A second line" ))
TagGroup positionTgs = DLGBuildPositionFromApplication()
positionTgs.TagGroupSetTagAsTagGroup( "Width", DLGBuildAutoSize() )
positionTgs.TagGroupSetTagAsTagGroup( "Height", DLGBuildAbsoluteSize( 45, "pixel" ) )
DLG.DLGPosition( positionTgs )
self.super.Init( DLG ).Display("Test")
}
}
Alloc(CMyClass).InitAndShow()
在上面DLGBuildPositionFromApplication()
将应用程序窗口设置为对话框的参考框架。DLGBuildRelativePosition()
然后,可以使用带有-1|0|1
相应参数的命令定义对话框 left|center|right 和 top|center|bottom 到该帧的位置,如示例中所示:
class CMyClass : UIFrame
{
void InitAndShow( object self ) {
Taggroup DLG,DLGItems
DLG = DLGCreateDialog("Test",DLGItems)
DLGItems.DLGAddElement( DLGCreateLabel( "Just some long text for extra width" ))
DLGItems.DLGAddElement( DLGCreateLabel( "A second line" ))
TagGroup positionTgs = DLGBuildPositionFromApplication()
positionTgs.TagGroupSetTagAsTagGroup( "Width", DLGBuildAutoSize() )
positionTgs.TagGroupSetTagAsTagGroup( "Height", DLGBuildAutoSize() )
// Appear top-right
positionTgs.TagGroupSetTagAsTagGroup( "X", DLGBuildRelativePosition( "Inside", 1 ) )
positionTgs.TagGroupSetTagAsTagGroup( "Y", DLGBuildRelativePosition( "Inside", -1 ) )
DLG.DLGPosition( positionTgs )
self.super.Init( DLG ).Display("Test")
}
}
Alloc(CMyClass).InitAndShow()
不过,参考框架不一定是应用程序窗口。您可以指定任何想要的 using DLGBuildPosition()
,它允许使用 fe 一个窗口矩形,然后将对话框放在它的右边。并且使用参考框架,还可以使用DLGBuildMatchSize()
以下示例中的相对于对话框窗口的大小来调整对话框窗口的大小:
class CMyClass : UIFrame
{
void InitAndShow( object self, documentWindow win ) {
Taggroup DLG,DLGItems
DLG = DLGCreateDialog("Test",DLGItems)
DLGItems.DLGAddElement( DLGCreateLabel( "Just some long text for extra width" ))
DLGItems.DLGAddElement( DLGCreateLabel( "A second line" ))
number t,l,b,r
win.WindowGetFrameBounds(t,l,b,r)
TagGroup positionTgs = DLGBuildPosition(t,l,b,r)
positionTgs.TagGroupSetTagAsTagGroup( "Width", DLGBuildAutoSize() )
positionTgs.TagGroupSetTagAsTagGroup( "Height", DLGBuildMatchSize() )
// Appear center-right outside the window
positionTgs.TagGroupSetTagAsTagGroup( "X", DLGBuildRelativePosition( "Outside", 1 ) )
positionTgs.TagGroupSetTagAsTagGroup( "Y", DLGBuildRelativePosition( "Inside", 0 ) )
DLG.DLGPosition( positionTgs )
self.super.Init( DLG ).Display("Test")
}
}
image img := RealImage("test",4,100,100)
img.ShowImage()
documentWindow win = img.ImageGetOrCreateImageDocument().ImageDocumentGetWindow()
Alloc(CMyClass).InitAndShow(win)
推荐阅读
- json - 在 Azure 数据工厂中读取变量 JSON 时出现问题
- javascript - 计算变量在 useEffect 中返回未定义
- python - 在 python 中切换到虚拟环境后尝试运行代码时,VS Code 总是出错
- flutter - 如何使用 http 包获取内容配置标头?
- javascript - 无法读取未定义节点 js 的属性“文件名”
- c# - C# 中的 IConfiguration 功能
- r - R 总是显示“错误:1:8:意外输入 1:PATH=C:\ ^”
- python - OSError: [WinError 193] %1 在使用 ctypes 时不是有效的 Win32 应用程序
- javascript - 如何通过硒访问链接?
- reactjs - 单击弹出框时,页面的整个内容(背景除外)消失