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
PyQt5
PyGObject-stubs
PyQt5
PyQt5-stubs

35
vpet.py
View File

@ -65,7 +65,6 @@ 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
@ -75,7 +74,6 @@ 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
@ -83,7 +81,6 @@ 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
@ -91,14 +88,12 @@ 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
@ -111,7 +106,6 @@ 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
@ -122,43 +116,26 @@ class Activity:
class VPet:
def __init__(self, move, pos, draw, monitor, x=0, y=0,):
self.monitor = monitor
def __init__(self, move, pos, draw, x=0, y=0, screen=1):
self.screen = screen
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()
self.animation_start = 0
self.animation_end = 0
def action_loop(self):
if self.activity.is_interacting_with_user:
self.is_busy = True
return
print(f'Interacting with user: {self.activity.is_interacting_with_user}')
if self.activity.is_interacting_with_user: 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)
if self.activity.is_sleeping:
pass
def choose_walk_destination(self):
"""Decide, where the VPet should move to"""

View File

@ -1,73 +1,66 @@
import time
from time import sleep
#!/bin/python3
import time
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.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)
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.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.v_pet = VPet(self.move, self.pos, self.draw)
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()
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 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 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()
self.click_event_time = 0
self.v_pet.activity.is_interacting_with_user = False
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')
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
self.click_event_time = 0
self.v_pet.activity.is_interacting_with_user = False
def draw(self, img):
img = img.rotate(Rotate.up)
self.resize(img.width, img.height)
self.setCentralWidget(TransparentGLWidget(img))
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 loop(self):
self.v_pet.action_loop()
self.show()
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_()