コード例 #1
0
ファイル: ArchivesEdit.py プロジェクト: golden7602/ProjectM
    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()
コード例 #2
0
ファイル: StyleHelper.py プロジェクト: sunnyLF/LRSMSingle
    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()
コード例 #3
0
    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)
コード例 #4
0
 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()
コード例 #5
0
 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()
コード例 #6
0
    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)
コード例 #7
0
ファイル: ArchivesEdit.py プロジェクト: golden7602/ProjectM
    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)
コード例 #8
0
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_())
コード例 #9
0
    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())
コード例 #10
0
 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()
コード例 #11
0
    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)
コード例 #12
0
    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
コード例 #13
0
    def loadResources(self):
        """Load resources for current theme"""

        if not Krita.activeWindow() is None:
            # Need to clear pixmap cache otherwise some icons are not relaoded from new resource file
            QPixmapCache.clear()

            if not self.__registeredResource is None:
                QResource.unregisterResource(self.__registeredResource)

            palette = QApplication.palette()

            if palette.color(QPalette.Window).value() <= 128:
                self.__theme = BCTheme.DARK_THEME
            else:
                self.__theme = BCTheme.LIGHT_THEME

            self.__registeredResource = os.path.join(
                os.path.dirname(__file__), 'resources',
                f'{self.__theme}theme_icons.rcc')

            if not QResource.registerResource(self.__registeredResource):
                self.__registeredResource = None
コード例 #14
0
ファイル: ArchivesEdit.py プロジェクト: golden7602/ProjectM
 def render_pdf_page(self, page_data, r, i):
     imageFormat = QImage.Format_RGB888
     pagePixmap1 = page_data.getPixmap(matrix=fitz.Matrix(1, 1),
                                       alpha=False)
     pageQImage1 = QImage(pagePixmap1.samples, pagePixmap1.width,
                          pagePixmap1.height, pagePixmap1.stride,
                          imageFormat)
     # 生成 pixmap 对象
     QPixmapCache.clear()
     tempPixmap = QPixmap()
     tempPixmap.convertFromImage(pageQImage1)
     # fn = os.path.join(self.cachePath, "{}_{}.jpg".format(r.md5FileName, i))
     # tempPixmap.save(fn, "JPG")
     temp = picInfo()
     temp.md5FileName = r.md5FileName
     temp.pageIndex = i
     temp.Md5FileIndex = r.file_index
     temp.pageIndex = i
     temp.originalName = r.original_name
     a, b = os.path.splitext(r.original_name)
     temp.icoText = "P{} {}".format(i, a)
     # temp.viewPicPath = fn
     temp.viewPixmap = tempPixmap
     return temp
コード例 #15
0
 def clear(self):
     self.selected_acquisition = None
     self.selected_metals.clear()
     self._metal_color_map.clear()
     QPixmapCache.clear()
     gc.collect()
コード例 #16
0
 def update_img(self, img):
     self.gui.ui.previewLabel.setScaledContents(False)
     self.gui.ui.previewLabel.setPixmap(img)
     QPixmapCache.clear()
