#!/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'); # 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); # Text-Widget my $In = $nw->Text (-wrap => 'none')->pack; my $Out = $nw->Text (-wrap => 'none')->pack; # 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('', [\&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('', [ \&read, $tw ]); } # sub open # Datei zum Lesen und Schreiben Öffnen sub read { CORE::open (IFILE, "< $input") or die "can't open '$input':$!\n"; while () { $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('', [\&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 { }