Gtk2-Ex-ComboBoxBits

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


Version 29, January 2011
    - ComboBoxBits new set_active_path()

Version 28, January 2011
    - new Gtk2::Ex::ToolItem::ComboEnum
    - jump version number across Gtk2::Ex::ComboBox::PixbufType
      had $VERSION=27

Version 6, December 2010
    - new Gtk2::Ex::Menu::EnumRadio

Version 5, November 2010
    - ComboBoxBits set_active_text() undef do nothing if no model set
    - ComboBox::Enum new get_active_nick() and set_active_nick()

Version 4, October 2010
    - new Gtk2::Ex::ComboBox::PixbufType

Version 3, September 2010
    - tests at least one not depending on DISPLAY

MANIFEST  view on Meta::CPAN

devel/toolbutton-overflow-leak.c
devel/toolbutton-overflow-leak.pl
examples/text-builder.pl
examples/tool-enum-builder.pl
inc/my_pod2html
inc/MyMakeMakerExtras.pm
lib/Gtk2/Ex/ComboBox/Enum.pm
lib/Gtk2/Ex/ComboBox/PixbufType.pm
lib/Gtk2/Ex/ComboBox/Text.pm
lib/Gtk2/Ex/ComboBoxBits.pm
lib/Gtk2/Ex/Menu/EnumRadio.pm
lib/Gtk2/Ex/Menu/EnumRadio/Item.pm
lib/Gtk2/Ex/ToolItem/ComboEnum.pm
Makefile.PL
MANIFEST			This list of files
MANIFEST.SKIP
SIGNATURE
t/ComboBoxBits-import.t
t/ComboBoxBits-load.t
t/ComboBoxBits.t
t/Enum-display.t
t/Enum-weaken.t
t/Enum.t
t/Menu-EnumRadio.t
t/MyTestHelpers.pm
t/PixbufType-weaken.t
t/PixbufType.t
t/Test/Weaken/ExtraBits.pm
t/Text-display.t
t/ToolItem-EnumCombo-weaken.t
t/ToolItem-EnumCombo.t
xt/0-META-read.t
xt/0-no-debug-left-on.t
xt/0-Test-ConsistentVersion.t

META.yml  view on Meta::CPAN

    ExtUtils::MakeMaker:  0
requires:
    Glib::Ex::ConnectProperties:  9
    Glib::Ex::EnumBits:   10
    Glib::Ex::FreezeNotify:  1
    Glib::Ex::ObjectBits:  12
    Glib::Ex::SignalBits:  9
    Glib::Object::Subclass:  0
    Gtk2:                 1.220
    Gtk2::Ex::ContainerBits:  21
    Gtk2::Ex::MenuBits:   35
    Gtk2::Ex::MenuItem::Subclass:  30
    Gtk2::Ex::PixbufBits:  38
    perl:                 5.008
resources:
    homepage:  http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html
    license:   http://www.gnu.org/licenses/gpl.html
no_index:
    directory:
        - t
        - inc
        - xt

