22

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?

1
  • Especially appindicators for pyqt5 or pygi and python3 (that will also work outside unity as well).
    – Mateo
    Jun 29, 2014 at 18:08

2 Answers 2

7

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:

3
+100

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

1
  • Note that the first link now points to a non-existent domain (conjurecode.com).
    – andrew.46
    Aug 2, 2022 at 5:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .