Tk/CheckListViewer.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 88 CC 2 SCAR 9.8
CC
2
Cov
0%
Populate
6.0
ClassInit
2.0
add_value_help
2.0
CRAP 2.7
1 #
2 # This file is part of Config-Model-TkUI
3 #
4 # This software is Copyright (c) 2008-2021 by Dominique Dumont.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Config::Model::Tk::CheckListViewer 1.382;
11  
12 use strict;
13 use warnings;
14 use Carp;
15  
16 use base qw/Tk::Frame Config::Model::Tk::AnyViewer/;
17 use subs qw/menu_struct/;
18 use Tk::ROText;
19  
20 Construct Tk::Widget 'ConfigModelCheckListViewer';
21  
22 my @fbe1 = qw/-fill both -expand 1/;
23 my @fxe1 = qw/-fill x -expand 1/;
24 my @fx = qw/-fill x/;
25  
26 sub ClassInit {
27 my ( $cw, $args ) = @_;
28  
29 # ClassInit is often used to define bindings and/or other
30 # resources shared by all instances, e.g., images.
31  
32 # cw->Advertise(name=>$widget);
33 }
34  
35 sub Populate {
36 my ( $cw, $args ) = @_;
37 my $leaf = $cw->{leaf} = delete $args->{-item}
38 || die "CheckListViewer: no -item, got ", keys %$args;
39 my $path = delete $args->{-path}
40 || die "CheckListViewer: no -path, got ", keys %$args;
41 my $cme_font = delete $args->{-font};
42  
43 my $inst = $leaf->instance;
44  
45 $cw->add_header( View => $leaf )->pack(@fx);
46  
47 my $rt = $cw->Scrolled(
48 'ROText',
49 -scrollbars => 'osoe',
50 -height => 6,
51 )->pack(@fbe1);
52 $rt->tagConfigure( 'in', -background => 'black', -foreground => 'white' );
53  
54 my %h = $leaf->get_checked_list_as_hash;
55 foreach my $c ( $leaf->get_choice ) {
56 my $tag = $h{$c} ? 'in' : 'out';
57 $rt->insert( 'end', $c . "\n", $tag );
58 }
59  
60 $cw->add_annotation($leaf)->pack(@fx);
61 $cw->add_summary($leaf)->pack(@fx);
62  
63 my ( $help_frame, $help_widget ) = $cw->add_help( "Value help" => '', 1 );
64 $help_frame->pack(@fx);
65 $cw->{value_help_widget} = $help_widget;
66 $cw->set_value_help( $leaf->get_checked_list );
67  
68 $cw->add_description($leaf)->pack(@fbe1);
69  
70 $cw->add_info_button()->pack( @fxe1, -side => 'left' );
71 $cw->add_editor_button($path)->pack( @fxe1, -side => 'right' );
72  
73 $cw->ConfigSpecs(
74 -font => [['SELF','DESCENDANTS'], 'font','Font', $cme_font ],
75  
76 #-fill => [ qw/SELF fill Fill both/],
77 #-expand => [ qw/SELF expand Expand 1/],
78 -relief => [qw/SELF relief Relief groove/],
79 -borderwidth => [qw/SELF borderwidth Borderwidth 2/],
80 DEFAULT => [qw/SELF/],
81 );
82  
83 $cw->SUPER::Populate($args);
84 }
85  
86 sub add_value_help {
87 my $cw = shift;
88  
89 my $help_frame = $cw->Frame(
90 -relief => 'groove',
91 -borderwidth => 2,
92 )->pack(@fbe1);
93 my $leaf = $cw->{leaf};
94 $help_frame->Label( -text => 'value help: ' )->pack( -side => 'left' );
95 $help_frame->Label( -textvariable => \$cw->{help} )
96 ->pack( -side => 'left', -fill => 'x', -expand => 1 );
97 }
98  
99 sub set_value_help {
100 my $cw = shift;
101 my @set = @_;
102  
103 my @help = grep {defined $_ } map { $cw->{leaf}->get_help($_) } @set ;
104  
105 $cw->update_help($cw->{value_help_widget}, join("\n\n", @help));
106 }
107  
108 sub cme_object {
109 my $cw = shift;
110 return $cw->{leaf};
111 }
112  
113 1;