天天看点

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

一、调整对话框尺寸

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

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

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

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

二、行列布局管理器

当一个窗体中控件数量较多时,除了使用FXHorizontalFrame和 FXVerticalFrame控件来布置子控件的布局之外,还可以使用行列布局管理器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)排布。

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

按列排列:

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

按行排列

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

代码:

界面文件【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'
)