~ubuntu-branches/ubuntu/trusty/horae/trusty

« back to all changes in this revision

Viewing changes to 0CPAN/Tk-HistEntry-0.42/examples/1.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/local/bin/perl -w
2
 
# -*- perl -*-
3
 
 
4
 
#
5
 
# $Id: 1.pl,v 1.8 1998/08/28 00:41:44 eserte Exp $
6
 
# Author: Slaven Rezic
7
 
#
8
 
# Copyright (C) 1997,1998 Slaven Rezic. All rights reserved.
9
 
# This program is free software; you can redistribute it and/or
10
 
# modify it under the same terms as Perl itself.
11
 
#
12
 
# Mail: eserte@cs.tu-berlin.de
13
 
# WWW:  http://user.cs.tu-berlin.de/~eserte/
14
 
#
15
 
 
16
 
use Tk;
17
 
use Tk::HistEntry;
18
 
use strict;
19
 
 
20
 
my $top = new MainWindow;
21
 
 
22
 
my($foo, $bla, $blubber);
23
 
 
24
 
my $f = $top->Frame->grid(-row => 0, -column => 0,  -sticky => 'n');
25
 
my $lb = $top->Scrolled('Listbox', -scrollbars => 'osoe'
26
 
                       )->grid(-row => 0, -column => 1);
27
 
$f->Label(-text => 'HistEntry')->pack;
28
 
my $b = $f->HistEntry(-textvariable => \$foo)->pack;
29
 
my $bb = $f->Button(-text => 'Add current',
30
 
                    -command => sub {
31
 
                        return unless $foo;
32
 
                        $b->historyAdd($foo);
33
 
                        $lb->delete(0, 'end');
34
 
                        foreach ($b->history) {
35
 
                            $lb->insert('end', $_);
36
 
                        }
37
 
                        $lb->see('end');
38
 
                        $foo = '';
39
 
                    })->pack;
40
 
$f->Button(-text => 'Replace history',
41
 
           -command => sub {
42
 
               $b->history([keys %ENV]);
43
 
           }
44
 
          )->pack;
45
 
$b->bind('<Return>' => sub { $bb->invoke });
46
 
 
47
 
my $f2 = $top->Frame->grid(-row => 1, -column => 0, -sticky => 'n');
48
 
my $lb2 = $top->Scrolled('Listbox', -scrollbars => 'osoe'
49
 
                        )->grid(-row => 1, -column => 1);
50
 
$f2->Label(-text => 'HistEntry with invoke, limit ...')->pack;
51
 
my $b2;
52
 
$b2 = $f2->HistEntry(-textvariable => \$bla,
53
 
                     -match => 1,
54
 
                     -label => 'Test label',
55
 
                     -labelPack => [-side => 'left'],
56
 
                     -width => 10,
57
 
                     -bell => 0,
58
 
                     -dup => 0,
59
 
                     -limit => 6,
60
 
                     -command => sub {
61
 
                         my $w = shift;
62
 
                         # automatic historyAdd
63
 
                         $lb2->delete(0, 'end');
64
 
                         foreach ($b2->history) {
65
 
                             $lb2->insert('end', $_);
66
 
                         }
67
 
                         $lb2->see('end');
68
 
                     })->pack;
69
 
 
70
 
#XXX$b2->configure(-match => 1);#XXX
71
 
$f2->Button(-text => 'Add current',
72
 
            -command => sub { $b2->invoke })->pack;
73
 
 
74
 
my $f3 = $top->Frame->grid(-row => 2, -column => 0, -sticky => 'n');
75
 
my $lb3 = $top->Scrolled('Listbox', -scrollbars => 'osoe'
76
 
                        )->grid(-row => 2, -column => 1);
77
 
$f3->Label(-text => 'SimpleHistEntry')->pack;
78
 
my $b3 = $f3->SimpleHistEntry(-textvariable => \$blubber,
79
 
                              -command => sub {
80
 
                                  my($w, $line, $added) = @_;
81
 
                                  if ($added) {
82
 
                                      $lb3->insert('end', $line);
83
 
                                      $lb3->see('end');
84
 
                                  }
85
 
                                  $blubber = '';
86
 
                              })->pack;
87
 
$f3->Button(-text => 'Add current',
88
 
            -command => sub { $b3->invoke })->pack;
89
 
 
90
 
# # Autodestroy
91
 
# my $seconds = 60;
92
 
# my $autodestroy_text = "Autodestroy in " . $seconds . "s\n";
93
 
# $top->Label(-textvariable => \$autodestroy_text,
94
 
#          )->grid(-row => 99, -column => 0, -columnspan => 2);
95
 
# $top->repeat(1000, sub { if ($seconds <= 0) { $top->destroy }
96
 
#                        $seconds--;
97
 
#                        $autodestroy_text = "Autodestroy in " . $seconds
98
 
#                          . "s\n";
99
 
#                    });
100
 
 
101
 
$top->Button(-text => 'Exit',
102
 
             -command => sub { $top->destroy },
103
 
            )->grid(-row => 99, -column => 0, -columnspan => 2);
104
 
 
105
 
MainLoop;
106