dotReader

 view release on metacpan or  search on metacpan

client/app.pl  view on Meta::CPAN

#!/usr/bin/perl

package MainApp;

use warnings;
use strict;

use dtRdr::0;
use Time::HiRes ();
########################################################################
# END PRELUDE
########################################################################
my $splash;
use Wx ();
BEGIN {
  # our own little splashfast

  dtRdr->program_dir(__FILE__); # seed for data_dir

  unless($ENV{DOTREADER_NOSPLASH}) {
    Wx::Image::AddHandler(Wx::PNGHandler->new);
    $splash = Wx::SplashScreen->new(
      Wx::Bitmap->new(
        dtRdr->data_dir . 'gui_default/images/splash.png',
        &Wx::wxBITMAP_TYPE_PNG
      ),
      Wx::wxSPLASH_CENTRE_ON_SCREEN(), 0, undef , -1
    );
    #Wx::Yield();
    my $now = Time::HiRes::time();
    #warn "splash is out in ", $now - dtRdr->start_time, " seconds\n";
  }
}

#### PAR_LOADS_DEPS_HERE # don't mess with this, it is a token

use dtRdr;
dtRdr->init_app_dir(__FILE__); # requires us to be next to data/

use base 'dtRdr::GUI::Wx';

use dtRdr::GUI::Wx::Frame;
use Wx ();
use Wx::DND (); # clipboard+drag-n-drop support


# testing accessor:
my $frame_main;
sub _main_frame {$frame_main};

{
  my $on_first_idle;
  sub _on_first_idle {$on_first_idle};
  sub _set_on_first_idle {$on_first_idle = $_[1]};
}
sub OnInit {
  my $self = shift;

  ######################################################################
  dtRdr->init; # ***** MUST CALL ** dtRdr->init ** EARLY *****
  ######################################################################

  Wx::InitAllImageHandlers();
  # XXX wish I could: Wx::Image::RemoveHandler('wxPCXHandler');

  $frame_main = dtRdr::GUI::Wx::Frame->new();
  $splash and $frame_main->set_splash_screen($splash);
  $self->SetTopWindow($frame_main);

  $self->init($frame_main);
  $frame_main->init;

  # setting the the "on-load-done" to happen at idle gets all of the
  # focus and fun to work correctly
  my $did_idle = 0;
  if(my $on_first_idle = $self->_on_first_idle) {
    $self->Connect(-1, -1, &Wx::wxEVT_IDLE, sub {
      #$_[1]->Skip; # makes macs mad?
      (++$did_idle > 1) and return(); # eek
      dtRdr::Logger::RL('#idle')->info("run startup idle");
      $on_first_idle->();
      $self->Disconnect(-1, -1, &Wx::wxEVT_IDLE);
      if($ENV{DOTREADER_TEST}) {
        my $exit = 1;
        eval($ENV{DOTREADER_TEST});
        $@ and die;
        if($exit) {
          $frame_main->Close; $self->ExitMainLoop;
        }
        else {
          warn "skipped exit";
        }
      }
    });
  }

  $frame_main->Show(1);
  return 1;
} # end subroutine OnInit definition
########################################################################


=head2 OnExit



( run in 1.226 second using v1.01-cache-2.11-cpan-84e82930d8c )