I'm looking to try and develop some simple indicators, for numlock/capslock and brigthness, etc. How would I go about creating indicators in python? Are there any tutorials that walk me through writing my first appindicator (like for apps in quickly)? Any easy solutions for starting like quickly templates?
You can find the page for writing app indicators here:
On that page you'll find links to examples in Python and the API documentation. The ubuntu-application template in Quickly should have examples on using appindicators. Good luck!
I think Writing indicators with Python, GIR and GTK3 ,as mentioned by @fossfreedom, covers how create indicators for Unity. (Read that 1st)
I'm using Ubuntu 14.04, Quickly 12.08.1 . This is demo for a complete working example build from a Quickly template.
OP wants just indicator (not complete GUI app) so let's start with ubuntu-cli Quickly template:
quickly create ubuntu-cli indicator-demo
It may raise an error message for unreleased bug fix (bug#1064110) in this template:
Creating project directory indicator-demo Creating bzr repository and committing Launching your newly created project! Traceback (most recent call last): ... OSError: [Errno 13] Permission denied ERROR: create command failed Aborting
cd indicator-demo/ chmod +x bin/indicator-demo
$ quickly run I'm launched and my args are:
There is a nice PYGI example from Ubuntu Wiki: Application Indicators. It should be easy to integrate it.
Open for edit:
__init__.py, add need modules imports:
from gi.repository import Gtk from gi.repository import AppIndicator3 as appindicator
print _("I'm launched and my args are: %s") % (" ".join(args)) logging.debug(_('end of prog'))
ind = appindicator.Indicator.new_with_path ( _("Indicator demo for Quickly"), "indicator-demo-icon-normal", appindicator.IndicatorCategory.APPLICATION_STATUS, indicator_democonfig.get_data_path()) ind.set_status (appindicator.IndicatorStatus.ACTIVE) ind.set_attention_icon ("indicator-demo-icon-attention") # create a menu menu = Gtk.Menu() # create one item menu_items = Gtk.MenuItem(_("Quit")) menu.append(menu_items) # this is where you would connect your menu item up with a function: menu_items.connect("activate", Gtk.main_quit ) # show the item menu_items.show() ind.set_menu(menu) Gtk.main()
Add icons to a newly created data folder:
I copied some icons from installed packages, just to make the example:
cp /usr/share/icons/ubuntu-mono-dark/status/22/indicator-messages.svg data/indicator-demo-icon-normal.svg cp /usr/share/icons/ubuntu-mono-dark/status/22/indicator-messages-new.svg data/indicator-demo-icon-attention.svg
Create package and publish it:
quickly package quickly share --ppa your-ppa
Well, I didn't update debian package control file, But the dependencies have been auto added to the generated DEB:
Package: indicator-demo Version: 0.1 Architecture: all Maintainer: UNKNOWN <UNKNOWN> Installed-Size: 57 Depends: python (>= 2.7), python (<< 2.8), python:any (>= 2.7.1-0ubuntu2), gir1.2-gtk-3.0, gir1.2-appindicator3-0.1 Section: python Priority: extra Description: UNKNOWN UNKNOWN
Also, the previously added icons in data folder were included in the package.
I faced a similar case before, How to add a keyboard modifier state applet to Unity panel?. The answer contains an example/prototype keyboard indicator using libappindicator (But in the c programming language).
libappindicator lacks an important feature which make easy to ports other desktops indicators. Icon can be loaded only from path. See Bug #812067 API needed: pixbuf icon setting support
The complete API reference for libappindicator is available as HTML in the
libappindicator-docpackage. Look in
Notice that it supports adding label a beside indicator icon.
- Ubuntu Wiki: Application Indicators
- Ubuntu Wiki: Quickly
This link will teach you to create a basic new mail indicator in python+unity, which works with GMail. This will give you a solid grounding in the basic structure of an applet while providing a real-world (albeit simplistic) example that you can easily extend.
It's go through the final script piece by piece.
This is another python program with comments in code, made using