Tickit-Widget-LogAny

 view release on metacpan or  search on metacpan

lib/Tickit/Widget/LogAny.pm  view on Meta::CPAN

	$holder->add(
		Tickit::Widget::Button->new(
			class => 'stacktrace_ok',
			style => { linetype => 'none' },
			label => 'OK',
			on_click => sub {
				eval {
					$cleanup->();
					1
				} or warn "Failed to do cleanup - $@";

				$win->close;
				$win->tickit->later(sub {
					try {
						dispose $holder;
					} catch {
						warn "Failed to dispose vbox - $@";
					}
				});
			}
		)
	);
	retain $holder;
}

sub stacktrace_holder_widget {
	my ($self, $code) = @_;
	my $container = $self;
	$container = $container->parent while !$container->isa('Tickit::Widget::FloatBox') && !$container->isa('Tickit::Widget::Layout::Desktop') && $container->can('parent') && $container->parent;
	$container = $self unless $container;

	my $cleanup = sub { ... };
	retain(my $vbox = Tickit::Widget::VBox->new(style => { spacing => 1 }));
	my $win = $self->window;
	if($container->isa('Tickit::Widget::FloatBox')) {
		$container->add_float(
			child => $vbox
		)
	} elsif($container->isa('Tickit::Widget::Layout::Desktop')) {
		my $panel = $container->create_panel(
			label => 'Stack trace',
			lines => 20,
			cols  => 60,
			top   => 5,
			left  => 5,
		);
		$panel->add($vbox);
		$cleanup = sub {
			$panel->close;
			$win->tickit->later(sub {
				try {
					dispose $vbox;
					dispose $panel;
				} catch {
					warn "Failed - $@";
				}
			});
			$win->expose;
		};
	} else {
		# We don't have any suitable float holders, so we'll just overlay this
		# using our window as a parent. This next set of measurements assumes we
		# have a bit of space to play with - if we don't, I'm not sure how best
		# to handle this: use the root window instead, or just bail out?
		my $float = $win->make_float(
			2,
			2,
			$win->lines - 4,
			$win->cols - 4
		);
		# Need to hold on to the top widget in the new hierarchy
		retain(my $frame = Tickit::Widget::Frame->new(
			child => $vbox,
			title => 'Stack trace',
			style => { linetype => 'single' }
		));

		$frame->set_window($float);
		$float->show;

		# We're responsible for disposing the $frame object, since we retained
		# it earlier.
		$cleanup = sub {
			$frame->set_window(undef);
			$float->close;
			$win->tickit->later(sub {
				try {
					dispose $frame;
					dispose $vbox;
				} catch {
					warn "Failed to dispose frame - $@";
				}
				$win->expose;
			})
		};
	}
	return $vbox, $cleanup;
}

1;

__END__

=head1 SEE ALSO

=over 4

=item * L<Log::Any>

=item * L<Log::Any::Adapter::Tickit>

=item * L<Tie::Tickit::STDERR>

=back

=head1 AUTHOR

Tom Molesworth <TEAM@cpan.org>

=head1 LICENSE



( run in 0.568 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )