| 1 | # Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2017 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | package App::Chart::Gtk2::TickerMain; | ||
| 18 | 1 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 0 | ▶ | use Glib; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 22 | use Gtk2; | ||
| 23 | use List::Util qw(min max); | ||
| 24 | use Locale::TextDomain 'App-Chart'; | ||
| 25 | |||
| 26 | use App::Chart::Glib::Ex::MoreUtils; | ||
| 27 | use App::Chart::Gtk2::GUI; | ||
| 28 | use App::Chart::Gtk2::Symlist; | ||
| 29 | use App::Chart::Gtk2::Ticker; | ||
| 30 | |||
| 31 | # uncomment this to run the ### lines | ||
| 32 | #use Devel::Comments; | ||
| 33 | |||
| 34 | |||
| 35 | use Glib::Object::Subclass | ||
| 36 | 'Gtk2::Window', | ||
| 37 | properties => [Glib::ParamSpec->object | ||
| 38 | ('ticker', | ||
| 39 | 'ticker', | ||
| 40 | 'Ticker widget (a App::Chart::Gtk2::Ticker) displayed.', | ||
| 41 | 'App::Chart::Gtk2::Ticker', | ||
| 42 | 'readable') | ||
| 43 | ]; | ||
| 44 | |||
| 45 | sub INIT_INSTANCE { | ||
| 46 | my ($self) = @_; | ||
| 47 | |||
| 48 | $self->set_title (__('Chart: Ticker')); | ||
| 49 | my $screen = $self->get_screen; | ||
| 50 | $self->set_default_size ($screen->get_width * 0.9, -1); | ||
| 51 | |||
| 52 | my $ticker = $self->{'ticker'} = App::Chart::Gtk2::Ticker->new; | ||
| 53 | $ticker->signal_connect (menu_created => \&_do_menu_created); | ||
| 54 | $ticker->show; | ||
| 55 | $self->add ($ticker); | ||
| 56 | } | ||
| 57 | |||
| 58 | # 'menu-created' on ticker widget | ||
| 59 | sub _do_menu_created { | ||
| 60 | my ($ticker, $menu) = @_; | ||
| 61 | my $self = $ticker->get_toplevel; | ||
| 62 | |||
| 63 | # remove the Hide item | ||
| 64 | foreach my $item (grep {$_->get_name eq 'hide'} $menu->get_children) { | ||
| 65 | $item->destroy; | ||
| 66 | } | ||
| 67 | |||
| 68 | # add a quit instead | ||
| 69 | my $item = Gtk2::ImageMenuItem->new_from_stock | ||
| 70 | ('gtk-quit', $menu->get_accel_group); | ||
| 71 | $item->signal_connect (activate => \&_do_quit, | ||
| 72 | App::Chart::Glib::Ex::MoreUtils::ref_weak($self)); | ||
| 73 | $item->show; | ||
| 74 | $menu->append ($item); | ||
| 75 | } | ||
| 76 | |||
| 77 | # 'activate' on quit menu item | ||
| 78 | sub _do_quit { | ||
| 79 | my ($item, $ref_weak_self) = @_; | ||
| 80 | my $self = $$ref_weak_self || return; | ||
| 81 | $self->destroy; | ||
| 82 | } | ||
| 83 | |||
| 84 | sub main { | ||
| 85 | my ($class, $args) = @_; | ||
| 86 | Gtk2->disable_setlocale; # leave LC_NUMERIC alone for version nums | ||
| 87 | Gtk2->init; | ||
| 88 | |||
| 89 | require Gtk2::Ex::ErrorTextDialog::Handler; | ||
| 90 | Glib->install_exception_handler | ||
| 91 | (\&Gtk2::Ex::ErrorTextDialog::Handler::exception_handler); | ||
| 92 | { | ||
| 93 | ## no critic (RequireLocalizedPunctuationVars) | ||
| 94 | $SIG{'__WARN__'} = \&Gtk2::Ex::ErrorTextDialog::Handler::exception_handler; | ||
| 95 | } | ||
| 96 | my $self = $class->new; | ||
| 97 | $self->{'ticker'}->set (symlist => args_to_symlist($args)); | ||
| 98 | $self->signal_connect (destroy => \&_do_destroy_main_quit); | ||
| 99 | $self->show_all; | ||
| 100 | Gtk2->main; | ||
| 101 | } | ||
| 102 | |||
| 103 | # 'destroy' signal handler on self, only for main() | ||
| 104 | sub _do_destroy_main_quit { | ||
| 105 | Gtk2->main_quit; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub args_to_symlist { | ||
| 109 | my ($args) = @_; | ||
| 110 | ### args_to_symlist(): $args | ||
| 111 | |||
| 112 | if (@$args == 0) { | ||
| 113 | # default favourites | ||
| 114 | require App::Chart::Gtk2::Symlist::Favourites; | ||
| 115 | return App::Chart::Gtk2::Symlist::Favourites->instance; | ||
| 116 | } | ||
| 117 | |||
| 118 | if (@$args == 1 && ref($args->[0])) { | ||
| 119 | # single list | ||
| 120 | return $args->[0]; | ||
| 121 | } | ||
| 122 | |||
| 123 | my @symlists; | ||
| 124 | my @consts; | ||
| 125 | my $flush = sub { | ||
| 126 | if (@consts) { | ||
| 127 | ### Constructed: @consts | ||
| 128 | require App::Chart::Gtk2::Symlist::Constructed; | ||
| 129 | push @symlists, App::Chart::Gtk2::Symlist::Constructed->new (@consts); | ||
| 130 | @consts = (); | ||
| 131 | } | ||
| 132 | }; | ||
| 133 | foreach my $arg (@$args) { | ||
| 134 | if (ref $arg) { | ||
| 135 | &$flush(); | ||
| 136 | push @symlists, $arg; | ||
| 137 | |||
| 138 | } elsif ($arg =~ /[[*?]/) { | ||
| 139 | &$flush(); | ||
| 140 | require App::Chart::Gtk2::Symlist::All; | ||
| 141 | my $all = App::Chart::Gtk2::Symlist::All->instance; | ||
| 142 | require App::Chart::Gtk2::Symlist::Glob; | ||
| 143 | push @symlists, App::Chart::Gtk2::Symlist::Glob->new ($all, $arg); | ||
| 144 | } else { | ||
| 145 | push @consts, $arg; | ||
| 146 | } | ||
| 147 | &$flush(); | ||
| 148 | } | ||
| 149 | |||
| 150 | my $symlist; | ||
| 151 | if (@symlists > 1) { | ||
| 152 | require App::Chart::Gtk2::Symlist::Join; | ||
| 153 | $symlist = App::Chart::Gtk2::Symlist::Join->new (@symlists); | ||
| 154 | $symlist->{'name'} = __('Command Line'); | ||
| 155 | $App::Chart::Gtk2::Symlist::instances{$symlist->key} = $symlist; | ||
| 156 | } else { | ||
| 157 | $symlist = $symlists[0]; | ||
| 158 | } | ||
| 159 | ### final: $symlist | ||
| 160 | return $symlist; | ||
| 161 | } | ||
| 162 | |||
| 163 | 1; | ||
| 164 | __END__ | ||