首页 > 分享 > linux桌面宠物

linux桌面宠物

环境:

ubuntu19.10

xfce4

步骤如下:

python getpet.py(获取宠物动作图片)

然后会弹出来一个对话框,对话框里面你看中哪个宠物就用鼠标双击一下,然后终端就会开始下载这个宠物的图片

python start.py(启动桌面宠物)

小技巧:

可以把你下载的宠物给备份起来,以后就不用重复下载啦.

效果:

目前宠物总是喜欢待在最下面,脚本还需要改进啊.

#------------------------------------------------附录--------------------------------------------------------------------------------------

getpet.py

import sys

from PyQt5.QtWidgets import *

from PyQt5.QtGui import *

from PyQt5.QtCore import *

import requests

import threading

import os

import zipfile

from PIL import Image

class Workchange(QThread):

"""docstring for WorkThread"""

change_done = pyqtSignal()

def __init__(self):

super(Workchange, self).__init__()

def run(self):

url = self.url

name = url.split('/')[-1] + '.zip'

print('正在下载资源',name)

data = requests.get(url).content

with open(name,'wb') as f:

f.write(data)

print('下载完成!')

path="./"

if not os.path.exists(path):

os.makedirs(path)

print('正在解压资源...')

z = zipfile.ZipFile(name, 'r')

z.extractall(path=path)

z.close()

for i in range(1,47):

os.rename(path + 'shime%s.png'% str(i),path+str(i)+'.png')

pri_image = Image.open(path+'%s.png' %str(i))

pri_image.transpose(Image.FLIP_LEFT_RIGHT).save(path+'-%s.png'%str(i))

for i in os.listdir(path):

os.system('convert %s %s'%(path+i,path+i))

print('解压完成')

os.remove(name)

self.change_done.emit()

class Workinit(QThread):

"""docstring for WorkThread"""

init_done = pyqtSignal(dict)

def __init__(self):

super(Workinit, self).__init__()

def run(self):

for i in range(3,90):

threading.Thread(target=self.load,args=(i,)).start()

def load(self,i):

url = ''' http://pepeswap.com/thumb/%s''' %str(i)

data = requests.get(url).content

name = str(i)

dict_data = dict(data=data,name=name)

self.init_done.emit(dict_data)

class DQListWidget(QListWidget):

def __init__(self):

super(DQListWidget, self).__init__()

self.workinit = Workinit()

self.workchange = Workchange()

self.workchange.change_done.connect(self.change_done)

self.workinit.init_done.connect(self.load_picture)

self.workinit.start()

self.itemDoubleClicked.connect(self.change)

def change_done(self):

QMessageBox.about(self,'提示','更换完成!(*>﹏<*)')

def change(self,item):

self.workchange.url = 'http://pepeswap.com/mascot/' + item.text()

self.workchange.start()

def load_picture(self,dict_data):

item = QListWidgetItem(dict_data['name'])

item.setSizeHint(QSize(10, 128))

self.addItem(item)

pixmap = QPixmap()

label = QLabel()

pixmap.loadFromData(dict_data['data'])

label.setPixmap(pixmap)

self.setItemWidget(item,label)

class Mywin(QWidget):

def __init__(self):

super(Mywin, self).__init__()

list_ = DQListWidget()

layout = QVBoxLayout(self)

layout.addWidget(list_)

self.setLayout(layout)

app = QApplication(sys.argv)

mywin = Mywin()

mywin.setWindowTitle('Hello world!')

mywin.show()

sys.exit(app.exec())

start.py

import sys

from PyQt5.QtWidgets import *

from PyQt5.QtGui import *

from PyQt5.QtCore import *

import time

import random

import os

def random_probability(r):

s = random.randint(1,100)

if r >= s:

return True

else:

return False

class Donghua(QWidget):

def __init__(self):

super(Donghua, self).__init__()

self.desktop = QApplication.desktop()

self.screenRect = self.desktop.screenGeometry()

self.HEIGHT = self.screenRect.height()

self.WIDTH = self.screenRect.width()

self.setWindowFlags(Qt.FramelessWindowHint)

self.setAttribute(Qt.WA_TranslucentBackground)

self.timer = QTimer()

self.timer.timeout.connect(self.update)

self.img_timer = QTimer()

self.img_timer.timeout.connect(self.update_img)

self.label = QLabel(self)

self.label.setScaledContents(True)

layout = QVBoxLayout(self)

layout.addWidget(self.label)

self.setLayout(layout)

self.index = 0

self.x = 0

self.is_right = True

self.m_flag = False

