diff options
author | Jayaram Pai | 2014-05-19 11:02:57 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-05-19 11:02:57 +0530 |
commit | 8377256e7d90aa7ba1cb51f6164e99f81e2eb53c (patch) | |
tree | 5afcc8e82d7f7d4f6fbff900520bd8f05eb343ca /OSCAD/forntEnd | |
download | FreeEDA-8377256e7d90aa7ba1cb51f6164e99f81e2eb53c.tar.gz FreeEDA-8377256e7d90aa7ba1cb51f6164e99f81e2eb53c.tar.bz2 FreeEDA-8377256e7d90aa7ba1cb51f6164e99f81e2eb53c.zip |
initial commit
Diffstat (limited to 'OSCAD/forntEnd')
-rw-r--r-- | OSCAD/forntEnd/my_oscad.py | 301 | ||||
-rw-r--r-- | OSCAD/forntEnd/newProject.py | 352 | ||||
-rw-r--r-- | OSCAD/forntEnd/openProject.py | 57 | ||||
-rw-r--r-- | OSCAD/forntEnd/oscad.py | 184 | ||||
-rw-r--r-- | OSCAD/forntEnd/selectOption.py | 55 | ||||
-rw-r--r-- | OSCAD/forntEnd/setPath.py | 2 | ||||
-rw-r--r-- | OSCAD/forntEnd/template.py | 117 | ||||
-rw-r--r-- | OSCAD/forntEnd/test.py | 35 | ||||
-rw-r--r-- | OSCAD/forntEnd/toolTip.py | 48 |
9 files changed, 1151 insertions, 0 deletions
diff --git a/OSCAD/forntEnd/my_oscad.py b/OSCAD/forntEnd/my_oscad.py new file mode 100644 index 0000000..b83dd41 --- /dev/null +++ b/OSCAD/forntEnd/my_oscad.py @@ -0,0 +1,301 @@ +from setPath import OSCAD_HOME +from Tkinter import * +import thread +import ttk +import template +import tkMessageBox +import os.path +import os +import toolTip +import selectOption +from string import maketrans +from PIL import Image, ImageTk +import tkFileDialog +import os +import Image +import ImageTk + +def new_Project(e=None): + text.insert(END,"Select the directory to save the project\n") + directory=tkFileDialog.askdirectory() + if directory: + try: + os.chdir(directory) + text.insert(END, "Changing directory to "+directory+"\n\n") + text.yview(END) + except OSError, msg: + tkMessageBox.showerror("Change Directory Failed",msg) + else: + tkMessageBox.showwarning("Bad input","Directory is not specified, please try again") + text.insert(END, "In Main window:\n") + text.insert(END, "Please select the proper option from File Menu\n") + text.yview(END) + text.insert(END, "Please enter a project Name\n") + text.yview(END) +# Read project information (name) + project= newProject.ProjectInfo(root,text) +# Create project files + if project.status: + projectParam = newProject.ProjectParam(root,text,project.projectName) + +# Open an existing model +def open_Project(e=None): +# Read project information (name) + text.insert(END, "Please enter the project Name\n") + text.yview(END) + project= openProject.ProjectInfo(root,text) +# Open model file + if project.status: + projectParam = newProject.ProjectParam(root,text,project.projectName) + text.insert(END, "In Main window:\n") + text.insert(END, "Please select the proper option from File Menu\n") + +# Change the current directory to new directory +def changeDirectory(event=None): + folderName=tkFileDialog.askdirectory() + if folderName: + try: + os.chdir(folderName) + text.insert(END, "Changing directory to "+folderName+"\n\n") + text.yview(END) + open_Project() + except OSError, msg: + tkMessageBox.showerror("Change Directory Failed",msg) + else: + tkMessageBox.showwarning("Bad input","Directory is not specified, please try again") + text.insert(END, "In Main window:\n") + text.insert(END, "Please select the proper option from File Menu\n") + text.yview(END) + +def exit_Project(e=None): + if tkMessageBox.askokcancel("QUIT","Do you really wish to quit?"): + text.insert(END, "Bye Bye......\n") + root.destroy() + +# Display help content +def help_Project(e=None): + pass + +# Display help content +def about_Project(): + tkMessageBox.showinfo("About Editor","Created by Yogesh Dilip Save") + +def createButtonForCommand(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=20, height=14, command=commandName, default=ACTIVE) + w.image=photo + w.pack(side=TOP, padx=1, pady=1) + toolTip.createToolTip(w,textlabel) + +def call_system(command): + os.system(command) + +def openSchematic(e=None): + text.insert(END, " Opening schematic editor .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + #update_idletasks() + command="eeschema "+self.projectName+".sch " + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openFootprint(e=None): + text.insert(END, " Opening footprint editor .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + update_idletasks() + command="cvpcb "+self.projectName+".net " + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openLayout(e=None): + text.insert(END, " Opening layout editor .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + update_idletasks() + command="pcbnew "+self.projectName+".net " + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openNetConverter(e=None): + text.insert(END, " Running netlist converter .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + update_idletasks() + command="xterm -e \""+self.OSCAD_HOME+"/kicadtoNgspice/KicadtoNgspice.py "+self.projectName+".cir 1\"" + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openAnalysisInserter(e=None): + text.insert(END, " Opening analysis inserter .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + update_idletasks() + command=self.OSCAD_HOME+"/analysisInserter/convertgui.py" + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openModelBuilder(e=None): + text.insert(END, " Opening model editor .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + update_idletasks() + command=self.OSCAD_HOME+"/modelEditor/modelEditor.py " +self.projectName+".cir " + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openSubcircuitBuilder(e=None): + text.insert(END, " Opening Sub-circuit editor ................\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + 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 + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openNgspice(e=None): + text.insert(END, " Running ngspice circuit simulator .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + update_idletasks() + command="xterm -e \"ngspice "+self.projectName+".cir.out \"" + try: + thread.start_new_thread(self.call_system,(command,)) + except Exception,err: + print err + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + +def openSMCSim(e=None): + text.insert(END, " Running scilab based circuit simulator .........\n") + text.yview(END) + # Call all pending idle tasks, without processing any other events. + 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 + text.insert(END, "Select a tool from tool menu\n") + text.yview(END) + + +# Create and configure a graphical window +root = Tk() +root.title("OSCAD for Electronics and Electrical Engineers") + +# make it cover the entire screen +w, h = root.winfo_screenwidth(), root.winfo_screenheight() +root.geometry("%dx%d" % (0.65*w, 0.65*h)) +root.focus_set() + +# Create and configure a menu +menu = Menu(root) +root.config(menu=menu) + +# Create File menu +filemenu= Menu(menu) +menu.add_cascade(label="File", menu=filemenu) +filemenu.add_command(label="New F2", command=new_Project) +filemenu.add_command(label="Open F3", command=changeDirectory) +filemenu.add_separator() +filemenu.add_command(label="Exit F4", command=exit_Project) + +# Create help menu +helpmenu=Menu(menu) +menu.add_cascade(label="Help", menu=helpmenu) +helpmenu.add_command(label="Help F1",command=help_Project) +helpmenu.add_command(label="About...",command=about_Project) + +# Protocol for deletion of main window +root.protocol("WM_DELETE_WINDOW",exit_Project) + +# Create shortcut keys +root.bind("<F2>", new_Project) +root.bind("<F3>", open_Project) +root.bind("<F4>", exit_Project) +root.bind("<F1>", help_Project) +root.bind("<F5>", changeDirectory) + +mainWindow = LabelFrame(root, bd=4, relief=SUNKEN,text="Main Window", bg='lightblue') +mainWindow.pack(side=TOP,fill="both", padx=5, pady=5,expand="Y") +mainWindow.place(relheight=0.85, relwidth=0.99, rely=0.0) + +c = Canvas(mainWindow, bg='white',width=745, height=320) +c.pack() +im = Image.open(OSCAD_HOME+"/images/OSCADlogo.jpeg") +tkim = ImageTk.PhotoImage(im) +c.create_image(375, 150, image=tkim) + +buttonWindow = Frame(root, bd=4, relief=SUNKEN) +buttonWindow.pack(side=RIGHT,fill="both", padx=2, pady=2,expand="Y") +buttonWindow.place(relheight=0.6, relwidth=0.06, rely=0.04, relx=0.01) + +createButtonForCommand(buttonWindow,openSchematic,OSCAD_HOME+"/images/seLogo.jpg","Schematic Editor") +createButtonForCommand(buttonWindow,openFootprint,OSCAD_HOME+"/images/feLogo.jpg","Footprint Editor") +createButtonForCommand(buttonWindow,openLayout,OSCAD_HOME+"/images/leLogo.jpg","Layout Editor") +createButtonForCommand(buttonWindow,openAnalysisInserter,OSCAD_HOME+"/images/anLogo.jpg","Analysis Insertor") +createButtonForCommand(buttonWindow,openModelBuilder,OSCAD_HOME+"/images/mbLogo.jpg","Model builder") +createButtonForCommand(buttonWindow,openSubcircuitBuilder,OSCAD_HOME+"/images/sbLogo.jpg","Subcircuit builder") +createButtonForCommand(buttonWindow,openNetConverter,OSCAD_HOME+"/images/knLogo.jpg","NetList Converter") +createButtonForCommand(buttonWindow,openNgspice,OSCAD_HOME+"/images/ngLogo.jpg","Ngspice") +createButtonForCommand(buttonWindow,openSMCSim,OSCAD_HOME+"/images/slLogo.jpg","SMCSim") + +reportWindow = LabelFrame(root, bd=4, relief=SUNKEN,text="Report Window") +reportWindow.pack(side=BOTTOM,fill="both", padx=5, pady=5,expand="Y") +reportWindow.place(relheight=0.35, relwidth=0.99, rely=0.65) + +text = Text(reportWindow) +text.insert(INSERT, "Welcome.....\n") +text.insert(END, "First select project working directory using File Menu\n") +text.insert(END, "Then select the proper option in File Menu\n") +text.focus_set() +text.pack() +text.place(relheight=0.98, relwidth=0.99, rely=0.02) +text.config(borderwidth=5) + +scrollY = Scrollbar(reportWindow,orient=VERTICAL,command=text.yview) +scrollY.pack(fill=Y) +scrollY.place(relheight=0.98,relwidth=0.01, rely=0.02, relx=0.99) +text.config(yscrollcommand=scrollY.set) +scrollY.set(0,0.5) + + +def execute(event): + print "yogesh" + +text.bind("<Return>",execute) +mainloop() diff --git a/OSCAD/forntEnd/newProject.py b/OSCAD/forntEnd/newProject.py new file mode 100644 index 0000000..0f24201 --- /dev/null +++ b/OSCAD/forntEnd/newProject.py @@ -0,0 +1,352 @@ +#!/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 \""+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\"" + 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) + + 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() diff --git a/OSCAD/forntEnd/openProject.py b/OSCAD/forntEnd/openProject.py new file mode 100644 index 0000000..6625229 --- /dev/null +++ b/OSCAD/forntEnd/openProject.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +# openProject.py is a python script to open an existing 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 Tkinter import * +import template +import tkMessageBox +import os.path +from string import maketrans + +class ProjectInfo(template.MyTemplate): + """ Class for accept model information from user """ + def body(self, master): + # Ask for compoent name + Label(master, text="Enter Project name:").grid(row=0) + self.e1 = Entry(master) + self.e1.grid(row=0, column=1,pady=10,columnspan=2) + tempStr=os.getcwd() + tempStr2=tempStr.split('/') + self.e1.insert(0,tempStr2[len(tempStr2)-1]) + +# Collect project information + def apply(self): + """ a method for writing project information to the file""" + self.text.insert(END, "Successfully opened project " + self.projectName+". \n") + self.text.yview(END) + pass + +# Validate the model information + def validate(self): + # Remove trailing and leading spaces from modelName + self.projectName=self.e1.get().strip() + if len(self.projectName): + self.text.insert(END, "Opening project " + self.projectName+" ...... \n") + self.text.yview(END) + # Read project file + try: + self.text.insert(END, " Checking project information file " + self.projectName+".proj. ...... \n") + self.text.yview(END) + f = open(self.projectName+".proj","r") + except : + tkMessageBox.showwarning("Error","Project information file does not exist, Try again") + return 0 + f.close() + return 1 + else: + tkMessageBox.showwarning("Bad input","Project Name is not specified, please try again") + return 0 + +if __name__=='__main__': + root=Tk() + project= ProjectInfo(root) + mainloop() + diff --git a/OSCAD/forntEnd/oscad.py b/OSCAD/forntEnd/oscad.py new file mode 100644 index 0000000..5015e0c --- /dev/null +++ b/OSCAD/forntEnd/oscad.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +# oscad.py is a python script to create fornt end 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 ttk +import tkMessageBox +import tkFileDialog +import newProject +import openProject +import os +import Image +import ImageTk +import os +import sys +# T=os.popen("ls -l").read() +# text.insert(END, T) + +# Create a new model +def new_Project(e=None): + #text.insert(END,"Select the directory to save the project\n") + directory=tkFileDialog.askdirectory() + if directory: + try: + os.chdir(directory) + text.insert(END, "Changing directory to "+directory+"\n\n") + text.yview(END) + project= newProject.ProjectInfo(root,text) + except msg: + tkMessageBox.showerror("Change Directory Failed",msg) + else: + tkMessageBox.showwarning("Bad input","Directory is not specified, please try again") +# Create project files + try: + if project.status: + projectParam = newProject.ProjectParam(root,text,project.projectName) + except: + pass + +# Open an existing model +def open_Project(e=None): +# Read project information (name) + text.insert(END, "Please enter the project Name\n") + text.yview(END) + project= openProject.ProjectInfo(root,text) +# Open model file + if project.status: + projectParam = newProject.ProjectParam(root,text,project.projectName) + #text.insert(END, "In Main window:\n") + #text.insert(END, "Please select the proper option from File Menu\n") + +# Change the current directory to new directory +def changeDirectory(event=None): + folderName=tkFileDialog.askdirectory() + if folderName: + try: + os.chdir(folderName) + text.insert(END, "Changing directory to "+folderName+"\n\n") + text.yview(END) + open_Project() + except OSError, msg: + tkMessageBox.showerror("Change Directory Failed",msg) + else: + tkMessageBox.showwarning("Bad input","Directory is not specified, please try again") + +# Exit an model editor +def exit_Project(e=None): + if tkMessageBox.askokcancel("QUIT","Do you really wish to quit, this will close all OSCAD projects that are running ?"): + text.insert(END, "Good Bye !!\n") + root.destroy() + +# Display help content +def help_Project(e=None): + pass + +# Display help content +def about_Project(): + tkMessageBox.showinfo("About Oscad","Oscad is a free & open source CAD tool for\ + Electronics & Electrical Engineers.\n \ + \nDeveloped by putting together open source soft like:\neeschema(kicad), \nPCB layout editor (kicad), \nNGSpice, \nScilab.\n\ + \nDeveloped at IIT Bombay by FOSSEE team") + +# Create and configure a graphical window +root = Tk() +root.title("Oscad") +"""img = PhotoImage(file="an.jpg") +root.tk.call('wm', 'iconphoto', root._w, img)""" + +# make it cover the entire screen +w, h = root.winfo_screenwidth(), root.winfo_screenheight() +root.geometry("%dx%d" % (0.15*w, 0.25*h)) +root.focus_set() +root.resizable(0,0) + +"""mainWindow = Frame(root) + +b1 = Button(mainWindow, text="New", width=18, command=new_Project) +b1.pack() +b2 = Button(mainWindow, text="Open", width=18, command=changeDirectory) +b2.pack() +b3 = Button(mainWindow, text="Exit", width=18, command=exit_Project) +b3.pack() + +mainWindow.pack()""" + +"""c = Canvas(root, bg='lightblue') +c.pack(side=LEFT) +c.place(relheight=0.99, relwidth=0.99, rely=0.0,relx=0.2) +im = Image.open(OSCAD_HOME+"/images/logo.png") +tkim = ImageTk.PhotoImage(im) +c.create_image(75, 75, image=tkim)""" + +img = ImageTk.PhotoImage(Image.open(OSCAD_HOME+"/images/logo.png")) +panel = Label(root, image = img) +panel.place(relheight=0.8,relwidth=0.8,rely=0.0,relx=0.1) +panel.pack() + +# Create and configure a menu +menu = Menu(root) +root.config(menu=menu) + +# Create File menu +filemenu= Menu(menu) +menu.add_cascade(label="Project", menu=filemenu) +filemenu.add_command(label="New F2", command=new_Project) +filemenu.add_command(label="Open F3", command=changeDirectory) +filemenu.add_separator() +filemenu.add_command(label="Exit F4", command=exit_Project) + +# Create help menu +helpmenu=Menu(menu) +menu.add_cascade(label="Help", menu=helpmenu) +helpmenu.add_command(label="Help F1",command=help_Project) +helpmenu.add_command(label="About...",command=about_Project) + +# Protocol for deletion of main window + + +# Create shortcut keys +root.bind("<F2>", new_Project) +root.bind("<F3>", changeDirectory) +root.bind("<F4>", exit_Project) +root.bind("<F1>", help_Project) + +"""mainWindow = LabelFrame(root, bd=4, relief=SUNKEN,text="Main Window", bg='lightblue') +mainWindow.pack(side=TOP,fill="both", padx=5, pady=5,expand="Y") +mainWindow.place(relheight=0.85, relwidth=0.99, rely=0.0) + +c = Canvas(mainWindow, bg='white',width=750, height=325) +c.pack() +im = Image.open(OSCAD_HOME+"/images/OSCADlogo.jpeg") +tkim = ImageTk.PhotoImage(im) +c.create_image(375, 150, image=tkim)""" + +reportWindow = LabelFrame(root, bd=4, relief=SUNKEN,text="Report Window") +#reportWindow.pack(side=BOTTOM,fill="both", padx=5, pady=5,expand="Y") +#reportWindow.place(relheight=0.52, relwidth=0.98, rely=0.47) + +text = Text(reportWindow) +"""text.insert(INSERT, "Welcome !!\n") +text.insert(END, "New: Create a New Project\n") +text.insert(END, "Open: Open an Exising Project\n") +text.focus_set() +text.pack() +text.place(relheight=0.99, relwidth=0.99) +text.config(borderwidth=5) + +scrollY = Scrollbar(reportWindow,orient=VERTICAL,command=text.yview) +scrollY.pack(fill=Y) +scrollY.place(relheight=0.98,relwidth=0.01, rely=0.02, relx=0.99) +text.config(yscrollcommand=scrollY.set) +scrollY.set(0,0.5)""" + +root.protocol("WM_DELETE_WINDOW",exit_Project) + +def execute(event): + print "yogesh" + +#text.bind("<Return>",execute) +mainloop() diff --git a/OSCAD/forntEnd/selectOption.py b/OSCAD/forntEnd/selectOption.py new file mode 100644 index 0000000..447179b --- /dev/null +++ b/OSCAD/forntEnd/selectOption.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# selectOption.py is a python script to select option for Scilab based circuit simulator. 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 template +import tkMessageBox +import os.path +from string import maketrans + +class SelectOption(template.MyTemplate): + """ Class for accept model information from user """ + def body(self, master): + # Define default mode type and set it to symbolic + self.option = StringVar() + self.option.set("1") + + # Ask for scilab option + Label(master, text="Enter mode for scilab based circuit simulator:").grid(row=1) + Radiobutton(master, text="Normal", variable=self.option, value="0").grid(row=2,column=0,columnspan=2,sticky=W) + Radiobutton(master, text="Symbolic", variable=self.option, value="1").grid(row=3,column=0,columnspan=2,sticky=W) + Radiobutton(master, text="Matrix", variable=self.option, value="2").grid(row=4,column=0,columnspan=2,sticky=W) + +# Collect model information + def apply(self): + self.mode=self.option.get() + 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) + HOME=self.OSCAD_HOME+"/LPCSim/LPCSim/" + # Open file for writing option + fileName=HOME+"option" + os.system("rm -rf "+ fileName) + # Create model file for writing + try: + f = open(fileName,"w") + except : + tkMessageBox.showwarning("Error","Model file can not be wriiten. please check the file system permission") + f.write(self.mode) + f.close() + +if __name__=='__main__': + root=Tk() + model= SelectOption(root) + mainloop() + diff --git a/OSCAD/forntEnd/setPath.py b/OSCAD/forntEnd/setPath.py new file mode 100644 index 0000000..778e6f3 --- /dev/null +++ b/OSCAD/forntEnd/setPath.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +OSCAD_HOME="/home/hardik/OSCAD" diff --git a/OSCAD/forntEnd/template.py b/OSCAD/forntEnd/template.py new file mode 100644 index 0000000..e5f843b --- /dev/null +++ b/OSCAD/forntEnd/template.py @@ -0,0 +1,117 @@ +#!/usr/bin/python +from Tkinter import * +import os + +class MyTemplate(Toplevel): + """Template to construct new window""" +# Define constructor + def __init__(self, parent, text=None, title=None, buttonbox=True): + # Set new window properties same as parent + Toplevel.__init__(self, parent) + + # Set report window + if text: + self.text=text + + # Create a new window on top of the parent such that don't appear in taskbar + self.transient(parent) + + # Set the title + if title: + self.title("Tools") + # Set Parent of active window + self.parent =parent + + # Create a new frame + body =Frame (self) + # Call body method + self.initial_focus = self.body(body) + # Display body + body.pack(padx=5, pady=5) + # Create buttons + if buttonbox: + self.buttonbox() + # Create status bar + self.statusBar() + # Take control of all the events + self.grab_set() + + # Take control of all the keyboard events + if not self.initial_focus: + self.initial_focus=self + + # Protocol when window is deleted. + self.protocol("WM_DELETE_WINDOW",self.cancel) + + # Position the geometry respect to main window + self.geometry("+%d+%d" % (parent.winfo_rootx()+10,parent.winfo_rooty()+22)) + self.initial_focus.focus_set() + + # Wait for widget to be destroyed + self.wait_window(self) + +# Construction of body of the window + def body(self, master): + # Create dialog body. This method should be overridden + pass + +# Add standard button box (OK, Cancel). Override if you don't want the standard buttons + def buttonbox(self): + # Construct a new frame + box = Frame(self) + # Create buttons + w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE) + w.pack(side=LEFT, padx=5, pady=5) + w = Button(box, text="Cancel", width=10, command=self.cancel) + w.pack(side=LEFT, padx=5, pady=5) + + # Bind Return and escape keys + self.bind("<Return>", self.ok) + self.bind("<Escape>", self.cancel) + # Create the frame "box" + box.pack(side=BOTTOM) + +# Add standard status bar. Override if you don't want the status bar + def statusBar(self): + pass + # self.statusbar = Label(self, text="", bd=1, relief=SUNKEN, anchor=W) + # self.statusbar.pack(side=BOTTOM, fill=X) + +# Template for action taken when OK is pressed + def ok(self, event=None): + # If data is not valid then put the focus back + if not self.validate(): + self.initial_focus.focus_set() + return + # Remove the window from the screen (without destroying it) + self.withdraw() + # Call all pending idle tasks, without processing any other events. + self.update_idletasks() + # Perform required task (collection of result, inputs etc.) + self.apply() + # Take action when all task has finished + self.cancel(status=1) + +# Template for action taken when cancel pressed + def cancel(self, event=None, status=0): + # Catch the status + self.status=status + # Put focus back to the parent window + self.parent.focus_set() + # Destroy child window + self.destroy() + +# Template for validation of data + def validate(self): + return 1 + +# Template for required action (Saving Data, results) + def apply(self): + pass + +# Test case +if __name__=='__main__': + root=Tk() + d =MyTemplate(root) + mainloop() + diff --git a/OSCAD/forntEnd/test.py b/OSCAD/forntEnd/test.py new file mode 100644 index 0000000..225030d --- /dev/null +++ b/OSCAD/forntEnd/test.py @@ -0,0 +1,35 @@ +##------------------------------- +# file: test.py +# simple demonstration of the Tkinter notebook + +from Tkinter import * +from notebook import * + +a = Tk() +n = notebook(a, LEFT) + +# uses the notebook's frame +f1 = Frame(n()) +b1 = Button(f1, text="Button 1") +e1 = Entry(f1) +# pack your widgets before adding the frame +# to the notebook (but not the frame itself)! +b1.pack(fill=BOTH, expand=1) +e1.pack(fill=BOTH, expand=1) + +f2 = Frame(n()) +# this button destroys the 1st screen radiobutton +b2 = Button(f2, text='Button 2', command=lambda:x1.destroy()) +b3 = Button(f2, text='Beep 2', command=lambda:Tk.bell(a)) +b2.pack(fill=BOTH, expand=1) +b3.pack(fill=BOTH, expand=1) + +f3 = Frame(n()) + +# keeps the reference to the radiobutton (optional) +x1 = n.add_screen(f1, "Screen 1") +n.add_screen(f2, "Screen 2") +n.add_screen(f3, "dummy") + +if __name__ == "__main__": + a.mainloop() diff --git a/OSCAD/forntEnd/toolTip.py b/OSCAD/forntEnd/toolTip.py new file mode 100644 index 0000000..0409390 --- /dev/null +++ b/OSCAD/forntEnd/toolTip.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +from Tkinter import * + +class ToolTip(object): + + def __init__(self, widget): + self.widget = widget + self.tipwindow = None + self.id = None + self.x = self.y = 0 + + def showtip(self, text): + "Display text in tooltip window" + self.text = text + if self.tipwindow or not self.text: + return + x, y, cx, cy = self.widget.bbox("insert") + x = x + self.widget.winfo_rootx() + 27 + y = y + cy + self.widget.winfo_rooty() +27 + self.tipwindow = tw = Toplevel(self.widget) + tw.wm_overrideredirect(1) + tw.wm_geometry("+%d+%d" % (x, y)) + try: + # For Mac OS + tw.tk.call("::tk::unsupported::MacWindowStyle", + "style", tw._w, + "help", "noActivates") + except TclError: + pass + label = Label(tw, text=self.text, justify=LEFT, + background="#ffffe0", relief=SOLID, borderwidth=1, + font=("tahoma", "8", "normal")) + label.pack(ipadx=1) + + def hidetip(self): + tw = self.tipwindow + self.tipwindow = None + if tw: + tw.destroy() + +def createToolTip(widget, text): + toolTip = ToolTip(widget) + def enter(event): + toolTip.showtip(text) + def leave(event): + toolTip.hidetip() + widget.bind('<Enter>', enter) + widget.bind('<Leave>', leave) |