math-image
view release on metacpan or search on metacpan
lib/App/MathImage/Gtk2/Main.pm view on Meta::CPAN
$haxis->add_events (['button-press-mask',
'button-release-mask',
'button-motion-mask',
'scroll-mask']);
$haxis->signal_connect (button_press_event => \&_do_numaxis_button_press);
$table->attach ($haxis, 1,2, 2,3, ['expand','fill'],[],0,0);
my $vadj = $draw->get('vadjustment');
my $vaxis = Gtk2::Ex::NumAxis->new (adjustment => $vadj,
inverted => 1);
set_property_maybe # tooltip-text new in 2.12
($vaxis, tooltip_text => __('Drag with mouse button 1 to scroll.'));
$vaxis->add_events (['button-press-mask',
'button-release-mask',
'button-motion-mask',
'scroll-mask']);
$vaxis->signal_connect (button_press_event => \&_do_numaxis_button_press);
$table->attach ($vaxis, 2,3, 1,2, [],['expand','fill'],0,0);
my $quadbutton;
if (Module::Util::find_installed('Gtk2::Ex::QuadButton::Scroll')) {
# quadbutton if available
require Gtk2::Ex::QuadButton::Scroll;
$quadbutton = Gtk2::Ex::QuadButton::Scroll->new
(hadjustment => $hadj,
vadjustment => $vadj,
vinverted => 1);
set_property_maybe # tooltip-text new in 2.12
($quadbutton, tooltip_text => __('Click to scroll up/down/left/right, hold the control key down to scroll by a page.'));
$table->attach ($quadbutton, 2,3, 2,3,
['fill','shrink'],['fill','shrink'],2,2);
}
my $action = $actiongroup->get_action ('Axes');
Glib::Ex::ConnectProperties->new
([$action,'active'],
[$haxis,'visible'],
[$vaxis,'visible'],
($quadbutton ? [$quadbutton,'visible'] : ()));
}
$table->show_all;
{
my $statusbar = $self->{'statusbar'} = Gtk2::Statusbar->new;
$statusbar->show;
$vbox->pack_start ($statusbar, 0,0,0);
my $pointerposition = $self->{'statusbar_pointerposition'}
= App::MathImage::Gtk2::Ex::Statusbar::PointerPosition->new
(widget => $draw,
statusbar => $statusbar);
$pointerposition->signal_connect
(message_string => \&_statusbar_pointerposition_message);
}
# {
# my $action = $actiongroup->get_action ('Toolbar');
# Glib::Ex::ConnectProperties->new ([$toolbar,'visible'],
# [$action,'active']);
# }
my $toolpos = -999;
my $path_combobox;
{
my $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new
(enum_type => 'App::MathImage::Gtk2::Drawing::Path',
overflow_mnemonic => __('_Path'));
set_property_maybe
($toolitem, # tooltip-text new in 2.12
tooltip_text => __('The path for where to place values in the plane.'));
$toolitem->show;
$toolbar->insert ($toolitem, $toolpos++);
$path_combobox = $self->{'path_combobox'} = $toolitem->get_child;
set_property_maybe ($path_combobox,
# tearoff-title new in 2.10
tearoff_title => __('Math-Image: Path'));
Glib::Ex::ConnectProperties->new ([$draw,'path'],
[$toolitem,'active-nick']);
my $path_params = $self->{'path_params'}
= App::MathImage::Gtk2::Params->new (toolbar => $toolbar,
after_toolitem => $toolitem);
### path_params path to parameter_info_array...
Glib::Ex::ConnectProperties->new
([$draw,'path'],
[$path_params,'parameter-info-array',
write_only => 1,
func_in => sub {
my ($path) = @_;
### Main path parameter info: $path
App::MathImage::Generator->path_class($path)->parameter_info_array;
}]);
### path_params values to draw...
Glib::Ex::ConnectProperties->new ([$path_params,'parameter-values'],
[$draw,'path-parameters']);
}
{
my $separator = Gtk2::SeparatorToolItem->new;
$separator->show;
$toolbar->insert ($separator, $toolpos++);
}
my $values_combobox;
{
my $toolitem = $self->{'values_toolitem'}
= Gtk2::Ex::ToolItem::ComboEnum->new
(enum_type => 'App::MathImage::Gtk2::Drawing::Values',
overflow_mnemonic => __('_Values'));
$toolitem->show;
$toolbar->insert ($toolitem, $toolpos++);
$values_combobox = $self->{'values_combobox'} = $toolitem->get_child;
set_property_maybe ($values_combobox, # tearoff-title new in 2.10
tearoff_title => __('Math-Image: Values'));
Glib::Ex::ConnectProperties->new ([$draw,'values'],
[$values_combobox,'active-nick']);
### values combobox initial: $values_combobox->get('active-nick')
require App::MathImage::Gtk2::Params;
my $values_params = $self->{'values_params'}
= App::MathImage::Gtk2::Params->new (toolbar => $toolbar,
after_toolitem => $toolitem);
### values_params values to parameter_info_array...
Glib::Ex::ConnectProperties->new
([$draw,'values'],
[$values_params,'parameter-info-array',
write_only => 1,
func_in => sub {
my ($values) = @_;
### Main values parameter info for: $values
my $values_class = App::MathImage::Generator->values_class($values);
### arrayref: $values_class->parameter_info_array
return $values_class->parameter_info_array;
}]);
Glib::Ex::ConnectProperties->new ([$draw,'values-parameters'],
[$values_params,'parameter-values']);
}
{
my $separator = Gtk2::SeparatorToolItem->new;
$separator->show;
$toolbar->insert ($separator, $toolpos++);
}
{
my $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new
(enum_type => 'App::MathImage::Gtk2::Drawing::Filters',
overflow_mnemonic => __('Filter'));
set_property_maybe ($toolitem, # tooltip-text new in 2.12
tooltip_text => __('Filter the values to only odd, or even, or primes, etc.'));
$toolitem->show;
$toolbar->insert ($toolitem, $toolpos++);
my $combobox = $toolitem->get_child;
set_property_maybe ($combobox,
tearoff_title => __('Math-Image: Filter'));
Glib::Ex::ConnectProperties->new
([$draw,'filter'],
[$combobox,'active-nick']);
}
{
my $toolitem = Gtk2::Ex::ToolItem::OverflowToDialog->new
(overflow_mnemonic => __('_Scale'));
$toolbar->insert ($toolitem, $toolpos++);
my $hbox = Gtk2::HBox->new;
set_property_maybe ($toolitem,
# tooltip-text new in 2.12
tooltip_text => __('How many pixels per square.'));
$toolitem->add ($hbox);
$hbox->pack_start (Gtk2::Label->new(__('Scale')), 0,0,0);
my $adj = Gtk2::Adjustment->new (1, # initial
1, 9999, # min,max
1,10, # step,page increment
0); # page_size
Glib::Ex::ConnectProperties->new ([$draw,'scale'],
[$adj,'value']);
my $spin = Gtk2::SpinButton->new ($adj, 10, 0);
$spin->set_width_chars(3);
$hbox->pack_start ($spin, 0,0,0);
$toolitem->show_all;
# hide for LinesLevel
Glib::Ex::ConnectProperties->new
([$values_combobox,'active-nick'],
[$toolitem,'visible',
write_only => 1,
func_in => sub { $_[0] ne 'LinesLevel' }]);
}
{
my $toolitem = Gtk2::Ex::ToolItem::ComboEnum->new
(enum_type => 'App::MathImage::Gtk2::Drawing::FigureType',
overflow_mnemonic => __('_Figure'));
set_property_maybe ($toolitem,
tooltip_text => __('The figure to draw at each position.'));
$toolitem->show;
$toolbar->insert ($toolitem, $toolpos++);
my $combobox = $toolitem->get_child;
set_property_maybe ($combobox, # tearoff-title new in 2.10
tearoff_title => __('Math-Image: Figure'));
Glib::Ex::ConnectProperties->new
([$draw,'figure'],
[$combobox,'active-nick']);
}
Gtk2::Ex::ActionTooltips::group_tooltips_to_menuitems ($actiongroup);
if (my $action = $actiongroup->get_action ('OeisBrowse')) {
Gtk2::Ex::ActionTooltips::action_tooltips_to_menuitems_dynamic ($action);
}
}
# 'destroy' class closure
sub _do_destroy {
my ($self) = @_;
### Main FINALIZE_INSTANCE(), break circular refs...
delete $self->{'actiongroup'};
delete $self->{'ui'};
return shift->signal_chain_from_overridden(@_);
}
sub _update_values_tooltip {
my ($self) = @_;
### _update_values_tooltip() ...
{
my $tooltip = __('The values to display.');
my $toolitem = $self->{'values_toolitem'};
my $values_combobox = $self->{'values_combobox'} || return;
my $enum_type = $values_combobox->get('enum_type');
my $values = $values_combobox->get('active-nick');
my $gen_object = $self->{'draw'}->gen_object;
if (my $values_seq = $gen_object->values_seq_maybe) {
{
my $name = Glib::Ex::EnumBits::to_display ($enum_type, $values);
$tooltip .= "\n\n" . __x('Current setting: {name}', name => $name);
}
if (my $desc = $values_seq->description) {
$tooltip .= "\n" . $desc;
}
if (my $anum = $values_seq->oeis_anum) {
$tooltip .= "\n" . __x('OEIS {anum}', anum => $anum);
}
}
### $tooltip
set_property_maybe ($toolitem, tooltip_text => $tooltip);
}
if (my $action = $self->{'actiongroup'}->get_action('OeisBrowse')) {
my $url = _oeis_url($self);
$action->set (tooltip => __x("Open browser at Online Encyclopedia of Integer Sequences (OEIS) web page for the current values\n{url}",
url => ($url||'')),
sensitive => defined($url));
}
}
sub _do_values_changed {
my ($widget) = @_;
### _do_values_changed(): "$widget"
my $self = $widget->get_ancestor(__PACKAGE__) || return;
_update_values_tooltip($self);
}
sub _oeis_url {
my ($self) = @_;
my ($values_seq, $anum);
return (($values_seq = $self->{'draw'}->gen_object->values_seq)
&& ($anum = $values_seq->oeis_anum)
&& "http://oeis.org/$anum");
}
sub _statusbar_pointerposition_message {
my ($pointerposition, $draw, $x, $y) = @_;
if (my $self = $draw->get_ancestor (__PACKAGE__)) {
return $draw->gen_object->xy_message ($x, $y);
}
return undef;
}
sub _do_motion_notify {
my ($draw, $event) = @_;
### Main _do_motion_notify()...
my $self;
if (($self = $draw->get_ancestor (__PACKAGE__))
&& (my $statusbar = $self->get('statusbar'))) {
my $id = $statusbar->get_context_id (__PACKAGE__);
$statusbar->pop ($id);
my $message = $draw->gen_object->xy_message ($event->x, $event->y);
### $message
( run in 0.968 second using v1.01-cache-2.11-cpan-59e3e3084b8 )