Download Padre

Padre Plugin Cookbook Recipe 02

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.
n/a
wxWidgetPropertiesEvents
IconTypenamelabel/titlepublicothertypevalue
ProjectCookbook02n/an/an/an/a
DialogPadre::Plugin::Cookbook02::FBP::MainFBMainn/awxRESIZE_BORDERn/an/a
wxBoxSizerbSizer1n/an/an/an/an/a
wxBoxSizerbSizer2n/an/aproportion = 0n/an/a
wxStaticTextheadingheading is publicpublicproportion = 0n/an/a
wxStaticLinem_staticline1n/an/an/an/an/a
wxFlexGridSizerfgSizer1n/an/an/an/an/a
wxCheckBoxttennisTTennispublic!checked{{{OnCheckBox}}}ttennis_checked
wxCheckBoxpingpingpublic!checked !enabled{{{OnCheckBox}}}ping_checked
spacern/an/an/an/an/an/a
wxCheckBoxpongpongpublic!checked !enabled{{{OnCheckBox}}}pong_checked
wxStaticTextm_staticText2n/an/aStatic Text\nPadre Config DB\nuser defined\nattributesn/an/a
wxRadioBoxuser_nameUser * Namepublicproportion = 0
choices = "nick" "cpan" "e-mail"
n/an/a
wxStaticLinem_staticline2n/an/an/an/an/a
wxBoxSizerbSizer3n/an/aproportion = 0
wxHORIZONTAL
n/an/a
wxStaticTextname_labelname_label publicpublicproportion = 0n/an/a
wxTextCtrlname_valuem/tpublicn/an/an/a
wxStaticLinem_staticline3n/an/an/an/an/a
wxFlexGridSizerfgSizer2n/an/aproportion = 0n/an/a
wxStaticTextm_staticText4Choices:n/aproportion = 0n/an/a
wxChoicechoice"CPL" "CPL" "BCPL" "B" "C" "PL"publicproportion = 0n/an/a
wxStaticLinem_staticline4n/an/an/an/an/a
wxBoxSizerbSizer4n/an/aproportion = 0
wxHORIZONTAL
n/an/a
wxButtonoutputOutputn/an/a{{{OnButonClick}}}output_clicked
wxButtonupdateUpdaten/an/a{{{OnButonClick}}}update_clicked
wxButtoncloseClosen/aDefault
wxID_CANCEL
n/an/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
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 Padre::Config
my $config = $main->config;
Then we can read the contets
$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:
$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