App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/Ticker.pm view on Meta::CPAN
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
package App::Chart::Gtk2::Ticker;
use 5.008;
use strict;
use warnings;
use Carp;
use Gtk2 1.200; # for working TreeModelFilter modify_func
use Gtk2::Ex::TickerView;
use List::Util qw(min max);
use Locale::TextDomain 'App-Chart';
use App::Chart::Glib::Ex::MoreUtils;
use Glib::Ex::SignalIds;
use Gtk2::Ex::Units;
use App::Chart;
use App::Chart::Gtk2::GUI;
use App::Chart::Gtk2::Symlist;
# uncomment this to run the ### lines
#use Smart::Comments;
BEGIN {
Glib::Type->register_enum ('App::Chart::Gtk2::Ticker::menu_position',
'centre' => 0,
'pointer' => 1);
}
use Glib::Object::Subclass
'Gtk2::Ex::TickerView',
signals => { button_press_event => \&_do_button_press_event,
menu_created => { param_types => ['Gtk2::Menu'],
return_type => undef,
},
menu_popup => { param_types => ['Glib::Int',
'App::Chart::Gtk2::Ticker::menu_position'],
return_type => undef,
class_closure => \&_do_menu_popup_action,
flags => [ 'run-last', 'action' ],
},
},
properties => [Glib::ParamSpec->object
('symlist',
'symlist',
'App::Chart::Gtk2::Symlist object for the symbols to display.',
# App::Chart::Gtk2::Symlist::Join is a ListModelConcat not
# a Symlist subclass, allow that by just Glib::Object here
'Glib::Object',
Glib::G_PARAM_READWRITE),
];
App::Chart::Gtk2::GUI::chart_style_class (__PACKAGE__);
# priority level "gtk" treating this as widget level default, for overriding
# by application or user RC
Gtk2::Rc->parse_string (<<'HERE');
binding "App__Chart__Gtk2__Ticker_keys" {
bind "F10" { "menu_popup" (0, centre) }
bind "Pointer_Button3" { "menu_popup" (3, pointer) }
}
class "App__Chart__Gtk2__Ticker" binding:gtk "App__Chart__Gtk2__Ticker_keys"
HERE
sub INIT_INSTANCE {
my ($self) = @_;
$self->add_events (['button-press-mask', 'key-press-mask']);
$self->set (fixed_height_mode => 1);
$self->set_flags ('can-focus');
my $renderer = Gtk2::CellRendererText->new;
$renderer->set (xpad => Gtk2::Ex::Units::em($self));
$self->pack_start ($renderer, 0);
$self->set_attributes ($renderer, markup => 0);
# default Favourites symlist, unless it's empty and All is not in which
# case use All
require App::Chart::Gtk2::Symlist::Favourites;
my $symlist = App::Chart::Gtk2::Symlist::Favourites->instance;
if ($symlist->is_empty) {
require App::Chart::Gtk2::Symlist::All;
my $all = App::Chart::Gtk2::Symlist::All->instance;
if (! $all->is_empty) {
$symlist = $all;
}
}
$self->set (symlist => $symlist);
}
sub FINALIZE_INSTANCE {
my ($self) = @_;
# Gtk2::Menu doesn't go away just by weakening if currently popped-up
# (because it's then a toplevel presumably); doing ->popdown() works, but
# ->destroy() seems the best idea
if (my $menu = $self->{'menu'}) {
$menu->destroy;
}
}
sub SET_PROPERTY {
my ($self, $pspec, $newval) = @_;
my $pname = $pspec->get_name;
my $oldval = $self->{$pname};
if ($pname eq 'symlist' && ($newval||0) != ($oldval||0)) {
### Ticker: "$self changed symlist"
my $symlist = $newval;
if (defined $symlist && ! $symlist->isa('App::Chart::Gtk2::Symlist')) {
croak "App::Chart::Gtk2::Ticker.symlist must be an App::Chart::Gtk2::Symlist";
}
$self->{$pname} = $newval; # per default GET_PROPERTY
require App::Chart::Gtk2::TickerModel;
my $model = $self->{'symlist_model'}
= $symlist && App::Chart::Gtk2::TickerModel->new ($symlist);
my $ref_weak_self = App::Chart::Glib::Ex::MoreUtils::ref_weak ($self);
$self->{'symlist_model_ids'} = $model && do {
Glib::Ex::SignalIds->new
($model,
$model->signal_connect (row_deleted => \&_do_row_deleted,
$ref_weak_self),
( run in 0.529 second using v1.01-cache-2.11-cpan-2398b32b56e )