From: DH <cra...@ya...> - 2002-05-10 03:57:16
|
The GUI i am writing is included below. To see the two behaviours just try if(0) or if(1) over after #### THE SWITCH ################################### line in the code. I got a screenshot of the two versions at http://crazyinsomniac.perlmonk.org/images/dillema.jpeg The Frame version looks AWFUL. There is horrible flickering, and it looks checkered. But, the Frame version exibits one behaviour which I like, when you attempt to resize the app, the frame version does not allow the user to resize it beyond the minimum size, that is, the frame version can never become a tiny little box. The Panel version looks EXCELLENT (still flicker on resize, but at least its painted *clean*) buuuut sadly this version can be resized into a tiny little box. I don't like that. Does anyone know how I can get the nice Panel-ized lood, with the Frame resize behaviour? oh yeah, heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelp!;D ### newgui.pl package RegexLab; use strict; use Wx qw/ :everything /; use base 'Wx::Frame'; sub new { my( $class ) = shift; my( $this ) = $class->SUPER::new( undef, -1, "Regex Lab - you know what it is ;)", [0,0], [350,350], wxDEFAULT_FRAME_STYLE # | wxCLIP_CHILDREN, # for easy commenting out ); $this->SetIcon( Wx::GetWxPerlIcon() ); ################################################### #### THE SWITCH ################################### ################################################### if(1) { use vars qw/ $COLOR /; # $COLOR = Wx::Colour->new(212,208,200); # $this->SetBackgroundColour($COLOR); # doesn't stop flicker++ GUI($this); # use Wx::Event qw/ EVT_SIZE /; # EVT_SIZE($this,\&OnSize); } else { ## Panels make everything pretty (no repainting issues) my $p = Wx::Panel->new( $this, -1, [50,50], [350,350], ); GUI($p); # use Wx::Event qw/ EVT_SIZE /; # EVT_SIZE($this,\&OnSize); } return $this; } sub OnSize { my( $this, $event ) = @_; my( $x, $y ) = $this->GetClientSizeXY(); my( $size ) = $event->GetSize(); my( $skip ) = 1; if( $x < 350 ) { $size->SetWidth(350); $skip = 0; } if( $y < 350 ) { $size->SetHeight(350); $skip = 0; } $event->Skip if $skip; # use Data::Dumper; # warn Dumper \@_; # warn "x $x y $y"; # warn "ex $eX ey $eY"; } sub BOXS { my( $parent, $str, $orient ) = @_; return Wx::StaticBoxSizer->new( Wx::StaticBox->new( $parent, -1, $str, ,), $orient, ,); } sub ID { use vars qw/ %ID_ $I/; # mess with at you own risk my( $key ) = @_; $I ||=6660; # $I is the perpetual ID incrementor if(exists $ID_{$key} ) { return $ID_{$key}; } else { return $ID_{$key} = ++$I; } } sub MahCheck { my( $parent, $IdKey, $str ) = @_; return Wx::CheckBox->new( $parent, ID($IdKey), # works with %ID_ $str, wxDefaultPosition, wxDefaultSize, 5, , ); } sub TEXS { my( $parent, $id, $init, $poss, $size ) = @_; $poss ||= wxDefaultPosition; $size ||=[300,40]; return Wx::TextCtrl->new( $parent, ID($id), $init, $poss, $size, wxTE_MULTILINE, ,); } sub GUI { my( $parent ) = @_; my( $RootSizer ) = Wx::BoxSizer->new( wxVERTICAL ); my( $RegexSizer ) = BOXS($parent, "Regex String", wxHORIZONTAL); my( $RegexString ) = TEXS( $parent, REGEXSTRING => "\\b([b-df-hj-np-tv-z])(\\w+)", ,); $RegexString->SetToolTip("insert regular expression pattern here"); $RegexSizer->AddWindow( $RegexString, 1, wxGROW|wxALIGN_CENTRE, 5,); $RootSizer->Add( $RegexSizer, 0, wxGROW|wxTOP|wxALIGN_CENTRE, 5 ); ## ROOT my( $RepCheckbox ) = MahCheck( $parent, REPLACEMENTCHECKBOX => "Make mine a replacement!", ,); $RepCheckbox->SetToolTip("don't just match (m//), substitute (s///) instead"); $RootSizer->AddWindow( $RepCheckbox, 0, wxGROW|wxTOP|wxALIGN_LEFT, 5 ); ## even though left is default, being explicit is good (it's documentation) my( $RepSizer ) = BOXS($parent, "Replacement String:", wxHORIZONTAL); my( $Rep ) = TEXS( $parent, REPSTRING => '$2-$1ay' ); Wx::ToolTip::Enable(1); Wx::ToolTip::SetDelay(50); # ms $Rep->SetToolTip( 's{pattern}{stuff you enter here goes here}' ); ## tool tips seem to suck for lables and text controls $Rep->Enable( 0 ); $RepSizer->Add( $Rep, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ); my( $TestSizer ) = BOXS($parent, "Test String (aka input):", wxHORIZONTAL); my( $TestInput ) = TEXS( $parent, TEXTCTRL => "hello world!" ); $TestInput->SetToolTip("string to operate on goes here"); $TestSizer->AddWindow( $TestInput, 1, wxALIGN_CENTRE, 5 ); my( $FlagSizer2 ) = BOXS($parent, "Flags (aka modifiers):", wxHORIZONTAL); my( $FlagSizer1 ) = Wx::BoxSizer->new( wxHORIZONTAL ); my( $gMOD ) = MahCheck( $parent, GFLAGCHECKBOX => "g", ); $gMOD->SetToolTip("g - match globally"); $FlagSizer1->AddWindow( $gMOD, 0, wxALIGN_CENTRE|wxALL, 5,); my $iMOD = MahCheck( $parent, IFLAGCHECKBOX => "i", ); $iMOD->SetToolTip("i - Do case-insensitive pattern matching." ."\nIf use locale is in effect, the case map is taken from the". "current locale. See the perllocale manpage."); $FlagSizer1->AddWindow( $iMOD, 0, wxALIGN_CENTRE|wxALL, 5,); my( $mMOD ) = MahCheck( $parent, MFLAGCHECKBOX => "m", ); $mMOD->SetToolTip("m - Treat string as multiple lines.\n\nThat is, change" ."``^'' and ``$'' from matching the start or end of the string to" ."matching the start or end of any line anywhere within the string. "); $FlagSizer1->AddWindow( $mMOD, 0, wxALIGN_CENTRE|wxALL, 5,); #rohnettes opened for the stones my( $sMOD ) = MahCheck( $parent, SFLAGCHECKBOX => "s", ); $sMOD->SetToolTip("Treat string as single line. \n\nThat is, change" ."``.'' to match any character whatsoever, even a newline, which" ."normally it would not match."); $FlagSizer1->AddWindow($sMOD , 0, wxALIGN_CENTRE|wxALL, 5,); my( $xMOD ) = MahCheck( $parent, XFLAGCHECKBOX => "x", ); $xMOD->SetToolTip("x - Extend your pattern's legibility by permitting" ."whitespace and comments. "); $FlagSizer1->AddWindow( $xMOD, 0, wxALIGN_CENTRE|wxALL, 5, ); my $eMOD = MahCheck( $parent, EFLAGCHECKBOX => "e", ); $eMOD->Enable(0); $eMOD->SetToolTip("e - Evaluate the right side as an expression."); $FlagSizer1->AddWindow( $eMOD, 0, wxALIGN_CENTRE|wxALL, 5, ); my( $TestButtonSizer ) = Wx::BoxSizer->new( wxVERTICAL ); my( $TestButton ) = Wx::Button->new( $parent, ID('TESTBUTTON'), "Test regex", wxDefaultPosition, wxDefaultSize, wxNO_BORDER ); $TestButton->SetToolTip("eval that code\ntest your *hypothesis* ;)"); $TestButton->SetDefault(); $TestButtonSizer->AddWindow( $TestButton, 1, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 ); $FlagSizer2->Add( $FlagSizer1, 1, wxGROW|wxALIGN_CENTRE, 0 ); $FlagSizer2->Add( $TestButtonSizer, 1, wxGROW|wxALIGN_RIGHT, 0 ); use Wx::Html; my( $HtmlOUT ) = Wx::HtmlWindow->new( $parent, -1 ); ## a 1 make it resize with sizer/window according to type (horiz/vert) $RootSizer->Add( $RepSizer, 0, wxGROW|wxTOP|wxALIGN_CENTRE, 5 ); $RootSizer->Add( $TestSizer, 0, wxGROW|wxTOP|wxALIGN_CENTRE, 5 ); $RootSizer->Add( $FlagSizer2, 0, wxGROW|wxTOP|wxALIGN_CENTRE, 5 ); ### PADDING Add( width, height, option, flag, border ) ## $RootSizer->Add( 0, 5, 0, 0, 0); ## no need since I figured out BORDERS (wxSIDE or wxALL) $RootSizer->Add( $HtmlOUT, 1, wxGROW|wxTOP|wxALIGN_CENTRE, 5 ); $parent->SetAutoLayout( 1 ); $parent->SetSizer( $RootSizer ); $RootSizer->Fit( $parent ); $RootSizer->SetSizeHints( $parent ); return $RootSizer; } package RegexLab::App; use strict; use Wx; use base qw(Wx::App); sub OnInit { my( $this ) = @_; my( $frame ) = new RegexLab(); $frame->Show(1); $frame->Refresh(); 1; } package main; unless( caller() ) { RegexLab::App->new()->MainLoop(); } __END__ =head1 NAME RegexLab - a Wx Dialog/App for testing Regular Expressions =head1 SYNOPSIS perl -MRegexLab -e RegexLab::App->new()->MainLoop() # or use RegexLab; # or should it be Wx::RegexLab . . . # your Wx::App subclass, ie your Wx::App application # where $this refers to an instance of it # usually called from a menu item RegexLab::GUI($this); # or RegexLab::GUI( new Wx::Frame( $this, -1) ); # or RegexLab::GUI( new Wx::Panel( $this, -1) ); # or even RegexLab::App->new()->MainLoop(); =head1 DESCRIPTION =head1 AUTHOR Originally written by boo_radley of PerlMonks.org fame. Transformed into its this form by crazyinsomniac (same fame), for easy inclusion in other Wx applications, or for standalone use. =cut __________________________________________________ Do You Yahoo!? Yahoo! Shopping - Mother's Day is May 12th! http://shopping.yahoo.com |
From: DH <cra...@ya...> - 2002-05-10 07:25:11
|
It appears that currently, AppendToPage is not available. Are there plans to add it? __________________________________________________ Do You Yahoo!? Yahoo! Shopping - Mother's Day is May 12th! http://shopping.yahoo.com |
From: Mattia B. <mb...@ds...> - 2002-05-10 18:57:45
|
> It appears that currently, AppendToPage is not available. > Are there plans to add it? It is available only in wxWindows 2.3.2 or later. Will be in the next release, when wxWIn 2.3.3 is released. Regards Mattia |