9 Einträge, 1 Seite |
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
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::PNG;
use Tk::JPEG;
use Tk::Text;
use Tk::NoteBook;
use Tk::Pane;
use Image::Size;
use Data::Dumper;
my $mw = MainWindow->new();
my $menu = $mw->Menu(-type => 'menubar');
createMenu($menu);
$mw->configure(-menu => $menu);
$mw->bind('<Control-Key-o>', sub{openFile()});
$mw->bind('<Control-Key-s>', sub{saveDumpe()});
$mw->bind('<Control-Key-q>', sub{exit});
my $nb = $mw->NoteBook()->pack();
my $nb_image = $nb->add('img', -label => 'Image');
my $nb_text = $nb->add('dmp', -label => 'Dump');
my $txt_field = $nb_text->Scrolled('Text', -scrollbars => 'se')->pack(-expand => 1, -fill => 'both');
my $pane = $nb_image->Scrolled('Pane', -scrollbars => 'se')->pack(-expand => 1, -fill => 'both');
my $label = $pane->Label()->pack(-expand => 1, -fill => 'both');
#my $label = $nb_image->Scrolled('Canvas',-scrollregion => [0,0,0,0], -scrollbars => 'se')->pack(-expand => 1, -fill => 'both');
MainLoop;
#------------------------------------------------------------------------------#
# Subroutines #
#------------------------------------------------------------------------------#
sub createMenu{
my $menufont = '{Arial} 8 {normal}';
$menu->cascade(-label => 'File',
-underline => 0,
-font => $menufont,
);
my $menu_app = $menu->Menu(-tearoff => 0);
$menu_app->command(-label => "open...",
-command => [\&openFile],
-accelerator => 'Ctrl-O',
);
$menu_app->command(-label => 'save dump...',
-command => [\&saveDump],
-accelerator => 'Ctrl-S',
);
$menu_app->command(-label => 'close',
-command => sub{exit;},
-accelerator => 'Ctrl-Q',
);
$menu->entryconfigure('File', -menu => $menu_app);
}# createMenu
sub openFile{
my @filetypes = (['All Images', ['.GIF','.XBM','.XPM','.BMP','.JPEG','.JPG','.PNG','.PPM','.PGM']],
['GIF Images', '.GIF'],
['XBM Images', '.XBM'],
['XPM Images', '.XPM'],
['BMP Images', '.BMP'],
['JPG Images', ['.JPEG','.JPG']],
['PNG Images', '.PNG'],
['PPM/PGM Images', ['.PPM','.PGM']],);
my $file = $mw->getOpenFile(-filetypes => \@filetypes);
return unless $file;
my $photo = $mw->Photo(-file => $file);
=pod
my ($x_size, $y_size) = imgsize($file);
$label->configure(-scrollregion => [0,0,$x_size,$y_size]);
my $test = $label->cget(-scrollregion);
print Dumper($test);
$label->delete('all');
$label->createImage($x_size,-$y_size,-image => $photo);
=cut
$label->configure(-image => $photo);
my ($suffix) = $file =~ /\.(.*?)$/;
$suffix = 'JPEG' if($suffix eq 'jpg' or $suffix eq 'JPG');
my $string = $photo->data(-format => $suffix);
$txt_field->delete('0.0','end');
$txt_field->Insert($string);
}# openFile
sub saveDump{
my $file = $mw->getSaveFile();
return unless $file;
if(open(my $fh,">$file")){
print $fh $txt_field->get('0.0','end');
close $fh;
}
}# saveDump
9 Einträge, 1 Seite |