def main(): from python_qt_binding import QtGui, QtCore, QT_BINDING import hyperspyui.info from hyperspyui.singleapplication import get_app from hyperspyui.settings import Settings from hyperspyui.util import dummy_context_manager # Need to set early to make QSettings accessible QtCore.QCoreApplication.setApplicationName("HyperSpyUI") QtCore.QCoreApplication.setOrganizationName("Hyperspy") QtCore.QCoreApplication.setApplicationVersion(hyperspyui.info.version) # First, clear all default settings! # TODO: This will cause a concurrency issue with multiple launch Settings.clear_defaults() # Setup default for single/multi-instance settings = Settings(group="General") settings.set_default('allow_multiple_instances', False) if settings['allow_multiple_instances', bool]: # Using multiple instances, get a new application app = QtGui.QApplication(sys.argv) else: # Make sure we only have a single instance app = get_app('hyperspyui') log_file = _get_logfile() if log_file: sys.stdout = sys.stderr = log_file else: log_file = dummy_context_manager() with log_file: # Create and display the splash screen splash_pix = QtGui.QPixmap( os.path.dirname(__file__) + './images/splash.png') splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() app.processEvents() # Need to have import here, as it can take some time, so should happen # after displaying splash from hyperspyui.mainwindow import MainWindow form = MainWindow() if not settings['allow_multiple_instances', bool]: if QT_BINDING == 'pyqt': app.messageAvailable.connect(form.handleSecondInstance) elif QT_BINDING == 'pyside': app.messageReceived.connect(form.handleSecondInstance) form.showMaximized() splash.finish(form) form.load_complete.emit() # Ensure logging is OK import hyperspy.api as hs hs.set_log_level(LOGLEVEL) app.exec_()
def main(): from qtpy.QtCore import QCoreApplication from qtpy.QtWidgets import QApplication from qtpy import API import hyperspyui.info from hyperspyui.settings import Settings # Need to set early to make QSettings accessible QCoreApplication.setApplicationName("HyperSpyUI") QCoreApplication.setOrganizationName("Hyperspy") QCoreApplication.setApplicationVersion(hyperspyui.info.version) # First, clear all default settings! # TODO: This will cause a concurrency issue with multiple launch Settings.clear_defaults() # Setup default for single/multi-instance settings = Settings(group="General") settings.set_default('allow_multiple_instances', False) if settings['allow_multiple_instances', bool]: # Using multiple instances, get a new application app = QApplication(sys.argv) else: # Make sure we only have a single instance from hyperspyui.singleapplication import get_app app = get_app('hyperspyui') splash = get_splash() log_file = _get_logfile() if log_file: sys.stdout = sys.stderr = log_file else: @contextmanager def dummy_context_manager(*args, **kwargs): yield log_file = dummy_context_manager() with log_file: # Need to have import here, since QApplication needs to be called first from hyperspyui.mainwindow import MainWindow form = MainWindow(splash=splash) if not settings['allow_multiple_instances', bool]: if "pyqt" in API: app.messageAvailable.connect(form.handleSecondInstance) elif API == 'pyside': app.messageReceived.connect(form.handleSecondInstance) form.showMaximized() form.splash.hide() form.load_complete.emit() # Ensure logging is OK import hyperspy.api as hs hs.set_log_level(LOGLEVEL) app.exec_()
def main(): from python_qt_binding import QtGui, QtCore, QT_BINDING import hyperspyui.info from hyperspyui.singleapplication import get_app from hyperspyui.settings import Settings from hyperspyui.util import dummy_context_manager # Need to set early to make QSettings accessible QtCore.QCoreApplication.setApplicationName("HyperSpyUI") QtCore.QCoreApplication.setOrganizationName("Hyperspy") QtCore.QCoreApplication.setApplicationVersion(hyperspyui.info.version) # First, clear all default settings! Settings.clear_defaults() # Setup default for single/multi-instance settings = Settings(group="General") settings.set_default('allow_multiple_instances', False) if settings['allow_multiple_instances', bool]: # Using multiple instances, get a new application app = QtGui.QApplication(sys.argv) else: # Make sure we only have a single instance app = get_app('hyperspyui') log_file = _get_logfile() if log_file: sys.stdout = sys.stderr = log_file else: log_file = dummy_context_manager() with log_file: # Create and display the splash screen splash_pix = QtGui.QPixmap( os.path.dirname(__file__) + './images/splash.png') splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) splash.show() app.processEvents() # Need to have import here, as it can take some time, so should happen # after displaying splash from hyperspyui.mainwindow import MainWindow form = MainWindow() if not settings['allow_multiple_instances', bool]: if QT_BINDING == 'pyqt': app.messageAvailable.connect(form.handleSecondInstance) elif QT_BINDING == 'pyside': app.messageReceived.connect(form.handleSecondInstance) form.showMaximized() splash.finish(form) form.load_complete.emit() # Ensure logging is OK import hyperspy.api as hs hs.set_log_level(LOGLEVEL) app.exec_()
def main(): from qtpy.QtCore import Qt, QCoreApplication from qtpy.QtWidgets import QApplication from qtpy import API import hyperspyui.info from hyperspyui.settings import Settings QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts) # Need to set early to make QSettings accessible QCoreApplication.setApplicationName("HyperSpyUI") QCoreApplication.setOrganizationName("Hyperspy") QCoreApplication.setApplicationVersion(hyperspyui.info.__version__) # First, clear all default settings! # TODO: This will cause a concurrency issue with multiple launch Settings.clear_defaults() # Setup default for single/multi-instance settings = Settings(group="General") settings.set_default('allow_multiple_instances', False) if settings['allow_multiple_instances', bool]: # Using multiple instances, get a new application app = QApplication(sys.argv) else: # Make sure we only have a single instance from hyperspyui.singleapplication import get_app app = get_app('hyperspyui') splash = get_splash() log_file = _get_logfile() if log_file: sys.stdout = sys.stderr = log_file else: @contextmanager def dummy_context_manager(*args, **kwargs): yield log_file = dummy_context_manager() with log_file: # Need to have import here, since QApplication needs to be called first from hyperspyui.mainwindow import MainWindow form = MainWindow(splash=splash) if not settings['allow_multiple_instances', bool]: if "pyqt" in API: app.messageAvailable.connect(form.handleSecondInstance) elif API == 'pyside': app.messageReceived.connect(form.handleSecondInstance) form.showMaximized() form.splash.hide() form.load_complete.emit() # Ensure logging is OK import hyperspy.api as hs hs.set_log_level(LOGLEVEL) app.exec_()
import sys from hyperspyui.singleapplication import get_app from python_qt_binding import QT_BINDING key = 'test_single_app' def handle_second_instance(argv): print(argv) app.exit() try: app = get_app(key) except SystemExit: print('Exiting early!') raise if QT_BINDING == 'pyqt': app.messageAvailable.connect(handle_second_instance) elif QT_BINDING == 'pyside': app.messageReceived.connect(handle_second_instance) print('Loaded app') sys.exit(app.exec_())
import sys from hyperspyui.singleapplication import get_app from qtpy import API key = 'test_single_app' def handle_second_instance(argv): print(argv) app.exit() try: app = get_app(key) except SystemExit: print('Exiting early!') raise if "pyqt" in API: app.messageAvailable.connect(handle_second_instance) elif API == 'pyside': app.messageReceived.connect(handle_second_instance) print('Loaded app') sys.exit(app.exec_())
def main(): from qtpy.QtCore import Qt, QCoreApplication from qtpy.QtWidgets import QApplication from qtpy import API import hyperspyui.info from hyperspyui.settings import Settings # QtWebEngineWidgets must be imported before a QCoreApplication instance # is created (used in eelsdb plugin) # Avoid a bug in Qt: https://bugreports.qt.io/browse/QTBUG-46720 from qtpy import QtWebEngineWidgets # Need to set early to make QSettings accessible QCoreApplication.setApplicationName("HyperSpyUI") QCoreApplication.setOrganizationName("Hyperspy") QCoreApplication.setApplicationVersion(hyperspyui.info.__version__) # To avoid the warning: # Qt WebEngine seems to be initialized from a plugin. Please set # Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute before # constructing QGuiApplication. # Only available for pyqt>=5.4 if hasattr(Qt, "AA_ShareOpenGLContexts"): QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts) # First, clear all default settings! # TODO: This will cause a concurrency issue with multiple launch Settings.clear_defaults() # Setup default for single/multi-instance settings = Settings(group="General") settings.set_default('allow_multiple_instances', False) if settings['allow_multiple_instances', bool]: # Using multiple instances, get a new application app = QApplication(sys.argv) else: # Make sure we only have a single instance from hyperspyui.singleapplication import get_app app = get_app('hyperspyui') splash = get_splash() log_file = _get_logfile() if log_file: sys.stdout = sys.stderr = log_file else: @contextmanager def dummy_context_manager(*args, **kwargs): yield log_file = dummy_context_manager() with log_file: # Need to have import here, since QApplication needs to be called first from hyperspyui.mainwindow import MainWindow form = MainWindow(splash=splash) if not settings['allow_multiple_instances', bool]: if "pyqt" in API: app.messageAvailable.connect(form.handleSecondInstance) elif API == 'pyside': app.messageReceived.connect(form.handleSecondInstance) form.showMaximized() form.splash.hide() form.load_complete.emit() # Ensure logging is OK import hyperspy.api as hs hs.set_log_level(LOGLEVEL) app.exec_()