view release on metacpan or search on metacpan
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
- devel
- examples
generated_by: ExtUtils::MakeMaker version 6.56
meta-spec:
Makefile.PL view on Meta::CPAN
# 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 =>
{ description => 'Have maximum inter-operation with other modules (optional other stuff).',
requires => { 'Locale::Messages' => 0 },
},
maximum_tests =>
{ description => 'Have "make test" do as much as possible.',
requires => { 'Test::Weaken' => 3,
debian/changelog view on Meta::CPAN
libgtk2-ex-comboboxbits-perl (32-1) unstable; urgency=low
* Packaged version.
-- Kevin Ryde <user42@zip.com.au> Fri, 20 May 2011 06:43:14 +1000
debian/control view on Meta::CPAN
# 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/>.
# Build-Depends could have the "maximum_tests" modules from META.yml
# for more tests, but they're optional author tests really and would
# just make the build tools drag in more stuff.
Source: libgtk2-ex-comboboxbits-perl
Section: perl
Priority: optional
Build-Depends: cdbs, debhelper (>= 5)
Maintainer: Kevin Ryde <user42@zip.com.au>
Standards-Version: 3.9.2
Homepage: http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html
Bugs: mailto:user42@zip.com.au
Package: libgtk2-ex-comboboxbits-perl
Architecture: all
Depends: perl (>= 5.8.0), libglib-perl, libgtk2-perl (>= 1:1.220), libglib-ex-objectbits-perl (>= 12), libglib-ex-connectproperties-perl (>= 9), libgtk2-ex-widgetbits-perl (>= 38), ${perl:Depends}, ${misc:Depends}
Description: Miscellaneous Gtk2::CombBox things
ComboBoxes for enum value, text list, and Pixbuf format types.
debian/copyright view on Meta::CPAN
Gtk2-Ex-ComboBoxBits is Copyright 2010, 2011 Kevin Ryde
Gtk2-Ex-ComboBoxBits is licensed under the GNU Public License GPL
version 3, or at your option any later version. The complete text of
GPL version 3 is in the file
/usr/share/common-licenses/GPL-3
Program home page:
http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html
debian/rules view on Meta::CPAN
# 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/>.
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/perlmodule.mk
DEB_INSTALL_EXAMPLES_libgtk2-ex-comboboxbits-perl = examples/*
debian/watch view on Meta::CPAN
#
# 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/>.
# Crib notes:
# "man uscan" describes the format.
# test with: uscan --report --verbose --watchfile=debian/watch
version=3
http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html \
.*/Gtk2-Ex-ComboBoxBits-([0-9]+)\.tar\.gz
devel/bits.pl view on Meta::CPAN
use Gtk2 '-init';
use Gtk2::Ex::ComboBoxBits;
my $model = Gtk2::TreeStore->new ('Glib::String');
$model->insert (undef, 0);
$model->insert (undef, 1);
$model->insert (undef, 2);
$model->insert ($model->iter_nth_child(undef,2), 0);
$model->insert ($model->iter_nth_child(undef,2), 1);
my $combobox = Gtk2::ComboBox->new;
$combobox->signal_connect (notify => sub {
my ($combobox, $pspec) = @_;
my $pname = $pspec->get_name;
say "notify $pname now ",$combobox->get($pname);
say " get(active) ",$combobox->get('active');
});
# $combobox->set('active',3,
# model => $model);
$combobox->set_active(3);
$combobox->set_model($model);
say "get(active) ",$combobox->get('active');
# $combobox->set_model ($model);
# is (get_active_path($combobox), undef);
# is (find_text_iter($combobox, 'nosuchentry'), undef);
#
# set_active_path($combobox,Gtk2::TreePath->new_from_indices(0,0));
# set_active_text($combobox,'nosuchentry');
# ok(1);
exit 0;
devel/builder-activetext.pl view on Meta::CPAN
my $builder = Gtk2::Builder->new;
$builder->add_from_string (<<'HERE');
<interface>
<object class="GtkWindow" id="toplevel">
<property name="type">toplevel</property>
<signal name="destroy" handler="do_quit"/>
<child>
<object class="GtkHBox" id="hbox">
<child>
<object class="Gtk2__Ex__ComboBox__Text" id="combobox">
<property name="append-text">First Choice</property>
<property name="append-text">Second Choice</property>
<property name="append-text">Choice the Third</property>
<property name="active-text">Second Choice</property>
</object>
</child>
<child>
<object class="GtkButton" id="quit">
<property name="label">gtk-quit</property>
<property name="use-stock">TRUE</property>
devel/tool-enum.pl view on Meta::CPAN
my $button = Gtk2::Button->new_with_label ('set active undef');
$button->signal_connect (clicked => sub {
$toolitem->set (active_nick => undef);
});
$button->show_all;
$vbox->pack_start ($button, 0, 0, 0);
}
{
my $button = Gtk2::CheckButton->new_with_label ('ComboBox add-tearoffs');
my $combobox = $toolitem->get_child;
require Glib::Ex::ConnectProperties;
Glib::Ex::ConnectProperties->new
([$combobox, 'add-tearoffs'],
[$button, 'active']);
$button->show;
$vbox->pack_start ($button, 0, 0, 0);
}
$toplevel->show;
Gtk2->main;
exit 0;
examples/text-builder.pl view on Meta::CPAN
# 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/>.
# Usage: perl text-builder.pl
#
# This is an example of making a Text combobox with Gtk2::Builder (which is
# new in Gtk 2.12).
# The class name is "Gtk2__Ex__ComboBox__Text", as usual for Gtk2-Perl
# package name to Gtk type name conversion in the builder.
#
# The append-text property is a handy way to fill the combobox with desired
# choices for the user. Once they're added the active-text property can
# then be set to the initially active choice.
#
# active-text is by string value. The usual ComboBox "active" property can
# set the active by number too. If for example the first choice is always
# the desired one then it may be easier to write "0" than copy the string,
#
# <property name="active">0</property>
#
examples/tool-enum-builder.pl view on Meta::CPAN
# This is an example of making a ToolItem::ComboEnum using Gtk2::Builder
# (which is new in Gtk 2.12).
#
# The class name is "Gtk2__Ex__ToolItem__ComboEnum", as usual for Gtk2-Perl
# package name to Gtk type name in the builder.
#
# The enum-type and initial active-nick are set on the toolitem in the usual
# way. Don't forget to set the enum-type first, since an active-nick can
# only be set once there's an enum of values for it.
#
# The <child internal-child="combobox"> provides access to the child
# combobox from the builder spec. "internal-child" means it's not a new
# child object created, but a reference to a pre-built one, and the "id" is
# the name to use to refer to it in the builder spec. (The syntax is rather
# unfortunately similar to a new child widget creation, but that's the way
# Gtk2::Builder works.)
#
# The combobox is referred to so as to set a couple of properties: the
# add-tearoffs option and a tooltip. A tooltip can also be put on the
# toolitem itself, and in fact that may be the better place for it.
#
use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::ToolItem::ComboEnum;
# uncomment this to run the ### lines
examples/tool-enum-builder.pl view on Meta::CPAN
<child>
<object class="GtkToolbar" id="toolbar">
<child>
<object class="Gtk2__Ex__ToolItem__ComboEnum" id="toolitem">
<property name="enum-type">GtkArrowType</property>
<property name="active-nick">left</property>
<property name="overflow-mnemonic">_Direction</property>
<child internal-child="combobox">
<object class="Gtk2__Ex__ComboBox__Enum" id="the_tool_combobox">
<property name="add-tearoffs">true</property>
<property name="tooltip-text">Tooltip for the ComboBox</property>
</object>
</child>
</object>
</child>
</object>
</child>
lib/Gtk2/Ex/ComboBox/Enum.pm view on Meta::CPAN
if ($pname eq 'enum_type') {
my $enum_type = $self->{$pname} = $newval;
# preserve active by its nick, if new type has that value
# set_active() below will notify if the active changes, in particular to
# -1 if nick not known in the new enum_type
$newval = $self->get('active-nick');
# Crib note: In gtk 2.4 believe set_model() doesn't accept NULL,
# including through set_property(), though a combobox starts out with
# NULL for the model. If $enum_type is unset then just clear the
# existing model, don't try to set undef.
#
my $model = $self->get_model;
if ($model) {
$model->clear;
}
if (defined $enum_type && $enum_type ne '') {
if (! $model) {
$model = Gtk2::ListStore->new ('Glib::String');
lib/Gtk2/Ex/ComboBox/Enum.pm view on Meta::CPAN
# for (my $iter = $model->get_iter_first;
# $iter;
# $iter = $model->iter_next ($iter)) {
# $model->set ($iter, _COLUMN_DISPLAY,
# $self->signal_emit('nick-to-display',
# $model->get ($iter, _COLUMN_NICK)));
# }
# }
=for stopwords Gtk2-Ex-ComboBoxBits enum ParamSpec GType pspec Enum Ryde ComboBoxBits combobox ComboBox paramspec
=head1 NAME
Gtk2::Ex::ComboBox::Enum -- combobox for values of a Glib::Enum
=head1 SYNOPSIS
use Gtk2::Ex::ComboBox::Enum;
my $combo = Gtk2::Ex::ComboBox::Enum->new
(enum_type => 'Glib::UserDirectory',
active_nick => 'home'); # initial selection
=head1 WIDGET HIERARCHY
lib/Gtk2/Ex/ComboBox/Enum.pm view on Meta::CPAN
(There's a secret experimental might change in the future C<nick-to-display>
signal for per-instance control of the display. A signal is a good way to
express a callback, but some care may be needed to get it connected early
enough, or for the calls to be later than when C<enum-type> is set, since
that property will often be set before making signal connections.)
=head1 FUNCTIONS
=over 4
=item C<< $combobox = Gtk2::Ex::ComboBox::Enum->new (key=>value,...) >>
Create and return a new C<Enum> combobox object. Optional key/value
pairs set initial properties per C<< Glib::Object->new >>.
my $combo = Gtk2::Ex::ComboBox::Enum->new
(enum_type => 'Gtk2::TextDirection',
active => 0); # the first row
=item C<< $str = $combobox->get_active_nick >>
=item C<< $combobox->set_active_nick ($str) >>
Get or set the C<active-nick> property described below. C<set_active_nick>
does nothing if C<$str> is already the active nick, in particular it doesn't
emit a C<notify>.
=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 ComboBox 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 on a different
row. If the C<active-nick> doesn't exist in the new type then the combobox
changes to nothing selected.
(This property is a C<Glib::Param::GType> in new enough Glib and Perl-Glib,
or a C<Glib::Param::String> otherwise. In both cases it's a type name
string at the Perl level, but GType checks a setting really is an enum.)
=item C<active-nick> (string or C<undef>, default C<undef>)
The nick of the selected enum value. The nick is the usual way an enum
value appears at the Perl level.
If there's no active row in the combobox or no C<enum-type> has been set
then C<active-nick> is C<undef>.
There's no default for C<active-nick>, just as there's no default for the
ComboBox C<active>, so when creating an Enum combobox it's usual to set the
desired initial selection, either by nick or perhaps just C<active> row 0
for the first value.
=back
=head1 BUGS
There's no way to set mnemonics for each enum value. A semi-automatic way
to pick sensible ones might be good.
The C<enum-type> paramspec C<get_default_value> should be C<undef> but is
not. For the C<GType> case it's C<"Glib::Enum">, or for the C<String> it's
an empty C<"">.
# should be undef, but isn't
$combobox->find_property('enum-type')->get_default_value
=head1 SEE ALSO
L<Gtk2::ComboBox>,
L<Glib::Ex::EnumBits>,
L<Gtk2::Ex::ComboBox::Text>
=head1 HOME PAGE
L<http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html>
=head1 LICENSE
Copyright 2010, 2011 Kevin Ryde
Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
lib/Gtk2/Ex/ComboBox/Enum.pm view on Meta::CPAN
You should have received a copy of the GNU General Public License along with
Gtk2-Ex-ComboBoxBits. If not, see L<http://www.gnu.org/licenses/>.
=cut
# =head1 SIGNALS
#
# =over 4
#
# =item C<nick-to-display> (parameters: combobox, nick -- return: string)
#
# Emitted to turn an enum nick into a text display string. The default is
# the C<to_display> of C<Glib::Ex::EnumBits>.
#
# =back
lib/Gtk2/Ex/ComboBox/PixbufType.pm view on Meta::CPAN
_COLUMN_DISPLAY, $display{$type});
}
# preserve existing setting
$self->set (active_type => $type);
}
1;
__END__
=for stopwords Gtk Gtk2 Perl-Gtk combobox ComboBox Gdk Pixbuf Gtk
writability png jpeg ico bmp programmatically
=head1 NAME
Gtk2::Ex::ComboBox::PixbufType -- combobox for Gdk Pixbuf file format types
=head1 SYNOPSIS
use Gtk2::Ex::ComboBox::PixbufType;
my $ptypecombo = Gtk2::Ex::ComboBox::PixbufType->new;
=head1 WIDGET HIERARCHY
C<Gtk2::Ex::ComboBox::PixbufType> is a subclass of
C<Gtk2::ComboBox>,
Gtk2::Widget
Gtk2::Container
Gtk2::Bin
Gtk2::ComboBox
Gtk2::Ex::ComboBox::PixbufType
=head1 DESCRIPTION
A C<PixbufType> combobox displays file format types available for
C<Gtk2::Gdk::Pixbuf>.
+------+
| PNG |
+------+
...
The C<active-type> property is the type displayed and updated with the
user's selection, eg "png".
lib/Gtk2/Ex/ComboBox/PixbufType.pm view on Meta::CPAN
Perl-Gtk2 (some time post 1.223), or for older Perl-Gtk2 there's a
hard-coded list of "png", "jpeg", "tiff", "ico" and "bmp" (less any not
applicable under an older Gtk).
=head1 FUNCTIONS
=over 4
=item C<< $ptypecombo = Gtk2::Ex::ComboBox::PixbufType->new (key=>value,...) >>
Create and return a new combobox object. Optional key/value pairs set
initial properties as per C<< Glib::Object->new >>. For example,
my $ptypecombo = Gtk2::Ex::ComboBox::PixbufType->new
(active_type => 'png');
=back
=head1 PROPERTIES
=over 4
=item C<active-type> (string or C<undef>, default C<undef>)
The format type selected in the ComboBox. This is the user's combobox
choice, or setting it programmatically changes that choice.
The value is a format type name string such as "png", as in the C<name>
field of C<Gtk2::Gdk::PixbufFormat> and as taken by C<< $pixbuf->save >>.
There's no default for C<active-type>, just as there's no default for the
ComboBox C<active>. When creating a PixbufType combobox a desired initial
selection can be set. "png" or "jpeg" are always available.
=item C<for-width> (integer 0 up, default 0)
=item C<for-height> (integer 0 up, default 0)
Show only those file format types which support an image of this size. For
example "ico" format only goes up to 255x255, so if C<for-width> and
C<for-height> are 300x150 then ico is not offered. The default size 0 means
no size restriction.
lib/Gtk2/Ex/ComboBox/PixbufType.pm view on Meta::CPAN
=back
=head1 SEE ALSO
L<Gtk2::ComboBox>,
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
Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
lib/Gtk2/Ex/ComboBox/Text.pm view on Meta::CPAN
shift->signal_chain_from_overridden (@_);
if ($pspec->get_name eq 'active') {
$self->notify ('active-text');
}
}
1;
__END__
=for stopwords Gtk2-Ex-ComboBoxBits ComboBoxBits combobox ComboBox Gtk BUILDABLE buildable Ryde
=head1 NAME
Gtk2::Ex::ComboBox::Text -- text combobox with "active-text" property
=head1 SYNOPSIS
use Gtk2::Ex::ComboBox::Text;
my $combo = Gtk2::Ex::ComboBox::Text->new_text;
$combo->append_text ('First Choice');
$combo->append_text ('Second Choice');
$combo->set (active_text => 'Second Choice');
lib/Gtk2/Ex/ComboBox/Text.pm view on Meta::CPAN
The C<active-text> property is the same as C<< $combo->get_active_text >>
but as a property can be treated a bit more generally than a method call,
for instance link it up to another widget with
C<Glib::Ex::ConnectProperties>.
=head1 FUNCTIONS
=over 4
=item C<< $combobox = Gtk2::Ex::ComboBox::Text->new (key => value,...) >>
=item C<< $combobox = Gtk2::Ex::ComboBox::Text->new_text (key => value,...) >>
Create and return a new Text combobox object. C<new> and C<new_text> are
the same thing, since a Text combobox is always text style. Optional
key/value pairs set initial properties per C<< Glib::Object->new >>.
my $combo = Gtk2::Ex::ComboBox::Text->new;
=item C<< $combobox->set_active_text ($str) >>
The choice C<$str> active, the same as setting the C<active-text> property.
It's slightly unspecified as yet what happens if C<$str> is not available as
a choice in C<$combobox>.
=back
=head1 PROPERTIES
=over 4
=item C<active-text> (string or C<undef>, default C<undef>)
The text of the selected item, or C<undef> if nothing selected.
=item C<append-text> (string, write-only)
=item C<prepend-text> (string, write-only)
Write-only pseudo-properties which add text choices to the combobox as per
the usual C<append_text> and C<prepend_text> methods.
=back
=head1 BUILDABLE
C<Gtk2::Ex::ComboBox::Text> inherits the usual buildable support from
C<Gtk2::ComboBox>, allowing C<Gtk2::Builder> (new in Gtk 2.12) to construct
a Text combobox. The class name is C<Gtk2__Ex__ComboBox__Text> and
properties and signal handlers can be set in the usual way.
The C<append-text> property is a good way to add choices to the combobox
from within the builder specification. Either C<active> or C<active-text>
can set an initial selection. Here's a sample fragment, or see
F<examples/text-builder.pl> in the ComboBoxBits sources for a complete
program.
<object class="Gtk2__Ex__ComboBox__Text" id="combo">
<property name="append-text">First Choice</property>
<property name="append-text">Second Choice</property>
<property name="active">0</property>
</object>
=head1 SEE ALSO
L<Gtk2::ComboBox>,
L<Gtk2::Ex::ComboBoxBits>,
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
Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
lib/Gtk2/Ex/ComboBoxBits.pm view on Meta::CPAN
find_text_iter);
# uncomment this to run the ### lines
#use Smart::Comments;
our $VERSION = 32;
#------------------------------------------------------------------------------
sub get_active_path {
my ($combobox) = @_;
my ($model, $iter);
return (($model = $combobox->get_model)
&& ($iter = $combobox->get_active_iter)
&& $model->get_path ($combobox->get_active_iter));
}
sub set_active_path {
my ($combobox, $path) = @_;
### set_active_path()
# Non-existent rows go to set_active(-1) since the Perl-Gtk2
# set_active_iter() doesn't accept undef (NULL) until 1.240.
# If ready to demand that version could
# $combobox->set_active_iter ($model && $path && $model->get_iter($path));
if ($path) {
if ($path->get_depth == 1) {
# top-level row using set_active()
$combobox->set_active ($path->get_indices);
return;
}
if (my $model = $combobox->get_model) {
if (my $iter = $model->get_iter($path)) {
$combobox->set_active_iter ($iter);
return;
}
}
}
# path=undef, or no model, or path not in model
# FIXME: ->set_active(-1) spits a warning in gtk 2.28 if no model,
# want Gtk2 1.240 for ->set_active_iter(undef)
if ($combobox->get_model) {
$combobox->set_active (-1);
}
}
#------------------------------------------------------------------------------
sub set_active_text {
my ($combobox, $str) = @_;
### ComboBoxBits set_active_text(): $str
if (defined $str && (my $iter = find_text_iter ($combobox, $str))) {
### $iter
$combobox->set_active_iter ($iter);
} else {
# As of Gtk 2.20 set_active() throws a g_log() warning if there's no
# model set. Prefer to quietly do nothing to make no active item when
# already no active item.
if ($combobox->get_model) {
# pending perl-gtk 1.240 set_active_iter() accepting undef
$combobox->set_active (-1);
}
}
### set_active_text() active num now: $combobox->get_active
}
sub find_text_iter {
my ($combobox, $str) = @_;
### ComboBoxBits find_text_iter(): $str
my $ret;
if (my $model = $combobox->get_model) {
$model->foreach (sub {
my ($model, $path, $iter) = @_;
### get_value: $model->get_value ($iter, 0)
if ($str eq $model->get_value ($iter, 0)) {
### found at: $path->to_string
$ret = $iter->copy;
return 1; # stop
}
return 0; # continue
});
}
### $ret
return $ret;
}
1;
__END__
# sub _text_to_nth {
# my ($combobox, $str) = @_;
# if (my @indices = _text_to_indices($combobox, $str)) {
# return $indices[0];
# } else {
# return -1;
# }
# return $n;
# }
# sub _text_to_indices {
# my ($combobox, $str) = @_;
# my @ret;
# if (my $model = $combobox->get_model) {
# $model->foreach (\&_text_to_nth_foreach, \$n);
# }
# return @ret;
# }
# sub _text_to_nth_foreach {
# my ($model, $path, $iter, $aref) = @_;
# if ($str eq $model->get_value ($iter, 0)) {
# @$aref = $path->get_indices;
# return 1; # stop
# }
lib/Gtk2/Ex/ComboBoxBits.pm view on Meta::CPAN
=head1 SYNOPSIS
use Gtk2::Ex::ComboBoxBits;
=head1 FUNCTIONS
=head2 Active Path
=over
=item C<< $path = Gtk2::Ex::ComboBoxBits::get_active_path ($combobox) >>
Return a C<Gtk2::TreePath> to the active item in C<$combobox>, or C<undef>
if empty or no model or nothing active.
=item C<< Gtk2::Ex::ComboBoxBits::set_active_path ($combobox, $path) >>
Set the active item in C<$combobox> to the given C<Gtk2::TreePath>
position. If C<$path> is empty or C<undef> or there's no such row in the
model then C<$combobox> is set to nothing active.
Some versions of ComboBox have a feature where if there's no model in
C<$combobox> then a toplevel active item is remembered ready for a model set
later. Not sure if that's documented, but C<set_active_path> tries to
cooperate by using C<set_active> for toplevels, and C<set_active_iter> for
sub-rows (which don't get the same remembering).
=back
=head2 Text Combos
The following are for use on a simplified "text" ComboBox as created by
C<< Gtk2::ComboBox->new_text() >>.
=over
=item C<< $str = Gtk2::Ex::ComboBoxBits::set_active_text ($combobox, $str) >>
C<$combobox> must be a simplified "text" type ComboBox. Set the entry
C<$str> active.
The corresponding "get" is C<< $combobox->get_active_text() >>, see
L<Gtk2::ComboBox>.
=item C<< $iter = Gtk2::Ex::ComboBoxBits::find_text_iter ($combobox, $str) >>
Return a C<Gtk2::TreeIter> which is the row for C<$str> in a text style
combobox. If C<$str> is not in C<$combobox> then return C<undef>.
=back
=head1 EXPORTS
Nothing is exported by default, but the functions can be requested in usual
C<Exporter> style,
use Gtk2::Ex::ComboBoxBits 'set_active_text';
This can be handy if using C<set_active_text> many times.
C<Gtk2::Ex::ComboBox::Text> imports it to use as an object method.
There's no C<:all> tag since this module is meant as a grab-bag of functions
and to import as-yet unknown things would be asking for name clashes.
=head1 HOME PAGE
L<http://user42.tuxfamily.org/gtk2-ex-comboboxbits/index.html>
=head1 LICENSE
Copyright 2010, 2011 Kevin Ryde
Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
lib/Gtk2/Ex/Menu/EnumRadio.pm view on Meta::CPAN
$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
Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
lib/Gtk2/Ex/ToolItem/ComboEnum.pm view on Meta::CPAN
'Overflow menu mnemonic',
'A mnemonic label string to show in the overflow menu. Default is some mangling of the enum-type.',
(eval {Glib->VERSION(1.240);1}
? undef # default
: ''), # no undef/NULL before Perl-Glib 1.240
Glib::G_PARAM_READWRITE),
];
sub INIT_INSTANCE {
my ($self) = @_;
my $combobox = Gtk2::Ex::ComboBox::Enum->new;
$combobox->show;
$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)
my $combobox;
return (($combobox = $self->get_child) # no child when destroyed, maybe
&& $combobox->get($pname));
}
return $self->{$pname};
}
sub SET_PROPERTY {
my ($self, $pspec, $newval) = @_;
my $pname = $pspec->get_name;
### ComboEnum SET_PROPERTY: $pname, $newval
lib/Gtk2/Ex/ToolItem/ComboEnum.pm view on Meta::CPAN
} else {
$self->{$pname} = $newval;
}
if ($pname eq 'overflow_mnemonic'
|| $pname eq 'enum_type') { # for when showing enum-type as fallback
_update_overflow_mnemonic($self);
}
}
sub _do_combobox_notify {
my ($combobox, $pspec) = @_;
### ComboEnum _do_combobox_notify()
if (my $self = $combobox->parent) { # in case unparented maybe
$self->notify($pspec->get_name);
}
}
sub _do_combobox_notify_add_tearoffs {
my ($combobox, $pspec) = @_;
### ComboEnum _do_combobox_notify_add_tearoffs()
if (my $self = $combobox->parent) { # in case unparented maybe
_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
lib/Gtk2/Ex/ToolItem/ComboEnum.pm view on Meta::CPAN
sub _update_overflow_mnemonic {
my ($self) = @_;
### ComboEnum _update_overflow_mnemonic()
my $menuitem = $self->{'menuitem'} || return;
my $label = $menuitem->get_child || return; # just in case gone
my $str = $self->{'overflow_mnemonic'};
if (! defined $str) {
if (my $combobox = $self->get_child) {
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;
}
return undef;
}
1;
__END__
# Maybe allowing a different ComboBox subclass to be plugged in ...
#
lib/Gtk2/Ex/ToolItem/ComboEnum.pm view on Meta::CPAN
# sub _do_add {
# my ($self, $child) = @_;
# my ($enum_type, $active_nick) = $self->get('enum_type','active_nick');
# shift->signal_chain_from_overridden (@_);
#
# $self->set(enum_type => $enum_type,
# active_nick => $active_nick);
# $self->{'child_ids'} = Glib::Ex::SignalIds->new
# ($child,
# $child->signal_connect ('notify::active-nick'
# => \&_do_combobox_notify_nick));
# }
# sub _do_remove {
# my ($self, $child) = @_;
# delete $self->{'child_ids'};
# shift->signal_chain_from_overridden (@_);
# }
#
# sub ADD_CHILD {
# my ($self, $builder, $child, $type) = @_;
# # replace default combobox created in init
# Gtk2::Ex::ContainerBits::remove_all($self);
# $self->add ($child);
# }
# If doing menu property linkage explicitly instead of ConnectProperties.
#
# if (my $menuitem = $self->get_proxy_menu_item (__PACKAGE__)) {
# $menuitem->get_submenu->set ($pname => $combobox->get('active-nick'));
# }
# $menu->signal_connect ('notify::active-nick'
# => \&_do_menu_notify_nick);
# sub _do_menu_notify_nick {
# my ($menu) = @_;
# if (my $self = $combobox->parent) { # perhaps in case unparented
# $self->notify('active-nick');
# if (my $menuitem = $self->get_proxy_menu_item (__PACKAGE__)) {
# $menuitem->get_submenu->set ($pname => $combobox->get('active-nick'));
# }
# }
# }
=for stopwords enum ParamSpec GType pspec Enum Ryde toolitem combobox Gtk ToolItem ComboBox
=head1 NAME
Gtk2::Ex::ToolItem::ComboEnum -- toolitem with combobox of enum values
=head1 SYNOPSIS
use Gtk2::Ex::ToolItem::ComboEnum;
my $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new
(enum_type => 'Glib::UserDirectory',
overflow_mnemonic => '_Directory',
active_nick => 'home'); # initial selection
=head1 WIDGET HIERARCHY
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
=item C<< $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new (key=>value,...) >>
Create and return a new C<ComboEnum> toolitem widget. Optional key/value
pairs set initial properties per C<< Glib::Object->new >>.
my $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new
(enum_type => 'Gtk2::TextDirection',
active_nick => 'ltr',
overflow_mnemonic => '_Direction');
=item C<< $combobox = $toolitem->get_child >>
The usual C<get_child> method (from L<Gtk2::Bin>) gives the child ComboBox
if you want to set properties etc on it.
=back
=head1 PROPERTIES
=over 4
lib/Gtk2/Ex/ToolItem/ComboEnum.pm view on Meta::CPAN
The C<add-tearoffs> property on the ComboBox child is propagated to the
overflow enum submenu so if there's a tearoff on the ComboBox then there's
also a tearoff on the enum menu.
=head1 BUILDABLE
C<Gtk2::Ex::ToolItem::ComboEnum> can be constructed with C<Gtk2::Builder>
(new in Gtk 2.12). The class name is C<Gtk2__Ex__ToolItem__ComboEnum> and
properties and signal handlers can be set in the usual way.
The child combobox is made available as an "internal child" under the name
"combobox". This can be used to set desired properties on that child (those
not otherwise offered on the ToolItem). Here's a sample fragment, or see
F<examples/tool-enum-builder.pl> in the ComboBoxBits sources for a complete
program.
<object class="Gtk2__Ex__ToolItem__ComboEnum" id="toolitem">
<child internal-child="combobox">
<object class="Gtk2__Ex__ComboBox__Enum" id="blah_combo">
<property name="tooltip-text">Tooltip for the ComboBox</property>
</object>
</child>
</object>
The C<internal-child> means C<< <child> >> is not creating a new child
object, but accessing one already built. The C<< id="blah_combo" >> part is
the name to refer to the child elsewhere in the Builder specification,
including a later C<< $builder->get_object >>. That C<id> be present even
lib/Gtk2/Ex/ToolItem/ComboEnum.pm view on Meta::CPAN
=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
Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
t/ComboBoxBits-import.t view on Meta::CPAN
set_active_text
find_text_iter);
require Gtk2;
Gtk2->disable_setlocale; # leave LC_NUMERIC alone for version nums
Gtk2->init_check
or plan skip_all => 'due to no DISPLAY available';
plan tests => 3;
my $combobox = Gtk2::ComboBox->new;
is (get_active_path($combobox), undef);
is (find_text_iter($combobox, 'nosuchentry'), undef);
set_active_path($combobox,Gtk2::TreePath->new_from_indices(0,0));
set_active_text($combobox,'nosuchentry');
ok(1);
exit 0;
t/ComboBoxBits.t view on Meta::CPAN
"VERSION class check $want_version");
my $check_version = $want_version + 1000;
ok (! eval { Gtk2::Ex::ComboBoxBits->VERSION($check_version); 1 },
"VERSION class check $check_version");
}
#------------------------------------------------------------------------------
# find_text_iter()
{
my $combobox = Gtk2::ComboBox->new;
is (Gtk2::Ex::ComboBoxBits::find_text_iter ($combobox, 'nosuchentry'),
undef);
}
#------------------------------------------------------------------------------
# set_active_text()
{
my $combobox = Gtk2::ComboBox->new;
Gtk2::Ex::ComboBoxBits::set_active_text ($combobox, undef);
is ($combobox->get_active, -1);
}
#------------------------------------------------------------------------------
# set_active_path()
{
my $combobox = Gtk2::ComboBox->new;
Gtk2::Ex::ComboBoxBits::set_active_path ($combobox, undef);
is ($combobox->get_active, -1, 'set_active_path() no model');
my $model = Gtk2::TreeStore->new ('Glib::String');
$model->insert (undef, 0);
$model->insert (undef, 1);
$model->insert (undef, 2);
$model->insert ($model->iter_nth_child(undef,2), 0);
$model->insert ($model->iter_nth_child(undef,2), 1);
$combobox->set_model ($model);
Gtk2::Ex::ComboBoxBits::set_active_path
($combobox, Gtk2::TreePath->new_from_indices(1));
is ($combobox->get_active, 1);
Gtk2::Ex::ComboBoxBits::set_active_path
($combobox, Gtk2::TreePath->new_from_indices(2,1));
{ my $iter = $combobox->get_active_iter;
my $path = $iter && $model->get_path($iter);
my $str = $path && $path->to_string;
is ($str, '2:1');
}
}
#------------------------------------------------------------------------------
# get_active_path()
{
my $combobox = Gtk2::ComboBox->new;
is (Gtk2::Ex::ComboBoxBits::get_active_path($combobox),
undef);
Gtk2::Ex::ComboBoxBits::set_active_path ($combobox, undef);
is (Gtk2::Ex::ComboBoxBits::get_active_path($combobox), undef);
is ($combobox->get_active, -1);
my $model = Gtk2::TreeStore->new ('Glib::String');
$model->insert (undef, 0);
$model->insert (undef, 1);
$model->insert (undef, 2);
$model->insert ($model->iter_nth_child(undef,2), 0);
$model->insert ($model->iter_nth_child(undef,2), 1);
$combobox->set_model ($model);
$combobox->set_active(-1);
is (Gtk2::Ex::ComboBoxBits::get_active_path($combobox),
undef);
$combobox->set_active(0);
{ my $got = Gtk2::Ex::ComboBoxBits::get_active_path($combobox);
is ($got && $got->to_string, '0');
}
$combobox->set_active(2);
{ my $got = Gtk2::Ex::ComboBoxBits::get_active_path($combobox);
is ($got && $got->to_string, '2');
}
$combobox->set_active_iter($model->get_iter(Gtk2::TreePath->new_from_indices
(2,1)));
{ my $got = Gtk2::Ex::ComboBoxBits::get_active_path($combobox);
is ($got && $got->to_string, '2:1');
}
}
exit 0;
t/ToolItem-EnumCombo.t view on Meta::CPAN
$toolitem->set (active_nick => 'foo');
is ($toolitem->get('active-nick'), 'foo', 'set(active-nick) get()');
}
#-----------------------------------------------------------------------------
# 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');
}
exit 0;