#!/usr/bin/perl -w use Tk; use strict; use warnings; use Tk::Pane; use Tk::Dialog; #use TK::Font; use IPC::SysV qw(IPC_PRIVATE IPC_RMID S_IRWXU); # Globalvariablen # my $top; my $labeltext = "Guten Morgen"; my ($max_width,$max_height); my $topscrollbar; my $status = 'Status AUS'; my $id=0; my $AnzahlVar; my $mpi; my $mpiadr; my $mpitext = 'MPI-Adresse'; my @format; my @istwert; my @mem; my $textblink=0; my $idafter; my $status_Button; #-------------------------------------------------------------------------------------------------------# $top = new MainWindow; $top->geometry("630x300+100+20"); $top->protocol('WM_DELETE_WINDOW', \&ExitApplication); $top->title ("Variableneditor"); my $menframe = $top->Frame()->pack(-side => "top", -fill => "y", -expand => 0,); $top->resizable(0,0); \$status ,-command => [\&status_ein_aus])-> pack(-side => 'left'); my $bezframe =$top->Frame(-borderwidth => 5)-> pack(-fill=> 'both', -anchor => 'nw'); my $frame = $top->Scrolled('Pane', -scrollbars => 'oe'); $frame->Frame(); $frame->pack(-side => 'top', -fill=> 'both', -expand => '1', -anchor => 'nw'); my $toplevel = $top->toplevel; # get $TOP's Toplevel widget reference my $menubar = $toplevel->Menu(-type => 'menubar'); $toplevel->configure(-menu => $menubar); my $f = $menubar->Cascade(qw/-label ~Datei -tearoff 0 -menuitems/ => [ [Button => 'oeffnen ...', -command => [\&oeffnen, 'oeffnen'],-image => $toplevel->Getimage("openfile"),-compound=> "left"], [Separator => ''], [Separator => ''], [Button => 'beenden', -command => [\&ExitApplication,'beenden']], ] ); MainLoop; # ---------------------------------------------------------------------------------------------------------------------------------------------------# sub oeffnen { my $filename; my $filetypes = [ ['template-Datei', ['template*'] ] ]; my @name; my @nummer; my $i=0; my $x=0; my $zeile=2; my @fileinhalt; my $uName; my $uNummer; my $uMem; my $uFormat; my $uIstwert; my @formatart = ('DEZIMAL','REAL', 'HEX', 'BIN', 'ASCII'); my @memart = ('DWORD','DINTEGER','WORD','INTEGER','BYTE'); my $bgcolor = 0; if ($status_Button == undef) { $status_Button = $menframe-> Button (-textvariable => \$status ,-command => [\&status_ein_aus])-> pack(-side => 'left'); $mpiadr = $menframe->Label(-textvariable => \$mpitext,-width=> 30, -font => $top->Font(-family => 'Verdana',-size => 16, -weight => 'bold', -underline => 0), )-> pack(-side => 'left'); } $filename = $toplevel->getOpenFile(-defaultextension => '',-filetypes => $filetypes,-title => 'oeffnen template-dateien...'); $_ = $filename; /_(\d{1,3})$/; $mpi = $1; open(DATEI, '<', $filename) or die "Datei kann nicht geoeffnet werden: $!\n"; @fileinhalt = ; foreach (@fileinhalt) { chomp; if ($bgcolor eq 'white') { $bgcolor = 'lightgray'; } else { $bgcolor = 'white'; } $name[$i] = $frame->Label( -text => $_, -relief => 'sunken', -width => '12', -bg => $bgcolor, -borderwidth => '1', -anchor => 'e', -padx => '2', -pady => '2', -font => $top->Font(-family => 'Verdana',-size => 12, -weight => 'bold'), )->grid(-row=>$zeile, -column=>0, -padx => '2',); $nummer[$i] = $frame->Label(-text => $i, -relief => 'sunken', -width => '5', -bg => $bgcolor, -borderwidth => '1', -padx => '2', -pady => '2', -font => $top->Font(-family => 'Verdana',-size => 12, -weight => 'bold'), )->grid(-row=>$zeile, -column=>1, -padx => '2'); $mem[$i] = $frame->BrowseEntry(-relief => 'sunken', -command => [\&tausche_mem,$i], -width => '10', -bg => $bgcolor, -font => $top->Font(-family => 'Verdana',-size => 14,), )->grid(-row=>$zeile, -column=>2, -padx => '2'); $format[$i] = $frame->BrowseEntry(-relief => 'sunken', -command => [\&tausche_format,$i], -width => '9', -bg => $bgcolor, -font => $top->Font(-family => 'Verdana',-size => 14,), )->grid(-row=>$zeile, -column=>3, -padx => '2'); foreach (@memart) {$mem[$i]->insert('end', $_,);} $mem[$i]->{MY_VAR} = $memart[0]; $mem[$i]->configure(-variable => \$mem[$i]->{MY_VAR}); foreach (@formatart) {$format[$i]->insert('end', $_,);} $format[$i]->{MY_VAR} = $formatart[0]; $format[$i]->configure(-variable => \$format[$i]->{MY_VAR}); $istwert[$i] = $frame->Label(-text => '....', -relief => 'ridge', -borderwidth => '1', -width=> 20, -bg => $bgcolor, -anchor => 'w', -padx => '2', -pady => '2', -font => $top->Font(-family => 'Verdana',-size => 12, -weight => 'bold'), )->grid(-row=>$zeile, -column=>4, -padx => '2'); $zeile++; $i++; } $AnzahlVar = $i; $uName = $bezframe->Label(-text => 'Name', -width=> 4, -font => $top->Font(-family => 'Verdana',-size => 14, -weight => 'bold',-underline => 1), )->grid(-row=>1, -column=>0); $uNummer = $bezframe->Label(-text => 'Nr', -width=> 5, -font => $top->Font(-family => 'Verdana',-size => 14, -weight => 'bold',-underline => 1), )->grid(-row=>1, -column=>1); $uMem = $bezframe->Label(-text => 'Speicher', -width=> 10, -anchor => 'w', -font => $top->Font(-family => 'Verdana',-size => 14, -weight => 'bold',-underline => 1), )->grid(-row=>1, -column=>2); $uFormat = $bezframe->Label(-text => 'Format', -width=> 9, -anchor => 'w', -font => $top->Font(-family => 'Verdana',-size => 14, -weight => 'bold',-underline => 1), )->grid(-row=>1, -column=>3); $uIstwert = $bezframe->Label(-text => 'Istwert', -width=> 20, -anchor => 'w', -font => $top->Font(-family => 'Verdana',-size => 14, -weight => 'bold',-underline => 1), )->grid(-row=>1, -column=>4); $mpitext= 'MPI-Adresse: '.$mpi; $mpiadr-> update; }