ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-FCP/FCP/Event/Tk.pm
Revision: 1.2
Committed: Thu Dec 1 19:08:36 2005 UTC (20 years, 9 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 package Net::FCP::Event::Tk;
2    
3     use Tk ();
4    
5     my $mw;
6    
7     sub new_from_fh {
8     my ($class, $fh) = @_;
9    
10     bless { fh => $fh }, $class;
11     }
12    
13     sub cb {
14     my ($self, $cb) = @_;
15     $self->{cb} = $cb;
16     $self;
17     }
18    
19     sub poll {
20     my ($self, $r, $w, $e) = @_;
21    
22     # we ignore $e, it's impossible
23    
24     my $cb = \$self->{cb}; # avoid $self-reference
25    
26     Tk::Event::IO::fileevent undef, $self->{fh}, readable => ""; # a mess!
27     Tk::Event::IO::fileevent undef, $self->{fh}, writable => ""; # even more so!
28    
29     Tk::Event::IO::fileevent undef, $self->{fh}, readable => sub { $$cb->() } if $r;
30     Tk::Event::IO::fileevent undef, $self->{fh}, writable => sub { $$cb->() } if $w;
31    
32     $self;
33     }
34    
35     sub DESTROY {
36     my ($self) = @_;
37    
38     if ($self->{fh}) {
39     Tk::Event::IO::fileevent undef, $self->{fh}, readable => "";
40     Tk::Event::IO::fileevent undef, $self->{fh}, writable => "";
41     }
42    
43     undef $mw;
44     }
45    
46     #############
47    
48     sub new_signal {
49     my $class = shift;
50    
51     bless \my $x, $class;
52     }
53    
54     sub send {
55     ${$_[0]}++;
56     }
57    
58     sub wait {
59     unless ($mw) {
60     $mw = new MainWindow;
61     $mw->withdraw;
62     }
63    
64     Tk::DoOneEvent (0) while !${$_[0]};
65     }
66    
67     1;
68