Background:
This is NOT for application-indicators but system-indicators.
Picture from: https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationIndicators
The objective is to show indicator-sysmonitor in Greeter/Lock/Ubiquity screens. There is a work around in:
How to make indicator-sysmonitor as a default indicator on the login screen
C Original Code: (working fine)
I already get one working in C language, see my other question:
How to develop a System Indicator for Unity?
However,
indicator-sysmonitor
is already developed in Python as many other application indicators. I don't like the idea that developers obliged to port their projects to C or write a Python-C proxy if they want to show the indicator in greeter/lock/ubiquity screens. Instead, making indicator-sysmonitor creates a system indicator directly from python would be the best solution (no workarounds, and it will be a generic solution for all python projects that currently using appindicator).
Python Code: (My failed trial to port c code to python)
I'm struggling to port it into Python. Here is my current code which doesn't work. It does create DBus object for both Menu & Actions. It is listed in the XFCE indicators plugin. But not showed on the panel.
/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 "Cancel" else: print "That should not have happened (cancel)!" def bus_acquired(bus, name): # menu submenu = Gio.Menu() submenu.append("Show", "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 (): #bus connection 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']
Question:
I expect the reason why, I didn't create the menu structure or its meta (pseudo items like _header
) as they are in the original C code.
Could anyone make a working port of this system indicator code in C to Python?
I've just uploaded a raw "working" Python example ported from the @user.dz C example. Here's the source code repository:
I will update it as I go along but any contribution is welcome.
Thanks for the useful information!
Ported source code of the main script. Note: It is initial copy as link may broke in future. For complete package and last update, follow the link above.
System Indicator Service
Well, it is really simpler then I expected. There is no specific API for it. Because it is just a GSimpleActionGroup & with corresponding GMenu's exported through DBus then Unity is told about their presence using declaration file with same name put in
/usr/share/unity/indicators/
. No need for any other library.Here a very small C language example:
Get a copy of
tests/indicator-test-service.c
fromlibindicator
source. indicator-test-service.c no changes
com.canonical.indicator.test modified to add lock & greeter mode
com.canonical.indicator.test.service remove .in postfix from filename and change the executable path
Compile it
Manual Installation
Configuration for Greeter, override the default indicators list
90_unity-greeter.gschema.override
Install
Test
Notes DBus service is troublesome, if you want user to be able to close application anytime. It is better to use autostart instead, like default indicators do.
I have uploaded ready files here:
https://github.com/sneetsher/mysystemindicator_minimum
and a modified copy here:
https://github.com/sneetsher/mysystemindicator
Where I have tried different menu for different mode. It could be installed and tested quickly.
This seems too simple and can be easily ported to any other language that have support for GIO Gnome lib (including DBus). As I'm looking for python, I may add it later.
References: libindicator README: The indicator service file format https://bazaar.launchpad.net/~indicator-applet-developers/libindicator/trunk.14.04/view/head:/README