Changeset 73


Ignore:
Timestamp:
08/19/08 09:06:09 (3 years ago)
Author:
szabgab
Message:

some code refactorin in the Padre::Demo code

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MANIFEST

    r72 r73  
    4141 
    4242eg/wx_demo/01_prompt.pl 
     43eg/wx_demo/03_filename.pl 
    4344 
    4445share/docview/print.xpm 
  • trunk/eg/wx_demo/01_prompt.pl

    r72 r73  
    1010 
    1111sub main { 
     12   open_frame(); 
    1213   my $name = prompt("What is your name?\n"); 
    1314   print_out("How are you $name today?\n"); 
    14  
    15    my $filename = promp_input_file("Select source file"); 
    16    print_out("The file you selected is $filename\n"); 
    1715 
    1816   return; 
  • trunk/lib/Padre/Demo.pm

    r72 r73  
    88use Padre::Demo::App; 
    99 
    10 our @EXPORT = qw(prompt print_out promp_input_file close_app); 
     10our @EXPORT = qw(prompt print_out promp_input_file close_app open_frame); 
    1111 
     12use Wx                 qw(:everything); 
     13use Wx::STC            (); 
     14use Wx::Event          qw(:everything); 
     15 
     16=head1 NAME 
     17 
     18Padre::Demo - temporary name of a Zenity clone in wxPerl 
     19 
     20=head1 SYNOPIS 
     21 
     22 use Padre::Demo; 
     23 
     24 Padre::Demo->run(\&main); 
     25 
     26 sub main { 
     27    my $name = prompt("What is your name?\n"); 
     28    print_out("How are you $name today?\n"); 
     29 
     30    return; 
     31 } 
     32 
     33Command line: 
     34 
     35 Not yet available. 
     36 
     37=head1 General Options 
     38 
     39There are some common option for every dialog 
     40 
     41title 
     42 
     43window-icon  Not implemented 
     44 
     45width 
     46 
     47height 
     48 
     49=cut 
     50 
     51=head1 METHODS 
     52 
     53Dialogs 
     54 
     55=head2 prompt 
     56 
     57Display a text entry dialog 
     58 
     59=cut 
    1260sub prompt { 
    13    my $frame = $Padre::Demo::App::frame; 
    14    $frame->prompt(@_); 
     61    my ($text) = @_; 
     62    my $frame = $Padre::Demo::App::frame; 
     63 
     64    my $dialog = Wx::TextEntryDialog->new( $frame, $text, "", '' ); 
     65    if ($dialog->ShowModal == wxID_CANCEL) { 
     66        return; 
     67    }    
     68    my $resp = $dialog->GetValue; 
     69    $dialog->Destroy; 
     70    return $resp; 
    1571} 
    1672 
     73 
     74 
     75=head2 print_out 
     76 
     77=cut 
    1778sub print_out { 
    1879   my $frame = $Padre::Demo::App::frame; 
     
    2081} 
    2182 
     83=head2 promp_input_file 
     84 
     85=cut 
    2286sub promp_input_file { 
    23    my $frame = $Padre::Demo::App::frame; 
    24    $frame->promp_input_file(@_); 
     87    my ($text) = @_; 
     88    my $frame = $Padre::Demo::App::frame; 
     89 
     90    my $dialog = Wx::FileDialog->new( $frame, $text, '', "", "*.*", wxFD_OPEN); 
     91    if ($^O !~ /win32/i) { 
     92       $dialog->SetWildcard("*"); 
     93    } 
     94    if ($dialog->ShowModal == wxID_CANCEL) { 
     95        return; 
     96    } 
     97    my $filename = $dialog->GetFilename; 
     98    my $default_dir = $dialog->GetDirectory; 
     99 
     100    return File::Spec->catfile($default_dir, $filename); 
    25101} 
    26102 
     103 
     104 
     105=head2 open_frame 
     106 
     107=cut 
     108sub open_frame { 
     109    
     110} 
     111 
     112 
     113=head2 close_app 
     114 
     115=cut 
    27116sub close_app { 
    28117   my $frame = $Padre::Demo::App::frame; 
    29118   $frame->Close; 
    30119} 
     120 
     121 
     122 
     123 
    31124 
    32125sub get_frame { 
  • trunk/lib/Padre/Demo/Frame.pm

    r71 r73  
    1414my $output; 
    1515 
    16 sub prompt { 
    17     my ($self, $text) = @_; 
    18  
    19     my $dialog = Wx::TextEntryDialog->new( $self, $text, "", '' ); 
    20     if ($dialog->ShowModal == wxID_CANCEL) { 
    21         return; 
    22     }    
    23     my $resp = $dialog->GetValue; 
    24     $dialog->Destroy; 
    25     return $resp; 
    26 } 
    27  
    2816sub print_out { 
    2917    my ($self, $text) = @_; 
    3018    $output->AddText($text); 
    3119    return; 
    32 } 
    33  
    34 sub promp_input_file { 
    35     my ($self, $text) = @_; 
    36  
    37     my $dialog = Wx::FileDialog->new( $self, $text, '', "", "*.*", wxFD_OPEN); 
    38     if ($^O !~ /win32/i) { 
    39        $dialog->SetWildcard("*"); 
    40     } 
    41     if ($dialog->ShowModal == wxID_CANCEL) { 
    42         return; 
    43     } 
    44     my $filename = $dialog->GetFilename; 
    45     my $default_dir = $dialog->GetDirectory; 
    46  
    47     return File::Spec->catfile($default_dir, $filename); 
    4820} 
    4921 
     
    6032    ); 
    6133 
    62     my $editor = Wx::StyledTextCtrl->new($self, -1, [-1, -1], [750, 700]); 
    63     $editor->SetMarginWidth(1, 0); 
     34    $output = Wx::StyledTextCtrl->new($self, -1, [-1, -1], [750, 700]); 
     35    $output->SetMarginWidth(1, 0); 
    6436 
    65     EVT_ACTIVATE($self, sub {on_activate($editor, @_) }); 
    66  
    67 #    my $button = Wx::Button->new( $self, -1, "Run" ); 
    68 #    Wx::Event::EVT_BUTTON( $self, $button, sub { 
    69 #         my ( $self, $event ) = @_; 
    70 #         print "preparing to popup window...\n"; 
    71 #         Wx::MessageBox( "This is the smell of an Onion", "Title", wxOK|wxCENTRE, $self ); 
    72 #    }); 
    73 #    $self->SetSize($button->GetSizeWH); 
     37    EVT_ACTIVATE($self, \&on_activate); 
    7438 
    7539    Wx::Event::EVT_CLOSE( $self,  sub { 
     
    8246 
    8347sub on_activate { 
    84    my ($editor, $frame, $event) = @_; 
     48   my ($frame, $event) = @_; 
    8549 
    86    $output = $editor; 
    8750   $frame->EVT_ACTIVATE(sub {}); 
    8851   #$Padre::Demo::app->Yield; 
Note: See TracChangeset for help on using the changeset viewer.