#!/usr/bin/perl use strict; use Wx; package MyCanvas; use strict; use vars qw(@ISA); @ISA = qw(Wx::ScrolledWindow); sub new { my( $class ) = shift; my( $this ) = $class->SUPER::new( @_[0,1,2,3], 0, $_[4] ); return $this; } package MusicOrganiserSplitterWindow; use strict; use vars qw(@ISA); @ISA = qw(Wx::SplitterWindow); use Wx qw(:splitterwindow wxDefaultPosition wxDefaultSize); use Wx::Event qw(EVT_SPLITTER_SASH_POS_CHANGED); sub new { my( $class ) = shift; my( $this ) = $class->SUPER::new( @_, wxDefaultPosition, wxDefaultSize, wxSP_3D|wxSP_LIVE_UPDATE ); $this->{FRAME} = $_[0]; return $this; } # Extend Wx's "Frame" class to create the main window. package MusicOrganiserFrame; use base qw(Wx::Frame); use Wx qw(wxOK wxICON_INFORMATION wxDefaultPosition wxDefaultSize); use Wx::Event qw(EVT_MENU); sub new { my $class = shift; my $self = $class->SUPER::new(@_); # Call superclass' constructor # Assign ID values my ($ID_MENU_FILE_REPORT, $ID_MENU_FILE_STATISTICS, $ID_MENU_EDIT_ADD, $ID_MENU_EDIT_DELETE, $ID_MENU_TOOLS_SETUP, $ID_MENU_HELP_CONTENTS, $ID_MENU_HELP_ABOUT, $ID_MENU_FILE_EXIT) = (1 .. 100); # Create menu objects my $file_menu = Wx::Menu->new(); my $tools_menu = Wx::Menu->new(); my $edit_menu = Wx::Menu->new(); my $help_menu = Wx::Menu->new(); # Create File menu $file_menu->Append($ID_MENU_FILE_REPORT, "\&Report\tCtrl+R", "Produce reports about your collection."); $file_menu->Append($ID_MENU_FILE_STATISTICS, "\&Statistics\tCtrl+S", "Display statistics for part or all of your collection."); $file_menu->AppendSeparator(); $file_menu->Append($ID_MENU_FILE_EXIT, "E\&xit\tCtrl+Q"); # Create Edit menu $edit_menu->Append($ID_MENU_EDIT_ADD, "\&Add volume", "Add a volume to your collection."); $edit_menu->Append($ID_MENU_EDIT_DELETE, "\&Delete volume", "Delete a volume from your collection."); # Create Tools menu $tools_menu->Append($ID_MENU_TOOLS_SETUP, "\&Setup", "Configure Music Organiser."); # Create Help menu $help_menu->Append($ID_MENU_HELP_CONTENTS, "\&Contents"); $help_menu->AppendSeparator(); $help_menu->Append($ID_MENU_HELP_ABOUT, "\&About"); # Create the menu bar that stores all the above menus my $menubar = Wx::MenuBar->new(); $menubar->Append($file_menu, '&File'); $menubar->Append($edit_menu, '&Edit'); $menubar->Append($tools_menu, '&Tools'); $menubar->Append($help_menu, '&Help'); $self->SetMenuBar($menubar); # Set up event handling for menu items. EVT_MENU($self, $ID_MENU_FILE_REPORT, \&OnMenu); # Set window icon $self->SetIcon(Wx::GetWxPerlIcon()); # Create status bar and assign values to the various segments $self->CreateStatusBar(3); $self->SetStatusText("Welcome to Music Organiser!", 1); $self->SetStatusText(scalar(gmtime), 2); my ($splitter) = $self->{SPLITTER} = MusicOrganiserSplitterWindow->new($self, -1); my ($lcanvas) = $self->{LEFTCANVAS} = MyCanvas->new($splitter, -1, [0,0], [400,400], 'Test1'); my ($rcanvas) = $self->{RIGHTCANVAS} = MyCanvas->new($splitter, -1, [0,0], [400,400], 'Test2'); $self->{TREE} = MusicOrganiserTree->new($lcanvas, -1, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS); $self->{SPLITTER}->SetMinimumPaneSize(250); $splitter->Initialize($lcanvas); $self->{LEFTCANVAS}->Show( 1 ); $self->{RIGHTCANVAS}->Show( 1 ); $self->{SPLITTER}->SplitVertically( @{$self}{'LEFTCANVAS','RIGHTCANVAS'} ); $self->{SPLITTER}->SetSashPosition(250,1); return $self; } sub OnMenu { Wx::MessageBox("Menu item selected", "Menu selected", wxOK | wxICON_INFORMATION, $_[0]); } package MusicOrganiserTree; use strict; use base qw(Wx::TreeCtrl); sub new { my $class = shift; my $this = $class->SUPER::new(@_); my $root = $this->AddRoot('Root', -1, -1, Wx::TreeItemData->new('Data')); my $tree_item; $tree_item = $this->AppendItem($root, "Please work", -1, -1, Wx::TreeItemData->new("I really hope this works!")); } package MusicOrganiserApp; use base qw(Wx::App); sub OnInit { my $self = shift; my $frame = MusicOrganiserFrame->new( undef, # Parent window -1, # Window ID 'Music Organiser', # Window title [1, 1], # X, Y position [600, 300] # X, Y size ); $self->SetTopWindow($frame); # Set the top-level window. $frame->Show(1); # Show the frame. } package main; my $app = MusicOrganiserApp->new(); $app->MainLoop;