Abaqus GUI程序开发之常用控件使用方法(十七):图标的创建及使用方法

一、引言

为了使插件程序或者自定义应用程序显示得更加直观,经常需要对某些功能键添加一个特有的图标,让用户可以直接根据图标的形式直观地明白该按键对应的功能(如图所示)。

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'
)
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是刃小木啦~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值