本文整理匯總了Python中softwarecenter.backend.recagent.RecommenderAgent.is_opted_in方法的典型用法代碼示例。如果您正苦於以下問題:Python RecommenderAgent.is_opted_in方法的具體用法?Python RecommenderAgent.is_opted_in怎麽用?Python RecommenderAgent.is_opted_in使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類softwarecenter.backend.recagent.RecommenderAgent
的用法示例。
在下文中一共展示了RecommenderAgent.is_opted_in方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RecommendationsPanel
# 需要導入模塊: from softwarecenter.backend.recagent import RecommenderAgent [as 別名]
# 或者: from softwarecenter.backend.recagent.RecommenderAgent import is_opted_in [as 別名]
class RecommendationsPanel(FramedHeaderBox):
"""
Base class for widgets that display recommendations
"""
__gsignals__ = {"application-activated": (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT,))}
def __init__(self):
FramedHeaderBox.__init__(self)
self.recommender_agent = RecommenderAgent()
# keep track of applications that have been viewed via a
# recommendation so that we can detect when a recommended app
# has been installed
self.recommended_apps_viewed = set()
self.backend = get_install_backend()
self.backend.connect("transaction-started", self._on_transaction_started)
self.backend.connect("transaction-finished", self._on_transaction_finished)
def _on_application_activated(self, tile, app):
self.emit("application-activated", app)
# we only report on items if the user has opted-in to the
# recommendations service
if self.recommender_agent.is_opted_in():
self.recommended_apps_viewed.add(app.pkgname)
if network_state_is_connected():
# let the recommendations service know that a
# recommended item has been viewed (if it is
# subsequently installed we will send an additional
# signal to indicate that, in on_transaction_finished)
# (there is no need to monitor for an error, etc., for this)
self.recommender_agent.post_implicit_feedback(app.pkgname, RecommenderFeedbackActions.VIEWED)
def _on_transaction_started(self, backend, pkgname, appname, trans_id, trans_type):
if trans_type != TransactionTypes.INSTALL and pkgname in self.recommended_apps_viewed:
# if the transaction is not an installation we don't want to
# track it as a recommended item
self.recommended_apps_viewed.remove(pkgname)
def _on_transaction_finished(self, backend, result):
if result.pkgname in self.recommended_apps_viewed:
self.recommended_apps_viewed.remove(result.pkgname)
if network_state_is_connected():
# let the recommendations service know that a
# recommended item has been successfully installed
# (there is no need to monitor for an error, etc., for this)
self.recommender_agent.post_implicit_feedback(result.pkgname, RecommenderFeedbackActions.INSTALLED)
def _on_recommender_agent_error(self, agent, msg):
LOG.warn("Error while accessing the recommender agent: %s" % msg)
# this can happen if:
# - there is a real error from the agent
# - no cached data is available
# hide the panel on an error
self.hide()