|< 1 2 >| | 12 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
use Tk;
$mw = MainWindow->new( );
# Create the notebook and fill the whole window
$nb = $mw->NoteBook( )->pack(-expand => 1, -fill => 'both');
# Page 1 on the notebook, with button on that page
$p1 = $nb->add('page1', -label => 'Page 1');
$p1->Label(-text => 'Seite 1!')->pack( );
# Empty page 2
$p2 = $nb->add('page2', -label => 'Page 2');
$p2->Button(-text => 'Seite 1!')->pack( );
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
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Tk;
require Tk::HList;
my $top = MainWindow->new(-title=>"FileSelector");
my $h = $top->Scrolled('HList',
-drawbranch => 1,
-separator => '/',
-indent => 15,
-command => \&show_or_hide_dir,
)
->pack(-fill => 'both',
-expand => 'y',
);
my $xpm = <<'END';
/* XPM */
static char *test[]={
"32 32 11 1",
". c None",
"# c #000000",
"h c #004000",
"g c #004040",
"f c #404000",
"e c #808080",
"i c #a0a0a4",
"c c #c0c000",
"d c #ffff00",
"b c #ffffc0",
"a c #ffffff",
"................................",
"................................",
"................................",
"................................",
".............#....###...........",
"............#a##.#aba##.........",
"...........#aaaa#aaaaaa##.......",
"..........#aaaa#aaaaaaaba##.....",
".........#aaaa#aaaaaaaaaaab##...",
"........#aaba#aaaaaaabaabaaaa##.",
".......#aaba#baaaaa#baaaaaabaaa#",
"......#aaaa#aaaaab#a##baaaaaaa#.",
".....#aaba#aacbba#aaaa##baaab#..",
"....#bbaa#abaacc#aaaaaaa##aa#...",
"...#bbbb#aaabaa#aaabaaaaaa##....",
"..#bbbb#bacaaa#aaaaaaaabaaaa##..",
".#bbbb#bbaacc#aacaaaaaaaaaaaba#.",
"#ddbb#bbbbba#aaaaccaaaaaaaaaaaa#",
"#edddfgcbbbfaacaaaaccaaaaaaaaa#e",
".#hedddfhcfabaaccaaabccaaaaaa#e.",
"...##edddhaacbbaaccbaaaccaab#i..",
".....##e#baaaccabaaccbaabaa#i...",
"......##bacbaabccbaaaccabb#e....",
"......#bbbbccaabbccaaaaab#i.....",
".....#bbbbbbbccabbaccaab#i......",
".....#ebbbbbbbbccbaabba#i.......",
"......##ebbbbbbbbccaabhe........",
"........##ebbbbbbbbbb#e.........",
"..........##ibbbbbbbhe..........",
"............##ebbbb#e...........",
"..............#hee#i............",
"................##i............."};
END
my %icons;
#$icons{"open"} = $top->Bitmap(-file => './open_folder.xbm');
#$icons{"closed"} = $top->Bitmap(-file => './folder.xbm');
$icons{"open"} = $top->Pixmap(-data => $xpm);
$icons{"closed"} = $top->Pixmap(-data => $xpm);
#show_or_hide_dir("c:\\programme");
show_or_hide_dir(@ARGV);
#show_or_hide_dir("p:");
#show_or_hide_dir("/temp");
MainLoop();
#-----------------------------------------------------------------------
sub show_or_hide_dir {
my $path = $_[0];
print "PATH:".$path;
return if (! -d $path);
if ($h->info('exists', $path)) {
my $next_entry = $h->info('next', $path);
if (!$next_entry || (index ($next_entry, "$path/") == -1)) {
$h->entryconfigure($path, '-image' => $icons{"open"});
add_dir_contents($path);
my $path1 = $path;
my $path2 = $path;
my @du = ("du", "-b", "-h", $path1, $path2);
my $dirSize = system(@du) == 0 or die "system @du failed: $?";
}
else {
$h->entryconfigure($path, '-image' => $icons{"closed"});
$h->delete('offsprings', $path);
}
}
else {
die "'$path' is not a directory\n" if (! -d $path);
$h->add($path,
-itemtype => 'imagetext',
-image => $icons{"open"},
-text => $path,
);
add_dir_contents($path);
}
}
sub add_dir_contents {
my $path = $_[0];
my $oldcursor = $top->cget('-cursor');
$top->configure(-cursor => 'watch');
$top->update();
my @files = <$path/*>;
foreach my $file (@files) {
$file =~ s|//|/|g;
#$file =~ /^\s*$/;
print "FILE:".$file."\n\n";
(my $text = $file) =~ s|^.*/||g;
if (-d $file) {
$h->add($file,
-itemtype => 'imagetext',
-image => $icons{"closed"},
-text => $text,
);
}
else {
$h->add($file,
-itemtype => 'text',
-text => $text,
);
}
}
$top->configure(-cursor => $oldcursor);
} # sub add_dir_contents
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
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Tk;
require Tk::HList;
my $top = MainWindow->new(-title=>"FileSelector");
$top->geometry("300x500");
my $h = $top->Scrolled('HList',
-drawbranch => 1,
-separator => '/',
-indent => 15,
-command => \&show_or_hide_dir,
-scrollbars => 'osoe',
)
->pack(-fill => 'both',
-expand => 'y',
);
my $xpm_p = <<'ENDE';
/* XPM */
static char *test[]={
"12 12 2 1",
". c None",
"# c #000000",
".....##.....",
".....##.....",
".....##.....",
".....##.....",
".....##.....",
"############",
"############",
".....##.....",
".....##.....",
".....##.....",
".....##.....",
".....##....."};
ENDE
my $xpm_m = <<'ENDE';
/* XPM */
static char *test[]={
"12 12 2 1",
". c None",
"# c #000000",
"............",
"............",
"............",
"............",
"............",
"############",
"############",
"............",
"............",
"............",
"............",
"............"};
ENDE
my %icons;
#$icons{"open"} = $top->Bitmap(-file => './open_folder.xbm');
#$icons{"closed"} = $top->Bitmap(-file => './folder.xbm');
#$icons{"open"} = $top->Pixmap(-data => $xpm);
#$icons{"closed"} = $top->Pixmap(-data => $xpm);
$icons{"open"} = $top->Pixmap(-data => $xpm_m);
$icons{"closed"} = $top->Pixmap(-data => $xpm_p);
#show_or_hide_dir("c:\\programme");
show_or_hide_dir(@ARGV);
#show_or_hide_dir("p:");
#show_or_hide_dir("/temp");
MainLoop();
#-----------------------------------------------------------------------
sub show_or_hide_dir {
my $path = $_[0];
print "PATH:".$path;
return if (! -d $path);
if ($h->info('exists', $path)) {
my $next_entry = $h->info('next', $path);
if (!$next_entry || (index ($next_entry, "$path/") == -1)) {
$h->entryconfigure($path, '-image' => $icons{"open"});
add_dir_contents($path);
my $path1 = $path;
my $path2 = $path;
my @du = ("du", "-b", "-h", $path1, $path2);
my $dirSize = system(@du) == 0 or die "system @du failed: $?";
}
else {
$h->entryconfigure($path, '-image' => $icons{"closed"});
$h->delete('offsprings', $path);
}
}
else {
die "'$path' is not a directory\n" if (! -d $path);
$h->add($path,
-itemtype => 'imagetext',
-image => $icons{"open"},
-text => $path,
);
add_dir_contents($path);
}
}
sub add_dir_contents {
my $path = $_[0];
my $oldcursor = $top->cget('-cursor');
$top->configure(-cursor => 'watch');
$top->update();
my @files = <$path/*>;
foreach my $file (@files) {
$file =~ s|//|/|g;
#$file =~ /^\s*$/;
print "FILE:".$file."\n\n";
(my $text = $file) =~ s|^.*/||g;
if (-d $file) {
$h->add($file,
-itemtype => 'imagetext',
-image => $icons{"closed"},
-text => $text,
);
}
else {
$h->add($file,
-itemtype => 'text',
-text => $text,
);
}
}
$top->configure(-cursor => $oldcursor);
} # sub add_dir_contents
|< 1 2 >| | 12 Einträge, 2 Seiten |