I'm developing a perl-based program for the sciences that does some quantum calculations. I'd like to be able to take the results of the calculations and draw a spectrum corresponding to the resulting numbers so I've coded a child window with a dc and draw the spectrum in it. The problem is, the first time I open the window and draw the spectrum it works fine but if I close the window and then open it again and draw the spectrum from the last drawing session is still there! I need it to go away.

I thought that when the window was closed the dc, created in the sub-window package, was destroyed but I guess not. Any help is much appreciated.


package DrawSpectrumWindow;
use strict;
use Wx qw[:everything];

use base qw(Wx::Frame);
use Wx::Event

# constants and global variables
sub new {
    my ( $class, $label, $parent ) = @_;
    my ( $i, $j, $n );
    my $this = $class->SUPER::new( $parent, -1, $label );

    #Drawing Area
    #create a text control object and a text attribute object
    $SpectrumWindow = Wx::Frame->new( $this, -1, "Draw Spectrum",
        wxDefaultPosition, wxDefaultSize, );
    EVT_PAINT( $SpectrumWindow, \&OnPaint );

    $SpectrumWindow->CreateToolBar( wxNO_BORDER | wxHORIZONTAL | wxTB_FLAT,
        $ID_TOOLBAR4 );
    my $toolbar = $SpectrumWindow->GetToolBar();
    $toolbar->AddTool( $ID_QUIT, "exit",
        Wx::Bitmap->new( $ProgramPath . "exit.png", wxBITMAP_TYPE_PNG ),
        wxNullBitmap, wxITEM_NORMAL, "exit" );

    #set the default colours

    EVT_TOOL( $this, $ID_QUIT, \&DrawSpectrumWindow::OnDrawSpectrumQuit );

    $SpectrumWindow->SetTitle("Draw Spectrum");
        Wx::Size->new( $SpectrumWidth, $SpectrumHeight ) );

    #    $this->do_DrawSpectrumLayout();

    # make sure the window has the focus rather than hiding
    # under the main window

# quantum stuff
    return $this;

sub OnPaint {
    my ( $self, $event ) = @_;

    my $dc = Wx::PaintDC->new($self);
    my $pen = Wx::Pen->new( wxBLACK, 1, wxSOLID );
    my $brush = Wx::Brush->new( wxWHITE, wxSOLID );

    #draw the first operator in the queue

#more stuff
sub OnDrawSpectrumQuit {
    my ( $self, $event ) = @_;


Reply via email to