use 2 space indentation
This commit is contained in:
parent
a66a2e8e97
commit
7a4edf66ed
3
vpet.py
3
vpet.py
@ -137,6 +137,9 @@ class VPet:
|
|||||||
self.frames = Frames()
|
self.frames = Frames()
|
||||||
self.activity = Activity()
|
self.activity = Activity()
|
||||||
|
|
||||||
|
self.animation_start = 0
|
||||||
|
self.animation_end = 0
|
||||||
|
|
||||||
def action_loop(self):
|
def action_loop(self):
|
||||||
if self.activity.is_interacting_with_user:
|
if self.activity.is_interacting_with_user:
|
||||||
self.is_busy = True
|
self.is_busy = True
|
||||||
|
|||||||
100
window_qt.py
100
window_qt.py
@ -11,61 +11,63 @@ from vpet import VPet
|
|||||||
|
|
||||||
|
|
||||||
def get_primary_monitor():
|
def get_primary_monitor():
|
||||||
m = next((monitor for monitor in get_monitors() if monitor.is_primary), None)
|
return next((monitor for monitor in get_monitors() if monitor.is_primary), None)
|
||||||
print(m.height)
|
|
||||||
print(m.width)
|
|
||||||
print(int(m.width/2))
|
|
||||||
return m
|
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.FPS = 60
|
self.interval = 60
|
||||||
self.primary_monitor = get_primary_monitor()
|
self.primary_monitor = get_primary_monitor()
|
||||||
# self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
# self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
||||||
self.setWindowFlags(Qt.WindowStaysOnTopHint)
|
self.setWindowFlags(Qt.WindowStaysOnTopHint)
|
||||||
# self.setAttribute(Qt.WA_TranslucentBackground)
|
# self.setAttribute(Qt.WA_TranslucentBackground)
|
||||||
self.click_event_time = 0
|
self.click_event_time = 0
|
||||||
self.v_pet = VPet(self.move, self.pos, self.draw, self.primary_monitor, x=int(self.primary_monitor.width/2), y=self.primary_monitor.height)
|
self.v_pet = VPet(self.move,
|
||||||
self.loop_timer = QTimer(self)
|
self.pos,
|
||||||
self.loop_timer.setSingleShot(False)
|
self.draw,
|
||||||
self.loop_timer.setInterval(self.FPS)
|
self.primary_monitor,
|
||||||
self.loop_timer.timeout.connect(self.loop)
|
x=int(self.primary_monitor.width / 2),
|
||||||
self.loop_timer.start()
|
y=self.primary_monitor.height)
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
self.loop_timer = QTimer(self)
|
||||||
self.click_event_time = time.time()
|
self.loop_timer.setSingleShot(False)
|
||||||
self.v_pet.activity.set_interacting_with_user()
|
self.loop_timer.setInterval(self.interval)
|
||||||
if event.button() == Qt.LeftButton:
|
self.loop_timer.timeout.connect(self.loop)
|
||||||
self.drag_position = event.globalPos()
|
self.loop_timer.start()
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
time_delta = time.time() - self.click_event_time
|
self.click_event_time = time.time()
|
||||||
if time_delta <= 0.2:
|
self.v_pet.activity.set_interacting_with_user()
|
||||||
if event.button() == Qt.LeftButton:
|
if event.button() == Qt.LeftButton:
|
||||||
print('Click left')
|
self.drag_position = event.globalPos()
|
||||||
if event.button() == Qt.RightButton:
|
|
||||||
print('Click right')
|
|
||||||
else:
|
|
||||||
if event.button() == Qt.RightButton:
|
|
||||||
print('Click long right')
|
|
||||||
|
|
||||||
self.click_event_time = 0
|
def mouseReleaseEvent(self, event):
|
||||||
self.v_pet.activity.is_interacting_with_user = False
|
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')
|
||||||
|
else:
|
||||||
|
if event.button() == Qt.RightButton:
|
||||||
|
print('Click long right')
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
self.click_event_time = 0
|
||||||
if event.buttons() == Qt.LeftButton:
|
self.v_pet.activity.is_interacting_with_user = False
|
||||||
delta = event.globalPos() - self.drag_position
|
|
||||||
self.move(self.pos() + delta)
|
|
||||||
self.drag_position = event.globalPos()
|
|
||||||
self.click_event_time = 0
|
|
||||||
|
|
||||||
def draw(self, img):
|
def mouseMoveEvent(self, event):
|
||||||
img = img.rotate(Rotate.up)
|
if event.buttons() == Qt.LeftButton:
|
||||||
self.resize(img.width, img.height)
|
delta = event.globalPos() - self.drag_position
|
||||||
self.setCentralWidget(TransparentGLWidget(img))
|
self.move(self.pos() + delta)
|
||||||
|
self.drag_position = event.globalPos()
|
||||||
|
self.click_event_time = 0
|
||||||
|
|
||||||
def loop(self):
|
def draw(self, img):
|
||||||
self.v_pet.action_loop()
|
img = img.rotate(Rotate.up)
|
||||||
self.show()
|
self.resize(img.width, img.height)
|
||||||
|
self.setCentralWidget(TransparentGLWidget(img))
|
||||||
|
|
||||||
|
def loop(self):
|
||||||
|
self.v_pet.action_loop()
|
||||||
|
self.show()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user