| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 1 |  | 455 | use 5.008; | 
|  | 1 |  |  |  |  | 3 |  | 
| 19 | 1 |  |  | 1 |  | 4 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 17 |  | 
| 20 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 21 | 1 |  |  | 1 |  | 137 | use Glib; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 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__ | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =for stopwords toplevel Eg | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | =head1 NAME | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | App::Chart::Gtk2::TickerMain -- stock ticker as toplevel window | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =for test_synopsis my ($symlist) | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | use App::Chart::Gtk2::TickerMain; | 
| 177 |  |  |  |  |  |  | App::Chart::Gtk2::TickerMain->main ($symlist) | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =head1 WIDGET HIERARCHY | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | C<App::Chart::Gtk2::TickerMain> is a subclass of C<Gtk2::Window>. | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | Gtk2::Widget | 
| 184 |  |  |  |  |  |  | Gtk2::Container | 
| 185 |  |  |  |  |  |  | Gtk2::Bin | 
| 186 |  |  |  |  |  |  | Gtk2::Window | 
| 187 |  |  |  |  |  |  | App::Chart::Gtk2::TickerMain | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | A C<App::Chart::Gtk2::TickerMain> widget is a toplevel window with a | 
| 192 |  |  |  |  |  |  | C<App::Chart::Gtk2::Ticker> widget to show scrolling stock quotes. | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | =over 4 | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | =item C<< App::Chart::Gtk2::TickerMain->main ($symbol_or_symlist,...) >> | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | ... | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | =item C<< App::Chart::Gtk2::TickerMain->new (key=>value,...) >> | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | Create and return a C<App::Chart::Gtk2::TickerMain> widget.  Optional key/value | 
| 205 |  |  |  |  |  |  | pairs set initial properties as per C<< Glib::Object->new >>. | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | The widget is not displayed, but can be using C<show> in the usual way.  Eg. | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | my $toplevel = App::Chart::Gtk2::TickerMain->new (symlist => $symlist); | 
| 210 |  |  |  |  |  |  | $toplevel->show; | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | =back | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | =head1 PROPERTIES | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | =over 4 | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | =item C<ticker> (read-only) | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | The child ticker widget displayed. | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | =back | 
| 223 |  |  |  |  |  |  |  | 
| 224 |  |  |  |  |  |  | =head1 HOME PAGE | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | L<http://user42.tuxfamily.org/chart/index.html> | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | =head1 LICENCE | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2017 Kevin Ryde | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | Chart is free software; you can redistribute it and/or modify it under the | 
| 233 |  |  |  |  |  |  | terms of the GNU General Public License as published by the Free Software | 
| 234 |  |  |  |  |  |  | Foundation; either version 3, or (at your option) any later version. | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | Chart is distributed in the hope that it will be useful, but WITHOUT ANY | 
| 237 |  |  |  |  |  |  | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
| 238 |  |  |  |  |  |  | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more | 
| 239 |  |  |  |  |  |  | details. | 
| 240 |  |  |  |  |  |  |  | 
| 241 |  |  |  |  |  |  | You should have received a copy of the GNU General Public License along with | 
| 242 |  |  |  |  |  |  | Chart; see the file F<COPYING>.  Failing that, see | 
| 243 |  |  |  |  |  |  | L<http://www.gnu.org/licenses/>. | 
| 244 |  |  |  |  |  |  |  | 
| 245 |  |  |  |  |  |  | =cut |