コード例 #17
0
    def setupUi(self):

        size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        # create title bar, content
        self.vboxWindow = QVBoxLayout(self)
        self.vboxWindow.setContentsMargins(0, 0, 0, 0)

        self.windowFrame = QWidget(self)
        self.windowFrame.setObjectName('windowFrame')

        self.vboxFrame = QVBoxLayout(self.windowFrame)
        self.vboxFrame.setContentsMargins(0, 0, 0, 0)

        self.titleBar = WindowDragger(self, self.windowFrame)
        self.titleBar.setObjectName('titleBar')
        self.titleBar.setSizePolicy(
            QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed))
        self.hboxTitle = QHBoxLayout(self.titleBar)
        self.hboxTitle.setContentsMargins(0, 0, 0, 0)

        #self.hboxTitle.setSpacing(0)

        self.btnClose = QToolButton(self.titleBar)
        self.btnClose.setObjectName('btnClose')
        self.btnClose.setSizePolicy(size_policy)
        self.hboxTitle.addWidget(self.btnClose)

        self.btnMinimize = QToolButton(self.titleBar)
        self.btnMinimize.setObjectName('btnMinimize')
        self.btnMinimize.setSizePolicy(size_policy)
        self.hboxTitle.addWidget(self.btnMinimize)

        #self.btnMinimize.setVisible(False)

        self.btnRestore = QToolButton(self.titleBar)
        self.btnRestore.setObjectName('btnRestore')
        self.btnRestore.setSizePolicy(size_policy)
        self.hboxTitle.addWidget(self.btnRestore)

        self.btnRestore.setVisible(False)

        self.btnMaximize = QToolButton(self.titleBar)
        self.btnMaximize.setObjectName('btnMaximize')
        self.btnMaximize.setSizePolicy(size_policy)
        self.hboxTitle.addWidget(self.btnMaximize)

        # self.btnMaximize.setVisible(False)

        self.showbuttons()

        self.spacelabel = QLabel("|")  #dummy label for space
        self.spacelabel.setSizePolicy(size_policy)
        self.hboxTitle.addWidget(self.spacelabel)

        QPixmapCache.clear()
        self.lblIcon = QLabel()
        self.pixmap = QPixmap("resources/images/rabbit_icon_16.png")
        self.lblIcon.setPixmap(self.pixmap)
        self.lblIcon.setSizePolicy(size_policy)
        self.hboxTitle.addWidget(self.lblIcon)

        #self.spacelabel = QLabel()  #dummy label for space
        #self.spacelabel.setSizePolicy(size_policy)
        #self.hboxTitle.addWidget(self.spacelabel)

        self.lblTitle = QLabel('Title')
        self.lblTitle.setObjectName('lblTitle')
        #self.lblTitle.setAlignment(Qt.AlignCenter)
        self.hboxTitle.addWidget(self.lblTitle)

        self.versionlabel = QLabel()
        self.versionlabel.setText("Version - {version}".format(
            version=self.parser.get(self.section_name, 'app.version')))
        #self.spacelabel.setSizePolicy(size_policy)
        self.versionlabel.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.hboxTitle.addWidget(self.versionlabel)

        self.vboxFrame.addWidget(self.titleBar)

        self.windowContent = QWidget(self.windowFrame)
        self.vboxFrame.addWidget(self.windowContent)

        self.vboxWindow.addWidget(self.windowFrame)

        # set window flags
        #self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.Tool)
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
                            | Qt.WindowSystemMenuHint | Qt.CustomizeWindowHint
                            | Qt.WindowTitleHint)

        self.window.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
                                   | Qt.WindowSystemMenuHint
                                   | Qt.CustomizeWindowHint
                                   | Qt.WindowTitleHint)
        '''Qt::CustomizeWindowHint 
        | Qt::WindowTitleHint | Qt: 
        | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint'''

        if QT_VERSION >= (5, ):
            self.setAttribute(Qt.WA_TranslucentBackground)

        # set stylesheet
        with open(_FL_STYLESHEET) as stylesheet:
            self.setStyleSheet(stylesheet.read())

        # automatically connect slots
        QMetaObject.connectSlotsByName(self)
コード例 #18
0
    def get_image_pos(self, event):
        if self.select_contours.isChecked():
            x = event.pos().x()
            y = event.pos().y()
            width_ratio = self.__originalW__ / float(self.pixmap.width())
            height_ratio = self.__originalH__ / float(self.pixmap.height())
            new_x = int(width_ratio * x)
            new_y = int(height_ratio * y)

            # Remove highlight contour if reselected
            in_highlighted = False
            if len(self.highlighted) > 0:
                for i, h in enumerate(self.highlighted):
                    if cv2.pointPolygonTest(contour=h,
                                            pt=(new_x, new_y),
                                            measureDist=False) == 1.0:
                        self.highlighted.pop(i)
                        in_highlighted = True
                        break
            # Try to add contour
            if not in_highlighted:
                for c in self.large_contours:
                    if cv2.pointPolygonTest(contour=c,
                                            pt=(new_x, new_y),
                                            measureDist=False) == 1.0:
                        self.highlighted.append(c)
                        break

        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())