| 1 | $Tk::MARC::Subfield::VERSION = '0.8'; | ||
| 2 | |||
| 3 | package Tk::MARC::Subfield; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Tk::MARC::Subfield - megawidget for editing MARC::Field subfields. | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Tk; | ||
| 12 | use Tk::MARC::Subfield; | ||
| 13 | |||
| 14 | my $mw = MainWindow->new; | ||
| 15 | $mw->MARC_Subfield(-field => '245', | ||
| 16 | -label => 'a', | ||
| 17 | -value => 'Spam: The wonders of canned luncheon meat.', | ||
| 18 | )->pack(-anchor => 'w'); | ||
| 19 | MainLoop; | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | This is a megawidget that allows editing of a MARC::Field subfield. | ||
| 24 | The widget itself does not change the MARC::Field subfield - that is | ||
| 25 | up to the widget's parent. | ||
| 26 | |||
| 27 | The widget indicates (by changing the text background color to green) | ||
| 28 | when you have changed the text. | ||
| 29 | |||
| 30 | It allows you to revert to the original text by clicking a button | ||
| 31 | (which also resets the text background to white). | ||
| 32 | |||
| 33 | It also allows you to indicate your desire to delete the subfield, also | ||
| 34 | by clicking a button (this changes the text background to red). | ||
| 35 | |||
| 36 | You will likely never use a Tk::MARC::Subfield directly - it is simply | ||
| 37 | a component of Tk::MARC::Field. | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | # Revision history for Tk::MARC::Subfield. | ||
| 42 | # ---------------------------------------- | ||
| 43 | # 0.8 January 20, 2004 | ||
| 44 | # - now uses Carp | ||
| 45 | # - croak on missing -field or missing -label | ||
| 46 | # | ||
| 47 | # 0.7 January 17, 2004 | ||
| 48 | # - renamed to Tk::MARC::Subfield (capitalized 'Subfield') | ||
| 49 | # to be consistant with Tk::MARC::Field | ||
| 50 | # | ||
| 51 | # 0.6 January 16, 2004 | ||
| 52 | # - properly handle get() for fields < '010' | ||
| 53 | # | ||
| 54 | # 0.5 January 15, 2004 | ||
| 55 | # - added get() routine | ||
| 56 | # | ||
| 57 | # 0.4 January 14, 2004 | ||
| 58 | # - first bit of POD | ||
| 59 | # | ||
| 60 | # 0.3 January 14, 2004 | ||
| 61 | # - built a couple of sample routines in pl/ | ||
| 62 | # - t/01-use.t | ||
| 63 | # | ||
| 64 | # 0.2 January 09, 2004 | ||
| 65 | # - now uses the newly-written MARC::Descriptions module | ||
| 66 | # (which is available on the CPAN) | ||
| 67 | # | ||
| 68 | # 0.1 January 06, 2004 | ||
| 69 | # - original version | ||
| 70 | |||
| 71 | use Tk::widgets; | ||
| 72 | use base qw/Tk::Frame/; | ||
| 73 | use MARC::Descriptions; | ||
| 74 | use Carp; | ||
| 75 | use strict; | ||
| 76 | |||
| 77 | Construct Tk::Widget 'MARC_Subfield'; | ||
| 78 | |||
| 79 | our ( | ||
| 80 | $TD, # MARC::Descriptions tag data | ||
| 81 | ); | ||
| 82 | |||
| 83 | sub ClassInit { | ||
| 84 | my ($class, $mw) = @_; | ||
| 85 | $TD = new MARC::Descriptions; | ||
| 86 | $class->SUPER::ClassInit($mw); | ||
| 87 | } | ||
| 88 | |||
| 89 | sub Populate { | ||
| 90 | my ($self, $args) = @_; | ||
| 91 | |||
| 92 | my $field = delete $args->{'-field'}; | ||
| 93 | croak "Missing -field" unless (defined $field); | ||
| 94 | my $label = delete $args->{'-label'}; | ||
| 95 | croak "Missing -label" unless (defined $label); | ||
| 96 | my $value = delete $args->{'-value'}; | ||
| 97 | $value = 'New subfield' unless (defined $value); | ||
| 98 | |||
| 99 | $self->SUPER::Populate($args); | ||
| 100 | $self->{"fixed_font"} = "-adobe-courier-medium-r-normal--14-100-75-75-m-60-iso8859-2"; | ||
| 101 | |||
| 102 | my $FRAME = $self->Frame()->pack(-side => 'top', | ||
| 103 | -expand => 1, | ||
| 104 | -anchor => 'nw', | ||
| 105 | -fill => 'x'); | ||
| 106 | my $LABEL = $FRAME->Label(-text => $label, | ||
| 107 | -font => $self->{"fixed_font"}, | ||
| 108 | )->pack(-side => 'left', | ||
| 109 | -fill => 'x'); | ||
| 110 | $self->{FIELD} = $field; | ||
| 111 | $self->{SF} = $label; | ||
| 112 | $self->{VALUE} = $value; | ||
| 113 | $self->{ORIGINAL_VALUE} = $value; | ||
| 114 | my $ENTRY = $FRAME->Entry(-textvariable => \$self->{VALUE}, | ||
| 115 | -width => 40, | ||
| 116 | -background => "white", | ||
| 117 | )->pack(-side => 'left', | ||
| 118 | -expand => 0, | ||
| 119 | -fill => 'x'); | ||
| 120 | $self->{DELETED} = "no"; | ||
| 121 | $ENTRY->bind("<KeyPress>", sub { if ($self->{DELETED} eq "no") | ||
| 122 | { | ||
| 123 | $ENTRY->configure(-background => "green"); | ||
| 124 | } | ||
| 125 | }); | ||
| 126 | my $B_ORIG = $FRAME->Button(-text => "O", | ||
| 127 | -font => $self->{"fixed_font"}, | ||
| 128 | -width => 1, | ||
| 129 | -height => 1, | ||
| 130 | -padx => 0, | ||
| 131 | -pady => 0, | ||
| 132 | -command => sub { | ||
| 133 | $self->{VALUE} = $self->{ORIGINAL_VALUE}; | ||
| 134 | $ENTRY->configure(-background => "white"); | ||
| 135 | $self->{DELETED} = "no"; | ||
| 136 | } | ||
| 137 | )->pack(-side => 'left'); | ||
| 138 | my $B_DEL = $FRAME->Button(-text => "X", | ||
| 139 | -font => $self->{"fixed_font"}, | ||
| 140 | -width => 1, | ||
| 141 | -height => 1, | ||
| 142 | -padx => 0, | ||
| 143 | -pady => 0, | ||
| 144 | -command => sub { | ||
| 145 | $self->{DELETED} = "yes"; | ||
| 146 | $ENTRY->configure(-background => "red"); | ||
| 147 | } | ||
| 148 | )->pack(-side => 'left'); | ||
| 149 | |||
| 150 | my $s; | ||
| 151 | $s = $TD->get($field,"subfields",$label,"description"); | ||
| 152 | my $DESCRIPTION = $FRAME->Label(-text => $s, | ||
| 153 | -font => $self->{"fixed_font"}, | ||
| 154 | -anchor => 'nw', | ||
| 155 | -justify => 'left', | ||
| 156 | )->pack(-side => 'left', | ||
| 157 | -expand => 0, | ||
| 158 | -fill => 'x'); | ||
| 159 | |||
| 160 | $self->Advertise( 'entry', $ENTRY ); | ||
| 161 | $self->Advertise( 'label', $LABEL ); | ||
| 162 | $self->ConfigSpecs( '-field' => [ 'PASSIVE', , ,'245'], | ||
| 163 | '-label' => [ 'PASSIVE', , ,'Label'], | ||
| 164 | '-value' => [ 'PASSIVE', , ,'New subfield'], | ||
| 165 | 'DEFAULT' => [$ENTRY], | ||
| 166 | ); | ||
| 167 | $self->Delegates( 'DEFAULT' => $ENTRY ); | ||
| 168 | } | ||
| 169 | |||
| 170 | sub get { | ||
| 171 | my $self = shift; | ||
| 172 | if (defined $self->{VALUE}) { | ||
| 173 | if ($self->{DELETED} eq "no") { | ||
| 174 | my $sf; | ||
| 175 | if ($self->{FIELD} lt '010') { | ||
| 176 | $sf = $self->{VALUE}; | ||
| 177 | } else { | ||
| 178 | $sf = [ $self->{SF}, $self->{VALUE} ]; | ||
| 179 | } | ||
| 180 | return $sf; | ||
| 181 | } else { | ||
| 182 | return undef; | ||
| 183 | } | ||
| 184 | } else { | ||
| 185 | return undef; | ||
| 186 | } | ||
| 187 | } | ||
| 188 | |||
| 189 | =head1 AUTHOR | ||
| 190 | |||
| 191 | David Christensen, <DChristensenSPAMLESS@westman.wave.ca> | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | =head1 COPYRIGHT AND LICENSE | ||
| 196 | |||
| 197 | Copyright 2004 by David Christensen | ||
| 198 | |||
| 199 | This library is free software; you can redistribute it and/or modify it | ||
| 200 | under the same terms as Perl itself. | ||
| 201 | |||
| 202 | =cut | ||
| 203 | |||
| 204 | 1; |