Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Google Translator -> wxPerl frontend

by Anonymous Monk
on Oct 04, 2010 at 13:59 UTC ( #863347=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Google Translator -> wxPerl frontend
in thread Google Translator -> wxPerl frontend

fixed the size of the frame by removing Min & Max buttons..

Removing minimize/maximize/close buttons is cardinal sin, don't do that.

You were almost there

#!/usr/bin/perl -w -- # generated by wxGlade 0.6.3 on Sun Oct 3 14:38:31 2010 # To get wxPerl visit http://wxPerl.sourceforge.net/ use Wx 0.15 qw[:allclasses]; use strict; package MyFrame1; use Wx qw[:everything]; use base qw(Wx::Frame); use strict; use Lingua::Translate; Lingua::Translate::config ( back_end => 'Google', referer => 'http://dheeb.wordpress.com', format => 'text', userip => '192.168.1.1',#### This is the IP address of your + end user which Google encourages you to supply. ); sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_ +; $parent = undef unless defined $parent; $id = -1 unless defined $id; $title = "" unless defined $title; $pos = wxDefaultPosition unless defined $pos; #~ $size = wxDefaultSize unless defined $size; $size = Wx::Size->new(428, 77) unless defined $size; $name = "" unless defined $name; # begin wxGlade: MyFrame1::new $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $sty +le, $name ); $self->{label_1} = Wx::StaticText->new($self, -1, "From : ", wxDef +aultPosition, wxDefaultSize, ); $self->{origin} = Wx::ComboBox->new($self, -1, "", wxDefaultPositi +on, wxDefaultSize, ["AutoDetect", "Arabic", "English", "French", "Dut +ch", "German", "Persian", "Turkish", "Japanese", "Italian", "Slovak", + "Serbian", "Thai", "Hindi", "Hebrew", "Spanish", "Greek", "Russian", + "Swedish", "Croation", "Polish", "Portuguese", "Filipino", "Irish", +"Malay", "Belarusian", "Czech", "Norwegian", "Swahili", "Catalan", "B +ulgarian", "Korean", "Indonesian", "Chinese", "Vietnamese", "Yiddish" +, "Afrikaans"], wxCB_DROPDOWN|wxCB_SIMPLE|wxCB_DROPDOWN|wxCB_READONLY +|wxCB_SORT); $self->{Swap} = Wx::Button->new($self, -1, "Swap <->"); $self->{label_2} = Wx::StaticText->new($self, -1, "To :", wxDefaul +tPosition, wxDefaultSize, ); $self->{destination} = Wx::ComboBox->new($self, -1, "", wxDefaultP +osition, wxDefaultSize, ["Arabic", "English", "French", "Dutch", "Ger +man", "Persian", "Turkish", "Japanese", "Italian", "Slovak", "Serbian +", "Thai", "Hindi", "Hebrew", "Spanish", "Greek", "Russian", "Swedish +", "Croation", "Polish", "Portuguese", "Filipino", "Irish", "Malay", +"Belarusian", "Czech", "Norwegian", "Swahili", "Catalan", "Bulgarian" +, "Korean", "Indonesian", "Chinese", "Vietnamese", "Yiddish", "Afrika +ans", "Ukrainian"], wxCB_DROPDOWN|wxCB_SIMPLE|wxCB_DROPDOWN|wxCB_READ +ONLY|wxCB_SORT); $self->{Trans} = Wx::Button->new($self, -1, "Trans!"); $self->{origin_text} = Wx::TextCtrl->new($self, -1, "", wxDefaultP +osition, wxDefaultSize, wxTE_MULTILINE|wxHSCROLL); $self->{translated_text} = Wx::TextCtrl->new($self, -1, "", wxDefa +ultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY); $self->{Credits} = Wx::Button->new($self, -1, "Credits"); $self->{Exit} = Wx::Button->new($self, -1, "Exit"); $self->__set_properties(); $self->__do_layout(); Wx::Event::EVT_BUTTON($self, $self->{Swap}->GetId, \&OnSwap); Wx::Event::EVT_BUTTON($self, $self->{Trans}->GetId, \&OnTrans); Wx::Event::EVT_BUTTON($self, $self->{Credits}->GetId, \&OnCredit); Wx::Event::EVT_BUTTON($self, $self->{Exit}->GetId, \&OnExit); # end wxGlade return $self; } sub __set_properties { my $self = shift; # begin wxGlade: MyFrame1::__set_properties $self->SetTitle("GTranslate"); $self->{origin}->SetSelection(0); $self->{destination}->SetSelection(0); $self->{origin_text}->SetMinSize(Wx::Size->new(428, 77)); # end wxGlade } sub __do_layout { my $self = shift; # begin wxGlade: MyFrame1::__do_layout $self->{sizer_2} = Wx::BoxSizer->new(wxVERTICAL); $self->{sizer_3} = Wx::BoxSizer->new(wxVERTICAL); $self->{sizer_4} = Wx::BoxSizer->new(wxHORIZONTAL); $self->{sizer_5} = Wx::BoxSizer->new(wxHORIZONTAL); $self->{sizer_5}->Add($self->{label_1}, 0, wxALIGN_CENTER_HORIZONT +AL|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_5}->Add($self->{origin}, 0, wxALIGN_CENTER_HORIZONTA +L|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_5}->Add($self->{Swap}, 0, wxALIGN_CENTER_HORIZONTAL| +wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_5}->Add($self->{label_2}, 0, wxALIGN_CENTER_HORIZONT +AL|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_5}->Add($self->{destination}, 0, wxALIGN_CENTER_HORI +ZONTAL|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_5}->Add($self->{Trans}, 0, wxALIGN_CENTER_HORIZONTAL +|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_3}->Add($self->{sizer_5}, 0, wxEXPAND, 0); $self->{sizer_3}->Add($self->{origin_text}, 1, wxEXPAND|wxALIGN_CE +NTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_3}->Add($self->{translated_text}, 1, wxEXPAND|wxALIG +N_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0); $self->{sizer_4}->Add($self->{Credits}, 0, wxALIGN_RIGHT, 0); $self->{sizer_4}->Add($self->{Exit}, 0, wxALIGN_RIGHT, 0); $self->{sizer_3}->Add($self->{sizer_4}, 0, wxEXPAND, 0); $self->{sizer_2}->Add($self->{sizer_3}, 1, wxEXPAND, 0); $self->SetSizer($self->{sizer_2}); $self->{sizer_2}->Fit($self); $self->{sizer_2}->SetSizeHints($self); $self->Layout(); # end wxGlade } sub OnTrans { my ($self, $event) = @_; # wxGlade: MyFrame1::OnTrans <event_handler> if ($self->{origin_text}->GetValue()) { my $tag_1 = getTag($self->{origin}->GetValue()); my $tag_2 = getTag($self->{destination}->GetValue()); my $message = $self->{origin_text}->GetValue(); my $object = Lingua::Translate->new( src => $tag_1, dest => $tag_2 + ); my $trans = $object->translate($message); $self->{translated_text}->SetValue($trans);} else {$event->Skip;} # end wxGlade } sub OnCredit { my ($self, $event) = @_; # wxGlade: MyFrame1::OnCredit <event_handler> my $credit = Wx::MessageDialog->new( $self, "All Credit goes to : \n Google : http://translate.google.com \n CPAN : Lingua::Translate - Lingua::Translate::Google \n wxPerl & wxGlade : perl_sourcer\@yahoo.com \n Still under testing ;) ", "Credits"); $credit->ShowModal; # end wxGlade } sub OnExit { my ($self, $event) = @_; # wxGlade: MyFrame1::OnExit <event_handler> $self->Close(); # end wxGlade } sub OnSwap { my ($self, $event) = @_; # wxGlade: MyFrame1::OnSwap <event_handler> my $first = $self->{origin}->GetValue(); my $second = $self->{destination}->GetValue(); if($first eq "AutoDetect"){ $self->{translated_text}->SetValue("Can't use AutoDetect on desti +nation ! Please choose a language & try again ..");} else { ($first, $second) = ($second, $first); $self->{origin}->SetValue($first); $self->{destination}->SetValue($second); } # end wxGlade } sub getTag { my $value = shift; my %tags = qw/ AutoDetect auto Arabic ar English en French fr Dutc +h nl German de Persian fa Turkish tr Japanese ja Italian it Slovak sk Serbian sr + Thai th Hindi hi Hebrew iw Spanish es Greek el Russian ru Swedish sv Croa +tion hr Polish pl Portuguese pt Filipino tl Irish ga Malay ms Belarusian +be Czech cs Norwegian no Swahili sw Catalan ca Bulgarian bg Korean ko Indones +ian id Chinese zh-CN Vietnamese vi Yiddish yi Afrikaans af Ukrainian +uk/; return my $tag = $tags{$value}; } # end of class MyFrame1 1; 1; package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $frame_2 = MyFrame1->new(); $app->SetTopWindow($frame_2); $frame_2->Show(1); $app->MainLoop(); }
What Do These Sizer Things Do?


Comment on Re^4: Google Translator -> wxPerl frontend
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-07-11 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (218 votes), past polls