1

我正在用 wxpython 编写我的第一个 gui,我相当坚持如何正确地将输入的数据从 NumCtrl 获取到一个数据结构中,该数据结构可以由 matplotlib 轻松操作以给出我想要的图。我的 GUI 模板如下所示

图形用户界面模板

基本上对于每个角度,我想输入带有(C)和不带(U)准直器的计数。当我按下绘图按钮时,我会从每个 wx.NumCtrl 中获取数字并绘制图表。目前我们将计数输入电子表格并使用ggplot2from绘图R。但是,我想用在同一脚本中完成的绘图编写的更用户友好的 GUI 来替换它。下面给出了所需最终图的示例

在此处输入图像描述

以下是相关代码的片段:

#Set input boxes for results
numctrl_ccm90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_cc0 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_uc0 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_fwhm = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)

fgs.AddMany([(angle),(count_c), (count_u),(angle2),(count_c2), (count_u2),
             (wx.StaticText(panel, -1, '-90')),
             (numctrl_ccm90,0,wx.EXPAND,5),
             (numctrl_ucm90,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '90')),
             (numctrl_ccp90,0,wx.EXPAND,5),
             (numctrl_ucp90,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '-75')),
             (numctrl_ccm75,0,wx.EXPAND,5),
             (numctrl_ucm75,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '75')),
             (numctrl_ccp75,0,wx.EXPAND,5),
             (numctrl_ucp75,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '-60')),
             (numctrl_ccm60,0,wx.EXPAND,5),
             (numctrl_ucm60,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '60')),
             (numctrl_ccp60,0,wx.EXPAND,5),
             (numctrl_ucp60,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '-45')),
             (numctrl_ccm45,0,wx.EXPAND,5),
             (numctrl_ucm45,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '45')),
             (numctrl_ccp45,0,wx.EXPAND,5),
             (numctrl_ucp45,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '-30')),
             (numctrl_ccm30,0,wx.EXPAND,5),
             (numctrl_ucm30,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '30')),
             (numctrl_ccp30,0,wx.EXPAND,5),
             (numctrl_ucp30,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '-15')),
             (numctrl_ccm15,0,wx.EXPAND,5),
             (numctrl_ucm15,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '15')),
             (numctrl_ccp15,0,wx.EXPAND,5),
             (numctrl_ucp15,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '0')),
             (numctrl_cc0,0,wx.EXPAND,5),
             (numctrl_uc0,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, '')),
             (wx.StaticText(panel, -1, '')),
             (wx.StaticText(panel, -1, '')),
             (wx.StaticText(panel, -1, '')),
             (wx.StaticText(panel, -1, '')),
             (wx.StaticText(panel, -1, '')),
             (wx.StaticText(panel, -1, 'FWHM')),
             (numctrl_fwhm,0,wx.EXPAND,5),
             (wx.StaticText(panel, -1, 'deg'))])

其中numctrl_ccm90numctrl_ucp90是对应于 -90deg 的准直计数和 +90deg 的非准直计数等的小部件。

我假设我应该创建某种绑定,用每个 NumCtrl 小部件的计数更新变量/列表/字典。我不知道我应该怎么做以及以什么格式最适合后续的绘图。例如,当我在 numctrl_ccm90 中输入 1234 个计数时,我想将此信息存储为counts: 1234 collimator:Y Angle: -90.

当我完成输入数据时,我会按下绘图按钮,它将获取每个 numCtrl 框中的计数值(除了 fwhm numctrl)并将所有这些信息放在允许​​绘图的结构中

对于绘图 - 我绘制了准直和非准直探测器与角度的归一化计数。完成这项任务的最佳方法是什么。这一刻我很迷茫


我现在在列表列表中有我的计数

self.angle_list = []
self.angles_list.append([-90,'U',self.numctrl_ucm90.GetValue()])
self.angles_list.append([-75,'U',self.numctrl_ucm75.GetValue()])

其中 angle_list 的每个元素都是格式为 [angle, collimator, counts] 的列表

不知道这对我有什么帮助。我需要的是“U”与“C”两种组合的角度与计数的散点图。

4

1 回答 1

1

我建议有 3 个自动生成的控件列表,然后您可以按顺序运行这些列表,一旦填充了一个网格尺寸器,然后在每个绘图上单击运行每个再次拾取值以放入两个元组或数组列表中供应情节。例如

self.Angles = range(-90, 100, 15)
self.Texts = [wx.StaticText(panel, -1, '%d' % a) for a in Angles]
self.CCount = [NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB) for a in Angles]
self.UCount = [NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB) for a in Angles]

在您的OnPlot方法中添加到 sizer 中:

   Cs = [ctrl.GetValue() for ctrl in self.CCount]
   Us = [ctrl.GetValue() for ctrl in self.UCount]
   plot(zip(Cs, Angles)) # or something similar

ETC...

于 2013-07-30T20:34:15.803 回答