| 1 | package Tk::Multi::Any ; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use vars qw($VERSION); | ||
| 6 | |||
| 7 | $VERSION = sprintf "%d.%03d", q$Revision: 2.2 $ =~ /(\d+)\.(\d+)/; | ||
| 8 | |||
| 9 | # Items to export into callers namespace by default. Note: do not export | ||
| 10 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 11 | # Do not simply export all your public functions/methods/constants. | ||
| 12 | |||
| 13 | # Preloaded methods go here. | ||
| 14 | |||
| 15 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||
| 16 | |||
| 17 | |||
| 18 | sub print | ||
| 19 | { | ||
| 20 | my $cw= shift ; | ||
| 21 | |||
| 22 | my $popup = $cw -> Toplevel ; | ||
| 23 | $popup -> title ($cw->{'title'}.' print query') ; | ||
| 24 | $popup -> grab ; | ||
| 25 | $popup -> Label(-text => 'modify print command as needed :') -> pack ; | ||
| 26 | my $pentry = $popup -> Entry(-textvariable => $cw->{_printCmdRef}) | ||
| 27 | -> pack(-fill => 'x') ; | ||
| 28 | $popup -> Label(-text => 'print on file :') -> pack ; | ||
| 29 | my $fentry = $popup -> Entry(-textvariable => \$cw->{_printFile}, | ||
| 30 | -state => 'disabled' ) ; | ||
| 31 | |||
| 32 | $popup -> Checkbutton | ||
| 33 | ( | ||
| 34 | -text => 'print to file', | ||
| 35 | -variable => \$cw->{_printToFile}, | ||
| 36 | -command => sub | ||
| 37 | { | ||
| 38 | if ($cw->{_printToFile}) | ||
| 39 | { | ||
| 40 | $fentry->configure(-state => 'normal'); | ||
| 41 | $pentry->configure(-state => 'disabled'); | ||
| 42 | } | ||
| 43 | else | ||
| 44 | { | ||
| 45 | $pentry->configure(-state => 'normal'); | ||
| 46 | $fentry->configure(-state => 'disabled'); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | ) -> pack ; | ||
| 50 | |||
| 51 | $fentry -> pack(-fill => 'x') ; | ||
| 52 | |||
| 53 | my $f = $popup -> Frame -> pack(-fill => 'x') ; | ||
| 54 | $f -> Button (-text => 'print', | ||
| 55 | -command => sub { | ||
| 56 | $cw -> doPrint(); | ||
| 57 | $popup -> destroy ; | ||
| 58 | }) | ||
| 59 | -> pack (-side => 'left') ; | ||
| 60 | $f -> Button (-text => 'default', | ||
| 61 | -command => sub {$cw->resetPrintCmd();}) | ||
| 62 | -> pack (-side => 'left') ; | ||
| 63 | $f -> Button (-text => 'cancel', -command => sub {$popup -> destroy ;}) | ||
| 64 | -> pack (-side => 'right') ; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub doPrint | ||
| 68 | { | ||
| 69 | my $cw= shift ; | ||
| 70 | |||
| 71 | if ($cw->{_printToFile}) | ||
| 72 | { | ||
| 73 | open(POUT,'>'.$cw->{_printFile}) | ||
| 74 | or die "Can't open file $cw->{_printFile}$!\n"; | ||
| 75 | print POUT $cw->printableDump() ; | ||
| 76 | close POUT or die "print command failed: $!\n"; | ||
| 77 | } | ||
| 78 | else | ||
| 79 | { | ||
| 80 | my $ref = $cw->{_printCmdRef}; | ||
| 81 | open(POUT,'|'.$$ref) or die "Can't open print pipe $!\n"; | ||
| 82 | print POUT $cw->printableDump() ; | ||
| 83 | close POUT or die "print command failed: $!\n"; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | sub setPrintCmd | ||
| 89 | { | ||
| 90 | my $cw= shift ; | ||
| 91 | my $ref = $cw->{_printCmdRef} ; | ||
| 92 | $$ref = shift ; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub normalize | ||
| 96 | { | ||
| 97 | my ($cw) = shift; | ||
| 98 | |||
| 99 | my $href ; | ||
| 100 | if (@_ == 1 ) | ||
| 101 | { | ||
| 102 | $href = shift; | ||
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | my %h = @_ ; | ||
| 107 | $href = \%h ; | ||
| 108 | } | ||
| 109 | |||
| 110 | # add '-' to keys if necessary | ||
| 111 | map { $href->{'-'.$_} = delete $href->{$_} unless /^-/ } keys %$href ; | ||
| 112 | |||
| 113 | return %$href ; | ||
| 114 | } | ||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | 1; | ||
| 119 | __END__ |