Gtk2-Ex-DbLinker

 view release on metacpan or  search on metacpan

examples/Forms/Dnav2.pm  view on Meta::CPAN

package Forms::Dnav2;
use strict;
use warnings;
use Carp qw( carp croak confess);
use Data::Dumper;
use Gtk2::Ex::DbLinker::Datasheet;
use Scalar::Util qw( weaken );
my %refs = map { $_, 1 }
    qw(Gtk2::Ex::Datasheet::DBI Linker::Datasheet Gtk2::Ex::DbLinker::Datasheet);
my %ref_form =
    map { $_, 1 } qw(Gtk2::Ex::DBI Linker::Form Gtk2::Ex::DbLinker::Form);

sub new {
    my $class = shift;
    my %def   = ( ismain => 1 );
    my %arg   = ( %def, @_ );
    my $self  = \%arg;
    bless $self, $class;
    $self->{msg} = "Dnav";
    my $builder = Gtk2::Builder->new();

#    %INC is another special Perl variable that is used to cache the names of the files and
#    the modules that were successfully loaded and compiled by use(), require() or do() statements.
# my $path= $INC{"Forms/Dnav2.pm"};

# $path =~ s/\/Forms\/Dnav2.pm// ; #Enlever /Forms/Dnav.pm de $path
#$builder->add_from_file( $path . "\\Forms\\dnav.bld")   or die "Couldn't read  glade/dnav.bld";
    my $path;
    $self->{log}       = Log::Log4perl->get_logger(__PACKAGE__);
    $self->{w2hide}    = [];
    $self->{w2disable} = [];

    # $self->{size}=$size_ref;
    if ( $ENV{PAR_TEMP} ) {
        $path = $ENV{PAR_TEMP} . "/inc/" . "gladefiles/dnav.bld";

        #$path = $ENV{PAR_TEMP}. "/inc/" ."glade/dnav.bld";
    }
    else {
        $path = "./gladefiles/dnav2.bld";
    }
    $builder->add_from_file($path);
    $self->{glade_xml} = $builder;
    my $mainw = $self->{glade_xml}->get_object("mainwindow");

    # $self->list_children($mainw);
    # $self->{glade_xml}->connect_signals($self);
    if ( $self->{ismain} ) {

        $mainw->signal_connect( "destroy", \&gtk_main_quit, $self );
        if ( $self->{dbh} ) {
            $self->show_tables( sql => $self->{sql}, dbh => $self->{dbh} );

        }
    }
    $self->{events_id}       = {};
    $self->{events_callback} = {
        "add"    => \&on_add_clicked,
        "del"    => \&on_delete_clicked,
        "cancel" => \&on_cancel_clicked,
        "apply"  => \&on_apply_clicked
    };
    for my $n ( keys %{ $self->{events_callback} } ) {
        my $id =
            $builder->get_object($n)
            ->signal_connect( 'clicked', $self->{events_callback}->{$n},
            $self );

examples/Forms/Dnav2.pm  view on Meta::CPAN

        # print "populate widgets 1: $name\n";
        my $id = $self->getID($c);
        if (   $c->get_sensitive
            && $c->isa('Gtk2::Buildable')
            && $name ne "GtkVBox"
            && $name ne "GtkHBox"
            && $id ne "" )
        {

            # print "populate widgets 2: $id $name\n";
            unless ( $keepit->{$id} ) {

                # $c->set_sensitive(0);
                push @{ $self->{w2disable} }, $c;
            }
        }
        $self->populate_widgets( $c, $keepit, 1 );
    }

}

sub getID {
    my $self = shift;
    my $w    = $_[0];
    my $ref  = ref $w;
    my $id;

    # get the id
    #print "$ref\n";
    if ($w) {
        $id = ( bless $w, "Gtk2::Buildable" )->get_name;

        # restore package
        bless $w, $ref;
    }
    return ( $id ? $id : "" );
}

sub get_object {
    my ( $self, $ctrl_name ) = @_;
    $self->{glade_xml}->get_object($ctrl_name);
}

sub list_children {
    my ( $self, $w ) = @_;
    return unless defined($w);
    $self->{log}->debug( "list_children :", ref $w, " ", $self->getID($w) );
    return unless $w->isa('Gtk2::Container');
    for my $c ( $w->get_children ) {
        $self->list_children($c);
    }

}

sub test { my $self = shift; print $self->{msg}, " in dnav.pm\n"; }

sub gtk_main_quit {
    my ( $w, $self ) = @_;

    # print Dumper @_;
    weaken $self->{mibuilder};
    Gtk2->main_quit;
}

1;
__END__

=head1 NAME

Package Forms::Dnav

A Navigation toolbar (nvabar for short), that can be used for a mainwindow, and that has two predefinned menu, or that can be used to navigate the records in a subform (and the menu are hidden then).

This module should be placed under a lib directory and the PERL5LIB environment variable should point to it.

=head1 
Depends also on

=over

=item *
Forms::Tools

=item *
a glad xml file with path lib/Forms/dnav.bld and the lib directory beeing define in the PERL5LIB environement variable (ie U:\docs\perl\lib on my pc)

=back

=head1 
SYNOPSIS

	$self->{dnav} = Forms::Dnav->new();
	my $b = $self->{dnav}->get_builder;
	$b->add_from_file( some glade files ) or die "Couldn't read ...";
	$b->connect_signals($self);


Build a navbar around a mainform

	$self->{dnav} =  Forms::Dnav->new(0);

Get a new Dnav object that will be used for a subform navigation. The predefinned menu in the navbar will not show

	$self->{dnav}-connect_signal_for("button name", \&code_ref, $data, $signal);

	$self->{dnav}->connect_signal_for("mainwindow", \&gtk_main_quit, $self, "destroy" ); 

Where

=over

=item *
button name is the button id in the glade file

=item *
&code_ref is a function to be called on click (default) unless a string is given in $signal

=item *
$data a ref to the Dnav object or to the main form object

=back 



( run in 1.935 second using v1.01-cache-2.11-cpan-97f6503c9c8 )