def __init__(self, parent=None): super().__init__() QPixmapCache.setCacheLimit(app_constants.THUMBNAIL_CACHE_SIZE[0]* app_constants.THUMBNAIL_CACHE_SIZE[1]) self._painted_indexes = {} #misc.FileIcon.refresh_default_icon() self.file_icons = misc.FileIcon() if app_constants.USE_EXTERNAL_VIEWER: self.external_icon = self.file_icons.get_external_file_icon() else: self.external_icon = self.file_icons.get_default_file_icon() self.font_size = app_constants.GALLERY_FONT[1] self.font_name = app_constants.GALLERY_FONT[0] if not self.font_name: self.font_name = QWidget().font().family() self.title_font = QFont() self.title_font.setBold(True) self.title_font.setFamily(self.font_name) self.artist_font = QFont() self.artist_font.setFamily(self.font_name) if self.font_size is not 0: self.title_font.setPixelSize(self.font_size) self.artist_font.setPixelSize(self.font_size) self.title_font_m = QFontMetrics(self.title_font) self.artist_font_m = QFontMetrics(self.artist_font) t_h = self.title_font_m.height() a_h = self.artist_font_m.height() self.text_label_h = a_h + t_h * 2 self.W = app_constants.THUMB_W_SIZE self.H = app_constants.THUMB_H_SIZE + app_constants.GRIDBOX_LBL_H#self.text_label_h #+ app_constants.GRIDBOX_LBL_H
def find_or_get(path): pixmap = QPixmapCache.find(path) if pixmap is None: pixmap = QPixmap(path) QPixmapCache.insert(path, pixmap) return pixmap return pixmap
def __init__(self, path): super(Image, self).__init__() pix = QPixmap(path) QPixmapCache.insert(path, pix) self.setPixmap(pix)
def on_load_slide(self): file_path = self.open_file_name_dialog() if file_path: # self.slide_viewer.load_slide(file_path, start_level=1, start_image_rect=QRectF(1000, 1000, 1000, 1000)) slide_view_params = SlideViewParams(file_path) self.slide_viewer.load(slide_view_params) QPixmapCache.clear()
def __init__(self, parent=None): super().__init__(parent) QPixmapCache.setCacheLimit(app_constants.THUMBNAIL_CACHE_SIZE[0]* app_constants.THUMBNAIL_CACHE_SIZE[1]) self._painted_indexes = {} #misc.FileIcon.refresh_default_icon() self.file_icons = misc.FileIcon() if app_constants.USE_EXTERNAL_VIEWER: self.external_icon = self.file_icons.get_external_file_icon() else: self.external_icon = self.file_icons.get_default_file_icon() self.font_size = app_constants.GALLERY_FONT[1] self.font_name =0 # app_constants.GALLERY_FONT[0] if not self.font_name: self.font_name = QWidget().font().family() self.title_font = QFont() self.title_font.setBold(True) self.title_font.setFamily(self.font_name) self.artist_font = QFont() self.artist_font.setFamily(self.font_name) if self.font_size is not 0: self.title_font.setPixelSize(self.font_size) self.artist_font.setPixelSize(self.font_size) self.title_font_m = QFontMetrics(self.title_font) self.artist_font_m = QFontMetrics(self.artist_font) t_h = self.title_font_m.height() a_h = self.artist_font_m.height() self.text_label_h = a_h + t_h * 2 self.W = app_constants.THUMB_W_SIZE self.H = app_constants.THUMB_H_SIZE + app_constants.GRIDBOX_LBL_H#self.text_label_h #+ app_constants.GRIDBOX_LBL_H
def load_slide(self, file_path): viewer = SlideViewerWidget() viewer.slide_viewer.load(SlideViewParams(file_path)) file_name = os.path.basename(file_path) self.tabWidget.addTab(viewer, file_name) self.slide_list.add_item(file_name) QPixmapCache.clear()
def previousPage(self): ''' 切换到上一页画布 :return: ''' if self.isWritten or (self.page == self.pages): # 当前页有输入或改动则保存当前页 self.savePicture(True) # self.pos_pages[self.page] = self.pos_xyc # 记录当前页笔画路径 self.isWritten = False # 关闭改动标志 if self.page > 1: # 当前页码非第一页 self.page -= 1 # 当前页码减一 fileName = str(self.page) readFileName = os.path.join(self.filePath, 'temp', fileName + '.jpg') QPixmapCache.clear() # 清空画布 self.pix.load(readFileName) # self.pos_xyc = self.pos_pages[self.page] else: # 当前页码为第一页 pass self.update() # 更新内容 print('下一页6') # self.setWindowTitle('当前' + str(self.page) + '/' + str(self.pages) + '页') # 更新标题栏显示的页码 # t_changName = threading.Thread(target=self.changeWinName, args=(self.page, self.pages,)) # t_changName.start() logger.debug('上翻页第%s页', self.page)
def findIcon(self, name=str, size=int): for _name in name: pixmapName = ''.join(('$qt', str(_name), str(size))) self.pixmap = QPixmapCache.find(pixmapName) if (self.pixmap): logging.debug('Icon %s returned from cache' % _name) return self.pixmap self._themes = [] if self.themeName: self._themes.append(self.themeName) for _name in name: self.pixmap = self.findIconHelper(int(size), self.themeName, _name) if not self.pixmap.isNull(): break if self.pixmap.isNull(): for _name in name: self._themes.extend(self.themeIndex.parents) if len(self._themes) > 0: self.pixmap = self.findIconHelper(int(size), self._themes[0], _name) if not self.pixmap.isNull(): break if not name: return QPixmap() pixmapName = ''.join(('$qt', str(_name), str(size))) if not self.pixmap.isNull(): logging.debug('Icon cached with name: %s ' % pixmapName) QPixmapCache.insert(pixmapName, self.pixmap) return self.pixmap
def addOnePixmaptoForm(self, item: picInfo): QPixmapCache.clear() if 'pixcount' not in self.__dict__: self.pixcount = 1 else: self.pixcount += 1 logging.getLogger().debug("得到一个图片信息准备加载:{}".format(self.pixcount)) obj = None pItem = None if item.viewPixmap: obj = item.viewPixmap self.viewPicInfos.append(item) pItem = QListWidgetItem( QIcon( obj.scaled(self.icoSize, Qt.KeepAspectRatio, Qt.SmoothTransformation)), '') elif item.viewPixmap_Ico: obj = item.viewPixmap_Ico pItem = QListWidgetItem( QIcon( obj.scaled(self.icoSize, Qt.KeepAspectRatio, Qt.SmoothTransformation)), '') pItem.setSizeHint(self.pdfPageSize) pItem.picInfo = item pItem.setToolTip(item.originalName) pItem.setText(item.icoText if item.icoText else item.originalName) self.ui.listWidget.addItem(pItem) QGuiApplication.processEvents()
def _apply(self): """使用当前的style""" preferences = Preferences.instance() application_style = preferences.application_style() if application_style == ApplicationStyle.FusionStyle: desired_style = "fusion" desired_palette = create_palette(preferences.base_color(), preferences.selection_color()) elif application_style == ApplicationStyle.LRSMStyle: desired_style = "lsrm" desired_palette = create_palette(preferences.base_color(), preferences.selection_color()) else: desired_style = self.default_style() desired_palette = self.default_palette() if QApplication.style().objectName() != desired_style: if desired_style == "lsrm": style = QStyleFactory.create("fusion") style = LRSMProxyStyle(desired_palette, style) else: style = QStyleFactory.create(desired_style) QApplication.setStyle(style) if QApplication.palette() != desired_palette: QPixmapCache.clear() QApplication.setPalette(desired_palette) style = QApplication.style() if isinstance(style, LRSMProxyStyle): style.set_palette(desired_palette) self.style_applied_signal.emit()
def findIcon(self, name = str, size = int): for _name in name: pixmapName = ''.join(('$qt', str(_name), str(size))) if (QPixmapCache.find(pixmapName, self.pixmap)): logging.debug('Icon %s returned from cache' % _name) return self.pixmap self._themes = [] if self.themeName: self._themes.append(self.themeName) for _name in name: self.pixmap = self.findIconHelper(int(size), self.themeName, _name) if not self.pixmap.isNull(): break if self.pixmap.isNull(): for _name in name: self._themes.extend(self.themeIndex.parents) if len(self._themes) > 0: self.pixmap = self.findIconHelper(int(size), self._themes[0] ,_name) if not self.pixmap.isNull(): break if not name: return QPixmap() pixmapName = ''.join(('$qt', str(_name), str(size))) if not self.pixmap.isNull(): logging.debug('Icon cached with name: %s ' % pixmapName) QPixmapCache.insert(pixmapName, self.pixmap) return self.pixmap
def createEveryPixmapFromFile(self): for i, r in enumerate(self.addtionalData): if r.deleted: continue ################################# # 找到要显示文件的真实路径(数据库中已经存在的和新添加的不同,用于防止用户重复添加同一文件) filePath = r.md5FilePath if (r.archives_pk) else r.original_path if os.path.exists(filePath): QPixmapCache.clear() expName = r.file_type.upper() docDic = { "XLS": 0, "XLSX": 0, "DOC": 1, "DOCX": 1, "ZIP": 2, "RAR": 3 } icoLst = ["excel.png", "word.png", "zip.png", "rar.png"] if expName in docDic.keys(): pi = picInfo() icoName = icoLst[docDic[expName]] pi.iconPath = self.pub.getIcoPath(icoName) pi.originalPath = filePath pi.originalName = r.original_name pi.md5FileName = r.md5FileName pi.viewPixmap_Ico = QPixmap(pi.iconPath) self.onePixmCreated.emit(pi) elif expName in ["JPG", "PNG", "BMP"]: pi = picInfo() pi.originalPath = r.original_path pi.viewPicPath = r.original_path pi.originalName = r.original_name pi.md5FileName = r.md5FileName pi.viewPicPath = r.md5FilePath pi.viewPixmap = QPixmap(r.md5FilePath) self.onePixmCreated.emit(pi) elif expName == "PDF": doc = fitz.open(filePath) # 当PDF页数过多时,只显示图标 if doc.pageCount > self.maxViewPdfPages: pi = picInfo() pi.iconPath = self.pub.getIcoPath('pdf_2.png') pi.originalPath = filePath pi.originalName = r.original_name pi.md5FileName = r.md5FileName pi.viewPixmap_Ico = QPixmap(pi.iconPath) self.onePixmCreated.emit(pi) else: for i in range(doc.pageCount): pageData = doc.loadPage(i) pi = self.render_pdf_page(pageData, r, i) self.onePixmCreated.emit(pi) doc.close() del doc else: logging.getLogger().error("文件没有找到:{}".format(filePath)) self.oneFileLoaded.emit(r.original_name)
def update_plot(self): QPixmapCache.clear() # Get contours self.cv2_image = cv2.imread(self.image_path) if not self.select_contours.isChecked(): self.contours = mcf(image=self.cv2_image, k_blur=2 * self.k_blur.value() - 1, C=self.C.value(), blocksize=2 * self.blocksize.value() - 1, k_laplacian=2 * self.k_laplacian.value() - 1, k_dilate=2 * self.k_dilate.value() - 1, k_gradient=2 * self.k_gradient.value() - 1, k_foreground=2 * self.k_foreground.value() - 1, skip_flood=True) # Set min/max contour size try: Amin = int(self.Amin.text()) except ValueError: Amin = int(1) try: Amax = int(self.Amax.text()) except ValueError: Amax = int(self.__originalH__ * self.__originalW__) # Refine contours self.large_contours = contour_size_selection(self.contours, Amin=Amin, Amax=Amax) if self.use_approxPolys.isChecked(): self.large_contours = [ cv2.approxPolyDP(curve=c, epsilon=self.epsilon.value(), closed=True) for c in self.large_contours ] if self.use_convexHulls.isChecked(): self.large_contours = [ cv2.convexHull(c) for c in self.large_contours ] cv2.drawContours(self.cv2_image, contours=self.large_contours, contourIdx=-1, color=self.contour_color, thickness=self.contour_thickness.value()) if len(self.highlighted) > 0: cv2.drawContours(self.cv2_image, contours=self.highlighted, contourIdx=-1, color=self.highlight_color, thickness=self.contour_thickness.value()) cv2.circle(self.cv2_image, (self.click_x, self.click_y), 10, (0, 0, 255), -1) # Convert to QImage self.np_image = cv2.cvtColor(self.cv2_image, cv2.COLOR_BGR2RGB) self.qimage = QImage(self.np_image, self.np_image.shape[1], self.np_image.shape[0], self.bytesPerLine, QImage.Format_RGB888) self.pixmap = QPixmap(self.qimage) self.viewer.setPhoto(self.pixmap)
def paint(self, painter: QtGui.QPainter, option: QStyleOptionViewItem, index: QtCore.QModelIndex) -> None: item_size = option.rect.size() custom_decoration_w, custom_decoration_h = index.data( SlideListModel.DecorationSizeOrRatioRole) if option.decorationPosition == QStyleOptionViewItem.Left: text_x, text_y = custom_decoration_w + self.icon_and_text_spacing, 0 text_width = item_size.width( ) - custom_decoration_w - self.icon_and_text_spacing text_height = custom_decoration_h elif option.decorationPosition == QStyleOptionViewItem.Top: text_size = super().sizeHint(option, index) custom_decoration_h = custom_decoration_h - text_size.height() text_x, text_y = 0, custom_decoration_h + self.icon_and_text_spacing text_width = custom_decoration_w text_height = item_size.height( ) - custom_decoration_h - self.icon_and_text_spacing slide_view_params: SlideViewParams = index.data( SlideListModel.SlideViewParamsRole) scene_rect = QRectF(*slide_view_params.level_rect) img_key = "{}_{}_{}".format(custom_decoration_w, custom_decoration_h, slide_view_params.cache_key()) icon_pixmap = QPixmapCache.find(img_key) if icon_pixmap is None: slide_helper = SlideHelper(slide_view_params.slide_path) # print("read", img_key) scene = QGraphicsScene() # t1 = elapsed() # print("before slide_graphics", t1) slide_graphics = SlideGraphicsGroup(slide_view_params) # t2 = elapsed() # print("slide_graphics", t2 - t1) scene.clear() scene.invalidate() scene.addItem(slide_graphics) slide_graphics.update_visible_level(slide_view_params.level) scene.setSceneRect( slide_helper.get_rect_for_level(slide_view_params.level)) image = build_screenshot_image( scene, QSize(custom_decoration_w, custom_decoration_h), scene_rect) # t3 = elapsed() # print("build_screenshot_image", t3 - t2) icon_pixmap = QtGui.QPixmap.fromImage(image) QPixmapCache.insert(img_key, icon_pixmap) # t4 = elapsed() painter.fillRect(option.rect, painter.background()) painter.drawPixmap(option.rect.topLeft(), icon_pixmap) # painter.drawRect(option.rect) painter.drawRect(option.rect.topLeft().x(), option.rect.topLeft().y(), icon_pixmap.width(), icon_pixmap.height()) option.rect = option.rect.translated(text_x, text_y) option.rect.setSize(QSize(text_width, text_height)) super().paint(painter, option, index)
def main(): app = QApplication(sys.argv) QPixmapCache.setCacheLimit(cache_size_in_kb) QPixmapCache.clear() win = CbirMainWindow() win.showMaximized() # win.showFullScreen() win.after_show() sys.exit(app.exec_())
def __init__(self) -> None: # Allow Ctrl-C killing of the Qt app, see: # http://stackoverflow.com/questions/4938723/ signal.signal(signal.SIGINT, signal.SIG_DFL) self.cache_dir = os.path.join(xdg.BaseDirectory.xdg_cache_home, "dt-fileview") self.config_dir = os.path.join(xdg.BaseDirectory.xdg_config_home, "dt-fileview") self.config_file = os.path.join(self.config_dir, "config.ini") if not os.path.isdir(self.config_dir): os.makedirs(self.config_dir) self.stream_dir = os.path.join(self.cache_dir, "streams") if not os.path.isdir(self.stream_dir): os.makedirs(self.stream_dir) logging_config = os.path.join(self.config_dir, "logging.ini") if os.path.exists(logging_config): print("loading logger config from: {}".format(logging_config)) try: logging.config.fileConfig(logging_config, defaults=None, disable_existing_loggers=False) except Exception as err: print(traceback.format_exc()) settings.init(self.config_file) self.file_history = SqlHistory(os.path.join(self.config_dir, "file.sqlite")) self.location_history = SqlHistory(os.path.join(self.config_dir, "locations.sqlite")) self.bookmarks = Bookmarks(os.path.join(self.config_dir, "bookmarks.txt")) QPixmapCache.setCacheLimit(102400) self.qapp = QApplication([]) self.qapp.setQuitOnLastWindowClosed(False) self.qapp.lastWindowClosed.connect(self.on_last_window_closed) self.stream_manager = StreamManager(self.stream_dir) self.vfs = VirtualFilesystem(self.cache_dir, self) self.executor = Executor(self) self.thumbnailer = Thumbnailer(self.vfs) self.metadata_collector = MetaDataCollector(self.vfs.get_stdio_fs()) self.session_bus = QDBusConnection.sessionBus() self.dbus_thumbnail_cache = DBusThumbnailCache(self.session_bus) self.mime_database = MimeDatabase(self.vfs) self.mime_associations = XdgMimeAssociations.system() self.fs_operations = FilesystemOperations(self) self.fs = Filesystem() self.directory_thumbnailer = DirectoryThumbnailer(self) self.directory_thumbnailer.start() self.controllers: List[Controller] = [] self.actions = ApplicationActions(self) self._preferences_dialog = PreferencesDialog()
def update_plot(self): QPixmapCache.clear() self.cv2_image = cv2.imread(self.image_path) self.contours = mcf(image=self.cv2_image, k_blur=2 * self.k_blur.value() - 1, C=self.C.value(), blocksize=2 * self.blocksize.value() - 1, k_laplacian=2 * self.k_laplacian.value() - 1, k_dilate=2 * self.k_dilate.value() - 1, k_gradient=2 * self.k_gradient.value() - 1, k_foreground=2 * self.k_foreground.value() - 1, skip_flood=True) try: Amin = int(self.Amin.text()) except ValueError: Amin = int(1) try: Amax = int(self.Amax.text()) except ValueError: Amax = int(self.__originalH__ * self.__originalW__) self.large_contours = contour_size_selection(self.contours, Amin=Amin, Amax=Amax) if self.use_approxPolys.isChecked(): self.large_contours = [ cv2.approxPolyDP(c, epsilon=self.epsilon.value(), closed=True) for c in self.large_contours ] if self.use_convexHulls.isChecked(): self.large_contours = [ cv2.convexHull(c) for c in self.large_contours ] cv2.drawContours(self.cv2_image, contours=self.large_contours, contourIdx=-1, color=self.contour_color, thickness=2) if len(self.highlighted) > 0: cv2.drawContours(self.cv2_image, contours=self.highlighted, contourIdx=-1, color=self.highlight_color, thickness=2) self.np_image = cv2.cvtColor(self.cv2_image, cv2.COLOR_BGR2RGB) self.qimage = QImage(self.np_image, self.np_image.shape[1], self.np_image.shape[0], self.bytesPerLine, QImage.Format_RGB888) pixmap = QPixmap(self.qimage) self.pixmap = pixmap.scaled(self.label.width(), self.label.height(), QtCore.Qt.KeepAspectRatio) self.label.setPixmap(self.pixmap) self.label.resize(self.width(), self.height())
def showImage(self, path): if isinstance(path, str): img = QPixmap(path) elif isinstance(path, QImage): img = QPixmap.fromImage(path, Qt.AutoColor) else: img = path self.graphics_view.img_item.setPixmap( img.scaled(img.width(), img.height())) self.compareWithViewAndImage(img.width(), img.height()) self.setImageCenterOn() QPixmapCache.clear() self.graphics_view.scene.update()
def set_state(self, state): """ Set the state of the square. Values must correspond to a value from `Minesweeper.state`. Numbers should be encoded as strings, so that state can be passed on to Qt's C++ backend as a QString. """ if state == 'None': self._pixmap = QPixmapCache.find_or_get(':closed.png') elif state == '?': self._pixmap = QPixmapCache.find_or_get(':question_mark.png') else: self._pixmap = QPixmapCache.find_or_get(':{}.png'.format(state)) if self._pixmap.isNull(): raise ValueError( 'The given state ({}) does not exist.'.format(state))
def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget): self.pixmap = QPixmapCache.find(self.cache_key) if not self.pixmap: with openslide.open_slide(self.slide_path) as slide: tile_pilimage = slide.read_region( (self.slide_rect_0.x(), self.slide_rect_0.y()), self.level, (self.slide_rect_0.width(), self.slide_rect_0.height()), ) self.pixmap = self.pilimage_to_pixmap(tile_pilimage) # self.pixmap.fill(Qt.red) QPixmapCache.insert(self.cache_key, self.pixmap) painter.drawPixmap(self.boundingRect().toRect(), self.pixmap)
def verticalGradient(painter: QPainter, spanRect: QRect, clipRect: QRect): keyColor = BASE_COLOR key = "verticalGradient %d %d %d %d %d" % (spanRect.width( ), spanRect.height(), clipRect.width(), clipRect.height(), keyColor.rgb()) pixmap = QPixmapCache.find(key) if pixmap is None: pixmap = QPixmap(clipRect.size()) p = QPainter(pixmap) rect = QRect(0, 0, clipRect.width(), clipRect.height()) verticalGradientHelper(p, spanRect, rect) p.end() QPixmapCache.insert(key, pixmap) painter.drawPixmap(clipRect.topLeft(), pixmap)
def __init__(self, weboob, backend, songlyrics, parent=None): super(MiniSonglyrics, self).__init__(parent) self.parent = parent self.ui = Ui_MiniSonglyrics() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.songlyrics = songlyrics self.ui.titleLabel.setText(songlyrics.title) if not empty(songlyrics.artist): if len(songlyrics.artist) > 300: self.ui.artistLabel.setText('%s [...]' % songlyrics.artist[:300]) else: self.ui.artistLabel.setText(songlyrics.artist) else: self.ui.artistLabel.setText('') self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed)
def __init__(self, weboob, backend, movie, parent=None): super(MiniMovie, self).__init__(parent) self.parent = parent self.ui = Ui_MiniMovie() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.movie = movie self.ui.titleLabel.setText(movie.original_title) self.ui.shortDescLabel.setText(movie.short_description) self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed) self.ui.viewThumbnailButton.clicked.connect(self.gotThumbnail) if self.parent.parent.ui.showTCheck.isChecked(): self.gotThumbnail()
def __init__(self, weboob, backend, person, parent=None): super(MiniPerson, self).__init__(parent) self.parent = parent self.ui = Ui_MiniPerson() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.person = person self.ui.nameLabel.setText('%s' % person.name) if not empty(person.short_description): if self.parent.ui.currentActionLabel.text().startswith('Casting'): self.ui.shortDescTitleLabel.setText(u'Role') self.ui.shortDescLabel.setText('%s' % person.short_description) else: self.ui.shortDescTitleLabel.hide() self.ui.shortDescLabel.hide() self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed) self.ui.viewThumbnailButton.clicked.connect(self.gotThumbnail) if self.parent.parent.ui.showTCheck.isChecked(): self.gotThumbnail()
def __init__(self, weboob, backend, torrent, parent=None): super(MiniTorrent, self).__init__(parent) self.parent = parent self.ui = Ui_MiniTorrent() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.torrent = torrent self.ui.nameLabel.setText(torrent.name) if not empty(torrent.seeders) and not empty(torrent.leechers): self.ui.seedLeechLabel.setText('%s/%s' % (torrent.seeders, torrent.leechers)) if not empty(torrent.size): self.ui.sizeLabel.setText(u'%s' % sizeof_fmt(torrent.size)) self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed)
def main(): app = QApplication(sys.argv) win = SlideListMainWindow() cache_size_in_kb = 700 * 10**3 QPixmapCache.setCacheLimit(cache_size_in_kb) # dirpath = r'C:\Users\DIMA\Google Диск\Pictures\Mountains' # dirpath = r'C:\Users\DIMA\Downloads\svs' # dirpath = r'C:\Users\DIMA\PycharmProjects\slide_cbir_47\temp\slides\Aperio' # filepathes = [os.path.join(dirpath, filename) for filename in os.listdir(dirpath)] # items = [slidepath_to_slideviewparams(filepath) for filepath in filepathes[0:1]] # win.slide_list_widget.list_model.update_items(items) win.list_view_menu.item_mode_menu.delegate_mode_action.trigger() win.show() sys.exit(app.exec_())
def __init__(self, weboob, backend, recipe, parent=None): super(MiniRecipe, self).__init__(parent) self.parent = parent self.ui = Ui_MiniRecipe() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.recipe = recipe self.ui.titleLabel.setText(recipe.title) if not empty(recipe.short_description): if len(recipe.short_description) > 300: self.ui.shortDescLabel.setText('%s [...]' % recipe.short_description[:300]) else: self.ui.shortDescLabel.setText(recipe.short_description) else: self.ui.shortDescLabel.setText('') self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed) self.ui.viewThumbnailButton.clicked.connect(self.gotThumbnail) if self.parent.parent.ui.showTCheck.isChecked(): self.gotThumbnail()
def __init__(self, weboob, backend, recipe, parent=None): super(MiniRecipe, self).__init__(parent) self.parent = parent self.ui = Ui_MiniRecipe() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.recipe = recipe self.ui.titleLabel.setText(recipe.title) if not empty(recipe.short_description): if len(recipe.short_description) > 300: self.ui.shortDescLabel.setText('%s [...]'%recipe.short_description[:300]) else: self.ui.shortDescLabel.setText(recipe.short_description) else: self.ui.shortDescLabel.setText('') self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed) self.ui.viewThumbnailButton.clicked.connect(self.gotThumbnail) if self.parent.parent.ui.showTCheck.isChecked(): self.gotThumbnail()
def load(self, name, size=128, forceCache=False): icon = QIcon() size = int(size) self.pixmap = QPixmap() if not type(name) in (list, tuple): name = [str(name)] if forceCache or self._forceCache: for _name in name: for _size in self.iconSizes: self.pixmap = QPixmapCache.find('$qt' + str(_name) + str(_size)) if (self.pixmap): logging.debug('Icon %s returned from cache' % _name) return self.pixmap logging.debug('Getting icon : %s size: %s' % (','.join(name), size)) pix = self.findIcon(name, size) if pix.isNull(): for _size in self.iconSizes: pix = self.findIcon(name, _size) if not pix.isNull(): if size == _size: return pix icon.addPixmap(pix) if icon.isNull(): return self.pixmap return icon.pixmap(QSize(size, size)) return pix
def load(self, name, size = 128, forceCache = False): icon = QIcon() size = int(size) self.pixmap = QPixmap() if not type(name) in (list, tuple): name = [str(name)] if forceCache or self._forceCache: for _name in name: for _size in self.iconSizes: if (QPixmapCache.find('$qt'+str(_name)+str(_size), self.pixmap)): logging.debug('Icon %s returned from cache' % _name) return self.pixmap logging.debug('Getting icon : %s size: %s' % (','.join(name), size)) pix = self.findIcon(name, size) if pix.isNull(): for _size in self.iconSizes: pix = self.findIcon(name, _size) if not pix.isNull(): if size == _size: return pix icon.addPixmap(pix) if icon.isNull(): return self.pixmap return icon.pixmap(QSize(size, size)) return pix
def __init__(self, weboob, backend, songlyrics, parent=None): super(MiniSonglyrics, self).__init__(parent) self.parent = parent self.ui = Ui_MiniSonglyrics() self.ui.setupUi(self) self.weboob = weboob self.backend = backend self.songlyrics = songlyrics self.ui.titleLabel.setText(songlyrics.title) if not empty(songlyrics.artist): if len(songlyrics.artist) > 300: self.ui.artistLabel.setText('%s [...]'%songlyrics.artist[:300]) else: self.ui.artistLabel.setText(songlyrics.artist) else: self.ui.artistLabel.setText('') self.ui.backendButton.setText(backend.name) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) self.ui.backendButton.setIcon(QIcon(pixmap)) self.ui.newTabButton.clicked.connect(self.newTabPressed) self.ui.viewButton.clicked.connect(self.viewPressed)
def main(): app = QApplication(sys.argv) cache_size_in_kb = 700 * 10**3 QPixmapCache.setCacheLimit(cache_size_in_kb) app.setWindowIcon(QIcon(":/icons/app.svg")) f = QFile(":/style.qss") f.open(QFile.ReadOnly | QFile.Text) app.setStyleSheet(QTextStream(f).readAll()) f.close() mw = MainWindow() mw.show() sys.exit(app.exec_())
def paint(self, painter: QtGui.QPainter, option: QStyleOptionGraphicsItem, widget: typing.Optional[QWidget] = ...): # print("pos ", self.pos()) # print("paint ", self.slide_rect_0, option.rect, option.exposedRect) self.pixmap = QPixmapCache.find(self.cache_key) if not self.pixmap: # print("read", self.slide_rect_0) with openslide.open_slide(self.slide_path) as slide: tile_pilimage = slide.read_region( (self.slide_rect_0.x(), self.slide_rect_0.y()), self.level, (self.slide_rect_0.width(), self.slide_rect_0.height())) self.pixmap = self.pilimage_to_pixmap(tile_pilimage) QPixmapCache.insert(self.cache_key, self.pixmap) # painter.drawPixmap(self.slide_rect_0, self.pixmap) painter.drawPixmap(self.boundingRect().toRect(), self.pixmap)
def __init__(self, args): QApplication.__init__(self, args) self.setStyle('Fusion') self.setOrganizationName("UZH Zurich") self.setOrganizationDomain("http://www.bodenmillerlab.org") self.setApplicationName("HistoSlider") self.setWindowIcon(QIcon(":/icons/icons8-eukaryotic-cells-96.png")) cache_size_in_kb = 700 * 10 ** 3 QPixmapCache.setCacheLimit(cache_size_in_kb) f = QFile(":/style.qss") f.open(QFile.ReadOnly | QFile.Text) self.setStyleSheet(QTextStream(f).readAll()) f.close() # DataManager singleton initialization Manager()
def pixmap(self): if not self.p: key = "%s%s%s" % (self.barcode["value"], self.barcode["type"], self.barcode["res"]) if not QPixmapCache.find(key): self._createBarcode() if self.barcode["valid"]: key = "%s%s%s" % (self.barcode["value"], self.barcode["type"], self.barcode["res"]) if key: QPixmapCache.insert(key, self.p) else: self.p = QPixmapCache.find(key) self.barcode["valid"] = True if not self.p: self.barcode["valid"] = False return self.p
def nextPage(self): ''' 切换下一页画布 :return: ''' print('下一页1') if self.isWritten: # 当前页有输入或改动则保存当前页 self.savePicture(True) # self.pos_pages[self.page] = self.pos_xyc # 记录当前页笔画路径 self.isWritten = False # 关闭改动标志 print('下一页2') if self.page == self.pages: # 开辟新一页,总页数加一 # self.pos_xyc = [] # 当前页路径清空 self.pages += 1 # 页总数加一 self.pix.fill(Qt.white) # 清空画布 else: # 当前页并非最后一页 print('下一页3') fileName = str(self.page + 1) readFileName = os.path.join(self.filePath, 'temp', fileName + '.jpg') QPixmapCache.clear() self.pix.load(readFileName) # self.pos_xyc = self.pos_pages[self.page + 1] print('下一页4') self.update() # 更新内容 print('下一页5') self.page = self.page + 1 # 当前页码加一 print('下一页6') # t_changName = threading.Thread(target=self.changeWinName, args=(self.page, self.pages,)) # t_changName.start() # self.setWindowTitle('当前' + str(self.page) + '/' + str(self.pages) + '页') # 更新标题栏显示的页码 print('下一页7') logger.debug('下翻页第%s页', self.page)
def loadResources(self, clearPixmapCache=True): """Load resources for current theme""" # Need to clear pixmap cache otherwise some icons are not reloaded from new resource file if clearPixmapCache: QPixmapCache.clear() if not self.__registeredResource is None: QResource.unregisterResource(self.__registeredResource) palette = QApplication.palette() if palette.color(QPalette.Window).value() <= 128: self.__theme = UITheme.DARK_THEME else: self.__theme = UITheme.LIGHT_THEME self.__registeredResource = os.path.join(self.__rccPath, f'{self.__theme}theme_icons.rcc') if not QResource.registerResource(self.__registeredResource): self.__registeredResource = None
def addBackends(self, cap=None, entry_all=True, entry_title=False): """ Populate the model by adding backends. Appends backends to the model, without clearing previous entries. For each entry in the model, the cap name is stored under role RoleBackendName and the capability object under role RoleCapability. :param cap: capabilities to add (None to add all loaded caps) :param entry_all: if True, add a "All backends" entry :param entry_title: if True, add a disabled entry with the cap name """ if entry_title: if cap: capname = cap.__name__ else: capname = '(All capabilities)' item = QStandardItem(capname) item.setEnabled(False) self.appendRow(item) first = True for backend in self.weboob.iter_backends(caps=cap): if first and entry_all: item = QStandardItem('(All backends)') item.setData('', self.RoleBackendName) item.setData(cap, self.RoleCapability) self.appendRow(item) first = False item = QStandardItem(backend.name) item.setData(backend.name, self.RoleBackendName) item.setData(cap, self.RoleCapability) minfo = self.weboob.repositories.get_module_info(backend.NAME) icon_path = self.weboob.repositories.get_module_icon_path(minfo) if icon_path: pixmap = QPixmapCache.find(icon_path) if not pixmap: pixmap = QPixmap(QImage(icon_path)) item.setIcon(QIcon(pixmap)) self.appendRow(item)
def accept(self): set = settings.set # App / General / Gallery app_constants.SUBFOLDER_AS_GALLERY = self.subfolder_as_chapters.isChecked() set(app_constants.SUBFOLDER_AS_GALLERY, 'Application', 'subfolder as gallery') app_constants.EXTRACT_CHAPTER_BEFORE_OPENING = self.extract_gallery_before_opening.isChecked() set(app_constants.EXTRACT_CHAPTER_BEFORE_OPENING, 'Application', 'extract chapter before opening') app_constants.OPEN_GALLERIES_SEQUENTIALLY = self.open_galleries_sequentially.isChecked() set(app_constants.OPEN_GALLERIES_SEQUENTIALLY, 'Application', 'open galleries sequentially') app_constants.SCROLL_TO_NEW_GALLERIES = self.scroll_to_new_gallery.isChecked() set(app_constants.SCROLL_TO_NEW_GALLERIES, 'Application', 'scroll to new galleries') app_constants.MOVE_IMPORTED_GALLERIES = self.move_imported_gs.isChecked() set(app_constants.MOVE_IMPORTED_GALLERIES, 'Application', 'move imported galleries') if not self.move_imported_def_path.text() or os.path.exists(self.move_imported_def_path.text()): app_constants.IMPORTED_GALLERY_DEF_PATH = self.move_imported_def_path.text() set(app_constants.IMPORTED_GALLERY_DEF_PATH, 'Application', 'imported gallery def path') app_constants.OPEN_RANDOM_GALLERY_CHAPTERS = self.open_random_g_chapters.isChecked() set(app_constants.OPEN_RANDOM_GALLERY_CHAPTERS, 'Application', 'open random gallery chapters') app_constants.RENAME_GALLERY_SOURCE = self.rename_g_source_group.isChecked() set(app_constants.RENAME_GALLERY_SOURCE, 'Application', 'rename gallery source') app_constants.unrar_tool_path = self.path_to_unrar.text() set(app_constants.unrar_tool_path, 'Application', 'unrar tool path') # App / General / Search app_constants.ALLOW_SEARCH_REGEX = self.search_allow_regex.isChecked() set(app_constants.ALLOW_SEARCH_REGEX, 'Application', 'allow search regex') app_constants.SEARCH_AUTOCOMPLETE = self.search_autocomplete.isChecked() set(app_constants.SEARCH_AUTOCOMPLETE, 'Application', 'search autocomplete') if self.search_on_enter.isChecked(): app_constants.SEARCH_ON_ENTER = True else: app_constants.SEARCH_ON_ENTER = False set(app_constants.SEARCH_ON_ENTER, 'Application', 'search on enter') # App / General / External Viewer if not self.external_viewer_path.text(): app_constants.USE_EXTERNAL_VIEWER = False set(False, 'Application', 'use external viewer') else: app_constants.USE_EXTERNAL_VIEWER = True set(True, 'Application', 'use external viewer') app_constants._REFRESH_EXTERNAL_VIEWER = True app_constants.EXTERNAL_VIEWER_PATH = self.external_viewer_path.text() set(app_constants.EXTERNAL_VIEWER_PATH,'Application', 'external viewer path') # App / Monitor / misc app_constants.ENABLE_MONITOR = self.enable_monitor.isChecked() set(app_constants.ENABLE_MONITOR, 'Application', 'enable monitor') app_constants.LOOK_NEW_GALLERY_STARTUP = self.look_new_gallery_startup.isChecked() set(app_constants.LOOK_NEW_GALLERY_STARTUP, 'Application', 'look new gallery startup') app_constants.LOOK_NEW_GALLERY_AUTOADD = self.auto_add_new_galleries.isChecked() set(app_constants.LOOK_NEW_GALLERY_AUTOADD, 'Application', 'look new gallery autoadd') # App / Monitor / folders paths = [] folder_p_widgets = self.take_all_layout_widgets(self.folders_layout) for x, l_edit in enumerate(folder_p_widgets): p = l_edit.text() if p: paths.append(p) set(paths, 'Application', 'monitor paths') app_constants.MONITOR_PATHS = paths # App / Monitor / ignore list paths = [] ignore_p_widgets = self.take_all_layout_widgets(self.ignore_path_l) for x, l_edit in enumerate(ignore_p_widgets): p = l_edit.text() if p: paths.append(p) set(paths, 'Application', 'ignore paths') app_constants.IGNORE_PATHS = paths # Web / Downloader if self.archive_download.isChecked(): app_constants.HEN_DOWNLOAD_TYPE = 0 else: app_constants.HEN_DOWNLOAD_TYPE = 1 set(app_constants.HEN_DOWNLOAD_TYPE, 'Web', 'hen download type') app_constants.DOWNLOAD_DIRECTORY = self.download_directory.text() set(app_constants.DOWNLOAD_DIRECTORY, 'Web', 'download directory') app_constants.TORRENT_CLIENT = self.torrent_client.text() set(app_constants.TORRENT_CLIENT, 'Web', 'torrent client') # Web / Metdata if self.default_ehen_url.isChecked(): app_constants.DEFAULT_EHEN_URL = 'http://g.e-hentai.org/' else: app_constants.DEFAULT_EHEN_URL = 'http://exhentai.org/' set(app_constants.DEFAULT_EHEN_URL, 'Web', 'default ehen url') app_constants.REPLACE_METADATA = self.replace_metadata.isChecked() set(app_constants.REPLACE_METADATA, 'Web', 'replace metadata') app_constants.ALWAYS_CHOOSE_FIRST_HIT = self.always_first_hit.isChecked() set(app_constants.ALWAYS_CHOOSE_FIRST_HIT, 'Web', 'always choose first hit') app_constants.GLOBAL_EHEN_TIME = self.web_time_offset.value() set(app_constants.GLOBAL_EHEN_TIME, 'Web', 'global ehen time offset') app_constants.CONTINUE_AUTO_METADATA_FETCHER = self.continue_a_metadata_fetcher.isChecked() set(app_constants.CONTINUE_AUTO_METADATA_FETCHER, 'Web', 'continue auto metadata fetcher') app_constants.USE_JPN_TITLE = self.use_jpn_title.isChecked() set(app_constants.USE_JPN_TITLE, 'Web', 'use jpn title') app_constants.USE_GALLERY_LINK = self.use_gallery_link.isChecked() set(app_constants.USE_GALLERY_LINK, 'Web', 'use gallery link') # Web / ExHentai self.exprops.ipb_id = self.ipbid_edit.text() self.exprops.ipb_pass = self.ipbpass_edit.text() # Visual / Grid View / Tooltip app_constants.GRID_TOOLTIP = self.grid_tooltip_group.isChecked() set(app_constants.GRID_TOOLTIP, 'Visual', 'grid tooltip') app_constants.TOOLTIP_TITLE = self.visual_grid_tooltip_title.isChecked() set(app_constants.TOOLTIP_TITLE, 'Visual', 'tooltip title') app_constants.TOOLTIP_AUTHOR = self.visual_grid_tooltip_author.isChecked() set(app_constants.TOOLTIP_AUTHOR, 'Visual', 'tooltip author') app_constants.TOOLTIP_CHAPTERS = self.visual_grid_tooltip_chapters.isChecked() set(app_constants.TOOLTIP_CHAPTERS, 'Visual', 'tooltip chapters') app_constants.TOOLTIP_STATUS = self.visual_grid_tooltip_status.isChecked() set(app_constants.TOOLTIP_STATUS, 'Visual', 'tooltip status') app_constants.TOOLTIP_TYPE = self.visual_grid_tooltip_type.isChecked() set(app_constants.TOOLTIP_TYPE, 'Visual', 'tooltip type') app_constants.TOOLTIP_LANG = self.visual_grid_tooltip_lang.isChecked() set(app_constants.TOOLTIP_LANG, 'Visual', 'tooltip lang') app_constants.TOOLTIP_DESCR = self.visual_grid_tooltip_descr.isChecked() set(app_constants.TOOLTIP_DESCR, 'Visual', 'tooltip descr') app_constants.TOOLTIP_TAGS = self.visual_grid_tooltip_tags.isChecked() set(app_constants.TOOLTIP_TAGS, 'Visual', 'tooltip tags') app_constants.TOOLTIP_LAST_READ = self.visual_grid_tooltip_last_read.isChecked() set(app_constants.TOOLTIP_LAST_READ, 'Visual', 'tooltip last read') app_constants.TOOLTIP_TIMES_READ = self.visual_grid_tooltip_times_read.isChecked() set(app_constants.TOOLTIP_TIMES_READ, 'Visual', 'tooltip times read') app_constants.TOOLTIP_PUB_DATE = self.visual_grid_tooltip_pub_date.isChecked() set(app_constants.TOOLTIP_PUB_DATE, 'Visual', 'tooltip pub date') app_constants.TOOLTIP_DATE_ADDED = self.visual_grid_tooltip_date_added.isChecked() set(app_constants.TOOLTIP_DATE_ADDED, 'Visual', 'tooltip date added') # Visual / Grid View / Gallery app_constants.USE_EXTERNAL_PROG_ICO = self.external_viewer_ico.isChecked() set(app_constants.USE_EXTERNAL_PROG_ICO, 'Visual', 'use external prog ico') app_constants.DISPLAY_GALLERY_TYPE = self.gallery_type_ico.isChecked() set(app_constants.DISPLAY_GALLERY_TYPE, 'Visual', 'display gallery type') if self.gallery_text_elide.isChecked(): app_constants.GALLERY_FONT_ELIDE = True else: app_constants.GALLERY_FONT_ELIDE = False set(app_constants.GALLERY_FONT_ELIDE, 'Visual', 'gallery font elide') app_constants.GALLERY_FONT = (self.font_lbl.text(), self.font_size_lbl.value()) set(app_constants.GALLERY_FONT[0], 'Visual', 'gallery font family') set(app_constants.GALLERY_FONT[1], 'Visual', 'gallery font size') # Visual / Grid View / Colors if self.color_checker(self.grid_title_color.text()): app_constants.GRID_VIEW_TITLE_COLOR = self.grid_title_color.text() set(app_constants.GRID_VIEW_TITLE_COLOR, 'Visual', 'grid view title color') if self.color_checker(self.grid_artist_color.text()): app_constants.GRID_VIEW_ARTIST_COLOR = self.grid_artist_color.text() set(app_constants.GRID_VIEW_ARTIST_COLOR, 'Visual', 'grid view artist color') if self.color_checker(self.grid_label_color.text()): app_constants.GRID_VIEW_LABEL_COLOR = self.grid_label_color.text() set(app_constants.GRID_VIEW_LABEL_COLOR, 'Visual', 'grid view label color') # Advanced / Misc # Advanced / Misc / Grid View app_constants.SCROLL_SPEED = self.scroll_speed set(self.scroll_speed, 'Advanced', 'scroll speed') self.scroll_speed_changed.emit() app_constants.THUMBNAIL_CACHE_SIZE = self.cache_size set(self.cache_size[1], 'Advanced', 'cache size') QPixmapCache.setCacheLimit(self.cache_size[0]* self.cache_size[1]) # Advanced / General / Gallery Text Fixer app_constants.GALLERY_DATA_FIX_REGEX = self.g_data_regex_fix_edit.text() set(app_constants.GALLERY_DATA_FIX_REGEX, 'Advanced', 'gallery data fix regex') app_constants.GALLERY_DATA_FIX_TITLE = self.g_data_fixer_title.isChecked() set(app_constants.GALLERY_DATA_FIX_TITLE, 'Advanced', 'gallery data fix title') app_constants.GALLERY_DATA_FIX_ARTIST = self.g_data_fixer_artist.isChecked() set(app_constants.GALLERY_DATA_FIX_ARTIST, 'Advanced', 'gallery data fix artist') app_constants.GALLERY_DATA_FIX_REPLACE = self.g_data_replace_fix_edit.text() set(app_constants.GALLERY_DATA_FIX_REPLACE, 'Advanced', 'gallery data fix replace') # About / DB Overview app_constants.TAGS_TREEVIEW_ON_START = self.tags_treeview_on_start.isChecked() set(app_constants.TAGS_TREEVIEW_ON_START, 'Application', 'tags treeview on start') settings.save() self.close()
def paint(self, painter, option, index): assert isinstance(painter, QPainter) if index.data(Qt.UserRole+1): if app_constants.HIGH_QUALITY_THUMBS: painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.setRenderHint(QPainter.Antialiasing) gallery = index.data(Qt.UserRole+1) title = gallery.title artist = gallery.artist title_color = app_constants.GRID_VIEW_TITLE_COLOR artist_color = app_constants.GRID_VIEW_ARTIST_COLOR label_color = app_constants.GRID_VIEW_LABEL_COLOR # Enable this to see the defining box #painter.drawRect(option.rect) # define font size if 20 > len(title) > 15: title_size = "font-size:{}px;".format(self.font_size) elif 30 > len(title) > 20: title_size = "font-size:{}px;".format(self.font_size-1) elif 40 > len(title) >= 30: title_size = "font-size:{}px;".format(self.font_size-2) elif 50 > len(title) >= 40: title_size = "font-size:{}px;".format(self.font_size-3) elif len(title) >= 50: title_size = "font-size:{}px;".format(self.font_size-4) else: title_size = "font-size:{}px;".format(self.font_size) if 30 > len(artist) > 20: artist_size = "font-size:{}px;".format(self.font_size) elif 40 > len(artist) >= 30: artist_size = "font-size:{}px;".format(self.font_size-1) elif len(artist) >= 40: artist_size = "font-size:{}px;".format(self.font_size-2) else: artist_size = "font-size:{}px;".format(self.font_size) #painter.setPen(QPen(Qt.NoPen)) #option.rect = option.rect.adjusted(11, 10, 0, 0) option.rect.setWidth(self.W) option.rect.setHeight(self.H) rec = option.rect.getRect() x = rec[0] y = rec[1] w = rec[2] h = rec[3] text_area = QTextDocument() text_area.setDefaultFont(option.font) text_area.setHtml(""" <head> <style> #area {{ display:flex; width:{6}px; height:{7}px }} #title {{ position:absolute; color: {4}; font-weight:bold; {0} }} #artist {{ position:absolute; color: {5}; top:20px; right:0; {1} }} </style> </head> <body> <div id="area"> <center> <div id="title">{2} </div> <div id="artist">{3} </div> </div> </center> </body> """.format(title_size, artist_size, title, artist, title_color, artist_color, 130+app_constants.SIZE_FACTOR, 1+app_constants.SIZE_FACTOR)) text_area.setTextWidth(w) #chapter_area = QTextDocument() #chapter_area.setDefaultFont(option.font) #chapter_area.setHtml(""" #<font color="black">{}</font> #""".format("chapter")) #chapter_area.setTextWidth(w) def center_img(width): new_x = x if width < w: diff = w - width offset = diff//2 new_x += offset return new_x def img_too_big(start_x): txt_layout = misc.text_layout("Image is too big!", w, self.title_font, self.title_font_m) clipping = QRectF(x, y+h//4, w, app_constants.GRIDBOX_LBL_H - 10) txt_layout.draw(painter, QPointF(x, y+h//4), clip=clipping) # if we can't find a cached image pix_cache = QPixmapCache.find(self.key(gallery.profile)) if isinstance(pix_cache, QPixmap): self.image = pix_cache img_x = center_img(self.image.width()) if self.image.width() > w or self.image.height() > h: img_too_big(img_x) else: if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) else: self.image = QPixmap(gallery.profile) img_x = center_img(self.image.width()) QPixmapCache.insert(self.key(gallery.profile), self.image) if self.image.width() > w or self.image.height() > h: img_too_big(img_x) else: if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) # draw ribbon type painter.save() painter.setPen(Qt.NoPen) if app_constants.DISPLAY_GALLERY_RIBBON: type_ribbon_w = type_ribbon_l = w*0.11 rib_top_1 = QPointF(x+w-type_ribbon_l-type_ribbon_w, y) rib_top_2 = QPointF(x+w-type_ribbon_l, y) rib_side_1 = QPointF(x+w, y+type_ribbon_l) rib_side_2 = QPointF(x+w, y+type_ribbon_l+type_ribbon_w) ribbon_polygon = QPolygonF([rib_top_1, rib_top_2, rib_side_1, rib_side_2]) ribbon_path = QPainterPath() ribbon_path.setFillRule(Qt.WindingFill) ribbon_path.addPolygon(ribbon_polygon) ribbon_path.closeSubpath() painter.setBrush(QBrush(QColor(self._ribbon_color(gallery.type)))) painter.drawPath(ribbon_path) # draw if favourited if gallery.fav == 1: star_ribbon_w = star_ribbon_l = w*0.08 rib_top_1 = QPointF(x+star_ribbon_l, y) rib_side_1 = QPointF(x, y+star_ribbon_l) rib_top_2 = QPointF(x+star_ribbon_l+star_ribbon_w, y) rib_side_2 = QPointF(x, y+star_ribbon_l+star_ribbon_w) rib_star_mid_1 = QPointF((rib_top_1.x()+rib_side_1.x())/2, (rib_top_1.y()+rib_side_1.y())/2) rib_star_factor = star_ribbon_l/4 rib_star_p1_1 = rib_star_mid_1 + QPointF(rib_star_factor, -rib_star_factor) rib_star_p1_2 = rib_star_p1_1 + QPointF(-rib_star_factor, -rib_star_factor) rib_star_p1_3 = rib_star_mid_1 + QPointF(-rib_star_factor, rib_star_factor) rib_star_p1_4 = rib_star_p1_3 + QPointF(-rib_star_factor, -rib_star_factor) crown_1 = QPolygonF([rib_star_p1_1, rib_star_p1_2, rib_star_mid_1, rib_star_p1_4, rib_star_p1_3]) painter.setBrush(QBrush(QColor("yellow"))) painter.drawPolygon(crown_1) ribbon_polygon = QPolygonF([rib_top_1, rib_side_1, rib_side_2, rib_top_2]) ribbon_path = QPainterPath() ribbon_path.setFillRule(Qt.WindingFill) ribbon_path.addPolygon(ribbon_polygon) ribbon_path.closeSubpath() painter.drawPath(ribbon_path) #painter.setPen(QColor("#d35400")) #painter.drawPolyline(rib_top_1, rib_star_p1_1, rib_star_p1_2, rib_star_mid_1, rib_star_p1_4, rib_star_p1_3, rib_side_1) #painter.drawLine(rib_top_1, rib_top_2) #painter.drawLine(rib_top_2, rib_side_2) #painter.drawLine(rib_side_1, rib_side_2) painter.restore() if app_constants._REFRESH_EXTERNAL_VIEWER: if app_constants.USE_EXTERNAL_VIEWER: self.external_icon = self.file_icons.get_external_file_icon() else: self.external_icon = self.file_icons.get_default_file_icon() if gallery.state == self.G_DOWNLOAD: painter.save() dl_box = QRect(x, y, w, 20) painter.setBrush(QBrush(QColor(0,0,0,123))) painter.setPen(QColor('white')) painter.drawRect(dl_box) painter.drawText(dl_box, Qt.AlignCenter, 'Downloading...') painter.restore() else: if app_constants.DISPLAY_GALLERY_TYPE: self.type_icon = self.file_icons.get_file_icon(gallery.path) if self.type_icon and not self.type_icon.isNull(): self.type_icon.paint(painter, QRect(x+2, y+app_constants.THUMB_H_SIZE-16, 16, 16)) if app_constants.USE_EXTERNAL_PROG_ICO: if self.external_icon and not self.external_icon.isNull(): self.external_icon.paint(painter, QRect(x+w-30, y+app_constants.THUMB_H_SIZE-28, 28, 28)) def draw_text_label(lbl_h): #draw the label for text painter.save() painter.translate(x, y+app_constants.THUMB_H_SIZE) box_color = QBrush(QColor(label_color))#QColor(0,0,0,123)) painter.setBrush(box_color) rect = QRect(0, 0, w, lbl_h) #x, y, width, height painter.fillRect(rect, box_color) painter.restore() return rect if option.state & QStyle.State_MouseOver or\ option.state & QStyle.State_Selected: title_layout = misc.text_layout(title, w, self.title_font, self.title_font_m) artist_layout = misc.text_layout(artist, w, self.artist_font, self.artist_font_m) t_h = title_layout.boundingRect().height() a_h = artist_layout.boundingRect().height() if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(min(t_h+a_h+3, app_constants.GRIDBOX_LBL_H)) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) clipping = QRectF(x, y+app_constants.THUMB_H_SIZE, w, app_constants.GRIDBOX_LBL_H - 10) painter.setPen(QColor(title_color)) title_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE), clip=clipping) painter.setPen(QColor(artist_color)) artist_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE+t_h), clip=clipping) #painter.fillRect(option.rect, QColor) else: if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(self.text_label_h) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) # draw text painter.save() alignment = QTextOption(Qt.AlignCenter) alignment.setUseDesignMetrics(True) title_rect = QRectF(0,0,w, self.title_font_m.height()) artist_rect = QRectF(0,self.artist_font_m.height(),w, self.artist_font_m.height()) painter.translate(x, y+app_constants.THUMB_H_SIZE) if app_constants.GALLERY_FONT_ELIDE: painter.setFont(self.title_font) painter.setPen(QColor(title_color)) painter.drawText(title_rect, self.title_font_m.elidedText(title, Qt.ElideRight, w-10), alignment) painter.setPen(QColor(artist_color)) painter.setFont(self.artist_font) alignment.setWrapMode(QTextOption.NoWrap) painter.drawText(artist_rect, self.title_font_m.elidedText(artist, Qt.ElideRight, w-10), alignment) else: text_area.setDefaultFont(QFont(self.font_name)) text_area.drawContents(painter) ##painter.resetTransform() painter.restore() if option.state & QStyle.State_Selected: painter.save() selected_rect = QRectF(x, y, w, lbl_rect.height()+app_constants.THUMB_H_SIZE) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor(164,164,164,120))) painter.drawRoundedRect(selected_rect, 5, 5) #painter.fillRect(selected_rect, QColor(164,164,164,120)) painter.restore() if gallery.dead_link: painter.save() selected_rect = QRectF(x, y, w, lbl_rect.height()+app_constants.THUMB_H_SIZE) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor(255,0,0,120))) p_path = QPainterPath() p_path.setFillRule(Qt.WindingFill) p_path.addRoundedRect(selected_rect, 5,5) p_path.addRect(x,y, 20, 20) p_path.addRect(x+w-20,y, 20, 20) painter.drawPath(p_path.simplified()) painter.setPen(QColor("white")) txt_layout = misc.text_layout("Cannot find gallery source!", w, self.title_font, self.title_font_m) txt_layout.draw(painter, QPointF(x, y+h*0.3)) painter.restore() if app_constants.DEBUG: painter.save() painter.setBrush(QBrush(QColor("red"))) painter.setPen(QColor("white")) txt_l = self.title_font_m.width(str(gallery.id)) painter.drawRect(x, y+40, txt_l*2, self.title_font_m.height()) painter.drawText(x+1, y+51, str(gallery.id)) painter.restore() if option.state & QStyle.State_Selected: painter.setPen(QPen(option.palette.highlightedText().color())) else: super().paint(painter, option, index)
def paint(self, painter, option, index): assert isinstance(painter, QPainter) if index.data(Qt.UserRole+1): if app_constants.HIGH_QUALITY_THUMBS: painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.setRenderHint(QPainter.Antialiasing) gallery = index.data(Qt.UserRole+1) title = gallery.title artist = gallery.artist title_color = app_constants.GRID_VIEW_TITLE_COLOR artist_color = app_constants.GRID_VIEW_ARTIST_COLOR label_color = app_constants.GRID_VIEW_LABEL_COLOR # Enable this to see the defining box #painter.drawRect(option.rect) # define font size if 20 > len(title) > 15: title_size = "font-size:{}px;".format(self.font_size) elif 30 > len(title) > 20: title_size = "font-size:{}px;".format(self.font_size-1) elif 40 > len(title) >= 30: title_size = "font-size:{}px;".format(self.font_size-2) elif 50 > len(title) >= 40: title_size = "font-size:{}px;".format(self.font_size-3) elif len(title) >= 50: title_size = "font-size:{}px;".format(self.font_size-4) else: title_size = "font-size:{}px;".format(self.font_size) if 30 > len(artist) > 20: artist_size = "font-size:{}px;".format(self.font_size) elif 40 > len(artist) >= 30: artist_size = "font-size:{}px;".format(self.font_size-1) elif len(artist) >= 40: artist_size = "font-size:{}px;".format(self.font_size-2) else: artist_size = "font-size:{}px;".format(self.font_size) #painter.setPen(QPen(Qt.NoPen)) #option.rect = option.rect.adjusted(11, 10, 0, 0) option.rect.setWidth(self.W) option.rect.setHeight(self.H) rec = option.rect.getRect() x = rec[0] y = rec[1] w = rec[2] h = rec[3] text_area = QTextDocument() text_area.setDefaultFont(option.font) text_area.setHtml(""" <head> <style> #area {{ display:flex; width:140px; height:10px }} #title {{ position:absolute; color: {4}; font-weight:bold; {0} }} #artist {{ position:absolute; color: {5}; top:20px; right:0; {1} }} </style> </head> <body> <div id="area"> <center> <div id="title">{2} </div> <div id="artist">{3} </div> </div> </center> </body> """.format(title_size, artist_size, title, artist, title_color, artist_color)) text_area.setTextWidth(w) #chapter_area = QTextDocument() #chapter_area.setDefaultFont(option.font) #chapter_area.setHtml(""" #<font color="black">{}</font> #""".format("chapter")) #chapter_area.setTextWidth(w) def center_img(width): new_x = x if width < w: diff = w - width offset = diff//2 new_x += offset return new_x # if we can't find a cached image pix_cache = QPixmapCache.find(self.key(gallery.profile)) if isinstance(pix_cache, QPixmap): self.image = pix_cache img_x = center_img(self.image.width()) if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) else: self.image = QPixmap(gallery.profile) img_x = center_img(self.image.width()) QPixmapCache.insert(self.key(gallery.profile), self.image) if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) # draw star if it's favorited if gallery.fav == 1: painter.drawPixmap(QPointF(x,y), QPixmap(app_constants.STAR_PATH)) if app_constants._REFRESH_EXTERNAL_VIEWER: if app_constants.USE_EXTERNAL_VIEWER: self.external_icon = self.file_icons.get_external_file_icon() else: self.external_icon = self.file_icons.get_default_file_icon() if gallery.state == self.G_DOWNLOAD: painter.save() dl_box = QRect(x, y, w, 20) painter.setBrush(QBrush(QColor(0,0,0,123))) painter.setPen(QColor('white')) painter.drawRect(dl_box) painter.drawText(dl_box, Qt.AlignCenter, 'Downloading...') painter.restore() else: if app_constants.DISPLAY_GALLERY_TYPE: self.type_icon = self.file_icons.get_file_icon(gallery.path) if self.type_icon and not self.type_icon.isNull(): self.type_icon.paint(painter, QRect(x+2, y+app_constants.THUMB_H_SIZE-16, 16, 16)) if app_constants.USE_EXTERNAL_PROG_ICO: if self.external_icon and not self.external_icon.isNull(): self.external_icon.paint(painter, QRect(x+w-30, y+app_constants.THUMB_H_SIZE-28, 28, 28)) def draw_text_label(lbl_h): #draw the label for text painter.save() painter.translate(x, y+app_constants.THUMB_H_SIZE) box_color = QBrush(QColor(label_color))#QColor(0,0,0,123)) painter.setBrush(box_color) rect = QRect(0, 0, w, lbl_h) #x, y, width, height painter.fillRect(rect, box_color) painter.restore() return rect if option.state & QStyle.State_MouseOver or\ option.state & QStyle.State_Selected: title_layout = self.text_layout(title, w, self.title_font, self.title_font_m) artist_layout = self.text_layout(artist, w, self.artist_font, self.artist_font_m) t_h = title_layout.boundingRect().height() a_h = artist_layout.boundingRect().height() if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(min(t_h+a_h+3, app_constants.GRIDBOX_LBL_H)) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) clipping = QRectF(x, y+app_constants.THUMB_H_SIZE, w, app_constants.GRIDBOX_LBL_H - 10) title_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE), clip=clipping) artist_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE+t_h), clip=clipping) #painter.fillRect(option.rect, QColor) else: if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(self.text_label_h) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) # draw text painter.save() alignment = QTextOption(Qt.AlignCenter) alignment.setUseDesignMetrics(True) title_rect = QRectF(0,0,w, self.title_font_m.height()) artist_rect = QRectF(0,self.artist_font_m.height(),w, self.artist_font_m.height()) painter.translate(x, y+app_constants.THUMB_H_SIZE) if app_constants.GALLERY_FONT_ELIDE: painter.setFont(self.title_font) painter.setPen(QColor(title_color)) painter.drawText(title_rect, self.title_font_m.elidedText(title, Qt.ElideRight, w-10), alignment) painter.setPen(QColor(artist_color)) painter.setFont(self.artist_font) alignment.setWrapMode(QTextOption.NoWrap) painter.drawText(artist_rect, self.title_font_m.elidedText(artist, Qt.ElideRight, w-10), alignment) else: text_area.setDefaultFont(QFont(self.font_name)) text_area.drawContents(painter) ##painter.resetTransform() painter.restore() if option.state & QStyle.State_Selected: painter.save() selected_rect = QRectF(x, y, w, lbl_rect.height()+app_constants.THUMB_H_SIZE) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor(164,164,164,120))) p_path = QPainterPath() p_path.setFillRule(Qt.WindingFill) p_path.addRoundedRect(selected_rect, 5,5) p_path.addRect(x,y, 20, 20) p_path.addRect(x+w-20,y, 20, 20) painter.drawPath(p_path.simplified()) #painter.fillRect(selected_rect, QColor(164,164,164,120)) painter.restore() #if option.state & QStyle.State_Selected: # painter.setPen(QPen(option.palette.highlightedText().color())) else: super().paint(painter, option, index)
def draw_icon(icon, rect, painter, icon_mode, shadow=False): cache = icon.pixmap(rect.size()) dip_offset = QPoint(1, -2) cache = QPixmap() pixname = "icon {0} {1} {2}".format( icon.cacheKey(), icon_mode, rect.height() ) if QPixmapCache.find(pixname) is None: pix = icon.pixmap(rect.size()) device_pixel_ratio = pix.devicePixelRatio() radius = 3 * device_pixel_ratio offset = dip_offset * device_pixel_ratio cache = QPixmap(pix.size() + QSize(radius * 2, radius * 2)) cache.fill(Qt.transparent) cache_painter = QPainter(cache) if icon_mode == QIcon.Disabled: im = pix.toImage().convertToFormat(QImage.Format_ARGB32) for y in range(0, im.height()): scanline = im.scanLine(y) for x in range(0, im.width()): pixel = scanline intensity = qGray(pixel) scanline = qRgba( intensity, intensity, intensity, qAlpha(pixel)) scanline += 1 pix = QPixmap.fromImage(im) # Draw shadow tmp = QImage(pix.size() + QSize(radius * 2, radius * 2), QImage.Format_ARGB32_Premultiplied) tmp.fill(Qt.transparent) tmp_painter = QPainter(tmp) tmp_painter.setCompositionMode(QPainter.CompositionMode_Source) tmp_painter.drawPixmap( QRect(radius, radius, pix.width(), pix.height()), pix) tmp_painter.end() # Blur the alpha channel blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied) blur_painter = QPainter(blurred) blur_painter.end() # tmp = blurred tmp_painter.begin(tmp) tmp_painter.setCompositionMode(QPainter.CompositionMode_SourceIn) tmp_painter.fillRect(tmp.rect(), QColor(0, 0, 0, 150)) tmp_painter.end() tmp_painter.begin(tmp) tmp_painter.setCompositionMode(QPainter.CompositionMode_SourceIn) tmp_painter.fillRect(tmp.rect(), QColor(0, 0, 0, 150)) tmp_painter.end() # Draw the blurred drop shadow cache_painter.drawImage( QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp) # Draw the actual pixmap cache_painter.drawPixmap( QRect(QPoint(radius, radius) + offset, QSize(pix.width(), pix.height())), pix) cache_painter.end() cache.setDevicePixelRatio(device_pixel_ratio) QPixmapCache.insert(pixname, cache) target_rect = cache.rect() target_rect.setSize(target_rect.size() / cache.devicePixelRatio()) target_rect.moveCenter(rect.center() - dip_offset) painter.drawPixmap(target_rect, cache)
def accept(self): set = settings.set # App / Monitor / misc gui_constants.ENABLE_MONITOR = self.enable_monitor.isChecked() set(gui_constants.ENABLE_MONITOR, 'Application', 'enable monitor') gui_constants.LOOK_NEW_GALLERY_STARTUP = self.look_new_gallery_startup.isChecked() set(gui_constants.LOOK_NEW_GALLERY_STARTUP, 'Application', 'look new gallery startup') gui_constants.LOOK_NEW_GALLERY_AUTOADD = self.auto_add_new_galleries.isChecked() set(gui_constants.LOOK_NEW_GALLERY_AUTOADD, 'Application', 'look new gallery autoadd') # App / Monitor / folders n = self.folders_layout.rowCount() paths = '' for x in range(n): item = self.folders_layout.takeAt(x+1) l_edit = item.widget() p = l_edit.text() if p: if x == n-1: paths += '{}'.format(p) else: paths += '{},'.format(p) set(paths, 'Application', 'monitor paths') gui_constants.MONITOR_PATHS = paths.split(',') # Web / General if self.default_ehen_url.isChecked(): gui_constants.DEFAULT_EHEN_URL = 'http://g.e-hentai.org/' else: gui_constants.DEFAULT_EHEN_URL = 'http://exhentai.org/' set(gui_constants.DEFAULT_EHEN_URL, 'Web', 'default ehen url') gui_constants.REPLACE_METADATA = self.replace_metadata.isChecked() set(gui_constants.REPLACE_METADATA, 'Web', 'replace metadata') gui_constants.ALWAYS_CHOOSE_FIRST_HIT = self.always_first_hit.isChecked() set(gui_constants.ALWAYS_CHOOSE_FIRST_HIT, 'Web', 'always choose first hit') gui_constants.GLOBAL_EHEN_TIME = self.web_time_offset.value() set(gui_constants.GLOBAL_EHEN_TIME, 'Web', 'global ehen time offset') gui_constants.CONTINUE_AUTO_METADATA_FETCHER = self.continue_a_metadata_fetcher.isChecked() set(gui_constants.CONTINUE_AUTO_METADATA_FETCHER, 'Web', 'continue auto metadata fetcher') gui_constants.USE_JPN_TITLE = self.use_jpn_title.isChecked() set(gui_constants.USE_JPN_TITLE, 'Web', 'use jpn title') # Web / ExHentai self.exprops.ipb_id = self.ipbid_edit.text() self.exprops.ipb_pass = self.ipbpass_edit.text() # Visual / Grid View / Tooltip gui_constants.GRID_TOOLTIP = self.grid_tooltip_group.isChecked() set(gui_constants.GRID_TOOLTIP, 'Visual', 'grid tooltip') gui_constants.TOOLTIP_TITLE = self.visual_grid_tooltip_title.isChecked() set(gui_constants.TOOLTIP_TITLE, 'Visual', 'tooltip title') gui_constants.TOOLTIP_AUTHOR = self.visual_grid_tooltip_author.isChecked() set(gui_constants.TOOLTIP_AUTHOR, 'Visual', 'tooltip author') gui_constants.TOOLTIP_CHAPTERS = self.visual_grid_tooltip_chapters.isChecked() set(gui_constants.TOOLTIP_CHAPTERS, 'Visual', 'tooltip chapters') gui_constants.TOOLTIP_STATUS = self.visual_grid_tooltip_status.isChecked() set(gui_constants.TOOLTIP_STATUS, 'Visual', 'tooltip status') gui_constants.TOOLTIP_TYPE = self.visual_grid_tooltip_type.isChecked() set(gui_constants.TOOLTIP_TYPE, 'Visual', 'tooltip type') gui_constants.TOOLTIP_LANG = self.visual_grid_tooltip_lang.isChecked() set(gui_constants.TOOLTIP_LANG, 'Visual', 'tooltip lang') gui_constants.TOOLTIP_DESCR = self.visual_grid_tooltip_descr.isChecked() set(gui_constants.TOOLTIP_DESCR, 'Visual', 'tooltip descr') gui_constants.TOOLTIP_TAGS = self.visual_grid_tooltip_tags.isChecked() set(gui_constants.TOOLTIP_TAGS, 'Visual', 'tooltip tags') gui_constants.TOOLTIP_LAST_READ = self.visual_grid_tooltip_last_read.isChecked() set(gui_constants.TOOLTIP_LAST_READ, 'Visual', 'tooltip last read') gui_constants.TOOLTIP_TIMES_READ = self.visual_grid_tooltip_times_read.isChecked() set(gui_constants.TOOLTIP_TIMES_READ, 'Visual', 'tooltip times read') gui_constants.TOOLTIP_PUB_DATE = self.visual_grid_tooltip_pub_date.isChecked() set(gui_constants.TOOLTIP_PUB_DATE, 'Visual', 'tooltip pub date') gui_constants.TOOLTIP_DATE_ADDED = self.visual_grid_tooltip_date_added.isChecked() set(gui_constants.TOOLTIP_DATE_ADDED, 'Visual', 'tooltip date added') # Visual / Grid View / Gallery gui_constants.USE_EXTERNAL_PROG_ICO = self.external_viewer_ico.isChecked() set(gui_constants.USE_EXTERNAL_PROG_ICO, 'Visual', 'use external prog ico') gui_constants.DISPLAY_GALLERY_TYPE = self.gallery_type_ico.isChecked() set(gui_constants.DISPLAY_GALLERY_TYPE, 'Visual', 'display gallery type') if self.gallery_text_elide.isChecked(): gui_constants.GALLERY_FONT_ELIDE = True else: gui_constants.GALLERY_FONT_ELIDE = False set(gui_constants.GALLERY_FONT_ELIDE, 'Visual', 'gallery font elide') gui_constants.GALLERY_FONT = (self.font_lbl.text(), self.font_size_lbl.value()) set(gui_constants.GALLERY_FONT[0], 'Visual', 'gallery font family') set(gui_constants.GALLERY_FONT[1], 'Visual', 'gallery font size') # Visual / Grid View / Colors if self.color_checker(self.grid_title_color.text()): gui_constants.GRID_VIEW_TITLE_COLOR = self.grid_title_color.text() set(gui_constants.GRID_VIEW_TITLE_COLOR, 'Visual', 'grid view title color') if self.color_checker(self.grid_artist_color.text()): gui_constants.GRID_VIEW_ARTIST_COLOR = self.grid_artist_color.text() set(gui_constants.GRID_VIEW_ARTIST_COLOR, 'Visual', 'grid view artist color') if self.color_checker(self.grid_label_color.text()): gui_constants.GRID_VIEW_LABEL_COLOR = self.grid_label_color.text() set(gui_constants.GRID_VIEW_LABEL_COLOR, 'Visual', 'grid view label color') # Advanced / Misc # Advanced / Misc / Grid View gui_constants.SCROLL_SPEED = self.scroll_speed set(self.scroll_speed, 'Advanced', 'scroll speed') self.scroll_speed_changed.emit() gui_constants.THUMBNAIL_CACHE_SIZE = self.cache_size set(self.cache_size[1], 'Advanced', 'cache size') QPixmapCache.setCacheLimit(self.cache_size[0]* self.cache_size[1]) # Advanced / Misc / Search gui_constants.ALLOW_SEARCH_REGEX = self.search_allow_regex.isChecked() set(gui_constants.ALLOW_SEARCH_REGEX, 'Advanced', 'allow search regex') gui_constants.SEARCH_AUTOCOMPLETE = self.search_autocomplete.isChecked() set(gui_constants.SEARCH_AUTOCOMPLETE, 'Advanced', 'search autocomplete') if self.search_on_enter.isChecked(): gui_constants.SEARCH_ON_ENTER = True else: gui_constants.SEARCH_ON_ENTER = False set(gui_constants.SEARCH_ON_ENTER, 'Advanced', 'search on enter') # Advanced / Misc / External Viewer if not self.external_viewer_path.text(): gui_constants.USE_EXTERNAL_VIEWER = False set(False, 'Advanced', 'use external viewer') else: gui_constants.USE_EXTERNAL_VIEWER = True set(True, 'Advanced', 'use external viewer') gui_constants._REFRESH_EXTERNAL_VIEWER = True gui_constants.EXTERNAL_VIEWER_PATH = self.external_viewer_path.text() set(gui_constants.EXTERNAL_VIEWER_PATH,'Advanced', 'external viewer path') settings.save() self.close()