ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/bin/cv
(Generate patch)

Comparing CV/bin/cv (file contents):
Revision 1.54 by root, Fri Aug 19 00:19:52 2005 UTC vs.
Revision 1.73 by root, Thu Nov 22 08:52:57 2007 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use Cwd (); 3use Cwd ();
4use Encode (); 4use Encode ();
5use File::Glob ();
5 6
6use Gtk2 -init; 7use Gtk2 -init;
7use Gtk2::Gdk::Keysyms; 8use Gtk2::Gdk::Keysyms;
8 9
9use Gtk2::CV; 10use Gtk2::CV;
23 24
24use File::Spec; 25use File::Spec;
25 26
26my $mainwin; 27my $mainwin;
27my $viewer; 28my $viewer;
29my $viewer_count;
28my $schnauzer; 30my $schnauzer;
29my $info; 31my $info;
30my $help; 32my $help;
31 33
32my $schnauzer_idx = 0; 34my $schnauzer_idx = 0;
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 (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
53sub 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
51sub std_keys { 98sub 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
131if (@ARGV) { 165if (@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 ([map Glib::filename_to_unicode $_, split /\x00/, <STDIN>], 1, $show_first);
175 } elsif (@ARGV == 1 && -d $ARGV[0]) {
176 $schnauzer->set_dir (Glib::filename_to_unicode 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 ([map Glib::filename_to_unicode $_, @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
144main Gtk2; 191main Gtk2;
145 192
193Gtk2::CV::flush_aio;
194
146__DATA__ 195__DATA__
196
197=encoding utf-8
147 198
148=head1 NAME 199=head1 NAME
149 200
150cv - a fast gtk+ image viewer loosely modeled after XV 201cv - a fast gtk+ image viewer loosely modeled after XV
151 202
160 211
161=over 4 212=over 4
162 213
163=item * optimized directory scanning algorithm 214=item * optimized directory scanning algorithm
164 215
165The directory scanning in CV plays some tricks that - on most modern 216The directory scanning in CV uses some tricks that - on most modern
166filesystems - makes it possible to detect filetypes faster than stat()'ing 217filesystems - makes it possible to detect filetypes faster than stat()'ing
167every file. This makes CV suitable for directories with lots of files 218every file. This makes CV suitable for directories with lots of files
168(10000+). 219(10000+).
169 220
170This algorithm is quite unprecise - it doesn't make a difference between 221This algorithm is quite unprecise - it doesn't make a difference between
171files, device nodes, symlinks and the like, and filetype detection is done 222files, device nodes, symlinks and the like, and filetype detection is done
172using the file extension only. 223using the file extension only.
224
225On the positive side, it is usually many orders of magnitude faster than
226traditional scanning techniques (good for directories with 10000 or
227100000+ files).
173 228
174=item * queuing for all time-consuming background tasks 229=item * queuing for all time-consuming background tasks
175 230
176All tasks, such as unlinking files or generating thumbnails, that can be 231All tasks, such as unlinking files or generating thumbnails, that can be
177done in the background will be done so - no waiting required, even when 232done in the background will be done so - no waiting required, even when
188=item * fast image loading 243=item * fast image loading
189 244
190The time span between the user issuing a command and displaying the new 245The time span between the user issuing a command and displaying the new
191image should be as small as possible. CV uses optimized (especially 246image should be as small as possible. CV uses optimized (especially
192for JPEG) loading functions and sacrifices some quality (e.g no gamma 247for JPEG) loading functions and sacrifices some quality (e.g no gamma
193correction) to achieve this speed. 248correction, although this might change) to achieve this speed.
194 249
195=item * fast thumbnail creation 250=item * fast thumbnail creation
196 251
197Thumbnail creation is crucial for me, so it's better be fast. Thumbnail 252Thumbnail creation uses both CPU and Disk-I/O. CV interleaves both, so
253on modern CPUs, thumbnailing is usually limited by I/O speed. Thumbnail
198creation for JPEGs has been specially optimized. 254creation for JPEGs has been specially optimized and can even take
255advantage of multiple CPUs.
199 256
200=item * minimum optical clutter 257=item * minimum optical clutter
201 258
202CV has no menus or other user interface elements that take up a lot of 259CV has no menus or other user interface elements that take up a lot of
203screen space. The schnauzer windows can also be somewhat crowded. 260screen space (or are useful for beginning users). The schnauzer windows
261can also be somewhat crowded.
204 262
205The point of an image viewer is viewing images, not a nice GUI. This is 263The point of an image viewer is viewing images, not a nice GUI. This is
206similar to XV's behaviour. 264similar to XV's behaviour.
207 265
208=item * efficient (and hard to learn) user interface 266=item * efficient (and hard to learn) user interface
209 267
210CV uses key combinations. A lot. If you are an experienced XV user, you 268CV uses key combinations. A lot. If you are an experienced XV user, you
211will find most of these keys familiar. If not, CV might be hard to use at 269will find most of these keys familiar. If not, CV might be hard to use at
212first, but will be an efficient tool later. 270first, but will be an efficient tool later.
213 271
272=item * multi-window GUI
273
274CV doesn't force you to use a specific layout, instead it relies on your
275window manager, thus enabling you to chose whatever layout that suits you
276most.
277
214=item * i18n'ed filename handling throughout 278=item * i18n'ed filename handling throughout
215 279
216As long as glib can recognize your filename encoding (either UTF-8 or 280As long as glib can recognize your filename encoding (either UTF-8 or
217locale-specific, depending on your settings) and you have the relevant 281locale-specific, depending on the setting of G_BROKEN_FILENAMES) and you
218fonts, CV will display your filenames correctly. 282have the relevant fonts, CV will display your filenames correctly.
219 283
220=item * extensible through plug-ins 284=item * extensible through plug-ins
221 285
222I have weird plug-ins that access remote databases to find a 286I have weird plug-ins that access remote databases to find a
223directory. This is not likely to be of any use to other people. Likewise, 287directory. This is not likely to be of any use to other people. Likewise,
244 . enlarge the image by 10% 308 . enlarge the image by 10%
245 n reset to normal size 309 n reset to normal size
246 m maximize to screensize 310 m maximize to screensize
247 M maximize to screensize, respecting image aspect 311 M maximize to screensize, respecting image aspect
248 ctrl-m toggle maxpect-always mode 312 ctrl-m toggle maxpect-always mode
313 ctrl-sift-m toggle using current image size as max image size
249 u uncrop 314 u uncrop
250 r set scaling mode to 'nearest' (fastest) 315 r set scaling mode to 'nearest' (fastest)
251 s set scaling mode to 'bilinear' (default) 316 s set scaling mode to 'bilinear' (default)
252 shift-s set scaling mode to 'hyper' (slowest) 317 shift-s set scaling mode to 'hyper' (slowest)
253 t rotate clockwise 90° 318 t rotate clockwise 90°
254 T rotate counterclockwise° 319 T rotate counterclockwise°
320 a apply all rotations loslessly to a jpeg file (using exiftran)
255 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
256 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
257 ctrl-p fire up the print fialog 324 ctrl-p fire up the print dialog
258 escape cancel a crop action 325 escape cancel a crop action
259 326
260And when playing movies, these additional keys are active: 327And when playing movies, these additional keys are active:
261 328
262 left rewind by 10 seconds 329 left rewind by 10 seconds
277Left-clicking into the image window will let you crop the image (usually 344Left-clicking into the image window will let you crop the image (usually
278to zoom into large images that CV scales down). 345to zoom into large images that CV scales down).
279 346
280=head2 THE VISUAL SCHNAUZER 347=head2 THE VISUAL SCHNAUZER
281 348
349Any image-loading action in a schnauzer window acts on the
350"last-recently-activated" imagewindow, which currently is simply the last
351image window that received a keypress.
352
282You can use the following keys in the schnauzer window: 353You can use the following keys in the schnauzer window:
283 354
284 ctrl-space, 355 ctrl-space,
285 space move to and display next image 356 space move to and display next image
286 ctrl-backspace, 357 ctrl-backspace,
300 ctrl-g force generation of thumbnais for the selected files 371 ctrl-g force generation of thumbnais for the selected files
301 ctrl-s rescan current direcory or files updates/deletes etc. 372 ctrl-s rescan current direcory or files updates/deletes etc.
302 ctrl-u update selected (or all) icons if neccessary 373 ctrl-u update selected (or all) icons if neccessary
303 ctrl-l don't use, will become a plug-in eventually 374 ctrl-l don't use, will become a plug-in eventually
304 375
376 ^ go to parent directory (caret).
377
305 0-9, 378 0-9,
306 a-z find the first filename beginning with this letter 379 a-z find the first filename beginning with this letter
307 380
308Right-clicking into the schnauzer window displays a pop-up menu with 381Right-clicking into the schnauzer window displays a pop-up menu with
309additional actions. 382additional actions.
310 383
384=head3 SELECTION
385
386You can select entries in the Schnauzer in a variety of ways:
387
388=over 4
389
390=item Keyboard
391
392Moving the cursor with the keyboard will first deselect all files and then
393select the file you moved to.
394
395=item Clicking
396
397Clicking on an entry will select the one you clicked and deselect all
398others.
399
400=item Shift-Clicking
401
402Shift-clicking will toggle the selection on the entry under the mouse.
403
404=item Dragging
405
406Dragging will select all entries between the one selected when pushing the
407button and the one selected when releasing the button. If you move above
408or below the schnauzer area while drag-selecting, the schnauzer will move
409up/down one row twice per second. In addition, horizontal mouse movement
410acts as a kind of invisible horizontal scrollbar.
411
412=item Hint: double-click works while click-selecting
413
414You can double-click any image while click-selecting to display it
415without stopping the selection process. This will act as if you normally
416double-clicked the image to display it, and will toggle the selection
417twice, resulting in no change.
418
419=back
420
311=head1 FILES 421=head1 FILES
312 422
313When starting, CV runs the F<.cvrc> file in your F<$HOME> directory as if 423When starting, CV runs the F<.cvrc> file in your F<$HOME> directory as if
314it were a perl script. in that, you will mostly load plug-ins. 424it were a perl script. in that, you will mostly load plug-ins.
315 425
327 437
328=item CV_EDITOR 438=item CV_EDITOR
329 439
330The program that gets executed when the user presses C<CTRL-e> in the 440The program that gets executed when the user presses C<CTRL-e> in the
331Schnauzer or image window. The default is C<gimp>. 441Schnauzer or image window. The default is C<gimp>.
442
443=item CV_AUDIO_PLAYER
444
445Program used to play all sorts of audio (wav, aif, mp3, ogg...), default "play".
446Will be called like C<< $CV_AUDIO_PLAYER -- <path> >>.
332 447
333=item CV_PRINT_DESTINATION 448=item CV_PRINT_DESTINATION
334 449
335The default (perl-style) destination to use in the print dialog. 450The default (perl-style) destination to use in the print dialog.
336 451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines