add screen detection
This commit is contained in:
parent
4535d43dfe
commit
a66a2e8e97
7
main.py
7
main.py
@ -0,0 +1,7 @@
|
|||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from window_qt import MainWindow
|
||||||
|
|
||||||
|
|
||||||
|
app = QApplication([])
|
||||||
|
window = MainWindow()
|
||||||
|
app.exec_()
|
||||||
@ -1,4 +1,5 @@
|
|||||||
|
screeninfo
|
||||||
PyOpenGL
|
PyOpenGL
|
||||||
PyGObject-stubs
|
|
||||||
PyQt5
|
PyQt5
|
||||||
|
PyGObject-stubs
|
||||||
PyQt5-stubs
|
PyQt5-stubs
|
||||||
23
vpet.py
23
vpet.py
@ -122,15 +122,15 @@ class Activity:
|
|||||||
|
|
||||||
|
|
||||||
class VPet:
|
class VPet:
|
||||||
def __init__(self, move, pos, draw, x=0, y=100, screen=1):
|
def __init__(self, move, pos, draw, monitor, x=0, y=0,):
|
||||||
self.screen = screen
|
self.monitor = monitor
|
||||||
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.p = 0
|
self.is_busy = False
|
||||||
|
|
||||||
self.move = move
|
self.move = move
|
||||||
self.draw = draw
|
self.draw = draw
|
||||||
@ -138,17 +138,24 @@ class VPet:
|
|||||||
self.activity = Activity()
|
self.activity = Activity()
|
||||||
|
|
||||||
def action_loop(self):
|
def action_loop(self):
|
||||||
# print(f'Interacting with user: {self.activity.is_interacting_with_user}')
|
if self.activity.is_interacting_with_user:
|
||||||
self.update_position()
|
self.is_busy = True
|
||||||
print(self.x_postion, self.y_postion)
|
return
|
||||||
if self.activity.is_interacting_with_user: return
|
|
||||||
self.x_postion = self.pos().x() + 3
|
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.draw(self.frames.idle_1)
|
||||||
self.move(self.x_postion, self.y_postion)
|
self.move(self.x_postion, self.y_postion)
|
||||||
|
self.update_position()
|
||||||
|
|
||||||
def update_position(self):
|
def update_position(self):
|
||||||
self.x_postion = self.pos().x()
|
self.x_postion = self.pos().x()
|
||||||
self.y_postion = self.pos().y()
|
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"""
|
||||||
|
|||||||
30
window_qt.py
30
window_qt.py
@ -1,26 +1,33 @@
|
|||||||
#!/bin/python3
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
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():
|
||||||
|
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):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.FPS = 60
|
self.FPS = 60
|
||||||
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
self.primary_monitor = get_primary_monitor()
|
||||||
# self.setWindowFlags(Qt.WindowStaysOnTopHint)
|
# self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
||||||
self.setAttribute(Qt.WA_TranslucentBackground)
|
self.setWindowFlags(Qt.WindowStaysOnTopHint)
|
||||||
|
# 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.pos, self.draw)
|
|
||||||
|
|
||||||
self.loop_timer = QTimer(self)
|
self.loop_timer = QTimer(self)
|
||||||
self.loop_timer.setSingleShot(False)
|
self.loop_timer.setSingleShot(False)
|
||||||
self.loop_timer.setInterval(self.FPS)
|
self.loop_timer.setInterval(self.FPS)
|
||||||
@ -62,8 +69,3 @@ class MainWindow(QMainWindow):
|
|||||||
def loop(self):
|
def loop(self):
|
||||||
self.v_pet.action_loop()
|
self.v_pet.action_loop()
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
app = QApplication([])
|
|
||||||
window = MainWindow()
|
|
||||||
app.exec_()
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user