r6854 - in bigboard/trunk: . bigboard bigboard/libbig bigboard/stocks/files bigboard/stocks/google_calendar
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r6854 - in bigboard/trunk: . bigboard bigboard/libbig bigboard/stocks/files bigboard/stocks/google_calendar
- Date: Wed, 31 Oct 2007 16:35:40 -0500 (CDT)
Author: hp
Date: 2007-10-31 16:35:40 -0500 (Wed, 31 Oct 2007)
New Revision: 6854
Modified:
bigboard/trunk/bigboard/google_stock.py
bigboard/trunk/bigboard/libbig/gutil.py
bigboard/trunk/bigboard/stock.py
bigboard/trunk/bigboard/stocks/files/FilesStock.py
bigboard/trunk/bigboard/stocks/google_calendar/CalendarStock.py
bigboard/trunk/main.py
Log:
add and invoke a hook when a stock is delisted, and add usage of it to disconnect a few signals in a couple stocks, more usage is needed
Modified: bigboard/trunk/bigboard/google_stock.py
===================================================================
--- bigboard/trunk/bigboard/google_stock.py 2007-10-31 16:42:22 UTC (rev 6853)
+++ bigboard/trunk/bigboard/google_stock.py 2007-10-31 21:35:40 UTC (rev 6854)
@@ -3,6 +3,7 @@
import bigboard.google as google
import bigboard.accounts as accounts
import accounts_dialog
+import bigboard.libbig.gutil as gutil
_logger = logging.getLogger("bigboard.Google")
@@ -22,14 +23,23 @@
self.__action_id = action_id
+ self.__connections = gutil.DisconnectSet()
+
accts = accounts.get_accounts()
for a in accts.get_accounts_with_kind(accounts.KIND_GOOGLE):
self.__on_account_added(a)
- accts.connect('account-added', self.__on_account_added)
- accts.connect('account-removed', self.__on_account_removed)
+ id = accts.connect('account-added', self.__on_account_added)
+ self.__connections.add(accts, id)
+ id = accts.connect('account-removed', self.__on_account_removed)
+ self.__connections.add(accts, id)
- ## FIXME need to unhook everything when stock is removed
+
+ ## we can't just override _on_delisted() because of multiple inheritance,
+ ## so our subclasses have to override it then call this
+ def _delist_google(self):
+ self.__connections.disconnect_all()
+
def __on_account_added(self, acct):
gobj = google.get_google_for_account(acct)
gobj.add_poll_action_func(self.__action_id, lambda gobj: self.update_google_data(gobj))
Modified: bigboard/trunk/bigboard/libbig/gutil.py
===================================================================
--- bigboard/trunk/bigboard/libbig/gutil.py 2007-10-31 16:42:22 UTC (rev 6853)
+++ bigboard/trunk/bigboard/libbig/gutil.py 2007-10-31 21:35:40 UTC (rev 6854)
@@ -10,6 +10,18 @@
logger.exception('Exception in idle')
return False
+class DisconnectSet(object):
+ def __init__(self):
+ super(DisconnectSet, self).__init__()
+ self.__connections = set()
+
+ def add(self, object, id):
+ self.__connections.add((object, id))
+
+ def disconnect_all(self):
+ for (object, id) in self.__connections:
+ object.disconnect(id)
+
def call_timeout(timeout, func, *args, **kwargs):
if 'logger' in kwargs:
logger = kwargs['logger']
@@ -64,4 +76,4 @@
watchid = gobject.io_add_watch(subp.stdout.fileno(), gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP, handle_data_avail)
return watchid
-__all__ = ['call_timeout', 'call_idle', 'call_timeout_once', 'call_idle_once', 'defer_idle_func', 'read_subprocess_idle']
+__all__ = ['call_timeout', 'call_idle', 'call_timeout_once', 'call_idle_once', 'defer_idle_func', 'read_subprocess_idle', 'DisconnectSet']
Modified: bigboard/trunk/bigboard/stock.py
===================================================================
--- bigboard/trunk/bigboard/stock.py 2007-10-31 16:42:22 UTC (rev 6853)
+++ bigboard/trunk/bigboard/stock.py 2007-10-31 21:35:40 UTC (rev 6854)
@@ -58,6 +58,15 @@
# For use in subclasses as well
self._logger = logging.getLogger('bigboard.stocks.' + self._id)
_logger.debug("initializing")
+
+ def on_delisted(self):
+ """Called when stock is shut down (removed)"""
+ _logger.debug("on_delisted stock %s" % (self._id))
+ self._on_delisted() ## saves derived classes the need to chain up
+
+ def _on_delisted(self):
+ """The most-derived concrete stock object can override this instead of on_delisted, then not chain up"""
+ pass
def get_id(self):
return self._id
@@ -114,15 +123,26 @@
self._dependent_handlers = []
self._mugshot = global_mugshot.get_mugshot()
- self._mugshot.connect("initialized", lambda mugshot: self._on_mugshot_initialized())
+ self.__connections = DisconnectSet()
+
+ id = self._mugshot.connect("initialized", lambda mugshot: self._on_mugshot_initialized())
+ self.__connections.add(self._mugshot, id)
if self._mugshot.get_initialized():
call_idle(self.__invoke_mugshot_initialized)
- self._mugshot.connect("connection-status", lambda mugshot, auth, xmpp, contacts: self.__handle_mugshot_connection_status(auth, xmpp, contacts))
+
+ id = self._mugshot.connect("connection-status", lambda mugshot, auth, xmpp, contacts: self.__handle_mugshot_connection_status(auth, xmpp, contacts))
+ self.__connections.add(self._mugshot, id)
+
call_idle(self.__handle_mugshot_connection_status, *self._mugshot.current_connection_status())
self.__cursize = None
self.__box = hippo.CanvasBox()
+ def on_delisted(self):
+ self.__connections.disconnect_all()
+
+ super(AbstractMugshotStock, self).on_delisted()
+
def __sync_content(self):
self.__box.remove_all()
if self._auth:
Modified: bigboard/trunk/bigboard/stocks/files/FilesStock.py
===================================================================
--- bigboard/trunk/bigboard/stocks/files/FilesStock.py 2007-10-31 16:42:22 UTC (rev 6853)
+++ bigboard/trunk/bigboard/stocks/files/FilesStock.py 2007-10-31 21:35:40 UTC (rev 6854)
@@ -230,6 +230,9 @@
search.enable_search_provider('files', constructor=self.__construct_search_provider)
#### FIXME need to figure out when to call search.disable_search_provider
+ def _on_delisted(self):
+ self._delist_google()
+
def __construct_search_provider(self):
return FileSearchProvider(stock=self)
Modified: bigboard/trunk/bigboard/stocks/google_calendar/CalendarStock.py
===================================================================
--- bigboard/trunk/bigboard/stocks/google_calendar/CalendarStock.py 2007-10-31 16:42:22 UTC (rev 6853)
+++ bigboard/trunk/bigboard/stocks/google_calendar/CalendarStock.py 2007-10-31 21:35:40 UTC (rev 6854)
@@ -447,6 +447,9 @@
self._add_more_button(self.__on_more_button)
+ def _on_delisted(self):
+ self._delist_google()
+
def __change_day(self):
self.__close_slideout()
self.__events_for_day_displayed = None
Modified: bigboard/trunk/main.py
===================================================================
--- bigboard/trunk/main.py 2007-10-31 16:42:22 UTC (rev 6853)
+++ bigboard/trunk/main.py 2007-10-31 21:35:40 UTC (rev 6854)
@@ -324,6 +324,10 @@
self.__render_pymodule()
else:
self.__render_google_gadget()
+
+ def on_delisted(self):
+ _logger.debug("on_delisted exchange %s" % (str(self)))
+ self.__unrender_pymodule()
def __toggle_expanded(self):
self.__expanded = not self.__expanded
@@ -364,6 +368,15 @@
if self.__ticker_text:
self.set_child_visible(self.__ticker_container, size == Stock.SIZE_BULL)
+ def __unrender_pymodule(self):
+ if not self.__pymodule:
+ _logger.debug("Not a pymodule exchange")
+ return
+
+ _logger.debug("delisting pymodule %s" % (str(self.__pymodule)))
+ self.__pymodule.on_delisted()
+ self.__pymodule = None
+
class BigBoardPanel(dbus.service.Object):
def __init__(self, bus_name):
dbus.service.Object.__init__(self, bus_name, '/bigboard/panel')
@@ -382,7 +395,7 @@
self.__autohide_id = 0
- self._exchanges = {}
+ self._exchanges = {} ## metainfo.srcurl to Exchange
self._canvas = hippo.Canvas()
self._dw.get_content().add(self._canvas)
@@ -482,12 +495,21 @@
@log_except(_logger)
def __sync_listing(self):
_logger.debug("doing stock listing sync")
- new_listed = list(self.__stock_manager.get_listed())
+ new_listed = list(self.__stock_manager.get_listed())
+ new_listed_srcurls = map(lambda mi: mi.srcurl, new_listed)
for exchange in list(self._stocks_box.get_children()):
if exchange.get_metainfo().srcurl in self.__hardcoded_stocks:
continue
- _logger.debug("removing %s", exchange)
+
+ _logger.debug("unrendering %s", exchange)
+
self._stocks_box.remove(exchange)
+
+ if exchange.get_metainfo().srcurl not in new_listed_srcurls:
+ _logger.debug("removing %s", exchange)
+ del self._exchanges[exchange.get_metainfo().srcurl]
+ exchange.on_delisted()
+
for metainfo in new_listed:
self.__append_metainfo(metainfo)
_logger.debug("done with stock load")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]