diff --git a/conf/config.py b/conf/config.py index 26346ba..76cc7f8 100644 --- a/conf/config.py +++ b/conf/config.py @@ -30,10 +30,12 @@ IsLoadingPicture = True UpdateUrl = "https://github.com/tonquer/picacg-windows/releases/latest" -UpdateVersion = "v1.1.3" +UpdateUrl2 = "https://github.com/tonquer/picacg-windows/releases" +UpdateVersion = "v1.1.4" # waifu2x CanWaifu2x = True +ErrorMsg = "" Encode = 0 Waifu2xThread = 2 diff --git a/src/index/book.py b/src/index/book.py index d98975f..f433b5d 100644 --- a/src/index/book.py +++ b/src/index/book.py @@ -35,6 +35,7 @@ def __init__(self): self.categories = [] # 分类 self.tags = [] # tag self.eps = [] # 章节列表BookEps + self.epsDict = {} @property def id(self): @@ -89,21 +90,24 @@ def AddBookEpsInfoBack(self, backData): limit = r.data['eps']["limit"] # 优化,如果分页已经加载好了,只需要重新加载更新最后一页即可 - for i, data in enumerate(r.data['eps']['docs']): - index = (page -1) * limit + i - if len(info.eps) > index: - epsInfo = info.eps[index] + for i, data2 in enumerate(r.data['eps']['docs']): + # index = (page -1) * limit + i + epsId = data2.get('id') + if epsId in info.epsDict: + epsInfo = info.epsDict[epsId] else: epsInfo = BookEps() - info.eps.append(epsInfo) - ToolUtil.ParseFromData(epsInfo, data) + info.epsDict[epsId] = epsInfo + # info.eps.append(epsInfo) + ToolUtil.ParseFromData(epsInfo, data2) - loadPage = int((len(info.eps)-1) / limit + 1) + loadPage = int((len(info.epsDict)-1) / limit + 1) nextPage = page + 1 # 如果已经有了,则从最后那一页加载起就可以了 if loadPage > nextPage: nextPage = loadPage + info.eps = list(info.epsDict.values()) info.eps.sort(key=lambda a: a.order) if nextPage <= pages: diff --git a/src/qt/chat/qtchatroom.py b/src/qt/chat/qtchatroom.py index bc110e6..52f76b6 100644 --- a/src/qt/chat/qtchatroom.py +++ b/src/qt/chat/qtchatroom.py @@ -193,7 +193,7 @@ def _RecvBroadcastMsg(self, data): if not os.path.isdir(path): os.makedirs(path) f = open(saveName, "wb") - f.write(audio) + f.write(audio.encode("utf-8")) f.close() except Exception as es: Log.Error(es) diff --git a/src/qt/chat/qtchatroommsg.py b/src/qt/chat/qtchatroommsg.py index f3e478d..f27ee33 100644 --- a/src/qt/chat/qtchatroommsg.py +++ b/src/qt/chat/qtchatroommsg.py @@ -1,12 +1,10 @@ from PySide2 import QtWidgets -from PySide2.QtCore import QEvent, QUrl, QProcess -from PySide2.QtGui import QPixmap, Qt, QIcon, QCursor, QDesktopServices -from PySide2.QtWebSockets import QWebSocket +from PySide2.QtCore import QEvent, QProcess +from PySide2.QtGui import QPixmap, Qt, QIcon, QCursor from PySide2.QtWidgets import QMenu, QApplication from resources.resources import DataMgr from src.qt.com.qtimg import QtImgMgr -from src.util import Log from ui.chatrootmsg import Ui_ChatRoomMsg diff --git a/src/qt/com/qtimg.py b/src/qt/com/qtimg.py index acaace7..af24380 100644 --- a/src/qt/com/qtimg.py +++ b/src/qt/com/qtimg.py @@ -6,6 +6,7 @@ from PySide2.QtGui import QColor, QPainter, QPixmap, QImage from PySide2.QtWidgets import QFrame, QGraphicsPixmapItem, QGraphicsScene, QApplication, QFileDialog +from conf import config from src.qt.com.qtbubblelabel import QtBubbleLabel from src.qt.util.qttask import QtTask from src.util import Singleton, ToolUtil, Log @@ -23,18 +24,21 @@ def ShowImg(self, data): self.data = data self.waifu2xData = None QtTask().CancelConver("QtImg") - self.obj.comboBox.setEnabled(True) - self.obj.changeButton.setEnabled(True) + if config.CanWaifu2x: + self.obj.comboBox.setEnabled(True) + self.obj.changeButton.setEnabled(True) self.obj.changeButton.setText("转换") self.obj.ShowImg(data) elif self.data: - self.obj.comboBox.setEnabled(True) - self.obj.changeButton.setEnabled(True) + if config.CanWaifu2x: + self.obj.comboBox.setEnabled(True) + self.obj.changeButton.setEnabled(True) self.obj.changeButton.setText("转换") self.obj.ShowImg(self.data) else: - self.obj.comboBox.setEnabled(True) - self.obj.changeButton.setEnabled(True) + if config.CanWaifu2x: + self.obj.comboBox.setEnabled(True) + self.obj.changeButton.setEnabled(True) self.obj.changeButton.setText("转换") self.obj.show() diff --git a/src/qt/com/qtlistwidget.py b/src/qt/com/qtlistwidget.py index fd6e829..db52ccc 100644 --- a/src/qt/com/qtlistwidget.py +++ b/src/qt/com/qtlistwidget.py @@ -1,14 +1,13 @@ import weakref from PySide2.QtCore import Qt, QSize -from PySide2.QtGui import QPixmap, QColor, QIntValidator, QImage, QFont, QCursor +from PySide2.QtGui import QPixmap, QColor, QIntValidator, QFont, QCursor from PySide2.QtWidgets import QListWidget, QLabel, QWidget, QVBoxLayout, QHBoxLayout, QListWidgetItem, QAbstractSlider, \ - QScroller, QGridLayout, QSpacerItem, QSizePolicy, QMenu, QApplication + QScroller, QMenu, QApplication from conf import config -from resources import resources from src.qt.com.qtcomment import QtComment -from src.qt.com.qtimg import QtImg, QtImgMgr +from src.qt.com.qtimg import QtImgMgr from src.qt.util.qttask import QtTask from src.util import ToolUtil from src.util.status import Status diff --git a/src/qt/com/qtloading.py b/src/qt/com/qtloading.py index 6807261..5a92385 100644 --- a/src/qt/com/qtloading.py +++ b/src/qt/com/qtloading.py @@ -1,9 +1,8 @@ import weakref -from PySide2 import QtWidgets, QtCore, QtGui -from PySide2.QtCore import QPoint, QTimer +from PySide2 import QtWidgets, QtCore +from PySide2.QtCore import QTimer from PySide2.QtGui import QPixmap, QImage -from PySide2.QtWidgets import QDesktopWidget from resources import resources from ui.loading import Ui_Loading diff --git a/src/qt/main/qtindex.py b/src/qt/main/qtindex.py index eb57e95..cd61347 100644 --- a/src/qt/main/qtindex.py +++ b/src/qt/main/qtindex.py @@ -7,7 +7,7 @@ from resources.resources import DataMgr from src.qt.com.qtlistwidget import QtBookList -from src.server import Server, req, Status, Log +from src.server import Server, req, Log from src.user.user import User from ui.index import Ui_Index diff --git a/src/qt/menu/qtsetting.py b/src/qt/menu/qtsetting.py index d91dbdf..537c4b1 100644 --- a/src/qt/menu/qtsetting.py +++ b/src/qt/menu/qtsetting.py @@ -163,6 +163,6 @@ def SetGpuInfos(self, gpuInfo): def GetGpuName(self): index = config.Encode - if index >= len(self.gpuInfos): + if index >= len(self.gpuInfos) or index < 0: return "GPU" return self.gpuInfos[index] diff --git a/src/qt/qtmain.py b/src/qt/qtmain.py index 96acaa4..ef0d7ed 100644 --- a/src/qt/qtmain.py +++ b/src/qt/qtmain.py @@ -1,5 +1,4 @@ -import os -import re + from PySide2 import QtWidgets, QtGui # 导入PySide2部件 from PySide2.QtCore import QTimer, QUrl @@ -9,7 +8,7 @@ from conf import config from resources import resources from src.qt.chat.qtchat import QtChat -from src.qt.com.qtimg import QtImg, QtImgMgr +from src.qt.com.qtimg import QtImgMgr from src.qt.main.qtindex import QtIndex from src.qt.menu.qtabout import QtAbout from src.qt.read.qtbookinfo import QtBookInfo @@ -138,14 +137,14 @@ def Init(self): self.settingForm.SetGpuInfos(gpuInfo) Log.Info("waifu2x初始化: " + str(stat) + " encode: " + str(config.Encode)) else: - self.msgForm.ShowError("waifu2x无法启用") + self.msgForm.ShowError("waifu2x无法启用, "+config.ErrorMsg) self.settingForm.checkBox.setEnabled(False) self.qtReadImg.frame.qtTool.checkBox.setEnabled(False) self.downloadForm.autoConvert = False - self.downloadForm.radioButton.setChecked(False) - QtImgMgr().obj.radioButton.setChecked(False) + self.downloadForm.radioButton.setEnabled(False) QtImgMgr().obj.radioButton.setEnabled(False) QtImgMgr().obj.changeButton.setEnabled(False) + QtImgMgr().obj.changeButton.setEnabled(False) QtImgMgr().obj.comboBox.setEnabled(False) config.IsOpenWaifu = 0 @@ -173,6 +172,6 @@ def InitUpdateBack(self, data): data), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if r == QMessageBox.Yes: - QDesktopServices.openUrl(QUrl("https://github.com/tonquer/picacg-windows/releases")) + QDesktopServices.openUrl(QUrl(config.UpdateUrl2)) except Exception as es: Log.Error(es) \ No newline at end of file diff --git a/src/qt/read/qtbookinfo.py b/src/qt/read/qtbookinfo.py index 5e0359f..ebb2404 100644 --- a/src/qt/read/qtbookinfo.py +++ b/src/qt/read/qtbookinfo.py @@ -35,9 +35,9 @@ def __init__(self, owner): self.msgForm = QtBubbleLabel(self) self.picture.installEventFilter(self) - self.title.setGeometry(QRect(328, 240, 329, 27 * 4)) + # self.title.setGeometry(QRect(328, 240, 329, 27 * 4)) self.title.setWordWrap(True) - self.title.setAlignment(Qt.AlignTop) + # self.title.setAlignment(Qt.AlignLeft) self.title.setContextMenuPolicy(Qt.CustomContextMenu) self.title.customContextMenuRequested.connect(self.CopyTitle) @@ -307,13 +307,15 @@ def UpdateEpsData(self): downloadIds = self.owner().downloadForm.GetDownloadCompleteEpsId(self.bookId) for index, epsInfo in enumerate(info.eps): label = QLabel(epsInfo.title) + # label.setWordWrap(True) label.setContentsMargins(20, 10, 20, 10) item = QListWidgetItem(self.epsListWidget) if index in downloadIds: item.setBackground(QColor(18, 161, 130)) else: item.setBackground(QColor(0,0,0,0)) - item.setSizeHint(label.sizeHint()) + item.setSizeHint(label.sizeHint() + QSize(2, 0)) + item.setToolTip(epsInfo.title) self.epsListWidget.setItemWidget(item, label) self.tabWidget.setTabText(0, "章节({})".format(str(len(info.eps)))) return diff --git a/src/qt/read/qtreadimg.py b/src/qt/read/qtreadimg.py index 930a54b..f0c227f 100644 --- a/src/qt/read/qtreadimg.py +++ b/src/qt/read/qtreadimg.py @@ -91,6 +91,7 @@ def OpenPage(self, bookId, epsId, name): info = BookMgr().books.get(bookId) if info: self.category = info.tags[:] + self.category.extend(info.categories) self.qtTool.checkBox.setChecked(config.IsOpenWaifu) self.qtTool.SetData(isInit=True) self.graphicsItem.setPixmap(QPixmap()) @@ -196,7 +197,8 @@ def ShowImg(self, isShowWaifu=True): self.graphicsItem.setPixmap(QPixmap()) self.qtTool.modelBox.setEnabled(False) return - self.qtTool.modelBox.setEnabled(True) + if config.CanWaifu2x: + self.qtTool.modelBox.setEnabled(True) assert isinstance(p, QtFileData) if not isShowWaifu: p2 = p.data diff --git a/src/qt/read/qtreadimg_tool.py b/src/qt/read/qtreadimg_tool.py index edbe09b..49c81d1 100644 --- a/src/qt/read/qtreadimg_tool.py +++ b/src/qt/read/qtreadimg_tool.py @@ -227,7 +227,8 @@ def SetData(self, pSize=None, dataLen=0, state="", waifuSize=None, waifuDataLen= self.stateWaifu.setStyleSheet("color:red;") else: self.stateWaifu.setStyleSheet("color:dark;") - self.stateWaifu.setText("状态:" + waifuState) + if config.CanWaifu2x: + self.stateWaifu.setText("状态:" + waifuState) if waifuTick or isInit: self.tickLabel.setText("耗时:" + str(waifuTick) + "s") diff --git a/src/qt/user/qtuser.py b/src/qt/user/qtuser.py index 3fdea08..9f5cb7f 100644 --- a/src/qt/user/qtuser.py +++ b/src/qt/user/qtuser.py @@ -2,8 +2,8 @@ from PySide2 import QtWidgets, QtGui from PySide2.QtCore import Qt, QSize, QEvent -from PySide2.QtGui import QIcon, QPixmap -from PySide2.QtWidgets import QListWidget, QListWidgetItem +from PySide2.QtGui import QPixmap +from PySide2.QtWidgets import QListWidgetItem from resources import resources from src.qt.com.qtimg import QtImgMgr diff --git a/start.py b/start.py index 57034b9..d4e15bf 100644 --- a/start.py +++ b/start.py @@ -9,6 +9,7 @@ config.CanWaifu2x = True except Exception as es: config.CanWaifu2x = False + config.ErrorMsg = es.msg from PySide2 import QtWidgets # 导入PySide2部件 from src.qt.qtmain import BikaQtMainWindow