self.action_dcit = {

'left_go':(1,3),

'right_go':(-3,-1),

'left_hold':(5,7),

'right_hold':(-7,-5),

'left_release':(4,4),

'right_release':(-4,-4),

'left_down':(18,19),

'right_down':(-19,-18),

'left_crawl':(12,14),

'right_crawl':(-14,-12),

'left_rest':(26,27),

'right_rest':(-27,-26),

'left_rest2':(27,29),

'right_rest2':(-29,-27),

}

self.action = 'right_release'

self.pre_action = ''

self.timer.start(100)

self.img_timer.start(200)

def mousePressEvent(self, event):

x = (event.globalPos()-self.pos()).x()

y = (event.globalPos()-self.pos()).y()

if event.button() == Qt.LeftButton and x < 128 and y < 128:

self.m_flag = True

self.m_Position = event.globalPos()-self.pos()

event.accept()

if self.is_right:

self.action='right_hold'

else:

self.action='left_hold'

self.setCursor(QCursor(Qt.OpenHandCursor))

def mouseMoveEvent(self, QMouseEvent):

if Qt.LeftButton and self.m_flag:

self.move(QMouseEvent.globalPos()-self.m_Position)

QMouseEvent.accept()

def mouseReleaseEvent(self, QMouseEvent):

self.m_flag = False

if self.is_right:

self.action = 'right_release'

else:

self.action = 'left_release'

if self.x <= 0 and self.y > 0:

self.action = 'left_crawl'

elif self.x + self.width >= self.WIDTH and self.y > 0:

self.action = 'right_crawl'

self.setCursor(QCursor(Qt.ArrowCursor))

def update(self):

self.width = self.geometry().width()

self.height = self.geometry().height()

self.x = self.geometry().x()

self.y = self.geometry().y()

exec('self.%s()'% self.action)

def right_crawl(self):

if self.y > 0:

self.y -= 10

self.setGeometry(self.x,self.y,100,100)

else:

self.action = 'right_release'

def left_crawl(self):

if self.y > 0:

self.y -= 10

self.setGeometry(self.x,self.y,100,100)

else:

self.action = 'left_release'

def right_down(self):

if self.index+1 == self.action_dcit[self.action][1]:

self.action = 'right_go'

def left_down(self):

if self.index+1 == self.action_dcit[self.action][1]:

self.action = 'left_go'

def right_release(self):

if self.y + self.height > self.HEIGHT:

self.action = 'right_down'

else:

self.action = 'right_release'

self.y += 100

self.setGeometry(self.x,self.y,100,100)

def left_release(self):

if self.y + self.height > self.HEIGHT:

self.action = 'left_down'

else:

self.action = 'left_release'

self.y += 100

self.setGeometry(self.x,self.y,100,100)

def right_go(self):

self.x += 5

self.action = 'right_go'

if self.x + self.width> self.WIDTH:

if random_probability(30):

self.action = 'right_crawl'

else:

self.is_right = False

self.action = 'left_go'

if random_probability(1):

self.action = 'right_rest'

self.setGeometry(self.x,self.y,100,100)

def left_go(self):

self.x -= 5

self.action = 'left_go'

if self.x < 0:

if random_probability(30):

self.action = 'left_crawl'

else:

self.is_right = True

self.action = 'right_go'

if random_probability(1):

self.action = 'left_rest'

self.setGeometry(self.x,self.y,100,100)

def right_rest(self):

if random_probability(1):

self.action = 'right_go'

def left_rest(self):

if random_probability(1):

self.action = 'left_go'

def right_hold(self):

pass

def left_hold(self):

pass

def update_img(self):

start_index,end_index = self.action_dcit[self.action]

if self.pre_action != self.action:

self.index = start_index

self.pre_action = self.action

if self.index == end_index:

self.index = start_index

else:

self.index += 1

q = QPixmap(path +'%s.png' % self.index)

self.label.setPixmap(q)

if __name__ == '__main__':

path = "./"

app = QApplication(sys.argv)

mywin = Donghua()

mywin.show()

sys.exit(app.exec())

相关知识

Linux学习教程
ANeko桌面宠物
kali linux 2.0 web 渗透测试 电子书
QQ宠物桌面是怎么开发的
python如何制作桌面宠物
面对电脑的时间有点多,求桌面宠物
Linux 常用命令(持续补充)
Linux busybox mount
linux基本命令练习
桌面宠物软件下载指南?最受欢迎的桌面宠物软件排行榜

网址: linux桌面宠物 https://m.mcbbbk.com/newsview780171.html

所属分类:萌宠日常
上一篇: 多多桌面宠物app安卓最新版下载
下一篇: 桌面宠物下载大全免费