Abaqus GUI程序开发之常用控件使用方法(二十五):调整对话框尺寸及行列布局管理

本文介绍了如何在ABAQUS中自定义用户界面,包括调整对话框尺寸和使用行列布局管理器FXMatrix进行控件布局。通过在创建对话框时添加DECOR_RESIZE选项,可以实现对话框大小的调节。同时,FXMatrix允许按行或按列排列多个控件,便于复杂界面的构建。示例展示了FXMatrix如何用于按列和按行排列六个按钮的代码实现。
摘要由CSDN通过智能技术生成

一、调整对话框尺寸

默认情况下,用户创建的对话框大小是不可调节的,以带孔板参数化建模程序为例,其对话框的创建代码如下。

在设置窗口的后面,增加一个DECOR_RESIZE

 

二、行列布局管理器

当一个窗体中控件数量较多时,除了使用FXHorizontalFrameFXVerticalFrame控件来布置子控件的布局之外,还可以使用行列布局管理器FXMatrix对多个控件按行按列进行排布。

FXMatrix(p, n=1, opts=MATRIX_BY_ROWS, 
    x=0, y=0, w=0, h=0,pl=DEFAULT_SPACING, 
    pr=DEFAULT_SPACING,pt=DEFAULT_SPACING, 
    pb=DEFAULT_SPACING,hs=DEFAULT_SPACING, 
    vs=DEFAULT_SPACING)

其中n为行数或者列数,在opts 参数中可以指定按行(MATRIX_BY_ROWS)或者按列(MATRIX_BY_COLUMNS)排布。

实例展示:对六个按钮进行排版

按列排列:

 

按行排列

 

代码:

界面文件【testFXMatrixDB.py】

from abaqusConstants import *
from abaqusGui import *
from kernelAccess import mdb, session
class testFXMatrixDB(AFXDataDialog):
    def __init__(self, form):

        AFXDataDialog.__init__(self, form, 'Test FXMatrix',
            self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR)          

        okBtn = self.getActionButton(self.ID_CLICKED_OK)
        okBtn.setText('OK')
                  
        m=FXMatrix(self, n=3,opts=MATRIX_BY_ROWS)               
        FXButton(m, 'Button 1')
        FXButton(m, 'Button 2')
        FXButton(m, 'Button 3')
        FXButton(m, 'Button 4')
        FXButton(m, 'Button 5')
        FXButton(m, 'Button 6') 

注册文件【testFXMatrix_plugin.py】

# -* - coding:UTF-8 -*- 
from abaqusGui import *
from abaqusConstants import ALL
import osutils, os

class testFXMatrix_plugin(AFXForm):
    [
        ID_WARNING,
    ] = range(AFXForm.ID_LAST, AFXForm.ID_LAST+1)
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def __init__(self, owner):
        
        # Construct the base class.
        #
        AFXForm.__init__(self, owner)
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def getFirstDialog(self):

        import testFXMatrixDB
        return testFXMatrixDB.testFXMatrixDB(self)

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def doCustomChecks(self):

        # Try to set the appropriate radio button on. If the user did
        # not specify any buttons to be on, do nothing.
        #
        for kw1,kw2,d in self.radioButtonGroups.values():
            try:
                value = d[ kw1.getValue() ]
                kw2.setValue(value)
            except:
                pass            
        return True    

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def okToCancel(self):

        # No need to close the dialog when a file operation (such
        # as New or Open) or model change is executed.
        #
        return False
    def onCmdWarning(self, sender, sel, ptr):

        if sender.getPressedButtonId() == \
            AFXDialog.ID_CLICKED_YES:
                self.issueCommands()
        elif sender.getPressedButtonId() == \
            AFXDialog.ID_CLICKED_NO:
                self.deactivate() 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Register the plug-in
#
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)

toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(
    buttonText='testFXMatrix', 
    object=testFXMatrix_plugin(toolset),
    messageId=AFXMode.ID_ACTIVATE,
    icon=None,
    kernelInitString='',
    applicableModules=ALL,
    version='N/A',
    author='N/A',
    description='N/A',
    helpUrl='N/A'
)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是刃小木啦~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值