Gtk2-Ex-VolumeButton
view release on metacpan or search on metacpan
lib/Gtk2/Ex/VolumeButton.pm view on Meta::CPAN
'Icon Size',
'Size of the icons',
0,
1000,
18,
[qw( readable writable )]
),
Glib::ParamSpec->string(
'position',
'Position',
'Position of the popup window',
'bottom',
[qw( readable writable )]
),
Glib::ParamSpec->boolean(
'muted',
'Muted',
'Is the volume muted?',
0,
[qw( readable writable )]
)
lib/Gtk2/Ex/VolumeButton.pm view on Meta::CPAN
my $vol = $widget->get_value();
$vol = _CLAMP( $vol, 0, 100 );
$self->{volume} = $vol;
$self->update_image($vol);
$self->signal_emit( 'volume_changed', $vol );
}
sub popup_button_press_event_cb {
my( undef, undef, $self ) = @_;
if( $self->{popup} ) {
$self->hide_scale();
return TRUE;
}
return FALSE;
}
sub show_scale {
my $self = shift;
$self->{popup} = Gtk2::Window->new('popup');
$self->{popup}->set_screen( $self->get_screen );
$self->{revert_volume} = $self->{volume};
my $frame = Gtk2::Frame->new();
$frame->set_border_width(0);
$frame->set_shadow_type('out');
$frame->show();
$self->{popup}->add($frame);
my $box = Gtk2::VBox->new( FALSE, 0 );
$box->show();
$frame->add($box);
my $adj = Gtk2::Adjustment->new( $self->{volume}, 0, 100, 5, 10, 0 );
$self->{scale} = Gtk2::VScale->new($adj);
$self->{scale}->set_draw_value(FALSE);
$self->{scale}->set_update_policy('continuous');
$self->{scale}->set_inverted(TRUE);
$self->{scale}->show();
$self->{popup}->signal_connect( 'button_press_event',
\&popup_button_press_event_cb, $self);
$self->{scale}->signal_connect( 'key_press_event', \&scale_key_press_cb,
$self );
$self->{scale}->signal_connect( 'value_changed', \&scale_value_changed_cb,
$self );
my $label = Gtk2::Label->new('+');
$label->show();
$box->pack_start( $label, FALSE, TRUE, 0 );
$label = Gtk2::Label->new('-');
$label->show();
$box->pack_end( $label, FALSE, TRUE, 0 );
$box->pack_start( $self->{scale}, TRUE, TRUE, 0 );
my $req = $self->{popup}->size_request();
my($x, $y) = $self->window->get_origin();
my $alloc = $self->allocation();
$req->width( _MAX($req->width, $alloc->width) );
$self->{scale}->set_size_request( -1, 100 );
$self->{popup}->set_size_request( $req->width, -1 );
$x += $alloc->x;
if( $self->{position} eq 'bottom' ) {
$y += $alloc->y + $alloc->height;
} else {
$y -= ($self->{popup}->get_size())[1];
}
$x = _MAX( 0, $x );
$y = _MAX( 0, $y );
$self->{popup}->move($x, $y);
$self->{popup}->show();
$self->{popup}->grab_focus();
Gtk2->grab_add( $self->{popup} );
my $grabbed = Gtk2::Gdk->pointer_grab(
$self->{popup}->window, TRUE,
[qw( button-press-mask button-release-mask pointer-motion-mask )],
undef, undef, Gtk2->get_current_event_time() );
if( $grabbed eq 'success' ) {
$grabbed = Gtk2::Gdk->keyboard_grab( $self->{popup}->window, TRUE,
Gtk2->get_current_event_time() );
$grabbed = 'success';
unless( $grabbed eq 'success' ) {
Gtk2->grab_remove( $self->{popup} );
$self->{popup}->destroy();
}
} else {
Gtk2->grab_remove( $self->{popup} );
$self->{popup}->destroy();
}
}
sub hide_scale {
my $self = shift;
if( $self->{popup} ) {
Gtk2->grab_remove( $self->{popup} );
Gtk2::Gdk->pointer_ungrab( Gtk2->get_current_event_time() );
Gtk2::Gdk->keyboard_ungrab( Gtk2->get_current_event_time() );
$self->{popup}->destroy();
}
if( $self->get_active() ) {
$self->set_active(FALSE);
}
}
sub toggle_cb {
my $self = shift;
lib/Gtk2/Ex/VolumeButton.pm view on Meta::CPAN
=head1 NAME
Gtk2::Ex::VolumeButton - widget to control volume and similar values
=head1 DESCRIPTION
Gtk2::Ex::VolumeButton is a simple Gtk2 widget based on Gtk2::ToggleButton to
control the volume and similar values. It consists of a Gtk2::ToggleButton
widget displaying an image representing the current volume. When the button is
clicked a popup window containing a Gtk2::VScale widget shows up and allows you
to change the widgets volume value. It's also possible to change the volume
using the scroll wheel over the toggle button even if the popup window isn't
shown.
This widget is modeled after the widgets use in gnome-panel, muine and
rhythmbox. Much code is stolen from the muine volume-button widget.
=head1 OBJECT HIERARCHY
Glib::Object
+----Gtk2::Object
+----Gtk2::Widget
lib/Gtk2/Ex/VolumeButton.pm view on Meta::CPAN
=item 'medium_image' (string : readable / writable)
Image to display when the volume is medium
=item 'max_image' (string : readable / writable)
Image to display when the volume is maximal
=item 'position' (string : readable / writable)
Position of the popup window relativ to the button
'top' and 'buttom' are supported
=item 'muted' (boolean : readable / writable)
Is the volume muted?
=back
=head1 SIGNALS
( run in 1.194 second using v1.01-cache-2.11-cpan-364913b4093 )