免责声明:我对 Python 和 Ubuntu 还很陌生。完整代码在https://github.com/bluppfisk/coinprice-indicator/tree/multipletickers
我正在调整一个加密货币价格代码,它使用 libappindicator 显示在 Ubuntu 的任务栏中,以便能够运行自身的多个实例。
但是,系统似乎无法区分各种通知项,并试图覆盖它们而不是添加另一个。错误:
libappindicator-WARNING **:无法在路径“/org/ayatana/NotificationItem/Coin_Price_indicator”上注册对象:已在 /org/ayatana/NotificationItem/Coin_Price_indicator 为接口 org.kde.StatusNotifierItem 导出对象
我认为创建指示器类的新实例(启动 NotificationItem)应该自动执行此操作。另外,我对它们进行了多线程处理,并在启动线程后启动了主 Gtk 线程:
for cp_instance in cp_instances:
++counter
settings = cp_instance['exchange'] + ':' + cp_instance['asset_pair'] + ':' + str(cp_instance['refresh'])
indicator = Indicator(config, 'indicator' + str(counter), counter, config, settings)
indicators.append(indicator)
for indicator in indicators:
indicator.start()
indicator.join()
Gtk.main()
指标.py
class Indicator(object):
def __init__(self, config, settings=None):
self.config = config
self.settings = Settings(settings)
self.refresh_frequency = self.settings.refresh()
self.active_exchange = self.settings.exchange()
icon = self.config['project_root'] + '/resources/icon_32px.png'
self.indicator = AppIndicator.Indicator.new(self.config['app']['name'], icon,
AppIndicator.IndicatorCategory.APPLICATION_STATUS)
self.indicator.set_status(AppIndicator.IndicatorStatus.ACTIVE)
self.indicator.set_label("syncing", "$888.88")
self.exchanges = None