Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
新增保存壁纸功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ambition_echo committed Jul 29, 2022
1 parent 34283c3 commit ad9d61a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
12 changes: 6 additions & 6 deletions scripts/0.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
# 下载图像
def download(url, path):
img = requests.get(url)
with open(path, "wb") as fwi:
with open("/tmp/0.png", "wb") as fwi:
fwi.write(img.content)


# 填充黑色适配屏幕尺寸
def fill_img(path):
def fill_img(download_path):
global X, Y # 屏幕分辨率
height = int(500.0 / (float(SIZE) * 0.01))
width = int(height * (float(X) / float(Y)))
img = Image.open(path)
img = Image.open(download_path)
new_img = Image.new(img.mode, (width, height), color='black')
new_img.paste(img, (int(width / 2 - 250), int(height / 2 - 250)))
today = datetime.datetime.utcnow()
name = today.strftime("%Y%m%d%H%M%s")
new_img.save(path[:-4] + name + ".png")
set_wallpaper(path[:-4] + name + ".png")
new_img.save(path + name + ".png")
set_wallpaper(path + name + ".png")


def get_time_path():
Expand All @@ -54,7 +54,7 @@ def main():

# name = "00_0_0.png"
download(url, path + name)
fill_img(path + name)
fill_img("/tmp/0.png")


if __name__ == '__main__':
Expand Down
31 changes: 28 additions & 3 deletions src/trayicon.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "trayicon.h"
#include "config.h"
#include "src/thread.h"
#include "thread.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include <QScreen>
#include <QStandardPaths>
#include <qaction.h>

TrayIcon::TrayIcon(QSystemTrayIcon *parent)
{
Expand All @@ -33,6 +33,8 @@ void TrayIcon::initConnect()
connect(this->config, &QAction::triggered, this, &TrayIcon::showConfigPage);
//刷新壁纸
connect(this->refresh, &QAction::triggered, this, &TrayIcon::handle);
//保存壁纸
connect(this->save, &QAction::triggered, this, &TrayIcon::saveCurrentImg);
//定时器
connect(&this->timer, &QTimer::timeout, this, &TrayIcon::handle);
}
Expand All @@ -44,12 +46,16 @@ void TrayIcon::initTrayIcon()
config = new QAction();
exit = new QAction();
refresh = new QAction();
save = new QAction();

config->setText("设置");
refresh->setText("更新壁纸");
save->setText("保存当前壁纸");
exit->setText("退出");

trayIconMenu->addAction(config);
trayIconMenu->addAction(save);
trayIconMenu->addAction(refresh);
trayIconMenu->addAction(config);
trayIconMenu->addAction(exit);

this->setContextMenu(trayIconMenu);
Expand Down Expand Up @@ -112,4 +118,23 @@ void TrayIcon::handle()
Thread *thread = new Thread(command);
thread->start();
timer.start(60000 * settings->value("APP/updateTime").toInt());
}
void TrayIcon::saveCurrentImg()
{
QString dirpath = "/tmp/earth-wallpaper";
QDir dir(dirpath);
QStringList nameFilters;
nameFilters << "[1-9]*";
dir.setNameFilters(nameFilters);
QStringList files = dir.entryList(QDir::Files, QDir::Name);
QString picturePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/earth-wallpaper";
if (!QDir(picturePath).exists())
{
QDir(picturePath).mkpath(picturePath);
}
QFile target = QFile("/tmp/earth-wallpaper/" + files[files.count() - 1]);
if (target.copy(picturePath + "/" + files[files.count() - 1]))
{
QMessageBox::information(nullptr, "保存", "保存成功!", QMessageBox::Yes);
}
}
3 changes: 3 additions & 0 deletions src/trayicon.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QSettings>
#include <QSystemTrayIcon>
#include <QTimer>
#include <qaction.h>

class TrayIcon : public QSystemTrayIcon
{
Expand All @@ -20,6 +21,7 @@ class TrayIcon : public QSystemTrayIcon
QAction *config;
QAction *exit;
QAction *refresh;
QAction *save;
explicit TrayIcon(QSystemTrayIcon *parent = nullptr);
~TrayIcon() override;

Expand All @@ -30,4 +32,5 @@ class TrayIcon : public QSystemTrayIcon
void checkConfig(); //检查配置文件
void reloadSettings(); //启动线程
void handle();
void saveCurrentImg();
};

0 comments on commit ad9d61a

Please sign in to comment.