Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

WxBrowser - a wxPerl HTML Browser

by crazyinsomniac (Prior)
on May 06, 2002 at 14:42 UTC ( #164341=sourcecode: print w/ replies, xml ) Need Help??

Category: GUI Programming
Author/Contact Info /tell crazyinsomniac
Description: A crude HTML Browser written using wxPerl. More of a minimalistic demo than anything. Nice layout IMO (a hint of things to come).

If you want the GOBAR at the bottom, just ## switch these two lines, the wxBOTTOM or wxTOP don't matter
$sizer1->Add( $sizer3, 0, wxGROW|wxTOP, 0 );
$sizer1->Add( $sizer2, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 0 );

#!/usr/bin/perl -w

package WxBrowser::GUI;
use strict;
use Wx qw/:everything/;
use Wx::Html;
use base qw(Wx::Frame);

use Wx::Event qw( EVT_BUTTON EVT_MENU);

use vars qw/ %ID_ $I/;

%ID_ = map { $_ => 1000 + int(rand 30) + $I++
        } qw/ GOTEXT GOBUTTON HTML ABOUT QUIT GOTEXT/;

sub new {
    my( $class ) = shift;
    my( $this ) = $class->SUPER::new(
                    undef, -1,
                    "WxBrowser - a wxPerl HTML Browser ",
                    [0,0],
                    [300,300],
                    wxDEFAULT_FRAME_STYLE| wxCLIP_CHILDREN,
                 );


    $this->CreateStatusBar( 2 );
    $this->SetStatusText( "Welcome to WxBrowser!", 1);

    $this->GOOEY();
    $this->SetMenuBar( MENUU($this) );

    EVT_BUTTON( $this, $ID_{GOBUTTON}, \&GONOW );
    EVT_MENU( $this, $ID_{ABOUT}, \&OnAbout );
    EVT_MENU( $this, $ID_{QUIT}, \&OnQuit );

    return $this;
}


sub OnAbout {
    my( $this, $event ) = @_;
    
    Wx::MessageBox( "Welcome to WxBrowser 1.0

WxBrowser is a crude browser created as a demo of wxPerl
Has basic support for html (probably html 1.0 or 2.0)
That means, no cookies, no images, no forms, bad tables ;)

(C)opyright CrazyInsomniac of PerlMonks.org.
This program is released under the same terms as perl itself
(if you don't know what that means, visit perl.com )
",
        "About WxBrowser", wxOK|wxICON_INFORMATION, $this );
}

sub OnQuit {
    my( $this, $event ) = @_;
    
    $this->Close(1);
}


sub MENUU {
    my( $bar ) = Wx::MenuBar->new();
    
    my( $filemenu ) = Wx::Menu->new();
    $filemenu->Append( $ID_{ABOUT}, "About", "Find Out Who Created WxB
+rowser" );
    $filemenu->Append( $ID_{QUIT}, "Quit", "Exit this application" );
    $bar->Append( $filemenu, "File" );
    return $bar;
}

sub GONOW {
    my ($this, $event) = @_;
    my $html = $this->FindWindow($ID_{HTML});
    my $text = $this->FindWindow($ID_{GOTEXT});

    $html->LoadPage($text->GetValue());

    return();
}

sub GOOEY{
    my $parent = shift;
    my( $sizer1 ) = Wx::BoxSizer->new( wxVERTICAL );
    
    my( $sizer2 ) = Wx::BoxSizer->new( wxVERTICAL );

    my( $htmlsizer ) = Wx::BoxSizer->new( wxVERTICAL ); ###

    my( $html ) = Wx::HtmlWindow->new( ###
                        $parent,
                        $ID_{HTML},
                        wxDefaultPosition,
                        wxDefaultSize,
                    );



    $html->SetRelatedFrame($parent, "WxBrowser: %s");
    $html->SetRelatedStatusBar(0);



    $html->SetPage('<H1><a href="http://perlmonk.org/~grinder"><font c
+olor="#be2076">W</font><font color="#b15088">a</font><font color="#a2
+8999">v</font><font color="#93bea9">e</font> <font color="#83e3b9">i<
+/font><font color="#73efc7">t</font> <font color="#63e0d3">h</font><f
+ont color="#54b9dd">i</font><font color="#4583e5">g</font><font color
+="#374aeb">h</font><font color="#2a1cef">,</font><P><font color="#1e0
+2ef">l</font><font color="#1404ee">e</font><font color="#0c08e9">t</f
+ont> <font color="#060de3">t</font><font color="#0214da">h</font><fon
+t color="#001bcf">a</font><font color="#0024c2">t</font> <font color=
+"#092eb3">f</font><font color="#1e38a4">r</font><font color="#3d4393"
+>e</font><font color="#624f82">a</font><font color="#8a5b70">k</font>
+<P><font color="#af685f">f</font><font color="#cf754e">l</font><font 
+color="#e5813e">a</font><font color="#ef8e2f">g</font> <font color="#
+ec9a22">f</font><font color="#dda617">l</font><font color="#c2b20d">y
+</font>!</a></H1>');

    $htmlsizer->AddWindow( $html, 1, wxALIGN_CENTRE|wxGROW, 0 );###

    $sizer2->Add($htmlsizer, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 0 );##
+#

    my( $sizer3 ) = Wx::BoxSizer->new( wxHORIZONTAL );
    
    my( $text ) = Wx::TextCtrl->new( $parent, $ID_{GOTEXT},
            "http://perlmonk.org/#jc+wrocks!",
            wxDefaultPosition,
#            [460,-1],
            wxDefaultSize,
            wxGROW # I don't even know if this works here
        );
    $sizer3->AddWindow( $text, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL, 0 
+);

    my( $item9 ) = Wx::Button->new( $parent,
            $ID_{GOBUTTON},
            "GO",
            wxDefaultPosition,
            [50,20], 0
        );
    $sizer3->AddWindow( $item9, 0, wxALIGN_RIGHT|wxALL, 0 );


## switch these two lines, the wxBOTTOM  or wxTOP don't matter
    $sizer1->Add( $sizer3, 0, wxGROW|wxTOP, 0 );
    $sizer1->Add( $sizer2, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 0 );

    $parent->SetAutoLayout( 1 );
    $parent->SetSizer( $sizer1 );
}



package WxBrowser;

use strict;
use base qw(Wx::App);
use Wx qw(:everything);

sub OnInit {
    my( $this ) = @_;

    my( $frame ) = new WxBrowser::GUI();
    $frame->Show(1);
    1;
}


package main;

my $Browser = new WxBrowser();
$Browser->MainLoop();

__END__

=pod

Run the program!

=cut

Comment on WxBrowser - a wxPerl HTML Browser
Download Code
Re: WxBrowser - a wxPerl HTML Browser
by ka1958 (Initiate) on Mar 09, 2010 at 12:53 UTC
    This is excelent. Thanks you for posting. Will be an awesome foundation for a full featured perl web browser I intend to write. Cant believe it took me so long to find it. ^_^ Cheers, Kyle.

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://164341]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-04-18 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (472 votes), past polls