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"
19 locale
.setlocale(locale
.LC_ALL
, "")
20 bindtextdomain(PACKAGE
, LOCALE_DIR
)
21 textdomain(TEXT_DOMAIN
)
23 def applet_factory(applet
, iid
, data
=None):
25 image
.set_from_file('/usr/share/icons/gnome/scalable/actions/system-shutdown-symbolic.svg')
27 applet
.connect('button-press-event', show_action_menu
)
31 def show_action_menu(applet
, event
):
32 if event
.button
!= Gdk
.BUTTON_PRIMARY
:
36 menu
.attach_to_widget(applet
, None)
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
)
45 icon
.set_from_icon_name(icon_name
, Gtk
.IconSize
.MENU
)
47 item
.connect("activate", action
)
50 menu
.popup(parent_menu_shell
=None,
51 parent_menu_item
=None,
55 activate_time
=event
.time
)
57 def lock_screen(widget
):
58 subprocess
.call(["gnome-screensaver-command", "--lock"])
61 subprocess
.call(["sudo", "-n", "halt"])
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()
76 if __name__
== '__main__':
77 PanelApplet
.Applet
.factory_main("ShutdownHelperFactory",
78 PanelApplet
.Applet
.__gtype
__,