[[PageOutline(1-4)]] [wiki:PadrePluginDialog <-menu] = Padre::Plugin::Cookbook Recipe-04 This page complements {{{Padre::Plugin::Cookbook Recipe-04}}}, It is just meant to be an aid, with a suggested layout and some ideas to speed you along, enjoy. * Recipe-04 is all about {{{ListCtrl or ConfigDB}}} now available via {{{Padre::Plugin::CookBook}}} see trunk * You may find this helpful, see: [wiki:DownloadRepository Download Padre from Repository] ---- == Tree Layout This has been covered in previous Recipes, here for continuity. {{{ Padre-Plugin-Cookbook/ ├── fbp │ └── Recipe04 │ ├── AboutFB.fbp │ ├── FrameFB.fbp (wx-frame unstable) │ └── MainFB.fbp ├── lib │ └── Padre │ └── Plugin │ ├── Cookbook │ │ └── Recipe04 │ │ ├── About.pm │ │ ├── FBP │ │ │ ├── AboutFB.pm │ │ │ └── MainFB.pm │ │ └── Main.pm │ └── Cookbook.pm ├── Changes ├── Makefile.PL ├── MANIFEST ├── t │ ├── 00.load.t │ ├── 01-Cookbook.t │ ├── 05-About04.t │ └── 05-Recipe04.t └── xt ├── changes.t ├── critic.t ├── hasversion.t ├── meta.t ├── minimumversion.t ├── podcoverage.t ├── podspell.t └── pod.t }}} NB Remember Padre can do some of this for you, see: [wiki:Features/ProjectSkeletonGeneration Project Skeleton Generation] ---- == {{{wxFormBuilder}}} (xml) * Use wxFormBuilder, v3.1.70 * Multiple! Why, well it's either a **Wx** thing or {{{P-P-FormBuilder}}} limitation, this is pants! Glade allows multi-dialogue's in single file. * This is in progress of being updated, so will be covered in a future Recipe-nn * The naming convention chosen starts to make more sense when you think about multiple dialogue's. * There is no pretty table to explain what's going on, you have to use {{{wxFormBuilder}}}, I suggest that you also view the *FB.fbp & *FB.pm files as well. === Create {{{MainFb.fbp}}} ||||=wxWidget=||||||||=Properties=||||=Events|| ||=Icon=||=Type=||name||label/title||public||other||type||value|| |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxproject.png)]] }}} {{{#!td Project }}} {{{#!td Cookbook }}} {{{#!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::Cookbook::Recipe04::FBP::MainFB }}} {{{#!td Main }}} {{{#!td n/a }}} {{{#!td wxRESIZE_BORDER }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxListCtrl.png)]] }}} {{{#!td wxListCtrl }}} {{{#!td list_ctrl }}} {{{#!td n/a }}} {{{#!td Yes }}} {{{#!td wxLC_EDIT_LABELS, wxLC_REPORT }}} {{{#!td _on_list_item_activated, _on_list_col_clicked }}} {{{#!td n/a }}} |---------------------------------- === Create {{{AboutFb.fbp}}} ||||=wxWidget=||||||||=Properties=||||=Events|| ||=Icon=||=Type=||name||label/title||public||other||type||value|| |---------------------------------- {{{#!td style="background: #ffd" [[Image(wxproject.png)]] }}} {{{#!td Project }}} {{{#!td Cookbook }}} {{{#!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::Cookbook::Recipe04::FBP::AboutFB }}} {{{#!td About }}} {{{#!td n/a }}} {{{#!td wxRESIZE_BORDER }}} {{{#!td n/a }}} {{{#!td n/a }}} |---------------------------------- ---- == {{{Padre::Plugin::FormBuilder}}} * {{{Padre::Plugin::FormBuilder}}} dose not support Wx menus yet, hence //fudge// work around in Main. * Use generator to create MainFB.pm from MainFB.fbp * Use generator to create AboutFB.pm from AboutFB.fbp * Tip have {{{Padre::Plugin::Cookbook::Recipe04::Main.pm}}} Open before running generator. * {{{Padre::Plugin::FormBuilder}}} {{{use FBP::Perl ();}}} * You need to read Source FBP::Perl for which Wx features are supported, **it's the only reference :(** ---- == Plug-in Code * Read POD for {{{Padre::Plugin}}} * Read POD for Cookbook.pm, Main.pm and About.pm. === {{{ListCtrl}}} A List Control is just a wrapper for List Items, with attribute headers (column headings) ==== Population * Clear list Control {{{#!perl # clear ListCtrl $self->list_ctrl->ClearAll; }}} * Attribute headers {{{#!perl # List the columns in the underlying table $self->list_ctrl->InsertColumn( $idx, Wx::gettext('index') ); }}} * Tuple data (List Item) {{{#!perl # NB my $item = Wx::ListItem->new; $self->list_ctrl->InsertItem($item); $self->list_ctrl->SetItem( $idx, 0, $idx ); $self->list_ctrl->SetItem( $idx, 1, $tuples[$idx][0] ); $self->list_ctrl->SetItem( $idx, 2, $tuples[$idx][1] ); $self->list_ctrl->SetItem( $idx, 3, $tuples[$idx][2] ); }}} ==== Events We now have to handle not only the event, but also it's data. * _on_list_col_clicked {{{#!perl sub _on_list_col_clicked { my ( $self, $list_event ) = @ARG; $col_num = $list_event->GetColumn(); }}} * _on_list_item_activated {{{#!perl sub _on_list_item_activated { my ( $self, $list_element ) = @ARG; my $session_id = $tuples[ $list_element->GetIndex ]['0']; }}} **NB** the above simplified code snippets can be found in Recipe04/Main.pm === {{{Padre::DB}}} All DB access is via Padre::DB, you will also need to look at ORLite for supported features. Other wise it's just SQL via Padre DBC. * Read POD for [http://search.cpan.org/~plaven/Padre/lib/Padre/DB.pm Padre::DB] * Read POD for [http://search.cpan.org/~adamk/ORLite-1.50/lib/ORLite.pm ORLite] NB ConfigDB is just an SQLite DB. === {{{StatusBar}}} We have assumed //Show low-priority info messages on statusbar (not in a popup)// is **true**, \\ if not I suggest you set this in Tools->Preferences->Apperance {{{#!perl sub clean_session { my $self = shift; my $main = $self->main; $main->info('Cleaning Session relation'); .... } }}} === {{{ProgressBar}}} * Read POD for [http://search.cpan.org/~plaven/Padre/lib/Padre/Wx/Progress.pm Padre::Wx::Progress] ---- == Run * perl dev -a -die * You should now have Cookbook in your Tools menu, enjoy. ---- == Foot Notes === Testing These may help get you thinking in the write direction. * [http://oreilly.com/catalog/9780596100926 Perl Testing: A Developer's Notebook] * [http://www.mclean.net.nz/osdc-tdd-full.pdf An Introduction to Test Driven Development Using Perl] Padre can help you with this, see: [wiki:Features/AutomatedBuildAndTest Automated Build and Test] ==== Exrta Tests * I have recently been exposed to [http://beta.metacpan.org/module/Test::XT Test::XT], really cool. * Here is the reasoning [http://use.perl.org/~Alias/journal/38822 Journal article] Ouch. Alias++ === Plugin attribute config Plugins DO have the ability to store stuff in the attribute config {{{#!perl $plugin->config_read $plugin->config_write }}} Alias++ See {{{Padre::Plugin::SpellCheck}}} for an example of it's use. **{{{__END__}}}** [wiki:PadrePluginDialog <-menu]