Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed Linux Lock X/Y positioning of elements.

  • Loading branch information...
commit 74f2ebd412e41b5afd15d4ff287968473ca7d854 1 parent b79b5bb
@tomas tomas authored
Showing with 58 additions and 26 deletions.
  1. +57 −25 lock/platform/linux/prey-lock
  2. +1 −1  lock/version
View
82 lock/platform/linux/prey-lock
@@ -7,25 +7,28 @@
#############################################
import os, sys
-import hashlib
+from hashlib import md5
import gtk
import pango
+image_file = "/../../lib/bg-lock-with-input.png"
+
class Lock:
def get_md5(self, string):
- return hashlib.md5(string).hexdigest()
+ return md5(string).hexdigest()
def enter_callback(self, widget, entry):
hashed_text = self.get_md5(entry.get_text())
# print hashed_text
if hashed_text != passwd:
- print " -- Bad password attempt."
+ print "Invalid password"
+ sys.stdout.flush()
self.label.show()
return True
else:
enable_XF86Switch()
- print ' -- Correctomondo. PC Unlocked.'
+ print 'Correctomondo. PC Unlocked.'
# self.label.set_markup('<span foreground="green">Very good. Access granted.</span>');
# self.label.show()
os._exit(66)
@@ -76,7 +79,7 @@ class Lock:
self.bg_window.set_deletable(False)
self.bg_window.show()
- monitors = self.bg_window.get_screen().get_n_monitors()
+ # monitors = self.bg_window.get_screen().get_n_monitors()
###################################
# window
@@ -104,7 +107,11 @@ class Lock:
main_screen_height = self.window.get_screen().get_monitor_geometry(0).height
main_screen_middle = main_screen_width/2
+ # print "Main screen size: %s x %s" % (main_screen_width, main_screen_height)
+ # print "Main screen middle: %s" % main_screen_middle
+
vbox = gtk.VBox(False, 0)
+ vbox.set_size_request(main_screen_width, main_screen_height)
self.window.add(vbox)
# vbox.show()
@@ -114,46 +121,72 @@ class Lock:
image = gtk.Image()
script_path = sys.path[0]
- bg_path = script_path + "/../../lib/bg-lock-with-input.png"
- image.set_from_file(bg_path)
+ bg_path = script_path + image_file
+ pixbuf = gtk.gdk.pixbuf_new_from_file(bg_path)
+ image_width = pixbuf.get_width()
+ image_height = pixbuf.get_height()
+
+ # print 'Image size: %s x %s' % (image_width, image_height)
+ scale = 1
+
+ if image_width > main_screen_width or image_height > main_screen_height:
+ scale = min(float(main_screen_width)/image_width, float(main_screen_height)/image_height)
+ new_width = int(scale*image_width)
+ new_height = int(scale*image_height)
+ # print "Scaled image to: %s x %s" % (new_width, new_height)
+ pixbuf = pixbuf.scale_simple(new_width, new_height, gtk.gdk.INTERP_BILINEAR)
+
+ image.set_from_pixbuf(pixbuf)
+ image.set_size_request(main_screen_width, main_screen_height)
image.show()
- vbox.set_size_request(main_screen_width, main_screen_height)
vbox.add(image)
###################################
# label
###################################
- hbox = gtk.HBox(False, 0)
- vbox.add(hbox)
- hbox.show()
-
self.entry = gtk.Entry(max=0)
self.entry.set_max_length(40)
self.entry.set_inner_border(None)
- self.entry.set_width_chars(32)
+ self.entry.set_width_chars(24)
self.entry.set_visibility(False)
self.entry.set_has_frame(False)
- self.entry.modify_font(pango.FontDescription("sans 20"))
+ self.entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FFFFFF"))
+ self.entry.modify_font(pango.FontDescription("sans 16"))
self.entry.set_flags(gtk.CAN_FOCUS | gtk.HAS_FOCUS | gtk.HAS_GRAB | gtk.CAN_DEFAULT | gtk.SENSITIVE)
self.entry.connect("activate", self.enter_callback, self.entry)
# self.entry.show()
+ input_size = 210
+
+ padding_left = int(input_size*scale)
+ padding_top = -3
+ # print 'Padding: left %s, top %s' % (padding_left, padding_top)
+
+ # if image was scaled down, calculate offset for positioning elements
+ if image_height > main_screen_height:
+ padding_top = 18 - int((image_height - main_screen_height)/8)
+
+ x_position = main_screen_middle-padding_left
+ y_position = -(main_screen_height/2)+padding_top
+ # print "Fixed position: %s, %s" % (x_position, y_position)
+
fixed = gtk.Fixed()
- fixed.put(self.entry, main_screen_middle-240, -(main_screen_height/2)+18)
+ fixed.put(self.entry, x_position, y_position)
fixed.show()
- hbox.pack_start(fixed, False, False, 30)
+ vbox.pack_start(fixed, False, False, 0)
text = 'Invalid password. Access denied.'
self.label = gtk.Label()
self.label.set_markup('<span foreground="#aa0000">'+text+'</span>');
- self.label.modify_font(pango.FontDescription("sans 20"))
- self.label.set_size_request(main_screen_width, 30)
+ self.label.modify_font(pango.FontDescription("sans 15"))
+ # self.label.set_size_request(main_screen_width, 30)
fixed2 = gtk.Fixed()
- fixed2.put(self.label, -main_screen_width/2-240, -(main_screen_height/2)+60)
- hbox.pack_start(fixed2, True, False, 30)
+ # push label down a bit, and left a bit so it remains centered
+ fixed2.put(self.label, x_position + 26, y_position + 44)
+ vbox.pack_start(fixed2, False, False, 0)
disable_XF86Switch()
@@ -201,7 +234,7 @@ def disable_XF86Switch():
subprocess.Popen(cmd)
except IndexError:
- print "Couldnt parse Xmodmap list"
+ print "Couldn't parse Xmodmap list."
except OSError, subprocess.CalledProcessError:
# print "Xmodmap not found"
@@ -211,10 +244,9 @@ def disable_XF86Switch():
if __name__ == "__main__":
- if len(sys.argv) < 2:
- passwd = 'e75f0173be748b6f68b3feb61255693c' # preyrocks
- # print 'No password specified.'
- # os._exit(1)
+ if len(sys.argv) < 2 or len(sys.argv[1]) != 32:
+ print "You need to pass an MD5 hexdigested string."
+ sys.exit(1)
else:
passwd = sys.argv[1]
View
2  lock/version
@@ -1 +1 @@
-2.9
+3.0
Please sign in to comment.
Something went wrong with that request. Please try again.