- WIDGET HIERARCHY
- SEE ALSO
- HOME PAGE
Gtk2::Ex::Menu::EnumRadio -- menu of enum values as radio items
use Gtk2::Ex::Menu::EnumRadio; my $menu = Gtk2::Ex::Menu::EnumRadio->new (enum_type => 'Glib::UserDirectory', active_nick => 'home'); # initial selection
Gtk2::Ex::Menu::EnumRadio is a subclass of
Gtk2::Widget Gtk2::Container Gtk2::MenuShell Gtk2::Menu Gtk2::Ex::Menu::EnumRadio
Gtk2::Ex::Menu::EnumRadio displays the values of a
Glib::Enum in a menu as a radio group allowing the user to select one of them. The
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 Glib::Ex::EnumBits
to_display(), so an enum class can arrange how its values appear, or the default is a sensible word split and capitalization.
(There's a secret experimental might change in the future
nick-to-display signal for per-instance control of the display. A signal is good for a callback, but some care may be needed to have it connected early enough, or for the calls to be made later than when
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.
For reference, in the current code the menu items are a private subclass of
Gtk2::CheckMenuItem. They're not
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
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
Gtk2::TearoffMenuItem or equivalent like
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.
Create and return a new
EnumRadiomenu object. Optional key/value pairs set initial properties per
my $menu = Gtk2::Ex::Menu::EnumRadio->new (enum_type => 'Gtk2::TextDirection', active_nick => 'ltr');
Return the nick of the currently selected enum value, or
undefif nothing selected. This is the
Set the enum value selected, by its nick, or
undefto select nothing. This is the
In the current code if
$stris not a nick in the current
set_active_nick(and the property setting) quietly set to nothing selected. Perhaps this will change.
enum-type(type name, default
The enum type to display and select from. Until this is set the Menu is empty.
enum-typeif the current selected
active-nickalso exists in the new type then it remains selected (possibly a different menu item). If the
active-nickdoesn't exist in the new type then the menu changes to nothing selected.
This property is a
Glib::Param::GTypewhen possible or
Glib::Param::Stringotherwise. 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 enum.
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 menu or no
enum-typehas been set then
There's no default for
active-nick, so when creating an Enum menu it's usual to set the desired initial selection.
enum-type paramspec default is not the actual default
undef (in particular when it's a
# this should be undef, usually isn't $menu->find_property('enum-type')->get_default_value
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.
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/.