Coverage for /Users/Newville/Codes/xraylarch/larch/wxlib/__init__.py: 65%

71 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-09 10:08 -0600

1#!/usr/bin/env python 

2""" 

3wx widgets for Larch 

4""" 

5__DOC__ = ''' 

6WxPython functions for larch 

7 

8function description 

9------------ ------------------------------ 

10gcd graphical change directory - launch browser to select working folder 

11fileprompt launch file browser to select files. 

12 

13''' 

14 

15import locale 

16 

17from pyshortcuts import platform 

18import os 

19import sys 

20HAS_WXPYTHON = False 

21try: 

22 import wx 

23 HAS_WXPYTHON = True 

24except (ImportError, AttributeError): 

25 HAS_WXPYTHON = False 

26 

27_larch_name = '_sys.wx' 

28_larch_builtins = {} 

29 

30FONTSIZE = 10 

31FONTSIZE_FW = 10 

32if platform == 'win': 

33 FONTSIZE = 10 

34 FONTSIZE_FW = 10 

35 locale.setlocale(locale.LC_ALL, 'C') 

36elif platform == 'darwin': 

37 FONTSIZE = 11 

38 FONTSIZE_FW = 12 

39 

40 

41if HAS_WXPYTHON: 

42 from . import larchframe 

43 from . import larchfilling 

44 from . import readlinetextctrl 

45 

46 from wxutils import (set_sizer, pack, SetTip, Font, HLine, Check, MenuItem, 

47 Popup, RIGHT, LEFT, CEN , LTEXT, FRAMESTYLE, hms, 

48 DateTimeCtrl, Button, TextCtrl, ToggleButton, 

49 BitmapButton, Choice, YesNo, SimpleText, 

50 LabeledTextCtrl, HyperText, get_icon, OkCancel, 

51 FileOpen, FileSave, SelectWorkdir, fix_filename, 

52 SavedParameterDialog, GridPanel, RowPanel, make_steps, 

53 set_float, FloatCtrl, EditableListBox, COLORS, 

54 GUIColors, set_color, FileCheckList, FileDropTarget, 

55 NumericCombo, FloatSpin, FloatSpinWithPin, 

56 flatnotebook, PeriodicTablePanel, gcd, ExceptionPopup, 

57 show_wxsizes, panel_pack) 

58 

59 from .larchframe import LarchFrame, LarchPanel 

60 from .columnframe import ColumnDataFileFrame, EditColumnFrame 

61 from .athena_importer import AthenaImporter 

62 from .specfile_importer import SpecfileImporter 

63 from .reportframe import ReportFrame, DictFrame, DataTableGrid 

64 from .gui_utils import (databrowser, fileprompt, LarchWxApp, wx_update) 

65 from .larch_updater import LarchUpdaterDialog 

66 from .parameter import ParameterWidgets, ParameterPanel 

67 

68 from .feff_browser import FeffResultsFrame, FeffResultsPanel 

69 from .cif_browser import CIFFrame 

70 from .structure2feff_browser import Structure2FeffFrame 

71 

72 _larch_builtins = {'_sys.wx': dict(gcd=gcd, 

73 databrowser=databrowser, 

74 filepromspt=fileprompt, 

75 wx_update=wx_update)} 

76 

77 from .plotter import (_plot, _oplot, _newplot, _plot_text, fileplot, 

78 _plot_marker, _plot_arrow, _plot_setlimits, 

79 _plot_axvline, _plot_axhline, _scatterplot, 

80 _hist, _update_trace, _saveplot, _saveimg, 

81 get_display, _closeDisplays, _getcursor, 

82 last_cursor_pos, _imshow, _contour, _xrf_plot, 

83 _xrf_oplot, _fitplot, _redraw_plot, 

84 get_zoomlimits, set_zoomlimits) 

85 

86 

87 from . import xafsplots 

88 from .xafsplots import plotlabels 

89 

