in reply to Which GUI libraries allow creation of megawidgets? (wxPerl?Gtk?)
It's possible with wxPerl.
wxWidgets makes heavy use of subclassing, so "mega" widgets are not an uncommon occurrence. In fact, with the C++ API you almost always end up sublcassing at least several widgets (typically wxFrames, wxPanels, and wxBoxSizers) to process any significant number of events.
Here's an example of a wxPerl "mega" widget called LabelEntry. It creates a label, a text entry field, and a submit button. When the user clicks the submit button, the text is assigned to the variable specified by the caller and the caller's callback routine is invoked with the mega widget as the only argument. (Note that I've never used wxPerl before, so this will look somewhat rough):
#!/usr/bin/perl -w use strict; use Wx; my $wxobj = new MyApp; $wxobj->MainLoop; package MyApp; use Wx qw(wxOK wxICON_INFORMATION); use base 'Wx::App'; sub OnInit { my $self = shift; my $frame = Wx::Frame->new( undef, -1, 'MegaWidget test', [0, 0], [300, 200] ); $self->SetTopWindow($frame); $frame->Show(1); my $name; my $labentry = LabelEntry->new( $frame, "Your name: ", \$name, "Submit", sub { Wx::MessageBox( "Your name is: $name.", "Name", wxOK|wxICON_INFORMATION, $frame ); } ); return 1; } package LabelEntry; use Wx; use Wx::Event qw(EVT_BUTTON); use base 'Wx::Panel'; sub new { my $invo = shift; my $class = ref $invo || $invo; my ($window, $label, $var_ref, $button_label, $callback) = @_; my $self = $class->SUPER::new($window, -1, [0,0], [300, 30]); bless($self, $class); new Wx::StaticText ($self, -1, $label, [0, 0]); my $text_control = new Wx::TextCtrl ( $self, -1, "", [70, 0] ); my $button_id = 2; my $button = new Wx::Button ( $self, $button_id, $button_label, [170, 0] ); EVT_BUTTON( $self, $button_id, sub { $$var_ref = $text_control->GetLineText(0); $callback->($self); } ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Which GUI libraries allow creation of megawidgets? (wxPerl?Gtk?)
by HelenCr (Monk) on Apr 12, 2013 at 09:27 UTC |