Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

wimpole wxperl help

by gizmox (Initiate)
on Aug 18, 2016 at 15:57 UTC ( [id://1170004]=perlquestion: print w/replies, xml ) Need Help??

gizmox has asked for the wisdom of the Perl Monks concerning the following question:

ive been going crazy trying toi learn wx perl. I create gui's with wxdesigner and glade but they dont open when run.

can someone please walk me through a very simple app with 1 menu item and one panel inside main frame and walk me through wharts going on please. also would like to know how to open a panel from menu. thanks.

#!/usr/bin/perl #--------------------------------------------------------------------- +------- # Name: mosses.pl # Author: XXXX # Created: XX/XX/XX # Copyright: #--------------------------------------------------------------------- +------- use strict; use Wx; do 'mosses_wdr.pl'; # constants # WDR: classes package MyFrame; use strict; use vars qw(@ISA); @ISA=qw(Wx::Frame); use Wx::Event qw(EVT_MENU EVT_CLOSE EVT_SIZE EVT_UPDATE_UI); use Wx qw(wxOK wxID_ABOUT wxID_EXIT wxICON_INFORMATION wxTB_HORIZONTAL + wxNO_BORDER); sub new { my( $class ) = shift; my( $this ) = $class->SUPER::new( @_ ); $this->CreateMyMenuBar(); $this->CreateMyToolBar(); $this->CreateStatusBar( 1 ); $this->SetStatusText( "Welcome!", 0); # insert main window here # WDR: handler declarations for MyFrame EVT_MENU( $this, wxID_ABOUT, \&OnAbout ); EVT_MENU( $this, wxID_EXIT, \&OnQuit ); EVT_CLOSE( $this, \&OnCloseWindow ); $this; } # WDR: methods for MyFrame sub CreateMyMenuBar { my( $this ) = shift; $this->SetMenuBar( &main::MyMenuBarFunc() ); } sub CreateMyToolBar { my( $this ) = shift; my( $tb ) = $this->CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER); # &main::MyToolBarFunc( $tb ); } # WDR: handler implementations for MyFrame sub OnAbout { my( $this, $event ) = @_; Wx::MessageBox( "Welcome to SuperApp 1.0\n(C)opyright Joe Hacker", "About SuperApp", wxOK|wxICON_INFORMATION, $this ); } sub OnQuit { my( $this, $event ) = @_; $this->Close(1); } sub OnCloseWindow { my( $this, $event ) = @_; $this->Destroy(); } package MyApp; use strict; use vars qw(@ISA); @ISA=qw(Wx::App); sub OnInit { my( $this ) = @_; Wx::InitAllImageHandlers(); my( $frame ) = MyFrame->new( undef, -1, "SuperApp", [20,20], [500, +340] ); $frame->Show(1); 1; } package main; my( $app ) = MyApp->new(); $app->MainLoop();

Replies are listed 'Best First'.
Re: wimpole wxperl help
by jmlynesjr (Deacon) on Aug 19, 2016 at 02:09 UTC

    Lots of examples on the wxPerl Wiki - wiki.wxperl.nl/Main_Page(especially see wxPerl Book examples). Also many examples posted here at the Monestary.

    IMHO wxPerl has quite a learning curve.

    James

    There's never enough time to do it right, but always enough time to do it over...

      :) yup, pretty much all gui programming has the same learning curve

        Granted...

        Took me awhile to translate/interpret the C++ wxWidgets docs to wxPerl syntax. It didn't help that I was more familiar with C than C++.

        James

        There's never enough time to do it right, but always enough time to do it over...

Re: wimpole wxperl help
by Laurent_R (Canon) on Aug 18, 2016 at 18:58 UTC
    Please use <code> and </code> tags for your code snippets.

    Please also look at Markup in the Monastery for markup and formatting tips .

Re: wimpole wxperl help
by jmlynesjr (Deacon) on Aug 20, 2016 at 00:54 UTC

    gizmox

    For what it's worth, here's the wxPerl template that I start from.

    #! /usr/bin/perl # Name: .pl # Author: James M. Lynes, Jr. # Created: January 13, 2015 # Modified By: James M. Lynes, Jr. # Last Modified: May 4, 2016 # Environment Ubuntu 14.04LTS / perl v5.18.2 / wxPerl 3.0.1 / H +P 15 Quad Core # Change Log: 1/13/2015 - Program Created # 1/6/2016 - Fixed comment error in Sizer section # 5/4/2016 - Fixed missing Add in Sizer section, Added mes +sagebox and radiobox sections # Description: # Notes: # package main; use strict; use warnings; my $app = App->new(); $app->MainLoop; package App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Frame->new(); $frame->Show(1); } package Frame; use strict; use warnings; use Wx qw(:everything); use base qw(Wx::Frame); use Data::Dumper; sub new { my ($class, $parent) = @_; # Create Top Level Frame my $self = $class->SUPER::new($parent, -1, "Frame Title", wxDefaul +tPosition, wxDefaultSize); # Create Title Text $self->{titletext} = Wx::StaticText->new($self, -1, "Title Text", +wxDefaultPosition, wxDefaultSize); # Create Buttons $self->{button} = Wx::Button->new($self, -1, "Button Label", wxDef +aultPosition, wxDefaultSize); # Create Data Entry Prompts and Boxes $self->{label} = Wx::StaticText->new($self, -1, "Prompt Text", wxD +efaultPosition, wxDefaultSize); $self->{text} = Wx::TextCtrl->new($self, -1, "Default Value", wxDe +faultPosition, wxDefaultSize); # Create a Messsage/Error Box Wx::MessageBox("Multiline\nError\nText", "Message Box Title", wxIC +ON_ERROR, $self); # Create a Radio Box my $choices = [ "A", "B", "C", "D", "E", "F", "G", "H", "I"]; $self->{radiobox} = Wx::RadioBox->new($self, -1, "Radio Box Title" +, wxDefaultPosition, wxDefaultSize, $choices, 3, wxRA_SPECIFY_COLS); # Define Sizer Structure - My "Standard" Layout # Assumes: One Main Sizer(Vertical) # One Header Sizer(Horizontal) # One Body Sizer(Horizontal) containing # Left Body Sizer(Vertical) # Right Body Sizer(Vertical) # Three Footer Sizers(horizontal) # # Create Sizers my $mainSizer = Wx::BoxSizer->new(wxVERTICAL); $self->SetSizer($mainSizer); my $headerSizer = Wx::BoxSizer->new(wxHORIZONTAL); my $bodySizer = Wx::BoxSizer->new(wxHORIZONTAL); my $leftbodySizer = Wx::BoxSizer->new(wxVERTICAL); my $rightbodySizer = Wx::BoxSizer->new(wxVERTICAL); my $footer1Sizer = Wx::BoxSizer->new(wxHORIZONTAL); my $footer2Sizer = Wx::BoxSizer->new(wxHORIZONTAL); my $footer3Sizer = Wx::BoxSizer->new(wxHORIZONTAL); # Layout Main Sizer $mainSizer->Add($headerSizer,0,0,0); $mainSizer->AddSpacer(20); $mainSizer->Add($bodySizer,0,0,0); $mainSizer->AddSpacer(30); $mainSizer->Add($footer1Sizer,0,0,0); $mainSizer->AddSpacer(10); $mainSizer->Add($footer2Sizer,0,0,0); $mainSizer->AddSpacer(10); $mainSizer->Add($footer3Sizer,0,0,0); # Layout Header Sizer $headerSizer->AddSpacer(150); $headerSizer->Add($self->{titletext},0,0,0); # Layout Body Sizer $bodySizer->Add($leftbodySizer,0,0,0); $bodySizer->AddSpacer(50); $bodySizer->Add($rightbodySizer,0,0,0); # Layout Left and Right Body Sizers $leftbodySizer->Add($self->{},0,0,0); $rightbodySizer->Add($self->{},0,0,0); # Layout Footer Sizers $footer1Sizer->Add($self->{},0,0,0); $footer2Sizer->Add($self->{},0,0,0); $footer3Sizer->Add($self->{},0,0,0); # Assign mainSizer to the Frame and trigger layout $mainSizer->Fit($self); $mainSizer->Layout(); # Event Handler Template Wx::Event::EVT_BUTTON($self, $button, sub { my ($self, $event) = @_; }); Wx::Event::EVT_TEXT($self, $text, sub { my ($self, $event) = @_; }); # Define Timer $self->{timer} = Wx::Timer->new($self); # Start Timer $self->{timer}->Start(1000); # 1 sec period return $self; } 1;

    James

    There's never enough time to do it right, but always enough time to do it over...

Re: wimpole wxperl help
by Anonymous Monk on Aug 18, 2016 at 23:07 UTC

    Pick one problem please

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1170004]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found