Hi guys,

i wrote a little program to display filter sets used for microscopy. The
spectra data are shown using matplotlib and wxmpl. The GUI hat a menu item
"Set Lines" --> an extra Frame with checkboxes will open up.
Upon checking or unchecking, the laser lines should be displayed or deleted
inside the main panel as vertical lines, but I juts can not figure out, how
to acess the meain panel when checking.

The problem is located in line 58, 63 and 68

Here is the code:

#!/usr/bin/env python

import numpy
from pylab import *
import scipy
import scipy.linalg
import wx
import wxmpl
import os, sys


xmin = 350
xmax = 700
ymin = 0
ymax = 1.05


# normalizes dye spectra to 1
def normspec(datain):
        out = datain
        out[:,1] = datain[:,1]/datain[:,1].max(0)
        return out

# converts filters spectra to 0-1 range
def normspec_filter(datain):
        out = datain
        if datain[:,1].max(0)>10:
            out[:,1] = datain[:,1]/100
        return out

class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, -1, 'FilterSpectra')
        self.frame.Show(True)
        return True

class SetLaser(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(220, 130))

        wl = array([405, 445, 473])
        panel = wx.Panel(self, -1)

        self.cb0 = wx.CheckBox(panel, 10, str(wl[0])+'nm', (10,  10))
        self.cb1 = wx.CheckBox(panel, 11, str(wl[1])+'nm', (80,  10))
        self.cb2 = wx.CheckBox(panel, 12, str(wl[2])+'nm', (150, 10))

        self.Bind(wx.EVT_CHECKBOX, self.on_checkbox0, id=10)
        self.Bind(wx.EVT_CHECKBOX, self.on_checkbox1, id=11)
        self.Bind(wx.EVT_CHECKBOX, self.on_checkbox2, id=12)

        self.CenterOnParent()
        self.Show()

    def on_checkbox0(self, event):
            self.cb0value = event.IsChecked()
            print self.cb0value
            self.glaser0, = self.axes.plot([wl[i],wl[i]],[0,1],'b', lw=2)

    def on_checkbox1(self, event):
            self.cb1value = event.IsChecked()
            print self.cb1value
            self.glaser1, = self.axes.plot([wl[i],wl[i]],[0,1],'b', lw=2)

    def on_checkbox2(self, event):
            self.cb2value = event.IsChecked()
            print self.cb2value
            self.glaser2, = self.axes.plot([wl[i],wl[i]],[0,1],'b', lw=2)

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(1000, 800))

        menuBar = wx.MenuBar()
        self.CreateStatusBar()
        #--------------------------------------------------------------
        file = wx.Menu()
        file.Append(100, 'Save As ...', 'Saves Figure as ...')
        file.AppendSeparator()
        file.Append(113, '&Quit\tCtrl+W')
        #--------------------------------------------------------------
        dyes = wx.Menu()
        dyes.Append(101, '&Load Dye Absorption', 'Loads Absorption Spectra
(*.abs)')
        dyes.Append(102, '&Load Dye Fluorescence', 'Loads Fluorescence
Emission Spectra (*.flu)')
        dyes.AppendSeparator()
        dyes.Append(111, '&Delete last Absorption', 'Deletes last Absorption
Spectra')
        dyes.Append(112, '&Delete last Fluorescence', 'Deletes last
Fluorescence Emission')
        #--------------------------------------------------------------

        filter = wx.Menu()
        filter.Append(103, '&Load Excitation Filter', 'Loads Excitation
Filter (*.ex)')
        filter.Append(104, '&Load Dichroic Mirror', 'Loads Dichroic Mirror
(*.di)')
        filter.Append(105, '&Load Emission Filter', 'Loads Emission Filter
(*.em)')
        filter.AppendSeparator()
        filter.Append(107, '&Delete last EX filter', 'Deletes the last EX
filter')
        filter.Append(108, '&Delete last DI mirror', 'Deletes the last DI
mirror')
        filter.Append(109, '&Delete last EM filter', 'Deletes the last EM
filter')
        #--------------------------------------------------------------
        lightsource = wx.Menu()
        lightsource.Append(106, '&Load Light Source', 'Loads Spectral Data
of Light Source (*.txt)')
        lightsource.AppendSeparator()
        lightsource.Append(110, '&Delete last Light Source', 'Deletes the
last Light Source')
        #--------------------------------------------------------------
        laserline = wx.Menu()
        laserline.Append(114, '&Set Laser Lines',' Displays the selected
laser lines')
        #--------------------------------------------------------------
        menuBar.Append(file, '&File')
        menuBar.Append(dyes, '&Dyes')
        menuBar.Append(filter, '&Filter')
        menuBar.Append(lightsource, '&Light Source')
        menuBar.Append(laserline, '&Laser Lines')
        #--------------------------------------------------------------
        self.SetMenuBar(menuBar)
        #--------------------------------------------------------------
        self.Bind(wx.EVT_MENU, self.saveas,        id = 100)
        self.Bind(wx.EVT_MENU, self.openabs,    id = 101)
        self.Bind(wx.EVT_MENU, self.openflu,    id = 102)
        self.Bind(wx.EVT_MENU, self.openex,        id = 103)
        self.Bind(wx.EVT_MENU, self.opendi,        id = 104)
        self.Bind(wx.EVT_MENU, self.openem,        id = 105)
        self.Bind(wx.EVT_MENU, self.openls,        id = 106)
        self.Bind(wx.EVT_MENU, self.delex,        id = 107)
        self.Bind(wx.EVT_MENU, self.deldi,        id = 108)
        self.Bind(wx.EVT_MENU, self.delem,        id = 109)
        self.Bind(wx.EVT_MENU, self.dells,        id = 110)
        self.Bind(wx.EVT_MENU, self.delabs,        id = 111)
        self.Bind(wx.EVT_MENU, self.delflu,        id = 112)
        self.Bind(wx.EVT_MENU, self.OnQuit,        id = 113)
        self.Bind(wx.EVT_MENU, self.laserlines,    id = 114)

        self.plotPanel = wxmpl.PlotPanel(self, -1,)
        fig = self.plotPanel.get_figure()
        self.axes = fig.gca()
        self.axes.set_xticks(arange(xmin - 100, xmax + 100,  25))
        self.axes.set_yticks(arange(ymin - 100, ymax + 100, 0.1));
        self.axes.axis([xmin,xmax,ymin,ymax])
        self.axes.grid(True)
        self.axes.set_xlabel('Wavelength [nm]',fontsize=16)
        self.axes.set_ylabel('Transmission [%] or Intensity
[a.u.]',fontsize=16)


    def openex(self, event):
        dlg = wx.FileDialog(self, "Choose a Excitation Filter", os.getcwd(),
"", "*.ex*", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            pathex = dlg.GetPath()
            mypathex = os.path.basename(pathex)
            self.SetStatusText("Selected EX: %s" % mypathex)
            ex = numpy.loadtxt(pathex)
            ex = normspec_filter(ex)
            self.gex, = self.axes.plot(ex[:,0],ex[:,1],'b', lw=2,label =
mypathex)
            #self.axes.plot(ex[:,0],ex[:,1],'b', lw=2,label = mypathex)
            self.axes.axis([xmin,xmax,ymin,ymax])
            self.axes.legend(loc=4)
            self.plotPanel.draw()

        dlg.Destroy()
#...
# --> here is some more code ...
#...
class MyApp(wx.App):
    def OnInit(self):
        myframe = MyFrame(None, -1, "FilterSpectra")
        myframe.CenterOnScreen()
        myframe.Show(True)
        return True


app = MyApp(0)
app.MainLoop()


-- 
Dr. Sebastian Rhode
Grünwalder Str. 103a
81547 München
Tel: +49 89 4703091
sebrh...@googlemail.com
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to