Skip to content

Commit

Permalink
update v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tonquer committed Apr 4, 2021
1 parent 5ff58bc commit 0b3903c
Show file tree
Hide file tree
Showing 23 changed files with 517 additions and 267 deletions.
2 changes: 2 additions & 0 deletions conf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Uuid = "defaultUuid"
HttpProxy = "" # 代理
ChatProxy = 1 # 聊天室启用代理
ChatSavePath = "chat"

SavePath = ''
SavePathDir = "commies" # 下载目录
Expand All @@ -40,6 +41,7 @@

LookModel = 0 # 默认值
DownloadModel = 0 # 默认值
LogIndex = 0


Model1 = "cunet" # 通用
Expand Down
2 changes: 1 addition & 1 deletion src/qt/chat/qtchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, owner):
super(self.__class__, self).__init__(owner)
self.owner = weakref.ref(owner)
self.gridLayout = QGridLayout(self)
self.listWidget = QtBookList(None, self.__class__.__name__)
self.listWidget = QtBookList(None, self.__class__.__name__, owner)
self.listWidget.InitUser()
self.gridLayout.addWidget(self.listWidget)
self.closeFlag = self.__class__.__name__
Expand Down
19 changes: 16 additions & 3 deletions src/qt/chat/qtchatroom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import base64
import json
import os
import random
import time

from PySide2 import QtWidgets, QtWebSockets
from PySide2.QtCore import Signal, QTimer, QSize
Expand Down Expand Up @@ -153,7 +155,7 @@ def _RecvBroadcastMsg(self, data):
info = QtChatRoomMsg(self)
at = data.get('at')
if at:
msg = at.replace("嗶咔_", "@") + "\n" + msg
msg = "<font color=#1661ab>{}</font>".format(at.replace("嗶咔_", "@")) + "\n" + msg
info.commentLabel.setText(msg)
info.nameLabel.setText(name)
info.levelLabel.setText(" LV"+str(level)+" ")
Expand Down Expand Up @@ -182,8 +184,19 @@ def _RecvBroadcastMsg(self, data):
info.replayLabel.setVisible(False)
info.commentLabel.setVisible(False)
info.toolButton.setVisible(True)
info.audioData = audio
# info.toolButton.setText("")
try:
saveName = str(int(time.time())) + "_" + str(random.randint(1, 1000)) + ".3gp"
info.toolButton.setText(saveName)
path = os.path.join(config.SavePath, config.ChatSavePath)
saveName = os.path.join(path, saveName)
info.audioData = saveName
if not os.path.isdir(path):
os.makedirs(path)
f = open(saveName, "wb")
f.write(audio)
f.close()
except Exception as es:
Log.Error(es)
else:
info.toolButton.setVisible(False)

Expand Down
12 changes: 10 additions & 2 deletions src/qt/chat/qtchatroommsg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PySide2 import QtWidgets
from PySide2.QtCore import QEvent
from PySide2.QtGui import QPixmap, Qt, QIcon, QCursor
from PySide2.QtCore import QEvent, QUrl, QProcess
from PySide2.QtGui import QPixmap, Qt, QIcon, QCursor, QDesktopServices
from PySide2.QtWebSockets import QWebSocket

from resources.resources import DataMgr
Expand Down Expand Up @@ -32,6 +32,7 @@ def __init__(self, chatRoom):
self.picLabel.setScaledContents(True)
self.picLabel.setAttribute(Qt.WA_TranslucentBackground)
self.commentLabel.setWordWrap(True)
self.toolButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
# self.setStyleSheet("""
# background:transparent;
# border:2px solid red;
Expand Down Expand Up @@ -135,3 +136,10 @@ def At(self):
if self.chatRoom:
self.chatRoom.SetAtLabel(self.nameLabel.text())
return

def OpenAudioPath(self):
if self.audioData:
process = QProcess()
path = "explorer.exe /select,\"{}\"".format(self.audioData)
process.startDetached(path)
return
101 changes: 98 additions & 3 deletions src/qt/com/qtlistwidget.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import weakref

from PySide2.QtCore import Qt, QSize
from PySide2.QtGui import QPixmap, QColor, QIntValidator, QImage, QFont
from PySide2.QtGui import QPixmap, QColor, QIntValidator, QImage, QFont, QCursor
from PySide2.QtWidgets import QListWidget, QLabel, QWidget, QVBoxLayout, QHBoxLayout, QListWidgetItem, QAbstractSlider, \
QScroller, QGridLayout, QSpacerItem, QSizePolicy
QScroller, QGridLayout, QSpacerItem, QSizePolicy, 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.util.qttask import QtTask
from src.util import ToolUtil
from src.util.status import Status
Expand All @@ -18,6 +21,7 @@ def __init__(self, bottom, top, parent):
def fixup(self, input: str) -> str:
return str(self.top())


class ItemWidget(QWidget):
def __init__(self, _id, title, index, info, param, *args, **kwargs):
super(ItemWidget, self).__init__(*args, **kwargs)
Expand All @@ -28,6 +32,7 @@ def __init__(self, _id, title, index, info, param, *args, **kwargs):
layout = QVBoxLayout(self)
layout.setContentsMargins(10, 20, 10, 0)
# 图片label
self.pictureData = None
self.picIcon = QLabel(self)
# self.picIcon.setCursor(Qt.PointingHandCursor)
# self.picIcon.setScaledContents(True)
Expand Down Expand Up @@ -94,6 +99,7 @@ def __init__(self, _id, title, index, info, param, *args, **kwargs):
def SetPicture(self, data):
if not data:
return
self.pictureData = data
pic = QPixmap()
pic.loadFromData(data)
# maxW = self.picIcon.width()
Expand All @@ -119,7 +125,7 @@ def GetId(self):


class QtBookList(QListWidget):
def __init__(self, parent, name):
def __init__(self, parent, name, owner):
QListWidget.__init__(self, parent)
self.page = 1
self.pages = 1
Expand All @@ -128,6 +134,8 @@ def __init__(self, parent, name):
self.isLoadingPage = False
self.LoadCallBack = None
self.parentId = -1
self.popMenu = None
self.owner = weakref.ref(owner)

def GetName(self):
return self.name + "-QtBookList"
Expand All @@ -141,6 +149,30 @@ def InitBook(self, callBack=None):
self.setResizeMode(self.Adjust)
self.LoadCallBack = callBack

self.popMenu = QMenu(self)
action = self.popMenu.addAction("打开")
action.triggered.connect(self.OpenBookInfoHandler)
action = self.popMenu.addAction("查看封面")
action.triggered.connect(self.OpenPicture)
action = self.popMenu.addAction("复制标题")
action.triggered.connect(self.CopyHandler)
action = self.popMenu.addAction("下载")
action.triggered.connect(self.DownloadHandler)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.doubleClicked.connect(self.OpenBookInfo)
self.customContextMenuRequested.connect(self.SelectMenu)

def InstallCategory(self):
self.doubleClicked.disconnect(self.OpenBookInfo)
self.popMenu = QMenu(self)
action = self.popMenu.addAction("查看封面")
action.triggered.connect(self.OpenPicture)
return

def InstallDel(self):
action = self.popMenu.addAction("刪除")
action.triggered.connect(self.DelHandler)

def InitUser(self, callBack=None):
self.setFrameShape(self.NoFrame) # 无边框
self.LoadCallBack = callBack
Expand Down Expand Up @@ -219,6 +251,69 @@ def clear(self) -> None:
# 防止异步加载时,信息错乱
QtTask().CancelTasks(self.GetName())

def SelectMenu(self, pos):
index = self.indexAt(pos)
if index.isValid():
self.popMenu.exec_(QCursor.pos())
pass

def DownloadHandler(self):
selected = self.selectedItems()
for item in selected:
widget = self.itemWidget(item)
self.owner().epsInfoForm.OpenEpsInfo(widget.GetId())
pass

def OpenBookInfoHandler(self):
selected = self.selectedItems()
for item in selected:
widget = self.itemWidget(item)
self.owner().bookInfoForm.OpenBook(widget.GetId())
return

def CopyHandler(self):
selected = self.selectedItems()
if not selected:
return

data = ''
for item in selected:
widget = self.itemWidget(item)
data += widget.GetTitle() + str("\r\n")
clipboard = QApplication.clipboard()
data = data.strip("\r\n")
clipboard.setText(data)
pass

def DelHandler(self):
bookIds = set()
selected = self.selectedItems()
for item in selected:
widget = self.itemWidget(item)
bookIds.add(widget.GetId())
if not bookIds:
return
self.parent().DelCallBack(bookIds)

def OpenBookInfo(self, modelIndex):
index = modelIndex.row()
item = self.item(index)
if not item:
return
widget = self.itemWidget(item)
if not widget:
return
bookId = widget.id
if not bookId:
return
self.owner().bookInfoForm.OpenBook(bookId)

def OpenPicture(self):
selected = self.selectedItems()
for item in selected:
widget = self.itemWidget(item)
QtImgMgr().ShowImg(widget.pictureData)
return

class QtCategoryList(QListWidget):
def __init__(self, parent):
Expand Down
76 changes: 51 additions & 25 deletions src/qt/download/download_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DownloadInfo(object):
Waiting = "等待中"
Pause = "暂停"
Error = "出错了"
NotFound = "原始文件不存在"

Converting = "转码中"
ConvertSuccess = "转码成功"
Expand Down Expand Up @@ -273,6 +274,7 @@ def __init__(self, parent):

self.curPreDownloadIndex = 0
self.curPreConvertId = 0 # 转码
self.resetConvertCnt = 0
self.status = DownloadInfo.Downloading
self.tick = 0

