1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use Cwd (); |
3 | use Cwd (); |
4 | use Encode (); |
4 | use Encode (); |
|
|
5 | use File::Glob (); |
5 | |
6 | |
6 | use Gtk2 -init; |
7 | use Gtk2 -init; |
7 | use Gtk2::Gdk::Keysyms; |
8 | use Gtk2::Gdk::Keysyms; |
8 | |
9 | |
9 | use Gtk2::CV; |
10 | use Gtk2::CV; |
… | |
… | |
23 | |
24 | |
24 | use File::Spec; |
25 | use File::Spec; |
25 | |
26 | |
26 | my $mainwin; |
27 | my $mainwin; |
27 | my $viewer; |
28 | my $viewer; |
|
|
29 | my $viewer_count; |
28 | my $schnauzer; |
30 | my $schnauzer; |
29 | my $info; |
31 | my $info; |
30 | my $help; |
32 | my $help; |
31 | |
33 | |
32 | my $schnauzer_idx = 0; |
34 | my $schnauzer_idx = 0; |
… | |
… | |
35 | my $s = new Gtk2::CV::Schnauzer; |
37 | my $s = new Gtk2::CV::Schnauzer; |
36 | |
38 | |
37 | $s->signal_connect_after (key_press_event => \&std_keys); |
39 | $s->signal_connect_after (key_press_event => \&std_keys); |
38 | $s->signal_connect (activate => sub { |
40 | $s->signal_connect (activate => sub { |
39 | my $label = sprintf "%s (%d)", |
41 | my $label = sprintf "%s (%d)", |
40 | (File::Spec->splitpath ($_[1]))[2], |
42 | (Glib::filename_display_name +(File::Spec->splitpath ($_[1]))[2]), |
41 | -s $_[1]; |
43 | -s $_[1]; |
42 | $info->set_label ($label); |
44 | $info->set_label ($label); |
43 | $viewer->load_image ($_[1]); |
45 | $viewer->load_image ($_[1]) if $viewer; # TODO: error, or chose ANY viewer |
44 | }); |
46 | }); |
45 | |
47 | |
46 | Gtk2::CV::Plugin->call (new_schnauzer => $s); |
48 | Gtk2::CV::Plugin->call (new_schnauzer => $s); |
47 | |
49 | |
48 | $s |
50 | $s |
|
|
51 | } |
|
|
52 | |
|
|
53 | sub new_viewer { |
|
|
54 | my $self = new Gtk2::CV::ImageWindow; |
|
|
55 | |
|
|
56 | $viewer_count++; |
|
|
57 | |
|
|
58 | $self->set_title ("CV: Image"); |
|
|
59 | |
|
|
60 | $self->signal_connect (key_press_event => sub { |
|
|
61 | $viewer = $_[0]; |
|
|
62 | |
|
|
63 | my $key = $_[1]->keyval; |
|
|
64 | my $state = $_[1]->state; |
|
|
65 | |
|
|
66 | if ($state * "control-mask" && $key == $Gtk2::Gdk::Keysyms{c}) { |
|
|
67 | my $viewer = new_viewer (); |
|
|
68 | $viewer->set_image ($_[0]->{image}); |
|
|
69 | $viewer->show_all; |
|
|
70 | 1 |
|
|
71 | } else { |
|
|
72 | &std_keys |
|
|
73 | or $schnauzer->signal_emit (key_press_event => $_[1]) |
|
|
74 | } |
|
|
75 | }); |
|
|
76 | $self->signal_connect (delete_event => sub { $_[0]->destroy; 0 }); |
|
|
77 | $self->signal_connect (destroy => sub { |
|
|
78 | $viewer = undef if $viewer == $_[0]; |
|
|
79 | |
|
|
80 | main_quit Gtk2 unless --$viewer_count; |
|
|
81 | |
|
|
82 | 0 |
|
|
83 | }); |
|
|
84 | |
|
|
85 | $self->signal_connect (button3_press_event => sub { |
|
|
86 | $mainwin->visible |
|
|
87 | ? $mainwin->hide |
|
|
88 | : $mainwin->show_all; |
|
|
89 | |
|
|
90 | 1 |
|
|
91 | }); |
|
|
92 | |
|
|
93 | Gtk2::CV::Plugin->call (new_imagewindow => $self); |
|
|
94 | |
|
|
95 | $self |
49 | } |
96 | } |
50 | |
97 | |
51 | sub std_keys { |
98 | sub std_keys { |
52 | my $key = $_[1]->keyval; |
99 | my $key = $_[1]->keyval; |
53 | my $state = $_[1]->state; |
100 | my $state = $_[1]->state; |
54 | |
101 | |
55 | my $ctrl = $state * "control-mask"; |
102 | my $ctrl = $state * "control-mask"; |
56 | |
103 | |
57 | if ($key == $Gtk2::Gdk::Keysyms{q}) { |
104 | if ($key == $Gtk2::Gdk::Keysyms{q}) { |
58 | main_quit Gtk2; |
105 | $viewer->destroy; |
59 | } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) { |
106 | } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{v}) { |
60 | my $w = new Gtk2::Window; |
107 | my $w = new Gtk2::Window; |
61 | |
108 | |
|
|
109 | $w->set_role ("schnauzer"); |
62 | $w->set_title ("CV: Schnauzer"); |
110 | $w->set_title ("CV: Schnauzer"); |
63 | $w->add (my $s = new_schnauzer); |
111 | $w->add (my $s = new_schnauzer); |
64 | $s->set_dir (File::Spec->curdir); |
112 | $s->set_dir (File::Spec->curdir); |
65 | $s->set_geometry_hints; |
113 | $s->set_geometry_hints; |
66 | $w->show_all; |
114 | $w->show_all; |
67 | |
115 | |
68 | } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{h}) { |
116 | } elsif ($ctrl && $key == $Gtk2::Gdk::Keysyms{h}) { |
69 | unless ($help) { |
117 | unless ($help) { |
70 | require Gtk2::PodViewer; |
118 | require Gtk2::Ex::PodViewer; |
71 | |
119 | |
72 | $help = new Gtk2::Window; |
120 | $help = new Gtk2::Window; |
|
|
121 | $help->set_role ("help"); |
73 | $help->set_title ("CV: Help"); |
122 | $help->set_title ("CV: Help"); |
74 | $help->set_default_size (500, 300); |
123 | $help->set_default_size (500, 300); |
75 | $help->signal_connect (delete_event => sub { $help->hide; 1 }); |
124 | $help->signal_connect (delete_event => sub { $help->hide; 1 }); |
76 | |
125 | |
77 | $help->add (my $sw = new Gtk2::ScrolledWindow); |
126 | $help->add (my $sw = new Gtk2::ScrolledWindow); |
78 | $sw->add (my $h = new Gtk2::PodViewer); |
127 | $sw->add (my $h = new Gtk2::Ex::PodViewer); |
79 | |
128 | |
80 | #binmode DATA, ":utf8"; |
129 | #binmode DATA, ":utf8"; |
81 | $h->load_string (do { local $/; <DATA> }); |
130 | $h->load_string (do { local $/; <DATA> }); |
82 | } |
131 | } |
83 | |
132 | |
… | |
… | |
88 | |
137 | |
89 | 1 |
138 | 1 |
90 | } |
139 | } |
91 | |
140 | |
92 | { |
141 | { |
93 | $viewer = new Gtk2::CV::ImageWindow; |
142 | $viewer = new_viewer; |
94 | |
143 | $::cur_viewer = $viewer; |
95 | $viewer->set_title ("CV: Image"); |
|
|
96 | |
|
|
97 | $viewer->signal_connect (key_press_event => sub { |
|
|
98 | &std_keys |
|
|
99 | or $schnauzer->signal_emit (key_press_event => $_[1]) |
|
|
100 | }); |
|
|
101 | $viewer->signal_connect (delete_event => sub { main_quit Gtk2 }); |
|
|
102 | |
|
|
103 | $viewer->signal_connect (button3_press_event => sub { |
|
|
104 | $mainwin->visible |
|
|
105 | ? $mainwin->hide |
|
|
106 | : $mainwin->show_all; |
|
|
107 | 1 |
|
|
108 | }); |
|
|
109 | |
|
|
110 | Gtk2::CV::Plugin->call (new_imagewindow => $viewer); |
|
|
111 | |
144 | |
112 | $schnauzer = new_schnauzer; |
145 | $schnauzer = new_schnauzer; |
113 | |
146 | |
114 | $mainwin = new Gtk2::Window; |
147 | $mainwin = new Gtk2::Window; |
|
|
148 | $mainwin->set_role ("main"); |
115 | $mainwin->set_title ("CV"); |
149 | $mainwin->set_title ("CV"); |
116 | $mainwin->add (my $vbox = new Gtk2::VBox); |
150 | $mainwin->add (my $vbox = new Gtk2::VBox); |
117 | $mainwin->signal_connect (delete_event => sub { $mainwin->hide; 1 }); |
151 | $mainwin->signal_connect (delete_event => sub { $mainwin->hide; 1 }); |
118 | |
152 | |
119 | $vbox->add ($schnauzer); |
153 | $vbox->add ($schnauzer); |
… | |
… | |
127 | |
161 | |
128 | $schnauzer->set_geometry_hints; |
162 | $schnauzer->set_geometry_hints; |
129 | } |
163 | } |
130 | |
164 | |
131 | if (@ARGV) { |
165 | if (@ARGV) { |
132 | @ARGV == 1 && -d $ARGV[0] |
166 | my $show_first = sub { |
133 | ? $schnauzer->set_dir (Glib::filename_to_unicode shift) |
|
|
134 | : $schnauzer->set_paths ([map Glib::filename_to_unicode $_, @ARGV]); |
|
|
135 | $schnauzer->show_all; |
167 | $schnauzer->show_all; |
136 | $schnauzer->handle_key ($Gtk2::Gdk::Keysyms{space}, []); |
168 | $schnauzer->handle_key ($Gtk2::Gdk::Keysyms{space}, []); |
|
|
169 | $viewer->show_all; |
|
|
170 | }; |
|
|
171 | |
|
|
172 | if (@ARGV == 1 && $ARGV[0] eq "-0r") { |
|
|
173 | local $/; |
|
|
174 | $schnauzer->set_paths ([split /\x00/, <STDIN>], 1, $show_first); |
|
|
175 | } elsif (@ARGV == 1 && -d $ARGV[0]) { |
|
|
176 | $schnauzer->set_dir (shift, $show_first); |
|
|
177 | } else { |
|
|
178 | if ($ARGV[0] eq "-g") { |
|
|
179 | shift @ARGV; |
|
|
180 | @ARGV = map +(File::Glob::bsd_glob $_, File::Glob::GLOB_BRACE | File::Glob::GLOB_QUOTE), @ARGV; |
|
|
181 | } |
|
|
182 | $schnauzer->set_paths ([@ARGV], 1, $show_first); |
|
|
183 | } |
137 | } else { |
184 | } else { |
138 | $schnauzer->set_dir (File::Spec->curdir); |
185 | $schnauzer->set_dir (File::Spec->curdir, sub { |
139 | $mainwin->show_all; |
186 | $mainwin->show_all; |
140 | } |
|
|
141 | |
|
|
142 | $viewer->show_all; |
187 | $viewer->show_all; |
|
|
188 | }); |
|
|
189 | } |
143 | |
190 | |
144 | main Gtk2; |
191 | main Gtk2; |
|
|
192 | |
|
|
193 | Gtk2::CV::flush_aio; |
145 | |
194 | |
146 | __DATA__ |
195 | __DATA__ |
147 | |
196 | |
148 | =encoding utf-8 |
197 | =encoding utf-8 |
149 | |
198 | |
… | |
… | |
266 | r set scaling mode to 'nearest' (fastest) |
315 | r set scaling mode to 'nearest' (fastest) |
267 | s set scaling mode to 'bilinear' (default) |
316 | s set scaling mode to 'bilinear' (default) |
268 | shift-s set scaling mode to 'hyper' (slowest) |
317 | shift-s set scaling mode to 'hyper' (slowest) |
269 | t rotate clockwise 90° |
318 | t rotate clockwise 90° |
270 | T rotate counterclockwise° |
319 | T rotate counterclockwise° |
|
|
320 | a apply all rotations loslessly to a jpeg file (using exiftran) |
271 | ctrl-v open a new visual schnauzer window for the current dir |
321 | ctrl-v open a new visual schnauzer window for the current dir |
|
|
322 | ctrl-c clone the current image window |
272 | ctrl-e run an editor ($CV_EDITOR or "gimp") on the current image |
323 | ctrl-e run an editor ($CV_EDITOR or "gimp") on the current image |
273 | ctrl-p fire up the print dialog |
324 | ctrl-p fire up the print dialog |
274 | escape cancel a crop action |
325 | escape cancel a crop action |
275 | |
326 | |
276 | And when playing movies, these additional keys are active: |
327 | And when playing movies, these additional keys are active: |
… | |
… | |
293 | Left-clicking into the image window will let you crop the image (usually |
344 | Left-clicking into the image window will let you crop the image (usually |
294 | to zoom into large images that CV scales down). |
345 | to zoom into large images that CV scales down). |
295 | |
346 | |
296 | =head2 THE VISUAL SCHNAUZER |
347 | =head2 THE VISUAL SCHNAUZER |
297 | |
348 | |
|
|
349 | Any image-loading action in a schnauzer window acts on the |
|
|
350 | "last-recently-activated" imagewindow, which currently is simply the last |
|
|
351 | image window that received a keypress. |
|
|
352 | |
298 | You can use the following keys in the schnauzer window: |
353 | You can use the following keys in the schnauzer window: |
299 | |
354 | |
300 | ctrl-space, |
355 | ctrl-space, |
301 | space move to and display next image |
356 | space move to and display next image |
302 | ctrl-backspace, |
357 | ctrl-backspace, |
… | |
… | |
383 | =item CV_EDITOR |
438 | =item CV_EDITOR |
384 | |
439 | |
385 | The program that gets executed when the user presses C<CTRL-e> in the |
440 | The program that gets executed when the user presses C<CTRL-e> in the |
386 | Schnauzer or image window. The default is C<gimp>. |
441 | Schnauzer or image window. The default is C<gimp>. |
387 | |
442 | |
|
|
443 | =item CV_AUDIO_PLAYER |
|
|
444 | |
|
|
445 | Program used to play all sorts of audio (wav, aif, mp3, ogg...), default "play". |
|
|
446 | Will be called like C<< $CV_AUDIO_PLAYER -- <path> >>. |
|
|
447 | |
388 | =item CV_PRINT_DESTINATION |
448 | =item CV_PRINT_DESTINATION |
389 | |
449 | |
390 | The default (perl-style) destination to use in the print dialog. |
450 | The default (perl-style) destination to use in the print dialog. |
391 | |
451 | |
392 | =item CV_TRASHCAN |
452 | =item CV_TRASHCAN |