用下面兩個檔案就可以在AEDT底下生成一個包含combo box的簡單視窗.
template.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Application" Height="120" Width="240" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Grid>
<ComboBox x:Name="item_cb" VerticalAlignment="Top" Margin="10,10,10,0" SelectedIndex="0">
<ComboBoxItem Content="item1"/>
</ComboBox>
<Button x:Name="Run_bt" Content="Run" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="75" Margin="0,40,10,10" Height="30" Click="Run_bt_Click"/>
</Grid>
</Window>
template.py
import os, sys, re, clr
import math, cmath
import collections
win64_dir = oDesktop.GetExeDir()
dll_dir = os.path.join(win64_dir, 'common/IronPython/DLLs')
sys.path.append(dll_dir)
clr.AddReference('IronPython.Wpf')
import copy
import wpf
from System.Windows import Window, MessageBox
from System.Windows.Controls import ListBoxItem
from System.Windows.Forms import OpenFileDialog, SaveFileDialog, DialogResult, FolderBrowserDialog
os.chdir(os.path.dirname(__file__))
# Functions---------------------------------------------------------------------|
# GUI---------------------------------------------------------------------------|
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'template.xaml')
obj = self.item_cb.Items[0]
self.item_cb.Items.Clear()
for i in ['A1', 'A2', 'A3']:
x = copy.deepcopy(obj)
x.Content = i
self.item_cb.Items.Add(x)
self.item_cb.SelectedIndex = 0
def Run_bt_Click(self, sender, e):
AddWarningMessage(self.item_cb.SelectedItem.Content)
# Code End----------------------------------------------------------------------|
MyWindow().ShowDialog()
(圖一) AEDT的簡單combo box |
沒有留言:
張貼留言