NAME

Tk::MenuDialog - A Moo based object oriented interface for creating and display a dialog of buttons to be used as a menu using Tk

VERSION

Version 0.05

SYNOPSIS

  use Tk::MenuDialog;
  use File::Basename qw(dirname);

  my $menu = Tk::MenuDialog->new;

  ## Add the script's directory to the icon path
  ## when searching for icon files
  $menu->add_icon_path(dirname(__FILE__));
  
  ## Add menu items to the menu
  $menu->add_item(
    label => qq{&Configure},
    icon  => qq{settings.png},
    );
  $menu->add_item(
    label => qq{&Run Tests},
    icon  => qq{run.png},
    );
    
  ## Allow operator to cancel the menu
  $menu->can_cancel(1);
  
  ## Display the menu and return hash reference of the selected item, 
  ## or UNDEF if canceled
  my $selection = $menu->show;

ATTRIBUTES

title

    Title of the menu

    DEFAULT: ''

can_cancel

    Indicates if the operator can close the dialog without a selection

    DEFAULT: 1

cancel_on_escape

    Boolean value indicating if pressing the Escape key should simulate closing the window and canceling the dialog.

    DEFAULT: 1

items

    Array reference of items contained in this menu.

icon_path

    An array containing various paths to use when locating icon image files.

button_font

    Font to use for the buttons.

    DEFAULT: 'times 10'

button_spacing

    Number of pixels between each button

    DEFAULT: 0

min_width

    Minimum width of the dialog.

    DEFAULT: 300

min_height

    Minimum height of the dialog.

    DEFAULT: 80

METHODS

add_item($hash)

Description

Add a field to the form.

Parameters

A hash reference with the following key / value pairs: label - Required paramater with icon - Optional filename of the icon to display icon_location - Optional location relative to button text for the icon DEFAULT: "left"

Return

UNDEF on error, or the hash reference of the item created

show()

Description

Show the dialog as a new MainWindow.

The function will return if the users cancels the dialog or clicks a button

Parameters

NONE

Return

UNDEF when canceled, or the hash reference associated with the button clicked.

add_icon_path()

Description

Description goes here

Parameters

NONE

Return

NONE

initialize($param)

Description

initialize the form from a HASH reference, JSON string, or JSON file. In all cases, the hash should have the following format

  {
    title      => 'My Menu',
    can_cancel => 0,
    items => [
      {
        label => '&Configure',
        icon  => 'settings.png',
      },
      {
        label => '&Run',
        icon  => 'run.png',
      },
      {
        label => 'E&xit',
        icon  => 'exit.png',
      },
    ]
  }
Parameters

$param - HASH reference, or scalar containin JSON string, or filename

Return

NONE

AUTHOR

Paul Durden <alabamapaul AT gmail.com>

COPYRIGHT & LICENSE

Copyright (C) 2015 by Paul Durden.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.