This site uses cookies own and third. If you continue to browse consider to accept the use of cookies. OK More Info.

[Perl Tk] Finder Text 0.2

  • 0 Replies
  • 1786 Views

0 Members and 1 Guest are viewing this topic.

Offline BigBear

  • *
  • Underc0der
  • Posts: 543
  • Actividad:
    0%
  • Reputación 3
    • View Profile

[Perl Tk] Finder Text 0.2

  • on: June 23, 2012, 01:10:52 pm
Version Tk de un programa para buscar patrones en cualquier directorio.

Una imagen



El codigo

Code: (perl) You are not allowed to view links. Register or Login
#!usr/bin/perl
#Finder Text 0.2
#Version Tk
#Coded By Doddy H

use Tk;

my $color_fondo = "black";
my $color_texto = "green";

#if ($^O eq 'MSWin32') {
#use Win32::Console;
#Win32::Console::Free();
#}

my $vent =
  MainWindow->new( -background => $color_fondo, -foreground => $color_texto );
$vent->title("Finder Text 0.2 (C) Doddy Hackman 2012");
$vent->geometry("395x440+20+20");
$vent->resizable( 0, 0 );

$vent->Label(
    -text       => "Directory : ",
    -font       => "Impact1",
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 20, -y => 20 );
my $dir = $vent->Entry(
    -width      => 40,
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 100, -y => 23 );

$vent->Label(
    -text       => "String : ",
    -font       => "Impact1",
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 20, -y => 50 );
my $string = $vent->Entry(
    -width      => 30,
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 80, -y => 53 );

$vent->Button(
    -text             => "Find",
    -command          => \&now,
    -width            => 11,
    -background       => $color_fondo,
    -foreground       => $color_texto,
    -activebackground => $color_texto
)->place( -x => 271, -y => 53 );

$vent->Label(
    -text       => "Files Found",
    -font       => "Impact",
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 150, -y => 100 );
my $listas = $vent->Listbox(
    -width      => 50,
    -height     => 15,
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 45, -y => 150 );

$vent->Label(
    -text       => "Status : ",
    -font       => "Impact1",
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 70, -y => 390 );
my $tatus = $vent->Entry(
    -width      => 30,
    -background => $color_fondo,
    -foreground => $color_texto
)->place( -x => 130, -y => 393 );

$listas->bind( "<Double-1>", [ \&loader ] );

MainLoop;

sub loader {
    $listasx = $listas->curselection();
    for my $id (@$listasx) {
        my $linkar = $listas->get($id);
        system("$linkar");
    }
}

sub now {
    $listas->delete( "0.0", "end" );
    goodbye( $dir->get, $string->get );
    $tatus->configure( -text => " " );
}

sub verificar {

    my ( $file, $text ) = @_;
    my $numero_linea = 0;

    open( FILE, $file );
    my @words = <FILE>;
    close FILE;

    chomp @words;

    for my $linea (@words) {
        chomp $linea;
        $numero_linea++;
        if ( $linea =~ /$text/ ) {
            $listas->insert( "end", $file );
        }
    }
}

sub goodbye {
    opendir DIR, $_[0];
    my @archivos = readdir DIR;
    close DIR;

    for (@archivos) {
        next if $_ eq "." or $_ eq "..";
        my $fichero = $_[0] . "/" . $_;

        if ( -f $fichero ) {
            $vent->update;
            $tatus->configure( -text => $fichero );
            verificar( $fichero, $_[1] );
        }

        if ( -d $fichero ) {
            &goodbye( $fichero, $_[1] );
        }
    }
}

#The End ?