Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created an indicator that I think should work, but doesn't. I've added the UI interface from a glade file, loaded it and added the menu to appindicator. The following is the entire source code beginning with the XML. Is there any reason why this shouldn't work?

#!/usr/bin/env python
#coding: utf-8

import gtk
import sys
import appindicator

<?xml version="1.0" encoding="UTF-8"?>
  <requires lib="gtk+" version="2.24"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkMenu" id="jes_test_menu">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
      <object class="GtkCheckMenuItem" id="show_dialog">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="use_action_appearance">False</property>
        <property name="label" translatable="yes">Show dialog</property>
        <property name="use_underline">True</property>
        <signal name="toggled" handler="on_show_dialog_toggled" swapped="no"/>
      <object class="GtkMenuItem" id="new_events">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="use_action_appearance">False</property>
        <property name="label" translatable="yes">New events</property>
        <property name="use_underline">True</property>
        <signal name="activate-item" handler="on_new_events_activate_item" swapped="no"/>
        <signal name="activate" handler="on_new_events_activate" swapped="no"/>
      <object class="GtkMenuItem" id="exit_indicator">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="use_action_appearance">False</property>
        <property name="label" translatable="yes">Exit indicator</property>
        <property name="use_underline">True</property>
        <signal name="activate-item" handler="on_exit_indicator_activate_item" swapped="no"/>
        <signal name="activate" handler="on_exit_indicator_activate" swapped="no"/>

class JesTestMenu:
    def __init__(self):

        ui = gtk.Builder()

        menu = ui.get_object("jes_test_menu")

        ind = appindicator.Indicator("jes_test_menu", "indicator-messages", appindicator.CATEGORY_APPLICATION_STATUS)
        print("Indicator should now be visible")

    def on_exit_indicator_activate_item(self, widget, data=None):
        print("Exit activate item")

    def on_exit_indicator_activate(self, widget, data=None):
        print("Exit activate")

    def on_new_events_activate_item(self, widget, data=None):
    def on_new_events_activate(self, widget, data=None):
    def on_show_dialog_toggled(self, widget, data=None):

if __name__ == "__main__":
    menu = JesTestMenu()
share|improve this question
up vote 2 down vote accepted

The problem is that your Indicator object (ind) is not a class variable, it's scope is only in the __init__ function. This means it is being destroyed by Python's garbage collection once your class finishes initation. To fix this, replace ind with self.ind:

self.ind = appindicator.Indicator("jes_test_menu", "indicator-messages", appindicator.CATEGORY_APPLICATION_STATUS)
share|improve this answer
Ah! Thank you. One of those things that become so very obvious once they're explained. – Jo-Erlend Schinstad Jun 18 '11 at 18:07
@jo-erlend If this solves your problem, click the green checkmark so everyone can see that this question is solved. – Alvin Row Jun 18 '11 at 21:25
DoR, thanks. I didn't know about that when I asked. :) – Jo-Erlend Schinstad Aug 19 '11 at 6:18

Your Answer


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.