通用tray.pl

Python/PHP/Perl 开发与设计
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙
送出感谢: 4 次
接收感谢: 256 次

通用tray.pl

#1

帖子 eexpress » 2011-01-13 15:43

代码: 全选

● cat tray.pl 
#!/usr/bin/perl

my $Select=$ARGV[0];
use Config::IniFiles;
my $cfg = new Config::IniFiles( -file => "$ENV{HOME}/.tray.rc" );
die "No Select Profile.\n" if(! $cfg->val($Select,'act0'));
#----------------------------------
my $st=0;
use Gtk2 "-init"; 
use Encode;
#$SIG{CHLD} = 'IGNORE';
my $status_icon = Gtk2::StatusIcon->new;
$status_icon->set_tooltip(decode("utf8",$cfg->val($Select,'tip')));
$_=$cfg->val($Select,'pic0'); print "$_\n";
$status_icon->set_from_file($cfg->val($Select,'pic0'));
$status_icon->signal_connect('button_release_event',\&click);
$status_icon->signal_connect('scroll_event',\&scroll);
$status_icon->set_visible(1);
Gtk2 -> main;
#----------------------------------
sub click{
my ($check, $event) = @_;
if($event->button eq 1 || $event->button eq 3){
        system($cfg->val($Select,"act$st"));
#        if(fork()==0){`$_`;exit;}
        $st=$st eq 0?1:0;
        $status_icon->set_from_file($cfg->val($Select,"pic$st"));
}
if($event->button eq 2){exit;}
}
#----------------------------------
sub scroll{
my ($check, $event) = @_;
if($event->direction eq 'down'){system($cfg->val($Select,'down'));}
if($event->direction eq 'up'){system($cfg->val($Select,'up'));}
}
#----------------------------------

代码: 全选

● cat .tray.rc 
[Volume]
pic0=/home/exp/bin/clip0.png
pic1=/home/exp/bin/clip1.png
act0=amixer set Master toggle
act1=amixer set Master toggle
up=amixer set Master 10%+
down=amixer set Master 10%-
tip=调整音量。滚轮调大小,点击切换静音。

[Swap_Mouse]
pic0=/home/exp/right.png
pic1=/home/exp/left.png
act0=xmodmap -e "pointer = 3 2 1"
act1=xmodmap -e "pointer = 1 2 3"
tip=切换鼠标左右手
up=

● tray.pl Volume
● tray.pl Swap_Mouse
● 鸣学
头像
tenzu
论坛版主
帖子: 36913
注册时间: 2008-11-21 20:26
送出感谢: 0
接收感谢: 21 次

Re: 通用tray.pl

#2

帖子 tenzu » 2011-01-13 15:43

又见神码 :em70
头像
pocoyo
论坛版主
帖子: 25878
注册时间: 2008-03-25 15:49
来自: 谁知道?
送出感谢: 5 次
接收感谢: 9 次
联系:

Re: 通用tray.pl

#3

帖子 pocoyo » 2011-01-13 15:47

从没看懂过 :em70
头像
leeaman
帖子: 30702
注册时间: 2007-02-02 18:14
系统: debian sid
送出感谢: 1 次
接收感谢: 23 次

Re: 通用tray.pl

#4

帖子 leeaman » 2011-01-13 16:38

占位 :em05
醉了星星,醉月亮●●●●●The Long Way To Go(*^_^*)
头像
ChenFengyuan
帖子: 770
注册时间: 2008-03-23 0:39
送出感谢: 0
接收感谢: 4 次

Re: 通用tray.pl

#5

帖子 ChenFengyuan » 2011-01-13 16:42

use Config::IniFiles;
bad ee,用模块。。。。 :em20 :em20
头像
HuntXu
论坛版主
帖子: 5776
注册时间: 2007-09-29 3:09
送出感谢: 0
接收感谢: 6 次

Re: 通用tray.pl

#6

帖子 HuntXu » 2011-01-13 22:23

ChenFengyuan 写了:use Config::IniFiles;
bad ee,用模块。。。。 :em20 :em20
这有何难?
折腾的,才ini...

[perl]#!/usr/bin/perl -w
use strict;
use Gtk2 "-init";
use Encode;

######### Configurations ###############
# functions
my %volume = (
"pic0" => "audio-volume-high",
"pic1" => "audio-volume-muted",
"act0" => "amixer set Master toggle",
"act1" => "amixer set Master toggle",
"up" => "amixer set Master 10%+",
"down" => "amixer set Master 10%-",
"tip" => "调整音量。滚轮调大小,点击切换静音。",
);

# functions list
my %functions = (
"volume" => \%volume,
);

###### End of Configurations ###########

###### Script starts here ##############

$_ = $ARGV[0];
die "No such function.\n" unless exists($functions{$_});
$_ = $functions{$_};

my %sel = %$_;
my $st = 0;

my $status_icon = Gtk2::StatusIcon->new;
$status_icon->set_tooltip(decode("utf8", $sel{"tip"}));
$status_icon->set_from_icon_name($sel{"pic0"});
$status_icon->signal_connect("button_release_event", \&click);
$status_icon->signal_connect("scroll_event", \&scroll);
$status_icon->set_visible(1);
Gtk2 -> main;
#--------------------------------------
sub click {
my ($check, $event) = @_;
if ($event->button eq 1 || $event->button eq 3) {
system($sel{"act$st"});
$st = $st eq 0?1:0;
$status_icon->set_from_icon_name($sel{"pic$st"});
}
if ($event->button eq 2) {
exit;
}
}

sub scroll {
my ($check, $event) = @_;
if ($event->direction eq "down") {
system($sel{"down"});
}
if ($event->direction eq "up") {
system($sel{"up"});
}
}
[/perl]

运行方法一样...

代码: 全选

$ ./tray.pl volume
别忘了...

代码: 全选

[hunt@psycho ~]$ O_< grep icon .gtkrc-2.0 
gtk-icon-theme-name="Nostromo"
[hunt@psycho ~]$ O_< find ~/.icons/Nostromo/ -name "audio-volume*"
/home/hunt/.icons/Nostromo/16x16/status/audio-volume-muted.png
/home/hunt/.icons/Nostromo/16x16/status/audio-volume-low.png
/home/hunt/.icons/Nostromo/16x16/status/audio-volume-medium.png
/home/hunt/.icons/Nostromo/16x16/status/audio-volume-high.png
HUNT Unfortunately No Talent...
rediscover
帖子: 3173
注册时间: 2010-01-13 23:26
送出感谢: 0
接收感谢: 12 次

Re: 通用tray.pl

#7

帖子 rediscover » 2011-01-13 22:32

前面是神码,后面是高亮神码。
Here I am.
Ubuntu 桌面培训 - 全中文官方文档,含汉化截图,提供PDF
回复

回到 “Python/Php/Perl”