1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#
# Tk Import Module
#
# This module functions as a transparent Tk wrapper around Snap, much like
# the GtkImport module. In fact, the code is almost identical.
#
use SnapLib::HandleWrapper;
my $VERSION = "0.01";
BEGIN
{
if (tied %handles)
{
$SUCCESS = 0;
return 1;
}
my $oh = $SIG{__DIE__};
$SIG{__DIE__} = sub { return; };
eval
{
require Tk;
import Tk;
};
$SIG{__DIE__} = $oh;
if ($@)
{
print "Error, unable to load Tk Import module...\n";
$SUCCESS = 0;
return 1;
}
else
{
$SUCCESS = 1;
}
}
return if (! $SUCCESS);
eval {
$MainWin = new MainWindow(-title => 'Snap');
};
if ($@)
{
$TK_ENABLED = 0;
}
else
{
$TK_ENABLED = 1;
}
if ($TK_ENABLED)
{
my %temp = %handles;
tie %handles, 'HandleWrapper', \&add_handle, \&remove_handle;
foreach (keys %temp) { $handles{$_} = $temp{$_}; }
push @extensions, "Tk";
print "Tk Import Module $VERSION Loaded...\n";
*main_loop = *main_tk; # Overwrite the main loop sub.
}
else
{
print "Error initializing Tk...\n";
return;
}
sub main_tk { MainLoop; }
sub add_handle
{
my $data = shift;
Tk::fileevent(undef, $data->{Handle}, 'readable',
sub { $data->{Callback}->($napster_sock,
$data->{Handle})} );
}
sub remove_handle
{
my $data = shift;
Tk::fileevent(undef, $data->{Handle}, 'readable', undef);
}
1;
|