首页 > 编程语言 >The Table Pet for the python <--CSDN @PythonWIN-->

The Table Pet for the python <--CSDN @PythonWIN-->

时间:2024-06-09 19:58:21浏览次数:16  
标签:-- os self pet python Pet action path config

-  This is a small software based on pyQT5:

        -We have used the well-known Python language

-I am currently developing desktop pet SVIP version 1.1 and using Python as my editor.

Now let me explain in detail its functions:

        -First,Animation drag and GIF animation playback

        -Second,custom right-click menus can be modified by modifying the menu in config, and scripts can also be customized to simplify computer usage

        -Third, customize the bug catching style by simply changing the pet folder and the GIF icon below to achieve the replacement of the bug catching style

        -----Follow me for Chinese version(关注我,查看中文版)

--------------------------------------------------------------------------------------

 About Right Click Menu Settings:

        -The context menu can be customized by editing the menu_config.json file under the config folder to dynamically modify the content of the context menu. 

                                        

                        ​​​​​​​        ​​​​​​​        ​​​​​​​                

-After this change, only the content is changed, to realize the corresponding function you need to create the corresponding script in the bat folder.

{
    "主菜单": [
        {
            "name": "GPT-academic",
            "type": "subprocess.Popen",# 可选type类型:subprocess.run、subprocess.Popen、webbrowser(打开浏览器)
            "params": [
                "powershell",
                "-ExecutionPolicy",
                "Bypass",
                "-File",
                ".\\bat\\academic.ps1"
            ]
        },
		......
    ],
    "子菜单的名称": [
        {
            "name": "子菜单的名称",
            "type": "使用何种方式打开",
            "params": "参数"
        },
        {#示例 在浏览器中打开网站http://localhost:5244/
            "name": "我要看Alist",
            "type": "webbrowser",
            "params": "http://localhost:5244/"
        }
    ]
    ......
}


-This is an example of a bat script, usually subprocess.run.

@echo off
start "" "D:\Qingfeng\HeyboxAccelerator\heyboxacc.exe"
start "" "D:\Program Files (x86)\Tencent\TIM\Bin\QQScLauncher.exe"
start "" "D:\Program Files\Steam++\Steam++.exe"

- This is a sample powershell script that generally uses subprocess.Popen

Start-Process "D:\sunshine\Sunshine\SunShine.exe" -WorkingDirectory "D:\sunshine\Sunshine"
Start-Process "C:\Program Files\Oray\SunLogin\SunloginClient\SunloginClient.exe"
Start-Process "C:\Program Files\Tailscale\tailscale-ipn.exe"

 -You don't need to configure the script file to open the web page, just modify it directly in the configuration file above

--------------------------------------------------------------------------------------

Custom Styles

-This is the format of the desktop pet styles folder.

        -The init file under the pet file holds the desk pet initialization gif file, the file names in           this must conform to the following rules

                -move.gif is the styleof the table favor when it is dragged.

                -start.gif is the style when the favorite is just started.

                -stay.gif is the style after the pet has been dragged.

-Then the other gif files below the pet folder are the table favor random play files, which don't need to change their names.

-Just follow the rules above when replacing them.

        ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        

--------------------------------------------------------------------------------------

Features planned to be added.

        -Adding Mobile Functionality

        -Access to large language modeling conversations

        -Voice dialog, voice wakeup

        -Access to agent framework for autonomous dialog and mobility?

        -Interact with mouse?

--------------------------------------------------------------------------------------

Not much bullshit! Put on the program:

