[[PageOutline(1-4)]] [wiki:PadrePluginDialog <-menu] = Padre::Plugin::Cookbook Recipe-02 * This page complements {{{Padre::Plugin::Cookbook Recipe-02}}}, it is not meant to be installable, just an aid, with a suggested layout, enjoy. More detail will follow in subsequent Cookbooks. * You can either svn Padre::Plugin::Cookbook or build your own with Cookbook02.zip in Attachments. * Updated to Padre plug-in API 2.2 ---- == Step 1 - Create Skeleton Padre can do this for you see [wiki:Features/ProjectSkeletonGeneration Project Skeleton Generation] * 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. ||||=wxWidget=||||||||=Properties=||||=Events|| ||=Icon=||=Type=||name||label/title||public||other||type||value|| |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxproject.png)]] }}} {{{#!td Project }}} {{{#!td Cookbook02 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxdialog.png)]] }}} {{{#!td Dialog }}} {{{#!td Padre::Plugin::Cookbook02::FBP::MainFB }}} {{{#!td Main }}} {{{#!td n/a }}} {{{#!td wxRESIZE_BORDER }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbsizer.png)]] }}} {{{#!td wxBoxSizer }}} {{{#!td bSizer1 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbsizer.png)]] }}} {{{#!td wxBoxSizer }}} {{{#!td bSizer2 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td proportion = 0 }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td [[Image(wxstatic_text.png)]] }}} {{{#!td wxStaticText }}} {{{#!td heading }}} {{{#!td heading is public }}} {{{#!td public }}} {{{#!td proportion = 0 }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td [[Image(wxstatic_line.png)]] }}} {{{#!td wxStaticLine }}} {{{#!td m_staticline1 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxflex_grid_sizer.png)]] }}} {{{#!td wxFlexGridSizer }}} {{{#!td fgSizer1 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxcheckbox.png)]] }}} {{{#!td wxCheckBox }}} {{{#!td ttennis }}} {{{#!td TTennis }}} {{{#!td public }}} {{{#!td !checked }}} {{{#!td {{{OnCheckBox}}} }}} {{{#!td ttennis_checked }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxcheckbox.png)]] }}} {{{#!td wxCheckBox }}} {{{#!td ping }}} {{{#!td ping }}} {{{#!td public }}} {{{#!td !checked !enabled }}} {{{#!td {{{OnCheckBox}}} }}} {{{#!td ping_checked }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxspacer.png)]] }}} {{{#!td spacer }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxcheckbox.png)]] }}} {{{#!td wxCheckBox }}} {{{#!td pong }}} {{{#!td pong }}} {{{#!td public }}} {{{#!td !checked !enabled }}} {{{#!td {{{OnCheckBox}}} }}} {{{#!td pong_checked }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxstatic_text.png)]] }}} {{{#!td wxStaticText }}} {{{#!td m_staticText2 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td Static Text\nPadre Config DB\nuser defined\nattributes }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxradio_box.png)]] }}} {{{#!td wxRadioBox }}} {{{#!td user_name }}} {{{#!td User * Name }}} {{{#!td public }}} {{{#!td proportion = 0 choices = "nick" "cpan" "e-mail" }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- |---------------------------------- {{{#!td [[Image(wxstatic_line.png)]] }}} {{{#!td wxStaticLine }}} {{{#!td m_staticline2 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbsizer.png)]] }}} {{{#!td wxBoxSizer }}} {{{#!td bSizer3 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td proportion = 0 wxHORIZONTAL }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td [[Image(wxstatic_text.png)]] }}} {{{#!td wxStaticText }}} {{{#!td name_label }}} {{{#!td name_label public }}} {{{#!td public }}} {{{#!td proportion = 0 }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxtext_ctrl.png)]] }}} {{{#!td wxTextCtrl }}} {{{#!td name_value }}} {{{#!td m/t }}} {{{#!td public }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td [[Image(wxstatic_line.png)]] }}} {{{#!td wxStaticLine }}} {{{#!td m_staticline3 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxflex_grid_sizer.png)]] }}} {{{#!td wxFlexGridSizer }}} {{{#!td fgSizer2 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td proportion = 0 }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td [[Image(wxstatic_text.png)]] }}} {{{#!td wxStaticText }}} {{{#!td m_staticText4 }}} {{{#!td Choices: }}} {{{#!td n/a }}} {{{#!td proportion = 0 }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxchoice.png)]] }}} {{{#!td wxChoice }}} {{{#!td choice }}} {{{#!td "CPL" "CPL" "BCPL" "B" "C" "PL" }}} {{{#!td public }}} {{{#!td proportion = 0 }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td [[Image(wxstatic_line.png)]] }}} {{{#!td wxStaticLine }}} {{{#!td m_staticline4 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbsizer.png)]] }}} {{{#!td wxBoxSizer }}} {{{#!td bSizer4 }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td proportion = 0 wxHORIZONTAL }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbutton.png)]] }}} {{{#!td wxButton }}} {{{#!td output }}} {{{#!td Output }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td {{{OnButonClick}}} }}} {{{#!td output_clicked }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbutton.png)]] }}} {{{#!td wxButton }}} {{{#!td update }}} {{{#!td Update }}} {{{#!td n/a }}} {{{#!td n/a }}} {{{#!td {{{OnButonClick}}} }}} {{{#!td update_clicked }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxbutton.png)]] }}} {{{#!td wxButton }}} {{{#!td close }}} {{{#!td Close }}} {{{#!td n/a }}} {{{#!td Default wxID_CANCEL }}} {{{#!td n/a }}} {{{#!td 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. === sub boilerplate To use Padre internal features {{{#!perl sub set_name_label_value { my $self = shift; my $main = $self->main; }}} === Config To use Padre Configuration variables, first we need some more boilerplate. * Read POD for [http://search.cpan.org/~plaven/Padre/lib/Padre/Config.pm Padre::Config] {{{#!perl my $config = $main->config; }}} Then we can read the contets {{{#!perl $config->identity_nickname }}} You may ask how did I know which $config to call, just look in Tools->Preferences->Advanced. === Output To use Padre Output window, to talk to our users, or we could just **say** to terminal :) 1. Open Padre Output window: {{{#!perl $main->show_output(1); }}} 1. Create a variable: {{{#!perl my $output = $main->output; }}} 1. Clear the Padre Output window. {{{#!perl $output->clear; }}} 1. Write to Padre Output window {{{#!perl $output->AppendText("output cliked \n"); }}} ---- == Step 5 Run * perl dev -a -die * You should now have Cookbook02 in your Tools menu, enjoy. ---- == Foot Notes * YOU MUST REFERENCE this: wxAlphabetical class reference http://docs.wxwidgets.org/stable/wx_classref.html * Tip {{{wxStaticText}}} has method {{{SetLabel}}} === public attributes * The use of **public** causes {{{Padre::Plugin::FormBuilder}}} to generate an attribute for you. {{{ #!perl sub heading { Wx::Window::FindWindowById($_[0]->{heading}); } }}} * which enables you to manipulate is value. * code snip from {{{Padre::Plugin::Cookbook02::Main::update_clicked}}} {{{#!perl $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). {{{ #!perl 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. {{{#!perl sub update_clicked { .... } }}} Snippets from {{{Padre::Plugin::Cookbook02::Main}}} **{{{__END__}}}** [wiki:PadrePluginDialog <-menu]