Hello Monks,
Here is a quick hack tool to view all the icons in PNG format in the current directory. It uses wxPerl and it's based on the tutorials I found here on PerlMonks and of course on the great work done by Mattia Barbon. Thank You!
Hope it will be useful.
#!/usr/bin/perl package IconFrame; use strict; use warnings; use Wx qw[:everything]; use base qw(Wx::Frame); use File::Find::Rule; sub new { my $self = shift; $self = $self->SUPER::new( undef, -1, 'Icon list', [-1, -1], [-1, -1], wxDEFAULT_FRAME_STYLE, ); Wx::InitAllImageHandlers(); # Image my $searchdir = '.'; my @iconfiles = File::Find::Rule ->name( '*.png' ) ->mindepth(1) ->maxdepth(1) ->file ->nonempty ->in($searchdir); # Try to compute grid sizees ;) my ($w, $h); my $icon_no = scalar @iconfiles; my $sqr = sqrt $icon_no; if ( $sqr == int $sqr) { $h = $w = $sqr; # Perfect square } else { $h = int $sqr; $w = int $sqr; while ( ($h * $w) < $icon_no ) { $w++; } } print "--> $icon_no icon files: $h x $w = ", $h * $w, "\n"; #- Grid Sizer $self->{sizer} = Wx::GridSizer->new($h, $w); foreach my $icon_idx (0 .. $#iconfiles) { my $file = $iconfiles[$icon_idx]; my $bmp = $self->make_bitmap_icon($file); #-- Create bitmap buttons my $button = Wx::BitmapButton->new( $self, -1, $bmp, [-1, -1], ); #-- Event handler Wx::Event::EVT_BUTTON( $self, $button, sub { print "$file\n"; } ); #-- Add buttons to grid sizer $self->{sizer}->Add( $button, 0, wxALIGN_CENTRE | wxGROW | wxALL, 2, ); } $self->SetSizer( $self->{sizer} ); $self->{sizer}->Fit($self); return $self; } sub make_bitmap_icon { my ($self, $iconfile) = @_; $self->{image} = Wx::Image->new( $iconfile, wxBITMAP_TYPE_ANY, -1, ); $self->{IconBmp} = Wx::Bitmap->new( $self->{image} ); return $self->{IconBmp}; } 1; package IconApp; use base 'Wx::App'; sub OnInit { my $frame = IconFrame->new(); $frame->Show( 1 ); } package main; use strict; use warnings; my $app = IconApp->new(); $app->MainLoop;
Regards, Stefan
Update: Code cleanup; Removed unnecessary loop
|
|---|