Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Using Icons on Wx::Notebook

by Steve_BZ (Hermit)
on Nov 18, 2009 at 17:09 UTC ( #807957=CUFP: print w/ replies, xml ) Need Help??

Here a small piece of code showing how to create a Notebook with icons at the side (think MSN). In this example you need two icons called "users.png" and "schedule.png" 16 x 16 pixels in directory "C:\Documents and Settings\Steve\My Documents\Projects\wx" and set the $loc_windows_linux flag to "l" or "w"

#!/usr/bin/perl -w -- # generated by wxGlade 0.6.3 on Wed Nov 18 13:50:09 2009 from "C:\Docu +ments and Settings\Steve\My Documents\Projects\wx\deletemeNotebook.wx +g" # To get wxPerl visit http://wxPerl.sourceforge.net/ use Wx 0.15 qw[:allclasses]; use strict; package MyFrame; use Wx qw[:everything]; use base qw(Wx::Frame); use strict; sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_ +; $parent = undef unless defined $parent; $id = -1 unless defined $id; $title = "" unless defined $title; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $name = "" unless defined $name; # begin wxGlade: MyFrame::new # my $loc_windows_linux = "l"; #Set to Linux my $loc_windows_linux = "w"; #Set to Windows my $loc_installation_path ; if ($loc_windows_linux eq "l") { $loc_installation_path = "/home/steve/Documents/wx/"; } if ($loc_windows_linux eq "w") { $loc_installation_path = "C:\\Documents and Settings\\Steve\\M +y Documents\\Projects\\wx\\"; } $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $sty +le, $name ); $self->{notebook_1} = Wx::Notebook->new($self, -1, wxDefaultPositi +on, Wx::Size->new(300, 300), wxNB_LEFT ); $self->{notebook_1_pane_1} = Wx::Panel->new($self->{notebook_1}, - +1, wxDefaultPosition, wxDefaultSize, ); $self->{notebook_1_pane_2} = Wx::Panel->new($self->{notebook_1}, - +1, wxDefaultPosition, wxDefaultSize, ); $self->{notebook_1_pane_3} = Wx::Panel->new($self->{notebook_1}, - +1, wxDefaultPosition, wxDefaultSize, ); $self->{notebook_1_pane_4} = Wx::Panel->new($self->{notebook_1}, - +1, wxDefaultPosition, wxDefaultSize, ); $self->{notebook_1_pane_5} = Wx::Panel->new($self->{notebook_1}, - +1, wxDefaultPosition, wxDefaultSize, ); $self->{Loc_Image_List} = Wx::ImageList->new(16,16,1, 1); my $loc_bitmap = Wx::Bitmap->new($loc_installation_path."schedule. +png", wxBITMAP_TYPE_PNG); my $a=$self->{Loc_Image_List} -> Add($loc_bitmap); $loc_bitmap = Wx::Bitmap->new($loc_installation_path."users.png", +wxBITMAP_TYPE_PNG); my $b=$self->{Loc_Image_List} -> Add($loc_bitmap); $self->{notebook_1}->AssignImageList($self->{Loc_Image_List}); $self->{notebook_1}->AddPage($self->{notebook_1_pane_1}, "", 0, $a +); $self->{notebook_1}->AddPage($self->{notebook_1_pane_2}, "", 1, $b +); $self->{notebook_1}->AddPage($self->{notebook_1_pane_3}, "tab3", 0 +, -1); $self->{notebook_1}->AddPage($self->{notebook_1_pane_4}, "tab4", 0 +, -1); $self->{notebook_1}->AddPage($self->{notebook_1_pane_5}, "tab5", 0 +, -1); $self->__set_properties(); $self->__do_layout(); # end wxGlade return $self; } sub __set_properties { my $self = shift; # begin wxGlade: MyFrame::__set_properties $self->SetTitle("frame_1"); # end wxGlade } sub __do_layout { my $self = shift; # begin wxGlade: MyFrame::__do_layout $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL); $self->{sizer_1}->Add($self->{notebook_1}, 1, wxEXPAND, 0); $self->SetSizer($self->{sizer_1}); $self->{sizer_1}->Fit($self); $self->Layout(); # end wxGlade } # end of class MyFrame 1; 1; package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $frame_1 = MyFrame->new(); $app->SetTopWindow($frame_1); $frame_1->Show(1); $app->MainLoop(); }

Comment on Using Icons on Wx::Notebook
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://807957]
Approved by Tanalis
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-10-23 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (128 votes), past polls