1

I am writing my first gui in wxpython and I am fairly stuck on how to properly get the entered data from the NumCtrl into a data structure that can be easily manipulated by matplotlib to give my desired plot. My GUI template is shown below

GUI template

Basically for each angle I want to enter the number of counts with (C) and without (U) a collimator in place. When I press the plot button I would then the numbers from each wx.NumCtrl and plot the graph. Currently we enter the counts into a spreadsheet and plot using ggplot2 from R. However I would like to replace this with a more user friendly GUI written with the plotting done within the same script. An example of the desired final plot is given below

enter image description here

Here is the snippet of the relevant code below:

#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'))])

where numctrl_ccm90 and numctrl_ucp90 are the widgets corresponding to the collimated counts at -90deg and the uncollimated counts +90deg etc.

I assume I should create some kind of binding that updates a variable/list/dictionary with the counts for each NumCtrl widget. I am not sure how I should do this and in what format is best for subsequent plotting. For example when I enter 1234 counts in numctrl_ccm90 I would like to store this information as counts: 1234 collimator:Y Angle: -90.

When I finish typing in the data I would press the plot button, which would pick up the counts value in each numCtrl box (apart from the fwhm numctrl) and would place all this information in a structure that allows plotting

For the plot - I plot normalised counts for collimated and uncollimated detector versus angle. What is the best way to approach this task. I'm pretty lost at this moment


I have my counts in a list of lists now

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

where each element of angle_list is a list with format [angle, collimator, counts]

Not sure how this helps me plot. What I need is a scatter plot of angle vs counts for the 2 combinations 'U' vs 'C'.

1 Answer 1

1

I would suggest having 3 lists of controls, auto-generated, you can then run through the lists in order, once populating a grid sizer and on each plot click run through each again picking up the values to put into two lists of tupples or arrays to supply to plot. e.g.

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]

do your adding to a sizer and in your OnPlot method:

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

etc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.