source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ a3221b6

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since a3221b6 was a3221b6, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Package SasView? with pyinstaller now. SASVIEW-906.
Minor issue with JupyterConsole? remaining.

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[f721030]1# UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE
2# ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE
[8353d90]3from PyQt5.QtWidgets import QMainWindow
4from PyQt5.QtWidgets import QMdiArea
5from PyQt5.QtWidgets import QSplashScreen
6from PyQt5.QtWidgets import QApplication
7from PyQt5.QtGui import QPixmap
[f721030]8
9# Local UI
[cd2cc745]10from sas.qtgui.UI import main_resources_rc
[b3e8629]11from .UI.MainWindowUI import Ui_MainWindow
[f721030]12
[0cd8612]13# Initialize logging
[83eb5208]14import sas.qtgui.Utilities.SasviewLogger
[0cd8612]15
[4992ff2]16class MainSasViewWindow(QMainWindow, Ui_MainWindow):
[f721030]17    # Main window of the application
[6fd4e36]18    def __init__(self, parent=None):
[f721030]19        super(MainSasViewWindow, self).__init__(parent)
[f51ed67]20        self.setupUi(self)
[a95260d]21
[f721030]22        # define workspace for dialogs.
[4992ff2]23        self.workspace = QMdiArea(self)
[f721030]24        self.setCentralWidget(self.workspace)
25
26        # Create the gui manager
[b3e8629]27        from .GuiManager import GuiManager
[4992ff2]28        try:
29            self.guiManager = GuiManager(self)
30        except Exception as ex:
[53c771e]31            import logging
[8ac3551]32            logging.error("Application failed with: " + str(ex))
[53c771e]33            print("Application failed with: ", ex)
[f721030]34
[9e426c1]35    def closeEvent(self, event):
[7451b88]36        if self.guiManager.quitApplication():
37            event.accept()
38        else:
39            event.ignore()
[481ff26]40
[a95260d]41
[f721030]42def SplashScreen():
43    """
44    Displays splash screen as soon as humanely possible.
45    The screen will disappear as soon as the event loop starts.
46    """
[31c5b58]47    # TODO: standardize path to images
[4992ff2]48    pixmap = QPixmap("src/sas/qtgui/images/SVwelcome_mini.png")
49    splashScreen = QSplashScreen(pixmap)
[f721030]50    return splashScreen
51
[a3221b6]52def run_sasview():
[4992ff2]53    app = QApplication([])
[f721030]54
55    # Main must have reference to the splash screen, so making it explicit
56    splash = SplashScreen()
57    splash.show()
58
[2a8bd705]59    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
60    import sys
61    if 'twisted.internet.reactor' in sys.modules:
62        del sys.modules['twisted.internet.reactor']
63
[f721030]64    # DO NOT move the following import to the top!
65    # (unless you know what you're doing)
[4992ff2]66    import qt5reactor
[d6b8a1d]67    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor
[4992ff2]68    qt5reactor.install()
[f721030]69
70    # DO NOT move the following import to the top!
71    from twisted.internet import reactor
72
73    # Show the main SV window
[6fd4e36]74    mainwindow = MainSasViewWindow()
[8353d90]75    mainwindow.showMaximized()
[f721030]76
77    # no more splash screen
78    splash.finish(mainwindow)
79
[8353d90]80    # Time for the welcome window
81    mainwindow.guiManager.showWelcomeMessage()
82
[f721030]83    # No need to .exec_ - the reactor takes care of it.
84    reactor.run()
85
[31c5b58]86if __name__ == "__main__":
[a3221b6]87    run_sasview()
Note: See TracBrowser for help on using the repository browser.