티스토리 뷰
Posted by jodrell@spod.uk.net on 2003-08-07 00:00:00
This is a short Perl script that can be used to set the desktop background in
Nautilus. To use it, paste the code into a file in ~/.gnome2/nautilus-scripts
and make it executable. Make sure you have the Gtk2-Perl libraries installed:
get them from CPAN or gtk2-perl.sf.net.
#!/usr/bin/perl use Gtk2 -init; use File::Basename qw(basename); use strict; my $gconf_path = '/desktop/gnome/background'; my $file = (split(/\n/, $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}))[0]; chomp(my $current = `gconftool-2 -g $gconf_path/picture_options`); my %options = ( 'Tiled' => 'wallpaper', 'Centered' => 'centered', 'Scaled' => 'scaled', 'Stretched' => 'stretched' ); unless (-e $file) { my $dialog = Gtk2::MessageDialog->new(undef, 'modal', 'error', 'ok', 'Error: file not found'); $dialog->signal_connect('response', sub { exit }); $dialog->run; } else { my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($file); my $x0 = $pixbuf->get_width; my $y0 = $pixbuf->get_height; my $scale_factor; if ($x0 < $y0) { $scale_factor = 90 / $y0; # portrait } else { $scale_factor = 120 / $x0; # landscape } my $preview = Gtk2::Image->new_from_pixbuf($pixbuf->scale_simple( int($x0 * $scale_factor), int($y0 * $scale_factor), 'bilinear', )); my $label = Gtk2::Label->new('Set Background:'); $label->set_alignment(0, 0); my $control = Gtk2::OptionMenu->new; my $menu = Gtk2::Menu->new; $control->set_menu($menu); my $i = 0; foreach my $option (sort keys %options) { my $item = Gtk2::MenuItem->new($option); $item->signal_connect('activate', sub { $current = $_[0]->child->get_text }); $menu->append($item); $control->set_history($i) if ($options{$option} eq $current); $i++; } my $dialog = Gtk2::Dialog->new; $dialog->set_title('Set Background'); $dialog->signal_connect('response', \&response); $dialog->set_border_width(8); $dialog->vbox->set_spacing(8); $dialog->add_buttons('gtk-cancel' => 1, 'gtk-ok' => 0); $dialog->vbox->add($preview); $dialog->vbox->add(Gtk2::Label->new(basename($file))); $dialog->vbox->add($label); $dialog->vbox->add($control); $dialog->show_all; $dialog->run; } exit; sub response { exit if ($_[1] != 0); system(sprintf( 'gconftool-2 -t string -s %s/picture_options %s &', $gconf_path, $options{$current}, )); system(sprintf( 'gconftool-2 -t string -s %s/picture_filename %s &', $gconf_path, quotemeta($file) )); exit; }
'hacking > linux&gnome' 카테고리의 다른 글
Retrieving the GNOME background from the shell (0) | 2003.08.09 |
---|---|
Changin' Splash Image (0) | 2003.08.09 |
Defining shortcuts in Metacity (0) | 2003.08.09 |
killev (0) | 2003.08.09 |
Using Evolution as default mail client with web broswers (0) | 2003.08.09 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- jQuery
- 영화
- **
- 자바스크립트
- maven
- 독후감
- Java
- ***
- Ajax
- DeveloperWorks
- docker
- JavaScript
- nodejs
- webapp
- CSS
- 장필순
- web
- Prototype
- 여행
- 자전거
- ****
- 책
- 해남
- 땅끝마을
- Dojo
- ***1/2
- HTML5
- Eclipse
- 노래
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함