App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/Main.pm view on Meta::CPAN
use strict;
use warnings;
use Carp;
use File::Spec;
use List::Util qw(min max);
use POSIX ();
use Locale::TextDomain 1.19 ('App-Chart'); # 1.19 for N__() in scalar context
use Glib 1.220;
use Gtk2 1.220;
use Glib::Ex::ConnectProperties;
use Gtk2::Ex::WidgetCursor;
use Gtk2::Ex::ActionTooltips;
use Gtk2::Ex::History;
use Gtk2::Ex::History::Action;
use App::Chart::Gtk2::Ex::ToplevelBits;
use App::Chart;
use App::Chart::Database;
use App::Chart::Gtk2::GUI;
use App::Chart::Gtk2::Symlist;
use App::Chart::Gtk2::View;
# uncomment this to run the ### lines
#use Smart::Comments;
use base 'App::Chart::Gtk2::Ex::ToplevelSingleton';
use Glib::Object::Subclass
'Gtk2::Window',
signals => { destroy => \&_do_destroy,
symbol_changed => { param_types => ['Glib::String'],
return_type => undef,
class_closure => \&_do_symbol_changed },
},
properties => [ Glib::ParamSpec->object
('statusbar',
'statusbar',
'The Gtk2::Statusbar at the bottom of the window.',
'Gtk2::Statusbar',
['readable']),
];
#------------------------------------------------------------------------------
use constant _ACTION_DATA =>
[ # name, stock id, label, accelerator, tooltip
{ name => 'FileMenu', label => '_File' },
{ name => 'EditMenu', label => '_Edit' },
{ name => 'ViewMenu', label => '_View' },
{ name => 'ToolsMenu', label => '_Tools' },
{ name => 'HelpMenu', label => '_Help' },
{ name => 'Open',
stock_id => 'gtk-open',
accelerator => __p('Main-accelerator-key','O'),
tooltip => __('View chart for a symbol, or add new symbol to the database'),
callback => sub {
my ($action, $self) = @_;
App::Chart::Gtk2::Ex::ToplevelBits::popup
('App::Chart::Gtk2::OpenDialog',
transient_for => $self,
hide_on_delete => 1);
},
},
{ name => 'Delete',
stock_id => 'gtk-delete',
tooltip => __('Delete this symbol from the database.'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Gtk2::DeleteDialog;
App::Chart::Gtk2::DeleteDialog->popup ($self->get_symbol, $self);
},
},
{ name => 'AddFavourite',
label => __('_Add Favourite'),
accelerator => __p('Main-accelerator-key','exclam'),
tooltip => __('Add this symbol to your Favourites list, or elevate in that list.'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Gtk2::Symlist::Favourites;
my $symlist = App::Chart::Gtk2::Symlist::Favourites->instance;
my $symbol = $self->get_symbol;
my $message = (($symlist->append_or_elevate($symbol) eq 'elevated')
? N__('{symbol} raised in {symlist}')
: N__('{symbol} added to {symlist}'));
_message ($self, __x($message,
symbol => $symbol,
symlist => $symlist->name));
},
},
{ name => 'RemoveFavourite',
label => __('_Remove Favourite'),
accelerator => __p('Main-accelerator-key','<Ctrl>exclam'),
tooltip => __('Remove this symbol from your Favourites list.'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Gtk2::Symlist::Favourites;
my $symlist = App::Chart::Gtk2::Symlist::Favourites->instance;
$symlist->delete_symbol ($self->get_symbol);
},
},
{ name => 'Next',
stock_id => 'gtk-media-next',
accelerator => __p('Main-accelerator-key','N'),
tooltip => __('Go to the next symbol (in the current symlist, or the next symlist).'),
callback => sub {
my ($action, $self) = @_;
$self->goto_next;
},
},
{ name => 'Prev',
stock_id => 'gtk-media-previous',
accelerator => __p('Main-accelerator-key','P'),
tooltip => __('Go to the previous symbol (in the current symlist, or the previous symlist).'),
callback => sub {
my ($action, $self) = @_;
$self->go_prev;
},
},
{ name => 'Quit',
stock_id => 'gtk-quit',
# no accelerator -- don't really want the usual Control-Q
callback => sub {
my ($action, $self) = @_;
if (App::Chart::Gtk2::JobQueue->can('instance')) { # if loaded
require App::Chart::Gtk2::JobsRunningDialog;
App::Chart::Gtk2::JobsRunningDialog->query_and_quit ($self);
} else {
$self->destroy;
}
},
},
{ name => 'Preferences',
stock_id => 'gtk-preferences',
callback => sub {
my ($action, $self) = @_;
App::Chart::Gtk2::Ex::ToplevelBits::popup
('App::Chart::Gtk2::PreferencesDialog', screen => $self);
},
},
{ name => 'Centre',
label => __('_Centre'),
accelerator => __p('Main-accelerator-key','<Ctrl>C'),
callback => sub { my ($action, $self) = @_;
$self->{'view'}->centre; }
},
{ name => 'ZoomInX',
label => __('Zoom Wider'),
accelerator => __p('Main-accelerator-key','W'),
callback => sub { my ($action, $self) = @_;
$self->{'view'}->zoom (1.5, 1) }
},
{ name => 'ZoomOutX',
label => __('Zoom Narrower'),
accelerator => __p('Main-accelerator-key','<Shift>W'),
callback => sub { my ($action, $self) = @_;
$self->{'view'}->zoom (0.75, 1) }
},
{ name => 'ZoomInY',
stock_id => 'gtk-zoom-in',
accelerator => __p('Main-accelerator-key','Z'),
callback => sub { my ($action, $self) = @_;
$self->{'view'}->zoom (1, 1.5) }
},
{ name => 'ZoomOutY',
stock_id => 'gtk-zoom-out',
accelerator => __p('Main-accelerator-key','<Shift>Z'),
callback => sub { my ($action, $self) = @_;
$self->{'view'}->zoom (1, 1/1.5) }
},
{ name => 'Redraw',
label => __('_Redraw'),
accelerator => __p('Main-accelerator-key','<Ctrl>L'),
tooltip => __('Force a redraw of the entire Chart display.'),
callback => sub { my ($action, $self) = @_;
$self->queue_draw; }
},
{ name => 'Intraday',
label => __('_Intraday'),
tooltip => __p('Main-accelerator-key','<Ctrl>I'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Gtk2::IntradayDialog;
App::Chart::Gtk2::IntradayDialog->popup ($self->get_symbol, $self);
},
},
{ name => 'Annotations',
label => __('_Annotations'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Gtk2::AnnotationsDialog;
App::Chart::Gtk2::AnnotationsDialog->popup ($self->get_symbol, $self);
},
},
{ name => 'ViewStyle',
label => __('_View Style'),
callback => sub { my ($action, $self) = @_;
Gtk2::Ex::WidgetCursor->busy;
require App::Chart::Gtk2::ViewStyleDialog;
my $vs = App::Chart::Gtk2::ViewStyleDialog->instance_for_screen($self);
$vs->present;
my $view = $self->{'view'};
$vs->set (view => $view,
viewstyle => $view->get('viewstyle'));
}
},
{ name => 'Raw',
label => __('_Raw data'),
callback => sub { my ($action, $self) = @_;
require App::Chart::Gtk2::RawDialog;
App::Chart::Gtk2::RawDialog->popup ($self->get_symbol, $self); }
},
{ name => "WebMenuItem",
label => __('_Web')
},
# Tools menu
{ name => 'Watchlist',
label => __('_Watchlist'),
callback => sub {
my ($action, $self) = @_;
App::Chart::Gtk2::Ex::ToplevelBits::popup
('App::Chart::Gtk2::WatchlistDialog',
screen => $self,
hide_on_delete => 1);
},
},
{ name => 'Download',
label => __('_Download'),
callback => sub { my ($action, $self) = @_;
require App::Chart::Gtk2::DownloadDialog;
App::Chart::Gtk2::DownloadDialog->popup ($self->get_symbol, $self); }
},
{ name => 'DownloadUpdate',
label => __('Download _Update'),
accelerator => __p('Main-accelerator-key','<Ctrl>U'),
callback => sub {
my ($action, $self) = @_;
# meant to be sensitive only with a symbol, but check anyway
my $symbol = $self->get_symbol || return;
require App::Chart::Gtk2::DownloadDialog;
my $dialog = App::Chart::Gtk2::DownloadDialog->instance_for_screen($self);
my $job = $dialog->start ($symbol, undef);
my $jobmsg = ($self->{'jobmsg'} ||= do {
require App::Chart::Gtk2::JobStatusbarMessage;
App::Chart::Gtk2::JobStatusbarMessage->new
(statusbar => $self->{'statusbar'});
});
$jobmsg->add_job ($job);
} },
{ name => 'History',
label => __('_History'),
tooltip => __('Dialog of back/forward symbols.'),
callback => sub {
my ($action, $self) = @_;
App::Chart::Gtk2::Ex::ToplevelBits::popup
('Gtk2::Ex::History::Dialog',
screen => $self,
properties => { history => $self->{'history'} });
},
},
{ name => 'Vacuum',
label => __('_Vacuum'),
tooltip => __('Compact and clean up the database.'),
callback => sub {
my ($action, $self) = @_;
App::Chart::Gtk2::Ex::ToplevelBits::popup ('App::Chart::Gtk2::VacuumDialog',
screen => $self);
},
},
{ name => 'Errors',
label => __('_Errors'),
tooltip => __('Open the errors dialog (it automatically popups up when there\'s an error to see)'),
callback => sub { my ($action, $self) = @_;
require Gtk2::Ex::ErrorTextDialog;
my $dialog = Gtk2::Ex::ErrorTextDialog->instance;
$dialog->set_screen ($self->get_screen);
$dialog->present;
}
},
{ name => 'Diagnostics',
label => __('Dia_gnostics'),
tooltip => __('Some diagnostic information about the program and the databases.'),
callback => sub { my ($action, $self) = @_;
require App::Chart::Gtk2::Diagnostics;
App::Chart::Gtk2::Diagnostics->popup ($self); }
},
{ name => 'About',
stock_id => 'gtk-about',
callback => sub {
my ($action, $self) = @_;
App::Chart::Gtk2::Ex::ToplevelBits::popup
('App::Chart::Gtk2::AboutDialog', screen => $self);
},
},
{ name => 'Manual',
label => __('_Manual'),
accelerator => 'F1',
callback => sub { my ($action, $self) = @_;
require App::Chart::Manual;
App::Chart::Manual->open (undef, $self); },
},
{ name => 'ManualDataSource',
label => __('This _Data Source'),
# tooltip generated dynamically
callback => sub { my ($action, $self) = @_;
require App::Chart::Manual;
App::Chart::Manual->open_for_symbol ($self->get_symbol, $self); }
},
{ name => 'ManualMovingAverage',
label => __('This _Moving Average'),
tooltip => __('Open the manual at the section about the moving average shown in the upper graph'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Manual;
App::Chart::Manual->open(manual_for_graph_n($self,0), $self);
}
},
{ name => 'ManualIndicator',
label => __('This _Indicator'),
tooltip => __('Open the manual at the section about the indicator shown in the lower graph'),
callback => sub {
my ($action, $self) = @_;
require App::Chart::Manual;
App::Chart::Manual->open(manual_for_graph_n($self,1), $self);
}
},
];
sub INIT_INSTANCE {
my ($self) = @_;
$self->set_title (__('Chart'));
App::Chart::chart_dirbroadcast()->connect_for_object
('delete-symbol', \&_do_delete_symbol, $self);
my $actiongroup = $self->{'actiongroup'} = Gtk2::ActionGroup->new ("main");
Gtk2::Ex::ActionTooltips::group_tooltips_to_menuitems ($actiongroup);
$actiongroup->set_translation_domain ('gtk20'); #fallback for _Edit and _Help
$actiongroup->add_actions (_ACTION_DATA, $self);
my $history = $self->{'history'} = Gtk2::Ex::History->new;
$history->signal_connect (place_to_text => \&_history_place_to_text);
$history->signal_connect ('notify::current' => \&_history_notify_current,
$self);
# sub new_in_actiongroup {
# my $class = shift;
# my $actiongroup = shift;
# my $self = $class->new (@_);
( run in 0.988 second using v1.01-cache-2.11-cpan-364913b4093 )