Last active
February 11, 2022 12:34
-
-
Save leiless/51f6b6e5caf967350b8944f0ba403fbf to your computer and use it in GitHub Desktop.
AppIndicator3 python3 example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import gi | |
import os | |
gi.require_version('Gtk', '3.0') | |
def gi_import(name, ver): | |
try: | |
gi.require_version(name, ver) | |
return True, None | |
except Exception as e: | |
return False, e | |
ok, e1 = gi_import('AppIndicator3', '0.1') | |
if not ok: | |
ok, e2 = gi_import('AyatanaAppIndicator3', '0.1') | |
if not ok: | |
raise Exception('cannot import app indicator: %s; %s' % (e1, e2)) | |
else: | |
from gi.repository import AyatanaAppIndicator3 as appindicator | |
else: | |
from gi.repository import AppIndicator3 as appindicator | |
from gi.repository import Gtk | |
def menuitem_response(w, buf): | |
print(buf) | |
if __name__ == "__main__": | |
ind = appindicator.Indicator.new ( | |
"example-simple-client", | |
"%s/logo.png" % os.getcwd(), | |
appindicator.IndicatorCategory.APPLICATION_STATUS) | |
ind.set_status (appindicator.IndicatorStatus.ACTIVE) | |
#ind.set_attention_icon_full ("indicator-messages-new", "Hi") | |
# create a menu | |
menu = Gtk.Menu() | |
# create some | |
for i in range(2): | |
buf = "Test-undermenu - %d" % i | |
menu_items = Gtk.MenuItem(label=buf) | |
menu.append(menu_items) | |
# this is where you would connect your menu item up with a function: | |
menu_items.connect("activate", menuitem_response, buf) | |
# show the items | |
menu_items.show() | |
ind.set_menu(menu) | |
Gtk.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3-gi
, (gir1.2-ayatanaappindicator3-0.1
orgir1.2-appindicator3-0.1
) should be installed