Compare commits

..

No commits in common. "develop" and "main" have entirely different histories.

4 changed files with 57 additions and 95 deletions

View File

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

View File

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

35
vpet.py
View File

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

View File

@ -1,73 +1,66 @@
import time #!/bin/python3
from time import sleep
import time
from PyQt5.QtWidgets import QMainWindow from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt, QTimer from PyQt5.QtCore import Qt, QTimer
from screeninfo import get_monitors
from transparent_widget import TransparentGLWidget from transparent_widget import TransparentGLWidget
from vpet import Rotate from vpet import Rotate
from vpet import VPet from vpet import VPet
def get_primary_monitor():
return next((monitor for monitor in get_monitors() if monitor.is_primary), None)
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.interval = 60 self.FPS = 60
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.loop_timer = QTimer(self) self.v_pet = VPet(self.move, self.pos, self.draw)
self.loop_timer.setSingleShot(False)
self.loop_timer.setInterval(self.interval)
self.loop_timer.timeout.connect(self.loop)
self.loop_timer.start()
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.FPS)
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')
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) self.click_event_time = 0
self.resize(img.width, img.height) if event.buttons() == Qt.LeftButton:
self.setCentralWidget(TransparentGLWidget(img)) delta = event.globalPos() - self.drag_position
self.move(self.pos() + delta)
self.drag_position = event.globalPos()
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()
app = QApplication([])
window = MainWindow()
app.exec_()