Makefile.PL  view on Meta::CPAN

                    'Glib::Ex::FreezeNotify' => 1, # started in v.1
                    'Glib::Ex::EnumBits'   => 10, # new in v.10
                    'Glib::Ex::SignalBits' => 9,  # new in v.9
                    'Glib::Ex::ObjectBits' => 12, # new in v.12

                    # my Glib-Ex-ConnectProperties
                    'Glib::Ex::ConnectProperties' => 9, # v.9 warnings maybe

                    # my Gtk2 Ex WidgetBits
                    'Gtk2::Ex::ContainerBits' => 21, # new in v.21
                    'Gtk2::Ex::MenuItem::Subclass' => 30, # v.30 $VERSION fix
                    'Gtk2::Ex::MenuBits' => 35, # v.35 mnemonic_escape
                    'Gtk2::Ex::PixbufBits' => 38, # v.38 type_supported_size()
                   },

   META_MERGE =>
   { resources =>
     { homepage => 'http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html',
     },
     optional_features =>
     {
      maximum_interoperation =>

SIGNATURE  view on Meta::CPAN

SHA1 5bb0ec7c5368682b09191a47c8707123a88d1e8c devel/toolbutton-overflow-leak.c
SHA1 700fd67ed34034f99607eae27f32f8e90e8901f1 devel/toolbutton-overflow-leak.pl
SHA1 f866b99f6db06943bf0071747da4eda50254393e examples/text-builder.pl
SHA1 f3f0ee887cfc665485b71b709a7c57d423324593 examples/tool-enum-builder.pl
SHA1 7aa92b5074cf12916763acbfc1c440575679a07e inc/MyMakeMakerExtras.pm
SHA1 7a988b2aa7ed09f1cb9029a1ef3f0e2139dca0cf inc/my_pod2html
SHA1 265d7747cb841b5aa822b552c33c6835c98c084b lib/Gtk2/Ex/ComboBox/Enum.pm
SHA1 3952a94435e9529b5ddb86b7cedefda5b14ac802 lib/Gtk2/Ex/ComboBox/PixbufType.pm
SHA1 f50531babce896fa4582239b0f62a52bc49ce118 lib/Gtk2/Ex/ComboBox/Text.pm
SHA1 942eadd15bcd0891b58b93ad90f484adb5ab64f9 lib/Gtk2/Ex/ComboBoxBits.pm
SHA1 4f06b672ccbd6fd0e3bfbbebc3ac53f3bab4792d lib/Gtk2/Ex/Menu/EnumRadio.pm
SHA1 049835f4c76948d9a16bdf03d4da3ce8646cc225 lib/Gtk2/Ex/Menu/EnumRadio/Item.pm
SHA1 cda7f3de06f5a88ab6741b1a2b9ed69d3a312c2a lib/Gtk2/Ex/ToolItem/ComboEnum.pm
SHA1 7a9d7b217111159ef57e07e4a729333bed5763e6 t/ComboBoxBits-import.t
SHA1 b225b40d1f88c173c58a9ee106608263d006c2f2 t/ComboBoxBits-load.t
SHA1 b2859671b75af55dcba8329fc26aff19abc2e846 t/ComboBoxBits.t
SHA1 7512277482173bbc6ca7f4c7c1db39bcdea0111f t/Enum-display.t
SHA1 ae0f4fc34a80a2e5294733be4b1df3dd410eeb5a t/Enum-weaken.t
SHA1 72090c5c7ca071ecbb6da7a59a6ff4ecb906f819 t/Enum.t
SHA1 f0621c32b583c36ad6ec4d716d0a6b6d0c20a8c2 t/Menu-EnumRadio.t
SHA1 4dc04c5401c223a0beedf001b5d8fb71afbdabfd t/MyTestHelpers.pm
SHA1 d756372ca936b60869b75647b4f68054ec5e4e5b t/PixbufType-weaken.t
SHA1 2f27811b3f7444859423249e0879032f3021f555 t/PixbufType.t
SHA1 1a0dee3ed339f3c1d681f29e7c32e8e218159b4d t/Test/Weaken/ExtraBits.pm
SHA1 e7ee85a7fc5a83e51bb3b470259ed22ad90cd382 t/Text-display.t
SHA1 b82cd3332164503637d5332b201076b2a0325dc5 t/ToolItem-EnumCombo-weaken.t
SHA1 47a7fec8936064f33a883a1022b2bf63d7b2a31c t/ToolItem-EnumCombo.t
SHA1 0279c9310ec528d10a2a14e602bf98f1c776cce1 xt/0-META-read.t
SHA1 219395eb91b03829e6f14db4ebd57d88ea972e61 xt/0-Test-ConsistentVersion.t
SHA1 8a5e0f34131de34e584fbb1939c191a152566155 xt/0-Test-DistManifest.t

devel/menu-enum.pl  view on Meta::CPAN



# gtk_radio_menu_item_activate() won't allow self to go off if no other in
# group is on.  When turning on sets all others in group to off.
#

use 5.010;
use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::Menu::EnumRadio 6; # v.6 in ComboBoxBits

use Smart::Comments;

use FindBin;
my $progname = $FindBin::Script;

if (0) {
  # my $menuitem = Gtk2::MenuItem->new ('_hello');
  my $menuitem = Gtk2::MenuItem->new_with_label ('hello');
  #  my $menuitem = Glib::Object::new ('Gtk2::MenuItem');
  ### child: $menuitem->get_child
  ### label: $menuitem->get('label')
  ### under: $menuitem->get('use-underline')
  # $menuitem->set(label => undef);
  exit 0;
}


Glib::Type->register_enum ('My::Test1', 'foo', 'bar-ski', 'quux',
                           # 100 .. 105,
                          );

my $toplevel = Gtk2::Window->new('toplevel');
$toplevel->signal_connect (destroy => sub { Gtk2->main_quit });

my $vbox = Gtk2::VBox->new;
$toplevel->add ($vbox);

my $menubar = Gtk2::MenuBar->new;
$vbox->pack_start ($menubar, 0,0,0);

my $item = Gtk2::MenuItem->new_with_label ('Menu');
$menubar->add ($item);

my $menu = Gtk2::Ex::Menu::EnumRadio->new
  (enum_type => 'My::Test1');
$menu->signal_connect ('notify::active-nick' => sub {
                         my ($menu) = @_;
                         print "$progname: active-nick now ",$menu->get('active-nick')||'[undef]',"\n";
                       });
$item->set_submenu ($menu);

my $tearoff = Gtk2::TearoffMenuItem->new;
$menu->prepend($tearoff);

{
  my $button = Gtk2::Button->new_with_label ('set active undef');
  $button->signal_connect (clicked => sub {
                             $menu->set (active_nick => undef);
                           });
  $vbox->pack_start ($button, 0, 0, 0);
}

devel/toolbutton-overflow-leak.pl  view on Meta::CPAN

use Glib 1.220;
use Gtk2 '-init';

use FindBin;
my $progname = $FindBin::Script;

# uncomment this to run the ### lines
use Smart::Comments;

{
  my $menuitem = Gtk2::ImageMenuItem->new_with_label ("hello");
  require Scalar::Util;
  Scalar::Util::weaken ($menuitem);
  ### weakened imagemenuitem: $menuitem
}

my $toplevel = Gtk2::Window->new('toplevel');
$toplevel->signal_connect (destroy => sub { Gtk2->main_quit });

my $vbox = Gtk2::VBox->new;
$vbox->show;

lib/Gtk2/Ex/Menu/EnumRadio.pm  view on Meta::CPAN

# later version.
#
# Gtk2-Ex-ComboBoxBits is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Gtk2-Ex-ComboBoxBits.  If not, see <http://www.gnu.org/licenses/>.

package Gtk2::Ex::Menu::EnumRadio;
use 5.008;
use strict;
use warnings;
use Gtk2;
use Glib::Ex::FreezeNotify;
use Glib::Ex::SignalBits;
use Glib::Ex::EnumBits;

use Gtk2::Ex::Menu::EnumRadio::Item;

# uncomment this to run the ### lines
#use Smart::Comments;

our $VERSION = 32;

use Glib::Object::Subclass
  'Gtk2::Menu',
  signals => { 'nick-to-display'
               => { param_types   => ['Glib::String'],
                    return_type   => 'Glib::String',
                    flags         => ['action','run-last'],
                    class_closure => \&default_nick_to_display,
                    accumulator   => \&Glib::Ex::SignalBits::accumulator_first_defined,
                  },
             },
  properties => [
                 # FIXME: default enum-type is undef but

lib/Gtk2/Ex/Menu/EnumRadio.pm  view on Meta::CPAN


  if ($pname eq 'enum_type') {
    my $enum_type = $self->{$pname} = $newval;

    # preserve active-nick if the current active exists in the new
    # enum-type, perhaps at a different position
    $newval = $self->get('active-nick');

    # remove old
    foreach my $item ($self->get_children) {
      if ($item->isa ('Gtk2::Ex::Menu::EnumRadio::Item')) {
        ### remove: "$item"
        $self->remove ($item);
      }
    }
    ### children now: "@{[$self->get_children]}"

    # add new
    if (defined $enum_type && $enum_type ne '') {
      my $item;
      foreach my $info (Glib::Type->list_values($enum_type)) {
        my $nick = $info->{'nick'};
        my $str = $self->signal_emit ('nick-to-display', $nick);
        $item = Gtk2::Ex::Menu::EnumRadio::Item->new_with_label
          ($str);
        $item->set (nick => $nick);
        ### sig: $item->signal_connect (activate => sub { print "activate $item ",$item->get_active,"\n" })
        $item->show;
        $self->append ($item);
      }
    }
  }

  # $pname eq 'active_nick', and also fall-through from 'enum_type' possibly

lib/Gtk2/Ex/Menu/EnumRadio.pm  view on Meta::CPAN

sub default_nick_to_display {
  my ($self, $nick) = @_;
  my $enum_type;
  return (($enum_type = $self->{'enum_type'})
          && Glib::Ex::EnumBits::to_display ($enum_type, $nick));
}

sub get_active_nick {
  my ($self) = @_;
  foreach my $item ($self->get_children) {
    if ($item->isa('Gtk2::Ex::Menu::EnumRadio::Item')
        && $item->get_active) {
      return $item->{'nick'};
    }
  }
  return undef;
}

# Each menuitem set_active() only does something if the new activeness is
# different.  If different then its activate handler raises
# "notify::active-nick" back up here on the menu.
#
sub set_active_nick {
  my ($self, $nick) = @_;

  # just one notify, not two for turning on and off
  my $freezer = Glib::Ex::FreezeNotify->new ($self);

  foreach my $item ($self->get_children) {
    if ($item->isa('Gtk2::Ex::Menu::EnumRadio::Item')) {
      if (defined $nick) {
        if ($item->{'nick'} eq $nick) {
          $item->set_active (1);
          last;
        }
      } else {
        ### inactive: $item->{'nick'}
        $item->set_active (0);
      }
    }
  }
}

1;
__END__

=for stopwords Gtk2-Ex-ComboBoxBits enum ParamSpec GType pspec Enum Ryde

=head1 NAME

Gtk2::Ex::Menu::EnumRadio -- menu of enum values as radio items

=head1 SYNOPSIS

 use Gtk2::Ex::Menu::EnumRadio;
 my $menu = Gtk2::Ex::Menu::EnumRadio->new
              (enum_type   => 'Glib::UserDirectory',
               active_nick => 'home');  # initial selection

=head1 WIDGET HIERARCHY

C<Gtk2::Ex::Menu::EnumRadio> is a subclass of C<Gtk2::Menu>,

    Gtk2::Widget
      Gtk2::Container
        Gtk2::MenuShell
          Gtk2::Menu
            Gtk2::Ex::Menu::EnumRadio

=head1 DESCRIPTION

C<Gtk2::Ex::Menu::EnumRadio> displays the values of a C<Glib::Enum> in a
menu as a radio group allowing the user to select one of them.  The
C<active-nick> property is the user's selection.

    +----+
    |Menu|
    +--------------------+
    |  Enum Value One    |
    |* Enum Value Two    |
    |  Enum Value Third  |
    |  Enum Value Fourth |
    +--------------------+

The text shown for each entry is per L<Glib::Ex::EnumBits> C<to_display()>,
so an enum class can arrange how its values appear, or the default is a
sensible word split and capitalization.

lib/Gtk2/Ex/Menu/EnumRadio.pm  view on Meta::CPAN

callback, but some care may be needed to have it connected early enough, or
for the calls to be made later than when C<enum-type> is set, since that
property will often be set before making signal connections.)

There's no way to set mnemonics for each enum value.  A semi-automatic way
to pick sensible ones might be good.

=head2 Implementation

For reference, in the current code the menu items are a private subclass of
C<Gtk2::CheckMenuItem>.  They're not C<Gtk2::RadioMenuItem> because it
insists on having one value always selected whereas for this EnumRadio the
initial default is nothing selected, similar to a ComboBox.  The items
display in C<draw-as-radio> style when possible (Gtk 2.4 up).

The current code will tolerate extra items added to the menu.  Only those
which are enum values are updated, deleted, etc.  The idea is to allow say a
C<Gtk2::TearoffMenuItem> or equivalent like C<Gtk2::Ex::Dashes::MenuItem> at
the start.  But this is not quite settled, so beware of future changes.  In
particular it may need something to express whether extra items belong
before or after the enum items.

=head1 FUNCTIONS

=over 4

=item C<< $menu = Gtk2::Ex::Menu::EnumRadio->new (key=>value,...) >>

Create and return a new C<EnumRadio> menu object.  Optional key/value pairs
set initial properties per C<< Glib::Object->new >>.

    my $menu = Gtk2::Ex::Menu::EnumRadio->new
                 (enum_type   => 'Gtk2::TextDirection',
                  active_nick => 'ltr');


=item C<< $str = $menu->get_active_nick() >>

Return the nick of the currently selected enum value, or C<undef> if nothing
selected.  This is the C<active-nick> property.

=item C<< $menu->set_active_nick($str) >>

lib/Gtk2/Ex/Menu/EnumRadio.pm  view on Meta::CPAN

selected.  Perhaps this will change.

=back

=head1 PROPERTIES

=over 4

=item C<enum-type> (type name, default C<undef>)

The enum type to display and select from.  Until this is set the Menu is
empty.

When changing C<enum-type> if the current selected C<active-nick> also
exists in the new type then it remains selected (possibly a different menu
item).  If the C<active-nick> doesn't exist in the new type then the menu
changes to nothing selected.

This property is a C<Glib::Param::GType> when possible or
C<Glib::Param::String> otherwise.  In both cases at the Perl level the value
is a type name string, but a GType will check the given type really is an

lib/Gtk2/Ex/Menu/EnumRadio.pm  view on Meta::CPAN

=head1 BUGS

The C<enum-type> paramspec default is not the actual default C<undef> (in
particular when it's a C<GType> it's C<"Glib::Enum"> instead).

    # this should be undef, usually isn't
    $menu->find_property('enum-type')->get_default_value

=head1 SEE ALSO

L<Gtk2::Menu>,
L<Glib::Ex::EnumBits>,
L<Gtk2::Ex::ComboBox::Enum>

=head1 HOME PAGE

L<http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html>

=head1 LICENSE

Copyright 2010, 2011 Kevin Ryde

lib/Gtk2/Ex/Menu/EnumRadio/Item.pm  view on Meta::CPAN

# later version.
#
# Gtk2-Ex-ComboBoxBits is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Gtk2-Ex-ComboBoxBits.  If not, see <http://www.gnu.org/licenses/>.

package Gtk2::Ex::Menu::EnumRadio::Item;
use 5.008;
use strict;
use warnings;
use Glib::Ex::ObjectBits;
use Gtk2;

# uncomment this to run the ### lines
#use Smart::Comments;

our $VERSION = 32;

# Gtk2::RadioMenuItem is no good as the base class since it insists on at
# least one item active all the time.
#
# The _do_activate() class handler here allows a parent notify without a
# separate activate signal connection on each item.

use Glib::Object::Subclass
  'Gtk2::CheckMenuItem',
  signals => { activate => \&_do_activate },
  properties => [ Glib::ParamSpec->string
                  ('nick',
                   'Enum nick',
                   'The enum nick for this item.',
                   (eval {Glib->VERSION(1.240);1}
                    ? undef # default
                    : ''),  # no undef/NULL before Perl-Glib 1.240
                   Glib::G_PARAM_READWRITE)
                ];

use Gtk2::Ex::MenuItem::Subclass;
unshift our @ISA, 'Gtk2::Ex::MenuItem::Subclass';

sub INIT_INSTANCE {
  my ($self) = @_;
  Glib::Ex::ObjectBits::set_property_maybe ($self, draw_as_radio => 1);
}

sub _do_activate {
  my ($self) = @_;
  ### EnumRadio-Item _do_activate()
  $self->signal_chain_from_overridden;

lib/Gtk2/Ex/ToolItem/ComboEnum.pm  view on Meta::CPAN

  $combobox->signal_connect ('notify::active-nick'  => \&_do_combobox_notify);
  $combobox->signal_connect ('notify::enum-type'    => \&_do_combobox_notify);
  $combobox->signal_connect ('notify::add-tearoffs'
                             => \&_do_combobox_notify_add_tearoffs);
  $self->add ($combobox);
}

sub FINALIZE_INSTANCE {
  my ($self) = @_;
  if (my $menuitem = delete $self->{'menuitem'}) {
    $menuitem->destroy;  # destroy circular MenuItem<->AccelLabel
  }
}

sub GET_PROPERTY {
  my ($self, $pspec) = @_;
  my $pname = $pspec->get_name;
  ### ComboEnum GET_PROPERTY: $pname

  if ($pname eq 'enum_type' || $pname eq 'active_nick') {
    ### fetch from combobox: $self->get_child && $self->get_child->get($pname)

lib/Gtk2/Ex/ToolItem/ComboEnum.pm  view on Meta::CPAN

    _update_overflow_tearoff ($self);
  }
}

sub _do_create_menu_proxy {
  my ($self) = @_;
  ### _do_create_menu_proxy()
  my $combobox = $self->get_child || return 0;  # if being destroyed maybe

  if (! $self->{'menuitem'}) {
    require Gtk2::Ex::Menu::EnumRadio;
    require Glib::Ex::ConnectProperties;
    my $menu = Gtk2::Ex::Menu::EnumRadio->new;
    # enum-type first otherwise active-nick not settable
    Glib::Ex::ConnectProperties->new ([$self,'enum-type'],
                                      [$menu,'enum-type']);
    Glib::Ex::ConnectProperties->new ([$self,'active-nick'],
                                      [$menu,'active-nick']);
    # ComboBox tearoff-title new in 2.10, but Menu tearoff-title always present
    if ($combobox->find_property('tearoff-title')) {
      Glib::Ex::ConnectProperties->new ([$combobox,'tearoff-title'],
                                        [$menu,'tearoff-title']);
    }
    ### initial menu enum-type: $menu->get_active_nick 
    ### initial menu active-nick: $menu->get_active_nick 

    # prompt store to $self->{'menuitem'} for safe destroy if any error
    my $menuitem = $self->{'menuitem'} = Gtk2::MenuItem->new_with_mnemonic ('');
    $menuitem->set_submenu ($menu);
    _update_overflow_mnemonic ($self); # initial label
    _update_overflow_tearoff ($self);  # initial tearoff
  }

  $self->set_proxy_menu_item (__PACKAGE__, $self->{'menuitem'});
  return 1;
}

sub _update_overflow_mnemonic {

lib/Gtk2/Ex/ToolItem/ComboEnum.pm  view on Meta::CPAN

      if (defined ($str = $combobox->get('enum-type'))) {
        $str =~ s/.*:://;
      } else {
        $str = $combobox->get_name;
      }
    } else {
      $str = $self->get_name;
    }
    require Glib::Ex::EnumBits;
    $str = Glib::Ex::EnumBits::to_display_default (undef, $str);
    require Gtk2::Ex::MenuBits;
    $str = Gtk2::Ex::MenuBits::mnemonic_escape($str);
  }
  ### $str
  $label->set_label ($str);
}

