diff options
Diffstat (limited to 'src/frontEnd')
-rwxr-xr-x | src/frontEnd/Application.py | 451 | ||||
-rw-r--r-- | src/frontEnd/DockArea.py | 356 | ||||
-rw-r--r-- | src/frontEnd/ProjectExplorer.py | 180 | ||||
-rw-r--r-- | src/frontEnd/ProjectExplorer.py.bak | 147 | ||||
-rw-r--r-- | src/frontEnd/Workspace.py | 106 | ||||
-rw-r--r-- | src/frontEnd/pathmagic.py | 6 |
6 files changed, 776 insertions, 470 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index 2f9bca28..19fe17ef 100755 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -1,28 +1,21 @@ - -#=============================================================================== +# ========================================================================= # # FILE: Application.py -# -# USAGE: --- -# +# +# USAGE: --- +# # DESCRIPTION: This main file use to start the Application -# +# # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Fahim Khan, fahim.elex@gmail.com # ORGANIZATION: eSim team at FOSSEE, IIT Bombay. -# CREATED: Wednesday 21 January 2015 +# CREATED: Wednesday 21 January 2015 # REVISION: --- -#=============================================================================== -import os -import sys -#Setting PYTHONPATH -cwd = os.getcwd() -(setPath,fronEnd) = os.path.split(cwd) -sys.path.append(setPath) - +# ========================================================================= +import pathmagic # noqa from PyQt4 import QtGui, QtCore from configuration.Appconfig import Appconfig from projManagement.openProject import OpenProjectInfo @@ -35,108 +28,151 @@ from frontEnd import Workspace from frontEnd import DockArea import time from PyQt4.Qt import QSize +import sys +import os class Application(QtGui.QMainWindow): - global project_name + global project_name """ Its our main window of application """ - def __init__(self,*args): + + def __init__(self, *args): """ Initialize main Application window """ - #Calling __init__ of super class - QtGui.QMainWindow.__init__(self,*args) - - #Creating require Object + # Calling __init__ of super class + QtGui.QMainWindow.__init__(self, *args) + + # Creating require Object self.obj_workspace = Workspace.Workspace() self.obj_Mainview = MainView() self.obj_kicad = Kicad(self.obj_Mainview.obj_dockarea) - self.obj_appconfig = Appconfig() + self.obj_appconfig = Appconfig() self.obj_validation = Validation() - #Initialize all widget + # Initialize all widget self.setCentralWidget(self.obj_Mainview) self.initToolBar() - + self.setGeometry(self.obj_appconfig._app_xpos, self.obj_appconfig._app_ypos, self.obj_appconfig._app_width, self.obj_appconfig._app_heigth) - self.setWindowTitle(self.obj_appconfig._APPLICATION) + self.setWindowTitle(self.obj_appconfig._APPLICATION) self.showMaximized() self.setWindowIcon(QtGui.QIcon('../../images/logo.png')) - #self.show() + # self.show() self.systemTrayIcon = QtGui.QSystemTrayIcon(self) self.systemTrayIcon.setIcon(QtGui.QIcon('../../images/logo.png')) self.systemTrayIcon.setVisible(True) - - + def initToolBar(self): """ This function initialize Tool Bar """ - #Top Tool bar - self.newproj = QtGui.QAction(QtGui.QIcon('../../images/newProject.png'),'<b>New Project</b>',self) + # Top Tool bar + self.newproj = QtGui.QAction( + QtGui.QIcon('../../images/newProject.png'), + '<b>New Project</b>', + self) self.newproj.setShortcut('Ctrl+N') self.newproj.triggered.connect(self.new_project) - #self.newproj.connect(self.newproj,QtCore.SIGNAL('triggered()'),self,QtCore.SLOT(self.new_project())) - - self.openproj = QtGui.QAction(QtGui.QIcon('../../images/openProject.png'),'<b>Open Project</b>',self) + # self.newproj.connect(self.newproj,QtCore.SIGNAL('triggered()'),self,QtCore.SLOT(self.new_project())) + + self.openproj = QtGui.QAction( + QtGui.QIcon('../../images/openProject.png'), + '<b>Open Project</b>', + self) self.openproj.setShortcut('Ctrl+O') self.openproj.triggered.connect(self.open_project) - - self.closeproj = QtGui.QAction(QtGui.QIcon('../../images/closeProject.png'),'<b>Close Project</b>',self) + + self.closeproj = QtGui.QAction( + QtGui.QIcon('../../images/closeProject.png'), + '<b>Close Project</b>', + self) self.closeproj.setShortcut('Ctrl+X') self.closeproj.triggered.connect(self.close_project) - - self.helpfile = QtGui.QAction(QtGui.QIcon('../../images/helpProject.png'),'<b>Help</b>',self) + + self.helpfile = QtGui.QAction( + QtGui.QIcon('../../images/helpProject.png'), '<b>Help</b>', self) self.helpfile.setShortcut('Ctrl+H') self.helpfile.triggered.connect(self.help_project) - + self.topToolbar = self.addToolBar('Top Tool Bar') self.topToolbar.addAction(self.newproj) self.topToolbar.addAction(self.openproj) - + self.topToolbar.addAction(self.closeproj) self.topToolbar.addAction(self.helpfile) - + self.spacer = QtGui.QWidget() - self.spacer.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding) + self.spacer.setSizePolicy( + QtGui.QSizePolicy.Expanding, + QtGui.QSizePolicy.Expanding) self.topToolbar.addWidget(self.spacer) self.logo = QtGui.QLabel() - self.logopic = QtGui.QPixmap(os.path.join(os.path.abspath('../..'),'images','fosseeLogo.png')) - self.logopic = self.logopic.scaled(QSize(150,150),QtCore.Qt.KeepAspectRatio) + self.logopic = QtGui.QPixmap( + os.path.join( + os.path.abspath('../..'), + 'images', + 'fosseeLogo.png')) + self.logopic = self.logopic.scaled( + QSize(150, 150), QtCore.Qt.KeepAspectRatio) self.logo.setPixmap(self.logopic) self.logo.setStyleSheet("padding:0 15px 0 0;") self.topToolbar.addWidget(self.logo) - - #Left Tool bar Action Widget - self.kicad = QtGui.QAction(QtGui.QIcon('../../images/kicad.png'),'<b>Open Schematic</b>',self) + + # Left Tool bar Action Widget + self.kicad = QtGui.QAction( + QtGui.QIcon('../../images/kicad.png'), + '<b>Open Schematic</b>', + self) self.kicad.triggered.connect(self.obj_kicad.openSchematic) - - self.conversion = QtGui.QAction(QtGui.QIcon('../../images/ki-ng.png'),'<b>Convert Kicad to Ngspice</b>',self) + + self.conversion = QtGui.QAction( + QtGui.QIcon('../../images/ki-ng.png'), + '<b>Convert Kicad to Ngspice</b>', + self) self.conversion.triggered.connect(self.obj_kicad.openKicadToNgspice) - - self.ngspice = QtGui.QAction(QtGui.QIcon('../../images/ngspice.png'), '<b>Simulation</b>', self) + + self.ngspice = QtGui.QAction( + QtGui.QIcon('../../images/ngspice.png'), + '<b>Simulation</b>', + self) self.ngspice.triggered.connect(self.open_ngspice) - - self.model = QtGui.QAction(QtGui.QIcon('../../images/model.png'),'<b>Model Editor</b>',self) - self.model.triggered.connect(self.open_modelEditor) - - self.subcircuit=QtGui.QAction(QtGui.QIcon('../../images/subckt.png'),'<b>Subcircuit</b>',self) + + self.model = QtGui.QAction( + QtGui.QIcon('../../images/model.png'), + '<b>Model Editor</b>', + self) + self.model.triggered.connect(self.open_modelEditor) + + self.subcircuit = QtGui.QAction( + QtGui.QIcon('../../images/subckt.png'), + '<b>Subcircuit</b>', + self) self.subcircuit.triggered.connect(self.open_subcircuit) - self.nghdl = QtGui.QAction(QtGui.QIcon('../../images/nghdl.png'), '<b>Nghdl</b>', self) + self.nghdl = QtGui.QAction( + QtGui.QIcon('../../images/nghdl.png'), + '<b>Nghdl</b>', + self) self.nghdl.triggered.connect(self.open_nghdl) - - self.omedit = QtGui.QAction(QtGui.QIcon('../../images/omedit.png'),'<b>Modelica Converter</b>',self) - self.omedit.triggered.connect(self.open_OMedit) - - self.omoptim=QtGui.QAction(QtGui.QIcon('../../images/omoptim.png'),'<b>OM Optimisation</b>',self) + + self.omedit = QtGui.QAction( + QtGui.QIcon('../../images/omedit.png'), + '<b>Modelica Converter</b>', + self) + self.omedit.triggered.connect(self.open_OMedit) + + self.omoptim = QtGui.QAction( + QtGui.QIcon('../../images/omoptim.png'), + '<b>OM Optimisation</b>', + self) self.omoptim.triggered.connect(self.open_OMoptim) - - #Adding Action Widget to tool bar + + # Adding Action Widget to tool bar self.lefttoolbar = QtGui.QToolBar('Left ToolBar') self.addToolBar(QtCore.Qt.LeftToolBarArea, self.lefttoolbar) self.lefttoolbar.addAction(self.kicad) @@ -148,131 +184,140 @@ class Application(QtGui.QMainWindow): self.lefttoolbar.addAction(self.omedit) self.lefttoolbar.addAction(self.omoptim) self.lefttoolbar.setOrientation(QtCore.Qt.Vertical) - self.lefttoolbar.setIconSize(QSize(40,40)) - + self.lefttoolbar.setIconSize(QSize(40, 40)) + def closeEvent(self, event): - exit_msg = "Are you sure you want to exit the program ? All unsaved data will be lost." - reply = QtGui.QMessageBox.question(self, 'Message', - exit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) - - if reply == QtGui.QMessageBox.Yes: + exit_msg = "Are you sure you want to exit the program\ + ? All unsaved data will be lost." + reply = QtGui.QMessageBox.question( + self, 'Message', exit_msg, QtGui.QMessageBox.Yes, + QtGui.QMessageBox.No) + + if reply == QtGui.QMessageBox.Yes: for proc in self.obj_appconfig.procThread_list: - try: - proc.terminate() - except: - pass - try: + try: + proc.terminate() + except BaseException: + pass + try: for process_object in self.obj_appconfig.process_obj: try: process_object.close() - except: - pass - except: + except BaseException: + pass + except BaseException: pass - ##Just checking if open project and New project window is open. If yes just close it when application is closed + # Just checking if open project and New project window is open. If + # yes just close it when application is closed try: self.project.close() - except: + except BaseException: pass event.accept() self.systemTrayIcon.showMessage('Exit', 'eSim is Closed.') - + elif reply == QtGui.QMessageBox.No: event.ignore() - - + def close_project(self): - print "Function : Close Project" + print("Function : Close Project") current_project = self.obj_appconfig.current_project['ProjectName'] - if current_project==None: + if current_project is None: pass else: - for pid in self.obj_appconfig.proc_dict[self.obj_appconfig.current_project['ProjectName']]: + temp = self.obj_appconfig.current_project['ProjectName'] + for pid in self.obj_appconfig.proc_dict[temp]: try: os.kill(pid, 9) - except: + except BaseException: pass self.obj_Mainview.obj_dockarea.closeDock() self.obj_appconfig.current_project['ProjectName'] = None - self.systemTrayIcon.showMessage('Close', 'Current project '+os.path.basename(current_project)+' is Closed.') - + self.systemTrayIcon.showMessage( + 'Close', + 'Current project ' + + os.path.basename(current_project) + + ' is Closed.') + def new_project(self): """ This function call New Project Info class. """ - text, ok = QtGui.QInputDialog.getText(self, 'New Project Info','Enter Project Name:') + text, ok = QtGui.QInputDialog.getText( + self, 'New Project Info', 'Enter Project Name:') if ok: self.projname = (str(text)) self.project = NewProjectInfo() - directory, filelist =self.project.createProject(self.projname) - - self.obj_Mainview.obj_projectExplorer.addTreeNode(directory, filelist) - + directory, filelist = self.project.createProject(self.projname) + + self.obj_Mainview.obj_projectExplorer.addTreeNode( + directory, filelist) + else: - print "No new project created" + print("No new project created") self.obj_appconfig.print_info('No new project created') try: - self.obj_appconfig.print_info('Current project is : ' + self.obj_appconfig.current_project["ProjectName"]) - except: + self.obj_appconfig.print_info( + 'Current project is : ' + + self.obj_appconfig.current_project["ProjectName"]) + except BaseException: pass - + def open_project(self): """ This project call Open Project Info class """ - print "Function : Open Project" + print("Function : Open Project") self.project = OpenProjectInfo() - + try: directory, filelist = self.project.body() - self.obj_Mainview.obj_projectExplorer.addTreeNode(directory, filelist) - except: + self.obj_Mainview.obj_projectExplorer.addTreeNode( + directory, filelist) + except BaseException: pass - - - - + def help_project(self): - print "Function : Help" + print("Function : Help") self.obj_appconfig.print_info('Help is called') - print "Current Project is : ",self.obj_appconfig.current_project - self.obj_Mainview.obj_dockarea.usermanual() - - + print("Current Project is : ", self.obj_appconfig.current_project) + self.obj_Mainview.obj_dockarea.usermanual() + def open_ngspice(self): """ This Function execute ngspice on current project """ - + self.projDir = self.obj_appconfig.current_project["ProjectName"] - - if self.projDir != None: + + if self.projDir is not None: self.obj_Mainview.obj_dockarea.ngspiceEditor(self.projDir) - time.sleep(2) #Need permanent solution - #Calling Python Plotting - + time.sleep(2) # Need permanent solution + # Calling Python Plotting + try: self.obj_Mainview.obj_dockarea.plottingEditor() except Exception as e: self.msg = QtGui.QErrorMessage(None) self.msg.showMessage('Error while opening python plotting Editor.\ Please look at console for more details ') - print "Exception Message:",str(e) + print("Exception Message:", str(e)) self.obj_appconfig.print_error('Exception Message : ' + str(e)) self.msg.setWindowTitle("Error Message") - + else: self.msg = QtGui.QErrorMessage() - self.msg.showMessage('Please select the project first. You can either create new project or open existing project') + self.msg.showMessage('Please select the project first. You can either\ + create new project or open existing project') self.msg.setWindowTitle("Error Message") - + def open_subcircuit(self): - print "Function : Subcircuit editor" + print("Function : Subcircuit editor") self.obj_appconfig.print_info('Subcircuit editor is called') self.obj_Mainview.obj_dockarea.subcircuiteditor() def open_nghdl(self): - print "Function : Nghdl" + print("Function : Nghdl") self.obj_appconfig.print_info('Nghdl is called') if self.obj_validation.validateTool('nghdl'): @@ -282,80 +327,100 @@ class Application(QtGui.QMainWindow): else: self.msg = QtGui.QErrorMessage(None) - self.msg.showMessage('Error while opening nghdl. Please make sure nghdl is installed') - self.obj_appconfig.print_error('Error while opening nghdl. Please make sure nghdl is installed') + self.msg.showMessage('Error while opening nghdl.\ + Please make sure nghdl is installed') + self.obj_appconfig.print_error('Error while opening nghdl.\ + Please make sure nghdl is installed') self.msg.setWindowTitle('nghdl Error Message') - - + def open_modelEditor(self): - print "Function : Model editor" + print("Function : Model editor") self.obj_appconfig.print_info('Model editor is called') self.obj_Mainview.obj_dockarea.modelEditor() - def open_OMedit(self): """ - This function call ngspice to OM edit converter and then launch OM edit. + This function call ngspice to OM edit converter + and then launch OM edit. """ self.obj_appconfig.print_info('OM edit is called') self.projDir = self.obj_appconfig.current_project["ProjectName"] - - if self.projDir != None: + + if self.projDir is not None: if self.obj_validation.validateCirOut(self.projDir): self.projName = os.path.basename(self.projDir) - self.ngspiceNetlist = os.path.join(self.projDir,self.projName+".cir.out") - self.modelicaNetlist = os.path.join(self.projDir,self.projName+".mo") - + self.ngspiceNetlist = os.path.join( + self.projDir, self.projName + ".cir.out") + self.modelicaNetlist = os.path.join( + self.projDir, self.projName + ".mo") + """ try: - #Creating a command for Ngspice to Modelica converter - self.cmd1 = "python ../ngspicetoModelica/NgspicetoModelica.py "+self.ngspiceNetlist + # Creating a command for Ngspice to Modelica converter + self.cmd1 = " + python ../ngspicetoModelica/NgspicetoModelica.py "\ + +self.ngspiceNetlist self.obj_workThread1 = Worker.WorkerThread(self.cmd1) self.obj_workThread1.start() - - + + if self.obj_validation.validateTool("OMEdit"): - #Creating command to run OMEdit + # Creating command to run OMEdit self.cmd2 = "OMEdit "+self.modelicaNetlist self.obj_workThread2 = Worker.WorkerThread(self.cmd2) self.obj_workThread2.start() else: self.msg = QtGui.QMessageBox() - self.msgContent = "There was an error while opening OMEdit.<br/>\ - Please make sure OpenModelica is installed in your system. <br/>\ - To install it on Linux : Go to <a href=https://www.openmodelica.org/download/download-linux>OpenModelica Linux</a> and install nigthly build release.<br/>\ - To install it on Windows : Go to <a href=https://www.openmodelica.org/download/download-windows>OpenModelica Windows</a> and install latest version.<br/>" + self.msgContent = "There was an error while + opening OMEdit.<br/>\ + Please make sure OpenModelica is installed in your\ + system. <br/>\ + To install it on Linux : Go to\ + <a href=https://www.openmodelica.org/download/\ + download-linux>OpenModelica Linux</a> and \ + install nigthly build release.<br/>\ + To install it on Windows : Go to\ + <a href=https://www.openmodelica.org/download/\ + download-windows>OpenModelica Windows</a>\ + and install latest version.<br/>" self.msg.setTextFormat(QtCore.Qt.RichText) self.msg.setText(self.msgContent) self.msg.setWindowTitle("Missing OpenModelica") self.obj_appconfig.print_info(self.msgContent) self.msg.exec_() - + except Exception as e: self.msg = QtGui.QErrorMessage() - self.msg.showMessage('Unable to convert NgSpice netlist to Modelica netlist :'+str(e)) - self.msg.setWindowTitle("Ngspice to Modelica conversion error") + self.msg.showMessage( + 'Unable to convert NgSpice netlist to\ + Modelica netlist :'+str(e)) + self.msg.setWindowTitle( + "Ngspice to Modelica conversion error") self.obj_appconfig.print_error(str(e)) """ self.obj_Mainview.obj_dockarea.modelicaEditor(self.projDir) - + else: self.msg = QtGui.QErrorMessage() - self.msg.showMessage('Current project does not contain any ngspice file. Please create ngspice file with extension .cir.out') + self.msg.showMessage( + 'Current project does not contain any ngspice file.\ + Please create ngspice file with extension .cir.out') self.msg.setWindowTitle("Missing Ngspice netlist") else: self.msg = QtGui.QErrorMessage() - self.msg.showMessage('Please select the project first. You can either create new project or open existing project') + self.msg.showMessage( + 'Please select the project first.\ + You can either create new project\ + or open existing project') self.msg.setWindowTitle("Error Message") - - + def open_OMoptim(self): - print "Function : OM Optim" + print("Function : OM Optim") self.obj_appconfig.print_info('OM Optim is called') - #Check if OMOptim is installed + # Check if OMOptim is installed if self.obj_validation.validateTool("OMOptim"): - #Creating a command to run + # Creating a command to run self.cmd = "OMOptim" self.obj_workThread = Worker.WorkerThread(self.cmd) self.obj_workThread.start() @@ -363,93 +428,97 @@ class Application(QtGui.QMainWindow): self.msg = QtGui.QMessageBox() self.msgContent = "There was an error while opening OMOptim.<br/>\ Please make sure OpenModelica is installed in your system. <br/>\ - To install it on Linux : Go to <a href=https://www.openmodelica.org/download/download-linux>OpenModelica Linux</a> and install nigthly build release.<br/>\ - To install it on Windows : Go to <a href=https://www.openmodelica.org/download/download-windows>OpenModelica Windows</a> and install latest version.<br/>" + To install it on Linux : Go to <a href=https://www.openmodelica\ + .org/download/download-linux>OpenModelica Linux</a> and \ + install nigthly build release.<br/>\ + To install it on Windows : Go to <a href=https://www.openmodelica.\ + org/download/download-windows>OpenModelica Windows</a> and \ + install latest version.<br/>" self.msg.setTextFormat(QtCore.Qt.RichText) self.msg.setText(self.msgContent) self.msg.setWindowTitle("Error Message") self.obj_appconfig.print_info(self.msgContent) self.msg.exec_() + class MainView(QtGui.QWidget): """ This class initialize the Main View of Application """ + def __init__(self, *args): # call init method of superclass QtGui.QWidget.__init__(self, *args) - + self.obj_appconfig = Appconfig() - + self.leftSplit = QtGui.QSplitter() self.middleSplit = QtGui.QSplitter() - + self.mainLayout = QtGui.QVBoxLayout() - #Intermediate Widget + # Intermediate Widget self.middleContainer = QtGui.QWidget() self.middleContainerLayout = QtGui.QVBoxLayout() - - #Area to be included in MainView + + # Area to be included in MainView self.noteArea = QtGui.QTextEdit() self.noteArea.setReadOnly(True) self.obj_appconfig.noteArea['Note'] = self.noteArea - self.obj_appconfig.noteArea['Note'].append(' eSim Started......') + self.obj_appconfig.noteArea['Note'].append( + ' eSim Started......') self.obj_appconfig.noteArea['Note'].append('Project Selected : None') self.obj_appconfig.noteArea['Note'].append('\n') - - #CSS + # CSS self.noteArea.setStyleSheet(" \ - QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; } \ + QWidget { border-radius: 15px; border: 1px \ + solid gray; padding: 5px; } \ ") - + self.obj_dockarea = DockArea.DockArea() self.obj_projectExplorer = ProjectExplorer.ProjectExplorer() - - #Adding content to vertical middle Split. + + # Adding content to vertical middle Split. self.middleSplit.setOrientation(QtCore.Qt.Vertical) self.middleSplit.addWidget(self.obj_dockarea) self.middleSplit.addWidget(self.noteArea) - - #Adding middle split to Middle Container Widget + + # Adding middle split to Middle Container Widget self.middleContainerLayout.addWidget(self.middleSplit) self.middleContainer.setLayout(self.middleContainerLayout) - - #Adding content of left split + + # Adding content of left split self.leftSplit.addWidget(self.obj_projectExplorer) self.leftSplit.addWidget(self.middleContainer) - - - #Adding to main Layout + + # Adding to main Layout self.mainLayout.addWidget(self.leftSplit) - self.leftSplit.setSizes([self.width()/4.5,self.height()]) - self.middleSplit.setSizes([self.width(),self.height()/2]) + self.leftSplit.setSizes([self.width() / 4.5, self.height()]) + self.middleSplit.setSizes([self.width(), self.height() / 2]) self.setLayout(self.mainLayout) - + def main(args): """ It is main function of the module.It starts the application """ - print "Starting eSim......" + print("Starting eSim......") app = QtGui.QApplication(args) - + splash_pix = QtGui.QPixmap('../../images/splash_screen_esim.png') - splash = QtGui.QSplashScreen(splash_pix,QtCore.Qt.WindowStaysOnTopHint) + splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() appView = Application() - appView.splash=splash + appView.splash = splash appView.obj_workspace.returnWhetherClickedOrNot(appView) appView.hide() - appView.obj_workspace.show() + appView.obj_workspace.show() sys.exit(app.exec_()) - - - + + # Call main function + + if __name__ == '__main__': # Create and display the splash screen main(sys.argv) - - - diff --git a/src/frontEnd/DockArea.py b/src/frontEnd/DockArea.py index 073072bf..b44a87e6 100644 --- a/src/frontEnd/DockArea.py +++ b/src/frontEnd/DockArea.py @@ -1,4 +1,4 @@ -from PyQt4 import QtGui,QtCore +from PyQt4 import QtGui, QtCore from ngspiceSimulation.pythonPlotting import plotWindow from ngspiceSimulation.NgspiceWidget import NgspiceWidget from configuration.Appconfig import Appconfig @@ -14,6 +14,7 @@ dockList = ['Welcome'] count = 1 dock = {} + class DockArea(QtGui.QMainWindow): def __init__(self): @@ -24,18 +25,19 @@ class DockArea(QtGui.QMainWindow): dock[dockName] = QtGui.QDockWidget(dockName) self.welcomeWidget = QtGui.QWidget() self.welcomeLayout = QtGui.QVBoxLayout() - self.welcomeLayout.addWidget(Welcome()) ##Call browser - - #Adding to main Layout + self.welcomeLayout.addWidget(Welcome()) # Call browser + + # Adding to main Layout self.welcomeWidget.setLayout(self.welcomeLayout) dock[dockName].setWidget(self.welcomeWidget) - #CSS + # CSS dock[dockName].setStyleSheet(" \ - QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ - ") - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock[dockName]) - - #self.tabifyDockWidget(dock['Notes'],dock['Blank']) + QWidget { border-radius: 15px; border: 1px solid gray;\ + padding: 5px; width: 200px; height: 150px; } \ + ") + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock[dockName]) + + # self.tabifyDockWidget(dock['Notes'],dock['Blank']) self.show() ''' @@ -50,10 +52,11 @@ class DockArea(QtGui.QMainWindow): dock[dockName].setWidget(self.welcome) #CSS dock[dockName].setStyleSheet(" \ - QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ - ") - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock[dockName]) - + QWidget { border-radius: 15px; border: 1px solid gray;\ + padding: 5px; width: 200px; height: 150px; } \ + ") + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock[dockName]) + #self.tabifyDockWidget(dock['Notes'],dock['Blank']) self.show() ''' @@ -68,31 +71,36 @@ class DockArea(QtGui.QMainWindow): self.testArea = QtGui.QTextEdit() self.testLayout = QtGui.QVBoxLayout() self.testLayout.addWidget(self.testArea) - - #Adding to main Layout + + # Adding to main Layout self.testWidget.setLayout(self.testLayout) - dock['Tips-'+str(count)] = QtGui.QDockWidget('Tips-'+str(count)) - dock['Tips-'+str(count)].setWidget(self.testWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['Tips-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['Tips-'+str(count)]) - + dock['Tips-' + str(count)] = QtGui.QDockWidget('Tips-' + str(count)) + dock['Tips-' + str(count)].setWidget(self.testWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['Tips-' + str(count)]) + self.tabifyDockWidget( + dock['Welcome'], dock['Tips-' + str(count)]) + """ #CSS dock['Tips-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px;\ + width: 200px; height: 150px; } \ ") """ - - dock['Tips-'+str(count)].setVisible(True) - dock['Tips-'+str(count)].setFocus() + + dock['Tips-' + str(count)].setVisible(True) + dock['Tips-' + str(count)].setFocus() """ dock['Tips-'+str(count)].setStyleSheet(" \ :hover { background-color: yellow; } \ ") """ - dock['Tips-'+str(count)].raise_() + dock['Tips-' + str(count)].raise_() - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['Tips-'+str(count)]) + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['Tips-' + str(count)]) count = count + 1 def plottingEditor(self): @@ -101,150 +109,177 @@ class DockArea(QtGui.QMainWindow): """ self.projDir = self.obj_appconfig.current_project["ProjectName"] self.projName = os.path.basename(self.projDir) - #self.project = os.path.join(self.projDir,self.projName) - - + # self.project = os.path.join(self.projDir,self.projName) + global count self.plottingWidget = QtGui.QWidget() self.plottingLayout = QtGui.QVBoxLayout() - self.plottingLayout.addWidget(plotWindow(self.projDir,self.projName)) - - #Adding to main Layout + self.plottingLayout.addWidget(plotWindow(self.projDir, self.projName)) + + # Adding to main Layout self.plottingWidget.setLayout(self.plottingLayout) - dock['Plotting-'+str(count)] = QtGui.QDockWidget('Plotting-'+str(count)) - dock['Plotting-'+str(count)].setWidget(self.plottingWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['Plotting-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['Plotting-'+str(count)]) - + dock['Plotting-' + str(count) + ] = QtGui.QDockWidget('Plotting-' + str(count)) + dock['Plotting-' + str(count)].setWidget(self.plottingWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['Plotting-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], dock['Plotting-' + str(count)]) + """ #CSS dock['Plotting-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px;\ + width: 200px; height: 150px; } \ ") """ - dock['Plotting-'+str(count)].setVisible(True) - dock['Plotting-'+str(count)].setFocus() - dock['Plotting-'+str(count)].raise_() + dock['Plotting-' + str(count)].setVisible(True) + dock['Plotting-' + str(count)].setFocus() + dock['Plotting-' + str(count)].raise_() - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['Plotting-'+str(count)]) + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['Plotting-' + str(count)]) count = count + 1 - - def ngspiceEditor(self,projDir): + + def ngspiceEditor(self, projDir): """ This function creates widget for NgSpice window """ - - + self.projDir = projDir self.projName = os.path.basename(self.projDir) - self.ngspiceNetlist = os.path.join(self.projDir,self.projName+".cir.out") - - - + self.ngspiceNetlist = os.path.join( + self.projDir, self.projName + ".cir.out") + global count self.ngspiceWidget = QtGui.QWidget() self.ngspiceLayout = QtGui.QVBoxLayout() - self.ngspiceLayout.addWidget(NgspiceWidget(self.ngspiceNetlist,self.projDir)) - - #Adding to main Layout + self.ngspiceLayout.addWidget( + NgspiceWidget( + self.ngspiceNetlist, + self.projDir)) + + # Adding to main Layout self.ngspiceWidget.setLayout(self.ngspiceLayout) - dock['NgSpice-'+str(count)] = QtGui.QDockWidget('NgSpice-'+str(count)) - dock['NgSpice-'+str(count)].setWidget(self.ngspiceWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['NgSpice-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['NgSpice-'+str(count)]) + dock['NgSpice-' + str(count) + ] = QtGui.QDockWidget('NgSpice-' + str(count)) + dock['NgSpice-' + str(count)].setWidget(self.ngspiceWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['NgSpice-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], dock['NgSpice-' + str(count)]) - #CSS - dock['NgSpice-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 0px; width: 200px; height: 150px; } \ + # CSS + dock['NgSpice-' + str(count)].setStyleSheet(" \ + .QWidget { border-radius: 15px; border: 1px solid gray; padding: 0px;\ + width: 200px; height: 150px; } \ ") - - dock['NgSpice-'+str(count)].setVisible(True) - dock['NgSpice-'+str(count)].setFocus() - dock['NgSpice-'+str(count)].raise_() - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['NgSpice-'+str(count)]) + + dock['NgSpice-' + str(count)].setVisible(True) + dock['NgSpice-' + str(count)].setFocus() + dock['NgSpice-' + str(count)].raise_() + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['NgSpice-' + str(count)]) count = count + 1 - def modelEditor(self): - print"in model editor" - global count - self.modelwidget = QtGui.QWidget() - - self.modellayout = QtGui.QVBoxLayout() - self.modellayout.addWidget(ModelEditorclass()) - - #Adding to main Layout - self.modelwidget.setLayout(self.modellayout) - - dock['Model Editor-'+str(count)] = QtGui.QDockWidget('Model Editor-'+str(count)) - dock['Model Editor-'+str(count)].setWidget(self.modelwidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['Model Editor-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['Model Editor-'+str(count)]) - - #CSS - dock['Model Editor-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + def modelEditor(self): + print("in model editor") + global count + self.modelwidget = QtGui.QWidget() + + self.modellayout = QtGui.QVBoxLayout() + self.modellayout.addWidget(ModelEditorclass()) + + # Adding to main Layout + self.modelwidget.setLayout(self.modellayout) + + dock['Model Editor-' + + str(count)] = QtGui.QDockWidget('Model Editor-' + str(count)) + dock['Model Editor-' + str(count)].setWidget(self.modelwidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['Model Editor-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], + dock['Model Editor-' + str(count)]) + + # CSS + dock['Model Editor-' + str(count)].setStyleSheet(" \ + .QWidget { border-radius: 15px; border: 1px solid gray; \ + padding: 5px; width: 200px; height: 150px; } \ ") - - dock['Model Editor-'+str(count)].setVisible(True) - dock['Model Editor-'+str(count)].setFocus() - dock['Model Editor-'+str(count)].raise_() - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['Model Editor-'+str(count)]) - count = count + 1 - - def kicadToNgspiceEditor(self,clarg1,clarg2=None): + dock['Model Editor-' + str(count)].setVisible(True) + dock['Model Editor-' + str(count)].setFocus() + dock['Model Editor-' + str(count)].raise_() + + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['Model Editor-' + str(count)]) + count = count + 1 + + def kicadToNgspiceEditor(self, clarg1, clarg2=None): global count - self.kicadToNgspiceWidget=QtGui.QWidget() - self.kicadToNgspiceLayout=QtGui.QVBoxLayout() - self.kicadToNgspiceLayout.addWidget(MainWindow(clarg1,clarg2)) - + self.kicadToNgspiceWidget = QtGui.QWidget() + self.kicadToNgspiceLayout = QtGui.QVBoxLayout() + self.kicadToNgspiceLayout.addWidget(MainWindow(clarg1, clarg2)) + self.kicadToNgspiceWidget.setLayout(self.kicadToNgspiceLayout) - dock['kicadToNgspice-'+str(count)] = QtGui.QDockWidget('kicadToNgspice-'+str(count)) - dock['kicadToNgspice-'+str(count)].setWidget(self.kicadToNgspiceWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['kicadToNgspice-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['kicadToNgspice-'+str(count)]) - - #CSS - dock['kicadToNgspice-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + dock['kicadToNgspice-' + + str(count)] = QtGui.QDockWidget('kicadToNgspice-' + str(count)) + dock['kicadToNgspice-' + + str(count)].setWidget(self.kicadToNgspiceWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['kicadToNgspice-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], + dock['kicadToNgspice-' + str(count)]) + + # CSS + dock['kicadToNgspice-' + str(count)].setStyleSheet(" \ + .QWidget { border-radius: 15px; border: 1px solid gray;\ + padding: 5px; width: 200px; height: 150px; } \ ") - - dock['kicadToNgspice-'+str(count)].setVisible(True) - dock['kicadToNgspice-'+str(count)].setFocus() - dock['kicadToNgspice-'+str(count)].raise_() - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['kicadToNgspice-'+str(count)]) + dock['kicadToNgspice-' + str(count)].setVisible(True) + dock['kicadToNgspice-' + str(count)].setFocus() + dock['kicadToNgspice-' + str(count)].raise_() + + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['kicadToNgspice-' + str(count)]) count = count + 1 - - def subcircuiteditor(self): """ This function creates a widget for different subcircuit options """ global count - self.subcktWidget=QtGui.QWidget() - self.subcktLayout=QtGui.QVBoxLayout() + self.subcktWidget = QtGui.QWidget() + self.subcktLayout = QtGui.QVBoxLayout() self.subcktLayout.addWidget(Subcircuit(self)) self.subcktWidget.setLayout(self.subcktLayout) - dock['Subcircuit-'+str(count)] = QtGui.QDockWidget('Subcircuit-'+str(count)) - dock['Subcircuit-'+str(count)].setWidget(self.subcktWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['Subcircuit-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['Subcircuit-'+str(count)]) - - #CSS - dock['Subcircuit-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + dock['Subcircuit-' + + str(count)] = QtGui.QDockWidget('Subcircuit-' + str(count)) + dock['Subcircuit-' + str(count)].setWidget(self.subcktWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['Subcircuit-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], + dock['Subcircuit-' + str(count)]) + + # CSS + dock['Subcircuit-' + str(count)].setStyleSheet(" \ + .QWidget { border-radius: 15px; border: 1px solid gray;\ + padding: 5px; width: 200px; height: 150px; } \ ") - - dock['Subcircuit-'+str(count)].setVisible(True) - dock['Subcircuit-'+str(count)].setFocus() - dock['Subcircuit-'+str(count)].raise_() - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['Subcircuit-'+str(count)]) + dock['Subcircuit-' + str(count)].setVisible(True) + dock['Subcircuit-' + str(count)].setFocus() + dock['Subcircuit-' + str(count)].raise_() + + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['Subcircuit-' + str(count)]) count = count + 1 def usermanual(self): @@ -253,25 +288,29 @@ class DockArea(QtGui.QMainWindow): """ global count - self.usermanualWidget=QtGui.QWidget() - self.usermanualLayout=QtGui.QVBoxLayout() + self.usermanualWidget = QtGui.QWidget() + self.usermanualLayout = QtGui.QVBoxLayout() self.usermanualLayout.addWidget(UserManual()) self.usermanualWidget.setLayout(self.usermanualLayout) - dock['User Manual-'+str(count)] = QtGui.QDockWidget('User Manual-'+str(count)) - dock['User Manual-'+str(count)].setWidget(self.usermanualWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['User Manual-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['User Manual-'+str(count)]) - - #CSS - dock['User Manual-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + dock['User Manual-' + + str(count)] = QtGui.QDockWidget('User Manual-' + str(count)) + dock['User Manual-' + str(count)].setWidget(self.usermanualWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['User Manual-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], + dock['User Manual-' + str(count)]) + + # CSS + dock['User Manual-' + str(count)].setStyleSheet(" \ + .QWidget { border-radius: 15px; border: 1px solid gray;\ + padding: 5px; width: 200px; height: 150px; } \ ") - - dock['User Manual-'+str(count)].setVisible(True) - dock['User Manual-'+str(count)].setFocus() - dock['User Manual-'+str(count)].raise_() - + + dock['User Manual-' + str(count)].setVisible(True) + dock['User Manual-' + str(count)].setFocus() + dock['User Manual-' + str(count)].raise_() + count = count + 1 def modelicaEditor(self, projDir): @@ -285,24 +324,29 @@ class DockArea(QtGui.QMainWindow): self.modelicaLayout.addWidget(OpenModelicaEditor(projDir)) self.modelicaWidget.setLayout(self.modelicaLayout) - dock['Modelica-'+str(count)] = QtGui.QDockWidget('Modelica-'+str(count)) - dock['Modelica-'+str(count)].setWidget(self.modelicaWidget) - self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['Modelica-'+str(count)]) - self.tabifyDockWidget(dock['Welcome'],dock['Modelica-'+str(count)]) + dock['Modelica-' + str(count) + ] = QtGui.QDockWidget('Modelica-' + str(count)) + dock['Modelica-' + str(count)].setWidget(self.modelicaWidget) + self.addDockWidget(QtCore.Qt.TopDockWidgetArea, + dock['Modelica-' + str(count)]) + self.tabifyDockWidget(dock['Welcome'], dock['Modelica-' + str(count)]) - dock['Modelica-'+str(count)].setVisible(True) - dock['Modelica-'+str(count)].setFocus() - dock['Modelica-'+str(count)].raise_() + dock['Modelica-' + str(count)].setVisible(True) + dock['Modelica-' + str(count)].setFocus() + dock['Modelica-' + str(count)].raise_() - #CSS - dock['Modelica-'+str(count)].setStyleSheet(" \ - .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + # CSS + dock['Modelica-' + str(count)].setStyleSheet(" \ + .QWidget { border-radius: 15px; border: 1px solid gray;\ + padding: 5px; width: 200px; height: 150px; } \ ") - - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['Modelica-'+str(count)]) + temp = self.obj_appconfig.current_project['ProjectName'] + self.obj_appconfig.dock_dict[temp].append( + dock['Modelica-' + str(count)]) count = count + 1 - def closeDock (self): - for dockwidget in self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']]: + def closeDock(self): + temp = self.obj_appconfig.current_project['ProjectName'] + for dockwidget in self.obj_appconfig.dock_dict[temp]: dockwidget.close() diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py index d14a8da9..77b3f124 100644 --- a/src/frontEnd/ProjectExplorer.py +++ b/src/frontEnd/ProjectExplorer.py @@ -1,4 +1,4 @@ -from PyQt4 import QtGui,QtCore +from PyQt4 import QtGui, QtCore import os import json from configuration.Appconfig import Appconfig @@ -9,139 +9,181 @@ class ProjectExplorer(QtGui.QWidget): QtGui.QWidget.__init__(self) self.obj_appconfig = Appconfig() self.treewidget = QtGui.QTreeWidget() - self.window= QtGui.QVBoxLayout() - header = QtGui.QTreeWidgetItem(["Projects","path"]) + self.window = QtGui.QVBoxLayout() + header = QtGui.QTreeWidgetItem(["Projects", "path"]) self.treewidget.setHeaderItem(header) - self.treewidget.setColumnHidden(1,True) - - #CSS + self.treewidget.setColumnHidden(1, True) + + # CSS self.treewidget.setStyleSheet(" \ - QTreeView { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ - QTreeView::branch:has-siblings:!adjoins-item { border-image: url(../../images/vline.png) 0; } \ - QTreeView::branch:has-siblings:adjoins-item { border-image: url(../../images/branch-more.png) 0; } \ - QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: url(../../images/branch-end.png) 0; } \ + QTreeView { border-radius: 15px; border: 1px solid gray; padding: \ + 5px; width: 200px; height: 150px; } \ + QTreeView::branch:has-siblings:!adjoins-item { border-image:\ + url(../../images/vline.png) 0; } \ + QTreeView::branch:has-siblings:adjoins-item { border-image:\ + url(../../images/branch-more.png) 0; } \ + QTreeView::branch:!has-children:!has-siblings:\ + adjoins-item { border-image: url(../../images/branch-end.png) 0; } \ QTreeView::branch:has-children:!has-siblings:closed, \ - QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(../../images/branch-closed.png); } \ + QTreeView::branch:closed:has-children:has-siblings { border-image:\ + none; image: url(../../images/branch-closed.png); } \ QTreeView::branch:open:has-children:!has-siblings, \ - QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(../../images/branch-open.png); } \ + QTreeView::branch:open:has-children:has-siblings { border-image: \ + none; image: url(../../images/branch-open.png); } \ ") - - for parents, children in self.obj_appconfig.project_explorer.items(): + + for parents, children in list( + self.obj_appconfig.project_explorer.items()): os.path.join(parents) if os.path.exists(parents): - pathlist= parents.split(os.sep) - parentnode = QtGui.QTreeWidgetItem(self.treewidget, [pathlist[-1],parents]) + pathlist = parents.split(os.sep) + parentnode = QtGui.QTreeWidgetItem( + self.treewidget, [pathlist[-1], parents]) for files in children: - childnode = QtGui.QTreeWidgetItem(parentnode, [files, os.path.join(parents,files)]) + QtGui.QTreeWidgetItem( + parentnode, [files, os.path.join(parents, files)]) self.window.addWidget(self.treewidget) - + self.treewidget.doubleClicked.connect(self.openProject) self.treewidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treewidget.customContextMenuRequested.connect(self.openMenu) self.setLayout(self.window) self.show() - + def addTreeNode(self, parents, children): os.path.join(parents) - pathlist= parents.split(os.sep) - parentnode = QtGui.QTreeWidgetItem(self.treewidget, [pathlist[-1], parents]) + pathlist = parents.split(os.sep) + parentnode = QtGui.QTreeWidgetItem( + self.treewidget, [pathlist[-1], parents]) for files in children: - childnode = QtGui.QTreeWidgetItem(parentnode, [files, os.path.join(parents,files)]) - self.obj_appconfig.proc_dict[self.obj_appconfig.current_project['ProjectName']] = [] - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']] = [] - + QtGui.QTreeWidgetItem( + parentnode, [files, os.path.join(parents, files)] + ) + + ( + self.obj_appconfig. + proc_dict[self.obj_appconfig.current_project['ProjectName']] + ) = [] + ( + self.obj_appconfig. + dock_dict[self.obj_appconfig.current_project['ProjectName']] + ) = [] + def openMenu(self, position): - + indexes = self.treewidget.selectedIndexes() if len(indexes) > 0: - + level = 0 index = indexes[0] while index.parent().isValid(): index = index.parent() level += 1 - + menu = QtGui.QMenu() if level == 0: deleteproject = menu.addAction(self.tr("Remove Project")) deleteproject.triggered.connect(self.removeProject) - refreshproject= menu.addAction(self.tr("Refresh")) + refreshproject = menu.addAction(self.tr("Refresh")) refreshproject.triggered.connect(self.refreshProject) elif level == 1: openfile = menu.addAction(self.tr("Open")) openfile.triggered.connect(self.openProject) - - menu.exec_(self.treewidget.viewport().mapToGlobal(position)) - + + menu.exec_(self.treewidget.viewport().mapToGlobal(position)) + def openProject(self): - self.indexItem =self.treewidget.currentIndex() - filename= self.indexItem.data().toString() - self.filePath= self.indexItem.sibling(self.indexItem.row(), 1).data().toString() - self.obj_appconfig.print_info('The current project is ' + self.filePath) - + self.indexItem = self.treewidget.currentIndex() + filename = str(self.indexItem.data()) + self.filePath = str( + self.indexItem.sibling( + self.indexItem.row(), + 1).data()) + self.obj_appconfig.print_info( + 'The current project is ' + self.filePath) + self.textwindow = QtGui.QWidget() self.textwindow.setMinimumSize(600, 500) - self.textwindow.setGeometry(QtCore.QRect(400,150,400,400)) + self.textwindow.setGeometry(QtCore.QRect(400, 150, 400, 400)) self.textwindow.setWindowTitle(filename) - + self.text = QtGui.QTextEdit() self.save = QtGui.QPushButton('Save and Exit') self.save.setDisabled(True) self.windowgrid = QtGui.QGridLayout() - if (os.path.isfile(str(self.filePath)))== True: + # if (os.path.isfile(str(self.filePath))) == True: + if (os.path.isfile(str(self.filePath))): self.fopen = open(str(self.filePath), 'r') lines = self.fopen.read() self.text.setText(lines) - - QtCore.QObject.connect(self.text,QtCore.SIGNAL("textChanged()"), self.enable_save) - + + QtCore.QObject.connect( + self.text, + QtCore.SIGNAL("textChanged()"), + self.enable_save) + vbox_main = QtGui.QVBoxLayout(self.textwindow) vbox_main.addWidget(self.text) vbox_main.addWidget(self.save) self.save.clicked.connect(self.save_data) - #self.connect(exit,QtCore.SIGNAL('close()'), self.onQuit) - + # self.connect(exit,QtCore.SIGNAL('close()'), self.onQuit) + self.textwindow.show() else: - self.obj_appconfig.current_project["ProjectName"]= str(self.filePath) - self.obj_appconfig.proc_dict[self.obj_appconfig.current_project['ProjectName']] = [] - if self.obj_appconfig.current_project['ProjectName'] not in self.obj_appconfig.dock_dict: - self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']] = [] - + self.obj_appconfig.current_project["ProjectName"] = str( + self.filePath) + self.obj_appconfig.proc_dict + [self.obj_appconfig.current_project['ProjectName']] = [ + ] + if self.obj_appconfig.current_project['ProjectName'] \ + not in self.obj_appconfig.dock_dict: + self.obj_appconfig.dock_dict + [self.obj_appconfig.current_project['ProjectName']] = [ + ] + def enable_save(self): self.save.setEnabled(True) - + def save_data(self): - self.fopen=open(self.filePath, 'w') + self.fopen = open(self.filePath, 'w') self.fopen.write(self.text.toPlainText()) self.fopen.close() self.textwindow.close() - + def removeProject(self): - self.indexItem =self.treewidget.currentIndex() - filename= self.indexItem.data().toString() - self.filePath= self.indexItem.sibling(self.indexItem.row(), 1).data().toString() + self.indexItem = self.treewidget.currentIndex() + self.filePath = str( + self.indexItem.sibling( + self.indexItem.row(), + 1).data()) self.int = self.indexItem.row() self.treewidget.takeTopLevelItem(self.int) - + if self.obj_appconfig.current_project["ProjectName"] == self.filePath: - self.obj_appconfig.current_project["ProjectName"] = None - + self.obj_appconfig.current_project["ProjectName"] = None + del self.obj_appconfig.project_explorer[str(self.filePath)] - json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath,'w')) - + json.dump(self.obj_appconfig.project_explorer, + open(self.obj_appconfig.dictPath, 'w')) + def refreshProject(self): - self.indexItem =self.treewidget.currentIndex() - filename= self.indexItem.data().toString() - self.filePath= str(self.indexItem.sibling(self.indexItem.row(), 1).data().toString()) - filelistnew= os.listdir(os.path.join(self.filePath)) + self.indexItem = self.treewidget.currentIndex() + self.filePath = str( + self.indexItem.sibling( + self.indexItem.row(), + 1).data()) + filelistnew = os.listdir(os.path.join(self.filePath)) parentnode = self.treewidget.currentItem() count = parentnode.childCount() for i in range(count): for items in self.treewidget.selectedItems(): items.removeChild(items.child(0)) for files in filelistnew: - childnode= QtGui.QTreeWidgetItem(parentnode, [files, os.path.join(self.filePath,files)]) - - self.obj_appconfig.project_explorer[self.filePath]= filelistnew - json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath,'w')) + QtGui.QTreeWidgetItem( + parentnode, [ + files, os.path.join( + self.filePath, files)]) + + self.obj_appconfig.project_explorer[self.filePath] = filelistnew + json.dump(self.obj_appconfig.project_explorer, + open(self.obj_appconfig.dictPath, 'w')) diff --git a/src/frontEnd/ProjectExplorer.py.bak b/src/frontEnd/ProjectExplorer.py.bak new file mode 100644 index 00000000..8c75398e --- /dev/null +++ b/src/frontEnd/ProjectExplorer.py.bak @@ -0,0 +1,147 @@ +from PyQt4 import QtGui,QtCore +import os +import json +from configuration.Appconfig import Appconfig + + +class ProjectExplorer(QtGui.QWidget): + def __init__(self): + QtGui.QWidget.__init__(self) + self.obj_appconfig = Appconfig() + self.treewidget = QtGui.QTreeWidget() + self.window= QtGui.QVBoxLayout() + header = QtGui.QTreeWidgetItem(["Projects","path"]) + self.treewidget.setHeaderItem(header) + self.treewidget.setColumnHidden(1,True) + + #CSS + self.treewidget.setStyleSheet(" \ + QTreeView { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \ + QTreeView::branch:has-siblings:!adjoins-item { border-image: url(../../images/vline.png) 0; } \ + QTreeView::branch:has-siblings:adjoins-item { border-image: url(../../images/branch-more.png) 0; } \ + QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: url(../../images/branch-end.png) 0; } \ + QTreeView::branch:has-children:!has-siblings:closed, \ + QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(../../images/branch-closed.png); } \ + QTreeView::branch:open:has-children:!has-siblings, \ + QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(../../images/branch-open.png); } \ + ") + + for parents, children in list(self.obj_appconfig.project_explorer.items()): + os.path.join(parents) + if os.path.exists(parents): + pathlist= parents.split(os.sep) + parentnode = QtGui.QTreeWidgetItem(self.treewidget, [pathlist[-1],parents]) + for files in children: + childnode = QtGui.QTreeWidgetItem(parentnode, [files, os.path.join(parents,files)]) + self.window.addWidget(self.treewidget) + + self.treewidget.doubleClicked.connect(self.openProject) + self.treewidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.treewidget.customContextMenuRequested.connect(self.openMenu) + self.setLayout(self.window) + self.show() + + def addTreeNode(self, parents, children): + os.path.join(parents) + pathlist= parents.split(os.sep) + parentnode = QtGui.QTreeWidgetItem(self.treewidget, [pathlist[-1], parents]) + for files in children: + childnode = QtGui.QTreeWidgetItem(parentnode, [files, os.path.join(parents,files)]) + self.obj_appconfig.proc_dict[self.obj_appconfig.current_project['ProjectName']] = [] + self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']] = [] + + def openMenu(self, position): + + indexes = self.treewidget.selectedIndexes() + if len(indexes) > 0: + + level = 0 + index = indexes[0] + while index.parent().isValid(): + index = index.parent() + level += 1 + + menu = QtGui.QMenu() + if level == 0: + deleteproject = menu.addAction(self.tr("Remove Project")) + deleteproject.triggered.connect(self.removeProject) + refreshproject= menu.addAction(self.tr("Refresh")) + refreshproject.triggered.connect(self.refreshProject) + elif level == 1: + openfile = menu.addAction(self.tr("Open")) + openfile.triggered.connect(self.openProject) + + menu.exec_(self.treewidget.viewport().mapToGlobal(position)) + + def openProject(self): + self.indexItem =self.treewidget.currentIndex() + filename= self.indexItem.data().toString() + self.filePath= self.indexItem.sibling(self.indexItem.row(), 1).data().toString() + self.obj_appconfig.print_info('The current project is ' + self.filePath) + + self.textwindow = QtGui.QWidget() + self.textwindow.setMinimumSize(600, 500) + self.textwindow.setGeometry(QtCore.QRect(400,150,400,400)) + self.textwindow.setWindowTitle(filename) + + self.text = QtGui.QTextEdit() + self.save = QtGui.QPushButton('Save and Exit') + self.save.setDisabled(True) + self.windowgrid = QtGui.QGridLayout() + if (os.path.isfile(str(self.filePath)))== True: + self.fopen = open(str(self.filePath), 'r') + lines = self.fopen.read() + self.text.setText(lines) + + QtCore.QObject.connect(self.text,QtCore.SIGNAL("textChanged()"), self.enable_save) + + vbox_main = QtGui.QVBoxLayout(self.textwindow) + vbox_main.addWidget(self.text) + vbox_main.addWidget(self.save) + self.save.clicked.connect(self.save_data) + #self.connect(exit,QtCore.SIGNAL('close()'), self.onQuit) + + self.textwindow.show() + else: + self.obj_appconfig.current_project["ProjectName"]= str(self.filePath) + self.obj_appconfig.proc_dict[self.obj_appconfig.current_project['ProjectName']] = [] + if self.obj_appconfig.current_project['ProjectName'] not in self.obj_appconfig.dock_dict: + self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']] = [] + + def enable_save(self): + self.save.setEnabled(True) + + def save_data(self): + self.fopen=open(self.filePath, 'w') + self.fopen.write(self.text.toPlainText()) + self.fopen.close() + self.textwindow.close() + + def removeProject(self): + self.indexItem =self.treewidget.currentIndex() + filename= self.indexItem.data().toString() + self.filePath= self.indexItem.sibling(self.indexItem.row(), 1).data().toString() + self.int = self.indexItem.row() + self.treewidget.takeTopLevelItem(self.int) + + if self.obj_appconfig.current_project["ProjectName"] == self.filePath: + self.obj_appconfig.current_project["ProjectName"] = None + + del self.obj_appconfig.project_explorer[str(self.filePath)] + json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath,'w')) + + def refreshProject(self): + self.indexItem =self.treewidget.currentIndex() + filename= self.indexItem.data().toString() + self.filePath= str(self.indexItem.sibling(self.indexItem.row(), 1).data().toString()) + filelistnew= os.listdir(os.path.join(self.filePath)) + parentnode = self.treewidget.currentItem() + count = parentnode.childCount() + for i in range(count): + for items in self.treewidget.selectedItems(): + items.removeChild(items.child(0)) + for files in filelistnew: + childnode= QtGui.QTreeWidgetItem(parentnode, [files, os.path.join(self.filePath,files)]) + + self.obj_appconfig.project_explorer[self.filePath]= filelistnew + json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath,'w')) diff --git a/src/frontEnd/Workspace.py b/src/frontEnd/Workspace.py index 7cefa6c6..7bc74deb 100644 --- a/src/frontEnd/Workspace.py +++ b/src/frontEnd/Workspace.py @@ -1,20 +1,20 @@ -#=============================================================================== +# ========================================================================= # # FILE: Workspace.py -# -# USAGE: --- -# -# DESCRIPTION: This define all configuration used in Application. -# +# +# USAGE: --- +# +# DESCRIPTION: This define all configuration used in Application. +# # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Fahim Khan, fahim.elex@gmail.com # ORGANIZATION: eSim team at FOSSEE, IIT Bombay. -# CREATED: Wednesday 05 February 2015 +# CREATED: Wednesday 05 February 2015 # REVISION: --- -#=============================================================================== +# ========================================================================= from PyQt4 import QtCore, QtGui from configuration.Appconfig import Appconfig import time @@ -25,46 +25,46 @@ class Workspace(QtGui.QWidget): """ This class creates Workspace GUI. """ - def __init__(self,parent=None): + + def __init__(self, parent=None): super(Workspace, self).__init__() self.obj_appconfig = Appconfig() - - #Initializing Workspace directory for project + + # Initializing Workspace directory for project self.initWorkspace() - - + def initWorkspace(self): - #print "Calling workspace" - + # print "Calling workspace" + self.mainwindow = QtGui.QVBoxLayout() self.split = QtGui.QSplitter() self.split.setOrientation(QtCore.Qt.Vertical) - + self.grid = QtGui.QGridLayout() self.note = QtGui.QTextEdit(self) self.workspace_label = QtGui.QLabel(self) self.workspace_loc = QtGui.QLineEdit(self) - + self.note.append(self.obj_appconfig.workspace_text) self.workspace_label.setText("Workspace:") self.workspace_loc.setText(self.obj_appconfig.home) - - #Buttons + + # Buttons self.browsebtn = QtGui.QPushButton('Browse') self.browsebtn.clicked.connect(self.browseLocation) self.okbtn = QtGui.QPushButton('OK') self.okbtn.clicked.connect(self.createWorkspace) self.cancelbtn = QtGui.QPushButton('Cancel') self.cancelbtn.clicked.connect(self.defaultWorkspace) - #Layout - self.grid.addWidget(self.note, 0,0,1,15) - self.grid.addWidget(self.workspace_label, 2,1) - self.grid.addWidget(self.workspace_loc,2,2,2,12) - self.grid.addWidget(self.browsebtn, 2,14) - self.grid.addWidget(self.okbtn, 4,13) - self.grid.addWidget(self.cancelbtn, 4,14) - - self.setGeometry(QtCore.QRect(500,250,400,400)) + # Layout + self.grid.addWidget(self.note, 0, 0, 1, 15) + self.grid.addWidget(self.workspace_label, 2, 1) + self.grid.addWidget(self.workspace_loc, 2, 2, 2, 12) + self.grid.addWidget(self.browsebtn, 2, 14) + self.grid.addWidget(self.okbtn, 4, 13) + self.grid.addWidget(self.cancelbtn, 4, 14) + + self.setGeometry(QtCore.QRect(500, 250, 400, 400)) self.setMaximumSize(4000, 200) self.setWindowTitle("eSim") self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) @@ -72,50 +72,48 @@ class Workspace(QtGui.QWidget): self.setWindowIcon(QtGui.QIcon('../../images/logo.png')) self.setLayout(self.grid) self.show() - - + def defaultWorkspace(self): - print "Default workspace selected : "+self.obj_appconfig.default_workspace["workspace"] - self.imp_var=1 - self.obj_appconfig.print_info('Default workspace selected : ' + self.obj_appconfig.default_workspace["workspace"]) + print("Default workspace selected : " + + self.obj_appconfig.default_workspace["workspace"]) + self.imp_var = 1 + self.obj_appconfig.print_info( + 'Default workspace selected : ' + + self.obj_appconfig.default_workspace["workspace"]) self.close() var_appView.show() time.sleep(1) var_appView.splash.close() - - - def close(self, *args, **kwargs): - self.window_open_close=1 - self.close_var=1 + self.window_open_close = 1 + self.close_var = 1 return QtGui.QWidget.close(self, *args, **kwargs) - - def returnWhetherClickedOrNot(self,appView): + def returnWhetherClickedOrNot(self, appView): global var_appView - var_appView=appView + var_appView = appView - def createWorkspace(self): - print "Function : Create workspace" + print("Function : Create workspace") self.create_workspace = str(self.workspace_loc.text()) self.obj_appconfig.print_info('Workspace : ' + self.create_workspace) - #Checking if Workspace already exist or not - if os.path.isdir(self.create_workspace): - self.obj_appconfig.default_workspace["workspace"] = self.create_workspace + # Checking if Workspace already exist or not + if os.path.isdir(self.create_workspace): + self.obj_appconfig.default_workspace["workspace"] \ + = self.create_workspace else: os.mkdir(self.create_workspace) - self.obj_appconfig.default_workspace["workspace"] = self.create_workspace - self.imp_var=1 - self.close() + self.obj_appconfig.default_workspace["workspace"] \ + = self.create_workspace + self.imp_var = 1 + self.close() var_appView.show() time.sleep(1) var_appView.splash.close() - - + def browseLocation(self): - print "Function : Browse Location" - self.workspace_directory = QtGui.QFileDialog.getExistingDirectory(self, "Browse Location",os.path.expanduser("~")) + print("Function : Browse Location") + self.workspace_directory = QtGui.QFileDialog.getExistingDirectory( + self, "Browse Location", os.path.expanduser("~")) self.workspace_loc.setText(self.workspace_directory) -
\ No newline at end of file diff --git a/src/frontEnd/pathmagic.py b/src/frontEnd/pathmagic.py new file mode 100644 index 00000000..92a5e6e2 --- /dev/null +++ b/src/frontEnd/pathmagic.py @@ -0,0 +1,6 @@ +import os +import sys +# Setting PYTHONPATH +cwd = os.getcwd() +(setPath, fronEnd) = os.path.split(cwd) +sys.path.append(setPath)
\ No newline at end of file |