Coverage for larch/qtrixs/application.py: 0%

44 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-10-16 21:04 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3""" 

4RIXS GUI APPLICATION 

5==================== 

6""" 

7import sys 

8import argparse 

9import signal 

10 

11from larch.utils.logging import getLogger 

12_logger = getLogger('lach.qtrixs.application') 

13 

14 

15def createParser(): 

16 """Application parser""" 

17 parser = argparse.ArgumentParser(description="Larch-RIXS GUI parser") 

18 

19 return parser 

20 

21 

22def mainQtApp(options): 

23 """Part of the main application depending on Qt""" 

24 try: 

25 # it should be loaded before h5py 

26 import hdf5plugin # noqa 

27 except ImportError: 

28 _logger.debug("Backtrace", exc_info=True) 

29 import h5py 

30 

31 import silx 

32 import silx.utils.files 

33 from silx.gui import qt 

34 

35 # Make sure matplotlib is configured 

36 # Needed for Debian 8: compatibility between Qt4/Qt5 and old matplotlib 

37 from silx.gui.plot import matplotlib 

38 

39 _logger.info('Starting application') 

40 app = qt.QApplication([]) 

41 qt.QLocale.setDefault(qt.QLocale.c()) 

42 

43 def sigintHandler(*args): 

44 """Handler for the SIGINT signal.""" 

45 qt.QApplication.quit() 

46 

47 signal.signal(signal.SIGINT, sigintHandler) 

48 sys.excepthook = qt.exceptionHandler 

49 

50 timer = qt.QTimer() 

51 timer.start(500) 

52 # Application have to wake up Python interpreter, else SIGINT is not 

53 # catched 

54 timer.timeout.connect(lambda: None) 

55 

56 from .window import RixsAppWindow as MainWindow 

57 

58 window = MainWindow(with_ipykernel=True) 

59 window.setAttribute(qt.Qt.WA_DeleteOnClose, True) 

60 

61 window.show() 

62 _logger.info('Finished initialization') 

63 

64 # Very important, IPython-specific step: this gets GUI event loop 

65 # integration going, and it replaces calling app.exec_() 

66 _logger.info('Starting the IPython kernel') 

67 window._ipykernel.kernel.start() 

68 

69 result = app.exec_() 

70 # remove ending warnings relative to QTimer 

71 app.deleteLater() 

72 return result 

73 

74 

75def main(argv): 

76 """Main function to launch sloth-daxs as an Application 

77 

78 Parameters 

79 ---------- 

80 argv : list 

81 command line arguments 

82 """ 

83 parser = createParser() 

84 options = parser.parse_args(argv[1:]) 

85 mainQtApp(options) 

86 

87 

88if __name__ == '__main__': 

89 main(sys.argv)