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

ESS_GUIESS_GUI_Pr_fixesESS_GUI_iss879ESS_GUI_project_save
Last change on this file since e4335ae was e4335ae, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 4 months ago

SASVIEW-957 logging changes (#158)

  • rework XStream to continue to write to stdout/stderr alongside redirection; make logging level setting consistent; make log configuration more consistent
  • rm XStream; QT signal in QtHandler? logging handler; only logs in Log Explorer (no stdout/stderr)
  • no need to change handler level
  • use QTextBrowser.append to facilitate auto-scrolling in the Log Explorer
  • modify logger unit test to reflect changes (passes)
  • Property mode set to 100644
File size: 2.5 KB
Line 
1# UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE
2# ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE
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
8
9# Local UI
10from sas.qtgui.UI import main_resources_rc
11from .UI.MainWindowUI import Ui_MainWindow
12
13class MainSasViewWindow(QMainWindow, Ui_MainWindow):
14    # Main window of the application
15    def __init__(self, parent=None):
16        super(MainSasViewWindow, self).__init__(parent)
17        self.setupUi(self)
18
19        # define workspace for dialogs.
20        self.workspace = QMdiArea(self)
21        self.setCentralWidget(self.workspace)
22
23        # Create the gui manager
24        from .GuiManager import GuiManager
25        try:
26            self.guiManager = GuiManager(self)
27        except Exception as ex:
28            import logging
29            logging.error("Application failed with: " + str(ex))
30            print("Application failed with: ", ex)
31
32    def closeEvent(self, event):
33        if self.guiManager.quitApplication():
34            event.accept()
35        else:
36            event.ignore()
37
38
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    """
44    # TODO: standardize path to images
45    pixmap = QPixmap("src/sas/qtgui/images/SVwelcome_mini.png")
46    splashScreen = QSplashScreen(pixmap)
47    return splashScreen
48
49def run_sasview():
50    app = QApplication([])
51
52    # Main must have reference to the splash screen, so making it explicit
53    splash = SplashScreen()
54    splash.show()
55
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
61    # DO NOT move the following import to the top!
62    # (unless you know what you're doing)
63    import qt5reactor
64    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor
65    qt5reactor.install()
66
67    # DO NOT move the following import to the top!
68    from twisted.internet import reactor
69
70    # Show the main SV window
71    mainwindow = MainSasViewWindow()
72    mainwindow.showMaximized()
73
74    # no more splash screen
75    splash.finish(mainwindow)
76
77    # Time for the welcome window
78    mainwindow.guiManager.showWelcomeMessage()
79
80    # No need to .exec_ - the reactor takes care of it.
81    reactor.run()
82
83if __name__ == "__main__":
84    run_sasview()
Note: See TracBrowser for help on using the repository browser.