如何创建一个允许换行符(通过按 Enter 键)并将其复制到字符串的文本框?
我正在尝试生成一个类似于 Digital Micrograph 中的 Image Info 文本框的对话框。此文本框将用于创建在最前面的图像上创建的文本注释。
DLGCreateTextBox 可以创建多行文本框,但它似乎不允许换行。
我搜索了DM Scripting和TU Graz 脚本数据库页面,但没有看到任何使用这种文本框的内容。
如何创建一个允许换行符(通过按 Enter 键)并将其复制到字符串的文本框?
我正在尝试生成一个类似于 Digital Micrograph 中的 Image Info 文本框的对话框。此文本框将用于创建在最前面的图像上创建的文本注释。
DLGCreateTextBox 可以创建多行文本框,但它似乎不允许换行。
我搜索了DM Scripting和TU Graz 脚本数据库页面,但没有看到任何使用这种文本框的内容。
不幸的是,对话框文本框并不是 DigitalMicrograph 脚本对话框中最方便的对话框项。有几点需要知道:
pose()
),返回键将立即充当“好的”并关闭对话框!考虑到这一点,以下示例脚本创建了一个文本框字段,其中可能包含换行符(返回)。但是,只有通过使用附加到按钮的“复制”操作,才能将文本“存储”在一个变量中,该变量可以在对话框关闭后访问。
class myDLG : UIFrame
{
string textBuffer
tagGroup CreateDLGSelf( object self )
{
number width = 20 // line width of box
number height = 10 // number of lines
number length = 500 // maximum length (characters) of content
TagGroup textBox = DLGCreateTextBox( width, height, length )
textBox.DLGIdentifier( "textBox" )
TagGroup StoreButton = DLGCreatePushButton( "Store" , "StoreText" )
TagGroup DLG, DLGitems
DLG = DLGCreateDialog( "TestBox", DLGitems )
DLGitems.DLGAddElement( textBox )
DLGitems.DLGAddElement( StoreButton )
return DLG
}
void StoreText( object self )
{
textBuffer = self.GetTextElementData( "textBox" )
}
string GetBufferedText( object self )
{
return textBuffer
}
object Init( object self )
{
return self.Super.Init( self.CreateDLGSelf() )
}
}
// Main script
{
object testDLG = Alloc(myDLG).Init()
if ( testDLG.pose() )
OKDialog( "Text:" + testDLG.GetBufferedText() )
}
如果对话框是无模式的(即通过 显示display()
),则可以直接访问这些字段。以下脚本演示了这一点 - 以及此类对话框如何在图像上创建注释标记。
class annoTool : UIFrame
{
tagGroup CreateToolDlg( object self )
{
number width = 50 // line width of box
number height = 5 // number of lines
number length = 300 // maximum length (characters) of content.
TagGroup textBox = DLGCreateTextBox( width, height, length )
textBox.DLGIdentifier("textBox")
TagGroup CreatAnnoButton = DLGCreatePushButton( "Copy to Image" , "CreateAnno" )
TagGroup InitTextButton = DLGCreatePushButton( "Intitialze" , "InitTextField" )
TagGroup DLG, DLGitems
DLG = DLGCreateDialog( "TestBox", DLGitems )
DLGitems.DLGAddElement( textBox )
DLGitems.DLGAddElement( DLGGroupItems( InitTextButton, CreatAnnoButton ).DLGTableLayout(2,1,0) )
return DLG
}
void InitTextField( object self )
{
string init = ""
init += "Date:" + GetDate(1) + "\n"
init += "Time:" + GetTime(0) + "\n"
init += "(c) My TEM Institute"
self.SetTextElementData( "textBox", init )
}
void CreateAnno( object self )
{
image front
string textBuffer = self.GetTextElementData("textBox")
if ( GetFrontImage(front) )
{
CreateTextAnnotation( front, 0, 0, textBuffer)
}
}
object Init( object self )
{
return self.Super.Init( self.CreateToolDlg() )
}
}
// Main script
{
Alloc(annoTool).Init().display( "Annotation Creater" )
}