背景:
这不是针对应用程序指示器,而是系统指示器。
图片来源:https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators
目标是在Greeter/Lock/Ubiquity屏幕上显示indicator-sysmonitor。有一个解决方法在:
C原始代码:(正常工作)
我已经在C语言中找到了一个工作的示例,可以参考我的其他问题:How to develop a System Indicator for Unity?">如何为Unity开发系统指示器?。然而,indicator-sysmonitor
已经以Python开发,并且许多其他应用程序指示器也是如此。我不喜欢开发人员被迫将他们的项目转换为C语言,或者编写一个Python-C代理,如果他们想要在登录/锁定/ubiquity屏幕上显示指示器。相反,直接从Python创建indicator-sysmonitor将是最好的解决方案(没有变通方法),并且它将成为当前使用appindicator的所有Python项目的通用解决方案。Python代码:(我尝试将C代码转换为Python的失败尝试)
我正在努力将它移植到Python中。这是我的当前代码,但它不起作用。它确实为菜单和操作创建了DBus对象。它在XFCE指示器插件中列出。但是在面板上没有显示。
/usr/lib/indicator-test/indicator-test-service #!/usr/bin/python2
import os import sys
import gi from gi.repository import Gio, GLib
APPLICATION_ID = 'local.sneetsher.indicator.test' DBUS_MENU_PATH = '/local/sneetsher/indicator/test/desktop' DBUS_ACTION_PATH = '/local/sneetsher/indicator/test'
def callback(): print ok
def quit_callback(notification, loop): global connection global exported_action_group_id global exported_menu_model_id
connection.unexport_action_group (exported_action_group_id) connection.unexport_menu_model (exported_menu_model_id)
loop.quit()
def cancel (notification, action, data): if action == "cancel": print "取消" else: print "不应该发生这种情况(取消)!"
def bus_acquired(bus, name): # 菜单 submenu = Gio.Menu() submenu.append("显示", "show") item = Gio.MenuItem.new(None, "_header") item.set_attribute([("x-canonical-type","s","com.canonical.indicator.root")]) item.set_submenu(submenu) menu = Gio.Menu() menu.append_item (item)
actions = Gio.SimpleActionGroup.new() action1 = Gio.SimpleAction.new("_header", None) actions.insert(action1) action2 = Gio.SimpleAction.new('show', None) actions.insert(action2) action2.connect("activate",callback)
global connection connection = bus
global exported_action_group_id exported_action_group_id = connection.export_action_group(DBUS_ACTION_PATH, actions)
global exported_menu_model_id exported_menu_model_id = connection.export_menu_model(DBUS_MENU_PATH, menu)
def setup (): #总线连接 Gio.bus_own_name(Gio.BusType.SESSION, APPLICATION_ID, 0, bus_acquired, None, None)
if __name__ == '__main__':
connection = None exported_menu_model_id = 0 exported_action_group_id = 0 password = ""
loop = GLib.MainLoop() setup ()
loop.run() local.sneetsher.indicator.test
[Indicator Service] Name=indicator-test ObjectPath=/local/sneetsher/indicator/test
[desktop] ObjectPath=/local/sneetsher/indicator/test/desktop [desktop_greeter] ObjectPath=/local/sneetsher/indicator/test/desktop [desktop_lockscreen] ObjectPath=/local/sneetsher/indicator/test/desktop local.sneetsher.indicator.test.service [D-BUS Service] Name=local.sneetsher.indicator.test Exec=/usr/lib/indicator-test/indicator-test-service 90_unity-greeter.gschema.override [com.canonical.unity-greeter] indicators=['ug-accessibility', 'com.canonical.indicator.keyboard', 'com.canonical.indicator.session', 'com.canonical.indicator.datetime', 'com.canonical.indicator.power', 'com.canonical.indicator.sound', 'local.sneetsher.indicator.test', 'application']
问题:
我预计的原因是,我没有像原始的C代码那样创建菜单结构或其元数据(伪项目,如_header)。
有人能将这个系统指示器代码在C中移植到Python并使其正常工作吗?
tests/indicator-test-service.c
并直接运行它。使用d-feet
检查它的DBus菜单结构。然后编写一个Python代码或修改我的代码来创建相同的DBus菜单结构。如果有任何问题,请随时询问,甚至是按照步骤进行测试。我在寻找GMenu和GSimpleActionGroup的清晰完整的Python文档方面遇到了困难,只有C文档是完整的,Python只是Glib Introspection的绑定。 - user.dzindicator-sysmonitor
已经以Python开发,就像许多其他应用程序指示器一样。我不喜欢开发人员被迫将他们的项目转换为C语言或编写一个Python-C代理,如果他们想在登录/锁定/ubiquity屏幕上显示指示器。相反,直接从Python创建一个系统指示器会是最好的解决方案(没有变通方法,并且适用于当前使用appindicator的所有Python项目)。 - user.dzindicator-multiload
,但我得去看看 indicator-sysmonitor。我可以理解在登录界面、锁屏界面和Ubiquity界面上显示这些信息的价值。非常感兴趣地观察中... :-) - Elder Geekindicator-application
中)。我喜欢挑战,也许有赏金猎人能超越我。 - user.dz