Re: massrotate works!



* Alexy Khrabrov <list+gtk2perl setup org> [2004-05-22 19:26]:
The script is attached.

You can massively pare down the init code's size by using the
right widget for the job. Instead of manually creating buttons
from manually requested stock images, you should just use a
toolbar. That brings your roughly 35 lines down to a simple

  my $hbox = Gtk2::Toolbar->new();
  $hbox->insert_stock('gtk-go-back', 'Next image', undef, \&prev_pic, undef, -1);
  $hbox->insert_stock('gtk-go-forward', 'Previous image', undef, \&next_pic, undef, -1);
  $hbox->insert_stock('gtk-undo', 'Rotate left', undef, \&rot_left, undef, -1);
  $hbox->insert_stock('gtk-redo', 'Rotate right', undef, \&rot_right, undef, -1);
  $hbox->insert_stock('gtk-save', 'Save image', undef, \&save_pic, undef, -1);
  $hbox->insert_stock('gtk-quit', 'Quit', undef, \&quit, undef, -1);

There is also a lot of duplicate code for a script this small.
Your prev_pic()/next_pic() could be conflated into a single sub
which could differentiate the direction using the $userdata
passed to. Same for rot_left()/rot_right()

For del_temp(), it would be better if you push()ed your
temporaries onto a global array, then just ``unlink @temp;''
instead of trying to guess filenames.

But since you're not trying to cache images, why keep the
temporaries around at all? Always have just one single temporary
file -- you can use the File::Temp module to get a unique
filename.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]