math-image
view release on metacpan or search on metacpan
devel/lib/App/MathImage/Gtk1/Main.pm view on Meta::CPAN
{
my $menu = Gtk::Menu->new;
{ my $item = Gtk::MenuItem->new_with_label (dgettext('gtk+','Help'));
my $label = $item->child;
my $keyval = 104; # $label->parse_uline ('_Help');
### $keyval
$item->add_accelerator ('activate', $accel_group,
$keyval, 'mod1-mask', 'locked');
$menubar->append ($item);
$item->set_submenu ($menu);
}
{
my $item = Gtk::MenuItem->new_with_label (__('About'));
$item->signal_connect (activate => \&_do_menuitem_about, $ref_weak_self);
$menu->append ($item);
}
if (Module::Util::find_installed('Browser::Open')) {
my $item = $self->{'menuitem_oeis'}
= Gtk::MenuItem->new_with_label (__('OEIS Web Page'));
$item->signal_connect (activate => \&_do_menuitem_oeis, $ref_weak_self);
$menu->append ($item);
$self->{'accel'} = $item->child;
}
}
my $draw = $self->{'draw'} = App::MathImage::Gtk1::Drawing->new;
$draw->add_events ('pointer-motion-mask');
$draw->signal_connect (motion_notify_event => \&_do_motion_notify);
my $toolbar = $self->{'toolbar'} = Gtk::Toolbar->new (0, 0);
$vbox->pack_start ($toolbar, 0,0,0);
my $toolpos = -999;
{
my $hbox = $self->{'scale_hbox'} = Gtk::HBox->new;
$toolbar->append_widget ($hbox, __('How many pixels per square.'), '');
$hbox->pack_start (Gtk::Label->new(__('Scale')), 0,0,0);
my $adj = Gtk::Adjustment->new ($draw->get('scale'), # initial
1, 9999, # min,max
1,10, # step,page increment
0); # page_size
# Glib::Ex::ConnectProperties->new ([$draw,'scale'],
# [$adj,'value']);
### $adj
my $spin = Gtk::SpinButton->new ($adj, 10, 0);
App::MathImage::Gtk1::Ex::SpinButtonBits::mouse_wheel($spin);
# $spin->set_width_chars(3);
$hbox->pack_start ($spin, 0,0,0);
$hbox->show_all;
$spin->signal_connect
(changed => sub {
my ($spin) = @_;
my $self = $spin->get_ancestor(__PACKAGE__) || return;
$self->{'draw'}->set (scale => $spin->get_value_as_int);
});
# # hide for LinesLevel
# Glib::Ex::ConnectProperties->new
# ([$values_combobox,'active-nick'],
# [$toolitem,'visible',
# write_only => 1,
# func_in => sub { $_[0] ne 'LinesLevel' }]);
}
{
my $combo = $self->{'figure_combo'} = Gtk::Combo->new;
App::MathImage::Gtk1::Ex::ComboBits::mouse_wheel($combo);
$combo->set_popdown_strings (App::MathImage::Generator->figure_choices);
$toolbar->append_widget ($combo,
__('The figure to draw at each position.'),
'');
$combo->entry->signal_connect
(changed => sub {
my ($entry) = @_;
### figure combo changed: @_
my $self = $entry->get_ancestor(__PACKAGE__) || return;
$self->{'draw'}->set (figure => $entry->get_text);
});
# Glib::Ex::ConnectProperties->new
# ([$draw,'figure'],
# [$combobox,'active-nick']);
}
$vbox->pack_start ($draw, 1,1,0);
{
my $statusbar = $self->{'statusbar'} = Gtk::Statusbar->new;
$vbox->pack_end ($statusbar, 0,0,0);
}
_update_oeis($self);
$vbox->show_all;
### Main GTK_OBJECT_INIT() done ...
}
sub GTK_CLASS_INIT {
my ($class) = @_;
### Main GTK_CLASS_INIT() ...
$class->add_arg_type ('fullscreen', 'gboolean', 3); #R/W
$class->add_arg_type ('statusbar', 'GtkWidget', 3); #R/W
}
sub GTK_OBJECT_SET_ARG {
my ($self,$arg,$id, $value) = @_;
### Main GTK_OBJECT_SET_ARG(): "$arg to $value"
# $self->{_color} = [split(' ',$value)];
# $self->update_color;
}
sub GTK_OBJECT_GET_ARG {
my ($self,$arg,$id) = @_;
### Main GTK_OBJECT_GET_ARG(): $arg
### is: $self->{$arg}
return $self->{$arg};
}
sub _do_menuitem_quit {
my ($item, $ref_weak_self) = @_;
my $self = $$ref_weak_self || return;
$self->destroy;
}
sub _do_menuitem_about {
my ($item, $ref_weak_self) = @_;
### _do_menuitem_about(): $item
my $self = $$ref_weak_self || return;
$self->popup_about;
}
sub popup_about {
my ($self) = @_;
### popup_about() ...
require App::MathImage::Gtk1::AboutDialog;
App::MathImage::Gtk1::AboutDialog->popup;
}
sub _do_menuitem_oeis {
my ($item, $ref_weak_self) = @_;
### _do_menuitem_oeis(): $item
my $self = $$ref_weak_self || return;
if (my $url = _oeis_url($self)) {
require Browser::Open;
my $cmd = Browser::Open::open_browser_cmd();
### $cmd
devel/lib/App/MathImage/Gtk1/Main.pm view on Meta::CPAN
my $vbox2 = $self->{'vbox2'} = Gtk::VBox->new;
$table->attach ($vbox2, 1,2, 1,2, ['expand','fill'],['expand','fill'],0,0);
$table->attach ($draw, 1,2, 1,2, ['expand','fill'],['expand','fill'],0,0);
{
my $hadj = $draw->get('hadjustment');
my $haxis = Gtk::Ex::NumAxis->new (adjustment => $hadj,
orientation => 'horizontal');
set_property_maybe # tooltip-text new in 2.12
($haxis, tooltip_text => __('Drag with mouse button 1 to scroll.'));
$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 = Gtk::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('Gtk::Ex::QuadButton::Scroll')) {
# quadbutton if available
require Gtk::Ex::QuadButton::Scroll;
$quadbutton = Gtk::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 $action = $actiongroup->get_action ('Toolbar');
Glib::Ex::ConnectProperties->new ([$toolbar,'visible'],
[$action,'active']);
}
my $path_combobox;
{
my $toolitem = Gtk::Ex::ToolItem::ComboEnum->new
(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::Gtk1::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 = Gtk::SeparatorToolItem->new;
$separator->show;
$toolbar->insert ($separator, $toolpos++);
}
my $values_combobox;
{
my $toolitem = $self->{'values_toolitem'}
= Gtk::Ex::ToolItem::ComboEnum->new
(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'));
$values_combobox->signal_connect
('notify::active-nick' => \&_do_values_changed);
Glib::Ex::ConnectProperties->new ([$draw,'values'],
[$values_combobox,'active-nick']);
### values combobox initial: $values_combobox->get('active-nick')
require App::MathImage::Gtk1::Params;
my $values_params = $self->{'values_params'}
= App::MathImage::Gtk1::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 = Gtk::SeparatorToolItem->new;
$separator->show;
$toolbar->insert ($separator, $toolpos++);
}
{
my $toolitem = Gtk::Ex::ToolItem::ComboEnum->new
(enum_type => 'App::MathImage::Gtk::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']);
}
}
# '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 $desc = Glib::Ex::EnumBits::to_description($enum_type, $values)
my $values_seq;
if (($values_seq = $self->{'draw'}->gen_object->values_seq)
&& (my $desc = $values_seq->description)) {
my $name = Glib::Ex::EnumBits::to_display ($enum_type, $values);
$tooltip .= "\n\n"
. __x('Current setting: {name}', name => $name)
. "\n"
. $desc;
}
### values_seq: "$values_seq"
### $tooltip
set_property_maybe ($toolitem, tooltip_text => $tooltip);
}
}
sub _do_values_changed {
my ($widget) = @_;
my $self = $widget->get_ancestor(__PACKAGE__) || return;
_update_values_tooltip($self);
}
sub SET_PROPERTY {
my ($self, $pspec, $newval) = @_;
my $pname = $pspec->get_name;
$self->{$pname} = $newval;
### SET_PROPERTY: $pname, $newval
if ($pname eq 'fullscreen') {
# hide the draw widget until fullscreen change takes effect, so as not
# to do the slow drawing stuff until the new size is set by the window
# manager
if ($self->mapped) {
$self->{'draw'}->hide;
}
if ($newval) {
### fullscreen
$self->fullscreen;
} else {
### unfullscreen
$self->unfullscreen;
}
}
### SET_PROPERTY done...
}
# 'window-state-event' class closure
sub _do_window_state_event {
my ($self, $event) = @_;
### _do_window_state_event: "@{[$event->new_window_state]}"
my $visible = ! ($event->new_window_state & 'fullscreen');
$self->get('toolbar')->set (visible => $visible);
$self->get('statusbar')->set (visible => $visible);
$self->{'draw'}->show;
# reparent the menubar
my $menubar = $self->get('menubar');
my $vbox = ($visible ? $self->{'vbox'} : $self->{'vbox2'});
if ($menubar->parent != $vbox) {
( run in 1.635 second using v1.01-cache-2.11-cpan-59e3e3084b8 )