示例#1
0
    def __init__(self, clnt, spex=None):
        wx.Frame.__init__(self, None, -1, "CCD Client")

        def fetch():
            try:
                x,y = clnt.get_spectrum()
            except InstrumentError:
                clnt.connect() # try reconnecting
                x,y = clnt.get_spectrum()
            y = y.sum(axis=0) # collapse to 1D
            tr = 3  # truncate point
            return x[tr:], y[tr:]

        self.disp = SpecGraph(self,fetch)
        self.centerline = None
        self.spexlines = {}

        self.sidebar = wx.BoxSizer(wx.VERTICAL)

        # cal data viewer
        self.caldata = CalData(self)
        self.sidebar.Add(self.caldata, 1, border=5, flag=wx.ALL)
        self.Bind(wx.EVT_CHECKBOX, self.on_ne_checkbox, self.caldata.ne)
        self.Bind(wx.EVT_CHECKBOX, self.on_ar_checkbox, self.caldata.ar)

        if spex is not None:
            self.control = Spectrometer(self,spec)
            self.sidebar.Add(self.control, 1, border=5, flag=wx.ALL|wx.EXPAND)

            # re-bind the buttons to new methods defined below.
            # this is necessary to inform the ccd program
            # note: to rebind something, use a "Bind" method
            # of the same instance from which it was bound before,
            # (hence self.control.Bind and not self.Bind below)
            self.control.Bind(wx.EVT_BUTTON, self.on_move_button, self.control.move.button)
            self.control.Bind(wx.EVT_TEXT_ENTER, self.on_move_button, self.control.move.field)
            self.control.Bind(wx.EVT_BUTTON, self.on_cal_button, self.control.cal.button)
            self.control.Bind(wx.EVT_TEXT_ENTER, self.on_cal_button, self.control.cal.field)

            # draw center line
            self.draw_centerline()

        self.sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer.Add(self.disp, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
        self.sizer.Add(self.sidebar, 0, border=5, flag=wx.ALL)

        self.SetSizer(self.sizer)
        self.sizer.Fit(self)
示例#2
0
class MainFrame(wx.Frame):

    def __init__(self, clnt, spex=None):
        wx.Frame.__init__(self, None, -1, "CCD Client")

        def fetch():
            try:
                x,y = clnt.get_spectrum()
            except InstrumentError:
                clnt.connect() # try reconnecting
                x,y = clnt.get_spectrum()
            y = y.sum(axis=0) # collapse to 1D
            tr = 3  # truncate point
            return x[tr:], y[tr:]

        self.disp = SpecGraph(self,fetch)
        self.centerline = None
        self.spexlines = {}

        self.sidebar = wx.BoxSizer(wx.VERTICAL)

        # cal data viewer
        self.caldata = CalData(self)
        self.sidebar.Add(self.caldata, 1, border=5, flag=wx.ALL)
        self.Bind(wx.EVT_CHECKBOX, self.on_ne_checkbox, self.caldata.ne)
        self.Bind(wx.EVT_CHECKBOX, self.on_ar_checkbox, self.caldata.ar)

        if spex is not None:
            self.control = Spectrometer(self,spec)
            self.sidebar.Add(self.control, 1, border=5, flag=wx.ALL|wx.EXPAND)

            # re-bind the buttons to new methods defined below.
            # this is necessary to inform the ccd program
            # note: to rebind something, use a "Bind" method
            # of the same instance from which it was bound before,
            # (hence self.control.Bind and not self.Bind below)
            self.control.Bind(wx.EVT_BUTTON, self.on_move_button, self.control.move.button)
            self.control.Bind(wx.EVT_TEXT_ENTER, self.on_move_button, self.control.move.field)
            self.control.Bind(wx.EVT_BUTTON, self.on_cal_button, self.control.cal.button)
            self.control.Bind(wx.EVT_TEXT_ENTER, self.on_cal_button, self.control.cal.field)

            # draw center line
            self.draw_centerline()

        self.sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer.Add(self.disp, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
        self.sizer.Add(self.sidebar, 0, border=5, flag=wx.ALL)

        self.SetSizer(self.sizer)
        self.sizer.Fit(self)

    def on_move_button(self,event):
        self.control.on_move_button(event)
        clnt.center_wl = spec.wavelength
        self.draw_centerline()

    def on_cal_button(self,event):
        self.control.on_cal_button(event)
        clnt.center_wl = spec.wavelength
        self.draw_centerline()

    def draw_centerline(self):
        if self.centerline is not None:
            self.centerline.remove()
        self.centerline = self.disp.axes.axvline(spec.wl, c='k', ls='--')

    def on_ne_checkbox(self, event):
        if event.Checked():
            self.spexlines['Ne'] = self.draw_spexlines(self.caldata.data, 'r')
        else:
            for line in self.spexlines['Ne']:
                line.remove()

    def on_ar_checkbox(self, event):
        if event.Checked():
            self.spexlines['Ar'] = self.draw_spexlines(self.caldata.data, 'm')
        else:
            for line in self.spexlines['Ar']:
                line.remove()

    def draw_spexlines(self, locs, color):
        wlmin, wlmax = self.disp.axes.get_xlim()
        nearlocs = [wl for wl in locs if (wl > wlmin and wl < wlmax)]
        return [self.disp.axes.axvline(wl, c=color, ls=':') for wl in nearlocs]