Skip to content

Commit

Permalink
update v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tonquer committed Feb 7, 2021
1 parent f64263b commit dc1c4df
Show file tree
Hide file tree
Showing 22 changed files with 922 additions and 218 deletions.
3 changes: 3 additions & 0 deletions conf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
# CacheExpired = 24 * 60 * 60 # cache过期时间24小时

IsLoadingPicture = True

UpdateUrl = "https://github.com/tonquer/picacg-windows/releases/latest"
UpdateVersion = "1.0.4"
21 changes: 21 additions & 0 deletions src/qt/qtabout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import weakref

from PyQt5 import QtWidgets
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices

from conf import config
from ui.about import Ui_AboutForm


class QtAbout(QtWidgets.QWidget, Ui_AboutForm):
def __init__(self, owner):
super(self.__class__, self).__init__()
Ui_AboutForm.__init__(self)
self.setupUi(self)
self.setWindowTitle("关于")
self.owner = weakref.ref(owner)
self.label_3.linkActivated.connect(self.OpenUrl)

def OpenUrl(self):
QDesktopServices.openUrl(QUrl(config.UpdateUrl))
50 changes: 33 additions & 17 deletions src/qt/qtbookinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from src.qt.qtbubblelabel import QtBubbleLabel
from src.qt.qtlistwidget import QtBookList
from src.qt.qtloading import QtLoading
from src.qt.qtreadimg import QtReadImg
from src.server import req, Log, Server, QtTask
from src.server import req, Log, Server, QtTask, ToolUtil
from src.user.user import User
from src.util.status import Status
from ui.bookinfo import Ui_BookInfo
Expand Down Expand Up @@ -69,16 +68,15 @@ def __init__(self, owner):

self.commentLayout.addWidget(self.listWidget)

self.qtReadImg = QtReadImg(self, owner)
self.stackedWidget.addWidget(self.qtReadImg)
# self.stackedWidget.addWidget(self.qtReadImg)
self.epsListWidget.clicked.connect(self.OpenReadImg)

self.closeFlag = self.__class__.__name__ + "-close" # 切换book时,取消加载

def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
if self.stackedWidget.currentIndex() == 1:
self.stackedWidget.setCurrentIndex(0)
self.qtReadImg.AddHistory()
self.owner().qtReadImg.AddHistory()
self.LoadHistory()
a0.ignore()
else:
Expand Down Expand Up @@ -111,7 +109,7 @@ def OpenBook(self, bookId):
self.download.setEnabled(True)

self.owner().qtTask.CancelTasks(self.closeFlag)
self.stackedWidget.setCurrentIndex(0)
# self.stackedWidget.setCurrentIndex(0)
self.show()
self.loadingForm.show()
self.owner().qtTask.AddHttpTask(lambda x: BookMgr().AddBookById(bookId, x), self.OpenBookBack)
Expand All @@ -126,15 +124,15 @@ def OpenBookBack(self, msg):
self.listWidget.UpdateState()
info = BookMgr().books.get(self.bookId)
if msg == Status.Ok and info:
self.autor.setText("作者:" + info.author)
self.title.setText("标题:" + info.title)
self.autor.setText(info.author)
self.title.setText(info.title)
self.bookName = info.title
self.description.setText("描述:" + info.description)
self.description.setText(info.description)
self.isFinished.setText("完本" if info.finished else "未完本")
self.categories.setText("分类:" + ','.join(info.categories))
self.tags.setText("TAG:" + ','.join(info.tags))
self.likes.setText("爱心数:" + str(info.totalLikes))
self.views.setText("观看数:" + str(info.totalViews))
self.categories.setText(','.join(info.categories))
self.tags.setText(','.join(info.tags))
self.likes.setText(str(info.totalLikes))
self.views.setText(str(info.totalViews))

if info.isFavourite:
self.favorites.setEnabled(False)
Expand All @@ -146,13 +144,16 @@ def OpenBookBack(self, msg):
name = info.thumb.get("originalName")
self.url = fileServer
self.path = path
timeArray, day = ToolUtil.GetDateStr(info.updated_at)
self.updateTick.setText(str(day) + "天前更新")
if config.IsLoadingPicture:

