复选框指可以同时选中多个选项的按钮。
复选框的基本语法
FXCheckButton(p, text, tgt=None, sel=0, opts=CHECKBUTTON_NORMAL,
x=0, y=0, w=0, h=0, pl=DEFAULT_PAD,
pr=DEFAULT_PAD, pt=DEFAULT_PAD, pb=DEFAULT_PAD)
参数的含义和前面的单选框、按钮都差不多,在这不再展示。
注意:每个复选框对应一个关键字,推荐使用RSG对话框对构造器中创建复选框,方便快捷。
实例演示
本实例是一个简单的复选框测试插件,主要由图形界面文件【testcheckbuttonDB.py】以及注册文件【testcheckbutton_plugin.py】组成。
判断复选框是否被选中
对于复选框按钮,其关键字的返回值为True或者False,例如上述实例中复选框“SOLID”对应的关键字分别为ele_solid,如果该复选框被勾选了,则ele_solid值为True,反之为False。因此在内核文件中添加一个if语句即可判断其是否被选中。
def testcheckbutton(ele_solid,ele_shell):
if cle_solid =-True:
#表示被勾选
#省略执行代码
else:
#表示未被勾选
#省略执行代码
附代码
【testcheckbutton_plugin.py】
from abaqusGui import *
from abaqusConstants import ALL
import osutils, os
###########################################################################
# Class definition
###########################################################################
class testcheckbutton_plugin(AFXForm):
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self, owner):
# Construct the base class.
#
AFXForm.__init__(self, owner)
self.radioButtonGroups = {}
self.cmd = AFXGuiCommand(mode=self, method='',
objectName='', registerQuery=False)
pickedDefault = ''
self.ele_solidKw = AFXBoolKeyword(self.cmd, 'ele_solid',
AFXBoolKeyword.TRUE_FALSE, True, True)
self.ele_shellKw = AFXBoolKeyword(self.cmd, 'ele_shell',
AFXBoolKeyword.TRUE_FALSE, True, False)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getFirstDialog(self):
import testcheckbuttonDB
return testcheckbuttonDB.testcheckbuttonDB(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
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Register the plug-in
#
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(
buttonText='test checkbutton',
object=testcheckbutton_plugin(toolset),
messageId=AFXMode.ID_ACTIVATE,
icon=None,
kernelInitString='',
applicableModules=ALL,
version='N/A',
author='N/A',
description='N/A',
helpUrl='N/A'
)
【testcheckbuttonDB.py】
from abaqusConstants import *
from abaqusGui import *
from kernelAccess import mdb, session
import os
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
class testcheckbuttonDB(AFXDataDialog):
def __init__(self, form):
AFXDataDialog.__init__(self, form, 'Test Check Button',
self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR)
okBtn = self.getActionButton(self.ID_CLICKED_OK)
okBtn.setText('OK')
GroupBox_1 = FXGroupBox(p=self, text='Element type', opts=FRAME_GROOVE)
FXCheckButton(p=GroupBox_1, text='SOLID', tgt=form.ele_solidKw, sel=0)
FXCheckButton(p=GroupBox_1, text='SEHLL', tgt=form.ele_shellKw, sel=0)