一、引言
为了使插件程序或者自定义应用程序显示得更加直观,经常需要对某些功能键添加一个特有的图标,让用户可以直接根据图标的形式直观地明白该按键对应的功能(如图所示)。
Abaqus/CAE界面下采用了大量的图标,Abaqus GUI控件中,绝大多数控件都可以通过icon参数设置相应的图标。
二、创建图标函数
在Abaqus 二次开发中,支持创建为图标文件的图片格式有多种,用户可以通过不同的函数命令将不同格式的图片创建为图标,具体如下。
(1)函数afxCreatelcon(fileName),支持BMP、GIF、 PNG、XPM多种格式的图片,使用此函数时无须声明图标文件格式。
- icon= afxCreatelcon(os.path.join(thisDir, 'my_icon.png’) )
(2)函数afxCreateBMPIcon(fileName),仅支持 BMP格式文件。
- icon = afxCreateBMPlcon(os.path.join(thisDir,"my_icon.bmp’))
(3)函数afxCreateGIFIcon(fileName),仅支持GIF格式文件。
- icon= afxCreateGIFIcon(os.path.join(thisDir, "my_icon.gif’))
(4)函数afxCreatePNGlcon(fileName),仅支持PNG格式文件。
- icon = afxCreatePNGIcon(os.path.join(thisDir, "my_icon.png'))
(5)函数afxCreateXPMIcon(fileName),仅支持XPM格式文件。
- icon = afxCreateXPMIcon(os.path.join(thisDir, 'my_icon.xpm’))
三、实例演示
效果
有原材料如下:
代码
图形界面【TESTICONDB.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 TESTICONDB(AFXDataDialog):
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self, form):
AFXDataDialog.__init__(self, form, 'Test Icon',
self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR)
okBtn = self.getActionButton(self.ID_CLICKED_OK)
okBtn.setText('OK')
#png文件
fileName1 = os.path.join(thisDir, 'icon_up.png')
icon_up = afxCreatePNGIcon(fileName1)
#bmp文件
fileName2 = os.path.join(thisDir, 'icon_down.bmp')
icon_down = afxCreateBMPIcon(fileName2)
#创建带图标的按钮
FXButton(p=self, text='UP', ic=icon_up , tgt=None, sel=0)
FXButton(p=self, text='DOWN', ic=icon_down, tgt=None, sel=0)
注册文件【TESTICON_plugin.py】
这里的icon是在下拉菜单里的那个图标
# -* - coding:UTF-8 -*-
from abaqusGui import *
from abaqusConstants import ALL
import osutils, os
class TESTICON_plugin(AFXForm):
def __init__(self, owner):
AFXForm.__init__(self, owner)
self.radioButtonGroups = {}
self.cmd = AFXGuiCommand(mode=self, method='',
objectName='', registerQuery=False)
pickedDefault = ''
def getFirstDialog(self):
import TESTICONDB
return TESTICONDB.TESTICONDB(self)
def doCustomChecks(self):
for kw1,kw2,d in self.radioButtonGroups.values():
try:
value = d[ kw1.getValue() ]
kw2.setValue(value)
except:
pass
return True
def okToCancel(self):
return False
thisPath = os.path.abspath(__file__)
thisDir = os.path.dirname(thisPath)
icon1= afxCreateIcon( os.path.join(thisDir, 'icon1.png') ) #创建插件图标
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(
buttonText='测试图标',
object=TESTICON_plugin(toolset),
messageId=AFXMode.ID_ACTIVATE,
icon=icon1,
kernelInitString='',
applicableModules=ALL,
version='N/A',
author='N/A',
description='N/A',
helpUrl='N/A'
)