Cosmetic adjustments

This commit is contained in:
cubernetes 2023-11-08 03:10:34 +01:00
parent 16c7474ca9
commit cd0e4c9084
2 changed files with 37 additions and 11 deletions

46
plock
View File

@ -1,21 +1,25 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import pwd
import sys import sys
import hashlib import hashlib
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QLineEdit from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QVBoxLayout from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import QCursor from PyQt5.QtWidgets import QDesktopWidget
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtCore import QTimer from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QCursor
CORRECT_PASSWORD_HASH = '1d2e2b10cf9a5474612138ac00bc8b1e8fe895822ddc1e77e0edd023fcff4565' CORRECT_PASSWORD_HASH = '1d2e2b10cf9a5474612138ac00bc8b1e8fe895822ddc1e77e0edd023fcff4565'
class FullScreenWindow(QMainWindow): class LockScreen(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.title = 'plock' self.title = 'plock'
@ -24,21 +28,40 @@ class FullScreenWindow(QMainWindow):
def initUI(self): def initUI(self):
self.setWindowTitle(self.title) self.setWindowTitle(self.title)
self.setWindowFlags(Qt.FramelessWindowHint)
self.central_widget = QWidget() self.central_widget = QWidget()
self.central_widget.setFixedSize(300, 100)
self.setCentralWidget(self.central_widget) self.setCentralWidget(self.central_widget)
layout = QVBoxLayout() layout = QVBoxLayout()
current_user = pwd.getpwuid(os.getuid())[0]
self.password_label = QLabel(f"{current_user}'s password:")
self.password_label.setAlignment(Qt.AlignCenter)
layout.addWidget(self.password_label)
self.password_field = QLineEdit() self.password_field = QLineEdit()
self.password_field.setEchoMode(QLineEdit.Password) self.password_field.setEchoMode(QLineEdit.Password)
self.password_field.returnPressed.connect(self.check_password) self.password_field.returnPressed.connect(self.check_password)
self.password_field.setFixedWidth(200) self.password_field.setFixedWidth(200)
layout.addWidget(self.password_field, 0, Qt.AlignCenter) layout.addWidget(self.password_field, 0, Qt.AlignCenter)
layout.setContentsMargins(50, 20, 50, 20)
self.central_widget.setLayout(layout) self.central_widget.setLayout(layout)
self.showFullScreen() self.show()
QTimer.singleShot(100, self.centerOnScreen)
# self.showFullScreen()
def centerOnScreen(self):
screen_center = QDesktopWidget().availableGeometry().center()
frame_geometry = self.frameGeometry()
screen_center.setY(screen_center.y() - 100)
frame_geometry.moveCenter(screen_center)
self.move(frame_geometry.topLeft())
def check_password(self): def check_password(self):
entered_password_hash = hashlib.sha256(self.password_field.text().encode('utf-8')).hexdigest() entered_password_hash = hashlib.sha256(self.password_field.text().encode('utf-8')).hexdigest()
@ -50,25 +73,28 @@ class FullScreenWindow(QMainWindow):
QTimer.singleShot(100, self.grabKeyboardAndMouse) QTimer.singleShot(100, self.grabKeyboardAndMouse)
def grabKeyboardAndMouse(self): def grabKeyboardAndMouse(self):
super().showFullScreen()
self.grabMouse() self.grabMouse()
self.grabKeyboard() self.grabKeyboard()
self.setCursor(QCursor(Qt.BlankCursor)) # self.setCursor(QCursor(Qt.BlankCursor))
self.password_field.setFocus() self.password_field.setFocus()
def keyPressEvent(self, event): def keyPressEvent(self, event):
self.grabMouse() self.grabMouse()
self.grabKeyboard() self.grabKeyboard()
if event.key() == Qt.Key_Escape: # Secret bypass (currently inactive)
if event.modifiers() & Qt.ControlModifier: if (
print("Secure exit requested") False
self.close() and event.key() == Qt.Key_Escape
and event.modifiers() & Qt.ControlModifier
):
print("Secure exit requested")
self.close()
else: else:
self.password_field.keyPressEvent(event) self.password_field.keyPressEvent(event)
def main() -> int: def main() -> int:
app = QApplication(sys.argv) app = QApplication(sys.argv)
ex = FullScreenWindow() ex = LockScreen()
return app.exec_() return app.exec_()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
/home/"$(whoami)"/.local/bin/cmatrix -f /home/"$(whoami)"/.local/bin/cmatrix -f -C blue "${@}"