Created
September 9, 2017 12:19
-
-
Save infirit/e05131eb5414b036a51acb8e0af47a9c to your computer and use it in GitHub Desktop.
AppIndicator experiment
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
| # This code is an example for a tutorial on Ubuntu Unity/Gnome AppIndicators: | |
| # http://candidtim.github.io/appindicator/2014/09/13/ubuntu-appindicator-step-by-step.html | |
| import os | |
| import signal | |
| import json | |
| import gi | |
| from urllib.request import Request, urlopen | |
| from urllib.error import URLError | |
| gi.require_versions( | |
| {'Gtk': '3.0', | |
| 'Notify': '0.7', | |
| 'AppIndicator3': '0.1'} | |
| ) | |
| from gi.repository import Gtk | |
| from gi.repository import Notify | |
| from gi.repository import AppIndicator3 as AppIndicator | |
| def build_menu(): | |
| menu = Gtk.Menu() | |
| item_joke = Gtk.MenuItem('Joke') | |
| item_joke.connect('activate', joke) | |
| menu.append(item_joke) | |
| item_quit = Gtk.MenuItem('Quit') | |
| item_quit.connect('activate', quit) | |
| menu.append(item_quit) | |
| menu.show_all() | |
| return menu | |
| def fetch_joke(): | |
| request = Request('http://api.icndb.com/jokes/random?limitTo=[nerdy]') | |
| response = urlopen(request) | |
| joke = json.loads(response.read())['value']['joke'] | |
| return "<b>%s</b>" % joke | |
| def joke(_): | |
| Notify.Notification.new("Joke", fetch_joke(), None).show() | |
| def quit(_): | |
| Notify.uninit() | |
| Gtk.main_quit() | |
| def main(): | |
| indicator = AppIndicator.Indicator.new("Testing", 'blueman', AppIndicator.IndicatorCategory.SYSTEM_SERVICES) | |
| indicator.set_status(AppIndicator.IndicatorStatus.ACTIVE) | |
| indicator.set_menu(build_menu()) | |
| indicator.set_title("blueman\n<b>Connections</b>") | |
| indicator.set_icon("firefox") | |
| indicator.set_label("Bluetooth", "Bluetooth") | |
| Notify.init("Testing") | |
| Gtk.main() | |
| if __name__ == "__main__": | |
| signal.signal(signal.SIGINT, signal.SIG_DFL) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment