Etk::Simple - Simplified function calls for Etk


Etk-Perl documentation Contained in the Etk-Perl distribution.

Index


Code Index:

NAME

Top

Etk::Simple - Simplified function calls for Etk

SYNOPSIS

Top

  use Etk::Simple;
  use Etk::Stock qw/:all/;

  my $button = Etk::Button->new();
  my $button_with_label = Etk::Button->new("This is a label");
  my $button_from_stock = Etk::Button->new(DocumentNew);

DESCRIPTION

Top

Many widgets in Etk have different constructors and require different calls for each type of constructor.

This module tries to simplify this process by providing a single "new" constructor that, depending on the number and type of arguments, calls the required C constructor.

OVERLOADED WIDGETS

Top

The following are the widgets that have had their constructors overloaded. For each widget we list the type/number of arguments it accepts

Etk::Button

	undef - creates an empty button
	string - creates a button with a label
	number - creates a button from stock

Etk::CheckButton

	undef - creates an empty checkbutton
	string - creates a checkbutton with a label

Etk::Image

	undef - creates an empty image
	number,number - creates an image from stock with a stock size
	string,string - creates an image from edje with key
	string - creates an image from file

Etk::Menu::Item

	undef - creates empty menu item
	number - creates menu item from stock
	string - creates menu item with label

Etk::Menu::Item::Check

	undef - creates empty menu item
	string - creates menu item with label

Etk::Menu::Item::Image

	undef - creates empty menu item
	number - creates menu item from stock
	string - creates menu item with label

Etk::Menu::Item::Radio

	undef - creates empty menu item
	object - creates menu item from the specified object
	string - creates menu item with label
	string,object - creates menu item with label from the specified object

Etk::ProgressBar

	undef - creates empty progressbar
	string - creates a progressbar with text

Etk::RadioButton

	undef - creates empty radio button
	object - creates radio button from the specified object
	string - creates radio button with label
	string,object - creates radio button with label from the specified object

Etk::ToolButton

	undef - creates empty tool button
	number - creates tool button from stock
	string - creates tool button with label

Etk::ToolToggleButton

	undef - creates empty tool togglebutton
	number - creates tool togglebutton from stock
	string - creates tool togglebutton with label

Etk::ToggleButton

	undef - creates empty togglebutton
	number - creates togglebutton from stock
	string - creates togglebutton with label

NOTES

Top

Since this module redefines the new() subroutines, it includes a `no warnings 'redefine'` to remove warnings.

AUTHOR

Top

Chady 'Leviathan' Kassouf, <chady.kassouf@gmail.com>

COPYRIGHT AND LICENSE

Top


Etk-Perl documentation Contained in the Etk-Perl distribution.

package Etk::Simple;

no warnings 'redefine';
use strict;
use Etk;

package Etk::Button;

my $bnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;
	return $bnew->(__PACKAGE__) unless defined $arg;
	return NewFromStock($arg)
		if $arg =~ /^\d+$/;
	return NewWithLabel($arg);
};

package Etk::CheckButton;

my $cbnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;
	return NewWithLabel($arg) if $arg;
	return $cbnew->(__PACKAGE__);
};

package Etk::Image;

my $inew = \&new;
*new = sub {
	my $class = shift;
	my $arg1 = shift;
	my $arg2 = shift;
	
	if (defined $arg1) {
		if ($arg1 =~ /^\d+$/) {
			if ($arg2 !~ /^\d+$/) {
				warn "no StockSize defined, using: SizeSmall";
				$arg2 = 0;
			}
			return NewFromStock($arg1, $arg2);
		} else {
			if (defined $arg2) {
				if ($arg1 =~ /\.edj$/) {
					return NewFromEdje($arg1, $arg2);
				} else {
					return NewFromFile($arg1, $arg2); 
				}
			}
		}
	}
			
	return $inew->(__PACKAGE__);
};

my $iset = \&SetFromFile;
*SetFromFile = sub {
	my $class = shift;
	my $arg1 = shift;
	my $arg2 = shift || "";
	
	return $iset->($class, $arg1, $arg2);
};


package Etk::Menu::Item;

my $minew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;

	if (defined $arg) {
		if ($arg =~ /^\d+$/) {
			return NewFromStock($arg);
		} else {
			return NewWithLabel($arg);
		}
	}
	return $minew->(__PACKAGE__);
};

package Etk::Menu::Item::Check;

my $micnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;

	if (defined $arg) {
		return NewWithLabel($arg);
	}
	return $micnew->(__PACKAGE__);
};

package Etk::Menu::Item::Image;

my $miinew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;

	if (defined $arg) {
		if ($arg =~ /^\d+$/) {
			return NewFromStock($arg);
		} else {
			return NewWithLabel($arg);
		}
	}
	return $miinew->(__PACKAGE__);
};

package Etk::Menu::Item::Radio;

my $mirnew = \&new;
*new = sub {
	my $class = shift;
	my $arg1 = shift;
	my $arg2 = shift;

	if (defined $arg1) {
		if (ref $arg1 && $arg1->isa("Etk::Widget")) {
			return NewFromWidget($arg1);
		} else {
			if (ref $arg2 && $arg2->isa("Etk::Widget")) {
				return NewWithLabelFromWidget($arg1, $arg2);
			} else {
				return NewWithLabel($arg1);
			}
		}
	}
	return $mirnew->(__PACKAGE__);
};


package Etk::ProgressBar;

my $pnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;
	if (defined $arg) {
		return NewWithText($arg);
	} 

	return $pnew->(__PACKAGE__);
};

package Etk::RadioButton;

my $rbnew = \&new;
*new = sub {
	my $class = shift;
	my $arg1 = shift;
	my $arg2 = shift;

	if (defined $arg1) {
		if (ref $arg1 && $arg1->isa("Etk::Widget")) {
			return NewFromWidget($arg1);
		} else {
			if (ref $arg2 && $arg2->isa("Etk::Widget")) {
				return NewWithLabelFromWidget($arg1, $arg2);
			} else {
				return NewWithLabel($arg1);
			}
		}
	}
	return $rbnew->(__PACKAGE__);
};

package Etk::ToolButton;

my $tbnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;

	if (defined $arg) {
		if ($arg =~ /^\d+$/) {
			return NewFromStock($arg);
		} else {
			return NewWithLabel($arg);
		}
	}
	return $tbnew->(__PACKAGE__);
};

package Etk::ToolToggleButton;

my $ttbnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;

	if (defined $arg) {
		if ($arg =~ /^\d+$/) {
			return NewFromStock($arg);
		} else {
			return NewWithLabel($arg);
		}
	}
	return $ttbnew->(__PACKAGE__);
};


package Etk::ToggleButton;

my $tnew = \&new;
*new = sub {
	my $class = shift;
	my $arg = shift;

	if (defined $arg) {
		return NewWithLabel($arg);
	}
	return $tnew->(__PACKAGE__);
};


1;

__END__