[Catalyst-commits] r13993 -
CatalystX-Restarter-GTK/trunk/lib/CatalystX/Restarter
dd070 at dev.catalyst.perl.org
dd070 at dev.catalyst.perl.org
Tue Mar 29 09:25:56 GMT 2011
Author: dd070
Date: 2011-03-29 09:25:55 +0000 (Tue, 29 Mar 2011)
New Revision: 13993
Modified:
CatalystX-Restarter-GTK/trunk/lib/CatalystX/Restarter/GTK.pm
Log:
added support for tray icon
Modified: CatalystX-Restarter-GTK/trunk/lib/CatalystX/Restarter/GTK.pm
===================================================================
--- CatalystX-Restarter-GTK/trunk/lib/CatalystX/Restarter/GTK.pm 2011-03-29 09:22:50 UTC (rev 13992)
+++ CatalystX-Restarter-GTK/trunk/lib/CatalystX/Restarter/GTK.pm 2011-03-29 09:25:55 UTC (rev 13993)
@@ -11,7 +11,7 @@
use IO::Handle qw();
use namespace::autoclean;
-our $VERSION = '0.04';
+our $VERSION = '0.05';
extends 'Catalyst::Restarter';
@@ -241,22 +241,16 @@
# Read console output from forked server and send to win proc
$self->srv_reader(AnyEvent->io(
fh => $reader,
-
poll => 'r',
-
cb => sub {
-
if (my $bytes = sysread($reader, my $msg, 256, 0)) {
-
syswrite($self->parent_sock, $msg, $bytes);
}
}
));
$self->notify_win('starting');
-
$sentry->dismiss;
-
$sem->op(0, 1, 0);
}
else {
@@ -275,7 +269,6 @@
$self->start_sub->();
}
catch {
-
STDERR->print($_);
exit 1;
};
@@ -287,13 +280,9 @@
if ($self->_child) {
kill 'INT', $self->_child;
-
waitpid($self->_child, 0);
-
$self->_child(0);
-
$self->notify_win('stopped');
-
}
}
@@ -310,12 +299,17 @@
use Glib qw(TRUE FALSE);
use Carp;
+my $path = __FILE__;
+$path =~ s/[^\/]+$//;
+
my %status_msg = (
starting => { msg => 'Starting', color => Gtk2::Gdk::Color->new(0, 0, 0x55 * 257) },
started => { msg => 'Started', color => Gtk2::Gdk::Color->new(0, 0x55 * 257, 0) },
stopped => { msg => 'Stopped', color => Gtk2::Gdk::Color->new(0x55 * 257, 0, 0) },
);
+$status_msg{$_}->{icon} = $path.$_.'.png' foreach (keys %status_msg);
+
sub new {
my ($class, $app_name) = @_;
@@ -363,14 +357,42 @@
$win->add($vbox);
$win->signal_connect(delete_event => sub { Gtk2->main_quit; });
-
+ $win->signal_connect('window-state-event' => sub {
+ if (shift(@{$_[1]->new_window_state}) eq 'iconified' && $obj->{trayicon}->is_embedded) {
+ $win->hide;
+ }
+ });
+
$win->show_all;
my $buffer = Gtk2::TextBuffer->new;
+ #-- Create tray icon and menu
+ my $trayicon = Gtk2::StatusIcon->new_from_file($status_msg{stopped}->{icon});
+ $trayicon->set_visible(TRUE);
+
+ my $traymenu = Gtk2::Menu->new;
+ my $tray_mconsole = Gtk2::MenuItem->new('View Console');
+ $tray_mconsole->signal_connect('activate' => sub { $console->activate; });
+
+ my $tray_mrestart = Gtk2::MenuItem->new('Restart');
+ $tray_mrestart->signal_connect('activate' => sub { $restart->activate; });
+
+ my $mexit = Gtk2::MenuItem->new('Exit');
+ $mexit->signal_connect('activate' => sub { Gtk2->main_quit; });
+
+ $traymenu->append($tray_mconsole);
+ $traymenu->append($tray_mrestart);
+ $traymenu->append(Gtk2::SeparatorMenuItem->new);
+ $traymenu->append($mexit);
+
+ $trayicon->signal_connect('popup-menu', sub {
+ my ($ticon, $button, $time) = @_;
+ my ($x, $y, $push) = Gtk2::StatusIcon::position_menu($traymenu, $ticon);
+ $traymenu->show_all;
+ $traymenu->popup(undef, undef, sub {($x, $y,$push)}, undef, $button, $time);
+ });
+
+ $obj = { %$obj, win => $win, trayicon => $trayicon, msg_buffer => $buffer, app_name => $app_name, lbstatus => $status, bt_restart => $restart, bt_console => $console };
- $obj = { %$obj, win => $win, msg_buffer => $buffer, app_name => $app_name, lbstatus => $status,
-
- bt_restart => $restart, bt_console => $console };
-
bless $obj, $class;
}
@@ -385,7 +407,8 @@
$self->{lbstatus}->modify_fg('normal', $msg->{color});
$self->{win}->set_title($self->{app_name}.'-'.$msg->{msg});
- $self->{bt_restart}->set_sensitive($st ne 'starting');
+ $self->{trayicon}->set_from_file($msg->{icon});
+ $self->{trayicon}->set_tooltip($self->{app_name}.' ('.$msg->{msg}.')');
}
More information about the Catalyst-commits
mailing list