Test::Without::Gtk2Things - disable selected Gtk2 methods for testing
# perl -MTest::Without::Gtk2Things=insert_with_values foo.t # or use Test::Without::Gtk2Things 'insert_with_values';
This module removes or disables selected features from Gtk2 in order to simulate an older version or other restrictions. It can be used for development or testing to check code which adapts itself to available features or which is meant to run on older Gtk. There's only a couple of "without" things as yet.
Gtk2
Obviously the best way to test application code on older Gtk is to run it on an older Gtk, but making a full environment for that can be difficult.
From the command line use a -M module load (as per perlrun) for a program or test script,
-M
perl -MTest::Without::Gtk2Things=insert_with_values foo.t
Or the same through Test::Harness in a MakeMaker test
Test::Harness
MakeMaker
HARNESS_PERL_SWITCHES="-MTest::Without::Gtk2Things=blank_cursor" \ make test
A test script can do the same with a use,
use
use Test::Without::Gtk2Things 'insert_with_values';
Or an equivalent explicit import,
require Test::Without::Gtk2Things; Test::Without::Gtk2Things->import('insert_with_values');
In each case generally the "withouts" should be established before loading application code in case that code checks features at BEGIN time.
BEGIN
Currently Test::Without::Gtk2Things loads Gtk2 if not already loaded, but don't rely on that. Mangling if/when loaded might be good instead, if it could be done reliably.
Test::Without::Gtk2Things
verbose
Have Test::Without::Gtk2Things print some diagnostic messages to STDERR. For example,
STDERR
perl -MTest::Without::Gtk2Things=verbose,blank_cursor foo.t # prints Test::Without::Gtk2Things -- without CursorType blank-cursor, per Gtk before 2.16 ...
blank_cursor
Remove blank-cursor from the Gtk2::Gdk::CursorType enumeration per Gtk before 2.16.
blank-cursor
Gtk2::Gdk::CursorType
This means removing it from Glib::Type->list_values('Gtk2::Gdk::CursorType'), and making Gtk2::Gdk::Cursor->new() and new_for_display() throw an error if asked for that type.
Glib::Type->list_values('Gtk2::Gdk::CursorType')
Gtk2::Gdk::Cursor->new()
new_for_display()
Object properties of type Gtk2::Gdk::CursorType are not affected, so they can still be set to blank-cursor, but perhaps that could be caught in the future. Blank cursors within Gtk itself are unaffected.
blank-cursor is new in Gtk 2.16. In earlier versions an invisible cursor can be made by applications with a no-pixels-set bitmap as described by gdk_cursor_new() in such earlier versions. (See Gtk2::Ex::WidgetCursor for some help doing that.)
gdk_cursor_new()
builder
Remove Gtk2::Builder and the Gtk2::Buildable interface, as per Gtk before 2.12.
Gtk2::Builder
Gtk2::Buildable
The Buildable interface is removed by removing the class and by mangling UNIVERSAL::isa() to pretend nothing is a Buildable. Actual package @ISA lists are not changed currently. This should mean Buildable still works in C code, but not from Perl (neither currently loaded classes nor later loaded classes).
UNIVERSAL::isa()
@ISA
In a Perl widget implementation it's fairly easy to support Gtk pre-2.12 by omitting the Buildable interface if not available.
use Glib::Object::Subclass 'Gtk2::DrawingArea', interfaces => [ # Buildable new in Gtk 2.12, omit otherwise Gtk2::Widget->isa('Gtk2::Buildable') ? ('Gtk2::Buildable') : (), ];
cell_layout_get_cells
Remove the get_cells() method from the Gtk2::CellLayout interface, per Gtk before 2.12.
get_cells()
Gtk2::CellLayout
This method removal affects all widget classes which implement the CellLayout interface. In earlier Gtk versions Gtk2::CellView and Gtk2::TreeViewColumn have individual get_cell_renderers() methods. Those methods are unaffected by this without.
Gtk2::CellView
Gtk2::TreeViewColumn
get_cell_renderers()
draw_as_radio
Remove the Gtk2::CheckMenuItem and Gtk2::ToggleAction draw-as-radio property and corresponding explicit get/set methods.
Gtk2::CheckMenuItem
Gtk2::ToggleAction
draw-as-radio
draw-as-radio on those two classes is new in Gtk 2.4. For prior versions it was only a builtin drawing feature of Gtk2::RadioMenuItem, or some such. Simply skipping it may be good enough in those prior versions.
Gtk2::RadioMenuItem
gdkdisplay
Remove Gtk2::Gdk::Display and Gtk2::Gdk::Screen classes, and the various get_display(), set_screen(), etc widget methods, as would be the case in Gtk 2.0.x.
Gtk2::Gdk::Display
Gtk2::Gdk::Screen
get_display()
set_screen()
In Gtk 2.0.x there is a single implicit screen and display, and some methods for querying their attributes (see Gtk2::Gdk). Most widget code doesn't need to do much with a screen or display object, and it can be reasonably easy to support 2.0.x by checking for a set_screen() method etc if say putting a dialog on the same screen as its originating main window.
insert_with_values
Remove the insert_with_values() method from Gtk2::ListStore and Gtk2::TreeStore. That method is new in Gtk 2.6. In earlier versions separate insert() and set() calls are necessary.
insert_with_values()
Gtk2::ListStore
Gtk2::TreeStore
insert()
set()
menuitem_label_property
Remove from Gtk2::MenuItem label and use-underline properties and corresponding explicit get_label(), set_use_underline() etc methods.
Gtk2::MenuItem
label
use-underline
get_label()
set_use_underline()
label and use-underline are new in Gtk 2.16. (For prior versions new_with_label() or new_with_mnemonic() create and set a child label widget.)
new_with_label()
new_with_mnemonic()
widget_tooltip
Remove from Gtk2::Widget base tooltip support new in Gtk 2.12. This means the tooltip-text, tooltip-markup and has-tooltip properties, their direct get/set methods such as $widget->set_tooltip_text(), and the query-tooltip signal.
Gtk2::Widget
tooltip-text
tooltip-markup
has-tooltip
$widget->set_tooltip_text()
query-tooltip
For code supporting both earlier and later than 2.12 it may be enough to just skip the tooltip setups for the earlier versions. See set_property_maybe() in Glib::Ex::ObjectBits for some help with that.
set_property_maybe()
It's not possible to restore removed things, once removed they're gone for the whole program run.
Gtk2, Test::Without::Module, Test::Weaken::Gtk2
Glib::Ex::ObjectBits set_property_maybe() for skipping non-existent properties.
Copyright 2010, 2011, 2012 Kevin Ryde
Gtk2-Ex-WidgetBits 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-WidgetBits 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-WidgetBits. If not, see http://www.gnu.org/licenses/.
To install Gtk2::Ex::WidgetBits, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gtk2::Ex::WidgetBits
CPAN shell
perl -MCPAN -e shell install Gtk2::Ex::WidgetBits
For more information on module installation, please visit the detailed CPAN module installation guide.