| 1 | # Module name: CPANPLUS::Shell::Wx::PODReader | ||
| 2 | # Author: Skaman Sam Tyler | ||
| 3 | # Date: May 9th, 2008 | ||
| 4 | # Description: This is a perl Module which is a frontend to CPANPLUS. | ||
| 5 | # | ||
| 6 | # generated by wxGlade 0.6.1 on Tue Jul 1 08:11:13 2008 | ||
| 7 | # To get wxPerl visit http://wxPerl.sourceforge.net/ | ||
| 8 | # | ||
| 9 | |||
| 10 | # Preloaded methods go here. | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | CPANPLUS::Shell::Wx::PODReader - GUI POD Reader | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | use Wx qw[:allclasses]; | ||
| 19 | use CPANPLUS::Shell::Wx::PODReader; | ||
| 20 | |||
| 21 | local *Wx::App::OnInit = sub{1}; | ||
| 22 | my $app = Wx::App->new(); | ||
| 23 | Wx::InitAllImageHandlers(); | ||
| 24 | |||
| 25 | my $frame_podreader = CPANPLUS::Shell::Wx::PODReader::Frame->new(); | ||
| 26 | |||
| 27 | $app->SetTopWindow($frame_podreader); | ||
| 28 | $frame_podreader->Show(1); | ||
| 29 | $app->MainLoop(); | ||
| 30 | ..... | ||
| 31 | $frame_podreader->Search($module_name,$where) | ||
| 32 | |||
| 33 | also | ||
| 34 | |||
| 35 | $podReader=CPANPLUS::Shell::Wx::PODReader::Embed->new($notebook); | ||
| 36 | $notebook->AddPage($podReader,"POD Reader"); | ||
| 37 | |||
| 38 | |||
| 39 | =head1 DESCRIPTION | ||
| 40 | |||
| 41 | There are two types of PODReader: a windowed version, | ||
| 42 | CPANPLUS::Shell::Wx::PODReader::Frame (a Wx::Frame), and a version which | ||
| 43 | can be embedded within other Wx::Windows, | ||
| 44 | CPANPLUS::Shell::Wx::PODReader::Emed (a Wx::Panel). They both have only one method, | ||
| 45 | Search(). | ||
| 46 | |||
| 47 | =head1 GUI DESCRIPTION | ||
| 48 | |||
| 49 | The GUI contains 3 basic entities: a Search Bar, the Status Text, and the | ||
| 50 | Tabs. | ||
| 51 | |||
| 52 | =head2 Search Bar | ||
| 53 | |||
| 54 | The search bar contains a Find button, which enacts the Search() facility, a | ||
| 55 | ComboBox, which is where you can type in the text to search for, and the | ||
| 56 | type box, where you can select where you want to search for the documentation. | ||
| 57 | It looks like this: | ||
| 58 | Find $text in $where. | ||
| 59 | The search box displays the previous 10 successful searches between sessions, | ||
| 60 | in $HOME/.wxPODReader/searches.txt. You can type in the location of a file | ||
| 61 | in this box to see the POD for that file. | ||
| 62 | |||
| 63 | |||
| 64 | =head2 Status Text | ||
| 65 | |||
| 66 | Some status information is displayed here. | ||
| 67 | |||
| 68 | =head2 Tabs | ||
| 69 | |||
| 70 | There are 4 tabs available: "Builtin Methods", "FAQ", "Module" | ||
| 71 | and "Source". They correspond to the values in the 'type' dropdown list. | ||
| 72 | Only the relevant tabs are displayed per search. | ||
| 73 | |||
| 74 | =head1 METHODS | ||
| 75 | |||
| 76 | =head2 $podreader->Search($text,$where) | ||
| 77 | |||
| 78 | This method searches for pod documentation, using the perldoc command. | ||
| 79 | |||
| 80 | =over 4 | ||
| 81 | |||
| 82 | =item $text | ||
| 83 | |||
| 84 | =over 4 | ||
| 85 | |||
| 86 | The text to search for. Can be anything. | ||
| 87 | |||
| 88 | =back | ||
| 89 | |||
| 90 | =item $where | ||
| 91 | |||
| 92 | =over 4 | ||
| 93 | |||
| 94 | The place to look for documentation. Can be any one of | ||
| 95 | "All", "Builtin Methods", "FAQ", "Modules" or "Sources". The default is 'All', | ||
| 96 | which searches through all documentation, and displays only the tabs that | ||
| 97 | contain the result. For example, a search for CPANPLUS will only show | ||
| 98 | the Source and Module tab. | ||
| 99 | |||
| 100 | =back | ||
| 101 | |||
| 102 | =back | ||
| 103 | |||
| 104 | =head1 SEE ALSO | ||
| 105 | |||
| 106 | CPAN, CPANPLUS, CPANPLUS::Shell::Tk | ||
| 107 | |||
| 108 | website: http://wxcpan.googlecode.com | ||
| 109 | mailing-list: wxcpan@googlegroups.com | ||
| 110 | mailing-list website: http://groups.google.com/group/wxcpan | ||
| 111 | |||
| 112 | =head1 AUTHOR | ||
| 113 | |||
| 114 | Skaman Sam Tyler, E<lt>skamansam@gmail.comE<gt> | ||
| 115 | website: http://rbe.homeip.net | ||
| 116 | |||
| 117 | =head1 COPYRIGHT AND LICENSE | ||
| 118 | |||
| 119 | Copyright (C) 2008 by Skaman Sam Tyler | ||
| 120 | |||
| 121 | This library is free software; you can redistribute it and/or modify | ||
| 122 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||
| 123 | at your option, any later version of Perl 5 you may have available. | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | |||
| 128 | package CPANPLUS::Shell::Wx::PODReader::Embed; | ||
| 129 | 0 | ▶ | use Wx qw[:everything]; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 130 | use base qw(Wx::Panel); | ||
| 131 | use strict; | ||
| 132 | use File::Spec; | ||
| 133 | use Data::Dumper; | ||
| 134 | use LWP::Simple; | ||
| 135 | use URI::Escape; | ||
| 136 | use File::HomeDir; | ||
| 137 | |||
| 138 | use constant NUM_SEARCHES=>10; | ||
| 139 | |||
| 140 | sub new { | ||
| 141 | my( $self, $parent, $id, $pos, $size, $style, $name ) = @_; | ||
| 142 | $parent = undef unless defined $parent; | ||
| 143 | $id = -1 unless defined $id; | ||
| 144 | $pos = wxDefaultPosition unless defined $pos; | ||
| 145 | $size = wxDefaultSize unless defined $size; | ||
| 146 | $name = "" unless defined $name; | ||
| 147 | |||
| 148 | |||
| 149 | $style = wxTAB_TRAVERSAL | ||
| 150 | unless defined $style; | ||
| 151 | |||
| 152 | Wx::InitAllImageHandlers(); | ||
| 153 | |||
| 154 | $self = $self->SUPER::new( $parent, $id, $pos, $size, $style, $name ); | ||
| 155 | |||
| 156 | $self->{nb_podreader} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, 0); | ||
| 157 | |||
| 158 | #setup tabs | ||
| 159 | $self->{module_tab} = Wx::Panel->new($self->{nb_podreader}, -1, wxDefaultPosition, wxDefaultSize, ); | ||
| 160 | $self->{faq_tab} = Wx::Panel->new($self->{nb_podreader}, -1, wxDefaultPosition, wxDefaultSize, ); | ||
| 161 | $self->{builtin_tab} = Wx::Panel->new($self->{nb_podreader}, -1, wxDefaultPosition, wxDefaultSize, ); | ||
| 162 | $self->{source_tab} = Wx::Panel->new($self->{nb_podreader}, -1, wxDefaultPosition, wxDefaultSize, ); | ||
| 163 | |||
| 164 | #setup search | ||
| 165 | $self->{search_btn} = Wx::Button->new($self, wxID_FIND, ""); | ||
| 166 | $self->{search_text} = Wx::ComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_DROPDOWN); | ||
| 167 | $self->{label_1} = Wx::StaticText->new($self, -1, " in ", wxDefaultPosition, wxDefaultSize, ); | ||
| 168 | $self->{status_text} = Wx::StaticText->new($self, -1, "[No Module Found]", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); | ||
| 169 | $self->{type_text} = Wx::ComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, ["All", "Builtin Methods", "FAQ", "Modules","Sources"], wxCB_DROPDOWN); | ||
| 170 | $self->{search_text}->SetSelection(-1); | ||
| 171 | $self->{type_text}->SetSelection(0); | ||
| 172 | |||
| 173 | $self->{module_text} = Wx::HtmlWindow->new($self->{module_tab}, -1); | ||
| 174 | $self->{faq_text} = Wx::HtmlWindow->new($self->{faq_tab}, -1); | ||
| 175 | $self->{source_text} = Wx::RichTextCtrl->new($self->{source_tab}, -1); | ||
| 176 | $self->{builtin_text} = Wx::HtmlWindow->new($self->{builtin_tab}, -1); | ||
| 177 | $self->{builtin_tab}->Show(0); | ||
| 178 | $self->{faq_tab}->Show(0); | ||
| 179 | $self->{module_tab}->Show(0); | ||
| 180 | $self->{source_tab}->Show(0); | ||
| 181 | |||
| 182 | $self->{podreader_embed_sizer} = Wx::BoxSizer->new(wxVERTICAL); | ||
| 183 | $self->{sizer_module} = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 184 | $self->{sizer_faq} = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 185 | $self->{sizer_builtin} = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 186 | $self->{sizer_source} = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 187 | $self->{sizer_search} = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 188 | $self->{sizer_search}->Add($self->{search_btn}, 0, wxADJUST_MINSIZE, 0); | ||
| 189 | $self->{sizer_search}->Add($self->{search_text}, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxADJUST_MINSIZE, 0); | ||
| 190 | $self->{sizer_search}->Add($self->{label_1}, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxADJUST_MINSIZE, 0); | ||
| 191 | $self->{sizer_search}->Add($self->{type_text}, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxADJUST_MINSIZE, 0); | ||
| 192 | $self->{podreader_embed_sizer}->Add($self->{sizer_search}, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0); | ||
| 193 | $self->{podreader_embed_sizer}->Add($self->{status_text}, 0, wxEXPAND, 0); | ||
| 194 | |||
| 195 | $self->{sizer_builtin}->Add($self->{builtin_text}, 1, wxEXPAND|wxADJUST_MINSIZE, 0); | ||
| 196 | $self->{builtin_tab}->SetSizer($self->{sizer_builtin}); | ||
| 197 | $self->{sizer_faq}->Add($self->{faq_text}, 1, wxEXPAND|wxADJUST_MINSIZE, 0); | ||
| 198 | $self->{faq_tab}->SetSizer($self->{sizer_faq}); | ||
| 199 | $self->{sizer_module}->Add($self->{module_text}, 1, wxEXPAND|wxADJUST_MINSIZE, 0); | ||
| 200 | $self->{module_tab}->SetSizer($self->{sizer_module}); | ||
| 201 | $self->{sizer_source}->Add($self->{source_text}, 1, wxEXPAND|wxADJUST_MINSIZE, 0); | ||
| 202 | $self->{source_tab}->SetSizer($self->{sizer_source}); | ||
| 203 | $self->{nb_podreader}->AddPage($self->{builtin_tab}, "Builtin"); | ||
| 204 | $self->{nb_podreader}->AddPage($self->{faq_tab}, "FAQ"); | ||
| 205 | $self->{nb_podreader}->AddPage($self->{module_tab}, "Modules"); | ||
| 206 | $self->{nb_podreader}->AddPage($self->{source_tab}, "Source"); | ||
| 207 | $self->{podreader_embed_sizer}->Add($self->{nb_podreader}, 2, wxEXPAND, 0); | ||
| 208 | $self->SetSizer($self->{podreader_embed_sizer}); | ||
| 209 | $self->{podreader_embed_sizer}->Fit($self); | ||
| 210 | |||
| 211 | Wx::Event::EVT_WINDOW_DESTROY($self,$self->GetId,\&SaveSearches); | ||
| 212 | Wx::Event::EVT_BUTTON($self, $self->{search_btn}->GetId, | ||
| 213 | sub{$self->Search($self->{search_text}->GetValue,$self->{type_text}->GetValue);} | ||
| 214 | ); | ||
| 215 | Wx::Event::EVT_TEXT_ENTER($self, $self->{search_text}->GetId, | ||
| 216 | sub{$self->Search($self->{search_text}->GetValue,$self->{type_text}->GetValue);} | ||
| 217 | ); | ||
| 218 | Wx::Event::EVT_HTML_LINK_CLICKED($self,$self->{module_text}->GetId,\&OnLinkClicked); | ||
| 219 | Wx::Event::EVT_HTML_LINK_CLICKED($self,$self->{builtin_text}->GetId,\&OnLinkClicked); | ||
| 220 | Wx::Event::EVT_HTML_LINK_CLICKED($self,$self->{faq_text}->GetId,\&OnLinkClicked); | ||
| 221 | |||
| 222 | $self->{searches}=GetSearches(); | ||
| 223 | foreach my $s (@{$self->{searches}}){ | ||
| 224 | $self->{search_text}->Append($s); | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | return $self; | ||
| 230 | |||
| 231 | } | ||
| 232 | |||
| 233 | #read previous searches from file: $ENV{'HOME'}.'.wxPODReader/searches.txt' | ||
| 234 | sub GetSearches{ | ||
| 235 | my ($self,$event)=@_; | ||
| 236 | my @searches=(); | ||
| 237 | my $saveDir=File::Spec->catdir(File::HomeDir->my_home,'.wxPODReader'); | ||
| 238 | my $searchFile=File::Spec->catfile($saveDir,'searches.txt'); | ||
| 239 | mkdir($saveDir,0750) unless (-e $saveDir); | ||
| 240 | if (open(F, $searchFile)){ | ||
| 241 | foreach my $l (<F>){ | ||
| 242 | chomp $l; | ||
| 243 | push (@searches,$l); | ||
| 244 | } | ||
| 245 | close F; | ||
| 246 | } | ||
| 247 | return \@searches; | ||
| 248 | } | ||
| 249 | #save previous searches to file: $ENV{'HOME'}.'.wxPODReader/searches.txt' | ||
| 250 | sub SaveSearches{ | ||
| 251 | my ($self,$event)=@_; | ||
| 252 | my $saveDir=File::Spec->catdir(File::HomeDir->my_home,'.wxPODReader'); | ||
| 253 | my $searchFile=File::Spec->catfile($saveDir,'searches.txt'); | ||
| 254 | mkdir($saveDir,0750) unless (-e $saveDir); | ||
| 255 | |||
| 256 | if (open(F, ">$searchFile")){ | ||
| 257 | foreach (@{$self->{searches}}){ | ||
| 258 | print F "$_\n"; | ||
| 259 | } | ||
| 260 | close F; | ||
| 261 | return 1; | ||
| 262 | } | ||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | |||
| 266 | |||
| 267 | sub OnLinkClicked{ | ||
| 268 | my ($self,$event)=@_; | ||
| 269 | my $ctrl=$event->GetEventObject(); | ||
| 270 | my $link=$event->GetLinkInfo()->GetHref(); | ||
| 271 | my $tmp=(split('/',$link))[-1]; | ||
| 272 | my $newref=uri_unescape($tmp); | ||
| 273 | $newref=~s/.*\?(.*)/$1/; | ||
| 274 | $self->Search($newref); | ||
| 275 | } | ||
| 276 | sub Search { | ||
| 277 | my ($self,$term,$where,$event) = @_; | ||
| 278 | $self->{status_text}->SetLabel("[Searching for $term".(($where)?" in $where]":']')); | ||
| 279 | my $hasFound=0; | ||
| 280 | my $content=''; | ||
| 281 | if (!$where || $where eq 'All' || $where eq 'Builtin Methods'){ | ||
| 282 | $self->{status_text}->SetLabel($self->{status_text}->GetLabel()." [Builtin Methods] "); | ||
| 283 | $content=`perldoc -o html -f $term`; | ||
| 284 | $self->{builtin_text}->SetPage($content); | ||
| 285 | $hasFound=1; | ||
| 286 | } | ||
| 287 | $self->{builtin_tab}->Show(($content?1:0)); | ||
| 288 | $content=''; | ||
| 289 | if (!$where || $where eq 'All' || $where eq 'FAQ'){ | ||
| 290 | $self->{status_text}->SetLabel($self->{status_text}->GetLabel()." [Perl FAQ] "); | ||
| 291 | $content=`perldoc -o html -q $term`; | ||
| 292 | $self->{faq_text}->SetPage($content); | ||
| 293 | $hasFound=1; | ||
| 294 | } | ||
| 295 | $self->{faq_tab}->Show(($content?1:0)); | ||
| 296 | |||
| 297 | $content=''; | ||
| 298 | if (!$where || $where eq 'All' || $where eq 'Modules'){ | ||
| 299 | $self->{status_text}->SetLabel($self->{status_text}->GetLabel()." [Modules] "); | ||
| 300 | $content=`perldoc -o html $term`; | ||
| 301 | $self->{module_text}->SetPage($content); | ||
| 302 | $hasFound=1; | ||
| 303 | } | ||
| 304 | $self->{module_tab}->Show(($content?1:0)); | ||
| 305 | $content=''; | ||
| 306 | if (!$where || $where eq 'All' || $where eq 'Source'){ | ||
| 307 | $self->{status_text}->SetLabel($self->{status_text}->GetLabel()." [Sources] "); | ||
| 308 | $content=`perldoc -o html -m $term`; | ||
| 309 | $self->{source_text}->SetValue($content); | ||
| 310 | $hasFound=1; | ||
| 311 | } | ||
| 312 | $self->{source_tab}->Show(($content?1:0)); | ||
| 313 | unless ($hasFound){ | ||
| 314 | $self->{status_text}->SetLabel("[No Documents found for $term ".(($where)?" in $where]":']')); | ||
| 315 | }else{ | ||
| 316 | $self->{search_text}->SetValue($term); | ||
| 317 | unless (grep($term,@{$self->{searches}})){ | ||
| 318 | $self->{search_text}->Insert(($term),0); | ||
| 319 | while (@{$self->{searches}}>NUM_SEARCHES){ | ||
| 320 | pop @{$self->{searches}}; | ||
| 321 | } | ||
| 322 | push(@{$self->{searches}},$term); | ||
| 323 | } | ||
| 324 | } | ||
| 325 | } | ||
| 326 | |||
| 327 | |||
| 328 | package CPANPLUS::Shell::Wx::PODReader::Frame; | ||
| 329 | |||
| 330 | use Wx qw[:everything]; | ||
| 331 | use base qw(Wx::Frame); | ||
| 332 | use strict; | ||
| 333 | |||
| 334 | sub new { | ||
| 335 | my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_; | ||
| 336 | $parent = undef unless defined $parent; | ||
| 337 | $id = -1 unless defined $id; | ||
| 338 | $title = "" unless defined $title; | ||
| 339 | $pos = wxDefaultPosition unless defined $pos; | ||
| 340 | $size = wxDefaultSize unless defined $size; | ||
| 341 | $name = "" unless defined $name; | ||
| 342 | |||
| 343 | $style = wxDEFAULT_FRAME_STYLE | ||
| 344 | unless defined $style; | ||
| 345 | |||
| 346 | $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name ); | ||
| 347 | $self->{podreader_embed} = CPANPLUS::Shell::Wx::PODReader::Embed->new($self, -1); | ||
| 348 | |||
| 349 | $self->SetTitle("PODReader"); | ||
| 350 | $self->SetSize(Wx::Size->new(520, 518)); | ||
| 351 | |||
| 352 | $self->{sizer_1} = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 353 | $self->{sizer_1}->Add($self->{podreader_embed}, 1, wxEXPAND, 0); | ||
| 354 | $self->SetSizer($self->{sizer_1}); | ||
| 355 | $self->Layout(); | ||
| 356 | |||
| 357 | return $self; | ||
| 358 | |||
| 359 | } | ||
| 360 | sub Search{ | ||
| 361 | my $self = shift; | ||
| 362 | $self->{podreader_embed}->Search(@_); | ||
| 363 | } | ||
| 364 | |||
| 365 | 1; | ||