# Beginner Problem with drawing

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.Append(100, 'Save As ...', 'Saves Figure as ...')
file.AppendSeparator()
file.Append(113, '&Quit\tCtrl+W')
#--------------------------------------------------------------
dyes.AppendSeparator()
dyes.Append(111, '&Delete last Absorption', 'Deletes last Absorption Spectra')
dyes.Append(112, '&Delete last Fluorescence', 'Deletes last Fluorescence Emission')
#--------------------------------------------------------------

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.AppendSeparator()
lightsource.Append(110, '&Delete last Light Source', 'Deletes the last Light Source')
#--------------------------------------------------------------
laserline.Append(114, '&Set Laser Lines',' Displays the selected laser lines')
#--------------------------------------------------------------
#--------------------------------------------------------------
#--------------------------------------------------------------

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 = 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
sebrhode@…982…