Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a4edf66ed | |||
| a66a2e8e97 | |||
| 4535d43dfe | |||
| 3e8e04c5fa | |||
| 3a1c63f4ce |
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
|
||||||
37
vpet.py
37
vpet.py
@ -65,6 +65,7 @@ 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
|
||||||
@ -74,6 +75,7 @@ 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
|
||||||
@ -81,6 +83,7 @@ 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
|
||||||
@ -88,12 +91,14 @@ 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
|
||||||
@ -106,6 +111,7 @@ 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
|
||||||
@ -116,26 +122,43 @@ class Activity:
|
|||||||
|
|
||||||
|
|
||||||
class VPet:
|
class VPet:
|
||||||
def __init__(self, move, pos, draw, x=0, y=0, 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.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()
|
||||||
|
|
||||||
def action_loop(self):
|
self.animation_start = 0
|
||||||
print(f'Interacting with user: {self.activity.is_interacting_with_user}')
|
self.animation_end = 0
|
||||||
if self.activity.is_interacting_with_user: return
|
|
||||||
|
|
||||||
if self.activity.is_sleeping:
|
def action_loop(self):
|
||||||
pass
|
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):
|
def choose_walk_destination(self):
|
||||||
"""Decide, where the VPet should move to"""
|
"""Decide, where the VPet should move to"""
|
||||||
|
|||||||
105
window_qt.py
105
window_qt.py
@ -1,66 +1,73 @@
|
|||||||
#!/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():
|
||||||
|
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.FPS = 60
|
self.interval = 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.click_event_time = 0
|
# 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)
|
def mousePressEvent(self, event):
|
||||||
self.loop_timer.setSingleShot(False)
|
self.click_event_time = time.time()
|
||||||
self.loop_timer.setInterval(self.FPS)
|
self.v_pet.activity.set_interacting_with_user()
|
||||||
self.loop_timer.timeout.connect(self.loop)
|
if event.button() == Qt.LeftButton:
|
||||||
self.loop_timer.start()
|
self.drag_position = event.globalPos()
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
self.click_event_time = time.time()
|
time_delta = time.time() - self.click_event_time
|
||||||
self.v_pet.activity.set_interacting_with_user()
|
if time_delta <= 0.2:
|
||||||
if event.button() == Qt.LeftButton:
|
if event.button() == Qt.LeftButton:
|
||||||
self.drag_position = event.globalPos()
|
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):
|
self.click_event_time = 0
|
||||||
time_delta = time.time() - self.click_event_time
|
self.v_pet.activity.is_interacting_with_user = False
|
||||||
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
|
def mouseMoveEvent(self, event):
|
||||||
self.v_pet.activity.is_interacting_with_user = False
|
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):
|
def draw(self, img):
|
||||||
self.click_event_time = 0
|
img = img.rotate(Rotate.up)
|
||||||
if event.buttons() == Qt.LeftButton:
|
self.resize(img.width, img.height)
|
||||||
delta = event.globalPos() - self.drag_position
|
self.setCentralWidget(TransparentGLWidget(img))
|
||||||
self.move(self.pos() + delta)
|
|
||||||
self.drag_position = event.globalPos()
|
|
||||||
|
|
||||||
def draw(self, img):
|
def loop(self):
|
||||||
img = img.rotate(Rotate.up)
|
self.v_pet.action_loop()
|
||||||
self.resize(img.width, img.height)
|
self.show()
|
||||||
self.setCentralWidget(TransparentGLWidget(img))
|
|
||||||
|
|
||||||
def loop(self):
|
|
||||||
self.v_pet.action_loop()
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
|
|
||||||
app = QApplication([])
|
|
||||||
window = MainWindow()
|
|
||||||
app.exec_()
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user