[Deskbar] Non-threaded async handler
- From: Mikkel Kamstrup Erlandsen <kamstrup daimi au dk>
- To: deskbar-applet-list gnome org
- Subject: [Deskbar] Non-threaded async handler
- Date: Wed, 12 Oct 2005 22:06:00 +0200
Here's a draft non-threaded async handler. Please think hard about if
there's a better way to handle the FIXME...
Cheers
Mikkel
class SignallingHandler (Handler, gobject.GObject):
"""
An asynchronous handler class without it's own thread.
"""
#
# FIXME: Is there a better way to handle changing queries?
#
QUERY_PRIORITY = gobject.PRIORITY_DEFAULT_IDLE
__gsignals__ = {
"query-ready" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
[gobject.TYPE_PYOBJECT])
}
def __init__ (self, iconfile=None):
Handler.__init__ (self, iconfile)
gobject.GObject.__init__ (self)
self.__last_query = ""
def query_async (self, qstring, max=5):
"""
This method is called by the main loop to start a query for qstring.
This method
in turn calls the query() method of self.
"""
self.__last_query = qstring
self.query (qstring, max)
def emit_query_ready (self, matches, qstring):
"""
Emits a 'query-ready' signal to the main loop if qstring matches the
current
query. This is to make sure we don't send obsolete matches to the
list.
Use this method to return matches to the main loop. matches should be
a list of
Matches objects and qstring should be the string from which the
matches was obtained.
"""
self.__last_query = qstring
if self.__emitted_queries == self.__started_queries:
gobject.idle_add (self.__emit_query_ready, matches,
priority=self.QUERY_PRIORITY)
def __emit_query_ready (self, matches):
"""Idle handler called from the main loop."""
self.emit ("query-ready", matches)
return False
def is_async (self):
return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]