Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Especially appindicators for pyqt5 or pygi and python3 (that will also work outside unity as well). –  Mateo Jun 29 at 18:08

3 Answers 3

up vote 12 down vote accepted

You can find the page for writing app indicators here:

See also:

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!

share|improve this answer
    
Thank you! I was hoping for a more step-by-step tutorial for my first try, but I'll make do with what is. I'll keep the question open for now in case someone knows of some other tutorials. –  DoGoDo Nov 11 '12 at 21:02
    
You'll find a tutorial to get you started on developer.ubuntu.com/get-started - check out the resources section for more content too! developer.ubuntu.com/resources/app-developer-cookbook/unity –  David Planella Nov 11 '12 at 21:50
    
Thanks, @DavidPlanella I watched that tutorial to get started with normal programmes, but it doesn't even mention indicators. Neither does the other link. –  DoGoDo Nov 11 '12 at 21:57
    
What do you not understand about the example here? It is a straightforwarded, simple, working example (taken from link in answer) developer.ubuntu.com/resources/technologies/… –  Timo Nov 11 '12 at 22:43
1  
Similar or the same question here - askubuntu.com/questions/108035/… –  fossfreedom Jun 24 at 18:10

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.

  1. 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
    

    Fix permissions

    cd indicator-demo/
    chmod +x bin/indicator-demo
    

    Test

    $ quickly run
    I'm launched and my args are:
    
  2. There is a nice PYGI example from Ubuntu Wiki: Application Indicators. It should be easy to integrate it.

    Open for edit:

    quickly edit
    
    • Modify __init__.py, add need modules imports:

      from gi.repository import Gtk
      from gi.repository import AppIndicator3 as appindicator
      
    • In the main() function, between:

      print _("I'm launched and my args are: %s") % (" ".join(args))
      logging.debug(_('end of prog'))
      

      add:

      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()
      
  3. Add icons to a newly created data folder:

    mkdir data
    

    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
    
  4. Test it:

    quickly run
    
  5. Create package and publish it:

    quickly package
    quickly share --ppa your-ppa
    

Notes:

  1. 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.

  2. 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

References:

Related Questions:

share|improve this answer

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 Pygtk

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.