树列表控件无法在RSG对话框构造器中直接创建,需要用户自己编写GUI命令。
树如下面所示:
基本语法
FXTreeList(p,nvis,tgt=None,sel=0,opts=TREELIST_NORMAL,x=0,y=0,w=0,h=0)
-
参数p(parent)为父级控件
-
nvis(number of visible items)为树控件的可显示项个数
-
tgt指向控件的目标对象
-
sel指定的是消息ID
-
其他参数与前面控件一致
树创建完成后,再添加项目:
addItemAfter(other, text, oi=None, ci=None, notify=False)
addItemBefore(other, text, oi=None, ci=None,notify=False)
addItemFirst(p, text, oi=None, ci=None, notify=False)
addItemLast(p, text, oi=None, ci=None, notify=False)
oi表示的是项目被选中时的图标,ci表示的是项目未被选中时的图标。
实例演示
效果是这样的:
代码展示
注册文件【testtreelist_plugin.py】
from abaqusGui import *
from abaqusConstants import ALL
import osutils, os
###########################################################################
# Class definition
###########################################################################
class testtreelist_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)
self.treeKw = AFXFloatKeyword(self.cmd, 'tree', True)
pickedDefault = ''
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getFirstDialog(self):
import testtreelistDB
return testtreelistDB.testtreelistDB(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 treelist',
object=testtreelist_plugin(toolset),
messageId=AFXMode.ID_ACTIVATE,
icon=None,
kernelInitString='',
applicableModules=ALL,
version='N/A',
author='N/A',
description='N/A',
helpUrl='N/A'
)
界面文件【testtreelistDB.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 testtreelistDB(AFXDataDialog):
[
ID_CLICKED,
] = range(AFXForm.ID_LAST, AFXForm.ID_LAST+1) #分配ID
def __init__(self, form):
AFXDataDialog.__init__(self, form, 'Test Treelist',
self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR)
okBtn = self.getActionButton(self.ID_CLICKED_OK)
okBtn.setText('OK')
vf = FXHorizontalFrame(p=self, opts=FRAME_SUNKEN|FRAME_THICK,
x=0, y=0, w=100, h=0,
pl=0, pr=DEFAULT_SPACING, pt=DEFAULT_SPACING, pb=DEFAULT_SPACING)
self.tree = FXTreeList(vf, 10, tgt=self, sel=self.ID_CLICKED,
opts=LAYOUT_FILL_X|LAYOUT_FILL_Y|
TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|
TREELIST_SHOWS_LINES|LAYOUT_FIX_WIDTH,
x=0, y=0, w=120, h=0) #定义数列表,指定其目标与ID
FXMAPFUNC(self,SEL_COMMAND,self.ID_CLICKED,testtreelistDB.onCmdTree) #消息映射
#定义图标
Icon1 =afxCreateIcon(os.path.join(thisDir, 'ico1.png') )
Icon2 =afxCreateIcon(os.path.join(thisDir, 'ico2.png') )
#添加项目
option1 = self.tree.addItemLast(None, 'Option 1') #创建树1,一级树
self.tree.addItemLast(option1, 'Option 1a',oi=Icon1,ci=Icon2) #创建树1的分支1a,且有图标的变化,二级树
self.tree.addItemLast(option1, 'Option 1b') #创建树1的分支1b,二级树
option2 = self.tree.addItemLast(None, 'Option 2') #创建树2,一级树
self.tree.addItemLast(option2, 'Option 2a') #创建树2的分支2a,二级树
option2b = self.tree.addItemLast(option2, 'Option 2b') #创建树2的分支2b,二级树,并且赋值给option2b
self.tree.addItemLast(option2b, 'Option 2bi') #创建树2b的分支2bi,三级树
option3 = self.tree.addItemLast(None, 'Option 3') #创建一个光秃秃的一级树3
def onCmdTree(self, sender, sel, ptr):
w = self.tree.getFirstItem()
while(w):
if self.tree.isItemSelected(w):
item=self.tree.getCurrentItem()
text=self.tree.getItemText(item)
print '%s was selected.' % text
break
if w.getFirst():
w=w.getFirst()
continue
while not w.getNext() and w.getParent():
w=w.getParent()
w=w.getNext()