Add code
This commit is contained in:
80
mobbing_notification.py
Normal file
80
mobbing_notification.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
from PyQt5.QtCore import Qt, QTimer
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
|
||||
|
||||
class MobbingNotification(QMainWindow):
|
||||
def __init__(self, vx=15, vy=-30, gravity=1, t_increment=0.8):
|
||||
super().__init__()
|
||||
|
||||
self.setAttribute(Qt.WA_TranslucentBackground, True)
|
||||
self.setAttribute(Qt.WA_NoSystemBackground, True)
|
||||
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool)
|
||||
|
||||
self.label = QLabel(self)
|
||||
pixmap = QPixmap(resource_path('image.png'))
|
||||
pixmap = pixmap.scaled(pixmap.width() // 2, pixmap.height() // 2)
|
||||
self.label.setPixmap(pixmap)
|
||||
self.label.setGeometry(0, 0, pixmap.width(), pixmap.height())
|
||||
|
||||
self.resize(pixmap.width(), pixmap.height())
|
||||
|
||||
# Initial position: below the screen
|
||||
screen = QApplication.primaryScreen().geometry()
|
||||
self.screen_height = screen.height()
|
||||
self.screen_width = screen.width()
|
||||
self.start_x = self.screen_width - 200
|
||||
self.start_y = self.screen_height + 100
|
||||
self.move(self.start_x, self.start_y)
|
||||
|
||||
# Animation parameters
|
||||
self.t = 0
|
||||
self.t_increment = t_increment
|
||||
self.vx = vx
|
||||
self.vy = vy
|
||||
self.gravity = gravity
|
||||
self.has_peaked = False
|
||||
|
||||
self.timer = QTimer()
|
||||
self.timer.timeout.connect(self.animate)
|
||||
self.timer.start(16)
|
||||
|
||||
def animate(self):
|
||||
self.t += self.t_increment
|
||||
x = self.start_x - self.vx * self.t
|
||||
y = self.start_y + self.vy * self.t + 0.5 * self.gravity * self.t ** 2
|
||||
|
||||
self.move(int(x), int(y))
|
||||
|
||||
if not self.has_peaked and self.vy + self.gravity * self.t > 0:
|
||||
self.has_peaked = True
|
||||
|
||||
if self.has_peaked and y > self.screen_height:
|
||||
QApplication.quit()
|
||||
|
||||
def resource_path(relative_path):
|
||||
try:
|
||||
base_path = sys._MEIPASS
|
||||
except Exception:
|
||||
base_path = os.path.abspath(".")
|
||||
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Animated window jumping into the screen.")
|
||||
parser.add_argument('--vx', type=float, default=15, help='Horizontal speed')
|
||||
parser.add_argument('--vy', type=float, default=-30, help='Initial vertical speed')
|
||||
parser.add_argument('--gravity', type=float, default=1, help='Gravity acceleration')
|
||||
parser.add_argument('--t_increment', type=float, default=0.8, help='Time increment per frame')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
window = MobbingNotification(vx=args.vx, vy=args.vy, gravity=args.gravity, t_increment=args.t_increment)
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user