-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcombobox.pl
92 lines (74 loc) · 2.31 KB
/
combobox.pl
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
#
# Example of GtkComboBoxText, a simple, text-only combo box,
# and handling its signal.
#
# Perl version by Dave M <dave.nerd@gmail.com>
use strict;
use warnings;
use Gtk3 '-init';
use Glib 'TRUE', 'FALSE';
my $window = Gtk3::Window->new( 'toplevel' );
$window->signal_connect( destroy => sub {Gtk3::main_quit} );
$window->set_title( 'ComboBoxText Example' );
$window->set_default_size( 250, 150 );
my $box = Gtk3::Box->new( 'vertical', 5 );
$window->add( $box );
my $grid = Gtk3::Grid->new;
$box->pack_start( $grid, TRUE, TRUE, 5 );
$grid->set_column_spacing( 5 );
$grid->set_row_spacing( 5 );
$grid->set_column_homogeneous( TRUE );
my $label = Gtk3::Label->new( 'Select a number:' );
$grid->attach( $label, 0, 0, 1, 1 );
my $cb = Gtk3::ComboBoxText->new;
$grid->attach( $cb, 1, 0, 1, 1 );
$cb->signal_connect(
changed => sub {
my $text = $cb->get_active_text;
return unless ( $text );
set_infobar_text( 'changed', $text );
}
);
my $button = Gtk3::Button->new_from_stock( 'gtk-apply' );
$grid->attach( $button, 2, 0, 1, 1 );
$button->signal_connect(
clicked => sub {
my $text = $cb->get_active_text;
return unless ( $text );
set_infobar_text( 'selected', $text );
}
);
$button = Gtk3::Button->new_from_stock( 'gtk-quit' );
$grid->attach( $button, 3, 0, 1, 1 );
$button->signal_connect( clicked => sub {Gtk3::main_quit} );
my $infobar = Gtk3::InfoBar->new;
$box->pack_start( $infobar, FALSE, FALSE, 5 );
populate_box();
$window->show_all;
Gtk3->main;
sub populate_box {
for ( 1 .. 15 ) {
$cb->append_text( $_ );
}
}
sub set_infobar_text {
my ( $signal, $fluff ) = @_;
my $message = '';
if ( $signal eq 'changed' ) {
$message = "You changed the value to $fluff."
. ' Now press apply.';
} elsif ( $signal eq 'selected' ) {
$message = "You selected the value $fluff";
}
if ( !$infobar->get_content_area->get_children ) {
$infobar->get_content_area->add( Gtk3::Label->new( $message ) );
} else {
for my $c ( $infobar->get_content_area->get_children ) {
if ( $c->isa( 'Gtk3::Label' ) ) {
$c->set_text( $message );
}
}
}
$infobar->show_all;
}