Coverage for larch/wxlib/__init__.py: 70%
66 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-16 21:04 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-16 21:04 +0000
1#!/usr/bin/env python
2"""
3wx widgets for Larch
4"""
5__DOC__ = '''
6WxPython functions for larch
8function description
9------------ ------------------------------
10gcd graphical change directory - launch browser to select working folder
11fileprompt launch file browser to select files.
13'''
15import locale
16from pathlib import Path
18import os
19import sys
20HAS_WXPYTHON = False
21try:
22 import wx
23 HAS_WXPYTHON = True
24except (ImportError, AttributeError):
25 HAS_WXPYTHON = False
27_larch_name = '_sys.wx'
28_larch_builtins = {}
30FONTSIZE = 10
31FONTSIZE_FW = 10
33def DarwinHLine(parent, size=(700, 3)):
34 """Horizontal line for MacOS
35 h = HLine(parent, size=(700, 3)
36 """
37 msize = (size[0], int(size[1]*0.75))
38 line = wx.Panel(parent, size=msize)
39 line.SetBackgroundColour((196,196,196))
40 return line
43if HAS_WXPYTHON:
44 from . import larchframe
45 from . import larchfilling
46 from . import readlinetextctrl
47 import wxutils as wxu
48 from wxutils import (set_sizer, pack, SetTip, Font, HLine, Check, MenuItem,
49 Popup, RIGHT, LEFT, CEN , LTEXT, FRAMESTYLE, hms,
50 DateTimeCtrl, Button, TextCtrl, ToggleButton,
51 BitmapButton, Choice, YesNo, SimpleText,
52 LabeledTextCtrl, HyperText, get_icon, OkCancel,
53 fix_filename, SavedParameterDialog, GridPanel,
54 RowPanel, make_steps, set_float, FloatCtrl,
55 EditableListBox, COLORS, GUIColors, set_color,
56 FileCheckList, FileDropTarget, NumericCombo,
57 FloatSpin, FloatSpinWithPin, flatnotebook,
58 PeriodicTablePanel, gcd, ExceptionPopup, show_wxsizes,
59 panel_pack)
61 def FileOpen(parent, message, **kws):
62 "File Open dialog wrapper."
63 result = wxu.FileOpen(parent, message, **kws)
64 if result is None:
65 return
66 return Path(result).absolute().as_posix()
68 def FileSave(parent, message, **kws):
69 "File Save dialog"
70 result = wxu.FileSave(parent, message, **kws)
71 if result is None:
72 return
73 return Path(result).absolute().as_posix()
75 def SelectWorkdir(parent, **kws):
76 "prompt for and change into a working directory "
77 return Path(wxu.SelectWorkdir(parent, **kws)).absolute().as_posix()
79 from .larchframe import LarchFrame, LarchPanel
80 from .columnframe import ColumnDataFileFrame, EditColumnFrame
81 from .athena_importer import AthenaImporter
82 from .specfile_importer import SpecfileImporter
83 from .xas_importer import XasImporter
84 from .reportframe import ReportFrame, DictFrame, DataTableGrid
85 from .gui_utils import (databrowser, fileprompt, LarchWxApp, wx_update)
86 from .larch_updater import LarchUpdaterDialog
87 from .parameter import ParameterWidgets, ParameterPanel
89 from .feff_browser import FeffResultsFrame, FeffResultsPanel
90 from .cif_browser import CIFFrame
91 from .structure2feff_browser import Structure2FeffFrame
93 _larch_builtins = {'_sys.wx': dict(gcd=gcd,
94 databrowser=databrowser,
95 filepromspt=fileprompt,
96 wx_update=wx_update)}
98 from .plotter import (_plot, _oplot, _newplot, _plot_text, fileplot,
99 _plot_marker, _plot_arrow, _plot_setlimits,
100 _plot_axvline, _plot_axhline, _scatterplot,
101 _hist, _update_trace, _saveplot, _saveimg,
102 get_display, _closeDisplays, _getcursor,
103 last_cursor_pos, _imshow, _contour, _xrf_plot,
104 _xrf_oplot, _fitplot, _redraw_plot,
105 get_zoomlimits, set_zoomlimits)
108 from . import xafsplots
109 from .xafsplots import plotlabels
112 _larch_builtins['_plotter'] = dict(plot=_plot, oplot=_oplot,
113 newplot=_newplot, plot_text=_plot_text,
114 plot_marker=_plot_marker,
115 plot_arrow=_plot_arrow,
116 plot_setlimits=_plot_setlimits,
117 plot_axvline=_plot_axvline,
118 plot_axhline=_plot_axhline,
119 scatterplot=_scatterplot, hist=_hist,
120 update_trace=_update_trace,
121 save_plot=_saveplot,
122 save_image=_saveimg,
123 get_display=get_display,
124 close_all_displays=_closeDisplays,
125 get_cursor=_getcursor,
126 last_cursor_pos=last_cursor_pos,
127 imshow=_imshow, contour=_contour,
128 xrf_plot=_xrf_plot,
129 xrf_oplot=_xrf_oplot,
130 fit_plot=_fitplot,
131 fileplot=fileplot,
132 redraw_plot=_redraw_plot)
134 _larch_builtins['_xafs'] = dict(redraw=xafsplots.redraw,
135 plotlabels=xafsplots.plotlabels,
136 plot_mu=xafsplots.plot_mu,
137 plot_bkg=xafsplots.plot_bkg,
138 plot_chie=xafsplots.plot_chie,
139 plot_chik=xafsplots.plot_chik,
140 plot_chir=xafsplots.plot_chir,
141 plot_chiq=xafsplots.plot_chiq,
142 plot_wavelet=xafsplots.plot_wavelet,
143 plot_chifit=xafsplots.plot_chifit,
144 plot_path_k=xafsplots.plot_path_k,
145 plot_path_r=xafsplots.plot_path_r,
146 plot_paths_k=xafsplots.plot_paths_k,
147 plot_paths_r=xafsplots.plot_paths_r,
148 plot_feffdat=xafsplots.plot_feffdat,
149 plot_diffkk=xafsplots.plot_diffkk,
150 plot_prepeaks_fit=xafsplots.plot_prepeaks_fit,
151 plot_prepeaks_baseline=xafsplots.plot_prepeaks_baseline,
152 plot_pca_components=xafsplots.plot_pca_components,
153 plot_pca_weights=xafsplots.plot_pca_weights,
154 plot_pca_fit=xafsplots.plot_pca_fit)
157 def _larch_init(_larch):
158 """add ScanFrameViewer to _sys.gui_apps """
159 if _larch is None:
160 return
161 _sys = _larch.symtable._sys
162 if not hasattr(_sys, 'gui_apps'):
163 _sys.gui_apps = {}
164 # _sys.gui_apps['xrfviewer'] = ('XRF Spectrum Viewer', XRFDisplayFrame)
165else:
166 def nullfunc(*args, **kws):
167 pass
169 _larch_builtins = {'_sys.wx': dict(gcd=nullfunc,
170 databrowser=nullfunc,
171 filepromspt=nullfunc,
172 wx_update=nullfunc)}
174 _larch_builtins['_plotter'] = dict(plot=nullfunc,
175 oplot=nullfunc,
176 newplot=nullfunc,
177 plot_text=nullfunc,
178 plot_marker=nullfunc,
179 plot_arrow=nullfunc,
180 plot_setlimits=nullfunc,
181 plot_axvline=nullfunc,
182 plot_axhline=nullfunc,
183 scatterplot=nullfunc,
184 hist=nullfunc,
185 update_trace=nullfunc,
186 save_plot=nullfunc,
187 save_image=nullfunc,
188 get_display=nullfunc,
189 close_all_displays=nullfunc,
190 get_cursor=nullfunc,
191 last_cursor_pos=nullfunc,
192 imshow=nullfunc,
193 contour=nullfunc,
194 xrf_plot=nullfunc,
195 xrf_oplot=nullfunc,
196 fit_plot=nullfunc)