[Return]

Report a post

Preview
Had teh bot add the ability to drag her around, and right click to quit. I should have just added that from teh start, my bad. :sweat2:

Now imagine, if we have someone here dedicated enough at art to make a few animations, we could make a Heyuri-tan one!! We could have it so that she squirms around when we click and move her, and an animation of her eating a snack when you right click > feed. :nyaoo:

import sys
from PyQt5 import QtWidgets, QtGui, QtCore

class DesktopPet(QtWidgets.QLabel):
    def __init__(self, gif_path):
        super().__init__()

        # Load animated GIF
        self.movie = QtGui.QMovie(gif_path, QtCore.QByteArray(), self)
        self.setMovie(self.movie)
        self.movie.start()

        # Frameless, transparent, always on top
        self.setWindowFlags(
            QtCore.Qt.FramelessWindowHint |
            QtCore.Qt.WindowStaysOnTopHint |
            QtCore.Qt.SubWindow
        )
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)

        # Resize to GIF size
        self.resize(self.movie.currentPixmap().size())

        # Place bottom-right by default
        screen = QtWidgets.QApplication.primaryScreen().geometry()
        x = screen.width() - self.width() - 20
        y = screen.height() - self.height() - 50
        self.move(x, y)

        # For dragging
        self.dragging = False
        self.offset = QtCore.QPoint()

        # Build context menu
        self.menu = QtWidgets.QMenu()
        quit_action = self.menu.addAction("Quit")
        quit_action.triggered.connect(QtWidgets.qApp.quit)

    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.dragging = True
            self.offset = event.globalPos() - self.frameGeometry().topLeft()
        elif event.button() == QtCore.Qt.RightButton:
            self.menu.exec_(event.globalPos())

    def mouseMoveEvent(self, event):
        if self.dragging:
            self.move(event.globalPos() - self.offset)

    def mouseReleaseEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.dragging = False


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    pet = DesktopPet(sys.argv[1])
    pet.show()
    sys.exit(app.exec_())
Post number No.155570
Board Off-Topic@Heyuri
Optional. Describe what's wrong with it.