Perl/Tk Bitmap problem (chasing the black cat)

David Billsbrough kc4zvw at taut.oau.org
Sat Jul 1 20:23:07 CDT 2000


Hello PerlMongers,

While try to get this sample directory browser built using a HList
widget, I'm getting this error:

Bad option `./openfolder.xbm' at /usr/lib/perl5/site_perl/5.005/i386-linux/Tk/Image.pm line 21.

Here is the program:

#!/usr/bin/perl -w

use Tk;

require Tk::HList;

$top = MainWindow->new();

$hlist = $top->Scrolled('HList',
	drawbranch => 1,
	indent => 15,
	command => \&show_or_hide_dir);
$hlist->pack(fill => 'both', expand => 'y');

$open_folder_bitmap = $top->Bitmap(file => './openfolder.xbm');
$close_folder_bitmap = $top->Bitmap(file => './folder.xbm');

#

show_or_hide_dir("~");

MainLoop();

#-----------------------------------------------------------

sub show_or_hide_dir
{
	my $path = $_[0];
	return if (! -d $path);

	if ($hlist->info('exists', $path)) {
	#
		$next_entry = $hlist->info('next', $path);

		if (!$next_entry || (index($next_entry, "$path/")) == -1) {
			# Nope. open it
			$hlist->entryconfigure($path, image => $open_folder_bitmap)
			&add_dir_contents($path);
		} else {
			# Yes. Close it by changing the icon and deleting the child.
			$hlist->entryconfigure($path, image => $close_folder_bitmap);
			$hlist->delete('offsprings', $path);
		}
	} else {
		die "'$path' is not a directory\n" if (! -d $path);
		$hlist->add($path, itemtype => 'imagetext',
			image => $icons{"open"}, text => $path);
		&add_dir_contents($path);
	}
}

sub add_dir_contents
{
	my $path = $_[0];
	my $oldcursor = $top->cget('cursor');

	$top->configure(cursor => 'watch');
	$top->update();
	my @files = glob "$path/*";

	foreach $file (@file) {
		$file = s|//|/|g;
		($text = $file) =~ s|^.*||g;
		if (-d $file) {
			$hlist->add($file, itemtype => 'imagetext',
				image => $icons{"closed"}, text => $text);
		} else {
			$hlist->add($file, itemtype => 'text', text => $ text);
		}
	}

	$top->configure(cursor => $oldcursor);
}

# End of script

regards,

// David //
-- 
David Billsbrough (KC4ZVW)
Altamonte Springs, Florida  Grid: EL98hp
AMSAT * ARRL * Linux * OpenBSD * PICmicro * QRP-L * TAPR



More information about the Orlando-pm mailing list