Leser: 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
#!/usr/bin/perl package TkApp; use base qw(Class::Accessor); use strict; use warnings; use FileHandle; use Data::Dumper qw/Dumper/; use Date::Format; use Tk; use Tk::Pane; use Tk::DHList; use DBI; use Config::Auto; use SQL::Abstract; __PACKAGE__->follow_best_practice(); __PACKAGE__->mk_accessors(qw(mw cfg dbh left right)); our $VERSION = 0.1; =head1 NAME TkApp - Demonstration of the export functionality of a canvas. Allows for different export formats than ps via L<PostScript::Convert>. =head1 SYNOPSIS use strict; use warnings; my $app = TkApp->new(); $app->run(); =head1 DESCRIPTION Display segments of two languages side by side and allow alignment of matching segments. The left side will be called source language (SL), the right side target language (TL). The following alignments are allowed: =over =item * 1:1 - one segment in the source language corresponds to exactely one segment in the target language. =item * 1:n - one segment of the target language corresponds to (one or) more than one segment in the target language. =item * n:1 - n segments in the source language correspond to exactely one segment in the target language. =back =head1 METHODS =head2 new() Ctor. Calls _build_gui and _init(). =cut sub new { my $class = shift; my %args = @_; my $self = bless({}, $class); $self->_init(\%args); $self->_build_gui(); return $self; } # /new =head2 _init( \%args ) Read config files, set up database connection etc. Private method. Don't call it directly, as this will be done by new(). =cut sub _init { my $self = shift; # -- MainWindow my $mw = Tk::MainWindow->new( -width => 1024, -height => 640, ); $mw->packPropagate(0); $self->set_mw($mw); } # /_init =head2 _build_gui() Build GUI. Set up widgets etc. Positioning is done here, too. Private method. Don't call it directly, as this will be done by new(). =cut sub _build_gui { my $self = shift; my $mw = $self->get_mw(); # define & pack your widgets here my $alignment_frame = $mw->Frame()->pack(-fill => 'both', -expand => 1,); my $left = $alignment_frame->Scrolled('DHList', -scrollbars => 'e', -cursor => 'right_ptr', -relief => 'sunken', -borderwidth => '2', -width => '10', # columns -height => '15', # lines -background => 'orange', -selectmode => 'extended', -viewtype => 'withdata', -databackground => 'skyblue', -numeric_primary_sort => '0', -numeric_secondary_sort => '1', )->pack(-side => 'left', -fill => 'both', -expand => 1,); $self->set_left($left); my $middle = $alignment_frame->Scrolled('Canvas', -bg => 'yellow',-width => '100', -scrollbars => 'e', )->pack(-side => 'left',-fill => 'both'); my $right = $alignment_frame->Scrolled('DHList', -scrollbars => 'e', -cursor => 'right_ptr', -relief => 'sunken', -borderwidth => '2', -width => '10', # columns -height => '15', # lines -background => 'orange', -selectmode => 'extended', -viewtype => 'withdata', -databackground => 'skyblue', -numeric_primary_sort => '0', -numeric_secondary_sort => '1', )->pack(-side => 'left', -fill => 'both', -expand => 1,); $self->set_right($right); my $buttons = $mw->Frame()->pack(-side => 'left', -fill => 'x', -expand => 1,); $buttons->Button(-text => 'align', -command => sub{ print "TODO...\n"; })->pack(); } # /_build_gui =head2 run() This actually starts the application, including the gui event loop. Fills in some data for testing purposes. =cut sub run { my $self = shift; my $mw = $self->get_mw(); # fill gui with samle data my @source_segments = ( {segment_id => 1, segment => 'Einstellungen'}, {segment_id => 2, segment => 'Peter geht nach Hause.'}, {segment_id => 3, segment => 'Schalten Sie Ihren Computer aus und das Gehirn ein.'}, ); my $left = $self->get_left(); foreach my $record ( @source_segments ) { $left->add($record->{segment_id}, -data => $record->{segment},); } my @target_segments = ( {segment_id => 30, segment => 'Settings'}, {segment_id => 31, segment => 'Peter is going home.'}, {segment_id => 32, segment => 'Turn off your computer.'}, {segment_id => 33, segment => 'Then use your brain.'}, ); my $right = $self->get_right(); foreach my $record ( @target_segments ) { $right->add($record->{segment_id}, -data => $record->{segment},); } $mw->MainLoop(); } # /run =head1 SEE ALSO L<Tk::Canvas>, L<Tk::DHList>. =cut 1; use strict; use warnings; use FindBin qw/$Bin/; my $app = TkApp->new(); $app->run();