如何在 DM 脚本中更改浮动调色板的宽度
How to change the width of a floating pallete in DM scripting
现在我正在尝试编写一个 DM 脚本来显示浮动调色板,如以下代码所示。但是,例如,此代码中包含的长字符串标签从调色板 window 中突出。所以,我想知道如何更改调色板 window 大小(即本例中的宽度)。实际上,一些 Gatan 的官方调色板 windows 例如 "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)
Be aware that the situation of floating palettes is different between GMS 2.x
and GMS 3.x
.
Essentially, registered floating palettes are phased out in GMS 3.x
with the new UI. They are still supported to some extend, but not all functionality remains and some behavior is buggy. For GMS 3.x
it is generally better to launch scripted dialogs as modal or modeless dialogs and no longer install them as palettes.
此答案适用于 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"
超宽
但是,position 标签还有一些附加选项,但它们不适用于浮动调色板,仅适用于常规 无模式对话框。您可以使用 绝对大小 值设置 window 的宽度和高度,或者让它 自动确定 的大小内容。这是一个例子:
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()
中,将应用程序 window 设置为对话框的参考框架。然后可以使用命令 DLGBuildRelativePosition()
和 -1|0|1
作为相应参数来定义对话框的左|中|右和上|中|下到该帧的位置,如示例所示:
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()
不过,参考框架不一定是应用程序 window。您可以使用 DLGBuildPosition()
指定任何想要的,这允许使用 f.e。一个 window 矩形,然后将对话框放在它的右边。使用参考框架,还可以相对于使用 DLGBuildMatchSize()
调整对话框 window 的大小,如下例所示:
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)
现在我正在尝试编写一个 DM 脚本来显示浮动调色板,如以下代码所示。但是,例如,此代码中包含的长字符串标签从调色板 window 中突出。所以,我想知道如何更改调色板 window 大小(即本例中的宽度)。实际上,一些 Gatan 的官方调色板 windows 例如 "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)
Be aware that the situation of floating palettes is different between
GMS 2.x
andGMS 3.x
.
Essentially, registered floating palettes are phased out inGMS 3.x
with the new UI. They are still supported to some extend, but not all functionality remains and some behavior is buggy. ForGMS 3.x
it is generally better to launch scripted dialogs as modal or modeless dialogs and no longer install them as palettes.
此答案适用于 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"
超宽
但是,position 标签还有一些附加选项,但它们不适用于浮动调色板,仅适用于常规 无模式对话框。您可以使用 绝对大小 值设置 window 的宽度和高度,或者让它 自动确定 的大小内容。这是一个例子:
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()
中,将应用程序 window 设置为对话框的参考框架。然后可以使用命令 DLGBuildRelativePosition()
和 -1|0|1
作为相应参数来定义对话框的左|中|右和上|中|下到该帧的位置,如示例所示:
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()
不过,参考框架不一定是应用程序 window。您可以使用 DLGBuildPosition()
指定任何想要的,这允许使用 f.e。一个 window 矩形,然后将对话框放在它的右边。使用参考框架,还可以相对于使用 DLGBuildMatchSize()
调整对话框 window 的大小,如下例所示:
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)