source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ 0101c9f

Last change on this file since 0101c9f was 3d18691, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

New category manager design

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