self.owner().qtTask.AddDownloadTask(fileServer, path, name, completeCallBack=self.UpdatePicture, cleanFlag=self.closeFlag)
self.owner().qtTask.AddDownloadTask(fileServer, path, completeCallBack=self.UpdatePicture, cleanFlag=self.closeFlag)
self.owner().qtTask.AddHttpTask(lambda x: Server().Send(req.GetComments(self.bookId), bakParam=x),
self.GetCommnetBack, cleanFlag=self.closeFlag)

self.owner().qtTask.AddHttpTask(lambda x: BookMgr().AddBookEpsInfo(self.bookId, x), self.GetEpsBack, cleanFlag=self.closeFlag)
self.startRead.setEnabled(False)
else:
# QtWidgets.QMessageBox.information(self, '加载失败', msg, QtWidgets.QMessageBox.Yes)
self.msgForm.ShowError(msg)
Expand Down Expand Up @@ -214,12 +215,14 @@ def UpdateEpsData(self):
info = BookMgr().books.get(self.bookId)
if not info:
return
self.startRead.setEnabled(True)
for epsInfo in info.eps:
label = QLabel(epsInfo.title)
label.setContentsMargins(20, 10, 20, 10)
item = QListWidgetItem(self.epsListWidget)
item.setSizeHint(label.sizeHint())
self.epsListWidget.setItemWidget(item, label)
self.tabWidget.setTabText(0, "章节({})".format(str(len(info.eps))))
return

def AddDownload(self):
Expand All @@ -243,21 +246,34 @@ def LoadNextPage(self):

def OpenReadImg(self, modelIndex):
index = modelIndex.row()
self.OpenReadIndex(index)

def OpenReadIndex(self, index):
item = self.epsListWidget.item(index)
if not item:
return
widget = self.epsListWidget.itemWidget(item)
if not widget:
return
name = widget.text()
self.qtReadImg.OpenPage(self.bookId, index, name)
self.stackedWidget.setCurrentIndex(1)
self.hide()
self.owner().qtReadImg.OpenPage(self.bookId, index, name)
# self.stackedWidget.setCurrentIndex(1)

def StartRead(self):
if self.lastEpsId >= 0:
self.OpenReadIndex(self.lastEpsId)
else:
self.OpenReadIndex(0)
return

def LoadHistory(self):
info = self.owner().historyForm.GetHistory(self.bookId)
if not info:
self.startRead.setText("观看第{}章".format(str(1)))
return
if self.lastEpsId == info.epsId:
self.startRead.setText("观看第{}章".format(str(self.lastEpsId + 1)))
return

if self.lastEpsId >= 0:
Expand All @@ -271,4 +287,4 @@ def LoadHistory(self):
item.setBackground(QColor(238, 162, 164))
self.epsListWidget.update()
self.lastEpsId = info.epsId

self.startRead.setText("观看第{}章".format(str(self.lastEpsId+1)))
2 changes: 1 addition & 1 deletion src/qt/qtdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def StartDownload(self, task):

if st == Status.Ok:
task.saveName = picInfo.originalName
self.owner().qtTask.AddDownloadTask(picInfo.fileServer, picInfo.path, picInfo.originalName,
self.owner().qtTask.AddDownloadTask(picInfo.fileServer, picInfo.path,
downloadCallBack=self.DownloadCallBack,
completeCallBack=self.CompleteDownloadPic, backParam=task.bookId,
isSaveCache=False)
Expand Down
1 change: 1 addition & 0 deletions src/qt/qthistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def AddHistory(self, bookId, name, epsId, index, url, path):
info = self.history.get(bookId)
if not info:
info = QtHistoryData()
self.history[bookId] = info
info.bookId = bookId
info.name = name
info.epsId = epsId
Expand Down
11 changes: 4 additions & 7 deletions src/qt/qtlistwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from conf import config
from resources import resources
from src.qt.qttask import QtTask
from src.util import ToolUtil
from src.util.status import Status


Expand Down Expand Up @@ -211,19 +212,15 @@ def AddBookItem(self, _id, title, info="", url="", path="", originalName=""):
self.setItemWidget(item, iwidget)
iwidget.picIcon.setText("图片加载中...")
if url and path and config.IsLoadingPicture:
QtTask().AddDownloadTask(url, path, originalName, None, self.LoadingPictureComplete, True, index, True, self.GetName())
QtTask().AddDownloadTask(url, path, None, self.LoadingPictureComplete, True, index, True, self.GetName())
pass

def AddUserItem(self, content, name, createdTime, floor, url="", path="", originalName=""):
index = self.count()
iwidget = UserItemWidget(self)
iwidget.commentLabel.setText(content)
iwidget.label.setText(name)

timeArray = time.strptime(createdTime, "%Y-%m-%dT%H:%M:%S.%fZ")
tick = int(time.mktime(timeArray))
now = int(time.time())
day = int((int(now - time.timezone) / 86400) - (int(tick - time.timezone) / 86400))
timeArray, day = ToolUtil.GetDateStr(createdTime)
if day >= 1:
iwidget.timeLabel.setText("{}天前".format(str(day)))
else:
Expand All @@ -236,7 +233,7 @@ def AddUserItem(self, content, name, createdTime, floor, url="", path="", origin
item.setSizeHint(iwidget.sizeHint())
self.setItemWidget(item, iwidget)
if url and path and config.IsLoadingPicture:
QtTask().AddDownloadTask(url, path, originalName, None, self.LoadingPictureComplete, True, index, True, self.GetName())
QtTask().AddDownloadTask(url, path, None, self.LoadingPictureComplete, True, index, True, self.GetName())
pass

def LoadingPictureComplete(self, data, status, index):
Expand Down
38 changes: 35 additions & 3 deletions src/qt/qtmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import time

from PyQt5 import QtWidgets, QtGui # 导入PyQt5部件
from PyQt5.QtCore import QTimer, pyqtSignal, QSettings
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import QTimer, pyqtSignal, QSettings, QUrl
from PyQt5.QtGui import QIcon, QPixmap, QDesktopServices
from PyQt5.QtWidgets import QMessageBox

from conf import config
from resources import resources
from src.qt.qtabout import QtAbout
from src.qt.qtbookinfo import QtBookInfo
from src.qt.qtbubblelabel import QtBubbleLabel
from src.qt.qtcategory import QtCategory
Expand All @@ -16,11 +18,13 @@
from src.qt.qtloading import QtLoading
from src.qt.qtlogin import QtLogin
from src.qt.qtrank import QtRank
from src.qt.qtreadimg import QtReadImg
from src.qt.qtregister import QtRegister
from src.qt.qtsearch import QtSearch
from src.qt.qtsetting import QtSetting
from src.qt.qttask import QtTask
from src.qt.qtuser import QtUser
from src.server import Server, req
from src.util import Log
from ui.main import Ui_MainWindow

Expand All @@ -41,6 +45,8 @@ def __init__(self):
pic.loadFromData(resources.DataMgr.GetData("logo_round"))
icon.addPixmap(pic, QIcon.Normal, QIcon.Off)
self.setWindowIcon(icon)
self.aboutForm = QtAbout(self)

self.searchForm = QtSearch(self)
self.favoriteForm = QtFavorite(self)
self.downloadForm = QtDownload(self)
Expand All @@ -53,6 +59,8 @@ def __init__(self):

self.historyForm = QtHistory(self)

self.qtReadImg = QtReadImg(self)

self.userForm = QtUser(self)
self.bookInfoForm = QtBookInfo(self)

Expand Down Expand Up @@ -109,6 +117,7 @@ def closeEvent(self, a0: QtGui.QCloseEvent) -> None:

def Init(self):
# self.ClearExpiredCache()
self.InitUpdate()
self.loginForm.Init()
return

Expand All @@ -117,4 +126,27 @@ def OpenSetting(self):
pass

def OpenAbout(self):
pass
self.aboutForm.show()
pass

def InitUpdate(self):
self.qtTask.AddHttpTask(lambda x: Server().Send(req.CheckUpdateReq(), bakParam=x), self.InitUpdateBack)

def InitUpdateBack(self, data):
try:
info = os.path.basename(data).split(".")
version = int(info[0]) * 100 + int(info[1]) * 10 + int(info[2]) * 1

info2 = config.UpdateVersion.split(".")
curversion = int(info2[0]) * 100 + int(info2[1]) * 10 + int(info2[2]) * 1
if version > curversion:
r = QMessageBox.information(self, "更新", "当前版本{} ,检查到更新{},是否前往更新".format(config.UpdateVersion,
info),
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if r == QMessageBox.Yes:
QDesktopServices.openUrl(QUrl(config.UpdateUrl))
except Exception as Es:
import sys
cur_tb = sys.exc_info()[2] # return (exc_type, exc_value, traceback)
e = sys.exc_info()[1]
Log.Error(cur_tb, e)
Loading

0 comments on commit dc1c4df

Please sign in to comment.