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.

Code:

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

use base qw(Wx::Frame);
use Wx::Event
    qw(EVT_PAINT EVT_BUTTON EVT_CLOSE EVT_TOOL );

# 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 );

    #toolbar
    $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" );
    $toolbar->Realize();

    #set the default colours
$SpectrumWindow->SetBackgroundColour($SpectrumBackgroundColour);
$SpectrumWindow->SetForegroundColour($SpectrumForegroundColour);

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

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

    #    $this->do_DrawSpectrumLayout();

    # make sure the window has the focus rather than hiding
    # under the main window
    $SpectrumWindow->SetFocus;

# quantum stuff
..
    $SpectrumWindow->Show();
    return $this;
}

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

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

    #draw the first operator in the queue
    &DrawSpectrumAllOps($dc);
}


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

    $self->Close(1);
}


Reply via email to