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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
#!/usr/bin/python
# newProject.py is a python script to create a new project. It is developed for OSCAD software. It is written by Yogesh Dilip Save (yogessave@gmail.com).
# Copyright (C) 2012 Yogesh Dilip Save, FOSS Project, IIT Bombay.
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from setPath import OSCAD_HOME
from Tkinter import *
import thread
import ttk
import sys
import subprocess, time
import template
import tkMessageBox
import os.path
import os
import toolTip
import selectOption
from string import maketrans
from PIL import Image, ImageTk
class ProjectInfo(template.MyTemplate):
""" Class for accept model information from user """
def body(self, master):
# Ask for project name
try:
Label(master, text="Enter Project name:").grid(row=0)
self.e1 = Entry(master)
self.e1.grid(row=0, column=1,pady=10,columnspan=2)
except:
print "error"
# Collect project information
def apply(self):
""" a method for writing project information to the file"""
self.text.insert(END, "Creating new project " + self.projectName+" ...... \n")
self.text.yview(END)
# Cerate directory for the project
try:
os.mkdir(self.projectName)
except:
tkMessageBox.showwarning("Error","Directory already exists")
self.text.insert(END, " The project directory "+self.projectName+"has been created.\n")
self.text.yview(END)
os.chdir(self.projectName)
self.text.insert(END, " Entered into the project directory "+self.projectName+"\n")
self.text.yview(END)
# Create model file for writing
try:
f = open(self.projectName+".proj","w")
except :
tkMessageBox.showwarning("Error","Project information file can not be wriiten. please check the file system permission")
return 0
f.write("schematicFile " + self.projectName+".sch\n")
f.close()
self.text.insert(END, "Successfully Created new project " + self.projectName+". \n")
self.text.yview(END)
return 1
# Validate the model information
def validate(self):
# Remove trailing and leading spaces from modelName
self.projectName=self.e1.get().strip()
if len(self.projectName):
if os.path.exists(self.projectName+".proj"):
tkMessageBox.showwarning("Bad input","Project already exists, please try again")
return 0
return 1
else:
tkMessageBox.showwarning("Bad input","Project Name is not specified, please try again")
return 0
class ProjectParam(template.MyTemplate):
"""Class for specifying parameter of the model"""
def __init__(self,parent,text,name):
# Collect model information
self.projectName=name
try:
self.OSCAD_HOME=OSCAD_HOME
except NameError:
try:
self.OSCAD_HOME=os.environ["OSCAD_HOME"]
except KeyError:
tkMessageBox.showerror("Error OSCAD_HOME is not set","Please set OSCAD_HOME variable in .bashrc\n\nStep to set OSCAD_HOME variable:\n 1) Open ~/.bashrc using text editor (vi ~/.bash).\n 2) Add the line \"Export OSCAD_HOME=<path_of_oscad>\" to it.\n 3) source ~/.bashrc")
exit(0)
# Call base class MyTemplate
template.MyTemplate.__init__(self,parent,text,name, buttonbox=False)
def body(self, master):
w, h = master.winfo_screenwidth(), master.winfo_screenheight()
self.geometry("%dx%d" % (0.075*w, 0.6*h))
self.resizable(0,0)
self.attributes("-topmost",True)
# Create and configure a menu
"""menu = Menu(self)
self.config(menu=menu)
# Create File menu
toolmenu= Menu(menu)
menu.add_cascade(label="Tool", menu=toolmenu)
toolmenu.add_command(label="Schematic Editor F2", command=self.openSchematic)
toolmenu.add_separator()
toolmenu.add_command(label="Footprint Editor F3", command=self.openFootprint)
toolmenu.add_command(label="Layout Editor F4", command=self.openLayout)
toolmenu.add_separator()
toolmenu.add_command(label="Analysis Insertor F5", command=self.openAnalysisInserter)
toolmenu.add_command(label="Model builder F6", command=self.openModelBuilder)
toolmenu.add_command(label="Subcircuit builder F7", command=self.openSubcircuitBuilder)
toolmenu.add_separator()
toolmenu.add_command(label="NetList Converter F8", command=self.openNetConverter)
toolmenu.add_separator()
toolmenu.add_command(label="Ngspice F9", command=self.openNgspice)
toolmenu.add_command(label="SMCSim F10", command=self.openSMCSim)
toolmenu.add_separator()
toolmenu.add_command(label="Exit F11", command=self.exitProject)
# Create help menu
helpmenu=Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="Help F1",command=self.helpProject)
helpmenu.add_command(label="About...",command=self.aboutProjectManager)
self.mainWindow = LabelFrame(self, bd=4, relief=SUNKEN,text="Tool Window",bg="lightblue")
self.mainWindow.pack(side=TOP,fill="both", padx=5, pady=5, expand="Y")
self.mainWindow.place(relheight=0.85, relwidth=0.99)"""
# Set frame for command buttons
buttonWindow = Frame(self, bd=4, relief=SUNKEN)
buttonWindow.pack(side=LEFT,fill="both", padx=2, pady=2,expand="Y")
buttonWindow.place(relheight=0.95, relwidth=0.87, rely=0.02, relx=0.07)
"""buttonWindow1 = Frame(self, bd=4, relief=SUNKEN)
buttonWindow1.pack(side=TOP,fill="both", padx=2, pady=2,expand="Y")
buttonWindow1.place(relheight=0.9, relwidth=0.25, rely=0.02, relx=0.37)
buttonWindow2 = Frame(self, bd=4, relief=SUNKEN)
buttonWindow2.pack(side=BOTTOM,fill="both", padx=2, pady=2,expand="Y")
buttonWindow2.place(relheight=0.9, relwidth=0.25, rely=0.02, relx=0.67)"""
def createToolboxWithScilab():
self.createButtonForCommandWithScilab(buttonWindow,self.openSchematic,self.OSCAD_HOME+"/images/se.png","Schematic Editor")
self.createButtonForCommandWithScilab(buttonWindow,self.openAnalysisInserter,self.OSCAD_HOME+"/images/an.png","Analysis Insertor")
self.createButtonForCommandWithScilab(buttonWindow,self.openNetConverter,self.OSCAD_HOME+"/images/kn.png","NetList Converter")
self.createButtonForCommandWithScilab(buttonWindow,self.openNgspice,self.OSCAD_HOME+"/images/ng.png","Ngspice")
self.createButtonForCommandWithScilab(buttonWindow,self.openFootprint,self.OSCAD_HOME+"/images/fp.png","Footprint Editor")
self.createButtonForCommandWithScilab(buttonWindow,self.openLayout,self.OSCAD_HOME+"/images/lout.png","Layout Editor")
self.createButtonForCommandWithScilab(buttonWindow,self.openSMCSim,self.OSCAD_HOME+"/images/sci.png","SMCSim")
self.createButtonForCommandWithScilab(buttonWindow,self.openModelBuilder,self.OSCAD_HOME+"/images/mb.png","Model builder")
self.createButtonForCommandWithScilab(buttonWindow,self.openSubcircuitBuilder,self.OSCAD_HOME+"/images/sub.png","Subcircuit builder")
def createToolboxWithoutScilab():
self.createButtonForCommandWithoutScilab(buttonWindow,self.openSchematic,self.OSCAD_HOME+"/images/se.png","Schematic Editor")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openAnalysisInserter,self.OSCAD_HOME+"/images/an.png","Analysis Insertor")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openNetConverter,self.OSCAD_HOME+"/images/kn.png","NetList Converter")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openNgspice,self.OSCAD_HOME+"/images/ng.png","Ngspice")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openFootprint,self.OSCAD_HOME+"/images/fp.png","Footprint Editor")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openLayout,self.OSCAD_HOME+"/images/lout.png","Layout Editor")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openModelBuilder,self.OSCAD_HOME+"/images/mb.png","Model builder")
self.createButtonForCommandWithoutScilab(buttonWindow,self.openSubcircuitBuilder,self.OSCAD_HOME+"/images/sub.png","Subcircuit builder")
if os.path.isfile(OSCAD_HOME + "/bin/scilab54"):
createToolboxWithScilab()
else:
createToolboxWithoutScilab()
# Protocol for deletion of main window
self.protocol("WM_DELETE_WINDOW",self.exitProject)
# Create shortcut keys
"""self.bind("<F2>", self.openSchematic)
self.bind("<F3>", self.openFootprint)
self.bind("<F4>", self.openLayout)
self.bind("<F5>", self.openAnalysisInserter)
self.bind("<F6>", self.openModelBuilder)
self.bind("<F7>", self.openSubcircuitBuilder)
self.bind("<F8>", self.openNetConverter)
self.bind("<F9>", self.openNgspice)
self.bind("<F10>",self.openSMCSim)
self.bind("<F11>",self.exitProject)
self.bind("<F1>", self.helpProject)
self.focus_set()"""
def createButtonForCommandWithScilab(self,frameName,commandName,imagePath,textlabel):
# Open images
im = Image.open(imagePath)
photo = ImageTk.PhotoImage(im)
# Create button and set label for tools
w = Button(frameName, image=photo, width=45, height=30, command=commandName, default=ACTIVE)
w.image=photo
w.pack(side=TOP, padx=1, pady=1)
toolTip.createToolTip(w,textlabel)
def createButtonForCommandWithoutScilab(self,frameName,commandName,imagePath,textlabel):
# Open images
im = Image.open(imagePath)
photo = ImageTk.PhotoImage(im)
# Create button and set label for tools
w = Button(frameName, image=photo, width=45, height=35, command=commandName, default=ACTIVE)
w.image=photo
w.pack(side=TOP, padx=1, pady=1)
toolTip.createToolTip(w,textlabel)
def call_system(self,command):
os.system(command)
def openSchematic(self,e=None):
self.text.insert(END, " Opening schematic editor .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command="eeschema "+self.projectName+".sch "
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openFootprint(self,e=None):
self.text.insert(END, " Opening footprint editor .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command="cvpcb "+self.projectName+".net "
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openLayout(self,e=None):
self.text.insert(END, " Opening layout editor .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command="pcbnew "+self.projectName+".net "
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openNetConverter(self,e=None):
self.text.insert(END, " Running netlist converter .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command="xterm -e python "+self.OSCAD_HOME+"/kicadtoNgspice/KicadtoNgspice.py "+self.projectName+".cir 1"
#command=self.OSCAD_HOME+"/kicadtoNgspice/KicadtoNgspice.py "+self.projectName+".cir 1\""
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openAnalysisInserter(self,e=None):
self.text.insert(END, " Opening analysis inserter .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command=self.OSCAD_HOME+"/analysisInserter/convertgui.py"
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openModelBuilder(self,e=None):
self.text.insert(END, " Opening model editor .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
#command="xterm -e \""+self.OSCAD_HOME+"/modelEditor/modelEditor.py " +self.projectName+".cir 1\""
command=self.OSCAD_HOME+"/modelEditor/modelEditor.py "+self.projectName+".cir 1"
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openSubcircuitBuilder(self,e=None):
self.text.insert(END, " Opening Sub-circuit editor ................\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command=self.OSCAD_HOME+"/subcktEditor/subcktEditor.py " +self.projectName+".cir "
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def openNgspice(self,e=None):
self.text.insert(END, " Running ngspice circuit simulator .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
command="xterm -e \"ngspice "+self.projectName+".cir.out \""
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
# opening pythonplotting:
command ="python " + self.OSCAD_HOME+"/forntEnd/pythonPlotting.py "+os.getcwd()+" "+self.projectName
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
def openSMCSim(self,e=None):
self.text.insert(END, " Running scilab based circuit simulator .........\n")
self.text.yview(END)
# Call all pending idle tasks, without processing any other events.
self.update_idletasks()
Option=selectOption.SelectOption(self,self.text,"LPCSim")
command=self.OSCAD_HOME+"/bin/scilab54 -f " +self.OSCAD_HOME+"/LPCSim/LPCSim/Main.sci -args "+self.projectName+".cir.ckt "
try:
thread.start_new_thread(self.call_system,(command,))
except Exception,err:
print err
self.text.insert(END, "Select a tool from tool menu\n")
self.text.yview(END)
def helpProject(self,e=None):
pass
# Display help content
def aboutProjectManager(self,e=None):
tkMessageBox.showinfo("About Project Manager","Created by Yogesh Dilip Save")
# Exit an Project Manager
def exitProject(self):
if tkMessageBox.askokcancel("QUIT","Do you really wish to quit?"):
self.destroy()
def apply(self):
pass
if __name__=='__main__':
root = Tk()
project= ProjectInfo(root)
projectParam = ProjectParam(root,project.modelName,project.modelType)
mainloop()
|