Add support for libnotify notifications.
This commit is contained in:
parent
5d2fd17715
commit
99845955b3
2 changed files with 48 additions and 13 deletions
5
Build.PL
5
Build.PL
|
@ -23,8 +23,9 @@ my $build = Module::Build->new(
|
||||||
'Test::More' => '0.10',
|
'Test::More' => '0.10',
|
||||||
},
|
},
|
||||||
recommends => {
|
recommends => {
|
||||||
'Growl::GNTP' => '0.15',
|
'Growl::GNTP' => '0.15',
|
||||||
'Wx' => '0.9901',
|
'Gtk2::Notify' => '0.05',
|
||||||
|
'Wx' => '0.9901',
|
||||||
},
|
},
|
||||||
script_files => ['slic3r.pl'],
|
script_files => ['slic3r.pl'],
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,13 +37,7 @@ sub OnInit {
|
||||||
$self->SetAppName('Slic3r');
|
$self->SetAppName('Slic3r');
|
||||||
Slic3r::debugf "wxWidgets version %s\n", &Wx::wxVERSION_STRING;
|
Slic3r::debugf "wxWidgets version %s\n", &Wx::wxVERSION_STRING;
|
||||||
|
|
||||||
if (eval "use Growl::GNTP; 1") {
|
$self->{notifier} = Slic3r::GUI::Notifier->new;
|
||||||
# register growl notifications
|
|
||||||
eval {
|
|
||||||
$self->{growler} = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => "$Slic3r::var/Slic3r.png");
|
|
||||||
$self->{growler}->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
# locate or create data directory
|
# locate or create data directory
|
||||||
$datadir = Wx::StandardPaths::Get->GetUserDataDir;
|
$datadir = Wx::StandardPaths::Get->GetUserDataDir;
|
||||||
|
@ -184,10 +178,7 @@ sub notify {
|
||||||
my $frame = $self->GetTopWindow;
|
my $frame = $self->GetTopWindow;
|
||||||
$frame->RequestUserAttention unless ($frame->IsActive);
|
$frame->RequestUserAttention unless ($frame->IsActive);
|
||||||
|
|
||||||
eval {
|
$self->{notifier}->notify($message);
|
||||||
$self->{growler}->notify(Event => 'SKEIN_DONE', Title => 'Slicing Done!', Message => $message)
|
|
||||||
if $self->{growler};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
package Slic3r::GUI::ProgressStatusBar;
|
package Slic3r::GUI::ProgressStatusBar;
|
||||||
|
@ -328,4 +319,47 @@ sub IsBusy {
|
||||||
return $self->{_busy};
|
return $self->{_busy};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package Slic3r::GUI::Notifier;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my $class = shift;
|
||||||
|
my $self;
|
||||||
|
|
||||||
|
$self->{icon} = "$Slic3r::var/Slic3r.png";
|
||||||
|
|
||||||
|
if (eval 'use Growl::GNTP; 1') {
|
||||||
|
# register with growl
|
||||||
|
eval {
|
||||||
|
$self->{growler} = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => $self->{icon});
|
||||||
|
$self->{growler}->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (eval 'use Gtk2::Notify; 1') {
|
||||||
|
# register with libnotify
|
||||||
|
eval {
|
||||||
|
Gtk2::Notify->init('Slic3r');
|
||||||
|
$self->{libnotify} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub notify {
|
||||||
|
my ($self, $message) = @_;
|
||||||
|
|
||||||
|
my $title = 'Slicing Done!';
|
||||||
|
|
||||||
|
|
||||||
|
eval {
|
||||||
|
$self->{growler}->notify(Event => 'SKEIN_DONE', Title => $title, Message => $message)
|
||||||
|
if $self->{growler};
|
||||||
|
};
|
||||||
|
eval {
|
||||||
|
Gtk2::Notify->new($title, $message, $self->{icon})->show if $self->{libnotify};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue