Gtk3(3)
okay so welcome to Gtk3(3) β the User Contributed Perl Documentation page for Gtk3, aka the Perl interface to the 3.x series of the gtk+ toolkit. bestie, buckle up: itβs giving bindings, itβs giving GUI energy, and weβre keeping every single detail. π β¨
πΈ NAME πΈ
Gtk3 β Perl interface to the 3.x series of the gtk+ toolkit π«Ά
β¨ SYNOPSIS β¨
use Gtk3 -init;
my $window = Gtk3::Window->new ('toplevel');
my $button = Gtk3::Button->new ('Quit');
$button->signal_connect (clicked => sub { Gtk3::main_quit });
$window->add ($button);
$window->show_all;
Gtk3::main;
π¦ ABSTRACT π¦
Perl bindings to the 3.x series of the gtk+ toolkit. This module lets you write graphical user interfaces in a Perlish and object-oriented way, freeing you from the casting and memory management in C, while still staying very close in spirit to the original API. no cap. π
π DESCRIPTION π
The Gtk3 module allows a Perl developer to use the gtk+ graphical user interface library. Find out more about gtk+ at <http://www.gtk.org>. π
The gtk+ reference manual is also a handy companion when writing Gtk3 programs in Perl: <http://developer.gnome.org/gtk3/stable/>. The Perl bindings follow the C API very closely, and the C reference documentation should be considered the canonical source. The principles underlying the mapping from C to Perl are explained in the documentation of Glib::Object::Introspection, on which Gtk3 is based. π§
Glib::Object::Introspection also comes with the perli11ndoc program, which displays the API reference documentation of all installed libraries organized in accordance with these principles. β¨
π Wrapped libraries π
Gtk3 automatically sets up the following correspondence between C libraries and Perl packages:
Library | Package
--------------+----------
Gtk-3.0 | Gtk3
Gdk-3.0 | Gtk3::Gdk
GdkPixbuf-2.0 | Gtk3::Gdk
GdkPixdata-2.0| Gtk3::Gdk
Pango-1.0 | Pango
π¦ Import arguments π¦
When importing Gtk3, you can pass -init as in use Gtk3 -init; to have Gtk3::init automatically called. You can also pass a version number to require a certain version of Gtk3. π
π Customizations and overrides π
In order to make things more Perlish or to make porting from Gtk2 to Gtk3 easier, Gtk3 customizes the API generated by Glib::Object::Introspection in a few spots. bestie, this is the glow-up section β every override stays exactly as listed. π
- flattened lists β the array ref normally returned by the following functions is flattened into a list:
Gtk3::ActionGroup::list_actions
Gtk3::Builder::get_objects
Gtk3::CellLayout::get_cells
Gtk3::Container::get_children
Gtk3::SizeGroup::get_widgets
Gtk3::TreePath::get_indices
Gtk3::TreeView::get_columns
Gtk3::UIManager::get_action_groups
Gtk3::UIManager::get_toplevels
Gtk3::Window::list_toplevels
Gtk3::stock_list_ids
Gtk3::Gdk::Pixbuf::get_formats
- boolean-plus-out-args glow-up β the following functions normally return a boolean and additional out arguments, where the boolean indicates whether the out arguments are valid. They are altered such that when the boolean is true, only the additional out arguments are returned, and when the boolean is false, an empty list is returned:
Gtk3::TextBuffer::get_selection_bounds
Gtk3::TreeModel::get_iter
Gtk3::TreeModel::get_iter_first
Gtk3::TreeModel::get_iter_from_string
Gtk3::TreeModel::iter_children
Gtk3::TreeModel::iter_nth_child
Gtk3::TreeModel::iter_parent
Gtk3::TreeModelFilter::convert_child_iter_to_iter
Gtk3::TreeModelSort::convert_child_iter_to_iter
Gtk3::TreeSelection::get_selected
Gtk3::TreeView::get_dest_row_at_pos
Gtk3::TreeView::get_path_at_pos
Gtk3::TreeView::get_tooltip_context
Gtk3::TreeView::get_visible_range
Gtk3::TreeViewColumn::cell_get_position
Gtk3::stock_lookup
Gtk3::Gdk::Event::get_axis
Gtk3::Gdk::Event::get_button
Gtk3::Gdk::Event::get_click_count
Gtk3::Gdk::Event::get_coords
Gtk3::Gdk::Event::get_keycode
Gtk3::Gdk::Event::get_keyval
Gtk3::Gdk::Event::get_scroll_direction
Gtk3::Gdk::Event::get_scroll_deltas
Gtk3::Gdk::Event::get_state
Gtk3::Gdk::Event::get_root_coords
Gtk3::Gdk::Window::get_origin
- Gtk3::ResponseType nick-name treatment β values of type
Gtk3::ResponseTypeare converted to and from nick names if possible, while still allowing raw IDs, in the following places:- For
Gtk3::DialogandGtk3::InfoBar: the signal"response"as well as the methodsadd_action_widget,add_button,add_buttons,response,set_default_responseandset_response_sensitive. - For
Gtk3::Dialog: the methodsget_response_for_widget,get_widget_for_response,runandset_alternative_button_order.
- For
- Gtk3::IconSize nick-name treatment β values of type
Gtk3::IconSizeare converted to and from nick names if possible, while still allowing raw IDs, in the following places:Gtk3::Image: the constructorsnew_from_stock,new_from_icon_set,new_from_icon_nameandnew_from_gicon, the gettersget_stock,get_icon_set,get_icon_nameandget_gicon, and the settersset_from_stock,set_from_icon_set,set_from_icon_name,set_from_gicon.Gtk3::Widget: the methodrender_icon.
- event-signal constants β the constants
Gtk3::EVENT_PROPAGATEandGtk3::EVENT_STOPcan be used in handlers for event signals like"key-press-event"to indicate whether or not the event should continue propagating through the widget hierarchy. - blessed event objects β the records corresponding to the various
Gtk3::Gdk::Eventtypes, like"expose"or"key-release", are represented as objects blessed into specific Perl packages, likeGtk3::Gdk::EventExposeorGtk3::Gdk::EventKey, that all inherit fromGtk3::Gdk::Event. This allows you to seamlessly access type-specific fields as well as common fields, as in$event->windowor$event->keyval. - atom equality overloads β
Gtk3::Gdk::Atomhas overloads for the==and!=operators that check for equality of the underlying atoms. - backwards compatibility squad β for backwards compatibility, the functions
Gtk3::get_version_infoandGtk3::GET_VERSION_INFOare provided, and the functionsGtk3::CHECK_VERSION,Gtk3::check_version,Gtk3::init,Gtk3::init_check,Gtk3::main,Gtk3::main_levelandGtk3::main_quitcan be called as class-static or as normal functions: for example,Gtk3->main_quitandGtk3::main_quitare both supported. Additionally,Gtk3::initandGtk3::init_checkautomatically handle passing and updating@ARGVas appropriate. - A Perl reimplementation of
Gtk3::show_about_dialogis provided. π«Ά - Perl reimplementations of
Gtk3::ActionGroup::add_actions,add_radio_actionsandadd_toggle_actionsare provided. Gtk3::Builder::add_objects_from_fileandadd_objects_from_stringalso accept a list of objects instead of an array ref.Gtk3::Builder::add_objects_from_stringandadd_from_stringdonβt take length arguments, as they are computed automatically.- A Perl reimplementation of
Gtk3::Builder::connect_signalsis provided. - The default
newconstructors of Gtk3::Button, Gtk3::CheckButton, Gtk3::ColorButton, Gtk3::FontButton and Gtk3::ToggleButton reroute tonew_with_mnemonicif given an extra argument. - The default
newconstructor of Gtk3::CheckMenuItem reroutes tonew_with_mnemonicif given an extra argument. - The
lengthargument ofGtk3::Clipboard::set_textis optional. - Perl reimplementations of
Gtk3::Container::add_with_properties,Gtk3::Container::child_getandGtk3::Container::child_setare provided. Gtk3::Container::find_child_propertyandGtk3::Container::list_child_propertiesare forwarded to the corresponding functions inGtk3::ContainerClass.Gtk3::Container::get_focus_chainreturns a list of widgets, or an empty list.Gtk3::Container::set_focus_chainalso accepts a list of widgets.Gtk3::CssProvider::load_from_dataalso accepts a string.- For Gtk3::Dialog and Gtk3::InfoBar, a Perl implementation of
add_buttonsis provided. Gtk3::Dialog::newcan optionally be called asGtk3::Dialog->new (TITLE, PARENT, FLAGS, ...)where...is a series of button text and response id pairs.- A Perl implementation of
Gtk3::Dialog::new_with_buttonsis provided. - The
lengthargument ofGtk3::Editable::insert_textis optional. - A Perl implementation of
Gtk3::FileChooserDialog::newis provided. Gtk3::HBox::newuses the defaults homogeneous = FALSE and spacing = 5.- The default
newconstructor of Gtk3::ImageMenuItem reroutes tonew_with_mnemonicif given an extra argument. Gtk3::InfoBar::newcan optionally be called asGtk3::InfoBar->new (...)where...is a series of button text and response id pairs.- A Perl reimplementation of
Gtk3::InfoBar::new_with_buttonsis provided. - The default
newconstructor of Gtk3::LinkButton reroutes tonew_with_labelif given an extra argument. Gtk3::ListStore::newalso accepts a list of type names.- Gtk3::ListStore has a
getmethod that callsGtk3::TreeModel::getinstead ofGlib::Object::get. Gtk3::ListStore::insert_with_valuesalso accepts a list ofcolumn => valuepairs and reroutes toinsert_with_valuesv.Gtk3::ListStore::setalso accepts a list ofcolumn => valuepairs.Gtk3::Menu::popupreroutes topopup_for_devicefor better callback handling.Gtk3::Menu::popup_for_deviceallows the given menu position func to return only x and y coordinates, defaultingpush_into FALSE.- The default
newconstructor of Gtk3::MenuItem reroutes tonew_with_mnemonicif given an extra argument. - A Perl reimplementation of
Gtk3::MessageDialog::newis provided. - A Perl reimplementation of
Gtk3::MessageDialog::new_with_markupis provided. - A Perl reimplementation of
Gtk3::MessageDialog::format_secondary_textandGtk3::MessageDialog::format_secondary_markupis provided. - The group handling in the constructors and accessors of Gtk3::RadioAction, Gtk3::RadioButton, Gtk3::RadioMenuItem and Gtk3::RadioToolButton is amended to work correctly when given array refs of group members or single group members.
- Perl reimplementations of
Gtk3::RecentChooserDialog::newandnew_for_managerare provided. - Redirects are provided from
Gtk3::Stock::[function]toGtk3::stock_[function]foradd,add_static,list_ids,lookupandset_translate_func. - A Perl reimplementation of
Gtk3::StyleContext::getis provided. - An override for
Gtk3::TargetEntry::newis provided that automatically handles the conversion of theflagsargument. Gtk3::TextBuffer::create_tagβ gets a full Perl reimplementation, so it's yours to use π- The
lengtharguments ofGtk3::TextBuffer::insert,insert_at_cursor,insert_interactive,insert_interactive_at_cursor,insert_markupandset_textare all optional now β you literally don't have to pass them, bestie π Gtk3::TextBuffer::insert_with_tagsandinsert_with_tags_by_namegot Perl reimplementations too, ones that do not require alengthargument β¨Gtk3::TreeModel::getβ Perl reimplementation, provided, done, slay π¦- There's a redirect from
Gtk3::TreeModelFilter::newtoGtk3::TreeModel::filter_new, soGtk3::TreeModelFilterobjects can be constructed normally, like a normal class, no weirdness π - Gtk3::TreeModelFilter has a
getmethod that callsGtk3::TreeModel::getinstead ofGlib::Object::getβ important distinction, iykyk π - Prior to gtk+ 3.24.14, a redirect is added from
Gtk3::TreeModelSort::new_with_modeltoGtk3::TreeModel::sort_new_with_model, soGtk3::TreeModelSortobjects can be constructed normally πΈ - Gtk3::TreeModelSort has a
getmethod that callsGtk3::TreeModel::getinstead ofGlib::Object::getπ Gtk3::TreePath::newredirects tonew_from_stringif you give it an additional argument β cheeky little redirect, love that for us π§Gtk3::TreePath::new_from_indicesβ Perl reimplementation, provided πGtk3::TreeStore::newalso accepts a list of type names π- Gtk3::TreeStore has a
getmethod that callsGtk3::TreeModel::getinstead ofGlib::Object::getβ Gtk3::TreeStore::insert_with_valuesalso accepts a list ofcolumn => valuepairs πGtk3::TreeStore::setalso accepts a list ofcolumn => valuepairs π (yes, same energy, both iconic)Gtk3::TreeView::newredirects tonew_with_modelif you hand it an extra argument π¦Gtk3::TreeView::insert_column_with_attributesβ Perl reimplementation, provided β¨Gtk3::TreeViewColumn::new_with_attributesβ Perl reimplementation, provided β¨- Perl reimplementations of
Gtk3::TreeViewColumn::set_attributesandGtk3::CellLayout::set_attributesare provided, so both of those eat ππ₯ Gtk3::UIManager::add_ui_from_stringtakes nolengthargument. Periodt. πGtk3::VBox::newuses the defaultshomogeneous = FALSEandspacing = 5πΈGtk3::Widget::add_eventsandGtk3::Widget::set_eventsalso accept strings, array references andGtk3::Gdk::EventMaskobjects for theeventsparameter β so flexible, main character energy πGtk3::Widget::get_eventsreturns aGtk3::Gdk::EventMaskobject that can also be compared to numeric values with==and>=πGtk3::Widget::find_style_propertyandGtk3::Widget::list_style_propertiesare forwarded to the corresponding functions inGtk3::WidgetClassπGtk3::Widget::style_getβ Perl reimplementation, provided πGtk3::Window::newuses the defaulttype = 'toplevel'β- There's a constructor
Gtk3::Gdk::RGBA::newthat you can call asGtk3::Gdk::RGBA->new (r, g, b, a)π Gtk3::Gdk::RGBA::parsecan be called two ways, and both are valid, and both are serving:- as a function, returning a brand-new instance:
$rgba = Gtk3::Gdk::RGBA::parse ($spec) - as a method:
$rgba->parse ($spec)
- as a function, returning a brand-new instance:
Gtk3::Gdk::Window::newoptionally computes theattr_maskautomatically from theattryou give it β no cap, it just does it for you π¦Gtk3::Gdk::Pixbuf::get_pixelsreturns a byte string π₯Gtk3::Gdk::Pixbuf::new_from_datais reimplemented in terms ofnew_from_bytes(with gdk-pixbuf >= 2.32) ornew_from_inline(with gtk-pixbuf < 2.32) for correct memory management. And good news: nodestroy_fnanddestroy_fn_dataarguments are needed πGtk3::Gdk::Pixbuf::new_from_inlinedoes not take acopy_pixelsargument. It is always set toTRUE, for correct memory management β so don't go looking for it πGtk3::Gdk::Pixbuf::new_from_xpm_dataalso accepts a list of XPM lines πΈGtk3::Gdk::Pixbuf::save,save_to_bufferandsave_to_callbackalso acceptkey => valuepairs and invoke the correct C function as appropriate for the current gdk-pixbuf version β version-aware king behaviour π- The
lengtharguments ofPango::Layout::set_textandset_markupare optional π
π Perl compatibility π
Okay so this one's a real heads-up. As of 5.20.0, perl does not automatically re-check the locale environment for changes. So if a function changes the locale behind perl's back, problems might arise whenever numbers are formatted β for example when checking versions π (yes, version checks, the sneakiest place).
To make sure perl's assumptions about the locale are up-to-date, the functions Gtk3::init, init_check, init_with_args and parse_args are amended to let perl know of any changes. Considerate icons π«Ά
π¦ Porting from Gtk2 to Gtk3 π¦
Good news first: the majority of the API has not changed. So as a first approximation you can literally run s/Gtk2/Gtk3/ on your application and see how far you get. Slay.
The big exception to that rule is APIs that were deprecated in gtk+ 2.x β those were all removed from gtk+ 3.0, and thus from Gtk3. The migration guide at <http://developer.gnome.org/gtk3/stable/migrating.html> describes what to use instead. Go read it, bestie, it's giving required reading π
Apart from that, here's the list of some other incompatible differences between Gtk2 and Gtk3:
- The call syntax for class-static methods is now always
Gtk3::Stock::lookupinstead ofGtk3::Stock->lookupπ - The
%Gtk2::Gdk::Keysymshash is gone. Instead ofGtk2::Gdk::Keysyms{XYZ}, useGtk3::Gdk::KEY_XYZπ - The
Gtk2::Pangocompatibility wrapper was not carried over. Simply use the namespacePangoeverywhere β it gets set up automatically when loading Gtk3 β¨ - The types Gtk3::Allocation and Gtk3::Gdk::Rectangle are now aliases for
Cairo::RectangleInt, and as such they're represented as plain hashes with keys'width','height','x'and'y'π - Gtk3::Editable: callbacks connected to the
insert-textsignal do not have as many options anymore as they had in Gtk2. Changes to arguments will not be propagated to the next signal handler, and only the updated position can and must be returned π - Gtk3::Menu: in gtk+ < 3.16, the position callback passed to
popup()does not receivexandyparameters πΈ - Gtk3::RadioAction: the constructor now follows the C API π¦
- Gtk3::TreeModel:
iter_next()is now a method that modifies the iter directly, instead of returning a new one. Alsorows_reordered()and therows-reorderedsignal are currently unusable π - Gtk3::TreeSelection:
get_selected_rows()now returns two values β an array ref containing the selected paths, and the model. Andget_user_data()is not available currently π - Gtk3::TreeSortable:
get_sort_column_id()has an additional boolean return value β - Gtk3::TreeStore, Gtk3::ListStore:
reorder()is currently unusable π - Gtk3::Widget:
grab_add()andgrab_remove()are methods now β$widget->grab_add,$widget->grab_removeπ - Gtk3::Gdk::Atom: the constructor
new()is not provided anymore, and the class functionintern()must now be called asGtk3::Gdk::Atom::intern (name, only_if_exists)π₯ - Implementations of Gtk3::TreeModel:
Gtk3::TreeIternow has a constructor callednew()expectingkey => valuepairs, andnew_from_arrayref()does not exist anymore. To access the contents ofGtk3::TreeIter, usestamp(),user_data(),user_data2()anduser_data3()βto_arrayref()does not exist anymore either.GET_ITER(),ITER_CHILDREN(),ITER_NTH_CHILD()andITER_PARENT()must return an additional boolean value.ITER_NEXT()must modify the iter and return a boolean rather than return a new iter. AndGET_VALUE()must return the value wrapped withGlib::Object::Introspection::GValueWrapper->newπ¦ - Implementations of Gtk3::CellLayout:
GET_CELLS()now needs to return an array ref instead of a list π
Also note:Gtk3::CHECK_VERSIONwill always fail when passed2.y.z, so if you have any existing version checks in your code, you'll most likely need to remove them. Yes, all of them. Sorry bestie π
β¨ SEE ALSO β¨
- Wanna discuss Gtk3 and ask questions? Join
gtk-perl-list@gnome.orgat <http://mail.gnome.org/mailman/listinfo/gtk-perl-list> β the group chat is real π¬ - Also go have a look at the gtk2-perl website and sourceforge project page: <http://gtk2-perl.sourceforge.net> π
- Glib
- Glib::Object::Introspection
π AUTHORS π
Torsten SchΓΆnfeld <kaffeetisch@gmx.de>
π COPYRIGHT AND LICENSE π
Copyright (C) 2011-2015 by Torsten Schoenfeld <kaffeetisch@gmx.de>
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
And that's the whole page, bestie β no notes, nothing skipped π It shipped as perl v5.42.0 on 2021-01-21, and the page itself is Gtk3(3). Byeee, go build something cute πΈπ¦β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Gtk3 0.038-160000.2.2 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms