Scott Lanning > Wx-WidgetMaker-0.11 > Wx::WidgetMaker

Download:
Wx-WidgetMaker-0.11.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.11   Source  

NAME ^

Wx::WidgetMaker - a CGI.pm-like library for wxPerl

SYNOPSIS ^

    use Wx::WidgetMaker;

    $dialog = Wx::Dialog->new(...);
    $q = Wx::WidgetMaker->new(-parent => $dialog);

    # The dialog "page"
    $pagesizer = Wx::BoxSizer->new(wxVERTICAL);

    # A "row" in the page
    $rowsizer = Wx::BoxSizer->new(wxHORIZONTAL);

    # "print" a control to a row
    $ctrl = $q->h1('H1 text');
    $q->print($ctrl, $rowsizer);

    # Add the row to the page
    $q->print($rowsizer, $pagesizer);

    # A new row
    $rowsizer = Wx::BoxSizer->new(wxHORIZONTAL);

    # print a label and textfield in an array
    $ctrl2 = $q->password_field(
        -name => 'password',
        -default => 'blue',
        -size => 50,         # window width, not number of chars
        -maxlength => 30,
    );
    $q->print([$q->print('Password: '), $ctrl2], $rowsizer);

    # Add the row to the page
    $q->print($rowsizer, $pagesizer);

    # Add some buttons
    $rowsizer = Wx::BoxSizer->new(wxHORIZONTAL);

    $okbutton = $q->submit('ok', 'OK', wxID_OK);
    $cancelbutton = $q->submit('cancel', 'Cancel', wxID_CANCEL);
    $q->print([$okbutton, $cancelbutton], $rowsizer);

    $q->print($rowsizer, $pagesizer);

    # Put widgets in the dialog as normal
    $dialog->SetAutoLayout(1);
    $dialog->SetSizer($pagesizer);
    $pagesizer->Fit($dialog);

    # Get dialog data
    if ($dialog->ShowModal() == wxID_OK) {
        $password = $q->param('password');
    }
    $dialog->Destroy();

DESCRIPTION ^

When starting to learn wxPerl, it can be frustrating trying to figure out which widgets handle what functionality. If you've ever done CGI development, you soon realize why it's not a bad idea to leverage the web browser as a graphical user interface: it can be complicated to implement functionality that you take for granted as an HTML/CGI developer.

This module tries to make implementing wxPerl dialogs friendlier to a Perl CGI programmer by using an API similar to CGI.pm. (Specifically, it supports what I consider to be a useful/relevant subset of CGI.pm's :standard export tags.) It tries to adhere as faithfully as reasonable to the CGI API where applicable, and otherwise to try to do something intuitive.

Every form-related method (popup_menu, textfield, etc.) requires a -name parameter. It serves the same purpose as in CGI.pm. The values the user has entered/selected on the form are accessible through $q->param('somename') where 'somename' was given as a -name argument.

METHODS ^

Here is a reference for the API. Generally methods either take named parameters (-name => 'first') or unnamed parameters passed in the order listed. Optional parameters have their default value listed to the right in parentheses; otherwise, the parameter is required.

new

The constructor.

Parameters

Returns

A new Wx::WidgetMaker object.

h1, h2, h3, h4, h5, h6

Analogous to the HTML tags with the same names. These methods display their string parameter in bold font in various sizes, h1 using the largest and h6 the smallest. Note that unlike the HTML tags, there are no linebreaks before or after the text, so you have to explicitly put them on their own row (e.g. by adding to a wxHORIZONTAL BoxSizer).

Parameters

Returns

A Wx::StaticText object.

textfield

Parameters

Returns

A Wx::TextCtrl object.

password_field

Parameters

Returns

A Wx::TextCtrl object.

textarea

Parameters

Returns

A Wx::TextCtrl object.

popup_menu

Parameters

Returns

A Wx::Choice object.

scrolling_list

Parameters

Returns

A Wx::ListBox object.

checkbox_group

This method is not implemented yet.

Parameters

checkbox

Parameters

Returns

A Wx::CheckBox object.

radio_group

Parameters

Returns

A Wx::RadioBox object.

submit

Makes a button with text on it. Note that this is not like the submit button in a CGI form because there is no event handler attached to the button, so by default clicking on the button does nothing.

Parameters

Returns

A Wx::Button object.

image_button

Parameters

Returns

A Wx::BitmapButton object.

print

This isn't a CGI.pm method (though it _is_ an Apache.pm method :), but is handy for either creating a StaticText object or adding Control or Sizer objects to a Sizer.

Parameters

Returns

Either a Wx::StaticText object if -text is a string, or some Wx::Control subclass if -sizer is given.

param

Parameters

Returns

If no arguments are passed, returns a list of all the child controls' names (assuming they have a name, which they will if they were created with this module). If a name is passed, in list context returns a list of the selected values, while in scalar context returns the first value found.

AUTHOR ^

Copyright 2002-2004, Scott Lanning <lannings@who.int>. All rights reserved.

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

SEE ALSO ^

The Wx and CGI PODs.

The wxPerl mailing list.

syntax highlighting: