Thread Übersetzungs-GUI 2 - Mein Programm: bin am Verzweifeln
(22 answers)
Opened by life_heart at 2007-06-03 14:46
Das hier fügt den markierten Text an das Ende von $Out an:
Code (perl): (dl
)
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 #!/usr/bin/perl use strict; use warnings; use Tk; my $input = 'noname.pl'; # Hauptfenster my $nw = MainWindow->new(); # Titel des Hauptfensters $nw->title ('Man Machine Interfaces II - UE - BSP 2'); # Text-Widget my $In = $nw->Text (-wrap => 'none')->pack; my $Out = $nw->Text (-wrap => 'none')->pack; # Menü my $mbar = $nw->Menu(); $nw->configure (-menu => $mbar); my $file = $mbar->cascade (-label => "File", -underline => 0); $file->command (-label => "New", -command => [\&neu, "new"], -accelerator => 'Crtl-N', -underline => 0); $file->command (-label => "Open", -command => [\&open, "open"], -accelerator => 'Crtl-O', -underline => 0); $file->command (-label => "Save", -command => [\&save, "save"], -accelerator => 'Crtl-S', -underline => 0); $file->separator(); $file->command (-label => "Exit", -command => [$nw => 'destroy'], -accelerator => 'Crtl-B', -underline => 0); my $do = $mbar->cascade (-label => "Do", -underline => 0); $do->command (-label => "Translation", -command => sub {translate()}, -accelerator => 'Crtl-T', -underline => 0); # Dictionary-Listbox my $Dict = $nw->Listbox()->pack (-side => 'top', -expand => 1, -fill => 'both'); $Dict->insert("end", "the - das"); $Dict->insert("end", "sea - meer"); $Dict->insert("end", "is - ist"); $Dict->insert("end", "blue - blau"); MainLoop(); sub file { } # sub file sub neu { my $tw = $nw->Toplevel(-title => 'New'); $tw->Label(-text => "Name of the File: ")->pack(); my $in = $tw->Entry(-textvariable => \$input)->pack(); $in->bind('<Return>', [\&create, $tw]); } # sub neu # Erzeugen einer neuen Datei sub create { CORE::open (IFILE, ">> $input") or die "can't create '$input':$!\n"; close IFILE; $_[1]->destroy(); #Fenster wieder löschen } # sub create sub open { my $tw = $nw->Toplevel(-title => 'Open'); $tw->Label(-text => "Open which File: ")->pack(); my $in = $tw->Entry(-textvariable => \$input)->pack(); $in->bind('<Return>', [ \&read, $tw ]); } # sub open # Datei zum Lesen und Schreiben Öffnen sub read { CORE::open (IFILE, "< $input") or die "can't open '$input':$!\n"; while (<IFILE>) { $In->insert("end", $_); } close IFILE; $_[1]->destroy(); #Fenster wieder löschen } # sub read sub save { my $tw = $nw->Toplevel(-title => 'Save'); $tw->Label(-text => "Save : $input")->pack(); my $in=$tw->Entry(-textvariable => \$input)->pack(); print $input , "\n"; $in->bind('<Return>', [\&write, $tw]); } # sub save #Speichern der Eingabe sub write { CORE::open (IFILE, "+< $input") or die "can't open '$input':$!\n"; print IFILE $In->get('1.0', 'end');; close IFILE or die $!; $_[1]->destroy(); #Fenster löschen } # sub write sub perl { system("/usr/bin/perl $input"); } # sub perl sub translate { my $text = $In->getSelected(); $Out->insert('end',$text); } OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/) -- Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html Perl-Entwicklung: http://perl-services.de/ |