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

Commit

Permalink
feat(wallhaven): 添加搜索关键词和颜色选项
Browse files Browse the repository at this point in the history
  • Loading branch information
ambition_echo committed Nov 23, 2022
1 parent ea92b10 commit 879296f
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 258 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/notify.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Notify
on:
on:
issues:
types: opened
issue_comment:
Expand All @@ -14,7 +14,7 @@ jobs:
- name: get issue_comment content
if: github.event_name == 'issue_comment'
run: |
echo "CONTENT=${{ github.event.comment.body }}" >> $GITHUB_ENV
echo "CONTENT=\"${{ github.event.comment.body }}\"" >> $GITHUB_ENV
- name: get issues content
if: github.event_name == 'issues'
run: |
Expand Down
2 changes: 1 addition & 1 deletion earth_wallpaper/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def get_version():
return "2.0.9"
return "2.1.3"


def compare(remote, local):
Expand Down
86 changes: 80 additions & 6 deletions earth_wallpaper/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shutil

from PySide6.QtCore import Qt, QSettings, Signal
from PySide6.QtGui import QIcon
from PySide6.QtGui import QIcon, QPixmap, QPainter, QColor
from PySide6.QtWidgets import QWidget, QMessageBox, QFileDialog
from earth_wallpaper.ui.UI_config import Ui_Config
from earth_wallpaper.utils.platformInfo import PlatformInfo
Expand Down Expand Up @@ -33,7 +33,8 @@ def __init__(self):
self.setAttribute(Qt.WA_DeleteOnClose)
self.config_path = PlatformInfo.config_path()
self.path = os.path.split(os.path.realpath(__file__))[0]
self.setWindowIcon(QIcon(os.path.join(self.path, "resource/earth-wallpaper.png")))
self.setWindowIcon(
QIcon(os.path.join(self.path, "resource/earth-wallpaper.png")))
self.setupUi(self)
self.initUI()
self.check()
Expand All @@ -56,18 +57,24 @@ def initUI(self):
self.sorting.addItem("Favorites")
self.sorting.addItem("Toplist")
self.sorting.addItem("Hot")
self.init_color_select()

def _update_layout_(self):
updateTimeGroup = [self.updateTime, self.updateTime_l]
earthSizeGroup = [self.earthSize, self.earthSize_l]
wallpaperDirGroup = [self.wallpaperDir, self.wallpaperDir_l, self.selectDir]
wallpaperFileGroup = [self.wallpaperFile, self.wallpaperFile_l, self.selectFile]
wallpaperDirGroup = [self.wallpaperDir,
self.wallpaperDir_l, self.selectDir]
wallpaperFileGroup = [self.wallpaperFile,
self.wallpaperFile_l, self.selectFile]
apikeyGroup = [self.apikey_l, self.apikey]
categoriesGroup = [self.categories_l, self.General, self.Anime, self.People]
categoriesGroup = [self.categories_l,
self.General, self.Anime, self.People]
purityGroup = [self.purity_l, self.SFW, self.Sketchy, self.NSFW]
sortingGroup = [self.sorting_l, self.sorting]
searchkeyGroup = [self.searchkey_l, self.searchkey]
colorGroup = [self.color_l, self.color]
all_layout = [updateTimeGroup, earthSizeGroup, wallpaperDirGroup, wallpaperFileGroup, apikeyGroup,
categoriesGroup, purityGroup, sortingGroup]
categoriesGroup, purityGroup, sortingGroup, searchkeyGroup, colorGroup]
class_name = _get_class_name_(self.source.currentText())
layout_list = getattr(interfaces, class_name).layout()
for i in all_layout:
Expand Down Expand Up @@ -109,6 +116,7 @@ def set_default_config(self):
settings.setValue("Sketchy", False)
settings.setValue("NSFW", False)
settings.setValue("sorting", "Random")
settings.setValue("color", "不选择")
settings.endGroup()

settings.beginGroup("System")
Expand Down Expand Up @@ -140,6 +148,8 @@ def read_config(self):
self.Sketchy.setChecked(trans(str(settings.value("Sketchy"))))
self.NSFW.setChecked(trans(str(settings.value("NSFW"))))
self.sorting.setCurrentText(settings.value("sorting"))
self.searchkey.setText(settings.value("searchkey"))
self.color.setCurrentText(settings.value("color"))
settings.endGroup()

settings.beginGroup("System")
Expand Down Expand Up @@ -171,6 +181,8 @@ def write_config(self):
settings.setValue("Sketchy", self.Sketchy.isChecked())
settings.setValue("NSFW", self.NSFW.isChecked())
settings.setValue("sorting", self.sorting.currentText())
settings.setValue("searchkey", self.searchkey.text())
settings.setValue("color", self.color.currentText())
settings.endGroup()

settings.beginGroup("System")
Expand Down Expand Up @@ -208,3 +220,65 @@ def clear_cache():
logger.info(f"删除缓存目录: {cache}")
message = QMessageBox()
QMessageBox.information(message, "清理缓存", "已删除全部缓存壁纸", QMessageBox.Yes)