Expand Down Expand Up @@ -323,17 +325,26 @@ def StartDownload(self):
def AddDownload(self):
bookInfo = BookMgr().books.get(self.parent.bookId)
epsInfo = bookInfo.eps[self.epsId]
picInfo = epsInfo.pics[self.curPreDownloadIndex]
self.picCnt = len(epsInfo.pics)
if os.path.isfile(self.curSavePath):
self.curPreDownloadIndex += 1
return self.StartDownload()
QtTask().AddDownloadTask(picInfo.fileServer,
picInfo.path,
downloadCallBack=self.AddDownloadBack,
completeCallBack=self.AddDownloadCompleteBack,
isSaveCache=False,
cleanFlag="download_".format(self.parent.bookId))
isDownloadNext = True
while self.curPreDownloadIndex < len(epsInfo.pics):
bookInfo = BookMgr().books.get(self.parent.bookId)
epsInfo = bookInfo.eps[self.epsId]
picInfo = epsInfo.pics[self.curPreDownloadIndex]
self.picCnt = len(epsInfo.pics)
if os.path.isfile(self.curSavePath):
self.curPreDownloadIndex += 1
else:
isDownloadNext = False
QtTask().AddDownloadTask(picInfo.fileServer,
picInfo.path,
downloadCallBack=self.AddDownloadBack,
completeCallBack=self.AddDownloadCompleteBack,
isSaveCache=False,
cleanFlag="download_{}".format(self.parent.bookId))
break
self.parent.UpdateTableItem()
if isDownloadNext:
self.StartDownload()

def AddDownloadBack(self, data, laveFileSize):
self.downloadLen += len(data)
Expand Down Expand Up @@ -374,20 +385,27 @@ def AddConvert(self):
savePath = os.path.join(self.parent.savePath, ToolUtil.GetCanSaveName(self.epsTitle))
filePath = os.path.join(savePath, "{:04}.{}".format(self.curPreConvertId + 1, "jpg"))
if not os.path.isfile(filePath):
self.status = DownloadInfo.Error
self.status = DownloadInfo.NotFound
self.parent.SetConvertStatu(self.status)
return
if os.path.isfile(self.curConvertPath):
self.curPreConvertId += 1
return self.StartConvert()
f = open(filePath, "rb")
data = f.read()
f.close()

w, h = ToolUtil.GetPictureSize(data)
model = ToolUtil.GetDownloadScaleModel(w, h)
QtTask().AddConvertTask("", data, model, self.AddConvertBack,
cleanFlag="download_".format(self.parent.bookId))
isConvertNext = True
while self.curPreConvertId < self.picCnt:
if os.path.isfile(self.curConvertPath):
self.curPreConvertId += 1
else:
isConvertNext = False
f = open(filePath, "rb")
data = f.read()
f.close()

w, h = ToolUtil.GetPictureSize(data)
model = ToolUtil.GetDownloadScaleModel(w, h)
QtTask().AddConvertTask("", data, model, self.AddConvertBack,
cleanFlag="download_{}".format(self.parent.bookId))
break
self.parent.UpdateTableItem()
if isConvertNext:
self.StartConvert()
return

def AddConvertBack(self, data, waifuId, backParam, tick):
Expand All @@ -400,8 +418,16 @@ def AddConvertBack(self, data, waifuId, backParam, tick):
f.write(data)
f.close()
self.tick = tick
self.resetConvertCnt = 0
self.curPreConvertId += 1
self.StartConvert()
else:
self.resetConvertCnt += 1
if self.resetConvertCnt >= 3:
self.status = DownloadInfo.Error
self.parent.SetConvertStatu(DownloadInfo.Error)
else:
self.StartConvert()
except Exception as es:
Log.Error(es)
self.status = DownloadInfo.Error
Expand All @@ -410,8 +436,8 @@ def AddConvertBack(self, data, waifuId, backParam, tick):

def Pause(self):
self.status = DownloadInfo.Pause
QtTask().CancelTasks(cleanFlag="download_".format(self.parent.bookId))
QtTask().CancelTasks(cleanFlag="download_{}".format(self.parent.bookId))
return

def PauseConvert(self):
QtTask().CancelConver(cleanFlag="download_".format(self.parent.bookId))
QtTask().CancelConver(cleanFlag="download_{}".format(self.parent.bookId))
2 changes: 1 addition & 1 deletion src/qt/download/qtdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def SelectMenu(self, pos):
else:
if task.convertStatus in [DownloadInfo.Converting]:
menu.addAction(self.pauseConvertAction)
elif task.convertStatus in [DownloadInfo.Pause]:
elif task.convertStatus in [DownloadInfo.Pause, DownloadInfo.Error, DownloadInfo.NotFound]:
menu.addAction(self.startConvertAction)
else:
menu = QMenu(self.tableWidget)
Expand Down
3 changes: 2 additions & 1 deletion src/qt/main/qtcategory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ def __init__(self, owner):
Ui_category.__init__(self)
self.setupUi(self)
self.owner = weakref.ref(owner)
self.bookList = QtBookList(self, self.__class__.__name__)
self.bookList = QtBookList(self, self.__class__.__name__, owner)
self.bookList.InitBook()
self.gridLayout_2.addWidget(self.bookList)
self.bookList.doubleClicked.connect(self.OpenSearch)
self.bookList.InstallCategory()

def SwitchCurrent(self):
if self.bookList.count() <= 0:
Expand Down

0 comments on commit 0b3903c

Please sign in to comment.