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