0

I'm working on a simple indicator in Ubuntu with python and I want the menuitem to display the return of a function and refresh every "n" second.

Here is what I have:

def build_menu():
    menu = gtk.Menu()
    item_internetstatus = gtk.MenuItem("Internet : " + internetstatus())
    menu.append(item_internetstatus)

The function is internetstatus() and my objective is to run internetstatus() every n seconds so that the menuitem label is also updated.

Thank you.

1 Answers1

0

In your init (or wherever you initialise stuff) set up a timer:

refreshIntervalInMinutes = 5
GLib.timeout_add_seconds( refreshIntervalInMinutes, build_menu )

Then ensure the last line of build_menu() returns True so the timer is continually called.

Bernmeister
  • 1,231
  • I have since added background script functionality to https://askubuntu.com/a/786708/67335 which would allow you to call your function at a given rate and display the result in the panel which may suit rather than rebuilding the menu each time. – Bernmeister Nov 06 '21 at 01:00