Compare commits

..

5 Commits

Author SHA1 Message Date
7a4edf66ed use 2 space indentation 2024-12-15 21:36:50 +01:00
a66a2e8e97 add screen detection 2024-12-13 00:49:04 +01:00
4535d43dfe fix update position bug 2024-12-12 20:24:09 +01:00
3e8e04c5fa add draw 2024-12-12 04:49:06 +01:00
3a1c63f4ce add long right click detection 2024-12-12 04:33:57 +01:00
4 changed files with 96 additions and 58 deletions

View File

@ -0,0 +1,7 @@
from PyQt5.QtWidgets import QApplication
from window_qt import MainWindow
app = QApplication([])
window = MainWindow()
app.exec_()

View File

@ -1,4 +1,5 @@
screeninfo
PyOpenGL
PyGObject-stubs
PyQt5
PyQt5-stubs
PyGObject-stubs
PyQt5-stubs

37
vpet.py
View File

@ -65,6 +65,7 @@ class Activity:
self.is_interacting_with_user = False
def set_idle(self):
print('Setting idle')
self.is_idle = True
self.is_sleeping = False
self.is_dreaming = False
@ -74,6 +75,7 @@ class Activity:
self.is_interacting_with_user = False
def set_sleeping(self):
print('Setting sleeping')
self.is_idle = False
self.is_sleeping = True
self.is_moving = False
@ -81,6 +83,7 @@ class Activity:
self.is_thinking = False
def set_dreaming(self):
print('Setting dreaming')
self.is_idle = False
self.is_dreaming = True
self.is_moving = False
@ -88,12 +91,14 @@ class Activity:
self.is_thinking = False
def set_moving(self):
print('Setting moving')
self.is_idle = False
self.is_moving = True
self.is_sleeping = False
self.is_dreaming = False
def set_talking(self):
print('Setting talking')
self.is_idle = False
self.is_talking = True
self.is_thinking = False
@ -106,6 +111,7 @@ class Activity:
self.is_sleeping = False
def set_interacting_with_user(self):
print('Setting interacting with user')
self.is_idle = False
self.is_sleeping = False
self.is_dreaming = False
@ -116,26 +122,43 @@ class Activity:
class VPet:
def __init__(self, move, pos, draw, x=0, y=0, screen=1):
self.screen = screen
def __init__(self, move, pos, draw, monitor, x=0, y=0,):
self.monitor = monitor
self.pos = pos
self.x_postion = x
self.y_postion = y
self.x_destination = 0
self.y_destination = 0
self.rotation = Rotate.up
self.is_busy = False
self.move = move
self.draw = draw
self.frames = Frames()
self.activity = Activity()
def action_loop(self):
print(f'Interacting with user: {self.activity.is_interacting_with_user}')
if self.activity.is_interacting_with_user: return
self.animation_start = 0
self.animation_end = 0
if self.activity.is_sleeping:
pass
def action_loop(self):
if self.activity.is_interacting_with_user:
self.is_busy = True
return
if not self.activity.is_interacting_with_user and self.is_busy:
self.update_position()
self.is_busy = False
self.activity.set_idle()
self.x_postion += 3
self.draw(self.frames.idle_1)
self.move(self.x_postion, self.y_postion)
self.update_position()
def update_position(self):
self.x_postion = self.pos().x()
self.y_postion = self.pos().y()
print(self.x_postion, self.y_postion)
def choose_walk_destination(self):
"""Decide, where the VPet should move to"""

View File

@ -1,66 +1,73 @@
#!/bin/python3
import time
from time import sleep
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt, QTimer
from screeninfo import get_monitors
from transparent_widget import TransparentGLWidget
from vpet import Rotate
from vpet import VPet
def get_primary_monitor():
return next((monitor for monitor in get_monitors() if monitor.is_primary), None)
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
def __init__(self):
super().__init__()
self.interval = 60
self.primary_monitor = get_primary_monitor()
# 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.primary_monitor,
x=int(self.primary_monitor.width / 2),
y=self.primary_monitor.height)
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.interval)
self.loop_timer.timeout.connect(self.loop)
self.loop_timer.start()
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 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')
else:
if event.button() == Qt.RightButton:
print('Click long right')
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
self.click_event_time = 0
self.v_pet.activity.is_interacting_with_user = False
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
delta = event.globalPos() - self.drag_position
self.move(self.pos() + delta)
self.drag_position = event.globalPos()
self.click_event_time = 0
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 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_()
def loop(self):
self.v_pet.action_loop()
self.show()