diff options
Diffstat (limited to 'src/frontEnd/Application.py')
-rw-r--r-- | src/frontEnd/Application.py | 205 |
1 files changed, 116 insertions, 89 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index 92013409..506f2fd8 100644 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -11,13 +11,21 @@ # NOTES: --- # AUTHOR: Fahim Khan, fahim.elex@gmail.com # MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in -# ORGANIZATION: eSim team at FOSSEE, IIT Bombay. +# ORGANIZATION: eSim Team at FOSSEE, IIT Bombay # CREATED: Tuesday 24 February 2015 -# REVISION: Friday 14 February 2020 +# REVISION: Saturday 01 August 2020 # ========================================================================= -from frontEnd import pathmagic # noqa -from PyQt4 import QtGui, QtCore +import os + +if os.name == 'nt': # noqa + from frontEnd import pathmagic # noqa:F401 + init_path = '' +else: + import pathmagic # noqa:F401 + init_path = '../../' + +from PyQt5 import QtGui, QtCore, QtWidgets from configuration.Appconfig import Appconfig from projManagement.openProject import OpenProjectInfo from projManagement.newProject import NewProjectInfo @@ -27,15 +35,14 @@ from projManagement import Worker from frontEnd import ProjectExplorer from frontEnd import Workspace from frontEnd import DockArea +from PyQt5.Qt import QSize +import shutil import time -from PyQt4.Qt import QSize import sys -import os -import shutil # Its our main window of application. -class Application(QtGui.QMainWindow): +class Application(QtWidgets.QMainWindow): """This class initializes all objects used in this file.""" global project_name @@ -43,7 +50,7 @@ class Application(QtGui.QMainWindow): """Initialize main Application window.""" # Calling __init__ of super class - QtGui.QMainWindow.__init__(self, *args) + QtWidgets.QMainWindow.__init__(self, *args) # Flag for mode of operation. Default is set to offline mode. self.online_flag = False @@ -62,13 +69,17 @@ class Application(QtGui.QMainWindow): 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.obj_appconfig._VERSION + ) self.showMaximized() - self.setWindowIcon(QtGui.QIcon('images/logo.png')) + self.setWindowIcon(QtGui.QIcon(init_path + 'images/logo.png')) - self.systemTrayIcon = QtGui.QSystemTrayIcon(self) - self.systemTrayIcon.setIcon(QtGui.QIcon('images/logo.png')) - self.systemTrayIcon.setVisible(True) + # self.systemTrayIcon = QtWidgets.QSystemTrayIcon(self) + # self.systemTrayIcon.setIcon( + # QtGui.QIcon(init_path + 'images/logo.png') + # ) + # self.systemTrayIcon.setVisible(True) def initToolBar(self): """ @@ -82,29 +93,29 @@ class Application(QtGui.QMainWindow): Converter, OM Optimisation) """ # Top Tool bar - self.newproj = QtGui.QAction( - QtGui.QIcon('images/newProject.png'), + self.newproj = QtWidgets.QAction( + QtGui.QIcon(init_path + 'images/newProject.png'), '<b>New Project</b>', self ) self.newproj.setShortcut('Ctrl+N') self.newproj.triggered.connect(self.new_project) - self.openproj = QtGui.QAction( - QtGui.QIcon('images/openProject.png'), + self.openproj = QtWidgets.QAction( + QtGui.QIcon(init_path + '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'), + self.closeproj = QtWidgets.QAction( + QtGui.QIcon(init_path + 'images/closeProject.png'), '<b>Close Project</b>', self ) self.closeproj.setShortcut('Ctrl+X') self.closeproj.triggered.connect(self.close_project) - self.wrkspce = QtGui.QAction( - QtGui.QIcon('images/workspace.ico'), + self.wrkspce = QtWidgets.QAction( + QtGui.QIcon(init_path + 'images/workspace.ico'), '<b>Change Workspace</b>', self ) self.wrkspce.setShortcut('Ctrl+W') @@ -113,18 +124,18 @@ class Application(QtGui.QMainWindow): self.switchmode = None self.validate_mode() if self.online_flag is True: - self.switchmode = QtGui.QAction(QtGui.QIcon( - 'images/online.png'), + self.switchmode = QtWidgets.QAction(QtGui.QIcon( + init_path + 'images/online.png'), '<b>Go Offline</b>', self ) elif self.online_flag is False: - self.switchmode = QtGui.QAction(QtGui.QIcon( - 'images/offline.png'), + self.switchmode = QtWidgets.QAction(QtGui.QIcon( + init_path + 'images/offline.png'), '<b>Go Online</b>', self ) elif self.online_flag is None: - self.switchmode = QtGui.QAction(QtGui.QIcon( - 'images/disable.png'), + self.switchmode = QtWidgets.QAction(QtGui.QIcon( + init_path + 'images/disable.png'), '<b>Mode switching has been disabled. ' + 'Default mode set to offline</b>', self ) @@ -132,8 +143,9 @@ class Application(QtGui.QMainWindow): self.switchmode.setShortcut('Ctrl+G') self.switchmode.triggered.connect(self.change_mode) - self.helpfile = QtGui.QAction( - QtGui.QIcon('images/helpProject.png'), '<b>Help</b>', self + self.helpfile = QtWidgets.QAction( + QtGui.QIcon(init_path + 'images/helpProject.png'), + '<b>Help</b>', self ) self.helpfile.setShortcut('Ctrl+H') self.helpfile.triggered.connect(self.help_project) @@ -148,15 +160,15 @@ class Application(QtGui.QMainWindow): # This part is setting fossee logo to the right # corner in the application window. - self.spacer = QtGui.QWidget() + self.spacer = QtWidgets.QWidget() self.spacer.setSizePolicy( - QtGui.QSizePolicy.Expanding, - QtGui.QSizePolicy.Expanding) + QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Expanding) self.topToolbar.addWidget(self.spacer) - self.logo = QtGui.QLabel() + self.logo = QtWidgets.QLabel() self.logopic = QtGui.QPixmap( os.path.join( - os.path.abspath(''), 'images', 'fosseeLogo.png' + os.path.abspath(''), init_path + 'images', 'fosseeLogo.png' )) self.logopic = self.logopic.scaled( QSize(150, 150), QtCore.Qt.KeepAspectRatio) @@ -165,51 +177,55 @@ class Application(QtGui.QMainWindow): self.topToolbar.addWidget(self.logo) # Left Tool bar Action Widget - self.kicad = QtGui.QAction( - QtGui.QIcon('images/kicad.png'), + self.kicad = QtWidgets.QAction( + QtGui.QIcon(init_path + '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'), + self.conversion = QtWidgets.QAction( + QtGui.QIcon(init_path + '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 = QtWidgets.QAction( + QtGui.QIcon(init_path + '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 = QtWidgets.QAction( + QtGui.QIcon(init_path + '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 = QtWidgets.QAction( + QtGui.QIcon(init_path + '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 = QtWidgets.QAction( + QtGui.QIcon(init_path + 'images/nghdl.png'), '<b>Nghdl</b>', self ) self.nghdl.triggered.connect(self.open_nghdl) - self.omedit = QtGui.QAction( - QtGui.QIcon('images/omedit.png'), + self.omedit = QtWidgets.QAction( + QtGui.QIcon(init_path + '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 = QtWidgets.QAction( + QtGui.QIcon(init_path + 'images/omoptim.png'), + '<b>OM Optimisation</b>', self ) self.omoptim.triggered.connect(self.open_OMoptim) # Adding Action Widget to tool bar - self.lefttoolbar = QtGui.QToolBar('Left ToolBar') + self.lefttoolbar = QtWidgets.QToolBar('Left ToolBar') self.addToolBar(QtCore.Qt.LeftToolBarArea, self.lefttoolbar) self.lefttoolbar.addAction(self.kicad) self.lefttoolbar.addAction(self.conversion) @@ -242,12 +258,12 @@ class Application(QtGui.QMainWindow): ''' exit_msg = "Are you sure you want to exit the program?" exit_msg += " All unsaved data will be lost." - reply = QtGui.QMessageBox.question( - self, 'Message', exit_msg, QtGui.QMessageBox.Yes, - QtGui.QMessageBox.No + reply = QtWidgets.QMessageBox.question( + self, 'Message', exit_msg, QtWidgets.QMessageBox.Yes, + QtWidgets.QMessageBox.No ) - if reply == QtGui.QMessageBox.Yes: + if reply == QtWidgets.QMessageBox.Yes: for proc in self.obj_appconfig.procThread_list: try: proc.terminate() @@ -271,12 +287,12 @@ class Application(QtGui.QMainWindow): event.accept() self.systemTrayIcon.showMessage('Exit', 'eSim is Closed.') - elif reply == QtGui.QMessageBox.No: + elif reply == QtWidgets.QMessageBox.No: event.ignore() def new_project(self): """This function call New Project Info class.""" - text, ok = QtGui.QInputDialog.getText( + text, ok = QtWidgets.QInputDialog.getText( self, 'New Project Info', 'Enter Project Name:' ) if ok: @@ -398,10 +414,14 @@ class Application(QtGui.QMainWindow): "/fp-lib-table-online") # Restore original files - shutil.copy('library/supportFiles/fp-lib-table-online', - self.obj_appconfig.kicad_path + "/") - shutil.copy('library/supportFiles/fp-lib-table', - self.obj_appconfig.kicad_path + "/") + shutil.copy( + init_path + 'library/supportFiles/fp-lib-table-online', + self.obj_appconfig.kicad_path + "/" + ) + shutil.copy( + init_path + 'library/supportFiles/fp-lib-table', + self.obj_appconfig.kicad_path + "/" + ) self.online_flag = False else: @@ -442,7 +462,7 @@ class Application(QtGui.QMainWindow): self.obj_appconfig.kicad_path + "/fp-lib-table" ) self.switchmode.setIcon( - QtGui.QIcon('images/offline.png') + QtGui.QIcon(init_path + 'images/offline.png') ) self.switchmode.setText('<b>Go Online</b>') self.switchmode.setEnabled(True) @@ -460,7 +480,7 @@ class Application(QtGui.QMainWindow): self.obj_appconfig.kicad_path + "/fp-lib-table" ) self.switchmode.setIcon( - QtGui.QIcon('images/online.png') + QtGui.QIcon(init_path + 'images/online.png') ) self.switchmode.setText('<b>Go Offline</b>') self.switchmode.setEnabled(True) @@ -468,7 +488,7 @@ class Application(QtGui.QMainWindow): elif self.online_flag is None: self.switchmode.setIcon( - QtGui.QIcon('images/disable.png') + QtGui.QIcon(init_path + 'images/disable.png') ) self.switchmode.setText( '<b>Mode switching has been ' + @@ -476,7 +496,7 @@ class Application(QtGui.QMainWindow): ) self.switchmode.setEnabled(False) else: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setWindowTitle("Error Message") self.msg.setModal(True) self.msg.showMessage( @@ -528,7 +548,7 @@ class Application(QtGui.QMainWindow): try: self.obj_Mainview.obj_dockarea.plottingEditor() except Exception as e: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) self.msg.setWindowTitle("Error Message") self.msg.showMessage( @@ -540,7 +560,7 @@ class Application(QtGui.QMainWindow): self.obj_appconfig.print_error('Exception Message : ' + str(e)) else: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) self.msg.setWindowTitle("Error Message") self.msg.showMessage( @@ -581,7 +601,7 @@ class Application(QtGui.QMainWindow): self.obj_workThread = Worker.WorkerThread(self.cmd) self.obj_workThread.start() else: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) self.msg.setWindowTitle('NGHDL Error') self.msg.showMessage('Error while opening NGHDL. ' + @@ -635,7 +655,7 @@ class Application(QtGui.QMainWindow): self.obj_workThread2 = Worker.WorkerThread(self.cmd2) self.obj_workThread2.start() else: - self.msg = QtGui.QMessageBox() + self.msg = QtWidgets.QMessageBox() self.msgContent = "There was an error while opening OMEdit.<br/>\ Please make sure OpenModelica is installed in your\ @@ -655,7 +675,7 @@ class Application(QtGui.QMainWindow): self.msg.exec_() except Exception as e: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) self.msg.setWindowTitle( "Ngspice to Modelica conversion error") @@ -669,7 +689,7 @@ class Application(QtGui.QMainWindow): self.obj_Mainview.obj_dockarea.modelicaEditor(self.projDir) else: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) self.msg.setWindowTitle("Missing Ngspice netlist") self.msg.showMessage( @@ -678,7 +698,7 @@ class Application(QtGui.QMainWindow): ) self.msg.exec_() else: - self.msg = QtGui.QErrorMessage() + self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) self.msg.setWindowTitle("Error Message") self.msg.showMessage( @@ -705,7 +725,7 @@ class Application(QtGui.QMainWindow): self.obj_workThread = Worker.WorkerThread(self.cmd) self.obj_workThread.start() else: - self.msg = QtGui.QMessageBox() + self.msg = QtWidgets.QMessageBox() self.msgContent = ( "There was an error while opening OMOptim.<br/>" "Please make sure OpenModelica is installed in your" @@ -726,7 +746,7 @@ class Application(QtGui.QMainWindow): # This class initialize the Main View of Application -class MainView(QtGui.QWidget): +class MainView(QtWidgets.QWidget): """ This class defines whole view and style of main page: @@ -740,20 +760,20 @@ class MainView(QtGui.QWidget): def __init__(self, *args): # call init method of superclass - QtGui.QWidget.__init__(self, *args) + QtWidgets.QWidget.__init__(self, *args) self.obj_appconfig = Appconfig() - self.leftSplit = QtGui.QSplitter() - self.middleSplit = QtGui.QSplitter() + self.leftSplit = QtWidgets.QSplitter() + self.middleSplit = QtWidgets.QSplitter() - self.mainLayout = QtGui.QVBoxLayout() + self.mainLayout = QtWidgets.QVBoxLayout() # Intermediate Widget - self.middleContainer = QtGui.QWidget() - self.middleContainerLayout = QtGui.QVBoxLayout() + self.middleContainer = QtWidgets.QWidget() + self.middleContainerLayout = QtWidgets.QVBoxLayout() # Area to be included in MainView - self.noteArea = QtGui.QTextEdit() + self.noteArea = QtWidgets.QTextEdit() self.noteArea.setReadOnly(True) self.obj_appconfig.noteArea['Note'] = self.noteArea self.obj_appconfig.noteArea['Note'].append( @@ -784,8 +804,8 @@ class MainView(QtGui.QWidget): # 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) @@ -796,13 +816,20 @@ def main(args): by this function. """ print("Starting eSim......") - app = QtGui.QApplication(args) + app = QtWidgets.QApplication(args) + app.setApplicationName("eSim") + + appView = Application() + appView.hide() - splash_pix = QtGui.QPixmap('images/splash_screen_esim.png') - splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) + splash_pix = QtGui.QPixmap(init_path + 'images/splash_screen_esim.png') + splash = QtWidgets.QSplashScreen( + appView, splash_pix, QtCore.Qt.WindowStaysOnTopHint + ) splash.setMask(splash_pix.mask()) + splash.setDisabled(True) splash.show() - appView = Application() + appView.splash = splash appView.obj_workspace.returnWhetherClickedOrNot(appView) @@ -814,10 +841,10 @@ def main(args): file.close() except IOError: work = 0 + if work != 0: appView.obj_workspace.defaultWorkspace() else: - appView.hide() appView.obj_workspace.show() sys.exit(app.exec_()) |