Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a sample status menu (appindicator) python 3 script. Via this script you can switch off the screen and open Facebook via google chrome.
#!/usr/bin/env python3
# Copyright 2014 H. Thilina C. Piyasundara
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from gi.repository import AppIndicator3 as appindicator
from gi.repository import Gtk as gtk
import subprocess
import sys
def screen_off(self):
subprocess.call(["gnome-screensaver-command", "-l"])
subprocess.call(["xset", "dpms", "force", "standby"])
def exit_menu(self):
sys.exit(0)
def run_facebook(self):
subprocess.call(["/usr/bin/google-chrome", "http://www.facebook.com/"])
if __name__ == "__main__":
indicator = appindicator.Indicator.new("My Menu", "tray-new-im", appindicator.IndicatorCategory.APPLICATION_STATUS)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
menu = gtk.Menu()
screenoff = gtk.MenuItem("Screenoff")
screenoff.connect("activate",screen_off)
screenoff.show()
menu.append(screenoff)
fb = gtk.MenuItem("Facebook")
fb.connect("activate",run_facebook)
fb.show()
menu.append(fb)
exit = gtk.MenuItem("Exit")
exit.connect("activate",exit_menu)
exit.show()
menu.append(exit)
menu.show()
indicator.set_menu(menu)
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.