- This page complements {{{Padre::Plugin::Cookbook Recipe-01}}}, 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 Cookbook01.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.
- for me this is, /src/Padre/Padre == {{{http://svn.perlide.org/padre/trunk/Padre}}}
- thus for me, Cookbook01 is located in /src/Padre/Padre-Plugin-Cookbook01, checkout some other Plugins to see for your self.
- FBP/fbp directories, follow current Padre trunk Naming convention
Padre-Plugin-Cookbook01/
├── fbp
│ └── MainFB.fbp
├── lib
│ └── Padre
│ └── Plugin
│ ├── Cookbook01
│ │ ├── FBP
│ │ │ └── MainFB.pm
│ │ └── Main.pm
│ └── Cookbook01.pm
└── t
Step 2 Create MainFB.fbp (xml)
- Use wxFormBuilder, v3.1.70
- Create in following order of table below.
- save to plug-in root /fbp/MainFB.fbp as above.
wxWidget | Properties | Events |
Icon | Type | name | label/title | public | other | type | value |
|
Project | Cookbook01 | n/a | n/a | n/a | n/a | n/a |
|
Dialog | Padre::Plugin::Cookbook01::FBP::MainFB | Main | n/a | wxRESIZE_BORDERn/a | n/a
|
wxBoxSizer | bSizer1 | n/a | n/a | n/a | n/a | n/a |
|
wxStaticText | m_staticText1 | Hello World | n/a | wxALIGN_CENTER | 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
Step 3 {{{Padre::Plugin::FormBuilder}}}
- Use generator to create MainFB.pm from MainFB.fbp
- Tip have {{{Padre::Plugin::Cookbook01.pm}}} Open before running generator.
Step 4 Perl Plug-in Code
- Read POD for {{{Padre::Plugin}}}
- Read POD for Cookbook01.pm and Main.pm.
- Cookbook01 Required methods with minimum requirements
sub padre_interfaces {
return (
# Default, required
'Padre::Plugin' => '0.91',
# used by MainFB by Padre::Plugin::FormBuilder
'Padre::Wx::Role::Main' => '0.91',
# used by MainFb by Padre::Plugin::FormBuilder
'Padre::Wx' => '0.91',
);
}
# Called by Padre::Wx::Dialog::PluginManager
# my @needs = $plugin->padre_interfaces;
sub plugin_name {
return 'Cookbook01';
}
# Called by Padre::Wx::Dialog::PluginManager
# $self->{label}->SetLabel( $plugin->plugin_name );
What is Padre::Wx
XS magic
Wx loads it at runtime
when you use Wx;
and when you use Padre::Wx you get Wx::*
http://perldoc.perl.org/perlxs.html
basically they are loading symbols on the fly when the C library loads
DLL
or shared library (.so)
Thanks for that azawawi.
- Run Tests, note results, //critiques welcome.
Step 5 Run
- perl dev -a -die
- You should now have Cookbook01 in your Tools menu, enjoy.
Foot Notes
Why Main
Well I needed a convention that I could expand upon. Which made sense to me, so here goes:
- MainFB.fbp is generated by wxFormBuilder,
- MainFB.pm is geneated from previous by {{{Padre::Plugin::FormBuilder}}}.
The FB tells me it's nought to do with me.
- Main.pm is the event handler for {{{MainFB.pm}}}.
Plugin Dialog