Merge remote-tracking branch 'flapflap/de-network_configuration'
[tails-test.git] / config / chroot_local-includes / usr / local / lib / shutdown-helper-applet
blob39fe58e2b08bdaa9848ca968c1b5ab29ec8b4f18
1 #!/usr/bin/env python
3 import locale
4 import os
5 import subprocess
6 import sys
8 from gettext import gettext as _
9 from gettext import bindtextdomain, textdomain
11 from gi.repository import Gdk
12 from gi.repository import Gtk
13 from gi.repository import PanelApplet
15 LOCALE_PREFIX = "%susr" % (os.sep)
16 LOCALE_DIR = "%s%sshare%slocale" % ( LOCALE_PREFIX, os.sep, os.sep )
17 PACKAGE = "shutdown_helper_applet"
18 TEXT_DOMAIN = "tails"
19 locale.setlocale(locale.LC_ALL, "")
20 bindtextdomain(PACKAGE, LOCALE_DIR)
21 textdomain(TEXT_DOMAIN)
23 def applet_factory(applet, iid, data=None):
24 image = Gtk.Image()
25 image.set_from_file('/usr/share/icons/gnome/scalable/actions/system-shutdown-symbolic.svg')
26 applet.add(image)
27 applet.connect('button-press-event', show_action_menu)
28 applet.show_all()
29 return True
31 def show_action_menu(applet, event):
32 if event.button != Gdk.BUTTON_PRIMARY:
33 return
35 menu = Gtk.Menu()
36 menu.attach_to_widget(applet, None)
37 menu_entries = [
38 # [_("Lock Screen"), 'gnome-lockscreen', lock_screen],
39 [_("Shutdown Immediately"), 'gnome-shutdown', shutdown],
40 [_("Reboot Immediately"), 'gtk-refresh', reboot]
42 for [label, icon_name, action] in menu_entries:
43 item = Gtk.ImageMenuItem.new_with_label(label)
44 icon = Gtk.Image()
45 icon.set_from_icon_name(icon_name, Gtk.IconSize.MENU)
46 item.set_image(icon)
47 item.connect("activate", action)
48 item.show()
49 menu.add(item)
50 menu.popup(parent_menu_shell=None,
51 parent_menu_item=None,
52 func=None,
53 data=None,
54 button=event.button,
55 activate_time=event.time)
57 def lock_screen(widget):
58 subprocess.call(["gnome-screensaver-command", "--lock"])
60 def shutdown(widget):
61 subprocess.call(["sudo", "-n", "halt"])
63 def reboot(widget):
64 subprocess.call(["sudo", "-n", "reboot"])
66 # run it in a gtk window
67 if len(sys.argv) > 1 and sys.argv[1] == "test":
68 main_window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
69 main_window.set_title("Shutdown Helper")
70 main_window.connect("destroy", Gtk.main_quit)
71 applet_factory(main_window, None)
72 main_window.show_all()
73 Gtk.main()
74 sys.exit()
76 if __name__ == '__main__':
77 PanelApplet.Applet.factory_main("ShutdownHelperFactory",
78 PanelApplet.Applet.__gtype__,
79 applet_factory,
80 None)