Abaqus GUI程序开发之常用控件使用方法(十五):自定义下拉框控件AFXComboBox使用方法

编程入门 行业动态 更新时间:2024-10-07 06:46:10

Abaqus GUI程序开发之常用<a href=https://www.elefans.com/category/jswz/34/1769529.html style=控件使用方法(十五):自定义下拉框控件AFXComboBox使用方法"/>

Abaqus GUI程序开发之常用控件使用方法(十五):自定义下拉框控件AFXComboBox使用方法

通常情况下,用户可以在RSG对话框构造器中快速创建下拉框,并自动生成代码,RSG对话框构造器提供了Standard、MDB repository和 ODB repository三类下拉框。

  • Standard类型为普通的下拉框
  • MDB repository类型为包含了Abaqus模型数据库的下拉框,用户可以在其中选择零件、载荷、分析步、材料等信息
  • ODBrepository类型是包含了Abaqus 计算结果数据库的下拉框,用户可以在其中选择零件、实例、单元集、材料等信息

 建议尽可能采用Abaqus RSG对话框构造器内嵌的MDB repository和 ODB repository类型的下拉框,当上述两种类型满足不了使用要求时再选用 Standard类型的下拉框。

基本语法

AFXComboBox(p, ncols, nvis, text, tgt=None, sel=0, opts=0,x=0, y=0, w=0, h=0, pl=DEFAULT_PAD, pr=DEFAULT_PAD,pt=DEFAULT_PAD, pb=DEFAULT_PAD)

实例演示

打开上述插件程序,当切换模型、零件或者创建新的集合时,自定义的下拉框中会自动更新,程序的执行效果如图4.30所示。可以参照该实例创建更多类型的自定义下拉框。

代码及过程展示

首先在RSG对话框构造器中分别创建一个MDB repository类型和 Standard标准型下拉框,将插件保存后会自动生成部分代码,所生成的代码中有关MDB repository类型下拉框部分不需要修改,标准型下拉框需要修改。注册文件由RSG对话框构造器自动生成,未进行修改。

保存后自动生成的代码 

【 testCombo_plugin.py 】

from abaqusGui import getAFXApp, Activator, AFXMode
from abaqusConstants import ALL
import os
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(buttonText='Combo', object=Activator(os.path.join(thisDir, 'testComboDB.py')),kernelInitString='',messageId=AFXMode.ID_ACTIVATE,icon=None,applicableModules=ALL,version='N/A',author='N/A',description='N/A',helpUrl='N/A'
)

【 testComboDB.py 】

from rsg.rsgGui import *
from abaqusConstants import INTEGER, FLOAT
execDir = os.path.split(thisDir)[1]
dialogBox = RsgDialog(title='Com', kernelModule='', kernelFunction='', includeApplyBtn=False, includeSeparator=True, okBtnText='OK', applyBtnText='Apply', execDir=execDir)
RsgComboBox(name='ComboBox_1', p='DialogBox', text='Part:', keyword='partName', default='', comboType='MDB', repository='parts', rootText='Model:', rootKeyword='modelName', layout='HORIZONTAL')
RsgComboBox(name='ComboBox_2', p='DialogBox', text='set', keyword='setName', default='', comboType='STANDARD', repository='', rootText='', rootKeyword=None, layout='')
RsgListItem(p='ComboBox_2', text='Item 1')
RsgListItem(p='ComboBox_2', text='Item 2')
RsgListItem(p='ComboBox_2', text='Item 3')
dialogBox.show()

修改自动生成的代码

testCombo_plugin.py

# -* - coding:UTF-8 -*-
from abaqusGui import *
from abaqusConstants import ALL
import osutils, os###########################################################################
# Class definition
###########################################################################class testcombobox_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.modelNameKw = AFXStringKeyword(self.cmd, 'modelName', True)self.partNameKw = AFXStringKeyword(self.cmd, 'partName', True)self.elesetKw = AFXStringKeyword(self.cmd, 'eleset', True)#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~def getFirstDialog(self):import testcomboboxDBreturn testcomboboxDB.testcomboboxDB(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:passreturn 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 combobox', object=testcombobox_plugin(toolset),messageId=AFXMode.ID_ACTIVATE,icon=None,kernelInitString='',applicableModules=ALL,version='N/A',author='N/A',description='N/A',helpUrl='N/A'
)

【testComboDB.py】 

# -* - coding:UTF-8 -*-
from abaqusConstants import *
from abaqusGui import *
from kernelAccess import mdb, session
import os
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
class testcomboboxDB(AFXDataDialog):def __init__(self, form):AFXDataDialog.__init__(self, form, '测试下拉框',self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR)okBtn = self.getActionButton(self.ID_CLICKED_OK)okBtn.setText('OK')frame = FXHorizontalFrame(self, 0, 0,0,0,0, 0,0,0,0)#系统自动创建MDB repository类型下拉框,父级对象为modelself.RootComboBox_1 = AFXComboBox(p=frame, ncols=0, nvis=1, text='Model:', tgt=form.modelNameKw, sel=0)self.RootComboBox_1.setMaxVisible(10)names = mdb.models.keys()names.sort()for name in names:self.RootComboBox_1.appendItem(name)if not form.modelNameKw.getValue() in names:form.modelNameKw.setValue( names[0] )msgCount = 7form.modelNameKw.setTarget(self)form.modelNameKw.setSelector(AFXDataDialog.ID_LAST+msgCount)msgHandler = str(self.__class__).split('.')[-1] + '.onComboBox_1PartsChanged'exec('FXMAPFUNC(self, SEL_COMMAND, AFXDataDialog.ID_LAST+%d, %s)'% (msgCount, msgHandler) )# 系统自动创建MDB repository类型下拉框,子对象为partself.ComboBox_1 = AFXComboBox(p=frame, ncols=0, nvis=1, text='Part:', tgt=form.partNameKw, sel=0)self.ComboBox_1.setMaxVisible(10)self.form = form#系统自动生成的标准型下拉框,对象为空self.ComboBox_2 = AFXComboBox(p=self, ncols=0, nvis=1, text='set:', tgt=form.elesetKw, sel=0)self.ComboBox_2.setMaxVisible(10)#新增代码,创建单元集合下拉框msgCount4 = 45form.partNameKw.setTarget(self)    #设置目标form.partNameKw.setSelector(AFXDataDialog.ID_LAST+msgCount4)  #设置消息IDmsgHandler4 = str(self.__class__).split('.')[-1] + '.onComboBox_2elesetChanged'           exec('FXMAPFUNC(self, SEL_COMMAND, AFXDataDialog.ID_LAST+%d, %s)' % (msgCount4, msgHandler4) ) #消息映射def show(self):AFXDataDialog.show(self)self.currentModelName = getCurrentContext()['modelName']self.form.modelNameKw.setValue(self.currentModelName)mdb.models[self.currentModelName].parts.registerQuery(self.updateComboBox_1Parts)mdb.models[self.currentModelName].parts.registerQuery(self.updateComboBox_2eleset)#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~def hide(self):AFXDataDialog.hide(self)mdb.models[self.currentModelName].parts.unregisterQuery(self.updateComboBox_1Parts)mdb.models[self.currentModelName].parts.unregisterQuery(self.updateComboBox_2eleset)#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~def onComboBox_1PartsChanged(self, sender, sel, ptr):self.updateComboBox_1Parts()return 1#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~def updateComboBox_1Parts(self):modelName = self.form.modelNameKw.getValue()# Update the names in the Parts combo#self.ComboBox_1.clearItems()names = mdb.models[modelName].parts.keys()names.sort()for name in names:self.ComboBox_1.appendItem(name)if names:if not self.form.partNameKw.getValue() in names:self.form.partNameKw.setValue( names[0] )else:self.form.partNameKw.setValue('')self.resize( self.getDefaultWidth(), self.getDefaultHeight() )#新增sets更新#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~def onComboBox_2elesetChanged(self, sender, sel, ptr):    #自定义下拉框函数self.updateComboBox_2eleset()return 1#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~def updateComboBox_2eleset(self):                    #更新下拉框内容modelName = self.form.modelNameKw.getValue()partName = self.form.partNameKw.getValue()# Update the names in the Parts comboif partName!='':    #判断是否有part,避免在无零件时报错self.ComboBox_2.clearItems()names = mdb.models[modelName].parts[partName].sets.keys()#指向零件的所有集合names.sort()for name in names:self.ComboBox_2.appendItem(name)                 #逐项添加到下拉框中if names:if not self.form.elesetKw.getValue() in names:self.form.elesetKw.setValue( names[0] )else:self.form.elesetKw.setValue('')self.resize( self.getDefaultWidth(), self.getDefaultHeight() )

更多推荐

Abaqus GUI程序开发之常用控件使用方法(十五):自定义下拉框控件AFXComboBox使用方法

本文发布于:2024-02-28 05:41:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1768406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   使用方法   自定义   程序开发   常用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!