source: epoptes/trunk/fuentes/epoptes-client/lock-screen @ 295

Last change on this file since 295 was 295, checked in by mabarracus, 3 years ago

copy trusty epoptes code

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4###########################################################################
5# Lock the screen.
6#
7# Copyright (C) 2010 Fotis Tsamis <ftsamis@gmail.com>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FINESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21#
22# On Debian GNU/Linux systems, the complete text of the GNU General
23# Public License can be found in `/usr/share/common-licenses/GPL".
24###########################################################################
25
26import gtk
27import gtk.gdk as gdk
28import pango
29import gobject
30import sys
31import time
32
33class lockscreen:
34    def lock(self, msg="The screen is locked by a system administrator."):
35        backlock = gtk.Window(gtk.WINDOW_POPUP)
36        backlock.resize(1, 1)
37        backlock.modify_bg(gtk.STATE_NORMAL, gdk.Color("#000000"))
38        frontview = gtk.Window()
39        frontview.modify_bg(gtk.STATE_NORMAL, gdk.Color("#000000"))
40
41        vbox = gtk.VBox(spacing=75)
42
43        imagepb = gtk.gdk.pixbuf_new_from_file_at_size('lock.svg', 250, 250)
44        image = gtk.Image()
45        image.set_from_pixbuf(imagepb)
46        vbox.pack_start(image, True)
47
48        # Italic fonts are trancated in the sides, so add a space
49        self.label = gtk.Label(" " + msg + " ")
50        self.label.modify_font(pango.FontDescription('FreeSans italic 18'))
51        self.fade(True)
52        vbox.pack_start(self.label, True)
53
54        align = gtk.Alignment(0.5, 0.5, 0, 0)
55        align.add(vbox)
56        frontview.add(align)
57
58        backlock.show_all()
59        frontview.show_all()
60
61        frontview.set_keep_above(True)
62        frontview.fullscreen()
63        gdk.beep()
64        gdk.keyboard_grab(backlock.window, False, 0L)
65
66        # To automatically unlock the screen after 7 seconds, uncomment this:
67        #gobject.timeout_add(7000, self.unlock)
68
69
70    def fade(self, firsttime=False):
71        if firsttime:
72            self.fadesecs = 3.0
73            self.fadestart = time.time()
74            # For debugging:
75            #print self.fadestart, self.fadesecs
76
77        percentage = (time.time() - self.fadestart) / self.fadesecs
78        i = min(round(255 * percentage), 255)
79        c = "#%02x%02x%02x" % (i, i, i)
80        # For debugging:
81        #print time.time(), '-', 100 * percentage, "completed, rendering color ", c
82        self.label.modify_fg(gtk.STATE_NORMAL, gdk.Color(c))
83        # Put a sleep() here if you want to test for slow thin clients:
84        #time.sleep(0.6)
85        if i < 255:
86            gobject.timeout_add(60, self.fade)
87
88        return False
89
90
91    def unlock(self):
92        gdk.keyboard_ungrab(0L)
93        exit()
94
95
96if len(sys.argv) <= 1:
97    lockscreen().lock()
98else:
99    lockscreen().lock(sys.argv[1])
100gtk.main()
Note: See TracBrowser for help on using the repository browser.