~ubuntu-branches/ubuntu/maverick/perl-tk/maverick

« back to all changes in this revision

Viewing changes to examples/tkfontsel

  • Committer: Bazaar Package Importer
  • Author(s): Colin Tuckley
  • Date: 2010-05-30 09:19:40 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100530091940-wbmq9bloo92t9m6x
Tags: 1:804.029-1
* New Upstream Release (Closes: #578814).
* Added debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/perl -w
 
2
use strict;
 
3
use Tk;
 
4
use Tk::Font;
 
5
use Tk::widgets qw(BrowseEntry Text Spinbox);
 
6
my %fopt = (-family => 'fixed', -weight => 'medium',
 
7
            -slant => 'roman', -size => 12);
 
8
my $mw   = MainWindow->new();
 
9
my $font = $mw->Font(%fopt);
 
10
my $family  = $mw->BrowseEntry(-variable => \$fopt{-family},
 
11
                           -options => [sort $mw->fontFamilies()],
 
12
                           -command => [\&SetFont,$font,\%fopt]);
 
13
my $size = $mw->Spinbox(-width => 3, -textvariable => \$fopt{-size},
 
14
                        -from => 6, -to => 72,
 
15
                        -command => [\&SetFont,$font,\%fopt]);
 
16
my $weight = $mw->Optionmenu(-width => 3, -variable => \$fopt{-weight},
 
17
                        -options => [qw(medium bold)],
 
18
                        -command => [\&SetFont,$font,\%fopt]);
 
19
 
 
20
Tk::grid($mw->Label(-text => 'Family:',-justify => 'right'), $family,
 
21
         $mw->Label(-text => 'Size:',-justify => 'right'), $size,
 
22
         $mw->Label(-text => 'Weight:',-justify => 'right'), $weight,
 
23
         -sticky => 'ew',
 
24
        );
 
25
 
 
26
my $text = $mw->Scrolled(Text => -font => $font, -width => 40, -height => 20)->grid(-sticky => 'nsew', -columnspan => 6);
 
27
 
 
28
my $l = '';
 
29
for my $ch (0x20..0x7E,0xa0..0xff)
 
30
 {
 
31
  $l .= chr($ch);
 
32
  if (length($l) == 16)
 
33
   {
 
34
    $text->insert(end => "$l\n");
 
35
    $l = '';
 
36
   }
 
37
 }
 
38
 
 
39
#$text->insert('end',<<"END");
 
40
#Example Text - list
 
41
#\x{20ac}40 Only.
 
42
#END
 
43
 
 
44
MainLoop;
 
45
 
 
46
sub SetFont
 
47
{
 
48
 my ($font,$fopt) = @_;
 
49
 my @opt = %$fopt;
 
50
 print "@opt\n";
 
51
 $font->configure(%$fopt);
 
52
 @opt = $font->actual;
 
53
 print "$$font @opt\n";
 
54
}
 
55