class ProcessPanel(wx.Panel): def __init__(self, parent, controller=None, reporter=None, **kws): wx.Panel.__init__(self, parent, -1, **kws) self.controller = controller self.reporter = reporter self.needs_update = False self.proc_timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.onProcessTimer, self.proc_timer) self.proc_timer.Start(100) self.build_display() def edit_config(self, event=None): pass def fill(self, dgroup): opts = self.controller.get_proc_opts(dgroup) self.xshift.SetValue(opts['xshift']) self.yshift.SetValue(opts['yshift']) self.xscale.SetValue(opts['xscale']) self.yscale.SetValue(opts['yscale']) self.smooth_op.SetStringSelection(opts['smooth_op']) self.smooth_conv.SetStringSelection(opts['smooth_conv']) self.smooth_c0.SetValue(opts['smooth_c0']) self.smooth_c1.SetValue(opts['smooth_c1']) self.smooth_sig.SetValue(opts['smooth_sig']) if dgroup.datatype == 'xas': self.xas_op.SetStringSelection(opts['xas_op']) self.xas_e0.SetValue(opts['e0']) self.xas_step.SetValue(opts['edge_step']) self.xas_pre1.SetValue(opts['pre1']) self.xas_pre2.SetValue(opts['pre2']) self.xas_nor1.SetValue(opts['norm1']) self.xas_nor2.SetValue(opts['norm2']) self.xas_vict.SetSelection(opts['nvict']) self.xas_nnor.SetSelection(opts['nnorm']) self.xas_showe0.SetValue(opts['show_e0']) self.xas_autoe0.SetValue(opts['auto_e0']) self.xas_autostep.SetValue(opts['auto_step']) def build_display(self): self.SetFont(Font(10)) titleopts = dict(font=Font(11), colour='#AA0000') gopts = dict(ncols=4, nrows=4, pad=2, itemstyle=LCEN) xas = self.xaspanel = GridPanel(self, **gopts) gen = self.genpanel = GridPanel(self, **gopts) self.btns = {} #gen opts = dict(action=self.UpdatePlot, size=(65, -1), gformat=True) self.xshift = FloatCtrl(gen, value=0.0, **opts) self.xscale = FloatCtrl(gen, value=1.0, **opts) self.yshift = FloatCtrl(gen, value=0.0, **opts) self.yscale = FloatCtrl(gen, value=1.0, **opts) self.btns['xshift'] = BitmapButton(gen, get_icon('plus'), action=partial(self.on_selpoint, opt='xshift'), tooltip='use last point selected from plot') self.btns['yshift'] = BitmapButton(gen, get_icon('plus'), action=partial(self.on_selpoint, opt='yshift'), tooltip='use last point selected from plot') opts = dict(action=self.onSmoothChoice, size=(30, -1)) sm_row1 = wx.Panel(gen) sm_row2 = wx.Panel(gen) sm_siz1= wx.BoxSizer(wx.HORIZONTAL) sm_siz2= wx.BoxSizer(wx.HORIZONTAL) self.smooth_c0 = FloatCtrl(sm_row1, value=2, precision=0, minval=1, **opts) self.smooth_c1 = FloatCtrl(sm_row1, value=1, precision=0, minval=1, **opts) self.smooth_msg = SimpleText(sm_row1, label=' ', size=(205, -1)) opts['size'] = (65, -1) self.smooth_sig = FloatCtrl(sm_row2, value=1, gformat=True, **opts) opts['size'] = (120, -1) self.smooth_op = Choice(sm_row1, choices=SMOOTH_OPS, **opts) self.smooth_op.SetSelection(0) self.smooth_conv = Choice(sm_row2, choices=CONV_OPS, **opts) self.smooth_c0.Disable() self.smooth_c1.Disable() self.smooth_sig.Disable() self.smooth_conv.SetSelection(0) self.smooth_conv.Disable() sm_siz1.Add(self.smooth_op, 0, LCEN, 1) sm_siz1.Add(SimpleText(sm_row1, ' n= '), 0, LCEN, 1) sm_siz1.Add(self.smooth_c0, 0, LCEN, 1) sm_siz1.Add(SimpleText(sm_row1, ' order= '), 0, LCEN, 1) sm_siz1.Add(self.smooth_c1, 0, LCEN, 1) sm_siz1.Add(self.smooth_msg, 0, LCEN, 1) sm_siz2.Add(SimpleText(sm_row2, ' form= '), 0, LCEN, 1) sm_siz2.Add(self.smooth_conv, 0, LCEN, 1) sm_siz2.Add(SimpleText(sm_row2, ' sigma= '), 0, LCEN, 1) sm_siz2.Add(self.smooth_sig, 0, LCEN, 1) pack(sm_row1, sm_siz1) pack(sm_row2, sm_siz2) gen.Add(SimpleText(gen, ' General Data Processing', **titleopts), dcol=8) gen.Add(SimpleText(gen, ' X shift:'), newrow=True) gen.Add(self.btns['xshift']) gen.Add(self.xshift, dcol=2) gen.Add(SimpleText(gen, ' X scale:')) gen.Add(self.xscale, dcol=2) gen.Add(SimpleText(gen, ' Y shift:'), newrow=True) gen.Add(self.btns['yshift']) gen.Add(self.yshift, dcol=2) gen.Add(SimpleText(gen, ' Y scale:')) gen.Add(self.yscale, dcol=2) gen.Add(SimpleText(gen, ' Smoothing:'), newrow=True) gen.Add(sm_row1, dcol=8) gen.Add(sm_row2, icol=1, dcol=7, newrow=True) gen.pack() #xas opts = {'action': self.UpdatePlot} e0opts_panel = wx.Panel(xas) self.xas_autoe0 = Check(e0opts_panel, default=True, label='auto?', **opts) self.xas_showe0 = Check(e0opts_panel, default=True, label='show?', **opts) sx = wx.BoxSizer(wx.HORIZONTAL) sx.Add(self.xas_autoe0, 0, LCEN, 4) sx.Add(self.xas_showe0, 0, LCEN, 4) pack(e0opts_panel, sx) self.xas_autostep = Check(xas, default=True, label='auto?', **opts) opts['size'] = (250, -1) self.xas_op = Choice(xas, choices=XASOPChoices, **opts) self.xas_op.SetStringSelection('Normalized') for name in ('e0', 'pre1', 'pre2', 'nor1', 'nor2'): bb = BitmapButton(xas, get_icon('plus'), action=partial(self.on_selpoint, opt=name), tooltip='use last point selected from plot') self.btns[name] = bb opts = {'size': (65, -1), 'gformat': True} self.xas_e0 = FloatCtrl(xas, value=0, action=self.onSet_XASE0, **opts) self.xas_step = FloatCtrl(xas, value=0, action=self.onSet_XASStep, **opts) opts['precision'] = 1 opts['action'] = self.UpdatePlot self.xas_pre1 = FloatCtrl(xas, value=-200, **opts) self.xas_pre2 = FloatCtrl(xas, value= -30, **opts) self.xas_nor1 = FloatCtrl(xas, value= 50, **opts) self.xas_nor2 = FloatCtrl(xas, value= -50, **opts) opts = {'size': (50, -1), 'choices': ('0', '1', '2', '3'), 'action': self.UpdatePlot} self.xas_vict = Choice(xas, **opts) self.xas_nnor = Choice(xas, **opts) self.xas_vict.SetSelection(1) self.xas_nnor.SetSelection(1) def CopyBtn(name): return Button(xas, 'Copy', size=(50, 30), action=partial(self.onCopyParam, name)) xas.Add(SimpleText(xas, ' XAS Data Processing', **titleopts), dcol=6) xas.Add(SimpleText(xas, ' Copy to Selected Groups?'), style=RCEN, dcol=3) xas.Add(SimpleText(xas, 'Arrays to Plot: '), newrow=True) xas.Add(self.xas_op, dcol=6) xas.Add((10, 10)) xas.Add(CopyBtn('xas_op'), style=RCEN) xas.Add(SimpleText(xas, 'E0 : '), newrow=True) xas.Add(self.btns['e0']) xas.Add(self.xas_e0) xas.Add(e0opts_panel, dcol=4) xas.Add((10, 1)) xas.Add(CopyBtn('xas_e0'), style=RCEN) xas.Add(SimpleText(xas, 'Edge Step: '), newrow=True) xas.Add((10, 1)) xas.Add(self.xas_step) xas.Add(self.xas_autostep, dcol=3) xas.Add((10, 1)) xas.Add((10, 1)) xas.Add(CopyBtn('xas_step'), style=RCEN) xas.Add(SimpleText(xas, 'Pre-edge range: '), newrow=True) xas.Add(self.btns['pre1']) xas.Add(self.xas_pre1) xas.Add(SimpleText(xas, ':')) xas.Add(self.btns['pre2']) xas.Add(self.xas_pre2) xas.Add(SimpleText(xas, 'Victoreen:')) xas.Add(self.xas_vict) xas.Add(CopyBtn('xas_pre'), style=RCEN) xas.Add(SimpleText(xas, 'Normalization range: '), newrow=True) xas.Add(self.btns['nor1']) xas.Add(self.xas_nor1) xas.Add(SimpleText(xas, ':')) xas.Add(self.btns['nor2']) xas.Add(self.xas_nor2) xas.Add(SimpleText(xas, 'PolyOrder:')) xas.Add(self.xas_nnor) xas.Add(CopyBtn('xas_norm'), style=RCEN) xas.pack() saveconf = Button(self, 'Save as Default Settings', size=(175, 30), action=self.onSaveConfigBtn) hxline = HLine(self, size=(550, 2)) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddMany([((10, 10), 0, LCEN, 10), (gen, 0, LCEN, 10), ((10, 10), 0, LCEN, 10), (hxline, 0, LCEN, 10), ((10, 10), 0, LCEN, 10), (xas, 0, LCEN, 10), ((10, 10), 0, LCEN, 10), (saveconf, 0, LCEN, 10), ]) xas.Disable() pack(self, sizer) def onSaveConfigBtn(self, evt=None): conf = self.controller.larch.symtable._sys.xyfit data_proc = {} data_proc.update(getattr(conf, 'data_proc', {})) data_proc['xshift'] = self.xshift.GetValue() data_proc['yshift'] = self.yshift.GetValue() data_proc['xscale'] = self.xscale.GetValue() data_proc['yscale'] = self.yscale.GetValue() data_proc['smooth_op'] = str(self.smooth_op.GetStringSelection()) data_proc['smooth_c0'] = int(self.smooth_c0.GetValue()) data_proc['smooth_c1'] = int(self.smooth_c1.GetValue()) data_proc['smooth_sig'] = float(self.smooth_sig.GetValue()) data_proc['smooth_conv'] = str(self.smooth_conv.GetStringSelection()) conf.data_proc = data_proc if self.xaspanel.Enabled: xas_proc = {} xas_proc.update(getattr(conf, 'xas_proc', {})) xas_proc['auto_e0'] = True xas_proc['auto_step'] = True xas_proc['pre1'] = self.xas_pre1.GetValue() xas_proc['pre2'] = self.xas_pre2.GetValue() xas_proc['norm1'] = self.xas_nor1.GetValue() xas_proc['norm2'] = self.xas_nor2.GetValue() xas_proc['nvict'] = self.xas_vict.GetSelection() xas_proc['nnorm'] = self.xas_nnor.GetSelection() xas_proc['show_e0'] = self.xas_showe0.IsChecked() xas_proc['nnorm'] = int(self.xas_nnor.GetSelection()) xas_proc['nvict'] = int(self.xas_vict.GetSelection()) xas_proc['xas_op'] = str(self.xas_op.GetStringSelection()) conf.xas_proc = xas_proc def onCopyParam(self, name=None, event=None): proc_opts = self.controller.group.proc_opts opts = {} name = str(name) if name == 'xas_op': opts['xas_op'] = proc_opts['xas_op'] elif name == 'xas_e0': opts['e0'] = proc_opts['e0'] opts['show_e0'] = proc_opts['show_e0'] opts['auto_e0'] = False elif name == 'xas_step': opts['edge_step'] = proc_opts['edge_step'] opts['auto_step'] = False elif name == 'xas_pre': opts['nvict'] = proc_opts['nvict'] opts['pre1'] = proc_opts['pre1'] opts['pre2'] = proc_opts['pre2'] elif name == 'xas_norm': opts['nnorm'] = proc_opts['nnorm'] opts['norm1'] = proc_opts['norm1'] opts['norm2'] = proc_opts['norm2'] for checked in self.controller.filelist.GetCheckedStrings(): groupname = self.controller.file_groups[str(checked)] grp = self.controller.get_group(groupname) if grp != self.controller.group: grp.proc_opts.update(opts) self.fill(grp) self.process(grp.groupname) def onSmoothChoice(self, evt=None, value=1): try: choice = self.smooth_op.GetStringSelection().lower() conv = self.smooth_conv.GetStringSelection() self.smooth_c0.Disable() self.smooth_c1.Disable() self.smooth_conv.Disable() self.smooth_sig.Disable() self.smooth_msg.SetLabel('') self.smooth_c0.SetMin(1) self.smooth_c0.odd_only = False if choice.startswith('box'): self.smooth_c0.Enable() elif choice.startswith('savi'): self.smooth_c0.Enable() self.smooth_c1.Enable() self.smooth_c0.Enable() self.smooth_c0.odd_only = True c0 = int(self.smooth_c0.GetValue()) c1 = int(self.smooth_c1.GetValue()) x0 = max(c1+1, c0) if x0 % 2 == 0: x0 += 1 self.smooth_c0.SetMin(c1+1) if c0 != x0: self.smooth_c0.SetValue(x0) self.smooth_msg.SetLabel('n must odd and > order+1') elif choice.startswith('conv'): self.smooth_conv.Enable() self.smooth_sig.Enable() self.needs_update = True except AttributeError: pass def onSet_XASE0(self, evt=None, **kws): self.xas_autoe0.SetValue(0) self.needs_update = True def onSet_XASStep(self, evt=None, **kws): self.xas_autostep.SetValue(0) self.needs_update = True def onProcessTimer(self, evt=None): if self.needs_update and self.controller.groupname is not None: self.process(self.controller.groupname) self.controller.plot_group(groupname=self.controller.groupname, new=True) self.needs_update = False def UpdatePlot(self, evt=None, **kws): self.needs_update = True def on_selpoint(self, evt=None, opt='e0'): xval, yval = self.controller.get_cursor() if xval is None: return e0 = self.xas_e0.GetValue() if opt == 'e0': self.xas_e0.SetValue(xval) self.xas_autoe0.SetValue(0) elif opt == 'pre1': self.xas_pre1.SetValue(xval-e0) elif opt == 'pre2': self.xas_pre2.SetValue(xval-e0) elif opt == 'nor1': self.xas_nor1.SetValue(xval-e0) elif opt == 'nor2': self.xas_nor2.SetValue(xval-e0) elif opt == 'xshift': self.xshift.SetValue(xval) elif opt == 'yshift': self.yshift.SetValue(yval) def process(self, gname, **kws): """ handle process (pre-edge/normalize) XAS data from XAS form, overwriting larch group 'x' and 'y' attributes to be plotted """ dgroup = self.controller.get_group(gname) proc_opts = {} proc_opts['xshift'] = self.xshift.GetValue() proc_opts['yshift'] = self.yshift.GetValue() proc_opts['xscale'] = self.xscale.GetValue() proc_opts['yscale'] = self.yscale.GetValue() proc_opts['smooth_op'] = self.smooth_op.GetStringSelection() proc_opts['smooth_c0'] = int(self.smooth_c0.GetValue()) proc_opts['smooth_c1'] = int(self.smooth_c1.GetValue()) proc_opts['smooth_sig'] = float(self.smooth_sig.GetValue()) proc_opts['smooth_conv'] = self.smooth_conv.GetStringSelection() self.xaspanel.Enable(dgroup.datatype.startswith('xas')) if dgroup.datatype.startswith('xas'): proc_opts['datatype'] = 'xas' proc_opts['e0'] = self.xas_e0.GetValue() proc_opts['edge_step'] = self.xas_step.GetValue() proc_opts['pre1'] = self.xas_pre1.GetValue() proc_opts['pre2'] = self.xas_pre2.GetValue() proc_opts['norm1'] = self.xas_nor1.GetValue() proc_opts['norm2'] = self.xas_nor2.GetValue() proc_opts['nvict'] = self.xas_vict.GetSelection() proc_opts['nnorm'] = self.xas_nnor.GetSelection() proc_opts['auto_e0'] = self.xas_autoe0.IsChecked() proc_opts['show_e0'] = self.xas_showe0.IsChecked() proc_opts['auto_step'] = self.xas_autostep.IsChecked() proc_opts['nnorm'] = int(self.xas_nnor.GetSelection()) proc_opts['nvict'] = int(self.xas_vict.GetSelection()) proc_opts['xas_op'] = self.xas_op.GetStringSelection() self.controller.process(dgroup, proc_opts=proc_opts) if dgroup.datatype.startswith('xas'): if self.xas_autoe0.IsChecked(): self.xas_e0.SetValue(dgroup.proc_opts['e0'], act=False) if self.xas_autostep.IsChecked(): self.xas_step.SetValue(dgroup.proc_opts['edge_step'], act=False) self.xas_pre1.SetValue(dgroup.proc_opts['pre1']) self.xas_pre2.SetValue(dgroup.proc_opts['pre2']) self.xas_nor1.SetValue(dgroup.proc_opts['norm1']) self.xas_nor2.SetValue(dgroup.proc_opts['norm2']) dgroup.orig_ylabel = dgroup.plot_ylabel dgroup.plot_ylabel = '$\mu$' dgroup.plot_y2label = None dgroup.plot_xlabel = '$E \,\mathrm{(eV)}$' dgroup.plot_yarrays = [(dgroup.mu, PLOTOPTS_1, dgroup.plot_ylabel)] y4e0 = dgroup.mu out = self.xas_op.GetStringSelection().lower() # raw, pre, norm, flat if out.startswith('raw data + pre'): dgroup.plot_yarrays = [(dgroup.mu, PLOTOPTS_1, '$\mu$'), (dgroup.pre_edge, PLOTOPTS_2, 'pre edge'), (dgroup.post_edge, PLOTOPTS_2, 'post edge')] elif out.startswith('pre'): dgroup.pre_edge_sub = dgroup.norm * dgroup.edge_step dgroup.plot_yarrays = [(dgroup.pre_edge_sub, PLOTOPTS_1, 'pre-edge subtracted $\mu$')] y4e0 = dgroup.pre_edge_sub dgroup.plot_ylabel = 'pre-edge subtracted $\mu$' elif 'norm' in out and 'deriv' in out: dgroup.plot_yarrays = [(dgroup.norm, PLOTOPTS_1, 'normalized $\mu$'), (dgroup.dmude, PLOTOPTS_D, '$d\mu/dE$')] y4e0 = dgroup.norm dgroup.plot_ylabel = 'normalized $\mu$' dgroup.plot_y2label = '$d\mu/dE$' dgroup.y = dgroup.norm elif out.startswith('norm'): dgroup.plot_yarrays = [(dgroup.norm, PLOTOPTS_1, 'normalized $\mu$')] y4e0 = dgroup.norm dgroup.plot_ylabel = 'normalized $\mu$' dgroup.y = dgroup.norm elif out.startswith('deriv'): dgroup.plot_yarrays = [(dgroup.dmude, PLOTOPTS_1, '$d\mu/dE$')] y4e0 = dgroup.dmude dgroup.plot_ylabel = '$d\mu/dE$' dgroup.y = dgroup.dmude dgroup.plot_ymarkers = [] if self.xas_showe0.IsChecked(): ie0 = index_of(dgroup.xdat, dgroup.e0) dgroup.plot_ymarkers = [(dgroup.e0, y4e0[ie0], {'label': '_nolegend_'})]
class ParameterWidgets(object): """a set of related widgets for a lmfit Parameter param = Parameter(value=11.22, vary=True, min=0, name='x1') wid = ParameterPanel(parent_wid, param) """ def __init__(self, parent, param, name_size=None, prefix=None, expr_size=120, stderr_size=120, float_size=80, minmax_size=60, widgets=PAR_WIDS): self.parent = parent self.param = param self._saved_expr = '' if (prefix is not None and not self.param.name.startswith(prefix)): self.param.name = "%s%s" % (prefix, self.param.name) for attr in PAR_WIDS: setattr(self, attr, None) # set vary_choice from param attributes vary_choice = PAR_VAR if param.expr not in (None, 'None', ''): vary_choice = PAR_CON elif not param.vary: vary_choice = PAR_FIX if 'name' in widgets: name = param.name if name in (None, 'None', ''): name = '' if name_size is None: name_size = min(50, len(param.name) * 10) self.name = wx.StaticText(parent, label=name, size=(name_size, -1)) if 'value' in widgets: self.value = FloatCtrl(parent, value=param.value, minval=param.min, maxval=param.max, action=self.onValue, act_on_losefocus=True, gformat=True, size=(float_size, -1)) if 'minval' in widgets: minval = param.min if minval in (None, 'None', -np.inf): minval = -np.inf self.minval = FloatCtrl(parent, value=minval, gformat=True, size=(minmax_size, -1), act_on_losefocus=True, action=self.onMinval) self.minval.Enable(vary_choice == PAR_VAR) if 'maxval' in widgets: maxval = param.max if maxval in (None, 'None', np.inf): maxval = np.inf self.maxval = FloatCtrl(parent, value=maxval, gformat=True, size=(minmax_size, -1), act_on_losefocus=True, action=self.onMaxval) self.maxval.Enable(vary_choice == PAR_VAR) if 'vary' in widgets: self.vary = Choice(parent, size=(90, -1), choices=VARY_CHOICES, action=self.onVaryChoice) self.vary.SetStringSelection(vary_choice) if 'expr' in widgets: expr = param.expr if expr in (None, 'None', ''): expr = '' self._saved_expr = expr self.expr = wx.TextCtrl(parent, -1, value=expr, size=(expr_size, -1)) self.expr.Enable(vary_choice == PAR_CON) self.expr.Bind(wx.EVT_CHAR, self.onExprChar) self.expr.Bind(wx.EVT_KILL_FOCUS, self.onExprKillFocus) SetTip(self.expr, 'Enter constraint expression') if 'stderr' in widgets: stderr = param.stderr if stderr in (None, 'None', ''): stderr = '' self.stderr = wx.StaticText(parent, label=stderr, size=(stderr_size, -1)) if 'minval' in widgets or 'maxval' in widgets: minval = param.min maxval = param.max bounds_choice = BOUNDS_custom if minval in (None, 'None', -np.inf) and maxval in (None, 'None', np.inf): bounds_choice = BOUNDS_none elif minval == 0: bounds_choice = BOUNDS_pos elif maxval == 0: bounds_choice = BOUNDS_neg self.bounds = Choice(parent, size=(90, -1), choices=BOUNDS_CHOICES, action=self.onBOUNDSChoice) self.bounds.SetStringSelection(bounds_choice) def onBOUNDSChoice(self, evt=None): bounds = str(evt.GetString().lower()) if bounds == BOUNDS_custom: pass elif bounds == BOUNDS_none: self.minval.SetValue(-np.inf) self.maxval.SetValue(np.inf) elif bounds == BOUNDS_pos: self.minval.SetValue(0) if float(self.maxval.GetValue()) == 0: self.maxval.SetValue(np.inf) elif bounds == BOUNDS_neg: self.maxval.SetValue(0) if float(self.minval.GetValue()) == 0: self.minval.SetValue(-np.inf) def onValue(self, evt=None, value=None): if value is not None: self.param.value = value def onExprChar(self, evt=None): key = evt.GetKeyCode() if key == wx.WXK_RETURN: self.onExpr(value=self.expr.GetValue()) evt.Skip() def onExprKillFocus(self, evt=None): self.onExpr(value=self.expr.GetValue()) evt.Skip() def onExpr(self, evt=None, value=None): if value is None and evt is not None: value = evt.GetString() try: ast.parse(value) self.param.expr = value bgcol, fgcol = 'white', 'black' except SyntaxError: bgcol, fgcol = 'red', 'yellow' self.expr.SetForegroundColour(fgcol) self.expr.SetBackgroundColour(bgcol) def onMinval(self, evt=None, value=None): if value in (None, 'None', ''): value = -np.inf if self.value is not None: v = self.value.GetValue() self.value.SetMin(value) self.value.SetValue(v) self.param.min = value if self.bounds is not None: if value == 0: self.bounds.SetStringSelection(BOUNDS_pos) elif value == -np.inf: if self.maxval.GetValue() == np.inf: self.bounds.SetStringSelection(BOUNDS_none) else: self.bounds.SetStringSelection(BOUNDS_custom) def onMaxval(self, evt=None, value=None): # print "onMaxval " , value, self.value, self.value if value in (None, 'None', ''): value = np.inf if self.value is not None: v = self.value.GetValue() self.value.SetMax(value) self.value.SetValue(v) self.param.max = value if self.bounds is not None: if value == 0: self.bounds.SetStringSelection(BOUNDS_neg) elif value == np.inf: if self.minval.GetValue() == -np.inf: self.bounds.SetStringSelection(BOUNDS_none) else: self.bounds.SetStringSelection(BOUNDS_custom) def onVaryChoice(self, evt=None): if self.vary is None: return vary = str(evt.GetString().lower()) self.param.vary = (vary == PAR_VAR) if ((vary == PAR_VAR or vary == PAR_FIX) and self.param.expr not in (None, 'None', '')): self._saved_expr = self.param.expr self.param.expr = '' elif (vary == PAR_CON and self.param.expr in (None, 'None', '')): self.param.expr = self._saved_expr if self.value is not None: self.value.Enable(vary != PAR_CON) if self.expr is not None: self.expr.Enable(vary == PAR_CON) if self.minval is not None: self.minval.Enable(vary == PAR_VAR) if self.maxval is not None: self.maxval.Enable(vary == PAR_VAR) if self.bounds is not None: self.bounds.Enable(vary == PAR_VAR)
class ColumnDataFileFrame(wx.Frame): """Column Data File, select columns""" def __init__(self, parent, filename=None, groupname=None, last_array_sel=None, read_ok_cb=None, edit_groupname=True, _larch=None): self.parent = parent self._larch = _larch self.path = filename group = self.initgroup = self.read_column_file(self.path) self.subframes = {} self.workgroup = Group(raw=group) for attr in ('path', 'filename', 'groupname', 'datatype', 'array_labels'): setattr(self.workgroup, attr, getattr(group, attr, None)) arr_labels = [l.lower() for l in self.initgroup.array_labels] if self.workgroup.datatype is None: self.workgroup.datatype = 'raw' if ('energ' in arr_labels[0] or 'energ' in arr_labels[1]): self.workgroup.datatype = 'xas' self.read_ok_cb = read_ok_cb self.array_sel = { 'xpop': '', 'xarr': None, 'ypop': '', 'yop': '/', 'yarr1': None, 'yarr2': None, 'use_deriv': False } if last_array_sel is not None: self.array_sel.update(last_array_sel) if self.array_sel['yarr2'] is None and 'i0' in arr_labels: self.array_sel['yarr2'] = 'i0' if self.array_sel['yarr1'] is None: if 'itrans' in arr_labels: self.array_sel['yarr1'] = 'itrans' elif 'i1' in arr_labels: self.array_sel['yarr1'] = 'i1' message = "Data Columns for %s" % group.filename wx.Frame.__init__(self, None, -1, 'Build Arrays from Data Columns for %s' % group.filename, style=FRAMESTYLE) self.SetFont(Font(10)) panel = wx.Panel(self) self.SetMinSize((600, 600)) self.colors = GUIColors() # title row title = SimpleText(panel, message, font=Font(13), colour=self.colors.title, style=LCEN) opts = dict(action=self.onUpdate, size=(120, -1)) yarr_labels = self.yarr_labels = arr_labels + ['1.0', '0.0', ''] xarr_labels = self.xarr_labels = arr_labels + ['_index'] self.xarr = Choice(panel, choices=xarr_labels, **opts) self.yarr1 = Choice(panel, choices=arr_labels, **opts) self.yarr2 = Choice(panel, choices=yarr_labels, **opts) self.yerr_arr = Choice(panel, choices=yarr_labels, **opts) self.yerr_arr.Disable() self.datatype = Choice(panel, choices=DATATYPES, **opts) self.datatype.SetStringSelection(self.workgroup.datatype) opts['size'] = (50, -1) self.yop = Choice(panel, choices=ARR_OPS, **opts) opts['size'] = (120, -1) self.use_deriv = Check(panel, label='use derivative', default=self.array_sel['use_deriv'], **opts) self.xpop = Choice(panel, choices=XPRE_OPS, **opts) self.ypop = Choice(panel, choices=YPRE_OPS, **opts) opts['action'] = self.onYerrChoice self.yerr_op = Choice(panel, choices=YERR_OPS, **opts) self.yerr_op.SetSelection(0) self.yerr_const = FloatCtrl(panel, value=1, precision=4, size=(90, -1)) ylab = SimpleText(panel, 'Y = ') xlab = SimpleText(panel, 'X = ') yerr_lab = SimpleText(panel, 'Yerror = ') self.xsuf = SimpleText(panel, '') self.ysuf = SimpleText(panel, '') self.xpop.SetStringSelection(self.array_sel['xpop']) self.ypop.SetStringSelection(self.array_sel['ypop']) self.yop.SetStringSelection(self.array_sel['yop']) if '(' in self.array_sel['ypop']: self.ysuf.SetLabel(')') ixsel, iysel, iy2sel = 0, 1, len(yarr_labels) - 1 if self.array_sel['xarr'] in xarr_labels: ixsel = xarr_labels.index(self.array_sel['xarr']) if self.array_sel['yarr1'] in arr_labels: iysel = arr_labels.index(self.array_sel['yarr1']) if self.array_sel['yarr2'] in yarr_labels: iy2sel = yarr_labels.index(self.array_sel['yarr2']) self.xarr.SetSelection(ixsel) self.yarr1.SetSelection(iysel) self.yarr2.SetSelection(iy2sel) bpanel = wx.Panel(panel) bsizer = wx.BoxSizer(wx.HORIZONTAL) _ok = Button(bpanel, 'OK', action=self.onOK) _cancel = Button(bpanel, 'Cancel', action=self.onCancel) _edit = Button(bpanel, 'Edit Array Names', action=self.onEditNames) bsizer.Add(_ok) bsizer.Add(_cancel) bsizer.Add(_edit) _ok.SetDefault() pack(bpanel, bsizer) sizer = wx.GridBagSizer(4, 8) sizer.Add(title, (0, 0), (1, 7), LCEN, 5) ir = 1 sizer.Add(xlab, (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.xpop, (ir, 1), (1, 1), CEN, 0) sizer.Add(self.xarr, (ir, 2), (1, 1), CEN, 0) sizer.Add(self.xsuf, (ir, 3), (1, 1), CEN, 0) ir += 1 sizer.Add(ylab, (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.ypop, (ir, 1), (1, 1), CEN, 0) sizer.Add(self.yarr1, (ir, 2), (1, 1), CEN, 0) sizer.Add(self.yop, (ir, 3), (1, 1), CEN, 0) sizer.Add(self.yarr2, (ir, 4), (1, 1), CEN, 0) sizer.Add(self.ysuf, (ir, 5), (1, 1), CEN, 0) sizer.Add(self.use_deriv, (ir, 6), (1, 1), LCEN, 0) ir += 1 sizer.Add(yerr_lab, (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.yerr_op, (ir, 1), (1, 1), CEN, 0) sizer.Add(self.yerr_arr, (ir, 2), (1, 1), CEN, 0) sizer.Add(SimpleText(panel, 'Value:'), (ir, 3), (1, 1), CEN, 0) sizer.Add(self.yerr_const, (ir, 4), (1, 2), CEN, 0) ir += 1 sizer.Add(SimpleText(panel, 'Data Type:'), (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.datatype, (ir, 1), (1, 2), LCEN, 0) ir += 1 self.wid_groupname = wx.TextCtrl(panel, value=group.groupname, size=(240, -1)) if not edit_groupname: self.wid_groupname.Disable() sizer.Add(SimpleText(panel, 'Group Name:'), (ir, 0), (1, 1), LCEN, 0) sizer.Add(self.wid_groupname, (ir, 1), (1, 2), LCEN, 0) ir += 1 sizer.Add(bpanel, (ir, 0), (1, 5), LCEN, 3) pack(panel, sizer) self.nb = fnb.FlatNotebook(self, -1, agwStyle=FNB_STYLE) self.nb.SetTabAreaColour(wx.Colour(248, 248, 240)) self.nb.SetActiveTabColour(wx.Colour(254, 254, 195)) self.nb.SetNonActiveTabTextColour(wx.Colour(40, 40, 180)) self.nb.SetActiveTabTextColour(wx.Colour(80, 0, 0)) self.plotpanel = PlotPanel(self, messenger=self.plot_messages) textpanel = wx.Panel(self) ftext = wx.TextCtrl(textpanel, style=wx.TE_MULTILINE | wx.TE_READONLY, size=(400, 250)) ftext.SetValue(group.text) ftext.SetFont(Font(10)) textsizer = wx.BoxSizer(wx.VERTICAL) textsizer.Add(ftext, 1, LCEN | wx.GROW, 1) pack(textpanel, textsizer) self.nb.AddPage(textpanel, ' Text of Data File ', True) self.nb.AddPage(self.plotpanel, ' Plot of Selected Arrays ', True) mainsizer = wx.BoxSizer(wx.VERTICAL) mainsizer.Add(panel, 0, wx.GROW | wx.ALL, 2) mainsizer.Add(self.nb, 1, LCEN | wx.GROW, 2) pack(self, mainsizer) self.statusbar = self.CreateStatusBar(2, 0) self.statusbar.SetStatusWidths([-1, -1]) statusbar_fields = [group.filename, ""] for i in range(len(statusbar_fields)): self.statusbar.SetStatusText(statusbar_fields[i], i) self.Show() self.Raise() self.onUpdate(self) def read_column_file(self, path): """read column file, generally as initial read""" parent, filename = os.path.split(path) with open(path, 'r') as fh: lines = fh.readlines() text = ''.join(lines) line1 = lines[0].lower() reader = 'read_ascii' if 'epics stepscan file' in line1: reader = 'read_gsexdi' elif 'xdi' in line1: reader = 'read_xdi' elif 'epics scan' in line1: reader = 'read_gsescan' tmpname = '_tmp_file_' read_cmd = "%s = %s('%s')" % (tmpname, reader, path) self.reader = reader deeplarch = self._larch._larch try: deeplarch.eval(read_cmd, add_history=False) except: pass if deeplarch.error: # self._larch.input.clear() msg = ["Error trying to read '%s':" % path, ""] for err in deeplarch.error: exc_name, errmsg = err.get_error() msg.append(errmsg) title = "Cannot read %s" % path r = Popup(self.parent, "\n".join(msg), title) return None group = self._larch.symtable.get_symbol(tmpname) self._larch.symtable.del_symbol(tmpname) group.text = text group.path = path group.filename = filename group.groupname = file2groupname(filename, symtable=self._larch.symtable) return group def show_subframe(self, name, frameclass, **opts): shown = False if name in self.subframes: try: self.subframes[name].Raise() shown = True except: del self.subframes[name] if not shown: self.subframes[name] = frameclass(self, **opts) def onEditNames(self, evt=None): self.show_subframe('editcol', EditColumnFrame, group=self.workgroup, on_ok=self.set_array_labels) def set_array_labels(self, arr_labels): self.workgroup.array_labels = arr_labels yarr_labels = self.yarr_labels = arr_labels + ['1.0', '0.0', ''] xarr_labels = self.xarr_labels = arr_labels + ['_index'] def update(wid, choices): curstr = wid.GetStringSelection() curind = wid.GetSelection() wid.SetChoices(choices) if curstr in choices: wid.SetStringSelection(curstr) else: wid.SetSelection(curind) update(self.xarr, xarr_labels) update(self.yarr1, yarr_labels) update(self.yarr2, yarr_labels) update(self.yerr_arr, yarr_labels) self.onUpdate() def onOK(self, event=None): """ build arrays according to selection """ if self.wid_groupname is not None: groupname = fix_varname(self.wid_groupname.GetValue()) yerr_op = self.yerr_op.GetStringSelection().lower() yerr_expr = '1' if yerr_op.startswith('const'): yerr_expr = "%f" % self.yerr_const.GetValue() elif yerr_op.startswith('array'): yerr_expr = '%%s.data[%i, :]' % self.yerr_arr.GetSelection() elif yerr_op.startswith('sqrt'): yerr_expr = 'sqrt(%s.ydat)' self.expressions['yerr'] = yerr_expr # generate script to pass back to calling program: labels = ', '.join(self.workgroup.array_labels) read_cmd = "%s('{path:s}', labels='%s')" % (self.reader, labels) buff = ["{group:s} = %s" % read_cmd, "{group:s}.path = '{path:s}'"] for attr in ('datatype', 'plot_xlabel', 'plot_ylabel'): val = getattr(self.workgroup, attr) buff.append("{group:s}.%s = '%s'" % (attr, val)) for aname in ('xdat', 'ydat', 'yerr'): expr = self.expressions[aname].replace('%s', '{group:s}') buff.append("{group:s}.%s = %s" % (aname, expr)) if getattr(self.workgroup, 'datatype', 'raw') == 'xas': if self.reader == 'read_gsescan': buff.append("{group:s}.energy = {group:s}.x") else: buff.append("{group:s}.energy = {group:s}.xdat") buff.append("{group:s}.mu = {group:s}.ydat") script = "\n".join(buff) if self.read_ok_cb is not None: self.read_ok_cb(script, self.path, groupname=groupname, array_sel=self.array_sel) self.Destroy() def onCancel(self, event=None): self.workgroup.import_ok = False self.Destroy() def onYerrChoice(self, evt=None): yerr_choice = evt.GetString() self.yerr_arr.Disable() self.yerr_const.Disable() if 'const' in yerr_choice.lower(): self.yerr_const.Enable() elif 'array' in yerr_choice.lower(): self.yerr_arr.Enable() self.onUpdate() def onUpdate(self, value=None, evt=None): """column selections changed calc xdat and ydat""" # dtcorr = self.dtcorr.IsChecked() # print("Column Frame on Update ") dtcorr = False use_deriv = self.use_deriv.IsChecked() rawgroup = self.initgroup workgroup = self.workgroup rdata = self.initgroup.data # print("onUpdate ", dir(rawgroup)) ix = self.xarr.GetSelection() xname = self.xarr.GetStringSelection() exprs = dict(xdat=None, ydat=None, yerr=None) ncol, npts = rdata.shape if xname.startswith('_index') or ix >= ncol: workgroup.xdat = 1.0 * np.arange(npts) xname = '_index' exprs['xdat'] = 'arange(%i)' % npts else: workgroup.xdat = rdata[ix, :] exprs['xdat'] = '%%s.data[%i, : ]' % ix workgroup.datatype = self.datatype.GetStringSelection().strip().lower() def pre_op(opwid, arr): opstr = opwid.GetStringSelection().strip() suf = '' if opstr in ('-log(', 'log('): suf = ')' if opstr == 'log(': arr = np.log(arr) elif opstr == '-log(': arr = -np.log(arr) return suf, opstr, arr try: xsuf, xpop, workgroup.xdat = pre_op(self.xpop, workgroup.xdat) self.xsuf.SetLabel(xsuf) exprs['xdat'] = '%s%s%s' % (xpop, exprs['xdat'], xsuf) except: return try: xunits = rawgroup.array_units[ix].strip() xlabel = '%s (%s)' % (xname, xunits) except: xlabel = xname yname1 = self.yarr1.GetStringSelection().strip() yname2 = self.yarr2.GetStringSelection().strip() iy1 = self.yarr1.GetSelection() iy2 = self.yarr2.GetSelection() yop = self.yop.GetStringSelection().strip() ylabel = yname1 if len(yname2) == 0: yname2 = '1.0' else: ylabel = "%s%s%s" % (ylabel, yop, yname2) if yname1 == '0.0': yarr1 = np.zeros(npts) * 1.0 yexpr1 = 'zeros(%i)' % npts elif len(yname1) == 0 or yname1 == '1.0' or iy1 >= ncol: yarr1 = np.ones(npts) * 1.0 yexpr1 = 'ones(%i)' % npts else: yarr1 = rdata[iy1, :] yexpr1 = '%%s.data[%i, : ]' % iy1 if yname2 == '0.0': yarr2 = np.zeros(npts) * 1.0 yexpr2 = '0.0' elif len(yname2) == 0 or yname2 == '1.0' or iy2 >= ncol: yarr2 = np.ones(npts) * 1.0 yexpr2 = '1.0' else: yarr2 = rdata[iy2, :] yexpr2 = '%%s.data[%i, : ]' % iy2 workgroup.ydat = yarr1 exprs['ydat'] = yexpr1 if yop in ('+', '-', '*', '/'): exprs['ydat'] = "%s %s %s" % (yexpr1, yop, yexpr2) if yop == '+': workgroup.ydat = yarr1.__add__(yarr2) elif yop == '-': workgroup.ydat = yarr1.__sub__(yarr2) elif yop == '*': workgroup.ydat = yarr1.__mul__(yarr2) elif yop == '/': workgroup.ydat = yarr1.__truediv__(yarr2) ysuf, ypop, workgroup.ydat = pre_op(self.ypop, workgroup.ydat) self.ysuf.SetLabel(ysuf) exprs['ydat'] = '%s%s%s' % (ypop, exprs['ydat'], ysuf) yerr_op = self.yerr_op.GetStringSelection().lower() exprs['yerr'] = '1' if yerr_op.startswith('const'): yerr = self.yerr_const.GetValue() exprs['yerr'] = '%f' % yerr elif yerr_op.startswith('array'): iyerr = self.yerr_arr.GetSelection() yerr = rdata[iyerr, :] exprs['yerr'] = '%%s.data[%i, :]' % iyerr elif yerr_op.startswith('sqrt'): yerr = np.sqrt(workgroup.ydat) exprs['yerr'] = 'sqrt(%s.ydat)' if use_deriv: try: workgroup.ydat = (np.gradient(workgroup.ydat) / np.gradient(workgroup.xdat)) exprs['ydat'] = 'deriv(%s)/deriv(%s)' % (exprs['ydat'], exprs['xdat']) except: pass self.expressions = exprs self.array_sel = { 'xpop': xpop, 'xarr': xname, 'ypop': ypop, 'yop': yop, 'yarr1': yname1, 'yarr2': yname2, 'use_deriv': use_deriv } try: npts = min(len(workgroup.xdat), len(workgroup.ydat)) except AttributeError: return workgroup.filename = rawgroup.filename workgroup.npts = npts workgroup.plot_xlabel = xlabel workgroup.plot_ylabel = ylabel workgroup.xdat = np.array(workgroup.xdat[:npts]) workgroup.ydat = np.array(workgroup.ydat[:npts]) workgroup.y = workgroup.ydat workgroup.yerr = yerr if isinstance(yerr, np.ndarray): workgroup.yerr = np.array(yerr[:npts]) if workgroup.datatype == 'xas': workgroup.energy = workgroup.xdat workgroup.mu = workgroup.ydat path, fname = os.path.split(workgroup.filename) popts = dict(marker='o', markersize=4, linewidth=1.5, title=fname, ylabel=ylabel, xlabel=xlabel, label="%s: %s" % (fname, workgroup.plot_ylabel)) self.plotpanel.plot(workgroup.xdat, workgroup.ydat, **popts) for i in range(self.nb.GetPageCount()): if 'plot' in self.nb.GetPageText(i).lower(): self.nb.SetSelection(i) def plot_messages(self, msg, panel=1): self.SetStatusText(msg, panel)
class DemoFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'wxutil demo', style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER | wx.TAB_TRAVERSAL) self.SetTitle('wxutil demo') self.SetFont(Font(11)) self.set_menu() self.statusbar = self.CreateStatusBar(2, 1) self.statusbar.SetStatusWidths([-2, -1]) statusbar_fields = ['Initializing....', ' '] for i in range(len(statusbar_fields)): self.statusbar.SetStatusText(statusbar_fields[i], i) self.Bind(wx.EVT_CLOSE, self.onExit) panel = GridPanel(self, nrows=8, ncols=4) tctrl_name = TextCtrl(panel, value='', action=self.onName, size=(250, -1)) lctrl_addr = LabeledTextCtrl(self, value='<>', action=self.onAddr, labeltext=' Address: ', size=(250, -1)) lab3 = HyperText(panel, ' FloatCtrl: ', size=(100, -1), action=self.onHyperText) val3 = FloatCtrl(panel, '3', action=self.onFloat1, precision=2, minval=0, maxval=1000, size=(250, -1)) lab4 = HyperText(panel, ' FloatSpin: ', size=(100, -1), action=self.onHyperText) val4 = FloatSpin(panel, '12.2', action=self.onFloatSpin, digits=2, increment=0.1, size=(250, -1)) labx = HyperText(panel, ' NumericCombo: ', size=(100, -1), action=self.onHyperText) steps = make_steps(prec=1, tmin=0, tmax=100) valx = NumericCombo(panel, steps, precision=1) self.choice1 = Choice(panel, size=(200, -1), action=self.onChoice) self.choice1.SetChoices(['Apple', 'Banana', 'Cherry']) yesno = YesNo(panel) check1 = Check(panel, label='enable? ', action=self.onCheck) btn1 = Button(panel, label='Start', size=(100, -1), action=self.onStart) pinbtn = BitmapButton(panel, get_icon('pin'), size=(50, -1), action=partial(self.onBMButton, opt='pin1'), tooltip='use last point selected from plot') togbtn = ToggleButton(panel, 'Press Me', action=self.onToggleButton, size=(100, -1), tooltip='do it, do it now, you will like it') browse_btn = Button(panel, 'Open File', action=self.onFileOpen, size=(150, -1)) okcancel = OkCancel(panel, onOK=self.onOK, onCancel=self.onCancel) ptable_btn = Button(panel, 'Show Periodic Table', action=self.onPTable, size=(175, -1)) edlist_btn = Button(panel, 'Show Editable Listbox', action=self.onEdList, size=(175, -1)) filelist_btn = Button(panel, 'Show File CheckList', action=self.onFileList, size=(175, -1)) panel.AddText(' Name: ', style=LEFT) panel.Add(tctrl_name, dcol=2) panel.Add(lctrl_addr.label, newrow=True) panel.Add(lctrl_addr, dcol=2) panel.Add(lab3, newrow=True) panel.Add(val3, dcol=3) panel.Add(lab4, newrow=True) panel.Add(val4, dcol=3) panel.Add(labx, newrow=True) panel.Add(valx, dcol=3) panel.AddText(' Choice : ', newrow=True) panel.Add(check1) panel.Add(self.choice1) panel.AddText(' Yes or No: ', newrow=True) panel.Add(yesno) panel.Add(HLine(panel, size=(500, -1)), dcol=3, newrow=True) panel.Add(btn1, newrow=True) panel.Add(pinbtn) panel.Add(togbtn) panel.Add(browse_btn, newrow=True) panel.Add(ptable_btn) panel.Add(edlist_btn, newrow=True) panel.Add(filelist_btn) panel.Add(okcancel, newrow=True) panel.pack() self.timer = wx.Timer(self) self.last_time = time.time() self.Bind(wx.EVT_TIMER, self.onTimer, self.timer) fsizer = wx.BoxSizer(wx.VERTICAL) fsizer.Add(panel, 0, LEFT | wx.EXPAND) wx.CallAfter(self.init_timer) psize = panel.GetBestSize() self.SetSize((psize[0] + 5, psize[1] + 25)) pack(self, fsizer) self.Refresh() def init_timer(self): self.timer.Start(500) def onTimer(self, event): idle_time = (time.time() - self.last_time) msg = "Time remaining = %.1f sec" % (30 - idle_time) self.statusbar.SetStatusText(msg, 1) if (time.time() - self.last_time) > 30: print("quitting...") self.onExit() def report(self, reason, value): self.statusbar.SetStatusText("%s: %s" % (reason, value), 0) self.last_time = time.time() def set_menu(self): menu = wx.Menu() mexit = MenuItem(self, menu, "Q&uit", "Quit Program", self.onExit) menubar = wx.MenuBar() menubar.Append(menu, "&File") self.SetMenuBar(menubar) def onOK(self, event=None): self.report("on OK: ", '') def onCancel(self, event=None): self.report("on Cancel: ", '') def onName(self, event=None): self.report("on Name: ", event) def onAddr(self, event=None): self.report("on Addr: ", event) def onHyperText(self, event=None, label=None): self.report("on HyperText ", label) def onFloat1(self, value=None): self.report("on Float1 ", value) def onFloatSpin(self, event=None): self.report("on FloatSpin ", event.GetString()) def onChoice(self, event=None): self.report("on Choice ", event.GetString()) def onCheck(self, event=None): self.report("on Check ", event.IsChecked()) self.choice1.Enable(event.IsChecked()) def onStart(self, event=None): self.report("on Start Button ", '') def onBMButton(self, event=None, opt='xxx'): self.report("on Bitmap Button ", opt) def onToggleButton(self, event=None): self.report(" on Toggle Button %s " % event.GetString(), event.IsChecked()) def onPTable(self, event=None): PTableFrame(fontsize=10).Show() def onEdList(self, event=None): frame = wx.Frame(self) edlist = EditableListBox(frame, self.onEdListSelect) edlist.Append(" Item 1 ") edlist.Append(" Item 2 ") edlist.Append(" Next ") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(edlist, 1, wx.EXPAND | wx.ALL, 5) pack(frame, sizer) frame.Show() frame.Raise() def onEdListSelect(self, event=None, **kws): self.report(" Editable List selected ", event.GetString()) def onFileList(self, event=None): frame = wx.Frame(self) edlist = FileCheckList(frame, select_action=self.onFileListSelect) for i in range(8): edlist.Append("File.%3.3d" % (i + 1)) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(edlist, 1, wx.EXPAND | wx.ALL, 5) pack(frame, sizer) frame.Show() frame.Raise() def onFileListSelect(self, event=None, **kws): self.report(" File List selected ", event.GetString()) def onFileOpen(self, event=None): wildcards = "%s|%s" % (PY_FILES, ALL_FILES) dlg = wx.FileDialog(self, message='Select File', wildcard=wildcards, style=wx.FD_OPEN) if dlg.ShowModal() == wx.ID_OK: path = os.path.abspath(dlg.GetPath()) self.report("file ", path) dlg.Destroy() def onExit(self, event=None): self.Destroy()