wiki:PadrePluginCookbook02

Version 3 (modified by bowtie, 3 years ago) (diff)

--

Padre::Plugin::Cookbook02

  • This page complements Padre::Plugin::Cookbook02, it is not meant to be installable, just an aid, with a suggested layout, enjoy. More detail will follow in subsequent Cookbooks.
  • Cookbook02.zip in Attachments.

Step 1 - Create Skeleton

  • Assumption you are building in your copy of Padre trunk.
Padre-Plugin-Cookbook02/
├── fbp
│   └── MainFB.fbp
├── lib
│   └── Padre
│       └── Plugin
│           ├── Cookbook02
│           │   ├── FBP
│           │   │   └── MainFB.pm
│           │   └── Main.pm
│           └── Cookbook02.pm
└── t

Step 2 Create MainFB.fbp (xml)

  • Use wxFormBuilder, v3.1.70
  • The table only shows the flow, not indentation, view file MainFB.fbp in wxFormBuilder for that.
  • fgSizer1 plays table tennis, RadioBox support added by Alias, much more elegant.
wxWidgetPropertiesEvents
IconTypenamelabel/titlepublicothertypevalue

wxWidget project

Project

Cookbook02

n/a

n/a

n/a

n/a

n/a

wxWidget dialog

Dialog

Padre::Plugin::Cookbook02::FBP::MainFB

Main

n/a

wxRESIZE_BORDER

n/a

n/a

wxWidget bsizer

wxBoxSizer

bSizer1

n/a

n/a

n/a

n/a

n/a

wxWidget bsizer

wxBoxSizer

bSizer2

n/a

n/a

proportion = 0

n/a

n/a

wxWidget static_text

wxStaticText

heading

heading is public

public

proportion = 0

n/a

n/a

wxWidget static_line

wxStaticLine

m_staticline1

n/a

n/a

n/a

n/a

n/a

wxWidget flex_grid_sizer

wxFlexGridSizer

fgSizer1

n/a

n/a

n/a

n/a

n/a

wxWidget checkbox

wxCheckBox

ttennis

TTennis

public

!checked

OnCheckBox

ttennis_checked

wxWidget checkbox

wxCheckBox

ping

ping

public

!checked

!enabled

OnCheckBox

ping_checked

wxWidget spacer

spacer

n/a

n/a

n/a

n/a

n/a

n/a

wxWidget checkbox

wxCheckBox

pong

pong

public

!checked

!enabled

OnCheckBox

pong_checked

wxWidget static_text

wxStaticText

m_staticText2

n/a

n/a

Static Text\nPadre Config DB\nuser defined\nattributes

n/a

n/a

wxWidget radio_box

wxRadioBox

user_name

User * Name

public

proportion = 0

choices = "nick" "cpan" "e-mail"

n/a

n/a

wxWidget static_line

wxStaticLine

m_staticline2

n/a

n/a

n/a

n/a

n/a

wxWidget bsizer

wxBoxSizer

bSizer3

n/a

n/a

proportion = 0

wxHORIZONTAL

n/a

n/a

n/a

n/a

n/a

n/a

n/a

wxWidget static_line

wxStaticLine

m_staticline3

n/a

n/a

n/a

n/a

n/a

wxWidget flex_grid_sizer

wxFlexGridSizer

fgSizer2

n/a

n/a

proportion = 0

n/a

n/a

n/a

n/a

n/a

n/a

n/a

wxWidget static_line

wxStaticLine

m_staticline4

n/a

n/a

n/a

n/a

n/a

wxWidget bsizer

wxBoxSizer

bSizer4

n/a

n/a

proportion = 0

wxHORIZONTAL

n/a

n/a

wxWidget button

wxButton

output

Output

n/a

n/a

OnButonClick

output_clicked

wxWidget button

wxButton

update

Update

n/a

n/a

OnButonClick

update_clicked

wxWidget button

wxButton

close

Close

n/a

Default

wxid_CANCEL

n/a

n/a

  • Dialog must start with Padre::Plugin for Step 3 to work.
  • A Sizer is compulsory to hold our text.
  • wxRESIZE_BORDER lets you grab lower left hand corner.
  • wxALIGN_CENTER centers text
  • proportion = 0, to prevent stretching.

Step 3 Padre::Plugin::FormBuilder

  • Use generator to create MainFB.pm from MainFB.fbp
    • Tip have Padre::Plugin::Cookbook02.pm Open before running generator.

Step 4 Perl Plug-in Code

  • Read POD for Padre::Plugin
  • Read POD for Cookbook02.pm and Main.pm
  • Run Tests, note results, critiques welcome.

Step 5 Run

  • perl dev -a -die
  • You should now have Cookbook02 in your Tools menu, enjoy.

Foot Notes

public attributes

  • The use of public causes Padre::Plugin::FormBuilder to generate an attribute for you.
    sub heading {
        Wx::Window::FindWindowById($_[0]->{heading});
    }
    
  • which enables you to manipulate is value.
  • code snip from Padre::Plugin::Cookbook02::Main::update_clicked
    $self->heading->SetLabel('I am in Control');
    

events handlers

  • The use of OnButonClick causes Padre::Plugin::FormBuilder to generate an empty event method for you (required method).
    sub update_clicked {
        $_[0]->main->error('Handler method update_clicked for event update.OnButtonClick not implemented');
    }
    
  • which enables you to perform an action based on a user input.
  • code snip from Padre::Plugin::Cookbook02, you must create your own event handler.
    sub update_clicked {
    ....
    }
    

output

  • To use Padre Output window, to talk to our users, or we could just say to terminal :)
  1. Open Padre Output window:
    $main->show_output(1);
    
  2. Create a variable:
    my $output = $main->output;
    
  3. Clear the Padre Output window.
    $output->clear;
    
  4. Write to Padre Output window
    $output->AppendText("output cliked \n");
    

Snippets from Padre::Plugin::Cookbook02::Main

__END__

Attachments