1 # File: Stem/Event/Tk.pm
3 # This file is part of Stem.
4 # Copyright (C) 1999, 2000, 2001 Stem Systems, Inc.
6 # Stem is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # Stem is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Stem; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # For a license to use the Stem under conditions other than those
21 # described here, to purchase support for this software, or to purchase a
22 # commercial warranty contract, please contact Stem Systems at:
24 # Stem Systems, Inc. 781-643-7504
25 # 79 Everett St. info@stemsystems.com
29 =head1 Stem::Event::Tk
31 This module wraps the CPAN module Event.pm for use by the rest of
32 Stem. It provides the common API for the standard Stem::Event classes:
37 =item Stem::Event::Plain
38 =item Stem::Event::Timer
39 =item Stem::Event::Signal
40 =item Stem::Event::Read
41 =item Stem::Event::Write
47 package Stem::Event::Tk ;
52 use Stem::Event::Signal ;
56 # basic wrappers for top level Tk.pm calls.
60 $tk_main_window ||= MainWindow->new() ;
61 $tk_main_window->withdraw() ;
71 #print "STOP INFO ", $tk_main_window->afterInfo(), "\n" ;
73 $tk_main_window->destroy() ;
74 $tk_main_window = undef ;
77 ############################################################################
79 package Stem::Event::Plain ;
85 # create the plain event watcher
87 $self->{'idle_event'} = Event->idle(
88 'cb' => [ $self, 'idle_triggered' ],
100 my $idle_event = delete $self->{'idle_event'} ;
101 $idle_event->cancel() ;
104 ############################################################################
106 package Stem::Event::Timer ;
112 Stem::Event::Tk::_init_loop() ;
114 # tk times in milliseconds and stem times in floating seconds so
115 # we convert to integer ms.
117 my $delay_ms = int( $self->{'delay'} * 1000 ) ;
119 # $self->{interval_ms} = int( ( $self->{'interval'} || 0 ) * 1000 ) ;
121 my $timer_method = $self->{'interval'} ? 'repeat' : 'after' ;
123 return $tk_main_window->$timer_method(
125 [$self => 'timer_triggered']
131 my( $self, $timer_event, $delay ) = @_ ;
132 my $delay_ms = int( $delay * 1000 ) ;
133 $timer_event->time( $delay_ms ) ;
137 my( $self, $timer_event ) = @_ ;
138 $timer_event->cancel() ;
142 ############################################################################
144 package Stem::Event::Read ;
149 goto &_start if $self->{active} ;
157 return $tk_main_window->fileevent(
164 sub _cancel { goto &_stop }
169 $tk_main_window->fileevent(
176 ############################################################################
178 package Stem::Event::Write ;
182 goto &_start if $self->{active} ;
190 return $tk_main_window->fileevent(
197 sub _cancel { goto &_stop }
203 $tk_main_window->fileevent(