-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathSwitch Generator.py
102 lines (81 loc) · 3.15 KB
/
Switch Generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import clr
import os
# Verify these are needed.
clr.AddReference('System')
clr.AddReference('System.Drawing')
clr.AddReference("System.Windows.Forms")
# Windows Forms Elements
from System.Drawing import Point, Icon, Color
from System.Windows import Forms
from System.Windows.Forms import Application, Form, TextBox, Label, MessageBox
from System.Windows.Forms import DialogResult, GroupBox, FormBorderStyle
from System.Windows.Forms import ComboBox, Button, DialogResult, FormStartPosition
from System.Drawing import Size, Color, SolidBrush, Rectangle
class SelectFromList(Form):
"""
form = SelectFromList(floor_types.keys())
form.show()
if form.DialogResult == DialogResult.OK:
chosen_type_name = form.selected
"""
def __init__(self):
# Window Settings
self.Text = 'Switch Generator'
self.Width = 200
self.Height = 220
self.MinimizeBox = False
self.MaximizeBox = False
self.BackgroundColor = Color.Red
self.FormBorderStyle = FormBorderStyle.FixedSingle
self.ShowIcon = False
self.label1 = Label()
self.label1.Text='Input number:'
self.label1.Location= Point(10,0)
self.tb=TextBox()
self.tb.Text="8"
self.tb.Location = Point(10,25)
self.tb.Width=160
self.label2 = Label()
self.label2.Text='file name:'
self.label2.Location= Point(10,60)
self.filepath=TextBox()
self.filepath.Text="c:/switch.cir"
self.filepath.Location = Point(10,85)
self.filepath.Width=160
button = Button()
button.Text = 'Generate'
button.Location = Point(10,120)
button.Width = 100
button.Height = 30
button.Click += self.button_click
self.Controls.Add(self.label1)
self.Controls.Add(self.tb)
self.Controls.Add(self.label2)
self.Controls.Add(self.filepath)
self.Controls.Add(button)
def button_click(self, sender, event):
number=int(self.tb.Text)
file=self.filepath.Text
netlist='.subckt switch in '+ ' '.join(['o'+str(i+1) for i in range(number)]) +' on=1 Zt=50\n'
for i in range(number):
if i==0:
netlist+='.if(on=={})\n'.format(i+1)
else:
netlist+='.elseif(on=={})\n'.format(i+1)
for j in range(number):
if i==j:
netlist+='r{0} o{0} in 0\n'.format(j+1)
else:
netlist+='r{0} o{0} 0 Zt\n'.format(j+1)
netlist+='.else\n'
netlist+='\n'.join(['r{0} o{0} 0 Zt'.format(i+1) for i in range(number)])
netlist+='\n.endif\n.ends'
with open(file, 'w') as f:
f.writelines(netlist)
MessageBox.Show(self.filepath.Text + " is generated!")
def show(self):
""" Show Dialog """
self.StartPosition = FormStartPosition.CenterParent;
self.ShowDialog()
form1 = SelectFromList()
form1.show()