Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created August 7, 2011 23:31
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 hughsaunders/1130929 to your computer and use it in GitHub Desktop.
Save hughsaunders/1130929 to your computer and use it in GitHub Desktop.
An annoying program to display a fullscreen reminder message before and after screen lock.
#!/usr/bin/env python
# HuntGroupReminder - Hugh Saunders 2011
# This is probably the most annoying program ever.
# It pops up a window before and after screen locking in order to remind me to login/logout of my desk phone.
# Actually, I couldn't figure out how to show a window before screen lock, so you have to call this program instead of locking the screen.
# This script will initiate screen lock via dbus once the initial window has been shown, it then subscribes to a dbus signal so it is notified
# when the screen is unlocked
# To use this in ubuntu: goto system > preferences > keyboard shortcuts.
# - reassign lock screen to something else (ctrl+alt+shitf+l)
# - add a custom keyboard shortcut, use this script and ctrl+alt+l
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import gtk
import pango
class DbusHandler:
def __init__(self,pn):
self.pn = pn
dbus_loop=DBusGMainLoop(set_as_default=True)
dbus.set_default_main_loop(dbus_loop)
self.session_bus = dbus.SessionBus()
# Register to receive a signal whenever the screen is locked or unlocked
self.session_bus.add_signal_receiver(pn.unlock_screen,
dbus_interface="org.gnome.ScreenSaver")
def quit(self):
self.session_bus.close()
def callback(self,*args):
pass
def lock(self):
gnome_screensaver=self.session_bus.get_object('org.gnome.ScreenSaver', '/org/gnome/ScreenSaver')
# these callbacks do nothing, but including them makes the call async:
gnome_screensaver.Lock(reply_handler=self.callback,error_handler=self.callback)
class PhoneNotifier:
def __init__(self):
self.loop = gobject.MainLoop()
self.dbh=DbusHandler(self)
def lock_screen(self):
self.show_window("<-- Admin Out",self.destroy_then_lock)
self.loop.run()
def unlock_screen(self,*args):
# if args[0] is true, then the screen is being locked, this should only be run with the screen is being unlocked.
if not args[0]:
self.show_window("<-- Login To Phone",self.destroy_then_quit)
def destroy_then_lock(self,control,window):
window.destroy()
self.dbh.lock()
def destroy_then_quit(self,control,window):
window.destroy()
self.quit()
def quit(self):
self.dbh.quit()
self.loop.quit()
def show_window(self, text,callback):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
#window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN) #makes no difference
box = gtk.VBox()
label = gtk.Label(text)
label.modify_font(pango.FontDescription("Sans 50"))
button = gtk.Button("OK, done that.")
button.connect("clicked", callback, window)
box.pack_start(label, expand=True)
box.pack_end(button, expand=False)
window.add(box)
box.show_all()
window.fullscreen()
window.show()
if __name__ == "__main__":
pn = PhoneNotifier()
pn.lock_screen()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment