67 lines
2.0 KiB
Python
Executable File
67 lines
2.0 KiB
Python
Executable File
#!/bin/python3
|
|
|
|
import time
|
|
from PyQt5.QtWidgets import QMainWindow
|
|
from PyQt5.QtWidgets import QApplication
|
|
from PyQt5.QtCore import Qt, QTimer
|
|
|
|
from transparent_widget import TransparentGLWidget
|
|
from vpet import Rotate
|
|
from vpet import VPet
|
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.FPS = 60
|
|
# self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
|
self.setWindowFlags(Qt.WindowStaysOnTopHint)
|
|
self.setAttribute(Qt.WA_TranslucentBackground)
|
|
self.click_event_time = 0
|
|
|
|
self.v_pet = VPet(self.move, self.pos, self.draw)
|
|
|
|
self.loop_timer = QTimer(self)
|
|
self.loop_timer.setSingleShot(False)
|
|
self.loop_timer.setInterval(self.FPS)
|
|
self.loop_timer.timeout.connect(self.loop)
|
|
self.loop_timer.start()
|
|
|
|
def mousePressEvent(self, event):
|
|
self.click_event_time = time.time()
|
|
self.v_pet.activity.set_interacting_with_user()
|
|
if event.button() == Qt.LeftButton:
|
|
self.drag_position = event.globalPos()
|
|
|
|
def mouseReleaseEvent(self, event):
|
|
time_delta = time.time() - self.click_event_time
|
|
if time_delta <= 0.2:
|
|
if event.button() == Qt.LeftButton:
|
|
print('Click left')
|
|
if event.button() == Qt.RightButton:
|
|
print('Click right')
|
|
|
|
self.click_event_time = 0
|
|
self.v_pet.activity.is_interacting_with_user = False
|
|
|
|
def mouseMoveEvent(self, event):
|
|
self.click_event_time = 0
|
|
if event.buttons() == Qt.LeftButton:
|
|
delta = event.globalPos() - self.drag_position
|
|
self.move(self.pos() + delta)
|
|
self.drag_position = event.globalPos()
|
|
|
|
def draw(self, img):
|
|
img = img.rotate(Rotate.up)
|
|
self.resize(img.width, img.height)
|
|
self.setCentralWidget(TransparentGLWidget(img))
|
|
|
|
def loop(self):
|
|
self.v_pet.action_loop()
|
|
self.show()
|
|
|
|
|
|
app = QApplication([])
|
|
window = MainWindow()
|
|
app.exec_()
|