Last active
August 4, 2016 19:43
-
-
Save bellbind/7367659 to your computer and use it in GitHub Desktop.
[python][pygi][ubuntu]Logout indicator for ubuntu Unity
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/python3 | |
# Logout indicator for ubuntu Unity | |
# module of python3-gi (PyGI) | |
from gi.repository import GLib | |
from gi.repository import Gio | |
from gi.repository import Gtk | |
from gi.repository import AppIndicator3 | |
def dbus_logout(w, arg): | |
Gtk.main_quit() | |
#cancel = Gio.Cancellable.new() | |
cancel = None | |
timeout = -1 | |
conn = Gio.bus_get_sync(Gio.BusType.SESSION, cancel) | |
session = Gio.DBusProxy.new_sync( | |
conn, 0, None, | |
"org.gnome.SessionManager", "/org/gnome/SessionManager", | |
"org.gnome.SessionManager", cancel) | |
# see: https://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html | |
args = GLib.Variant("(u)", (1,)) | |
#args = GLib.Variant("(u)", (0,)) | |
session.call_sync("Logout", args, 0, timeout, cancel) | |
pass | |
ind = AppIndicator3.Indicator.new( | |
"logout indicator", | |
"application-exit", # icons at /usr/share/icons/Humanity/*/*/ | |
AppIndicator3.IndicatorCategory.SYSTEM_SERVICES) | |
ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) | |
menu = Gtk.Menu() | |
ind.set_menu(menu) | |
mitem = Gtk.MenuItem("force logout") | |
menu.append(mitem) | |
mitem.show() | |
mitem.connect("activate", dbus_logout, None) | |
mitem = Gtk.SeparatorMenuItem() | |
menu.append(mitem) | |
mitem.show() | |
mitem = Gtk.MenuItem("quit indicator") | |
menu.append(mitem) | |
mitem.show() | |
mitem.connect("activate", lambda w, arg: Gtk.main_quit(), None) | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment