App-GUI-Notepad
view release on metacpan or search on metacpan
lib/App/GUI/Notepad.pm view on Meta::CPAN
use vars qw{$VERSION};
BEGIN {
$VERSION = '0.03';
}
sub OnInit {
my ($this) = @_;
Wx::InitAllImageHandlers();
my ($frame) = App::GUI::Notepad::Frame->new(
"Perlpad",
Wx::Point->new( 50, 50 ),
Wx::Size->new( 450, 350 )
);
$this->{frame} = $frame;
$this->SetTopWindow($frame);
$frame->Show(1);
$this;
}
1;
=pod
=head1 NAME
lib/App/GUI/Notepad/Frame.pm view on Meta::CPAN
my ($this) = $class->SUPER::new( undef, -1, $title, $position, $size );
$this->SetIcon( Wx::GetWxPerlIcon() );
$this->{menubar} = App::GUI::Notepad::MenuBar->new();
$this->SetMenuBar( $this->{menubar}->menubar() );
# Associate the various menu options with subroutines that are the
# actions to be carried out when the user clicks on the menu item.
#
# I wanted to do this in the MenuBar object but this function
# EVT_MENU need a reference to the frame and so they are called
# here
EVT_MENU( $this, $this->{menubar}->{ID_NEW}, \&_menu_new );
EVT_MENU( $this, $this->{menubar}->{ID_OPEN}, \&_menu_open );
EVT_MENU( $this, $this->{menubar}->{ID_SAVE}, \&_menu_save );
EVT_MENU( $this, $this->{menubar}->{ID_SAVEAS}, \&_menu_saveas );
EVT_MENU( $this, $this->{menubar}->{ID_CLOSE}, \&_menu_close );
EVT_MENU( $this, $this->{menubar}->{ID_EXIT}, \&_menu_exit );
EVT_MENU( $this, $this->{menubar}->{ID_UNDO}, \&_menu_undo );
EVT_MENU( $this, $this->{menubar}->{ID_REDO}, \&_menu_redo );
lib/App/GUI/Notepad/Frame.pm view on Meta::CPAN
$this->SetTitle("Perlpad");
$this->{textctrl}->SetValue("");
$this->{filename} = "";
return 1;
}
# This sub is called when the user clicks on menu File item Open
# The dialog that allows the user to choose a new file is displayed
# The text control is then instructed to load the contents of the file
# The title of the frame is altered to show the file's name
sub _menu_open {
my ($this) = @_;
my $opendialog = Wx::FileDialog->new($this, "Choose a file to open",
"", "", "*.*", 0, [0,0]);
my $result = $opendialog->ShowModal();
if ($result == wxID_OK) {
$this->{filename} = File::Spec->catfile(
$opendialog->GetDirectory(), $opendialog->GetFilename()
);
t/02_start_perlpad.t view on Meta::CPAN
}
use Test::NeedsDisplay;
use Test::More tests => 8;
use App::GUI::Notepad;
my $app = App::GUI::Notepad->new();
ok(defined $app, 'Åpplication object instantiation');
isa_ok($app, 'App::GUI::Notepad');
ok(defined $app->{frame}, 'Menubar instantiation');
isa_ok($app->{frame}, 'App::GUI::Notepad::Frame');
my $frame = $app->{frame};
ok(defined $frame->{menubar}, 'Frame has a menubar');
isa_ok($frame->{menubar}, 'App::GUI::Notepad::MenuBar');
ok(defined $frame->{textctrl}, 'Frame has a menubar');
isa_ok($frame->{textctrl}, 'Wx::TextCtrl');
exit(0);
t/03_newfile_and_save.t view on Meta::CPAN
}
use Test::NeedsDisplay;
use Test::More tests => 5;
use App::GUI::Notepad;
my $app = App::GUI::Notepad->new();
my $frame = $app->{frame};
my $textctrl = $frame->{textctrl};
can_ok($frame, '_menu_new');
ok($frame->_menu_new(), 'File..New');
ok($textctrl->GetValue eq '', 'File..New successful');
$frame->{filename} = 'test.txt';
can_ok($frame, '_menu_save');
ok($frame->_menu_save(), 'File..Save');
exit(0);
( run in 0.554 second using v1.01-cache-2.11-cpan-df04353d9ac )