Padre Plugin Dialog
- 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 |
Project | Cookbook02 | n/an/a | n/a | n/a | n/a | ||
Dialog | Padre::Plugin::Cookbook02::FBP::MainFB | Main | n/a | wxRESIZE_BORDER | n/a | n/a | |
wxBoxSizer | bSizer1 | n/a | n/a | n/a | n/a | n/a | |
wxBoxSizer | bSizer2 | n/a | n/a | proportion = 0 | n/a | n/a | |
wxStaticText | heading | heading is public | public | proportion = 0 | n/a | n/a | |
wxStaticLine | m_staticline1 | n/a | n/a | n/a | n/a | n/a | |
wxFlexGridSizer | fgSizer1 | n/a | n/a | n/a | n/a | n/a | |
wxCheckBox | ttennis | TTennis | public | !checked | {{{OnCheckBox}}} | ttennis_checked | |
wxCheckBox | ping | ping | public | !checked !enabled | {{{OnCheckBox}}} | ping_checked | |
spacer | n/a | n/a | n/a | n/a | n/a | n/a | |
wxCheckBox | pong | pong | public | !checked !enabled | {{{OnCheckBox}}} | pong_checked | |
wxStaticText | m_staticText2 | n/a | n/a | Static Text\nPadre Config DB\nuser defined\nattributes | n/a | n/a | |
wxRadioBox | user_name | User * Name | public | proportion = 0 choices = "nick" "cpan" "e-mail" | n/a | n/a | |
wxStaticLine | m_staticline2 | n/a | n/a | n/a | n/a | n/a | |
wxBoxSizer | bSizer3 | n/a | n/a | proportion = 0 wxHORIZONTAL | n/a | n/a | |
wxStaticText | name_label | name_label public | public | proportion = 0 | n/a | n/a | |
wxTextCtrl | name_value | m/t | public | n/a | n/a | n/a | |
wxStaticLine | m_staticline3 | n/a | n/a | n/a | n/a | n/a | |
wxFlexGridSizer | fgSizer2 | n/a | n/a | proportion = 0 | n/a | n/a | |
wxStaticText | m_staticText4 | Choices: | n/a | proportion = 0 | n/a | n/a | |
wxChoice | choice | "CPL" "CPL" "BCPL" "B" "C" "PL" | public | proportion = 0 | n/a | n/a | |
wxStaticLine | m_staticline4 | n/a | n/a | n/a | n/a | n/a | |
wxBoxSizer | bSizer4 | n/a | n/a | proportion = 0 wxHORIZONTAL | n/a | n/a | |
wxButton | output | Output | n/a | n/a | {{{OnButonClick}}} | output_clicked | |
wxButton | update | Update | n/a | n/a | {{{OnButonClick}}} | update_clicked | |
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.sub boilerplate
To use Padre internal featuressub 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 Padre::Configmy $config = $main->config;Then we can read the contets
$config->identity_nicknameYou 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:$main->show_output(1); 1. Create a variable:
my $output = $main->output;1. Clear the Padre Output window.
$output->clear;1. Write to Padre Output window
$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.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 { .... }Snippets from {{{Padre::Plugin::Cookbook02::Main}}} Padre Plugin Dialog