90 _larch_builtins['_plotter'] = dict(plot=_plot, oplot=_oplot, 

91 newplot=_newplot, plot_text=_plot_text, 

92 plot_marker=_plot_marker, 

93 plot_arrow=_plot_arrow, 

94 plot_setlimits=_plot_setlimits, 

95 plot_axvline=_plot_axvline, 

96 plot_axhline=_plot_axhline, 

97 scatterplot=_scatterplot, hist=_hist, 

98 update_trace=_update_trace, 

99 save_plot=_saveplot, 

100 save_image=_saveimg, 

101 get_display=get_display, 

102 close_all_displays=_closeDisplays, 

103 get_cursor=_getcursor, 

104 last_cursor_pos=last_cursor_pos, 

105 imshow=_imshow, contour=_contour, 

106 xrf_plot=_xrf_plot, 

107 xrf_oplot=_xrf_oplot, 

108 fit_plot=_fitplot, 

109 fileplot=fileplot, 

110 redraw_plot=_redraw_plot) 

111 

112 _larch_builtins['_xafs'] = dict(redraw=xafsplots.redraw, 

113 plotlabels=xafsplots.plotlabels, 

114 plot_mu=xafsplots.plot_mu, 

115 plot_bkg=xafsplots.plot_bkg, 

116 plot_chie=xafsplots.plot_chie, 

117 plot_chik=xafsplots.plot_chik, 

118 plot_chir=xafsplots.plot_chir, 

119 plot_chiq=xafsplots.plot_chiq, 

120 plot_wavelet=xafsplots.plot_wavelet, 

121 plot_chifit=xafsplots.plot_chifit, 

122 plot_path_k=xafsplots.plot_path_k, 

123 plot_path_r=xafsplots.plot_path_r, 

124 plot_paths_k=xafsplots.plot_paths_k, 

125 plot_paths_r=xafsplots.plot_paths_r, 

126 plot_feffdat=xafsplots.plot_feffdat, 

127 plot_diffkk=xafsplots.plot_diffkk, 

128 plot_prepeaks_fit=xafsplots.plot_prepeaks_fit, 

129 plot_prepeaks_baseline=xafsplots.plot_prepeaks_baseline, 

130 plot_pca_components=xafsplots.plot_pca_components, 

131 plot_pca_weights=xafsplots.plot_pca_weights, 

132 plot_pca_fit=xafsplots.plot_pca_fit) 

133 

134 

135 def _larch_init(_larch): 

136 """add ScanFrameViewer to _sys.gui_apps """ 

137 if _larch is None: 

138 return 

139 _sys = _larch.symtable._sys 

140 if not hasattr(_sys, 'gui_apps'): 

141 _sys.gui_apps = {} 

142 # _sys.gui_apps['xrfviewer'] = ('XRF Spectrum Viewer', XRFDisplayFrame) 

143 

144 ############################# 

145 ## Hack System and Startfile on Windows totry to track down 

146 ## weird error of starting other applications, like Mail 

147 if platform == 'win': 

148 from os import system as os_system 

149 from os import startfile as os_startfile 

150 

151 def my_system(command): 

152 print(f"#@-> os.system: {command}") 

153 return os_system(command) 

154 

155 def my_startfile(filepath, operation=None): 

156 print(f"#@-> os.startfile: {filepath}, {operation}") 

157 try: 

158 if operation is None: 

159 return os_startfile(filepath) 

160 else: 

161 return os_startfile(filepath, operation) 

162 except WindowsError: 

163 print(f"#@-> os.startfile failed: {filepath}, {operation}") 

164 

165 os.system = my_system 

166 os.startfile = my_startfile 

167 ############################# 

168 

169else: 

170 def nullfunc(*args, **kws): 

171 pass 

172 

173 _larch_builtins = {'_sys.wx': dict(gcd=nullfunc, 

174 databrowser=nullfunc, 

175 filepromspt=nullfunc, 

176 wx_update=nullfunc)} 

177 

178 _larch_builtins['_plotter'] = dict(plot=nullfunc, 

179 oplot=nullfunc, 

180 newplot=nullfunc, 

181 plot_text=nullfunc, 

182 plot_marker=nullfunc, 

183 plot_arrow=nullfunc, 

184 plot_setlimits=nullfunc, 

185 plot_axvline=nullfunc, 

186 plot_axhline=nullfunc, 

187 scatterplot=nullfunc, 

188 hist=nullfunc, 

189 update_trace=nullfunc, 

190 save_plot=nullfunc, 

191 save_image=nullfunc, 

192 get_display=nullfunc, 

193 close_all_displays=nullfunc, 

194 get_cursor=nullfunc, 

195 last_cursor_pos=nullfunc, 

196 imshow=nullfunc, 

197 contour=nullfunc, 

198 xrf_plot=nullfunc, 

199 xrf_oplot=nullfunc, 

200 fit_plot=nullfunc)