sub _update_overflow_tearoff {
  my ($self) = @_;
  ### ComboEnum _update_overflow_tearoff()
  my $combobox = $self->get_child || return 0;  # if being destroyed maybe
  my $menuitem = $self->{'menuitem'} || return;
  my $menu = $menuitem->get_submenu || return;  # if being destroyed maybe
  $combobox->find_property('add-tearoffs') || return;  # not in Gtk 2.4
  if ($combobox->get('add-tearoffs')) {
    ### tearoff wanted
    unless (List::Util::first
            {$_->isa('Gtk2::TearoffMenuItem')}
            $menu->get_children) {
      ### add new TearoffMenuItem
      $menu->prepend (Gtk2::TearoffMenuItem->new);
    }
  } else {
    ### tearoff not wanted
    Gtk2::Ex::ContainerBits::remove_widgets
        ($menu,
         grep {$_->isa('Gtk2::TearoffMenuItem')} $menu->get_children);
  }
}

#------------------------------------------------------------------------------
# Gtk2::Buildable interface

sub GET_INTERNAL_CHILD {
  my ($self, $builder, $name) = @_;
  if ($name eq 'combobox') {
    return $self->get_child;

lib/Gtk2/Ex/ToolItem/ComboEnum.pm  view on Meta::CPAN


and implements interfaces

    Gtk2::Buildable  (in Gtk 2.12 up)

=head1 DESCRIPTION

This is a ToolItem holding a C<Gtk2::Ex::ComboBox::Enum> to let the user
choose a value from an enum.  It shows the ComboBox normally, or in an
overflow menu offers the same choices in a radio menu using
C<Gtk2::Ex::Menu::EnumRadio>.  The menu is linked to the combobox so they
update together.

    toolbar overflow
       +---+    
       | V |  
       +---------------+
       | Other         |
       | Enumeration > |+------------+
       | Other         ||   EChoice1 |
       +---------------+|   EChoice2 |

lib/Gtk2/Ex/ToolItem/ComboEnum.pm  view on Meta::CPAN

=head1 BUGS

As of Perl-Gtk 1.223 the C<Gtk2::Buildable> interface from Perl code doesn't
chain up to the parent buildable methods, so some of GtkWidget specifics may
be lost, such as the C<< <accessibility> >> tags.

=head1 SEE ALSO

L<Gtk2::ToolItem>,
L<Gtk2::Ex::ComboBox::Enum>,
L<Gtk2::Ex::Menu::EnumRadio>,
L<Gtk2::Ex::ToolItem::OverflowToDialog>

=head1 HOME PAGE

L<http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html>

=head1 LICENSE

Copyright 2010, 2011 Kevin Ryde

t/Menu-EnumRadio.t  view on Meta::CPAN

BEGIN { MyTestHelpers::nowarnings() }

use Gtk2;
Gtk2->disable_setlocale;  # leave LC_NUMERIC alone for version nums
Gtk2->init_check
  or plan skip_all => 'due to no DISPLAY available';
MyTestHelpers::glib_gtk_versions();

plan tests => 32;

require Gtk2::Ex::Menu::EnumRadio;

Glib::Type->register_enum ('My::Test1', 'foo', 'bar-ski', 'quux');

#------------------------------------------------------------------------------
# VERSION

my $want_version = 32;
{
  is ($Gtk2::Ex::Menu::EnumRadio::VERSION,
      $want_version,
      'VERSION variable');
  is (Gtk2::Ex::Menu::EnumRadio->VERSION,
      $want_version,
      'VERSION class method');

  ok (eval { Gtk2::Ex::Menu::EnumRadio->VERSION($want_version); 1 },
      "VERSION class check $want_version");
  my $check_version = $want_version + 1000;
  ok (! eval { Gtk2::Ex::Menu::EnumRadio->VERSION($check_version); 1 },
      "VERSION class check $check_version");

  my $menu = Gtk2::Ex::Menu::EnumRadio->new;
  is ($menu->VERSION,  $want_version, 'VERSION object method');

  ok (eval { $menu->VERSION($want_version); 1 },
      "VERSION object check $want_version");
  ok (! eval { $menu->VERSION($check_version); 1 },
      "VERSION object check $check_version");
}


#-----------------------------------------------------------------------------
# property defaults





#-----------------------------------------------------------------------------
# Scalar::Util::weaken

{
  my $menu = Gtk2::Ex::Menu::EnumRadio->new;
  require Scalar::Util;
  Scalar::Util::weaken ($menu);
  is ($menu, undef, 'garbage collect when weakened');
}


#-----------------------------------------------------------------------------
# active-nick

{
  my $menu = Gtk2::Ex::Menu::EnumRadio->new
    (enum_type => 'My::Test1');
  is ($menu->get('active-nick'), undef, 'get(active-nick) initial');
  is ($menu->get_active_nick, undef, 'get_active_nick() initial');

  my $saw_notify;
  $menu->signal_connect ('notify::active-nick' => sub {
                           $saw_notify++;
                         });

  $saw_notify = 0;

t/Menu-EnumRadio.t  view on Meta::CPAN

  is ($menu->get_active_nick, 'foo', 'set_active_nick() get_active_nick()');
}

#-----------------------------------------------------------------------------
# enum-type change

Glib::Type->register_enum ('MyTest::OneTwo', 'one', 'two');
Glib::Type->register_enum ('MyTest::ThreeFourTwo', 'three', 'four', 'two');

{
  my $menu = Gtk2::Ex::Menu::EnumRadio->new
    (enum_type => 'MyTest::ThreeFourTwo');
  {
    my @children = $menu->get_children;
    is (scalar(@children), 3);
    is_deeply ([map{$_->find_property('nick')&&$_->get('nick')} @children],
               ['three', 'four', 'two'],
               'enum-type initial nicks');
  }
  $menu->set (enum_type => 'MyTest::OneTwo');
  {
    my @children = $menu->get_children;
    is (scalar(@children), 2);
    is_deeply ([map{$_->find_property('nick')&&$_->get('nick')} @children],
               ['one','two'],
               'enum-type changed nicks');
  }
  $menu->prepend (Gtk2::MenuItem->new_with_label('Hello'));
  {
    my @children = $menu->get_children;
    is (scalar(@children), 3,
        'add extra item');
  }
  $menu->set (enum_type => 'MyTest::ThreeFourTwo');
  {
    my @children = $menu->get_children;
    is (scalar(@children), 4);
    is_deeply ([map{$_->find_property('nick')&&$_->get('nick')} @children],

t/ToolItem-EnumCombo.t  view on Meta::CPAN

}

#-----------------------------------------------------------------------------
# overflow menu

{
  my $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new
    (enum_type => 'My::Test1');
  my $combobox = $toolitem->get_child;
  my $menuitem = $toolitem->retrieve_proxy_menu_item;
  isa_ok ($menuitem, 'Gtk2::MenuItem');  
  { my $m2 = $toolitem->retrieve_proxy_menu_item;
    is ($m2, $menuitem);
  }
  { my $m2 = $toolitem->retrieve_proxy_menu_item;
    is ($m2, $menuitem);
  }
  my $menu = $menuitem->get_submenu;
  isa_ok ($menu, 'Gtk2::Ex::Menu::EnumRadio');  

  is ($toolitem->get('active-nick'), undef);
  is ($combobox->get('active-nick'), undef);
  is ($menu->get('active-nick'), undef);

  $menu->set(active_nick => 'foo');
  is ($toolitem->get('active-nick'), 'foo');
  is ($combobox->get('active-nick'), 'foo');
  is ($menu->get('active-nick'), 'foo');
}



( run in 0.989 second using v1.01-cache-2.11-cpan-49f99fa48dc )