Thread Übersetzungs-GUI 2 - Mein Programm: bin am Verzweifeln (22 answers)
Opened by life_heart at 2007-06-03 14:46

life_heart
 2007-06-03 18:02
#46397 #46397
User since
2007-05-30
12 Artikel
BenutzerIn
[default_avatar]
ihr habt ja eh recht, aber da ich halt nun mal ein perl-neuling bin, habe ich nun mal schwierigkeiten in dingen, die ich leider nicht weiß, wie man sie schreibt. aber ich hab mich nun bemüht und es versucht.

ich hab das nun folgendermaßen gemacht:

Code: (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
105
106
107
108
109
110
111
112
#!/usr/bin/perl

use strict;
use warnings;
use Tk;
use Data::Dumper qw/Dumper/;
use WWW::Leo;

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')->grid(-column => 0, -row => 0);
my $Out = $nw->Text (-wrap => 'none')->grid(-column => 1, -row => 0);

# Menü
my $mbar = $nw->Menu();
$nw->configure (-menu => $mbar);
my $file = $mbar->cascade (-label => "File", -underline => 0, -tearoff => 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, -tearoff => 0);
$do->command (-label => "Translation", -command => sub {translate($In, $Out)}, -accelerator => 'Crtl-T', -underline => 0);

# Dictionary-Listbox
my $Dict = $nw->Listbox()->grid(-column => 0, -row => 1, -columnspan => 2, -sticky => 'we');
$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();
  my $leo = WWW::LEO->new();
  $leo->query();
  if ($leo->num_results) {
  print Dumper $leo->de_en();
  }else{
  print "Sorry, your query for '%s'gave no results.\n", $leo->query;}
  $Out->query('end',$leo);
}


es funktioniert zwar, aber das übersetzen in englisch funktioniert noch nicht ganz. wo ist denn da der haken?

und das kommt noch als fehlermeldung hinzu:

Code: (dl )
1
2
3
4
5
Sorry, your query for '%s'gave no results.
Use of uninitialized value in print at C:\bsp2_final.pl line 114.
Tk::Error: Can't locate auto/Tk/Text/query.al in @INC (@INC contains: C:/Perl/si
te/lib C:/Perl/lib .) at C:\bsp2_final.pl line 115
(menu invoke)
\n\n

<!--EDIT|life_heart|1180880007-->

View full thread Übersetzungs-GUI 2 - Mein Programm: bin am Verzweifeln