class DemoWin(QMainWindow):
    def __init__(self):
        super(DemoWin, self).__init__()
        # 初始化宠物
        self.select_pet = 'pet'
        self.select_music=''
        self.pet = []
        for i in os.listdir(os.path.abspath(self.select_pet)):
            self.pet.append(os.path.join(os.path.abspath(self.select_pet), i))
        self.pet.remove(os.path.join(os.path.abspath(self.select_pet), 'init'))
        # 初始化窗口
        self.initUI()
        # 初始化,不规则窗口
        # 将窗口设置为无边框、总在最前,并且作为子窗口使用
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.SubWindow)
        # 禁用了窗口的自动背景填充
        self.setAutoFillBackground(False)
        # 将窗口背景设置为透明
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        # 重新绘制窗口,以便上述设置立即生效
        self.repaint()
        # 是否跟随鼠标
        self.is_follow_mouse = False
        # 桌面宠物的坐标
        self.w = 1550
        self.h = 949
        # 设置桌面宠物的初始位置
        self.move(self.w, self.h)
        # 宠物是否飞行
        self.is_flying = None

        # 设置托盘选项
        iconpath = "./mypetico.ico"
        # 右键菜单
        quit_action = QAction(u'退出', self, triggered=self.quit)
        quit_action.setIcon(QIcon(iconpath))
        self.tray_icon_menu = QMenu(self)
        self.tray_icon_menu.addAction(quit_action)

        self.tray_icon = QSystemTrayIcon(self)
        self.tray_icon.setIcon(QIcon(iconpath))
        self.tray_icon.setContextMenu(self.tray_icon_menu)

        self.tray_icon.show()

        # 窗口透明程度
        self.setWindowOpacity(1)
        # 改变宠物样式
        self.change_pet = ''
        self.change_music = ''
        # 每隔一段时间做个动作
        self.timer = QTimer()
        self.timer.timeout.connect(self.randomAct)
        self.timer.start(1000)
        self.condition = 0
        self.talk_condition = 0


        # 默认动作为随机1, 飞翔动作为2 左右运动3
        self.action = 1
    '''随即桌宠皮肤'''
    def sent_pet(self, pet):
        self.pet = []
        for i in os.listdir(os.path.abspath(self.change_pet)):
            self.pet.append(os.path.join(os.path.abspath(self.change_pet), i))
        self.pet.remove(os.path.join(os.path.abspath(self.change_pet), 'init'))
        pass
    def music(self,music):
        print('music_do')
        QSound.play('music/轻音乐/'+music)

