Leser: 29
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
#!/usr/bin/perl -w use strict; use Tk; use Tk::HList; use Tk::ItemStyle; use Cwd; my $mw = MainWindow->new(); $mw->geometry("400x600"); chdir ".."; my $cwd = getcwd; my $hlist = $mw->HList(-columns=>2, -command=>\&neues_verzeichnis($cwd) # die Zeile wird noch so angepasst, dass das neue Verzeichnis übergeben wird )->pack(-expand=>1, -fill=>'both'); my $red = $hlist->ItemStyle('text', -foreground=>'#800000'); &neues_verzeichnis($cwd,$hlist); Tk::MainLoop; sub neues_verzeichnis{ my @inhalt; my $e; opendir(DIR, $_[0]); while (my $tmp = readdir(DIR)) { push(@inhalt,$tmp); }; $hlist->deleteAll; foreach (sort(@inhalt)) { $e = $hlist->addchild(""); $hlist->itemCreate($e, 0, -itemtype=>'text', -text=>$_, -style=>$red ); } }
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
#!/usr/bin/perl -w use strict; use Tk; use Tk::HList; use Tk::ItemStyle; use Cwd; my $mw = MainWindow->new(); $mw->geometry("400x600"); chdir ".."; my $cwd = getcwd; my $hlist = $mw->HList(-columns=>2,-itemtype => 'text', -command=>sub{&doppelklick;} )->pack(-expand=>1, -fill=>'both'); &neues_verzeichnis($cwd); MainLoop; sub doppelklick{ my $path = join "\n", $hlist->infoSelection(); my $cwd = getcwd; chdir "$cwd/$path"; $cwd = getcwd; print "\n$cwd"; &neues_verzeichnis($cwd); } sub neues_verzeichnis{ my @inhalt; opendir(DIR, $_[0]); while (my $tmp = readdir(DIR)) { push(@inhalt,$tmp); }; closedir DIR; $hlist->deleteAll; foreach (sort(@inhalt)) { $hlist->add("$_", -text=>$_); } }
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
#!/usr/bin/perl use Tk; use Tk::LabEntry; use Tk::DirTree; use Tk::HList; use Cwd; #use pam_aba_103_17; #use pam_aba_24_10; my $mw = MainWindow->new(-title=>"PAM_ABA v1.7"); # MainWindow my $width = $mw->screenwidth; my $height = $mw->screenheight; $mw->geometry($width.'x'.$height); $mw->configure(-menu => my $menubar = $mw->Menu); # Menüleiste my $materialtyp = $menubar->cascade(-label => '~Materialtyp', -tearoff=>0); #$menubar->command(-command=>\&konvertieren, -label=>"~Konvertieren"); #$menubar->command(-command=>\&verzeichnis, -label=>"~Verzeichnis"); $menubar->command(-command=>sub{exit}, -label=>"~Beenden"); @typ = ("SHE 103", "SOL 24"); # Materialtypen $i=0; foreach $typ (@typ){ $i++; $materialtyp->radiobutton(-label=>$typ, -variable=>\$rb, -value=>$i); } $rb = 1; $frame_hintergrund = $mw->Frame(-bg=>'green')->pack(-fill=>'both', -expand=>1); $frame0 = $frame_hintergrund->Frame(-height=>30, -bg=>'blue')->pack(-side=>'top', -expand=>1, -fill=>'x', -anchor=>'n'); #chdir("../Materialverzeichnis"); $pfad_mat = getcwd(); $LE = $frame0->LabEntry(-label=>"Abaqus Materialverzeichnis", -labelPack=>[-side=>'right'], -width=>80, -text=>"$pfad_mat")->pack(-padx=>20, -pady=>5); $frame1 = $frame_hintergrund->Frame(-width=>int($width/2), -bg=> 'red') ->pack(-side=>'left', -fill=>'y',-expand=>1); $frame2 = $frame_hintergrund->Frame(-width=>int($width/2), -bg=> 'yellow') ->pack(-expand=>1, -fill=>'y', -side=>'right', -anchor=>'e'); $DIR_TREE = $frame2->Scrolled('DirTree', -scrollbars => "osoe", -width => 30, -height => 25, -exportselection => 1, -browsecmd => sub {$cwd = shift}, -command => \&callback) ->pack(-fill => "both", -expand => 1);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = tkinit();
my $parent_frame = $mw->Frame()->pack(-fill => 'both', -expand => 1,);
my $left = $parent_frame->Frame(-bg => 'red')->pack(-side => 'left', -fill => 'x', -expand => 1,);
$left->Button(-text => 'test',)->pack();
my $right = $parent_frame->Frame(-bg => 'blue')->pack(-side => 'left', -fill => 'x', -expand => 1,);
$right->Button(-text => 'test',)->pack();
$mw->MainLoop();
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
#!/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::LabEntry;
use Tk::DirTree;
use Tk::HList;
__PACKAGE__->follow_best_practice();
__PACKAGE__->mk_accessors(qw(mw graph));
our $VERSION = 0.1;
=head1 NAME
TkApp - experimental layout
=head1 SYNOPSIS
use strict;
use warnings;
my $app = TkApp->new();
$app->run();
=head1 DESCRIPTION
- menu
- entry box
- two areas with equal size
=head2 EXPORT
None by default.
=head1 METHODS
=head2 new()
Ctor. Calls _build_gui.
=cut
sub new {
my $class = shift;
my $self = bless({}, $class);
my $mw = Tk::MainWindow->new();
$self->set_mw($mw);
$self->_build_gui();
return $self;
} # /new
=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();
my %gui = ();
# -- menu
my $menuitems = [
[Cascade => "~File", -menuitems =>
[
[Button => "Some ~Method", -command => sub{
return $self->some_method();
}],
[Separator => ""],
[Button => "~Exit", -command => sub{ exit(0); }],
],
],
];
my $menu = $mw->Menu(-menuitems => $menuitems);
$mw->configure(-menu => $menu);
# define & pack your widgets here
$gui{f_selectors} = $mw->Frame(-bg => 'green')->pack(-fill => 'x');
$gui{f_selectors}->LabEntry(
-label=>"Abaqus Materialverzeichnis",
-labelPack=>[-side=>'right'], -width=>80,
-text => 'TODO: initial value',
)->pack(-padx => 20, -pady => 5);
$gui{f_row2} = $mw->Frame(
-bg => 'yellow'
)->pack(-fill => 'both', -expand => 1,);
$gui{f_left} = $gui{f_row2}->Frame(
-bg => 'red',
)->pack( -side => 'left', -fill => 'both', -expand => 1, );
$gui{f_left}->Label(-text => 'test')->pack();
$gui{f_right} = $gui{f_row2}->Frame(
-bg => 'blue',
)->pack( -side => 'right', -fill => 'both', -expand => 1, );
} # /_build_gui
=head2 run()
This actually starts the application, including the gui event loop.
=cut
sub run {
my $self = shift;
my $mw = $self->get_mw();
$mw->MainLoop();
} # /run
=head1 SEE ALSO
Inspired by a thread at L<http://www.perl-community.de>.
=head1 AUTHOR
todo
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by todo
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself, either Perl version 5.8.8 or, at your option,
any later version of Perl 5 you may have available.
=cut
1;
use strict;
use warnings;
my $app = TkApp->new();
$app->run();
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
#!/usr/bin/perl use Tk; use Tk::LabEntry; use Tk::DirTree; use Tk::HList; use Cwd; my $mw = MainWindow->new(-title=>"PAM_ABA v1.8"); # MainWindow my $width = $mw->screenwidth; my $height = $mw->screenheight; $mw->geometry($width.'x'.$height); $mw->configure(-menu => my $menubar = $mw->Menu); # Menüleiste my $materialtyp = $menubar->cascade(-label => '~Materialtyp', -tearoff=>0); $menubar->command(-command=>\&konvertieren, -label=>"~Konvertieren"); #$menubar->command(-command=>\&verzeichnis, -label=>"~Verzeichnis"); $menubar->command(-command=>sub{exit}, -label=>"~Beenden"); @typ = ("SHE 103", "SOL 24"); # Materialtypen $i=0; foreach $typ (@typ){ $i++; $materialtyp->radiobutton(-label=>$typ, -variable=>\$rb, -value=>$i, -command=>\&label_anpassen); } $rb = 1; $frame0 = $mw->Frame(-height=>30)->pack(-expand=>1, -fill=>'x', -anchor=>'n'); $cwd = getcwd; $pfad_mat = getcwd(); $label_typ = $frame0->Label(-text=>"Typ: SHE 103")->place(-x=>0, -y=>0, -relheight=>1); $entry = $frame0->Entry(-width=>120, -text=>"$pfad_mat")->place(-x=>200, -y=>0, -relwidth=>2/3, -relheight=>1); $check = $frame0->Checkbutton(-text=>"Materialverzeichnis auswaehlen", -variable=>\$cb_value)->place(-x=>1300, -y=>0, -relheight=>1); $cb_value = 1; $frame_hintergrund = $mw->Frame->place(-x=>0, -y=>30, -relheight=>110/113, -relwidth=>1); $frame1 = $frame_hintergrund->Frame(-width=>int($width/3), -bg=> 'red') ->place(-x=>0,-y=>0, -relwidth=>1/3, -relheight=>1); $frame2 = $frame_hintergrund->Frame(-width=>int($width*2/3), -bg=> 'yellow') ->pack(-expand=>1, -fill=>'y', -side=>'right', -anchor=>'e'); $DIR_TREE = $frame1->Scrolled('DirTree', -scrollbars => "osoe", -width => 30, -height => 25, -exportselection => 1, -browsecmd => sub {$pfad_mat = shift;&neues_verzeichnis($pfad_mat);}, -command => \&callback)->place(-x=>0, -y=>0, -relwidth=>1, -relheight=>1); my $hlist = $frame2->Scrolled('HList', -scrollbars=>'oe', -columns=>1,-itemtype => 'text',-separator=>"/", -selectmode=>'extended', -header=>1, -command=>sub{&doppelklick;} )->place(-x=>0, -y=>0, -relwidth=>1, -relheight=>1); $hlist->header('create',0); $hlist->header('configure',0,-text=>"PAM CRASH Materialkarte (*.mat) auswaehlen; Mehrfachauswahl moeglich"); &neues_verzeichnis($pfad_mat); MainLoop; sub konvertieren{ print "\nBlubb" x10; } sub callback{ $entry->configure(-textvariable=>$pfad_mat) if ($cb_value == 1); } sub doppelklick{ my $path = join "\n", $hlist->infoSelection(); my $pfad_mat = getcwd; chdir "$pfad_mat/$path"; $pfad_mat = getcwd; &callback; &neues_verzeichnis($pfad_mat); } sub neues_verzeichnis{ opendir(DIR, $_[0]); my @inhalt = readdir(DIR); closedir DIR; $hlist->deleteAll; foreach (sort(@inhalt)) { $hlist->add("$_", -text=>$_); } } sub label_anpassen{ $label_typ->configure(-text=>"Typ: $typ[$rb-1]"); }
1
2
3
4
5
6
$frame_hintergrund = $mw->Frame(-bg=>'green')->pack(-fill=>'both', -expand=>1);
$frame0 = $frame_hintergrund->Frame()->pack(-side=>'top', -expand=>1, -fill=>'x', -anchor=>'n');
$LE = $frame0->LabEntry()->pack();
$frame1 = $frame_hintergrund->Frame()->pack(-side=>'left', -fill=>'y',-expand=>1);
$frame2 = $frame_hintergrund->Frame()->pack(-expand=>1, -fill=>'y', -side=>'right', -anchor=>'e');