App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/WatchlistDialog.pm view on Meta::CPAN
}
sub _want_delete_sensitive {
my ($self) = @_;
my $notebook = $self->{'notebook'};
my $pagenum = $notebook->get_current_page;
### $pagenum
if ($pagenum == NOTEBOOK_PAGENUM_SYMLISTS) {
my $key = $self->get_symlists_selected_key;
if (! defined $key) {
### no selected symlist
return 0;
}
my $symlist = App::Chart::Gtk2::Symlist->new_from_key ($key);
if (! $symlist) {
### no such symlist: $key
return 0;
}
### can_delete_symlist() on: $key
return $symlist->can_delete_symlist;
} else {
my $treeview = $self->{'symbols_treeview'};
my $selection = $treeview->get_selection;
my ($model, $iter) = $selection->get_selected;
if (! $iter) {
### no selected symbol
return 0;
}
my $symlist = $model->get_model;
return $symlist->can_edit;
}
}
sub _update_intraday_sensitive {
my ($self) = @_;
### Watchlist _update_intraday_sensitive()
my $symbol = $self->get_selected_symbol;
### $symbol
$self->set_response_sensitive (RESPONSE_INTRADAY,
symbol_intraday_sensitive($symbol));
}
sub symbol_intraday_sensitive {
my ($symbol) = @_;
if (! $symbol) { return 0; }
require App::Chart::IntradayHandler;
return scalar (App::Chart::IntradayHandler->handlers_for_symbol ($symbol));
}
sub _update_edit_sensitive {
my ($self) = @_;
$self->set_response_sensitive (RESPONSE_EDIT_NAME,
defined $self->get_symlists_selected_key);
}
sub _do_symbols_tab_button_press {
my ($symbols_tab_eventbox, $event) = @_;
my $self = $symbols_tab_eventbox->get_toplevel;
if ($event->button == 3) {
require App::Chart::Gtk2::SymlistRadioMenu;
my $symlist_menu = App::Chart::Gtk2::SymlistRadioMenu->new;
### menu destroy connection: $symlist_menu->signal_connect (destroy => sub { print "Watchlist symlist menu destroyed\n" })
Glib::Ex::ConnectProperties->new ([$self, 'symlist'],
[$symlist_menu, 'symlist']);
$symlist_menu->set_screen ($self->get_screen);
$symlist_menu->popup (undef, # parent menushell
undef, # parent menuitem
undef, # position func
undef, # position userdata
$_, # button
$event->time);
return Gtk2::EVENT_PROPAGATE;
}
# GtkNotebook button press handler can cope with an event from a child
# widget
return $self->{'notebook'}->signal_emit ('button_press_event', $event);
}
sub _do_symbol_treeview_activate {
my ($treeview, $path, $column) = @_;
my $self = $treeview->get_toplevel;
my $symlist = $self->{'symlist'};
my $iter = $symlist->get_iter ($path);
my $symbol = $symlist->get_value ($iter, 0);
require App::Chart::Gtk2::Main;
my $main = App::Chart::Gtk2::Main->find_for_dialog ($self);
$main->goto_symbol ($symbol, $symlist);
$main->present;
}
sub _do_symlists_treeview_activate {
my ($treeview, $path, $column) = @_;
my $model = $treeview->get_model;
my $iter = $model->get_iter ($path);
my $key = $model->get_value ($iter, $model->COL_KEY);
my $symlist = App::Chart::Gtk2::Symlist->new_from_key ($key);
my $self = $treeview->get_toplevel;
$self->set_symlist ($symlist);
$self->{'notebook'}->set_current_page (0);
}
sub _do_symbol_selection_changed {
my ($selection) = @_;
my $self = $selection->get_tree_view->get_toplevel;
_update_intraday_sensitive ($self);
_update_delete_sensitive ($self);
}
sub _do_symlist_selection_changed {
my ($selection) = @_;
my $self = $selection->get_tree_view->get_toplevel;
_update_delete_sensitive ($self);
_update_edit_sensitive ($self);
}
# 'response' signal handler
sub _do_response {
my ($self, $response) = @_;
### Watchlist _do_response(): $response
lib/App/Chart/Gtk2/WatchlistDialog.pm view on Meta::CPAN
App::Chart::Gtk2::DeleteSymlistDialog->popup ($symlist, $self);
return;
}
} else {
$treeview = $self->{'symbols_treeview'};
}
require Gtk2::Ex::TreeViewBits;
Gtk2::Ex::TreeViewBits::remove_selected_rows ($treeview);
} elsif ($response eq RESPONSE_INTRADAY) {
# supposed to be insensitive when no selected symbol, but check anyway
my $symbol = $self->get_selected_symbol // return;
App::Chart::Gtk2::Ex::ToplevelBits::popup
('App::Chart::Gtk2::IntradayDialog',
properties => { symbol => $symbol },
screen => $self);
} elsif ($response eq RESPONSE_EDIT_NAME) {
my $notebook = $self->{'notebook'};
my $pagenum = $notebook->get_current_page;
# supposed to be visible only when symlists showing, but check anyway
($pagenum == NOTEBOOK_PAGENUM_SYMLISTS) or return;
my $treeview = $self->{'symlists_treeview'};
my $selection = $treeview->get_selection;
my ($symlists_model, $iter) = $selection->get_selected;
# supposed to be insensitive if no selection, but check anyway
if (! defined $iter) { return; }
my $path = $symlists_model->get_path($iter);
### set_cursor to path: $path->to_string
$treeview->grab_focus;
my $renderer = $self->{'symlists_name_renderer'};
$renderer->set (editable => 1);
$treeview->set_cursor ($path, $self->{'symlists_name_treecolumn'}, 1);
$renderer->set (editable => 0);
} elsif ($response eq 'close') {
# as per a keyboard close, defaults to raising 'delete-event', which in
# turn defaults to a destroy
$self->signal_emit ('close');
} elsif ($response eq 'help') {
require App::Chart::Manual;
App::Chart::Manual->open(__p('manual-node','Watchlist'), $self);
}
}
sub refresh {
my ($self) = @_;
Gtk2::Ex::WidgetCursor->busy;
if (my $symlist = $self->{'symlist'}) {
require App::Chart::Gtk2::Job::Latest;
App::Chart::Gtk2::Job::Latest->start_symlist ($symlist);
}
}
sub _do_symbol_menu_popup {
my ($treeview, $event) = @_;
if ($event->button == 3) {
require App::Chart::Gtk2::WatchlistSymbolMenu;
App::Chart::Gtk2::WatchlistSymbolMenu->popup_from_treeview ($event, $treeview);
}
return Gtk2::EVENT_PROPAGATE;
}
sub _do_symlist_menu_popup {
# nothing yet ...
# my ($treeview, $event) = @_;
# my $self = $treeview->get_toplevel;
return Gtk2::EVENT_PROPAGATE;
}
# 'query-tooltip' signal on symbols_treeview
sub _do_query_tooltip {
my ($treeview, $x, $y, $keyboard_tip, $tooltip) = @_;
# ### Watchlist _do_query_tooltip() "$x,$y"
my ($bin_x, $bin_y, $model, $path, $iter)
= $treeview->get_tooltip_context ($x, $y, $keyboard_tip);
if (! defined $path) { return 0; }
my $symbol = $model->get_value($iter, $model->COL_SYMBOL);
if (! defined $symbol) { return 0; }
require App::Chart::Latest;
my $latest = App::Chart::Latest->get ($symbol);
require App::Chart::Database;
my $tip = $symbol;
if (my $name = ($latest->{'name'}
|| App::Chart::Database->symbol_name ($symbol))) {
$tip .= ' - ' . $name;
}
$tip .= "\n";
if (my $quote_date = $latest->{'quote_date'}) {
my $quote_time = $latest->{'quote_time'} || '';
$tip .= __x("Quote: {quote_date} {quote_time}",
quote_date => $quote_date,
quote_time => $quote_time);
$tip .= "\n";
}
if (my $last_date = $latest->{'last_date'}) {
my $last_time = $latest->{'last_time'} || '';
$tip .= __x("Last: {last_date} {last_time}",
last_date => $last_date,
last_time => $last_time);
$tip .= "\n";
}
$tip .= __x('{location} time; source {source}',
location => App::Chart::TZ->for_symbol($symbol)->name,
source => $latest->{'source'});
### $tip
$tooltip->set_text ($tip);
$treeview->set_tooltip_row ($tooltip, $path);
return 1;
}
sub _do_symlist_entry_activate {
lib/App/Chart/Gtk2/WatchlistDialog.pm view on Meta::CPAN
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;
## use critic
require App::Chart::Gtk2::TickerMain;
my $symlist = App::Chart::Gtk2::TickerMain::args_to_symlist ($args);
my $self = $class->new;
$self->set (symlist => $symlist);
$self->signal_connect (destroy =>
\&App::Chart::Gtk2::TickerMain::_do_destroy_main_quit);
$self->show_all;
Gtk2->main;
}
1;
__END__
=for stopwords watchlist Watchlist Popup
=head1 NAME
App::Chart::Gtk2::WatchlistDialog -- watchlist dialog module
=head1 SYNOPSIS
use App::Chart::Gtk2::WatchlistDialog;
=head1 WIDGET HIERARCHY
C<App::Chart::Gtk2::WatchlistDialog> is a subclass of C<Gtk2::Dialog>.
Gtk2::Widget
Gtk2::Container
Gtk2::Bin
Gtk2::Window
Gtk2::Dialog
App::Chart::Gtk2::WatchlistDialog
=head1 DESCRIPTION
A C<App::Chart::Gtk2::WatchlistDialog> widget is a watchlist display and dialog.
=head1 FUNCTIONS
=over 4
=item C<< App::Chart::Gtk2::WatchlistDialog->new (key=>value,...) >>
Create and return a new Watchlist dialog widget.
=back
=head1 SEE ALSO
L<App::Chart::Gtk2::WatchlistSymbolMenu>
=cut
# App::Chart::Gtk2::WatchlistDialog->popup();
# =item C<< App::Chart::Gtk2::WatchlistDialog->popup () >>
#
# =item C<< App::Chart::Gtk2::WatchlistDialog->popup ($parent) >>
#
# Popup a C<Watchlist> dialog. This function creates a C<Watchlist> widget
# the first time it's called, and then on subsequent calls just presents that
# single dialog.
#
# If C<$parent> is supplied then a Watchlist on that display is sought, and if
# one is created then it's on the same screen as C<$parent>.
( run in 1.253 second using v1.01-cache-2.11-cpan-13bb782fe5a )