def init_color_select(self):
pix = QPixmap(16, 16)
painter = QPainter(pix)
painter.fillRect(0, 0, 16, 16, QColor("#660000"))
self.color.addItem(QIcon(pix), "660000")
painter.fillRect(0, 0, 16, 16, QColor("#990000"))
self.color.addItem(QIcon(pix), "990000")
painter.fillRect(0, 0, 16, 16, QColor("#cc0000"))
self.color.addItem(QIcon(pix), "cc0000")
painter.fillRect(0, 0, 16, 16, QColor("#cc3333"))
self.color.addItem(QIcon(pix), "cc3333")
painter.fillRect(0, 0, 16, 16, QColor("#ea4c88"))
self.color.addItem(QIcon(pix), "ea4c88")
painter.fillRect(0, 0, 16, 16, QColor("#993399"))
self.color.addItem(QIcon(pix), "993399")
painter.fillRect(0, 0, 16, 16, QColor("#663399"))
self.color.addItem(QIcon(pix), "663399")
painter.fillRect(0, 0, 16, 16, QColor("#333399"))
self.color.addItem(QIcon(pix), "333399")
painter.fillRect(0, 0, 16, 16, QColor("#0066cc"))
self.color.addItem(QIcon(pix), "0066cc")
painter.fillRect(0, 0, 16, 16, QColor("#0099cc"))
self.color.addItem(QIcon(pix), "0099cc")
painter.fillRect(0, 0, 16, 16, QColor("#66cccc"))
self.color.addItem(QIcon(pix), "66cccc")
painter.fillRect(0, 0, 16, 16, QColor("#77cc33"))
self.color.addItem(QIcon(pix), "77cc33")
painter.fillRect(0, 0, 16, 16, QColor("#669900"))
self.color.addItem(QIcon(pix), "669900")
painter.fillRect(0, 0, 16, 16, QColor("#336600"))
self.color.addItem(QIcon(pix), "336600")
painter.fillRect(0, 0, 16, 16, QColor("#666600"))
self.color.addItem(QIcon(pix), "666600")
painter.fillRect(0, 0, 16, 16, QColor("#cccc33"))
self.color.addItem(QIcon(pix), "cccc33")
painter.fillRect(0, 0, 16, 16, QColor("#ffff00"))
self.color.addItem(QIcon(pix), "ffff00")
painter.fillRect(0, 0, 16, 16, QColor("#ffcc33"))
self.color.addItem(QIcon(pix), "ffcc33")
painter.fillRect(0, 0, 16, 16, QColor("#ff9900"))
self.color.addItem(QIcon(pix), "ff9900")
painter.fillRect(0, 0, 16, 16, QColor("#ff6600"))
self.color.addItem(QIcon(pix), "ff6600")
painter.fillRect(0, 0, 16, 16, QColor("#cc6633"))
self.color.addItem(QIcon(pix), "cc6633")
painter.fillRect(0, 0, 16, 16, QColor("#996633"))
self.color.addItem(QIcon(pix), "996633")
painter.fillRect(0, 0, 16, 16, QColor("#663300"))
self.color.addItem(QIcon(pix), "663300")
painter.fillRect(0, 0, 16, 16, QColor("#000000"))
self.color.addItem(QIcon(pix), "000000")
painter.fillRect(0, 0, 16, 16, QColor("#999999"))
self.color.addItem(QIcon(pix), "999999")
painter.fillRect(0, 0, 16, 16, QColor("#cccccc"))
self.color.addItem(QIcon(pix), "cccccc")
painter.fillRect(0, 0, 16, 16, QColor("#ffffff"))
self.color.addItem(QIcon(pix), "ffffff")
painter.fillRect(0, 0, 16, 16, QColor("#424153"))
self.color.addItem(QIcon(pix), "424153")
self.color.addItem("不选择")
painter.end()
6 changes: 6 additions & 0 deletions earth_wallpaper/interfaces/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def nsfw(self):
def sorting(self):
return self.settings.value("APP/sorting").lower().replace(" ", "_")

def searchkey(self):
return self.settings.value("APP/searchkey")

def color(self):
return self.settings.value("APP/color")

@staticmethod
def desktop_res() -> (int, int):
desktop = QApplication.primaryScreen()
Expand Down
9 changes: 8 additions & 1 deletion earth_wallpaper/interfaces/wallhaven.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self):
self.sketchy = Settings().sketchy()
self.nsfw = Settings().nsfw()
self.sorting = Settings().sorting()
self.searchkey = Settings().searchkey()
self.color = Settings().color()
self.download_path = PlatformInfo().download_path(".png")

def build_search_url(self):
Expand All @@ -41,6 +43,10 @@ def build_search_url(self):
purity[2] = '1'
self.search_url += f"&purity={''.join(purity)}"
self.search_url += f"&sorting={self.sorting}"
if not len(self.searchkey) == 0:
self.search_url += f"&q={self.searchkey}"
if not self.color == "不选择":
self.search_url += f"&colors={self.color}"
if not len(self.apikey) == 0:
self.search_url += f"&apikey={self.apikey}"
logger.info(f"search_url构造完成:{self.search_url}")
Expand Down Expand Up @@ -81,5 +87,6 @@ def name():

@staticmethod
def layout():
layout_list = ["updateTimeGroup", "apikeyGroup", "categoriesGroup", "purityGroup", "sortingGroup"]
layout_list = ["updateTimeGroup", "apikeyGroup", "categoriesGroup", "purityGroup", "sortingGroup",
"searchkeyGroup", "colorGroup"]
return layout_list
Loading

0 comments on commit 879296f

Please sign in to comment.