#老师就是这个上面这个music函数调用它的时候它不播放音乐。
    def initUI(self):
        # 将窗口设置为动图大小
        self.resize(400, 400)
        self.label1 = QLabel("", self)
        self.label1.setStyleSheet("font:15pt '楷体';border-width: 1px;color:blue;")  # 设置边框
        # 使用label来显示动画
        self.label = QLabel("", self)
        # label大小设置为动画大小
        self.label.setFixedSize(200, 200)
        self.Action(os.path.join(os.path.abspath(self.select_pet), "init/start.gif"))
        self.setWindowTitle("myPet")

    def playSound(self):
        QSound.play("chicken.wav")
        print('playsound_play')



    '''鼠标左键按下时, 宠物将和鼠标位置绑定'''

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.is_follow_mouse = True
            self.mouse_drag_pos = event.globalPos() - self.pos()
            event.accept()
            self.setCursor(QCursor(Qt.ClosedHandCursor))
            self.Action(os.path.join(os.path.abspath(self.select_pet), "init/move.gif"))

    '''鼠标移动, 则宠物也移动'''

    def mouseMoveEvent(self, event):
        if Qt.LeftButton and self.is_follow_mouse:
            self.move(event.globalPos() - self.mouse_drag_pos)
            event.accept()
            xy = self.pos()
            self.w, self.h = xy.x(), xy.y()
            pass

    '''鼠标释放时, 取消绑定'''

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.RightButton:
            return
        self.Action(os.path.join(os.path.abspath(self.select_pet), "init/touch.gif"))
        self.is_follow_mouse = False
        self.setCursor(Qt.OpenHandCursor)
        self.playSound()

    '''接触宠物的时候调用'''

    def enterEvent(self, event):  # 鼠标移进时调用
        # print('鼠标移入')
        self.Action(os.path.join(os.path.abspath(self.select_pet), "init/touch.gif"))
        self.setCursor(Qt.OpenHandCursor)

    def mouseDoubleClickEvent(self, event):
        print("鸡叫")
        self.playSound()

    def execute_action(self, action_config):
        #print(action_config)

        if action_config['type'] == 'subprocess.run':
            subprocess.run(action_config['params'], shell=True)
        elif action_config['type'] == 'webbrowser':
            webbrowser.open(action_config['params'])
        elif action_config['type'] == 'subprocess.Popen':
            subprocess.Popen(action_config['params'], creationflags=subprocess.CREATE_NEW_CONSOLE)
        elif action_config['type'] == 'pet':
            self.change_pet = action_config['params'][0]
            self.sent_pet(self.change_pet)
            self.select_pet = self.change_pet
        elif action_config['type'] == 'music':
            print('music_down')
            self.change_music = action_config['params'][0]
            print(self.change_music)
            self.music(self.change_music)
            #self.playSound()


    def contextMenuEvent(self, event):
        menus = []
        actions = []
        action_configs = []
        # 读取配置文件
        try:
            with open("./config/menu_config.json", "r", encoding="utf-8") as config:
                menu_config = json.load(config)
        except Exception as e:
            print(e)
            return

        # 获取子菜单项
        for menu in menu_config:
            # print(menu)
            menus.append(QMenu(str(menu), self))
            # 获取action
            for action_config in menu_config[menu]:
                # print(action_config)
                action_configs.append(action_config)
                actions.append(menus[-1].addAction(action_config["name"]))

        for i, menu in enumerate(menus):
            if i == 0:
                continue
            menus[0].addMenu(menu)

        quitAction = menus[0].addAction("退出")
        action = menus[0].exec_(self.mapToGlobal(event.pos()))

        if action in actions:
            self.execute_action(action_configs[actions.index(action)])

        if action == quitAction:
            qApp.quit()

    '''退出程序'''

    def quit(self):
        self.close()
        sys.exit()

    def Action(self, action):
        # 设置动画路径
        self.movie = QMovie(action)
        # 宠物大小
        self.movie.setScaledSize(QSize(200, 200))
        # 将动画添加到label中
        self.label.setMovie(self.movie)
        # 开始播放动画
        self.movie.start()

    '''随机做一个动作'''

    def randomAct(self):
        # 检测是否飞行
        if self.h != 949:
            self.playSound()
            self.is_flying = True
            self.action = 2
        else:
            self.is_flying = False
            self.action = 1

        if self.action == 1:
            if not self.condition:
                print("状态变更")
                a = random.choice(self.pet)
                print(a)
                self.Action(a)
                self.condition = 1
            else:
                print("状态还原")
                self.Action(os.path.join(os.path.abspath(self.select_pet), "init/stay.gif"))
                self.condition = 0
            self.timer.start(random.randint(10, 30) * 100)
        elif self.action == 2:
            # 实现行进效果
            if True:
                # 飞行效果
                if self.is_flying:
                    if self.h > 950:
                        self.h = 0
                    elif self.h > 940:
                        self.h += 1
                    else:
                        self.h += 10

                self.move(self.w, self.h)
                self.timer.start(random.randint(10, 30) * 100)
        elif self.action == 3:
            # self.w
            self.move(self.w, self.h)
            self.timer.start(random.randint(10, 30) * 10)

This is all the program!!!

--------------------------------------------------------------------------------------

If you want the full program.

        -Please add my QQ or WeChat:
                My QQ is '2693803445'
                My WeChat is 'creategreater'

        

标签:--,os,self,pet,python,Pet,action,path,config
From: https://blog.csdn.net/PythonWIM/article/details/139549367

