1Glib::MainLoop(3)     User Contributed Perl Documentation    Glib::MainLoop(3)
2
3
4

NAME

6       Glib::MainLoop -  An event source manager
7

DESCRIPTION

9       Event-driven programs need some sort of loop which watches for events
10       and launches the appropriate actions.  Glib::MainLoop provides this
11       functionality.
12
13       Mainloops have context, provided by the MainContext object.  For the
14       most part you can use the default context (see "default"), but if you
15       want to create a subcontext for a nested loop which doesn't have the
16       same event sources, etc, you can.
17
18       Event sources, attached to main contexts, watch for events to happen,
19       and launch appropriate actions.  Glib provides a few ready-made event
20       sources, the Glib::Timeout, Glib::Idle, and io watch
21       ("Glib::IO->add_watch").
22
23       Under the hood, Gtk+ adds event sources for GdkEvents to dispatch
24       events to your widgets.  In fact, Gtk2 provides an abstraction of
25       Glib::MainLoop (See "Gtk2->main" and friends), so you may rarely have
26       cause to use Glib::MainLoop directly.
27
28       Note: As of version 1.080, the Glib module uses a custom event source
29       to ensure that perl's safe signal handling and the glib polling event
30       loop play nicely together.  It is no longer necessary to install a
31       timeout to ensure that async signals get handled in a timely manner.
32

METHODS

34       maincontext thingamabob = Glib::MainContext->new
35
36       mainloop = Glib::MainLoop->new ($context=undef, $is_running=FALSE)
37
38           * $context (Glib::MainContext thingamabob)
39           * $is_running (boolean)
40
41       integer = Glib::Timeout->add ($interval, $callback, $data=undef, $pri‐
42       ority=G_PRIORITY_DEFAULT)
43
44           * $interval (integer) number of milliseconds
45           * $callback (subroutine)
46           * $data (scalar)
47           * $priority (integer)
48
49           Run $callback every $interval milliseconds until $callback returns
50           false.  Returns a source id which may be used with
51           "Glib::Source->remove".  Note that a mainloop must be active for
52           the timeout to execute.
53
54       integer = Glib::Idle->add ($callback, $data=undef, $priority=G_PRIOR‐
55       ITY_DEFAULT_IDLE)
56
57           * $callback (subroutine)
58           * $data (scalar)
59           * $priority (integer)
60
61           Run $callback when the mainloop is idle.  If $callback returns
62           false, it will uninstall itself, otherwise, it will run again at
63           the next idle iteration.  Returns a source id which may be used
64           with "Glib::Source->remove".
65
66       integer = Glib::IO->add_watch ($fd, $condition, $callback, $data=undef,
67       $priority=G_PRIORITY_DEFAULT)
68
69           * $fd (Glib::IO) file number, e.g. fileno($filehandle)
70           * $condition (Glib::IOCondition)
71           * $callback (subroutine)
72           * $data (scalar)
73           * $priority (integer)
74
75           Run $callback when there is an event on $fd that matches $condi‐
76           tion.  The watch uninstalls itself if $callback returns false.
77           Returns a source id that may be used with "Glib::Source->remove".
78
79           Glib's IO channels serve the same basic purpose as Perl's file han‐
80           dles, so for the most part you don't see GIOChannels in Perl.  The
81           IO watch integrates IO operations with the main loop, which Perl
82           file handles don't do.  For various reasons, this function requires
83           raw file descriptors, not full file handles.  See "fileno" in perl‐
84           func.
85
86       maincontext thingamabob = $loop->get_context
87
88       maincontext thingamabob = Glib::MainContext->default
89
90       boolean = $loop->is_running
91
92       boolean = $context->iteration ($may_block)
93
94           * $may_block (boolean)
95
96       integer = Glib::main_depth
97
98           Find the current main loop recursion level.  This is handy in
99           fringe situations, but those are very rare; see the C API reference
100           for a more in-depth discussion.
101
102       boolean = $context->pending
103
104       $loop->quit
105
106       boolean = Glib::Source->remove ($tag)
107
108           * $tag (integer)
109
110           Remove an event source.  $tag is the number returned by things like
111           "Glib::Timeout->add", "Glib::Idle->add", and "Glib::IO->add_watch".
112
113       $loop->run
114

ENUMS AND FLAGS

116       flags Glib::IOCondition
117
118       * 'in' / 'G_IO_IN'
119       * 'out' / 'G_IO_OUT'
120       * 'pri' / 'G_IO_PRI'
121       * 'err' / 'G_IO_ERR'
122       * 'hup' / 'G_IO_HUP'
123       * 'nval' / 'G_IO_NVAL'
124

SEE ALSO

126       Glib
127
129       Copyright (C) 2003-2007 by the gtk2-perl team.
130
131       This software is licensed under the LGPL.  See Glib for a full notice.
132
133
134
135perl v5.8.8                       2007-02-26                 Glib::MainLoop(3)
Impressum