App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Gtk2/TickerMain.pm  view on Meta::CPAN

use App::Chart::Glib::Ex::MoreUtils;
use App::Chart::Gtk2::GUI;
use App::Chart::Gtk2::Symlist;
use App::Chart::Gtk2::Ticker;

# uncomment this to run the ### lines
#use Devel::Comments;


use Glib::Object::Subclass
  'Gtk2::Window',
  properties => [Glib::ParamSpec->object
                 ('ticker',
                  'ticker',
                  'Ticker widget (a App::Chart::Gtk2::Ticker) displayed.',
                  'App::Chart::Gtk2::Ticker',
                  'readable')
                ];

sub INIT_INSTANCE {
  my ($self) = @_;

  $self->set_title (__('Chart: Ticker'));
  my $screen = $self->get_screen;
  $self->set_default_size ($screen->get_width * 0.9, -1);

  my $ticker = $self->{'ticker'} = App::Chart::Gtk2::Ticker->new;
  $ticker->signal_connect (menu_created => \&_do_menu_created);
  $ticker->show;
  $self->add ($ticker);
}

# 'menu-created' on ticker widget
sub _do_menu_created {
  my ($ticker, $menu) = @_;
  my $self = $ticker->get_toplevel;

  # remove the Hide item
  foreach my $item (grep {$_->get_name eq 'hide'} $menu->get_children) {
    $item->destroy;
  }

  # add a quit instead
  my $item = Gtk2::ImageMenuItem->new_from_stock
    ('gtk-quit', $menu->get_accel_group);
  $item->signal_connect (activate => \&_do_quit,
                         App::Chart::Glib::Ex::MoreUtils::ref_weak($self));
  $item->show;
  $menu->append ($item);
}

# 'activate' on quit menu item
sub _do_quit {
  my ($item, $ref_weak_self) = @_;
  my $self = $$ref_weak_self || return;
  $self->destroy;
}

sub main {
  my ($class, $args) = @_;
  Gtk2->disable_setlocale;  # leave LC_NUMERIC alone for version nums
  Gtk2->init;

  require Gtk2::Ex::ErrorTextDialog::Handler;
  Glib->install_exception_handler
    (\&Gtk2::Ex::ErrorTextDialog::Handler::exception_handler);
  {
    ## no critic (RequireLocalizedPunctuationVars)
    $SIG{'__WARN__'} = \&Gtk2::Ex::ErrorTextDialog::Handler::exception_handler;
  }
  my $self = $class->new;
  $self->{'ticker'}->set (symlist => args_to_symlist($args));
  $self->signal_connect (destroy => \&_do_destroy_main_quit);
  $self->show_all;
  Gtk2->main;
}

# 'destroy' signal handler on self, only for main()
sub _do_destroy_main_quit {
  Gtk2->main_quit;
}

sub args_to_symlist {
  my ($args) = @_;
  ### args_to_symlist(): $args

  if (@$args == 0) {
    # default favourites
    require App::Chart::Gtk2::Symlist::Favourites;
    return App::Chart::Gtk2::Symlist::Favourites->instance;
  }

  if (@$args == 1 && ref($args->[0])) {
    # single list
    return $args->[0];
  }

  my @symlists;
  my @consts;
  my $flush = sub {
    if (@consts) {
      ### Constructed: @consts
      require App::Chart::Gtk2::Symlist::Constructed;
      push @symlists, App::Chart::Gtk2::Symlist::Constructed->new (@consts);
      @consts = ();
    }
  };
  foreach my $arg (@$args) {
    if (ref $arg) {
      &$flush();
      push @symlists, $arg;

    } elsif ($arg =~ /[[*?]/) {
      &$flush();
      require App::Chart::Gtk2::Symlist::All;
      my $all = App::Chart::Gtk2::Symlist::All->instance;
      require App::Chart::Gtk2::Symlist::Glob;
      push @symlists, App::Chart::Gtk2::Symlist::Glob->new ($all, $arg);
    } else {
      push @consts, $arg;
    }



( run in 0.679 second using v1.01-cache-2.11-cpan-ceb78f64989 )