Skip to content

Instantly share code, notes, and snippets.

@afteroot
Created October 3, 2017 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afteroot/e18f2f622b9ab07ac7a88bf3a557f132 to your computer and use it in GitHub Desktop.
Save afteroot/e18f2f622b9ab07ac7a88bf3a557f132 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
#import signal
import json
from urllib2 import Request, urlopen
from gi.repository import GObject as gobject
from gi.repository import Gtk as gtk
from gi.repository import AppIndicator3 as appindicator
from gi.repository import Notify as notify
class IndicatorFly:
def __init__(self):
self.indicator = appindicator.Indicator.new(APPINDICATOR_ID, os.path.abspath('icon.svg'),
appindicator.IndicatorCategory.SYSTEM_SERVICES)
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
notify.init(APPINDICATOR_ID)
#Main Menu
self.main_menu = gtk.Menu()
self.listMenu = gtk.Menu()
# Sub menu
self.listItems = gtk.MenuItem("Configuration")
self.listItems.set_submenu(self.listMenu)
# Joke in sub Menu
self._joke = gtk.MenuItem("Joke")
self.listMenu.append(self._joke)
self._joke.connect('activate', self.joke)
#Config in sub menu
self._config = gtk.MenuItem("Config")
self.listMenu.append(self._config)
#Tool tips
self._config.set_tooltip_text(" Test ")
self._config.connect('activate', self.win)
#Notify in sub menu
self._notify = gtk.CheckMenuItem("Notify")
self._notify.connect('activate', self.status)
#self._notify.set_active(True)
# create exit menu
self._quit = gtk.MenuItem("Quit")
self._quit.connect("activate", self.quit)
self.main_menu.append(self.listItems)
self.main_menu.append(self._notify)
self.main_menu.append(self._quit)
self.main_menu.show_all()
self.indicator.set_menu(self.main_menu)
def onButtonPressed(self, widget):
self.label.set_text("Hello World")
def win(self, widget):
builder = gtk.Builder()
builder.add_from_file("main.glade")
window = builder.get_object("main_window")
label = builder.get_object("label1")
builder.connect_signals(IndicatorFly())
window.show_all()
#gtk.main()
# Procedure for exit
def quit(self, widget):
notify.uninit()
gtk.main_quit()
def fetch_joke(self, widget):
request = Request('http://api.icndb.com/jokes/random?limitTo=[nerdy]')
response = urlopen(request)
joke = json.loads(response.read())['value']['joke']
return joke
def joke(self):
#print "Joke "+str(show_notify)
if show_notify:
notify.Notification.new("<b>Joke</b>", self.fetch_joke(self), None).show()
return True
def status(self,widget):
global show_notify
if widget.get_active():
show_notify = True
else:
show_notify = False
if __name__ == "__main__":
APPINDICATOR_ID = "Myapp"
show_notify= False
#gtk.timeout_add(3000, indicator.joke)
indicator = IndicatorFly()
gobject.timeout_add(3000, indicator.joke)
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment