def Register(self): if not self.buttonGroup.checkedButton(): # QtWidgets.QMessageBox.information(self, '错误', "不能为空", QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowErrorEx(self, "不能为空") return if len(self.passwdEdit.text()) < 8: # QtWidgets.QMessageBox.information(self, '错误', "密码太短", QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowErrorEx(self, "密码太短") return data = { "email": self.userEdit.text(), "password": self.passwdEdit.text(), "name": self.nameEdit.text(), "birthday": self.birthdayEdit.text().replace("/", "-"), "gender": self.buttonGroup.checkedButton().objectName().replace("gender_", ""), # m, f, bot "answer1": self.answer1Edit.text(), "answer2": self.answer2Edit.text(), "answer3": self.answer3Edit.text(), "question1": self.question1Edit.text(), "question2": self.question2Edit.text(), "question3": self.question3Edit.text() } for v in data.values(): if not v: # QtWidgets.QMessageBox.information(self, '错误', "不能为空", QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowErrorEx(self, "不能为空") return self.loadingForm.show() self.owner().qtTask.AddHttpTask(lambda x: User().Register(data, x), self.RegisterBack) return
def RegisterBack(self, msg): self.loadingForm.close() if msg == Status.Ok: # self.close() # QtWidgets.QMessageBox.information(self, '注册成功', "注册成功", QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowMsgEx(self, "注册成功") self.close() else: # QtWidgets.QMessageBox.information(self, '注册失败', msg, QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowErrorEx(self, msg)
def SaveSetting(self): config.DownloadThreadNum = int(self.comboBox.currentText()) config.ImageQuality = self.buttonGroup.checkedButton().objectName().replace("quality_", "") httpProxy = self.httpEdit.text() config.SavePath = self.saveEdit.text() config.ChatProxy = 1 if self.checkBox_2.isChecked() else 0 self.settings.setValue("DownloadThreadNum", config.DownloadThreadNum) self.settings.setValue("ImageQuality", config.ImageQuality) config.HttpProxy = httpProxy self.settings.setValue("Proxy/Http", config.HttpProxy) self.settings.setValue("SavePath", config.SavePath) self.settings.setValue("ChatProxy", config.ChatProxy) config.Encode = self.encodeSelect.currentIndex() config.Waifu2xThread = int(self.threadSelect.currentIndex()) + 1 config.IsOpenWaifu = self.checkBox.isChecked() config.LookModel = int(self.lookModel.currentIndex()) config.DownloadModel = int(self.downloadModel.currentIndex()) self.settings.setValue("Waifu2x/Encode", config.Encode) # self.settings.setValue("Waifu2x/Thread", config.Waifu2xThread) # self.settings.setValue("Waifu2x/Scale", config.Scale) # self.settings.setValue("Waifu2x/Model", config.Model) self.settings.setValue("Waifu2x/Open", config.IsOpenWaifu) self.settings.setValue("Waifu2x/LookModel", config.LookModel) self.settings.setValue("Waifu2x/DownloadModel", config.DownloadModel) # QtWidgets.QMessageBox.information(self, '保存成功', "成功", QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowMsgEx(self, "保存成功")
def SendCommentChildrenBack(self, msg, index): try: item = self.listWidget.item(index) if not item: self.loadingForm.close() return widget = self.listWidget.itemWidget(item) if not widget: self.loadingForm.close() return data = json.loads(msg) if data.get("code") == 200: self.owner().qtTask.AddHttpTask(lambda x: Server().Send( req.GetCommentsChildrenReq(widget.id), bakParam=x), self.LoadCommentInfoBack, backParam=index, cleanFlag=self.closeFlag) else: self.loadingForm.close() QtBubbleLabel.ShowErrorEx(self, data.get("message", "错误")) self.commentLine.setText("") except Exception as es: self.loadingForm.close() Log.Error(es)
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.userInfo = None self.setupUi(self) self.setWindowTitle("Waifu2x-Gui") self.msgForm = QtBubbleLabel(self) self.settingForm = QtSetting(self) self.settingForm.hide() self.settingForm.LoadSetting() self.aboutForm = QtAbout(self) self.img = QtImg() self.stackedWidget.addWidget(self.img) # self.resize(1000, 1000) self.menuabout.triggered.connect(self.OpenAbout) desktop = QGuiApplication.primaryScreen().geometry()
def LastPage(self): if self.curIndex <= 0: QtBubbleLabel.ShowMsgEx(self.readImg, "已经是第一页") return self.curIndex -= 1 info = self.readImg.pictureData.get(self.curIndex) self.UpdateProcessBar(info) self.SetData(isInit=True) self.readImg.CheckLoadPicture() self.readImg.ShowImg() return
def zoom(self, factor): """缩放 :param factor: 缩放的比例因子 """ _factor = self.graphicsView.transform().scale(factor, factor).mapRect( QRectF(0, 0, 1, 1)).width() if _factor < 0.07 or _factor > 100: # 防止过大过小 return if factor >= 1: if self.frame.scaleCnt >= 10: QtBubbleLabel.ShowMsgEx(self, "已经最大") return self.frame.scaleCnt += 1 else: if self.frame.scaleCnt <= -10: QtBubbleLabel.ShowMsgEx(self, "已经最小") return self.frame.scaleCnt -= 1 self.graphicsView.scale(factor, factor)
def NextPage(self): if self.curIndex >= self.maxPic - 1: QtBubbleLabel.ShowMsgEx(self.readImg, "已经最后一页") return t = CTime() self.curIndex += 1 self.SetData(isInit=True) info = self.readImg.pictureData.get(self.curIndex) self.UpdateProcessBar(info) self.readImg.CheckLoadPicture() self.readImg.ShowImg() t.Refresh(self.__class__.__name__) return
def SendCommentBack(self, msg): try: data = json.loads(msg) if data.get("code") == 200: self.ClearCommnetList() self.owner().qtTask.AddHttpTask(lambda x: Server().Send(req.GetComments(self.bookId), bakParam=x), self.GetCommnetBack, cleanFlag=self.closeFlag) else: self.loadingForm.close() QtBubbleLabel.ShowErrorEx(self, data.get("message", "错误")) self.commentLine.setText("") except Exception as es: self.loadingForm.close() Log.Error(es)
def CopyPicture(self): clipboard = QApplication.clipboard() owner = self.readImg if self.checkBox.isChecked(): p = owner.pictureData.get(owner.curIndex) if not p or not p.waifuData: QtBubbleLabel.ShowErrorEx(owner, "解码还未完成") return img = QImage() img.loadFromData(p.waifuData) clipboard.setImage(img) QtBubbleLabel.ShowMsgEx(owner, "复制成功") else: p = owner.pictureData.get(owner.curIndex) if not p or not p.data: QtBubbleLabel.ShowErrorEx(owner, "下载未完成") return img = QImage() img.loadFromData(p.data) clipboard.setImage(img) QtBubbleLabel.ShowMsgEx(owner, "复制成功") return
def OpenNextEps(self): epsId = self.readImg.epsId bookId = self.readImg.bookId bookInfo = BookMgr().books.get(bookId) epsId += 1 if epsId >= len(bookInfo.eps): QtBubbleLabel.ShowMsgEx(self.readImg, "已经是最后一章") return if epsId >= len(bookInfo.eps): return epsInfo = bookInfo.eps[epsId] self.readImg.AddHistory() self.readImg.owner().bookInfoForm.LoadHistory() self.readImg.OpenPage(bookId, epsId, epsInfo.title) return
def SaveSetting(self): config.Encode = self.encodeSelect.currentIndex() config.UseCpuNum = int(self.threadSelect.currentIndex()) # config.LogIndex = int(self.logBox.currentIndex()) config.Language = int(self.languageSelect.currentIndex()) config.SelectEncodeGpu = self.encodeSelect.currentText() self.settings.setValue("Waifu2x/Encode", config.Encode) # self.settings.setValue("Waifu2x/Thread", config.Waifu2xThread) # self.settings.setValue("Waifu2x/Scale", config.Scale) # self.settings.setValue("Waifu2x/Model", config.Model) self.settings.setValue("Waifu2x/SelectEncodeGpu", config.SelectEncodeGpu) self.settings.setValue("Waifu2x/UseCpuNum", config.UseCpuNum) # self.settings.setValue("Waifu2x/LogIndex", config.LogIndex) self.settings.setValue("Waifu2x/Language", config.Language) Log.UpdateLoggingLevel() # QtWidgets.QMessageBox.information(self, '保存成功', "成功", QtWidgets.QMessageBox.Yes) QtBubbleLabel.ShowMsgEx(self, "Save Success") self.close()
def AddFavority(self): User().AddAndDelFavorites(self.bookId) QtBubbleLabel.ShowMsgEx(self, "添加收藏成功") self.favorites.setEnabled(False)
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.userInfo = None self.setupUi(self) self.setWindowTitle("哔咔漫画") self.msgForm = QtBubbleLabel(self) self.qtTask = QtTask() icon = QIcon() pic = QPixmap() pic.loadFromData(resources.DataMgr.GetData("logo_round")) icon.addPixmap(pic, QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.aboutForm = QtAbout(self) self.indexForm = QtIndex(self) self.searchForm = QtSearch(self) self.favoriteForm = QtFavorite(self) self.downloadForm = QtDownload(self) self.categoryForm = QtCategory(self) self.loadingForm = QtLoading(self) self.leaveMsgForm = QtLeaveMsg(self) self.chatForm = QtChat(self) self.rankForm = QtRank(self) self.loginForm = QtLogin(self) self.registerForm = QtRegister(self) self.historyForm = QtHistory(self) self.qtReadImg = QtReadImg(self) self.userForm = QtUser(self) self.bookInfoForm = QtBookInfo(self) self.epsInfoForm = QtEpsInfo(self) self.task = QtTask() self.task.SetOwner(self) self.timer = QTimer(self) self.timer.setInterval(100) # self.timer.timeout.connect(self.OnTimeOut) # self.timer.start() self.stackedWidget.addWidget(self.loginForm) self.stackedWidget.addWidget(self.userForm) self.settingForm = QtSetting(self) self.settingForm.LoadSetting() self.resize(self.settingForm.mainSize) self.bookInfoForm.resize(self.settingForm.bookSize) self.qtReadImg.resize(self.settingForm.readSize) self.loginForm.userIdEdit.setText(self.settingForm.userId) self.loginForm.passwdEdit.setText(self.settingForm.passwd) self.menusetting.triggered.connect(self.OpenSetting) self.menuabout.triggered.connect(self.OpenAbout)
def __init__(self, owner): super(self.__class__, self).__init__() Ui_BookInfo.__init__(self) self.setupUi(self) self.owner = weakref.ref(owner) self.loadingForm = QtLoading(self) self.bookId = "" self.url = "" self.path = "" self.bookName = "" self.lastEpsId = -1 self.msgForm = QtBubbleLabel(self) self.picture.installEventFilter(self) self.title.setGeometry(QRect(328, 240, 329, 27 * 4)) self.title.setWordWrap(True) self.title.setAlignment(Qt.AlignTop) self.title.setContextMenuPolicy(Qt.CustomContextMenu) self.title.customContextMenuRequested.connect(self.CopyTitle) # self.autor.setContextMenuPolicy(Qt.CustomContextMenu) # self.autor.customContextMenuRequested.connect(self.OpenAutor) layouy = self.horizontalLayout_4 self.autorList = QtCategoryList(self) layouy.addWidget(QLabel("作者:")) layouy.addWidget(self.autorList) self.autorList.itemClicked.connect(self.ClickTagsItem) self.description.setContextMenuPolicy(Qt.CustomContextMenu) self.description.customContextMenuRequested.connect( self.CopyDescription) self.description.setGeometry(QRect(328, 240, 329, 27 * 4)) self.description.setWordWrap(True) self.description.setAlignment(Qt.AlignTop) # self.categories.setGeometry(QRect(328, 240, 329, 27 * 4)) # self.categories.setWordWrap(True) # self.categories.setAlignment(Qt.AlignTop) layouy = self.horizontalLayout_6 self.categoriesList = QtCategoryList(self) layouy.addWidget(QLabel("分类:")) layouy.addWidget(self.categoriesList) self.categoriesList.itemClicked.connect(self.ClickCategoriesItem) # self.tags.setGeometry(QRect(328, 240, 329, 27 * 4)) # self.tags.setWordWrap(True) # self.tags.setAlignment(Qt.AlignTop) layouy = self.horizontalLayout_7 self.tagsList = QtCategoryList(self) layouy.addWidget(QLabel("Tags:")) layouy.addWidget(self.tagsList) self.tagsList.itemClicked.connect(self.ClickTagsItem) self.epsListWidget = QListWidget(self) self.epsListWidget.setFlow(self.epsListWidget.LeftToRight) self.epsListWidget.setWrapping(True) self.epsListWidget.setFrameShape(self.epsListWidget.NoFrame) self.epsListWidget.setResizeMode(self.epsListWidget.Adjust) self.epsLayout.addWidget(self.epsListWidget) self.listWidget = QtBookList(self, self.__class__.__name__) self.listWidget.InitUser(self.LoadNextPage) self.listWidget.doubleClicked.connect(self.OpenCommentInfo) self.childrenListWidget = QtBookList(None, self.__class__.__name__) self.childrenListWidget.InitUser(self.LoadChildrenNextPage) self.childrenWidget = QtWidgets.QWidget() layout = QHBoxLayout(self.childrenWidget) label = QLabel() label.setMinimumWidth(100) layout.addWidget(label) layout3 = QVBoxLayout() layout2 = QHBoxLayout() self.commentLine2 = QLineEdit() self.commentButton2 = QPushButton("回复") self.commentButton2.clicked.connect(self.SendCommentChildren) layout2.addWidget(self.commentLine2) layout2.addWidget(self.commentButton2) layout3.addLayout(layout2) layout3.addWidget(self.childrenListWidget) layout.addLayout(layout3) self.commentLayout.addWidget(self.listWidget) layout = QHBoxLayout() self.commentLine = QLineEdit() layout.addWidget(self.commentLine) self.commentButton = QPushButton("发送评论") layout.addWidget(self.commentButton) self.commentLayout.addLayout(layout, 1, 0) self.commentButton.clicked.connect(self.SendComment) # self.stackedWidget.addWidget(self.qtReadImg) self.epsListWidget.clicked.connect(self.OpenReadImg) self.closeFlag = self.__class__.__name__ + "-close" # 切换book时,取消加载
class QtBookInfo(QtWidgets.QWidget, Ui_BookInfo): def __init__(self, owner): super(self.__class__, self).__init__() Ui_BookInfo.__init__(self) self.setupUi(self) self.owner = weakref.ref(owner) self.loadingForm = QtLoading(self) self.bookId = "" self.url = "" self.path = "" self.bookName = "" self.lastEpsId = -1 self.msgForm = QtBubbleLabel(self) self.picture.installEventFilter(self) self.title.setGeometry(QRect(328, 240, 329, 27 * 4)) self.title.setWordWrap(True) self.title.setAlignment(Qt.AlignTop) self.title.setContextMenuPolicy(Qt.CustomContextMenu) self.title.customContextMenuRequested.connect(self.CopyTitle) # self.autor.setContextMenuPolicy(Qt.CustomContextMenu) # self.autor.customContextMenuRequested.connect(self.OpenAutor) layouy = self.horizontalLayout_4 self.autorList = QtCategoryList(self) layouy.addWidget(QLabel("作者:")) layouy.addWidget(self.autorList) self.autorList.itemClicked.connect(self.ClickTagsItem) self.description.setContextMenuPolicy(Qt.CustomContextMenu) self.description.customContextMenuRequested.connect( self.CopyDescription) self.description.setGeometry(QRect(328, 240, 329, 27 * 4)) self.description.setWordWrap(True) self.description.setAlignment(Qt.AlignTop) # self.categories.setGeometry(QRect(328, 240, 329, 27 * 4)) # self.categories.setWordWrap(True) # self.categories.setAlignment(Qt.AlignTop) layouy = self.horizontalLayout_6 self.categoriesList = QtCategoryList(self) layouy.addWidget(QLabel("分类:")) layouy.addWidget(self.categoriesList) self.categoriesList.itemClicked.connect(self.ClickCategoriesItem) # self.tags.setGeometry(QRect(328, 240, 329, 27 * 4)) # self.tags.setWordWrap(True) # self.tags.setAlignment(Qt.AlignTop) layouy = self.horizontalLayout_7 self.tagsList = QtCategoryList(self) layouy.addWidget(QLabel("Tags:")) layouy.addWidget(self.tagsList) self.tagsList.itemClicked.connect(self.ClickTagsItem) self.epsListWidget = QListWidget(self) self.epsListWidget.setFlow(self.epsListWidget.LeftToRight) self.epsListWidget.setWrapping(True) self.epsListWidget.setFrameShape(self.epsListWidget.NoFrame) self.epsListWidget.setResizeMode(self.epsListWidget.Adjust) self.epsLayout.addWidget(self.epsListWidget) self.listWidget = QtBookList(self, self.__class__.__name__) self.listWidget.InitUser(self.LoadNextPage) self.listWidget.doubleClicked.connect(self.OpenCommentInfo) self.childrenListWidget = QtBookList(None, self.__class__.__name__) self.childrenListWidget.InitUser(self.LoadChildrenNextPage) self.childrenWidget = QtWidgets.QWidget() layout = QHBoxLayout(self.childrenWidget) label = QLabel() label.setMinimumWidth(100) layout.addWidget(label) layout3 = QVBoxLayout() layout2 = QHBoxLayout() self.commentLine2 = QLineEdit() self.commentButton2 = QPushButton("回复") self.commentButton2.clicked.connect(self.SendCommentChildren) layout2.addWidget(self.commentLine2) layout2.addWidget(self.commentButton2) layout3.addLayout(layout2) layout3.addWidget(self.childrenListWidget) layout.addLayout(layout3) self.commentLayout.addWidget(self.listWidget) layout = QHBoxLayout() self.commentLine = QLineEdit() layout.addWidget(self.commentLine) self.commentButton = QPushButton("发送评论") layout.addWidget(self.commentButton) self.commentLayout.addLayout(layout, 1, 0) self.commentButton.clicked.connect(self.SendComment) # 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.owner().qtReadImg.AddHistory() self.LoadHistory() a0.ignore() else: a0.accept() def CopyTitle(self): clipboard = QApplication.clipboard() clipboard.setText(self.title.text()) self.msgForm.ShowMsg("复制标题") return # def OpenAutor(self): # text = self.autor.text() # self.owner().userForm.listWidget.setCurrentRow(0) # self.owner().searchForm.searchEdit.setText(text) # self.owner().searchForm.Search() # return def Clear(self): self.stackedWidget.setCurrentIndex(0) self.owner().qtTask.CancelTasks(self.closeFlag) self.epsListWidget.clear() self.ClearCommnetList() def CopyDescription(self): clipboard = QApplication.clipboard() clipboard.setText(self.description.text()) self.msgForm.ShowMsg("复制描述") return def OpenBook(self, bookId): self.bookId = bookId self.setWindowTitle(self.bookId) # if self.bookId in self.owner().downloadForm.downloadDict: # self.download.setEnabled(False) # else: # self.download.setEnabled(True) self.Clear() self.show() self.loadingForm.show() self.owner().qtTask.AddHttpTask( lambda x: BookMgr().AddBookById(bookId, x), self.OpenBookBack) def close(self): super(self.__class__, self).close() def OpenBookBack(self, msg): self.loadingForm.close() self.listWidget.UpdatePage(1, 1) self.childrenListWidget.UpdatePage(1, 1) self.childrenListWidget.UpdateState() self.listWidget.UpdateState() self.categoriesList.clear() self.tagsList.clear() self.autorList.clear() info = BookMgr().books.get(self.bookId) if msg == Status.Ok and info: # self.autor.setText(info.author) self.autorList.AddItem(info.author) self.title.setText(info.title) self.bookName = info.title self.description.setText(info.description) self.isFinished.setText("完本" if info.finished else "未完本") for name in info.categories: self.categoriesList.AddItem(name) # self.categories.setText(','.join(info.categories)) # self.tags.setText(','.join(info.tags)) for name in info.tags: self.tagsList.AddItem(name) self.likes.setText(str(info.totalLikes)) self.views.setText(str(info.totalViews)) if info.isFavourite: self.favorites.setEnabled(False) else: self.favorites.setEnabled(True) self.picture.setText("图片加载中...") fileServer = info.thumb.get("fileServer") path = info.thumb.get("path") 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, 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) self.hide() return def UpdatePicture(self, data, status): if status == Status.Ok: pic = QtGui.QPixmap() pic.loadFromData(data) pic.scaled(self.picture.size(), QtCore.Qt.KeepAspectRatio) self.picture.setPixmap(pic) # self.picture.setScaledContents(True) self.update() else: self.picture.setText("图片加载失败") return # 加载评论 def GetCommnetBack(self, data): try: self.loadingForm.close() self.listWidget.UpdateState() msg = json.loads(data) if msg.get("code") == 200: comments = msg.get("data", {}).get("comments", {}) topComments = msg.get("data", {}).get("topComments", []) page = int(comments.get("page", 1)) pages = int(comments.get("pages", 1)) limit = int(comments.get("limit", 1)) self.listWidget.UpdatePage(page, pages) total = comments.get("total", 0) self.tabWidget.setTabText(1, "评论({})".format(str(total))) if page == 1: for index, info in enumerate(topComments): floor = "置顶" content = info.get("content") name = info.get("_user", {}).get("name") avatar = info.get("_user", {}).get("avatar", {}) createdTime = info.get("created_at") commentsCount = info.get("commentsCount") commnetId = info.get('_id') likesCount = info.get("likesCount") self.listWidget.AddUserItem(commnetId, commentsCount, likesCount, content, name, createdTime, floor, avatar.get("fileServer"), avatar.get("path"), avatar.get("originalName")) for index, info in enumerate(comments.get("docs")): floor = total - ((page - 1) * limit + index) content = info.get("content") name = info.get("_user", {}).get("name") avatar = info.get("_user", {}).get("avatar", {}) createdTime = info.get("created_at") commentsCount = info.get("commentsCount") commnetId = info.get('_id') likesCount = info.get("likesCount") self.listWidget.AddUserItem(commnetId, commentsCount, likesCount, content, name, createdTime, floor, avatar.get("fileServer"), avatar.get("path"), avatar.get("originalName")) return except Exception as es: Log.Error(es) def GetEpsBack(self, st): if st == Status.Ok: self.UpdateEpsData() self.lastEpsId = -1 self.LoadHistory() return return def UpdateEpsData(self): self.epsListWidget.clear() info = BookMgr().books.get(self.bookId) if not info: return self.startRead.setEnabled(True) downloadIds = self.owner().downloadForm.GetDownloadCompleteEpsId( self.bookId) for index, epsInfo in enumerate(info.eps): label = QLabel(epsInfo.title) 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()) self.epsListWidget.setItemWidget(item, label) self.tabWidget.setTabText(0, "章节({})".format(str(len(info.eps)))) return def AddDownload(self): self.owner().epsInfoForm.OpenEpsInfo(self.bookId) # if self.owner().downloadForm.AddDownload(self.bookId): # QtBubbleLabel.ShowMsgEx(self, "添加下载成功") # else: # QtBubbleLabel.ShowMsgEx(self, "已在下载列表") # self.download.setEnabled(False) def AddFavority(self): User().AddAndDelFavorites(self.bookId) QtBubbleLabel.ShowMsgEx(self, "添加收藏成功") self.favorites.setEnabled(False) def LoadNextPage(self): self.loadingForm.show() self.owner().qtTask.AddHttpTask(lambda x: Server( ).Send(req.GetComments(self.bookId, self.listWidget.page + 1), bakParam=x), self.GetCommnetBack, cleanFlag=self.closeFlag) return 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.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: item = self.epsListWidget.item(self.lastEpsId) if item: downloadIds = self.owner( ).downloadForm.GetDownloadCompleteEpsId(self.bookId) if self.lastEpsId in downloadIds: item.setBackground(QColor(18, 161, 130)) else: item.setBackground(QColor(0, 0, 0, 0)) item = self.epsListWidget.item(info.epsId) if not item: return item.setBackground(QColor(238, 162, 164)) self.epsListWidget.update() self.lastEpsId = info.epsId self.startRead.setText("观看第{}章".format(str(self.lastEpsId + 1))) def ClickCategoriesItem(self, item): text = item.text() self.owner().userForm.listWidget.setCurrentRow(1) self.owner().searchForm.searchEdit.setText("") self.owner().searchForm.OpenSearchCategories(text) return def ClickTagsItem(self, item): text = item.text() self.owner().userForm.listWidget.setCurrentRow(1) self.owner().searchForm.searchEdit.setText(text) self.owner().searchForm.Search() return def SendComment(self): data = self.commentLine.text() if not data: return self.commentLine.setText("") self.loadingForm.show() self.owner().qtTask.AddHttpTask(lambda x: Server().Send( req.SendComment(self.bookId, data), bakParam=x), callBack=self.SendCommentBack) def SendCommentBack(self, msg): try: data = json.loads(msg) if data.get("code") == 200: self.ClearCommnetList() self.owner().qtTask.AddHttpTask(lambda x: Server().Send( req.GetComments(self.bookId), bakParam=x), self.GetCommnetBack, cleanFlag=self.closeFlag) else: self.loadingForm.close() QtBubbleLabel.ShowErrorEx(self, data.get("message", "错误")) self.commentLine.setText("") except Exception as es: self.loadingForm.close() Log.Error(es) def OpenCommentInfo(self, modelIndex): index = modelIndex.row() item = self.listWidget.item(index) if not item: return widget = self.listWidget.itemWidget(item) if not widget: return self.childrenListWidget.clear() self.childrenListWidget.UpdatePage(1, 1) self.childrenListWidget.UpdateState() if self.childrenListWidget.parentId == index: # self.childrenWidget.hide() self.childrenWidget.setParent(None) widget.gridLayout.removeWidget(self.childrenWidget) self.childrenListWidget.parentId = -1 item.setSizeHint(widget.sizeHint()) return if self.childrenListWidget.parentId >= 0: item2 = self.listWidget.item(self.childrenListWidget.parentId) widget2 = self.listWidget.itemWidget(item2) self.childrenWidget.setParent(None) widget2.gridLayout.removeWidget(self.childrenWidget) self.childrenListWidget.parentId = -1 item2.setSizeHint(widget2.sizeHint()) self.loadingForm.show() self.owner().qtTask.AddHttpTask(lambda x: Server().Send( req.GetCommentsChildrenReq(widget.id), bakParam=x), self.LoadCommentInfoBack, backParam=index, cleanFlag=self.closeFlag) def LoadCommentInfoBack(self, msg, index): try: self.loadingForm.close() item = self.listWidget.item(index) if not item: return widget = self.listWidget.itemWidget(item) if not widget: return self.childrenListWidget.UpdateState() data = json.loads(msg) self.childrenListWidget.parentId = index widget.gridLayout.addWidget(self.childrenWidget, 1, 0, 1, 1) if data.get("code") == 200: comments = data.get("data", {}).get("comments", {}) page = int(comments.get("page", 1)) total = int(comments.get("total", 1)) pages = int(comments.get("pages", 1)) limit = int(comments.get("limit", 1)) self.childrenListWidget.UpdatePage(page, pages) for index, info in enumerate(comments.get("docs")): floor = total - ((page - 1) * limit + index) content = info.get("content") name = info.get("_user", {}).get("name") avatar = info.get("_user", {}).get("avatar", {}) createdTime = info.get("created_at") commentsCount = info.get("commentsCount") likesCount = info.get("likesCount") commnetId = info.get('_id') self.childrenListWidget.AddUserItem( commnetId, commentsCount, likesCount, content, name, createdTime, floor, avatar.get("fileServer"), avatar.get("path"), avatar.get("originalName")) pass self.listWidget.scrollToItem( item, self.listWidget.ScrollHint.PositionAtTop) size = self.listWidget.size() item.setSizeHint(size) except Exception as es: Log.Error(es) def SendCommentChildren(self): data = self.commentLine2.text() if not data: return index = self.childrenListWidget.parentId item = self.listWidget.item(index) if not item: return widget = self.listWidget.itemWidget(item) if not widget: return self.commentLine2.setText("") commentId = widget.id self.loadingForm.show() self.childrenListWidget.clear() self.owner().qtTask.AddHttpTask(lambda x: Server().Send( req.SendCommentChildrenReq(commentId, data), bakParam=x), callBack=self.SendCommentChildrenBack, backParam=index) def SendCommentChildrenBack(self, msg, index): try: item = self.listWidget.item(index) if not item: self.loadingForm.close() return widget = self.listWidget.itemWidget(item) if not widget: self.loadingForm.close() return data = json.loads(msg) if data.get("code") == 200: self.owner().qtTask.AddHttpTask(lambda x: Server().Send( req.GetCommentsChildrenReq(widget.id), bakParam=x), self.LoadCommentInfoBack, backParam=index, cleanFlag=self.closeFlag) else: self.loadingForm.close() QtBubbleLabel.ShowErrorEx(self, data.get("message", "错误")) self.commentLine.setText("") except Exception as es: self.loadingForm.close() Log.Error(es) def LoadChildrenNextPage(self): index = self.childrenListWidget.parentId item = self.listWidget.item(index) if not item: return widget = self.listWidget.itemWidget(item) if not widget: return self.loadingForm.show() self.owner().qtTask.AddHttpTask( lambda x: Server().Send(req.GetCommentsChildrenReq( widget.id, self.childrenListWidget.page + 1), bakParam=x), self.LoadCommentInfoBack, backParam=index, cleanFlag=self.closeFlag) return def ClearCommnetList(self): if self.childrenListWidget.parentId >= 0: item2 = self.listWidget.item(self.childrenListWidget.parentId) widget2 = self.listWidget.itemWidget(item2) self.childrenWidget.setParent(None) widget2.gridLayout.removeWidget(self.childrenWidget) self.childrenListWidget.parentId = -1 item2.setSizeHint(widget2.sizeHint()) self.childrenListWidget.clear() self.listWidget.clear() def eventFilter(self, obj, event): if event.type() == QEvent.MouseButtonPress: if event.button() == Qt.LeftButton: if obj.pixmap() and not obj.text(): QtImgMgr().ShowImg(obj.pixmap()) return True else: return False else: return super(self.__class__, self).eventFilter(obj, event)
class QtMainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.userInfo = None self.setupUi(self) self.setWindowTitle("Waifu2x-Gui") self.msgForm = QtBubbleLabel(self) self.settingForm = QtSetting(self) self.settingForm.hide() self.settingForm.LoadSetting() self.aboutForm = QtAbout(self) self.img = QtImg() self.stackedWidget.addWidget(self.img) # self.resize(1000, 1000) self.menuabout.triggered.connect(self.OpenAbout) desktop = QGuiApplication.primaryScreen().geometry() # self.resize(desktop.width()//4*3, desktop.height()//4*3) # self.move(desktop.width()//8*1, desktop.height()//8*1) def closeEvent(self, a0: QtGui.QCloseEvent) -> None: super().closeEvent(a0) self.settingForm.ExitSaveSetting(self.size()) def RetranslateUi(self): self.settingForm.retranslateUi(self.settingForm) self.img.retranslateUi(self.img) self.aboutForm.retranslateUi(self.aboutForm) self.retranslateUi(self) def Init(self, app): self.settingForm.SetLanguage(app, self) if config.CanWaifu2x: from waifu2x_vulkan import waifu2x_vulkan stat = waifu2x_vulkan.init() if stat < 0: self.msgForm.ShowError("Waifu2x CPU Model") waifu2x_vulkan.setDebug(True) gpuInfo = waifu2x_vulkan.getGpuInfo() cpuNum = waifu2x_vulkan.getCpuCoreNum() self.settingForm.SetGpuInfos(gpuInfo, cpuNum) self.settingForm.exec() self.settingForm.SetLanguage(app, self) waifu2x_vulkan.initSet(config.Encode, config.UseCpuNum) self.img.gpuName.setText(config.EncodeGpu) Log.Info("waifu2x init: " + str(stat) + " encode: " + str(config.Encode) + " version:" + waifu2x_vulkan.getVersion()) # self.msgForm.ShowMsg("waifu2x初始化成功\n" + waifu2x.getVersion()) else: self.msgForm.ShowError("Waifu2x can not use, " + config.ErrorMsg) self.img.checkBox.setEnabled(False) self.img.changeJpg.setEnabled(False) self.img.changePng.setEnabled(False) self.img.comboBox.setEnabled(False) self.img.SetStatus(False) config.IsOpenWaifu = 0 return def OpenAbout(self, action): if action.text() == "about": self.aboutForm.show() pass
class BikaQtMainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.userInfo = None self.setupUi(self) self.setWindowTitle("哔咔漫画") self.msgForm = QtBubbleLabel(self) self.qtTask = QtTask() icon = QIcon() pic = QPixmap() pic.loadFromData(resources.DataMgr.GetData("logo_round")) icon.addPixmap(pic, QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.aboutForm = QtAbout(self) self.indexForm = QtIndex(self) self.searchForm = QtSearch(self) self.favoriteForm = QtFavorite(self) self.downloadForm = QtDownload(self) self.categoryForm = QtCategory(self) self.loadingForm = QtLoading(self) self.leaveMsgForm = QtLeaveMsg(self) self.chatForm = QtChat(self) self.rankForm = QtRank(self) self.loginForm = QtLogin(self) self.registerForm = QtRegister(self) self.historyForm = QtHistory(self) self.qtReadImg = QtReadImg(self) self.userForm = QtUser(self) self.bookInfoForm = QtBookInfo(self) self.epsInfoForm = QtEpsInfo(self) self.task = QtTask() self.task.SetOwner(self) self.timer = QTimer(self) self.timer.setInterval(100) # self.timer.timeout.connect(self.OnTimeOut) # self.timer.start() self.stackedWidget.addWidget(self.loginForm) self.stackedWidget.addWidget(self.userForm) self.settingForm = QtSetting(self) self.settingForm.LoadSetting() self.resize(self.settingForm.mainSize) self.bookInfoForm.resize(self.settingForm.bookSize) self.qtReadImg.resize(self.settingForm.readSize) self.loginForm.userIdEdit.setText(self.settingForm.userId) self.loginForm.passwdEdit.setText(self.settingForm.passwd) self.menusetting.triggered.connect(self.OpenSetting) self.menuabout.triggered.connect(self.OpenAbout) # def ClearExpiredCache(self): # try: # toPath = os.path.join(config.SavePath, config.CachePathDir) # for root, dirs, names in os.walk(toPath): # for name in names: # isDel = False # filename = os.path.join(root, name) # with open(filename, "rb") as f: # nameSize = int().from_bytes(f.read(2), byteorder='little') # timeTick = int().from_bytes(f.read(4), byteorder='little') # # if int(time.time()) - timeTick >= config.CacheExpired: # # isDel = True # # if isDel: # os.remove(filename) # # except Exception as es: # Log.Error(es) # def OnTimeOut(self): # self.task.run() def closeEvent(self, a0: QtGui.QCloseEvent) -> None: super().closeEvent(a0) userId = self.loginForm.userIdEdit.text() passwd = self.loginForm.passwdEdit.text() self.bookInfoForm.close() self.settingForm.ExitSaveSetting(self.size(), self.bookInfoForm.size(), self.qtReadImg.size(), userId, passwd) def Init(self): if config.CanWaifu2x: import waifu2x stat = waifu2x.Init(config.Encode, config.Waifu2xThread) if stat < 0: self.msgForm.ShowError("waifu2x初始化错误") gpuInfo = waifu2x.GetGpuInfo() if gpuInfo: self.settingForm.SetGpuInfos(gpuInfo) Log.Info("waifu2x初始化: " + str(stat) + " encode: " + str(config.Encode)) else: 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.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 self.InitUpdate() self.loginForm.Init() return def OpenSetting(self): self.settingForm.show() pass def OpenAbout(self, action): if action.text() == "about": self.aboutForm.show() elif action.text() == "img convert": QtImgMgr().ShowImg("") pass def InitUpdate(self): self.qtTask.AddHttpTask(lambda x: Server().Send(req.CheckUpdateReq(), bakParam=x), self.InitUpdateBack) def InitUpdateBack(self, data): try: r = QMessageBox.information(self, "更新", "当前版本{} ,检查到更新,是否前往更新\n{}".format(config.UpdateVersion, data), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if r == QMessageBox.Yes: QDesktopServices.openUrl(QUrl(config.UpdateUrl2)) except Exception as es: Log.Error(es)
def CopyPicture(self): clipboard = QApplication.clipboard() clipboard.setPixmap(self.pixMap) QtBubbleLabel.ShowMsgEx(self, "复制成功") return