breaktime lock
This commit is contained in:
parent
90a4a23bd4
commit
e969b50124
|
|
@ -12,7 +12,7 @@ from PyQt6.QtWidgets import (
|
|||
QMessageBox,
|
||||
)
|
||||
from PyQt6.QtGui import QIcon, QPixmap, QColor, QAction, QPainter
|
||||
from PyQt6.QtCore import QTimer, Qt
|
||||
from PyQt6.QtCore import QTimer, Qt, pyqtSignal, QEventLoop
|
||||
|
||||
|
||||
class State(Enum):
|
||||
|
|
@ -38,7 +38,8 @@ COLOR = {
|
|||
State.IDLE: "#608c58",
|
||||
State.PENDING: "#d32a5d",
|
||||
State.BREAK: "#7e95d3",
|
||||
QWidget: "rgba(40, 20, 40, 200)",
|
||||
0: "rgba(40, 20, 40, 200)",
|
||||
1: "rgba(40, 20, 40, 255)",
|
||||
}
|
||||
DONE = '/run/current-system/sw/share/sounds/freedesktop/stereo/complete.oga'
|
||||
POP = '/run/current-system/sw/share/sounds/freedesktop/stereo/message.oga'
|
||||
|
|
@ -103,15 +104,21 @@ class BreakTimer(QSystemTrayIcon):
|
|||
self.overlay.setGeometry(screen_geometry)
|
||||
|
||||
menu = QMenu()
|
||||
self.p_ac = QAction("Pause Timer", menu)
|
||||
self.p_ac.triggered.connect(self.pause_timers)
|
||||
menu.addAction(self.p_ac)
|
||||
b_ac = QAction("Break Now", menu)
|
||||
b_ac.triggered.connect(self.start_break)
|
||||
menu.addAction(b_ac)
|
||||
q_ac = QAction("Quit", menu)
|
||||
q_ac.triggered.connect(sys.exit)
|
||||
menu.addAction(q_ac)
|
||||
self.p_act = QAction("Pause Timer", menu)
|
||||
self.p_act.triggered.connect(self.pause_timers)
|
||||
menu.addAction(self.p_act)
|
||||
act = QAction("Reset Timer", menu)
|
||||
act.triggered.connect(self.start_idle)
|
||||
menu.addAction(act)
|
||||
act = QAction("Break Now", menu)
|
||||
act.triggered.connect(self.start_break)
|
||||
menu.addAction(act)
|
||||
act = QAction("Go Inactive", menu)
|
||||
act.triggered.connect(self.inactive_popup)
|
||||
menu.addAction(act)
|
||||
act = QAction("Quit", menu)
|
||||
act.triggered.connect(sys.exit)
|
||||
menu.addAction(act)
|
||||
self.setContextMenu(menu)
|
||||
|
||||
self.start_idle()
|
||||
|
|
@ -144,12 +151,13 @@ class BreakTimer(QSystemTrayIcon):
|
|||
self.timer.start(DURATION[self.state])
|
||||
|
||||
def start_idle(self):
|
||||
self.icon_timer.start()
|
||||
self.p_act.setText("Pause Timer")
|
||||
self.set_state(State.IDLE, DURATION[State.IDLE]//M)
|
||||
|
||||
def start_break(self):
|
||||
self.set_state(State.BREAK, "...")
|
||||
self.overlay.show()
|
||||
self.overlay.grabKeyboard()
|
||||
self.overlay.start()
|
||||
|
||||
def on_timeout(self):
|
||||
if self.state is State.IDLE:
|
||||
|
|
@ -164,9 +172,9 @@ class BreakTimer(QSystemTrayIcon):
|
|||
else:
|
||||
self.inactive_popup()
|
||||
elif self.state is State.BREAK:
|
||||
self.overlay.hide()
|
||||
self.start_idle()
|
||||
play_sound(POP)
|
||||
self.overlay.stop()
|
||||
self.start_idle()
|
||||
self.showMessage('Timer', 'Timer is complete')
|
||||
|
||||
def inactive_popup(self):
|
||||
|
|
@ -192,31 +200,59 @@ class BreakTimer(QSystemTrayIcon):
|
|||
self.update_icon()
|
||||
self.timer.stop()
|
||||
self.icon_timer.stop()
|
||||
self.p_ac.setText("Resume Timer")
|
||||
self.p_act.setText("Resume Timer")
|
||||
else:
|
||||
self.color = COLOR[self.state]
|
||||
self.update_icon()
|
||||
self.timer.start(self.remaining_time)
|
||||
self.icon_timer.start()
|
||||
self.p_ac.setText("Pause Timer")
|
||||
self.p_act.setText("Pause Timer")
|
||||
|
||||
|
||||
class TransparentOverlay(QWidget):
|
||||
unlock_sig = pyqtSignal()
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.keys = []
|
||||
self.setWindowFlags(Qt.WindowType.BypassWindowManagerHint)
|
||||
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
||||
layout = QVBoxLayout()
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
bg = QWidget()
|
||||
bg.setStyleSheet(f"background-color: {COLOR[QWidget]};")
|
||||
layout.addWidget(bg)
|
||||
self.bg = QWidget()
|
||||
self.bg.setStyleSheet(f"background-color: {COLOR[0]};")
|
||||
layout.addWidget(self.bg)
|
||||
self.setLayout(layout)
|
||||
|
||||
def start(self):
|
||||
self.keys = []
|
||||
self.locked = False
|
||||
self.show()
|
||||
self.grabKeyboard()
|
||||
|
||||
def stop(self):
|
||||
if self.locked:
|
||||
loop = QEventLoop()
|
||||
self.unlock_sig.connect(loop.quit)
|
||||
loop.exec()
|
||||
self.hide()
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() == Qt.Key.Key_Escape:
|
||||
k = event.key()
|
||||
self.keys.append(k)
|
||||
self.keys = self.keys[-10:]
|
||||
if self.locked:
|
||||
play_sound(POP)
|
||||
if self.keys[-6:] == list(b'UNLOCK'):
|
||||
self.locked = False
|
||||
self.bg.setStyleSheet(f"background-color: {COLOR[0]};")
|
||||
self.unlock_sig.emit()
|
||||
elif k == Qt.Key.Key_Escape:
|
||||
self.hide()
|
||||
elif self.keys[-4:] == list(b'LOCK'):
|
||||
self.locked = True
|
||||
self.bg.setStyleSheet(f"background-color: {COLOR[1]};")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue