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

Commit

Permalink
refactor(src): 重写脚本定位方式
Browse files Browse the repository at this point in the history
根据脚本头部Info信息定位脚本

Author: ambition-echo
  • Loading branch information
ambition_echo committed Aug 7, 2022
1 parent e43b03a commit 759d269
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 85 deletions.
4 changes: 3 additions & 1 deletion scripts/6.py → scripts/24hourWallpaper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# source: 24h壁纸
# updateTime wallpaperFile
import os
import sys
import json
Expand All @@ -6,7 +8,7 @@
from sunCalculator import SunCalculator, DateTime
import requests

file = sys.argv[1]
file = sys.argv[5]
unpackDir = "/tmp/" + file.split("/")[-1].split(".")[0]


Expand Down
2 changes: 2 additions & 0 deletions scripts/2.py → scripts/Bing-rand.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# source: 必应壁纸(随机)
# updateTime
from setWallpaper import set_wallpaper
from checkWakkpaperDir import check
import requests
Expand Down
4 changes: 3 additions & 1 deletion scripts/3.py → scripts/Bing-tody.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# source: 必应壁纸(今日)
# updateTime
from setWallpaper import set_wallpaper
from checkWakkpaperDir import check
import requests
Expand All @@ -9,7 +11,7 @@
def download(path):
headers = {
"user-agent":
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
}

img = requests.get(api_url, headers=headers)
Expand Down
2 changes: 2 additions & 0 deletions scripts/1.py → scripts/FY-4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# source: 风云四号
# updateTime earthSize
from PIL import Image
from setWallpaper import set_wallpaper
from checkWakkpaperDir import check
Expand Down
3 changes: 3 additions & 0 deletions scripts/0.py → scripts/Himawari-8.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# source: 向日葵八号
# updateTime earthSize

from PIL import Image
from setWallpaper import set_wallpaper
from checkWakkpaperDir import check
Expand Down
4 changes: 3 additions & 1 deletion scripts/5.py → scripts/LocalWallpaper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# source: 本地壁纸
# updateTime wallpaperDir
import sys
import os
from setWallpaper import set_wallpaper

wallpaperDir = sys.argv[1]
wallpaperDir = sys.argv[4]
currentFile = wallpaperDir + "/current.txt"

currentWallpaper = "None"
Expand Down
2 changes: 2 additions & 0 deletions scripts/4.py → scripts/wifu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# source: 动漫壁纸
# updateTime
from setWallpaper import set_wallpaper
from checkWakkpaperDir import check
import requests
Expand Down
132 changes: 84 additions & 48 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QStandardPaths>
#include <qfiledialog.h>

Config::Config(QWidget *parent) : QWidget(parent), ui(new Ui::Config)
{
Expand All @@ -32,7 +32,7 @@ Config::Config(QWidget *parent) : QWidget(parent), ui(new Ui::Config)
initUI();
initConnect();
readConfig();
controlOption();
controlOption(ui->earthSource->currentText());
}

Config::~Config()
Expand All @@ -44,19 +44,28 @@ Config::~Config()
void Config::initUI()
{
this->setWindowIcon(QIcon(":/img/cn.huguoyang.earthwallpaper.png"));
ui->earthSource->addItem("向日葵八号");
ui->earthSource->addItem("风云四号");
ui->earthSource->addItem("必应壁纸(随机)");
ui->earthSource->addItem("必应壁纸(每日)");
ui->earthSource->addItem("动漫壁纸");
ui->earthSource->addItem("本地壁纸");
ui->earthSource->addItem("24h壁纸");
ui->updateTime->addItem("10");
ui->updateTime->addItem("30");
ui->updateTime->addItem("60");
ui->updateTime->addItem("120");
ui->updateTime->addItem("180");
ui->updateTime->addItem("720");
QString exePath = QCoreApplication::applicationDirPath();
QDir scriptsDir(exePath + "/scripts");
QStringList nameFilters;
nameFilters << "*.py";
scriptsDir.setNameFilters(nameFilters);
QStringList files = scriptsDir.entryList(QDir::Files, QDir::Name);
foreach (QString file, files)
{
QFile scriptFile(exePath + "/scripts/" + file);
scriptFile.open(QIODevice::ReadOnly);
QString info = scriptFile.readLine();
if (info.split(" ")[1] == "source:")
{
ui->earthSource->addItem(info.split(" ")[2].remove("\n"));
}
}
}

void Config::initConnect()
Expand All @@ -72,7 +81,7 @@ void Config::readConfig()
this->settings = new QSettings(configPath + "/config", QSettings::IniFormat);
settings->setIniCodec("UTF8");
settings->beginGroup("APP");
ui->earthSource->setCurrentIndex(settings->value("earthSource").toInt());
ui->earthSource->setCurrentText(settings->value("earthSource").toString());
ui->updateTime->setCurrentText(settings->value("updateTime").toString());
ui->earthSize->setValue(settings->value("earthSize").toInt());
ui->wallpaperDir->setText(settings->value("wallpaperDir").toString());
Expand All @@ -82,7 +91,8 @@ void Config::readConfig()
void Config::writeConfig()
{
settings->beginGroup("APP");
settings->setValue("earthSource", ui->earthSource->currentIndex());
settings->setIniCodec("UTF8");
settings->setValue("earthSource", ui->earthSource->currentText());
settings->setValue("updateTime", ui->updateTime->currentText());
settings->setValue("earthSize", ui->earthSize->value());
settings->setValue("wallpaperDir", ui->wallpaperDir->text());
Expand All @@ -91,45 +101,71 @@ void Config::writeConfig()
QMessageBox::information(this, tr("设置"), tr("设置保存成功!"));
emit configChanged();
}
void Config::controlOption()
void Config::controlOption(QString source)
{
if (ui->earthSource->currentIndex() == 0 || ui->earthSource->currentIndex() == 1)
{
ui->label_3->show();
ui->earthSize->show();
}
else
{
ui->label_3->hide();
ui->earthSize->hide();
}
if (ui->earthSource->currentIndex() == 5)
QString exePath = QCoreApplication::applicationDirPath();
QDir scriptsDir(exePath + "/scripts");
QStringList nameFilters;
nameFilters << "*.py";
scriptsDir.setNameFilters(nameFilters);
QStringList files = scriptsDir.entryList(QDir::Files, QDir::Name);
foreach (QString file, files)
{
ui->label_4->show();
ui->wallpaperDir->show();
ui->select->show();
}
else
{
ui->label_4->hide();
ui->wallpaperDir->hide();
ui->select->hide();
}
if (ui->earthSource->currentIndex() == 6)
{
ui->label_5->show();
ui->wallpaperFile->show();
ui->selectFile->show();
ui->updateTime->hide();
ui->label_2->hide();
}
else
{
ui->label_5->hide();
ui->wallpaperFile->hide();
ui->selectFile->hide();
ui->updateTime->show();
ui->label_2->show();
QFile scriptFile(exePath + "/scripts/" + file);
scriptFile.open(QIODevice::ReadOnly);
QString info = scriptFile.readLine();
if (info.split(" ")[1] == "source:")
{
if (info.split(" ")[2].remove("\n") == source)
{
QString itemInfo = scriptFile.readLine();
if (itemInfo.contains("updateTime"))
{
ui->label_2->show();
ui->updateTime->show();
}
else
{
settings->setValue("APP/updateTime", "10");
ui->label_2->hide();
ui->updateTime->hide();
}
if (itemInfo.contains("earthSize"))
{
ui->label_3->show();
ui->earthSize->show();
}
else
{
ui->label_3->hide();
ui->earthSize->hide();
}
if (itemInfo.contains("wallpaperDir"))
{
ui->label_4->show();
ui->wallpaperDir->show();
ui->select->show();
}
else
{
ui->label_4->hide();
ui->wallpaperDir->hide();
ui->select->hide();
}
if (itemInfo.contains("wallpaperFile"))
{
ui->label_5->show();
ui->wallpaperFile->show();
ui->selectFile->show();
}
else
{
ui->label_5->hide();
ui->wallpaperFile->hide();
ui->selectFile->hide();
}
}
}
}
}
void Config::selectDir()
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Config : public QWidget
void initConnect();
void readConfig();
void writeConfig();
void controlOption();
void controlOption(QString source);
void selectDir();
void selectFile();

Expand Down
62 changes: 32 additions & 30 deletions src/trayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,38 +116,40 @@ void TrayIcon::reloadSettings()
void TrayIcon::handle()
{
qDebug() << "handling...";
int earthSource = settings->value("APP/earthSource").toInt();
QString earthSize = settings->value("APP/earthSize").toString();
QString wallpaperDir = settings->value("APP/wallpaperDir").toString();
QString wallpaperFile = settings->value("APP/wallpaperFile").toString();
QString exePath = QCoreApplication::applicationDirPath();
settings->beginGroup("APP");
settings->setIniCodec("UTF8");
QString earthSource = settings->value("earthSource").toString();
QString earthSize = settings->value("earthSize").toString();
QString wallpaperDir = settings->value("wallpaperDir").toString();
QString wallpaperFile = settings->value("wallpaperFile").toString();
settings->endGroup();
QString command = "";
switch (earthSource)
QString exePath = QCoreApplication::applicationDirPath();
QDir scriptsDir(exePath + "/scripts");
QStringList nameFilters;
nameFilters << "*.py";
scriptsDir.setNameFilters(nameFilters);
QStringList files = scriptsDir.entryList(QDir::Files, QDir::Name);
qDebug() << earthSource;
foreach (QString file, files)
{
case 0:
command = "python3 " + exePath + "/scripts/" + "0.py " + QString::number(this->height) + " " +
QString::number(this->width) + " " + earthSize;
break;
case 1:
command = "python3 " + exePath + "/scripts/" + "1.py " + QString::number(this->height) + " " +
QString::number(this->width) + " " + earthSize;
break;
case 2:
command = "python3 " + exePath + "/scripts/" + "2.py";
break;
case 3:
command = "python3 " + exePath + "/scripts/" + "3.py";
break;
case 4:
command = "python3 " + exePath + "/scripts/" + "4.py";
break;
case 5:
command = "python3 " + exePath + "/scripts/" + "5.py " + wallpaperDir;
break;
case 6:
settings->setValue("APP/updateTime", "10");
command = "python3 " + exePath + "/scripts/" + "6.py " + wallpaperFile;
break;
QFile scriptFile(exePath + "/scripts/" + file);
scriptFile.open(QIODevice::ReadOnly);
QString info = scriptFile.readLine();
if (info.split(" ")[1] == "source:")
{

qDebug() << info.split(" ")[2].remove("\n");
if (info.split(" ")[2].remove("\n") == earthSource)
{
command = "python3 " + exePath + "/scripts/" + file + " " + QString::number(this->height) + " " +
QString::number(this->width) + " " + earthSize + " " + wallpaperDir + " " + wallpaperFile;
if (file == "24h.py")
{
settings->setValue("APP/updateTime", "10");
}
}
}
}

// 根据设置下载、更新壁纸
Expand Down
6 changes: 3 additions & 3 deletions template/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[APP]
earthSource=0
earthSource=风云四号
updateTime=30
earthSize=60
wallpaperDir=""
wallpaperFile=""
wallpaperDir="/"
wallpaperFile="/"

0 comments on commit 759d269

Please sign in to comment.