當我們在App Builder建立了選單之後,可以輸出.xml及.py檔。在.xml當中<step>層級底下加入<onrefresh></onrefresh>標籤,並在當中呼叫RefreshChoice函數。
combobox.xml的內容
<!-- autogenerated by XmlWriter ( 15/11/2020 05:32:32 ) -->
<extension name="combobox">
<imagedirectory>.</imagedirectory>
<guid>b39d25c3-456b-47db-93fa-31e4f172e169</guid>
<script src="IDEGeneratedMain.py" />
<wizard name="cb" caption="cb" version="1" context="ElectronicsDesktop">
<step name="Step_1" version="0" caption="Step_1">
<property control="select" name="design" caption="design" persistent="False" parameterizable="False">
<attributes options="Refresh" />
</property>
<callbacks>
<onrefresh>RefreshChoice</onrefresh>
</callbacks>
</step>
</wizard>
</extension>
在.py檔當中,定義RefreshChoice函數,當中讀取專案底下所有的設計並加到下拉選單當中。
IDEGeneratedMain.py的內容
def onupdateStep(step):
pass
def RefreshChoice(step):
Designs_Field = step.Properties["design"]
Designs_Field.Options.Clear()
ActiveProject = oDesktop.GetActiveProject()
DesignList = ActiveProject.GetTopDesignList()
if len(DesignList) != 0:
ActiveDesign = ActiveProject.GetActiveDesign()
for design in DesignList:
Designs_Field.Options.Add(design)當啟動ACT之後,點一下下拉選單的Refresh選項之後,下拉選單便會更新加入所有的設計名稱。
(圖一)下拉選單在Refresh之後會加入所有設計的名稱 |
沒有留言:
張貼留言