Skip to content

Instantly share code, notes, and snippets.

@qpwo
Created January 3, 2025 06:04
Show Gist options
  • Save qpwo/05da71f2aa8ef773aadcb76e068aab73 to your computer and use it in GitHub Desktop.
Save qpwo/05da71f2aa8ef773aadcb76e068aab73 to your computer and use it in GitHub Desktop.
unquittable unminimizable clippy
import sys
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget, QLabel
from PyQt5.QtGui import QPixmap, QKeyEvent
from PyQt5.QtCore import QTimer, Qt, QPoint
import time
from datetime import datetime
def yyyy_mm_dd_hh_mm_ss():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
class ClippyWindow(QWidget):
def __init__(self, image_path):
super().__init__()
self.image_path = image_path
self.label = QLabel(self)
self.question_text ="What are you doing right now? Is there an easier way? (min 20 chars, 20 sec)"
self.question_label = QLabel(self.question_text, self)
self.question_label.setStyleSheet("""
color: white;
font-size: 32px;
font-weight: bold;
padding: 5px;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
""")
self.answer_label = QLabel("", self)
self.answer_label.setStyleSheet("""
color: white;
font-size: 24px;
font-weight: bold;
padding: 5px;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
""")
self.answer_text = ""
self.enter_count = 0
self.dragging = False
self.offset = QPoint()
self.initUI()
self.setupTimer()
def initUI(self):
pixmap = QPixmap(self.image_path)
self.label.setPixmap(pixmap)
# Set window attributes
self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
# Layout
layout = QVBoxLayout()
layout.addWidget(self.label)
layout.addWidget(self.question_label)
layout.addWidget(self.answer_label)
self.setLayout(layout)
# Adjust window size
self.resize(pixmap.width(), pixmap.height() + self.question_label.height() + self.answer_label.height() + 20)
self.started_at = time.time()
self.is_done = False
self.show()
def keyPressEvent(self, a0: QKeyEvent):
enough_time = time.time() - self.started_at > 20
enough_text = len(self.answer_text) >= 20
if (a0.key() == Qt.Key_Enter or a0.key() == Qt.Key_Return):
self.enter_count += 1
if enough_time and enough_text and self.enter_count >= 2:
self.save_answer()
else:
self.answer_text += "\n" # Add a newline for single enter
else:
self.enter_count = 0 # Reset enter count on other key presses
if Qt.Key_A <= a0.key() <= Qt.Key_Z or a0.key() == Qt.Key_Space:
self.answer_text += a0.text()
self.answer_label.setText(self.answer_text)
def save_answer(self):
with open("answers.txt", "a") as f:
f.write(yyyy_mm_dd_hh_mm_ss() + ' ' + self.answer_text + '\n')
print(f"Answer saved: {self.answer_text}")
self.answer_text = ""
self.answer_label.setText("")
self.close()
def mousePressEvent(self, a0):
if a0.button() == Qt.LeftButton:
self.dragging = True
self.offset = a0.globalPos() - self.frameGeometry().topLeft()
a0.accept()
def mouseMoveEvent(self, a0):
if self.dragging and (a0.buttons() & Qt.LeftButton): # type: ignore
self.move(a0.globalPos() - self.offset)
a0.accept()
def mouseReleaseEvent(self, a0):
self.dragging = False
a0.accept()
def setupTimer(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self.bringToForeground)
self.timer.start(1_00)
def bringToForeground(self):
self.raise_()
self.activateWindow()
# print('iter')
def closeEvent(self, a0):
# self.save_answer()
# a0.accept()
if self.is_done:
a0.accept()
else:
self.question_text += " You cant kill me i am death"
self.question_label.setText(self.question_text)
a0.ignore()
if __name__ == '__main__':
app = QApplication(sys.argv)
clippy = ClippyWindow("image.png")
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment