Skip to content

Commit 78ea06f

Browse files
committed
theme picture
1 parent 1eaeca7 commit 78ea06f

File tree

13 files changed

+93
-128
lines changed

13 files changed

+93
-128
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Library/*
1111
Library.zip
1212
*.log
1313
Resources/Data/*
14-
Resources/Images/Avatars/*.jpg
14+
Resources/Images/Avatars/*.jpg
15+
Resources/Images/Wallpaper/*

Resources/Themes/Dark/style.qss

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,16 @@ ToolTip > QLabel {
376376
}
377377

378378
/*主题图片tab标签*/
379-
PictureWidget::pane {
379+
#widgetCategories > QPushButton {
380380
border: none;
381-
}
382-
PictureWidget > QTabBar::tab {
383381
color: rgb(140, 140, 140);
384-
font-size: 18px;
385-
min-width: 100px;
386-
min-height: 46px;
382+
min-height: 26px;
387383
background: transparent;
388384
}
389-
PictureWidget > QTabBar::tab:hover {
385+
#widgetCategories > QPushButton:hover {
390386
color: black;
391387
}
392-
PictureWidget > QTabBar::tab:selected {
388+
#widgetCategories > QPushButton:checked {
393389
color: rgb(18, 183, 245);
394390
}
395391

Resources/Themes/Default/style.qss

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,16 @@ ToolTip > QLabel {
376376
}
377377

378378
/*主题图片tab标签*/
379-
PictureWidget::pane {
379+
#widgetCategories > QPushButton {
380380
border: none;
381-
}
382-
PictureWidget > QTabBar::tab {
383381
color: rgb(140, 140, 140);
384-
font-size: 18px;
385-
min-width: 100px;
386-
min-height: 46px;
382+
min-height: 26px;
387383
background: transparent;
388384
}
389-
PictureWidget > QTabBar::tab:hover {
385+
#widgetCategories > QPushButton:hover {
390386
color: black;
391387
}
392-
PictureWidget > QTabBar::tab:selected {
388+
#widgetCategories > QPushButton:checked {
393389
color: rgb(18, 183, 245);
394390
}
395391

Resources/Themes/春节/style.qss

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,20 +377,16 @@ ToolTip > QLabel {
377377
}
378378

379379
/*主题图片tab标签*/
380-
PictureWidget::pane {
380+
#widgetCategories > QPushButton {
381381
border: none;
382-
}
383-
PictureWidget > QTabBar::tab {
384382
color: rgb(140, 140, 140);
385-
font-size: 18px;
386-
min-width: 100px;
387-
min-height: 46px;
383+
min-height: 26px;
388384
background: transparent;
389385
}
390-
PictureWidget > QTabBar::tab:hover {
386+
#widgetCategories > QPushButton:hover {
391387
color: black;
392388
}
393-
PictureWidget > QTabBar::tab:selected {
389+
#widgetCategories > QPushButton:checked {
394390
color: rgb(18, 183, 245);
395391
}
396392

UiFiles/SkinDialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@
167167
<number>30</number>
168168
</property>
169169
<property name="topMargin">
170-
<number>20</number>
170+
<number>10</number>
171171
</property>
172172
<property name="rightMargin">
173173
<number>30</number>
174174
</property>
175175
<property name="bottomMargin">
176-
<number>20</number>
176+
<number>10</number>
177177
</property>
178178
<item>
179179
<widget class="QWidget" name="widgetCategories" native="true"/>

UiFiles/Ui_SkinDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def setupUi(self, FormSkinDialog):
6464
self.widget = QtWidgets.QWidget(self.tabPicture)
6565
self.widget.setObjectName("widget")
6666
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.widget)
67-
self.verticalLayout_5.setContentsMargins(30, 20, 30, 20)
67+
self.verticalLayout_5.setContentsMargins(30, 10, 30, 10)
6868
self.verticalLayout_5.setSpacing(0)
6969
self.verticalLayout_5.setObjectName("verticalLayout_5")
7070
self.widgetCategories = QtWidgets.QWidget(self.widget)

Utils/CommonUtil.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,12 @@ class _Signals(QObject):
156156
# 主推item点击,路径
157157
themeItemClicked = pyqtSignal(str, object)
158158

159-
# 获取壁纸目录
160-
getCategoriesFinished = pyqtSignal(list)
161-
# 分类获取完成
162-
getCategoryFinished = pyqtSignal(object, list)
163-
# 分类图片下载完成信号
164-
pictureDownloadFinished = pyqtSignal(object, int, list)
159+
# 分类图片下载完成并添加item
160+
pictureItemAdded = pyqtSignal(object, int, str, str)
165161
# 分类图片item点击,路径
166162
pictureItemClicked = pyqtSignal(str, object)
163+
# 单个分类下载完成
164+
pictureDownFinished = pyqtSignal(object)
167165

168166

169167
# 说白了就是全局信号定义

Utils/Constants.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
LogFormatter = '[%(asctime)s %(name)s] %(levelname)-8s %(message)s'
4040
LogFile = 'Resources/Data/app.log'
4141

42-
DirImages = 'Resources/Images'
42+
DirWallpaper = 'Resources/Images/Wallpaper' # 壁纸目录
4343
DirThemes = 'Resources/Themes' # 主题目录
4444
DirErrors = 'Resources/Data/Errors' # 错误日志目录
4545
DirProject = 'Resources/Data/Projects' # 本地项目目录
@@ -53,8 +53,7 @@
5353
UrlQQ = 'tencent://message/?uin=892768447'
5454
UrlGroup = 'tencent://groupwpa/?subcmd=all&param=7B2267726F757055696E223A3234363236393931392C2274696D655374616D70223A313531383537323831357D0A'
5555
UrlIssues = 'https://github.com/PyQt5/PyQtClient/issues/new'
56-
UrlGetAllCategoriesV2 = 'http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2'
57-
UrlGetAppsByCategory = 'http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={cid}&start={start}&count={count}&from=360chrome'
56+
UrlGetAppsByCategory = 'http://bizhi.ludashi.com/live/wallpaper/categoryList?category={category}&pageno={pageno}&count={count}&type=1&_={time}'
5857

5958
_Sha = ''
6059
_Account = ''

Utils/ThemeThread.py

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"""
1212
import os
1313
from pathlib import Path
14+
from time import time
1415

1516
from PyQt5.QtCore import QObject, QThread, QRunnable
1617
from PyQt5.QtGui import QLinearGradient, QColor
1718
import requests
1819

1920
from Utils.CommonUtil import AppLog, Signals
20-
from Utils.Constants import DirThemes, UrlGetAllCategoriesV2,\
21-
UrlGetAppsByCategory, DirImages
21+
from Utils.Constants import DirThemes, UrlGetAppsByCategory, DirWallpaper
2222

2323

2424
__Author__ = "Irony"
@@ -154,63 +154,56 @@ def run(self):
154154
AppLog.info('theme thread end')
155155

156156

157-
class GetAllCategoriesRunnable(QRunnable):
158-
159-
def __init__(self, *args, **kwargs):
160-
super(GetAllCategoriesRunnable, self).__init__(*args, **kwargs)
161-
self.setAutoDelete(True)
162-
163-
def run(self):
164-
categories = []
165-
try:
166-
req = requests.get(UrlGetAllCategoriesV2)
167-
content = req.json()
168-
categories = content.get('data', [])
169-
AppLog.debug('errmsg: %s', content.get('errmsg', ''))
170-
AppLog.debug('consume: %s', content.get('consume', ''))
171-
AppLog.debug('total: %s', content.get('total', ''))
172-
except Exception as e:
173-
AppLog.exception(e)
174-
Signals.getCategoriesFinished.emit(categories)
175-
176-
177157
class GetAllCategoryRunnable(QRunnable):
178158

179-
def __init__(self, cid, widget, *args, **kwargs):
159+
def __init__(self, category, widget, *args, **kwargs):
180160
super(GetAllCategoryRunnable, self).__init__(*args, **kwargs)
181161
self.setAutoDelete(True)
182-
self.cid = cid
162+
self.category = category
183163
self.widget = widget
184164

185-
def download(self, index, url):
165+
def download(self, index, title, url):
186166
try:
187-
dirPath = os.path.join(DirImages, self.cid)
167+
dirPath = os.path.join(DirWallpaper, self.category)
188168
os.makedirs(dirPath, exist_ok=True)
169+
path = os.path.join(dirPath, os.path.basename(url))
170+
if os.path.exists(path) and os.path.isfile(path):
171+
Signals.pictureItemAdded.emit(
172+
self.widget, index, title, path)
173+
return
189174
req = requests.get(url, headers=Headers)
190175
if req.status_code == 200:
191-
path = os.path.join(dirPath, os.path.basename(url))
192176
with open(path, 'wb') as fp:
193177
fp.write(req.content)
194-
self.pictureDownloadFinished.emit(self, index, path)
178+
Signals.pictureItemAdded.emit(
179+
self.widget, index, title, path)
195180
except Exception as e:
196181
AppLog.exception(e)
197182

198183
def run(self):
199-
datas = []
200184
try:
201185
req = requests.get(UrlGetAppsByCategory.format(
202-
cid=self.cid, start=0, count=200))
186+
category=self.category, pageno=1, count=20, time=time()))
203187
content = req.json()
204-
datas = content.get('data', [])
205-
AppLog.debug('errmsg: %s', content.get('errmsg', ''))
206-
AppLog.debug('consume: %s', content.get('consume', ''))
207-
AppLog.debug('total: %s', content.get('total', ''))
208-
# 加载前20个
209-
for i, item in enumerate(datas[:20]):
210-
url = item.get('url', None)
188+
errno = content.get('errno', 0)
189+
AppLog.debug('errno: %s', errno)
190+
AppLog.debug('msg: %s', content.get('msg', ''))
191+
if errno != 0:
192+
return
193+
194+
content = content.get('data', {})
195+
AppLog.debug('total_count: %s', content.get('total_count', ''))
196+
AppLog.debug('total_page: %s', content.get('total_page', ''))
197+
items = content.get('list', [])
198+
199+
for i, item in enumerate(items):
200+
title = item.get('title', '')
201+
url = item.get('image', None)
211202
if not url:
212203
continue
213-
self.download(i, url)
204+
self.download(i, title, url)
205+
QThread.msleep(200)
206+
QThread.yieldCurrentThread()
214207
except Exception as e:
215208
AppLog.exception(e)
216-
Signals.getCategoryFinished.emit(self.widget, datas)
209+
Signals.pictureDownFinished.emit(self.widget)

Widgets/Dialogs/SkinDialog.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from UiFiles.Ui_SkinDialog import Ui_FormSkinDialog
1717
from Utils.CommonUtil import Signals
1818
from Utils.ThemeManager import ThemeManager
19-
from Utils.ThemeThread import GetAllCategoriesRunnable
2019
from Widgets.Dialogs.MoveDialog import MoveDialog
2120
from Widgets.Layouts.FlowLayout import FlowLayout
2221
from Widgets.Skins.PictureWidget import PictureWidget
@@ -36,12 +35,7 @@ def __init__(self, *args, **kwargs):
3635
# 无边框
3736
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
3837
self.widgetBottom.setVisible(False)
39-
# 背景图片面板
40-
Signals.getCategoriesFinished.connect(self.onGetCategoriesFinished)
41-
Signals.getCategoryFinished.connect(self.onGetCategoryFinished)
42-
Signals.pictureDownloadFinished.connect(self.onPictureDownloadFinished)
43-
self.categoryLayout = FlowLayout(self.widgetCategories)
44-
self.categoryLayout.setSpacing(20)
38+
Signals.pictureItemAdded.connect(self.onPictureItemAdded)
4539
# 加载鼠标样式
4640
ThemeManager.loadCursor(self)
4741
self.on_tabWidgetSkinMain_currentChanged(0)
@@ -52,24 +46,26 @@ def on_tabWidgetSkinMain_currentChanged(self, index):
5246
if w == self.tabPicture:
5347
if self.stackedWidgetPictures.count() > 0:
5448
return
55-
QThreadPool.globalInstance().start(GetAllCategoriesRunnable())
49+
self.initCategories()
5650
else:
5751
w.init()
5852

59-
def onGetCategoriesFinished(self, categories):
53+
def initCategories(self):
6054
"""添加分类标签页
6155
:param categories: 分类
6256
"""
57+
self.categoryLayout = FlowLayout(self.widgetCategories)
58+
self.categoryLayout.setSpacing(10)
6359
self.categoryBtnGroups = QButtonGroup(self)
6460
self.categoryBtnGroups.buttonToggled.connect(self.onCategoryChanged)
65-
for category in categories:
66-
button = QPushButton(category.get(
67-
'name', '未知'), self.widgetCategories)
61+
for category in ('4K', '双屏', '美女', '动漫', '风景', '明星', '萌宠', '游戏', '科技', '其他'):
62+
button = QPushButton(category, self.widgetCategories)
6863
button.setCheckable(True)
6964
self.categoryBtnGroups.addButton(button)
7065
self.categoryLayout.addWidget(button)
71-
self.stackedWidgetPictures.addWidget(
72-
PictureWidget(category.get('id', '36'), self.stackedWidgetPictures))
66+
widget = PictureWidget(category, self.stackedWidgetPictures)
67+
button.setProperty('widget', widget)
68+
self.stackedWidgetPictures.addWidget(widget)
7369
self.categoryBtnGroups.buttons()[0].setChecked(True)
7470

7571
def onCategoryChanged(self, button, toggled):
@@ -79,21 +75,20 @@ def onCategoryChanged(self, button, toggled):
7975
"""
8076
if not toggled:
8177
return
82-
index = self.categoryBtnGroups.id(button)
83-
self.stackedWidgetPictures.setCurrentIndex(index)
84-
self.stackedWidgetPictures.widget(index).init()
85-
86-
def onGetCategoryFinished(self, widget, items):
87-
"""某个分类json下载完成
88-
:param widget: 该分类对应的PictureWidget
89-
:param items: 分类中的数组
90-
"""
91-
widget.setItems(items)
78+
widget = button.property('widget')
79+
self.stackedWidgetPictures.setCurrentWidget(widget)
80+
runnable = widget.init()
81+
if runnable:
82+
if not hasattr(self, '_threadPool'):
83+
self._threadPool = QThreadPool(self)
84+
self._threadPool.setMaxThreadCount(5)
85+
self._threadPool.start(runnable)
9286

93-
def onPictureDownloadFinished(self, widget, index, path):
94-
"""分类图片下载完成
87+
def onPictureItemAdded(self, widget, index, title, path):
88+
"""添加分类图片Item
9589
:param widget: 该分类对应的PictureWidget
9690
:param index: 序号
91+
:param title: 标题
9792
:param path: 图片路径
9893
"""
99-
widget.addItem(index, path)
94+
widget.addItem(index, title, path)

0 commit comments

Comments
 (0)