Python/Gtk 启动多个 AppIndicator 实例

Python/Gtk starting multiple AppIndicator instances

免责声明:我是 Python 和 Ubuntu 的新手。完整代码在 https://github.com/bluppfisk/coinprice-indicator/tree/multipletickers

我正在调整一个加密货币价格代码,它使用 libappindicator 显示在 Ubuntu 的任务栏中,以便能够 运行 自身的多个实例。

但是,系统似乎无法区分各种通知项,并试图覆盖它们而不是添加另一个。错误:

libappindicator-WARNING **: Unable to register object on path '/org/ayatana/NotificationItem/Coin_Price_indicator': An object is already exported for the interface org.kde.StatusNotifierItem at /org/ayatana/NotificationItem/Coin_Price_indicator

我认为创建 Indicator class 的新实例(启动 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()

Indicator.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", "8.88")

        self.exchanges = None

问题出在 AppIndicator.Indicator.new()。 运行 多个实例总是会收到相同的名称,因此会占用彼此的 space。为每个实例更改第一个参数 运行 是解决方案。