add screen detection

This commit is contained in:
DasMoorhuhn 2024-12-13 00:49:04 +01:00
parent 4535d43dfe
commit a66a2e8e97
4 changed files with 42 additions and 25 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
PyGObject-stubs
PyQt5-stubs

23
vpet.py
View File

@ -122,15 +122,15 @@ class Activity:
class VPet:
def __init__(self, move, pos, draw, x=0, y=100, 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.p = 0
self.is_busy = False
self.move = move
self.draw = draw
@ -138,17 +138,24 @@ class VPet:
self.activity = Activity()
def action_loop(self):
# print(f'Interacting with user: {self.activity.is_interacting_with_user}')
self.update_position()
print(self.x_postion, self.y_postion)
if self.activity.is_interacting_with_user: return
self.x_postion = self.pos().x() + 3
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,26 +1,33 @@
#!/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():
m = 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):
def __init__(self):
super().__init__()
self.FPS = 60
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
# self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
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.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.loop_timer.setSingleShot(False)
self.loop_timer.setInterval(self.FPS)
@ -62,8 +69,3 @@ class MainWindow(QMainWindow):
def loop(self):
self.v_pet.action_loop()
self.show()
app = QApplication([])
window = MainWindow()
app.exec_()