相关文章

  • Django API开发实战:前后端分离、Restful风格与DRF序列化器详解
    系列文章目录Django入门全攻略:从零搭建你的第一个Web项目DjangoORM入门指南:从概念到实践,掌握模型创建、迁移与视图操作DjangoORM实战:模型字段与元选项配置,以及链式过滤与QF查询详解DjangoORM深度游:探索多对一、一对一与多对多数据关系的奥秘与实践跨域问题与Django解决......
  • 鸿蒙创意开发2.0
    #鸿蒙期末作业#补救,基于鸿蒙开发的鸿蒙创意软件的外观已经完善了,由于上一篇内容质量太低,这期作者尽量把重点解说一下。本次开发创意型计算器1.创建一个计算器按钮先上代码://如果只有一个component显示不了,声明预览@Preview//因为没有设置高宽所以组件就一点//声明组件@......
  • 拿捏红黑树(C++)
    文章目录前言一、红黑树介绍二、插入操作三、验证红黑树四、红黑树与AVL性能比较与应用五、总体代码总结前言我们之前介绍了一种AVL的高阶数据结构,在本篇文章中,我们将会介绍一种与AVL旗鼓相当的数据结构–红黑树。我们并且会对它的部分接口进行模拟实现一、红黑树......
  • Kafka 主题 CLI 教程
    KafkaTopicsCLI,即kafka-topics用于创建、删除、描述或更改Kafka中的主题。请确保您已预先启动Kafka 如何创建Kafka主题?要创建Kafka主题,我们需要提供必需的参数:如果是Kafkav2.2+,请使用Kafka主机名和端口,例如,localhost:9092如果是旧版本的Kafka,请使用Zook......
  • 第三个计划表出炉
    2024年6月9号编写从2024年6月9号到2029年12月31号计划:1、2025年底必须结婚2、2026年考虑孩子的事3、2027年考虑是否要继续待北京4、2028年,如果27年工作不变,继续维持。如果有变动,尽量保持稳定5、2029年要考虑更多关于孩子的事理财计划:1、2024年年底全部撤出,至少目前主要账号成正......
  • BUUCTF爱因斯坦(杂项)
    开局一张图 顺手看了眼详细内容,果然  用010editor看了下应该是包含文件了,用binwalk试了下果然 binwalk-emisc2.jpg得到一个压缩包看了看010editor,也不是伪加密,暴力浅试了试也不对这个密码愣是没想到 行百里者半九十,最后把前面没用到的this_is_not_password输进......
  • python 字典是不是线程安全的
    Python字典(dict)对象本身不是线程安全的。在多线程环境下,对同一个字典对象的读写操作需要额外的同步机制来确保线程安全性。如果需要在多线程环境下使用线程安全的字典,可以使用collections.Counter对象,它是线程安全的,或者使用threading.local,它提供了线程局部存储的功能。另外......
  • 简单工厂模式( Simple Factory Pattern )
    简单工厂模式(SimpleFactoryPattern),在工厂类中对象决定创建出哪一种产品类的实例。这些产品类都实现了相同的接口,或者继承了相同的父类。结构图Factory(工厂角色):它是核心,负责实现创建所有实例的内部逻辑。在工厂类中,提供了一个静态方法,可以直接被外界直接调用,以创建具体产品......
  • 03-软件使用素材资源链接
    目录页1.设计类资源导航1.1.设计素材网站1.2.图形处理1.2.1.PPT图形素材1.3.影视动画1.设计类资源导航1.1.设计素材网站设计素材类免费下载网站名优缺点备注站长素材分享综合设计素材免费下载的平台(字体、音频、PPT、PSD素材)http://sc......
  • Redis的缓存穿透、击穿、雪崩及解决方案
    Redis的缓存穿透、击穿、雪崩是三个不同的缓存机制问题,在设计和使用Redis缓存系统时,我们需要考虑以下三种常见的问题:缓存穿透、缓存击穿和缓存雪崩。缓存穿透(CachePenetration)定义:缓存穿透:缓存穿透是指查询一个在缓存和数据库中都不存在的数据,用户不断发起这样的请求,由......