diff options
Diffstat (limited to 'silx/app/view/main.py')
-rw-r--r-- | silx/app/view/main.py | 74 |
1 files changed, 30 insertions, 44 deletions
diff --git a/silx/app/view/main.py b/silx/app/view/main.py index fc89a22..90b8b17 100644 --- a/silx/app/view/main.py +++ b/silx/app/view/main.py @@ -25,7 +25,7 @@ __authors__ = ["V. Valls"] __license__ = "MIT" -__date__ = "07/06/2018" +__date__ = "17/01/2019" import sys import argparse @@ -36,25 +36,6 @@ import signal _logger = logging.getLogger(__name__) """Module logger""" -if "silx.gui.qt" not in sys.modules: - # Try first PyQt5 and not the priority imposed by silx.gui.qt. - # To avoid problem with unittests we only do it if silx.gui.qt is not - # yet loaded. - # TODO: Can be removed for silx 0.8, as it should be the default binding - # of the silx library. - try: - import PyQt5.QtCore - except ImportError: - pass - -import silx -from silx.gui import qt - - -def sigintHandler(*args): - """Handler for the SIGINT signal.""" - qt.QApplication.quit() - def createParser(): parser = argparse.ArgumentParser(description=__doc__) @@ -83,16 +64,8 @@ def createParser(): return parser -def main(argv): - """ - Main function to launch the viewer as an application - - :param argv: Command line arguments - :returns: exit status - """ - parser = createParser() - options = parser.parse_args(argv[1:]) - +def mainQt(options): + """Part of the main depending on Qt""" if options.debug: logging.root.setLevel(logging.DEBUG) @@ -106,25 +79,22 @@ def main(argv): except ImportError: _logger.debug("Backtrace", exc_info=True) - try: - import h5py - except ImportError: - _logger.debug("Backtrace", exc_info=True) - h5py = None + import h5py - if h5py is None: - message = "Module 'h5py' is not installed but is mandatory."\ - + " You can install it using \"pip install h5py\"." - _logger.error(message) - return -1 - - # - # Run the application - # + import silx + import silx.utils.files + from silx.gui import qt + # Make sure matplotlib is configured + # Needed for Debian 8: compatibility between Qt4/Qt5 and old matplotlib + from silx.gui.plot import matplotlib app = qt.QApplication([]) qt.QLocale.setDefault(qt.QLocale.c()) + def sigintHandler(*args): + """Handler for the SIGINT signal.""" + qt.QApplication.quit() + signal.signal(signal.SIGINT, sigintHandler) sys.excepthook = qt.exceptionHandler @@ -150,7 +120,11 @@ def main(argv): # It have to be done after the settings (after the Viewer creation) silx.config.DEFAULT_PLOT_BACKEND = "opengl" + # NOTE: under Windows, cmd does not convert `*.tif` into existing files + options.files = silx.utils.files.expand_filenames(options.files) + for filename in options.files: + # TODO: Would be nice to add a process widget and a cancel button try: window.appendFile(filename) except IOError as e: @@ -164,5 +138,17 @@ def main(argv): return result +def main(argv): + """ + Main function to launch the viewer as an application + + :param argv: Command line arguments + :returns: exit status + """ + parser = createParser() + options = parser.parse_args(argv[1:]) + mainQt(options) + + if __name__ == '__main__': main(sys.argv) |