[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: resize bar




On Sun, Apr 12, 2009 at 9:55 PM, Zane C.B. <v velox vvelox net> wrote:
How would one go about implementing one of those widgets that allow
one to resize two different box widgets?
I'm not sure if I understood the question properly. Are you talking about a Gtk2::Paned?

Take a look at this page http://library.gnome.org/devel/gtk/unstable/GtkPaned.html, there's a screenshot that shows the widget. If that's the widget that you want then play with the sample program that's attached to this mail.

--
Emmanuel Rodriguez
#!/usr/bin/perl

use strict;
use warnings;

use Glib qw(TRUE FALSE);
use Gtk2 '-init';


exit main();

sub main {

	my $window = Gtk2::Window->new();
	$window->set_title('Resize');
	$window->set_default_size(640, 480);
	$window->signal_connect(destroy => sub {
		Gtk2->main_quit();
	});

	# A text widget	
	my $textview = Gtk2::TextView->new();
	my $scroll = Gtk2::ScrolledWindow->new();
	$scroll->set_policy('automatic', 'always');
	$scroll->set_shadow_type('out');
	$scroll->add($textview);
	my $buffer = $textview->get_buffer;
	load_text($buffer, $0);


	# Add buttons to one of the panels
	my $clipboard = Gtk2::Clipboard->get(Gtk2::Gdk->SELECTION_CLIPBOARD);
	my $buttons = Gtk2::VBox->new(TRUE);
	add_button($buttons, Clear => sub {
		$buffer->delete($buffer->get_start_iter, $buffer->get_end_iter);
	});
	add_button($buttons, Cut => sub {
		$buffer->cut_clipboard($clipboard, TRUE);
	});
	add_button($buttons, Copy => sub {
		$buffer->copy_clipboard($clipboard);
	});
	add_button($buttons, Paste => sub {
		$buffer->paste_clipboard($clipboard, $buffer->get_end_iter, TRUE);
	});


	# Pack the widgets together in a resizable vertical panel
	my $vpane = Gtk2::HPaned->new();
	$vpane->add1($buttons);
	$vpane->add2($scroll);
	$window->add($vpane);

	$window->show_all();
	
	Gtk2->main();

	return 0;
}


sub add_button {
	my ($parent, $text, $callback) = @_;
	my $button = Gtk2::Button->new($text);
	$button->signal_connect(clicked => $callback) if $callback;
	$parent->add($button);
}


sub load_text {
	my ($buffer, $file) = @_;
	open my $handle, $file or die "Can't read $file because $!";
	local $/ = undef;
	my $text = <$handle>;
	close $handle;
	$buffer->set_text($text);
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]