Exemplo n.º 1
0
class QtChat(QtWidgets.QWidget):
    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.InitUser()
        self.gridLayout.addWidget(self.listWidget)
        self.closeFlag = self.__class__.__name__
        self.listWidget.doubleClicked.connect(self.OpenChatRoom)
        self.chatRoom = QtChatRoom()

    def SwitchCurrent(self):
        if self.listWidget.count() > 0:
            return
        QtTask().AddHttpTask(
            lambda x: Server().Send(req.GetChatReq(), bakParam=x),
            self.GetChatBack, cleanFlag=self.closeFlag)
        return

    def GetChatBack(self, data):
        try:
            data = json.loads(data)
            if data.get("code") == 200:
                infos = data.get("data", {}).get("chatList", {})
                for index, info in enumerate(infos):
                    name = info.get("title")
                    content = info.get("description")
                    # avatar = info.get("_user", {}).get("avatar", {})
                    # createdTime = info.get("created_at")
                    self.listWidget.AddUserItem(info.get("url"), "", "", content, name, "", index+1,
                                                info.get("avatar"),
                                                "", "")
        except Exception as es:
            Log.Error(es)
        return

    def OpenChatRoom(self, modelIndex):
        index = modelIndex.row()
        item = self.listWidget.item(index)
        if not item:
            return
        widget = self.listWidget.itemWidget(item)
        if not widget:
            return
        self.chatRoom.OpenChat(widget.id, widget.nameLabel.text())
Exemplo n.º 2
0
class QtCategory(QtWidgets.QWidget, Ui_category):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_category.__init__(self)
        self.setupUi(self)
        self.owner = weakref.ref(owner)
        self.bookList = QtBookList(self, self.__class__.__name__)
        self.bookList.InitBook()
        self.gridLayout_2.addWidget(self.bookList)
        self.bookList.doubleClicked.connect(self.OpenSearch)

    def SwitchCurrent(self):
        if self.bookList.count() <= 0:
            self.owner().loadingForm.show()
            self.owner().qtTask.AddHttpTask(
                lambda x: CateGoryMgr().UpdateCateGory(x),
                callBack=self.InitCateGoryBack)
        pass

    def InitCateGoryBack(self, msg):
        self.owner().loadingForm.close()
        if msg == Status.Ok:
            for index, info in enumerate(CateGoryMgr().idToCateGoryBase):
                url = info.thumb.get("fileServer")
                path = info.thumb.get("path")
                originalName = info.thumb.get("originalName")
                _id = info.id
                self.bookList.AddBookItem(_id, info.title, "", url, path,
                                          originalName)
            self.owner().searchForm.InitCheckBox()
        return

    def OpenSearch(self, modelIndex):
        index = modelIndex.row()
        item = self.bookList.item(index)
        widget = self.bookList.itemWidget(item)
        text = widget.label.text()
        self.owner().userForm.listWidget.setCurrentRow(1)
        self.owner().searchForm.searchEdit.setText("")
        self.owner().searchForm.OpenSearchCategories(text)
        pass
Exemplo n.º 3
0
class QtIndex(QtWidgets.QWidget, Ui_Index):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_Index.__init__(self)
        self.setupUi(self)
        self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.owner = weakref.ref(owner)
        self.isInit = False
        self.bookList1 = QtBookList(self, "1", owner)
        self.bookList1.InitBook()
        self.horizontalLayout.addWidget(self.bookList1)
        self.bookList1.doubleClicked.connect(self.OpenSearch1)
        self.bookList2 = QtBookList(self, "2", owner)
        self.bookList2.InitBook()
        self.bookList2.doubleClicked.connect(self.OpenSearch2)
        self.horizontalLayout_2.addWidget(self.bookList2)

        self.bookList3 = QtBookList(self, "3", owner)
        self.bookList3.InitBook()
        self.bookList3.doubleClicked.connect(self.OpenSearch3)
        self.horizontalLayout_3.addWidget(self.bookList3)
        p = QPixmap()
        p.loadFromData(DataMgr().GetData("fold2"))
        q = QPixmap()
        q.loadFromData(DataMgr().GetData("fold1"))
        self.toolButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolButton.setIcon(QIcon(p))
        self.bookList1.setVisible(False)
        self.toolButton_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolButton_2.setIcon(QIcon(p))
        self.bookList2.setVisible(False)
        self.toolButton_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolButton_3.setIcon(QIcon(q))
        self.bookList3.setVisible(True)

        self.toolButton.clicked.connect(self.SwitchButton1)
        self.toolButton_2.clicked.connect(self.SwitchButton2)
        self.toolButton_3.clicked.connect(self.SwitchButton3)

    def SwitchCurrent(self):
        if User().token:
            self.Init()
            if not self.bookList3.count():
                self.InitRandom()
        pass

    def Init(self):
        self.isInit = True
        self.owner().loadingForm.show()
        self.owner().qtTask.AddHttpTask(
            lambda x: Server().Send(req.GetCollectionsReq(), bakParam=x),
            self.InitBack)

    def InitRandom(self):
        self.owner().loadingForm.show()
        self.owner().qtTask.AddHttpTask(
            lambda x: Server().Send(req.GetRandomReq(), bakParam=x),
            self.InitRandomBack)

    def InitBack(self, data):
        try:
            self.owner().loadingForm.close()
            self.bookList1.clear()
            self.bookList2.clear()
            data = json.loads(data)
            for categroys in data.get("data").get("collections"):
                if categroys.get("title") == "本子神推薦":
                    bookList = self.bookList1
                else:
                    bookList = self.bookList2
                for v in categroys.get('comics'):
                    title = v.get("title", "")
                    _id = v.get("_id")
                    url = v.get("thumb", {}).get("fileServer")
                    path = v.get("thumb", {}).get("path")
                    originalName = v.get("thumb", {}).get("originalName")
                    info = "完本," if v.get("finished") else ""
                    info += "{}E/{}P".format(str(v.get("epsCount")),
                                             str(v.get("pagesCount")))
                    bookList.AddBookItem(_id, title, info, url, path,
                                         originalName)
        except Exception as es:
            Log.Error(es)
            self.isInit = False

    def InitRandomBack(self, data):
        try:
            self.owner().loadingForm.close()
            data = json.loads(data)
            self.bookList3.clear()
            for v in data.get("data").get('comics'):
                bookList = self.bookList3
                title = v.get("title", "")
                _id = v.get("_id")
                url = v.get("thumb", {}).get("fileServer")
                path = v.get("thumb", {}).get("path")
                originalName = v.get("thumb", {}).get("originalName")
                info = "完本," if v.get("finished") else ""
                info += "{}E/{}P".format(str(v.get("epsCount")),
                                         str(v.get("pagesCount")))
                bookList.AddBookItem(_id, title, info, url, path, originalName)
        except Exception as es:
            Log.Error(es)

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

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

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

    def SwitchButton1(self):
        isVisible = self.bookList1.isVisible()
        self.bookList1.setVisible(not isVisible)
        p = QPixmap()
        if isVisible:
            p.loadFromData(DataMgr().GetData("fold2"))
        else:
            p.loadFromData(DataMgr().GetData("fold1"))
        self.toolButton.setIcon(QIcon(p))
        return

    def SwitchButton2(self):
        isVisible = self.bookList2.isVisible()
        self.bookList2.setVisible(not isVisible)
        p = QPixmap()
        if isVisible:
            p.loadFromData(DataMgr().GetData("fold2"))
        else:
            p.loadFromData(DataMgr().GetData("fold1"))
        self.toolButton_2.setIcon(QIcon(p))

        return

    def SwitchButton3(self):
        isVisible = self.bookList3.isVisible()
        self.bookList3.setVisible(not isVisible)
        p = QPixmap()
        if isVisible:
            p.loadFromData(DataMgr().GetData("fold2"))
        else:
            p.loadFromData(DataMgr().GetData("fold1"))
        self.toolButton_3.setIcon(QIcon(p))
        return
Exemplo n.º 4
0
class QtSearch(QtWidgets.QWidget, Ui_search):
    def __init__(self, owner):
        super(self.__class__, self).__init__(owner)
        Ui_search.__init__(self)
        self.setupUi(self)
        self.owner = weakref.ref(owner)
        self.index = 1
        self.data = ""
        self.bookList = QtBookList(self, self.__class__.__name__, owner)
        self.bookList.InitBook(self.LoadNextPage)

        self.bookLayout.addWidget(self.bookList)
        self.bookList.doubleClicked.connect(self.OpenSearch)
        self.categories = ""
        self.jumpLine.setValidator(QtIntLimit(1, 1, self))

        self.categoryList = QtCategoryList(self)
        layouy = QtWidgets.QHBoxLayout()
        layouy.addWidget(QLabel("屏蔽:"))
        layouy.addWidget(self.categoryList)
        self.bookLayout.addLayout(layouy, 1, 0)
        for name in ["耽美", "偽娘", "禁書", "扶她", "重口", "生肉", "純愛", "WEBTOON"]:
            self.categoryList.AddItem(name)
        self.categoryList.itemClicked.connect(self.ClickCategoryListItem)

        self.keywordList = QtCategoryList(self)
        layouy = QtWidgets.QHBoxLayout()
        layouy.addWidget(QLabel("大家都在搜:"))
        layouy.addWidget(self.keywordList)
        self.bookLayout.addLayout(layouy, 2, 0)
        self.keywordList.itemClicked.connect(self.ClickKeywordListItem)

    def SwitchCurrent(self):
        pass

    def InitCheckBox(self):
        # TODO 分类标签有点问题 暂时不显示
        return
        size = len(CateGoryMgr().idToCateGoryBase)
        hBoxLayout = QtWidgets.QHBoxLayout(self)
        a = QCheckBox("全部分类", self.groupBox)
        hBoxLayout.addWidget(a)

        for index, info in enumerate(CateGoryMgr().idToCateGoryBase, 2):
            if index % 9 == 0:
                self.comboBoxLayout.addLayout(hBoxLayout)
                hBoxLayout = QtWidgets.QHBoxLayout(self)
            a = QCheckBox(info.title, self.groupBox)
            hBoxLayout.addWidget(a)
        self.comboBoxLayout.addLayout(hBoxLayout)
        return

    def Search(self, categories=None):
        data = self.searchEdit.text()
        self.data = data
        if len(data) == len("5822a6e3ad7ede654696e482"):
            self.owner().bookInfoForm.OpenBook(data)
            return
        if not data:
            return
        if not categories:
            self.categories = []
        else:
            pass
        self.categories = ""
        self.bookList.clear()
        self.bookList.UpdatePage(1, 1)
        self.bookList.UpdateState()
        self.searchEdit.setPlaceholderText("")
        self.SendSearch(self.data, 1)

    def SendSearch(self, data, page):
        self.owner().loadingForm.show()
        self.index = 1
        sort = ["dd", "da", "ld", "vd"]
        sortId = sort[self.comboBox.currentIndex()]
        self.owner().qtTask.AddHttpTask(lambda x: Server().Send(req.AdvancedSearchReq(page, [], data, sortId), bakParam=x), self.SendSearchBack)

    def OpenSearchCategories(self, categories):
        self.bookList.clear()
        self.categories = categories
        self.searchEdit.setPlaceholderText(categories)
        self.bookList.UpdatePage(1, 1)
        self.bookList.UpdateState()
        self.SendSearchCategories(1)

    def SendSearchCategories(self, page):
        self.owner().loadingForm.show()
        # TODO 搜索和分类检索不太一样,切页时会有点问题
        sort = ["dd", "da", "ld", "vd"]
        sortId = sort[self.comboBox.currentIndex()]
        self.owner().qtTask.AddHttpTask(
            lambda x: Server().Send(req.CategoriesSearchReq(page, self.categories, sortId), bakParam=x),
            self.SendSearchBack)

    def InitKeyWord(self):
        self.owner().qtTask.AddHttpTask(
            lambda x: Server().Send(req.GetKeywords(), bakParam=x), self.SendKeywordBack)

    def SendSearchBack(self, raw):
        self.owner().loadingForm.close()
        try:
            self.bookList.UpdateState()
            data = json.loads(raw)
            if data.get("code") == 200:
                info = data.get("data").get("comics")
                page = int(info.get("page"))
                pages = int(info.get("pages"))
                self.bookList.UpdatePage(page, pages)
                self.jumpLine.setValidator(QtIntLimit(1, pages, self))
                pageText = "页:" + str(self.bookList.page) + "/" + str(self.bookList.pages)
                self.label.setText(pageText)
                for v in info.get("docs", []):
                    title = v.get("title", "")
                    _id = v.get("_id")
                    url = v.get("thumb", {}).get("fileServer")
                    path = v.get("thumb", {}).get("path")
                    originalName = v.get("thumb", {}).get("originalName")
                    info2 = "完本," if v.get("finished") else ""
                    info2 += "{}E/{}P".format(str(v.get("epsCount")), str(v.get("pagesCount")))
                    param = ",".join(v.get("categories"))
                    self.bookList.AddBookItem(_id, title, info2, url, path, param)
                self.CheckCategoryShowItem()
            else:
                # QtWidgets.QMessageBox.information(self, '未搜索到结果', "未搜索到结果", QtWidgets.QMessageBox.Yes)
                self.owner().msgForm.ShowError("未搜索到结果")
        except Exception as es:
            Log.Error(es)
        pass

    def SendKeywordBack(self, raw):
        try:
            data = json.loads(raw)
            if data.get("code") == 200:
                self.keywordList.clear()
                for keyword in data.get('data', {}).get("keywords", []):
                    self.keywordList.AddItem(keyword)
                pass
            else:
                pass
        except Exception as es:
            Log.Error(es)
        pass

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

    def JumpPage(self):
        page = int(self.jumpLine.text())
        if page > self.bookList.pages:
            return
        self.bookList.page = page
        self.bookList.clear()
        if not self.categories:
            self.SendSearch(self.data, page)
        else:
            self.SendSearchCategories(page)
        return

    def LoadNextPage(self):
        if not self.categories:
            self.SendSearch(self.data, self.bookList.page + 1)
        else:
            self.SendSearchCategories(self.bookList.page + 1)
        return

    def ChangeSort(self, pos):
        self.bookList.page = 1
        self.bookList.clear()
        if not self.categories:
            self.SendSearch(self.data, 1)
        else:
            self.SendSearchCategories(1)

    def ClickCategoryListItem(self, item):
        isClick = self.categoryList.ClickItem(item)
        data = item.text()
        if isClick:
            self.owner().msgForm.ShowMsg("屏蔽" + data)
        else:
            self.owner().msgForm.ShowMsg("取消屏蔽" + data)
        self.CheckCategoryShowItem()

    def CheckCategoryShowItem(self):
        data = self.categoryList.GetAllSelectItem()
        for i in range(self.bookList.count()):
            item = self.bookList.item(i)
            widget = self.bookList.itemWidget(item)
            isHidden = False
            for name in data:
                if name in widget.param:
                    item.setHidden(True)
                    isHidden = True
                    break
            if not isHidden:
                item.setHidden(False)

    def ClickKeywordListItem(self, item):
        data = item.text()
        self.searchEdit.setText(data)
        self.Search()