def search_epub_content(self): ''' Search epub content ''' # reset results layout self.search_results.clear() # get search input keyword = self.search_input.text() # search in each book db = self.db.new_api matched_ids = {book_id for book_id in db.all_book_ids() if 'EPUB' in db.formats(book_id)} for book_id in matched_ids: mi = db.get_metadata(book_id, get_cover=False, cover_as_data=False) if prefs['tags'] in mi.tags: title = mi.title filepath = fmt_path = self.gui.current_db.format_abspath(book_id, 'EPUB', index_is_id=True) grep = EpubGrep(keyword) grep.setPreview(True) grep_result = grep.searchin(filepath) #print(grep_result) if grep_result != None and len(grep_result) != 0: widgetLayout = QVBoxLayout() book_button = QPushButton(title, self) book_button.clicked.connect(partial(self.view, book_id, 0)) widgetLayout.addWidget(book_button) widgetLayout.setSizeConstraint(QLayout.SetFixedSize) widget = QWidget() widget.setLayout(widgetLayout) widgetItem = QListWidgetItem() widgetItem.setSizeHint(widget.sizeHint()) self.search_results.addItem(widgetItem) self.search_results.setItemWidget(widgetItem, widget) #matched = result.stdout.decode('utf-8') matched = grep_result search_result_count = 0 if prefs['search_result_count'] == '' else int(prefs['search_result_count']) count = 0 for lines in matched.split('--\n'): # only handles results within limit if search_result_count != 0 and count >= search_result_count: break widgetLayout = QVBoxLayout() qLabel = QLabel(lines.replace(keyword, '<font color=yellow>' + keyword + '</font>').replace('\n\n', '\n').replace('\n','<br/>') + '<br/>') qLabel.setTextFormat(Qt.RichText) qLabel.setStyleSheet(''' font-size: 24px; ''') widgetLayout.addWidget(qLabel) widgetLayout.setSizeConstraint(QLayout.SetFixedSize) widget = QWidget() widget.setLayout(widgetLayout) widgetItem = QListWidgetItem() widgetItem.setSizeHint(widget.sizeHint()) widgetItem.setData(Qt.ItemDataRole.UserRole, (book_id, count)) self.search_results.addItem(widgetItem) self.search_results.setItemWidget(widgetItem, widget) count += 1 self.search_results.itemClicked.connect(self.view_search_result)
def set_qpb_list_item(self, channel_id, lbp): item = QListWidgetItem(self.qpb_list_widget) item.setSizeHint(QSize(400, 80)) widget = QWidget(self.qpb_list_widget) v_layout = QVBoxLayout() label = QLabel(channel_id + "==>>>等待出包...") v_layout.addWidget(label) lbp['label'] = label qpb = QProgressBar(self.qpb_list_widget) v_layout.addWidget(qpb) lbp['qpb'] = qpb widget.setLayout(v_layout) self.qpb_list_widget.addItem(item) self.qpb_list_widget.setItemWidget(item, widget)
def addItem(self, collection): item = QListWidgetItem(self.collectionList) item.setSizeHint(QSize(36, CLOSED_SIZE)) self.collectionList.addItem(item) self.collectionList.setItemWidget( item, CollectionItem(self, collection, item))
def addItem(self, collection): item = QListWidgetItem(self.collectionList) item.setSizeHint(QSize(36, CLOSED_SIZE)) self.collectionList.addItem(item) self.collectionList.setItemWidget(item, CollectionItem(self, collection, item))