view release on metacpan or search on metacpan
devel/cellview.pl view on Meta::CPAN
my $button = Gtk2::Button->new_with_label ('Reorder Down');
$button->signal_connect
(clicked => sub {
my $len = $model->iter_n_children (undef);
my $end = $len - 1;
$model->reorder (undef, $end, 0 .. $end-1); # rotate
});
$left_vbox->pack_start ($button, 0,0,0);
}
$menu->popup (undef, undef, undef, undef, 0, 0);
$toplevel->show_all;
Gtk2->main;
exit 0;
devel/junk/ArrayMenu.pm view on Meta::CPAN
Gtk2::Ex::ArrayMenu -- menu of items from an array
=for test_synopsis my ($item)
=head1 SYNOPSIS
use Gtk2::Ex::ArrayMenu;
my $menu = Gtk2::Ex::ArrayMenu->new (array => ['One', 'Two']);
# standalone popup
$menu->popup;
# or as a submenu
$item->set_submenu ($menu);
=head1 WIDGET HIERARCHY
C<Gtk2::Ex::ArrayMenu> is a subclass of C<Gtk2::Menu>.
Gtk2::Widget
Gtk2::Container
devel/junk/t-arraymenu.pl view on Meta::CPAN
my $menu = Gtk2::Ex::ArrayMenu->new (array => ['<s>AA</s>',
'B_BB',
'C_C'],
name_proc => \&my_name,
use_mnemonic => 1,
);
$menu->signal_connect (activate => \&my_activate);
$menu->show;
$menu->popup (undef, undef, undef, undef, 0, 0);
Gtk2->main();
exit 0;
devel/run.pl view on Meta::CPAN
{
my $combobox = Gtk2::ComboBox->new_with_model ($treestore);
$combobox->set (add_tearoffs => 1);
$left_vbox->pack_start ($combobox, 0,0,0);
my $renderer = Gtk2::CellRendererText->new;
$renderer->set (xalign => 1); # right align
$combobox->pack_start ($renderer, 1);
$combobox->add_attribute ($renderer, text => 0);
}
$menuview->popup (undef, undef, undef, undef, 0, 0);
print "$progname: children ",$menuview->get_children,"\n";
$toplevel->show_all;
Gtk2->main;
exit 0;
#------------------------------------------------------------------------------
# return a new Gtk2::TreeStore which is a copy of the $model contents
devel/screenshot.pl view on Meta::CPAN
# You should have received a copy of the GNU General Public License along
# with Gtk2-Ex-MenuView. If not, see <http://www.gnu.org/licenses/>.
# Usage: perl screenshot.pl [outputfile.png]
#
# Popup a MenuView and write it to the given output file in PNG format.
# The default output file is /tmp/screenshot.png
#
# Must manually wave the mouse over the submenu to make it display. Then
# there's some weirdness needing $submenu->popup before its $submenu->window
# is set to get its root position ...
use 5.010;
use strict;
use warnings;
use File::Basename;
use FindBin;
use POSIX;
use Gtk2 1.220 '-init';
use Gtk2::Ex::MenuView;
devel/screenshot.pl view on Meta::CPAN
my $menuview = Gtk2::Ex::MenuView->new (model => $treestore);
$menuview->signal_connect (item_create_or_update => \&do_item_create_or_update);
sub do_item_create_or_update {
my ($menuview, $item, $treestore, $path, $iter) = @_;
return Gtk2::MenuItem->new_with_label ($treestore->get_value ($iter, 0));
}
$toplevel->signal_connect
(map_event => sub {
$menuview->popup (undef, undef,
\&position_in_toplevel, undef,
1, 0);
return Gtk2::EVENT_PROPAGATE;
});
sub position_in_toplevel {
my ($x, $y) = Gtk2::Ex::WidgetBits::get_root_position($toplevel);
$x += 10;
$y += 10;
print "popup position $x,$y\n";
return ($x, $y);
}
$menuview->signal_connect
(map_event => sub {
Glib::Timeout->add (3000, \&screenshot);
return Gtk2::EVENT_PROPAGATE;
});
sub screenshot {
devel/screenshot.pl view on Meta::CPAN
# system "convert -crop 27,65,115,116 /tmp/screenshot.xwd /tmp/screenshot.png";
my ($x, $y) = Gtk2::Ex::WidgetBits::get_root_position ($toplevel);
my ($mx, $my) = Gtk2::Ex::WidgetBits::get_root_position ($menuview);
print "menuview at $mx,$my\n";
my ($mw, $mh) = $menuview->window->get_size;
my $rx = $mx + $mw;
my $ry = $my + $mh;
my $submenu = $menuview->item_at_indices(2)->get_submenu;
$submenu->popup (undef,undef,undef,undef,1,0);
my $window = $submenu->window;
{ my ($sx, $sy) = Gtk2::Ex::WidgetBits::get_root_position ($submenu);
print "submenu at ",($sx//'undef'),",",($sy//'undef'),
" ",($window//'nowin'),"\n"; }
my $req = $submenu->size_request;
$rx += $req->width;
$rx += 8;
$ry += 10;
my $width = $rx - $x;
devel/screenshot.pl view on Meta::CPAN
# $height -= $y;
# $height += $menuview->allocation->height + 10;
#
# print "$x,$y ${width}x$height\n";
# Glib::Timeout->add
# (1000,
# sub {
# my $item = $menuview->item_at_indices(2);
# print "item 2: $item ",$item->get_child->get_text, "\n";
# # $item->get_submenu->popup ($menuview, $item, undef, undef, 0, 0);
# # $item->activate;
#
# Gtk2::Ex::WidgetBits::warp_pointer ($item->get_child, 200, 200);
#
# # my ($x, $y) = Gtk2::Ex::WidgetBits::get_root_position($menuview);
# # print "menu position $x,$y\n";
# # ($x, $y) = Gtk2::Ex::WidgetBits::get_root_position($item);
# # print "item position $x,$y\n";
# # print "item alloc ",$item->get_child->allocation->x,",",$item->get_child->allocation->y,"\n";
# # $x += 40;
examples/builder.pl view on Meta::CPAN
<signal name="item-create-or-update" handler="do_item_create_or_update"/>
<signal name="activate" handler="do_activate"/>
</object>
<object class="GtkWindow" id="toplevel">
<property name="type">toplevel</property>
<signal name="destroy" handler="do_quit"/>
<child>
<object class="GtkMenuBar" id="menubar">
<child>
<object class="GtkMenuItem" id="popup_item">
<property name="submenu">menu</property>
<child>
<object class="GtkLabel" id="popup_label">
<property name="label">Click to Popup</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
HERE
examples/checkitem.pl view on Meta::CPAN
my $vbox = Gtk2::VBox->new (0, 0);
$toplevel->add ($vbox);
#------------------------------------------------------------------------------
# menubar popping up a MenuView
my $menubar = Gtk2::MenuBar->new;
$vbox->pack_start ($menubar, 0,0,0);
my $baritem = Gtk2::MenuItem->new_with_label ('Click to popup menu');
$menubar->add ($baritem);
my $menuview = Gtk2::Ex::MenuView->new (model => $liststore);
$baritem->set_submenu ($menuview);
$menuview->signal_connect (item_create_or_update => \&my_item_create_or_update);
$menuview->signal_connect (activate => \&my_activate);
sub my_item_create_or_update {
my ($menuview, $item, $model, $path, $iter) = @_;
$item ||= Gtk2::CheckMenuItem->new_with_label ('');
examples/radiogroup.pl view on Meta::CPAN
use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::MenuView;
my $toplevel = Gtk2::Window->new('toplevel');
$toplevel->signal_connect (destroy => sub { Gtk2->main_quit });
my $label = Gtk2::Label->new ("Press mouse button\nto popup menu");
$toplevel->add ($label);
my $liststore = Gtk2::ListStore->new ('Glib::String');
foreach my $str ('Choice One',
'Choice Two',
'Choice Three') {
$liststore->set ($liststore->append, 0 => $str);
}
my $menuview = Gtk2::Ex::MenuView->new (model => $liststore);
examples/radiogroup.pl view on Meta::CPAN
my ($menuview, $item, $model, $path, $iter) = @_;
if ($item->get_active) {
print $model->get($iter,0), " is now active\n";
}
}
$toplevel->add_events ('button-press-mask');
$toplevel->signal_connect (button_press_event => \&my_button_event);
sub my_button_event {
my ($toplevel, $event) = @_;
$menuview->popup (undef, undef, undef, undef, $event->button, $event->time);
}
$toplevel->show_all;
Gtk2->main;
exit 0;
examples/simple.pl view on Meta::CPAN
# You should have received a copy of the GNU General Public License along
# with Gtk2-Ex-MenuView. If not, see <http://www.gnu.org/licenses/>.
# This is pretty much the simplest program that displays a MenuView. The
# model is a ListStore and the item-create-or-update handler shows column 0
# from it.
#
# The menu is popped-up from a mouse button press. Generally a menu is
# handled in one of two ways, either the submenu of a MenuItem in a MenuBar
# etc, or an explicit popup from an event like below.
use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::MenuView;
my $liststore = Gtk2::ListStore->new ('Glib::String');
$liststore->set ($liststore->append, 0 => 'One');
$liststore->set ($liststore->append, 0 => 'Two');
examples/simple.pl view on Meta::CPAN
(activate => sub {
my ($menuview, $item, $model, $path, $iter) = @_;
print "activate, path=", $path->to_string, "\n";
print " data=", $model->get($iter,0), "\n";
});
#-----------------------------------------------------------------
my $toplevel = Gtk2::Window->new('toplevel');
$toplevel->signal_connect (destroy => sub { Gtk2->main_quit });
my $label = Gtk2::Label->new ("Press mouse button\nto popup menu");
$toplevel->add ($label);
$toplevel->add_events (['button-press-mask','button-release-mask']);
$toplevel->signal_connect
(button_press_event => sub {
my ($toplevel, $event) = @_;
$menuview->popup (undef, undef, undef, undef,
$event->button, $event->time);
});
$toplevel->show_all;
Gtk2->main;
exit 0;
lib/Gtk2/Ex/MenuView.pm view on Meta::CPAN
# }
# sub prepend {
# my ($self, $child) = @_;
# $self->{'model_pos'}--;
# $self->SUPER::prepend ($child);
# }
1;
__END__
=for stopwords TreeModel MenuView Gtk undef menuview iter BUILDABLE menubar popup ComboBox renderer CellView renderers submenu MenuItem CellRenderer Subclassing RadioMenuItems toplevel submenus enum lookups CheckMenuItems CheckMenuItem iters recursin...
=head1 NAME
Gtk2::Ex::MenuView -- menu of items from a TreeModel
=for test_synopsis my ($my_model)
=head1 SYNOPSIS
use Gtk2::Ex::MenuView;
t/MenuView-display.t view on Meta::CPAN
my $req = $menuview->size_request;
my $item_count = scalar @{[$menuview->get_children]};
is ($item_count, 1, 'size_request - item count');
is_deeply (\%created, {0=>'done'}, 'size_request - created paths');
cmp_ok ($req->width, '>=', 150, 'size_request - width');
cmp_ok ($req->height, '>=', 150, 'size_request - height');
}
#------------------------------------------------------------------------------
# popup creates items
{
my $store = Gtk2::ListStore->new ('Glib::String');
$store->set ($store->append, 0 => 'foo');
$store->set ($store->append, 0 => 'bar');
my %created;
my $menuview = Gtk2::Ex::MenuView->new (model => $store);
$menuview->signal_connect
(item_create_or_update => sub {
my ($menuview, $item, $model, $path, $iter) = @_;
diag "create ",$path->to_string;
$created{$path->to_string} = 'done';
$item = Gtk2::MenuItem->new_with_label ($model->get($iter,0));
return $item;
});
$menuview->popup (undef, undef, undef, undef, 1, 0);
MyTestHelpers::wait_for_event ($menuview, 'map-event');
my $child_count = scalar @{[$menuview->get_children]};
is ($child_count, 2, 'popup create children - count');
is_deeply (\%created, {0=>'done',1=>'done'},
'popup create children - paths');
}
#------------------------------------------------------------------------------
# no signals left on model
{
my $model = Gtk2::ListStore->new ('Glib::String');
my $menuview = Gtk2::Ex::MenuView->new (model => $model);
ok (MyTestHelpers::any_signal_connections($model));
t/MenuView-weaken.t view on Meta::CPAN
$store->set ($store->append, 0 => 'bar');
my $menuview = Gtk2::Ex::MenuView->new (model => $store);
$menuview->signal_connect
(item_create_or_update => sub {
my ($menuview, $item, $model, $path, $iter) = @_;
diag "create ",$path->to_string;
$item = Gtk2::MenuItem->new_with_label ($model->get($iter,0));
$item->show;
return $item;
});
$menuview->popup (undef, undef, undef, undef, 1, 0);
# Gtk2->main;
MyTestHelpers::wait_for_event ($menuview, 'map-event');
$child_count = scalar @{[$menuview->get_children]};
return $menuview, $store;
},
destructor => sub {
my ($menuview, $store) = @_;
$menuview->popdown;
},
contents => \&my_contents,
});
is ($child_count, 2, 'deep garbage collection -- popup, child count');
is ($leaks, undef, 'deep garbage collection -- popup');
if ($leaks && defined &explain) {
diag "Test-Weaken ", explain $leaks;
my $unfreed = $leaks->unfreed_proberefs;
foreach my $proberef (@$unfreed) {
diag " unfreed $proberef";
}
foreach my $proberef (@$unfreed) {
diag " search $proberef";
MyTestHelpers::findrefs($proberef);