コード例 #1
0
ファイル: xarm_ui.py プロジェクト: vimior/UF-Debug-Tool
 def update_connect_status(self, item):
     try:
         img = QImage()
         if item[0]:
             logger.info('connect to {} success, report: {}'.format(
                 self.handler.addr, self.handler.report_type))
             if img.load(connect_icon_path):
                 self.label_connected.setPixmap(QPixmap.fromImage(img))
                 self.btn_connect.setText(i18n[self.lang]['Disconnect'])
                 self.btn_connect.setStyleSheet('''color: red;font:bold;''')
             self.set_disable(False)
         else:
             logger.info('disconnect from or failed connect {}'.format(
                 self.handler.addr))
             self.handler.cmd_que.queue.clear()
             if img.load(disconnect_icon_path):
                 self.label_connected.setPixmap(QPixmap.fromImage(img))
                 self.btn_connect.setText(i18n[self.lang]['Connect'])
                 self.btn_connect.setStyleSheet(
                     '''color: green;font:bold;''')
             self.set_disable(True)
         if item[1]:
             if img.load(connect_icon_path):
                 self.label_reported.setPixmap(QPixmap.fromImage(img))
         else:
             if img.load(disconnect_icon_path):
                 self.label_reported.setPixmap(QPixmap.fromImage(img))
     except Exception as e:
         print(e)
コード例 #2
0
 def _updateIcon(self):
     if self._button.isActive():
         mode = QIcon.Normal
     else:
         mode = QIcon.Disabled
     img = self._button.icon().pixmap(self.iconSize(), mode).toImage()
     self.setIcon(QPixmap.fromImage(img, Qt.MonoOnly))
コード例 #3
0
    def _updateButtons(self):
        """
        Update button icons.
        """
        sz = QSize(32, 32)
        if self.orientation() == Qt.Vertical:
            sz.setHeight(sz.height() / 2)
        pix = QPixmap(sz)
        pix.fill(Qt.transparent)
        pnt = QPainter(pix)
        pnt.setPen(Qt.black)

        path = QPainterPath()
        arrowwidth = pix.width() - 2 * 2
        arrowheight = min(arrowwidth / 2, pix.height() - 2 * 2)
        path.moveTo((pix.width() - arrowwidth) / 2,
                    (pix.height() - arrowheight) / 2)
        path.lineTo((pix.width() + arrowwidth) / 2,
                    (pix.height() - arrowheight) / 2)
        path.lineTo(pix.width() / 2, (pix.height() + arrowheight) / 2)
        path.lineTo((pix.width() - arrowwidth) / 2,
                    (pix.height() - arrowheight) / 2)
        pnt.fillPath(path, Qt.black)
        pnt.end()

        self._inc.setIcon(QIcon(pix))
        self._dec.setIcon(QIcon(QPixmap.fromImage(pix.toImage().mirrored())))
コード例 #4
0
ファイル: alternate_views.py プロジェクト: JimmXinu/calibre
def drag_icon(self, cover, multiple):
    cover = cover.scaledToHeight(120, Qt.SmoothTransformation)
    if multiple:
        base_width = cover.width()
        base_height = cover.height()
        base = QImage(base_width+21, base_height+21,
                QImage.Format_ARGB32_Premultiplied)
        base.fill(QColor(255, 255, 255, 0).rgba())
        p = QPainter(base)
        rect = QRect(20, 0, base_width, base_height)
        p.fillRect(rect, QColor('white'))
        p.drawRect(rect)
        rect.moveLeft(10)
        rect.moveTop(10)
        p.fillRect(rect, QColor('white'))
        p.drawRect(rect)
        rect.moveLeft(0)
        rect.moveTop(20)
        p.fillRect(rect, QColor('white'))
        p.save()
        p.setCompositionMode(p.CompositionMode_SourceAtop)
        p.drawImage(rect.topLeft(), cover)
        p.restore()
        p.drawRect(rect)
        p.end()
        cover = base
    return QPixmap.fromImage(cover)
コード例 #5
0
    def __init__(self, parent=None):
        QStackedWidget.__init__(self, parent)
        self.welcome = w = QLabel(
            '<p>' + _('Double click a file in the left panel to start editing'
                      ' it.'))
        self.addWidget(w)
        w.setWordWrap(True)
        w.setAlignment(Qt.AlignTop | Qt.AlignHCenter)

        self.container = c = QWidget(self)
        self.addWidget(c)
        l = c.l = QVBoxLayout(c)
        c.setLayout(l)
        l.setContentsMargins(0, 0, 0, 0)
        self.editor_tabs = t = QTabWidget(c)
        l.addWidget(t)
        t.setDocumentMode(True)
        t.setTabsClosable(True)
        t.setMovable(True)
        pal = self.palette()
        if pal.color(pal.WindowText).lightness() > 128:
            i = QImage(I('modified.png'))
            i.invertPixels()
            self.modified_icon = QIcon(QPixmap.fromImage(i))
        else:
            self.modified_icon = QIcon(I('modified.png'))
        self.editor_tabs.currentChanged.connect(self.current_editor_changed)
        self.editor_tabs.tabCloseRequested.connect(self._close_requested)
        self.search_panel = SearchPanel(self)
        l.addWidget(self.search_panel)
        self.restore_state()
        self.editor_tabs.tabBar().installEventFilter(self)
コード例 #6
0
ファイル: flip.py プロジェクト: Aliminator666/calibre
    def __call__(self, image, duration=0.5):
        '''
        Start the animation. You must have called :meth:`initialize` first.

        :param duration: Animation duration in seconds.

        '''
        if self.running:
            return
        self.after_image = QPixmap.fromImage(image)

        if self.flip_forwards:
            self.animation.setStartValue(image.width())
            self.animation.setEndValue(0)
            t = self.before_image
            self.before_image = self.after_image
            self.after_image = t
            self.animation.setEasingCurve(QEasingCurve(QEasingCurve.InExpo))
        else:
            self.animation.setStartValue(0)
            self.animation.setEndValue(image.width())
            self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))

        self.animation.setDuration(duration * 1000)
        self.animation.start()
コード例 #7
0
    def showPicture(self):
        fileName = DBConnectSingleton.instance.getPicPath(self.p_id)
        if (len(fileName) is not 0):
            print(fileName)
        img = QImage(fileName)
        if(img.height() is 0 or img.width() is 0):
            msg = QMessageBox()
            msg.setWindowTitle("ERROR")
            msg.setText("File open ERROR")
            msg.exec()
            return
        h = 155
        w = 201

        img_h = img.height()
        img_w = img.width()
        if (img_h > img_w):
            scale_factor = h / img_h
            img_h = h
            img_w *= scale_factor
        else:
            scale_factor = w / img_w
            img_w = w
            img_h *= scale_factor
        image = img.scaledToHeight(img_h)
        self.lbl_pic_view.setPixmap(QPixmap.fromImage(image))
コード例 #8
0
ファイル: utils.py プロジェクト: Indigo6/pdf_ocr
def get_image_view(scene, img_view, image):
    width = scene.width()
    height = scene.height()
    row, col = image.shape[1], image.shape[0]
    a = float(width / row)
    b = float(height / col)
    if a < b:
        scale = a
    else:
        scale = b
    dim = (int(row * scale), int(col * scale))
    # 缩放图像
    resized_frame = cv.resize(image, dim)
    # 将OpenCV格式储存的图片转换为QT可处理的图片类型
    show_img = cv_to_qt(resized_frame)

    # 将图片放入图片显示窗口
    img_item = scene.addPixmap(QPixmap.fromImage(show_img))

    width = img_item.boundingRect().getRect()[2]
    height = img_item.boundingRect().getRect()[3]
    scene_width = img_view.my_scene.width()
    scene_height = img_view.my_scene.height()

    img_item.setX((scene_width - width) / 2)
    img_item.setY((scene_height - height) / 2)
    return img_item
コード例 #9
0
def drag_icon(self, cover, multiple):
    cover = cover.scaledToHeight(120, Qt.SmoothTransformation)
    if multiple:
        base_width = cover.width()
        base_height = cover.height()
        base = QImage(base_width+21, base_height+21,
                QImage.Format_ARGB32_Premultiplied)
        base.fill(QColor(255, 255, 255, 0).rgba())
        p = QPainter(base)
        rect = QRect(20, 0, base_width, base_height)
        p.fillRect(rect, QColor('white'))
        p.drawRect(rect)
        rect.moveLeft(10)
        rect.moveTop(10)
        p.fillRect(rect, QColor('white'))
        p.drawRect(rect)
        rect.moveLeft(0)
        rect.moveTop(20)
        p.fillRect(rect, QColor('white'))
        p.save()
        p.setCompositionMode(p.CompositionMode_SourceAtop)
        p.drawImage(rect.topLeft(), cover)
        p.restore()
        p.drawRect(rect)
        p.end()
        cover = base
    return QPixmap.fromImage(cover)
コード例 #10
0
 def func():
     self._title = self._view.rootObject().property('title').strip()
     img = self._view.grabFramebuffer().scaled(self._size,
                                               Qt.IgnoreAspectRatio,
                                               Qt.SmoothTransformation)
     pixmap = QPixmap.fromImage(img)
     self.thumbnailCreated.emit(pixmap)
コード例 #11
0
ファイル: flip.py プロジェクト: PERCE-NEIGE/Calibribook
    def __call__(self, image, duration=0.5):
        '''
        Start the animation. You must have called :meth:`initialize` first.

        :param duration: Animation duration in seconds.

        '''
        if self.running:
            return
        self.after_image = QPixmap.fromImage(image)

        if self.flip_forwards:
            self.animation.setStartValue(image.width())
            self.animation.setEndValue(0)
            t = self.before_image
            self.before_image = self.after_image
            self.after_image = t
            self.animation.setEasingCurve(QEasingCurve(QEasingCurve.InExpo))
        else:
            self.animation.setStartValue(0)
            self.animation.setEndValue(image.width())
            self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))

        self.animation.setDuration(duration * 1000)
        self.animation.start()
コード例 #12
0
ファイル: book_info.py プロジェクト: jaronliu/calibre
    def refresh(self, row, mi=None):
        if isinstance(row, QModelIndex):
            row = row.row()
        if row == self.current_row and mi is None:
            return
        mi = self.view.model().get_book_display_info(row) if mi is None else mi
        if mi is None:
            # Indicates books was deleted from library, or row numbers have
            # changed
            return

        self.previous_button.setEnabled(False if row == 0 else True)
        self.next_button.setEnabled(False if row ==
                                    self.view.model().rowCount(QModelIndex()) -
                                    1 else True)
        self.current_row = row
        self.setWindowTitle(mi.title)
        self.cover_pixmap = QPixmap.fromImage(mi.cover_data[1])
        try:
            dpr = self.devicePixelRatioF()
        except AttributeError:
            dpr = self.devicePixelRatio()
        self.cover_pixmap.setDevicePixelRatio(dpr)
        self.resize_cover()
        html = render_html(mi,
                           True,
                           self,
                           pref_name='popup_book_display_fields')
        set_html(mi, html, self.details)
        self.marked = mi.marked
        self.cover.setBackgroundBrush(
            self.marked_brush if mi.marked else self.normal_brush)
        self.update_cover_tooltip()
コード例 #13
0
ファイル: MainWindow.py プロジェクト: otakbeku/FERNLV
 def update_faces(self, crops):
     for c in crops:
         label = QtWidgets.QLabel(self.scroll_contents)
         c_res = cv2.resize(c, (320, 240))
         c_res = ut.convert_to_QImage(c_res)
         label.setPixmap(QPixmap.fromImage(c_res))
         self.vertical_layout.addWidget(label)
コード例 #14
0
    def on_pb_cj_clicked(self):
        """读身份证信息(中控) 处理函数"""
        try:
            cr = zkCardReader.CardReader()
        except Exception as e:
            return e

        if cr.openDevice() > 0:
            re = cr.readCard()
            if re == 1:
                self.le_name.setText(cr.info['name'])
                self.le_address.setText(cr.info['address'])
                self.le_sex.setText(cr.info['sex'])
                self.le_nation.setText(cr.info['nation'])
                self.le_birthdate.setText(cr.info['birthdate'])
                self.le_idNum.setText(cr.info['idNum'])
                self.le_issue.setText(cr.info['issue'])
                self.le_effectedDate.setText(str(cr.info['effectedDate']))
                self.le_expiredDate.setText(str(cr.info['expiredDate']))
                photo = base64.b64decode(cr.info['b_Photo'])
                q_photo = QImage.fromData(photo)
                image = QPixmap.fromImage(q_photo)
                self.lb_photo.setPixmap(image)
                cr.closeDevice()
            else:
                QMessageBox.information(self, '提示', '请重新放置身份证!',
                                        QMessageBox.Yes)
        else:
            QMessageBox.information(self, '提示', '身份证阅读器打开失败!', QMessageBox.Yes)
コード例 #15
0
 def openfile(self):
     """ 
     打开图片,并且保存在self.srcImg中
     """
     # 获得图片地址,图片类型
     imgName, imgType = QFileDialog.getOpenFileName(
         self, "打开图片", "", "*.jpg;;*.png;;All Files(*)")
     if imgType != "*.jpg" and imgType != "*.png":
         return
     print(imgName, imgType)
     # 利用OpenCV读入图片并存入self.srcImg中
     self.srcImg = cv2.imread(imgName)
     # 缩放图像为适应窗口的大小
     # 获得缩放比例
     width = self.picview_source.width()
     height = self.picview_source.height()
     row, col = self.srcImg.shape[1], self.srcImg.shape[0]
     a = float(width / row)
     b = float(height / col)
     if a < b:
         scale = a
     else:
         scale = b
     dim = (int(row * scale), int(col * scale))
     # 缩放图像
     tmpImg = cv2.resize(self.srcImg, dim)
     # 将OpenCV格式储存的图片转换为QT可处理的图片类型
     qimg = self.cvPic2Qimg(tmpImg)
     # 将图片放入图片显示窗口
     scene = QGraphicsScene()
     scene.addPixmap(QPixmap.fromImage(qimg))
     self.picview_source.setScene(scene)
     self.hasOpen = True
     self.label_2.setText("处理图像")
コード例 #16
0
ファイル: ui.py プロジェクト: nikolawannabe/calibre
    def __init__(self, parent=None):
        QStackedWidget.__init__(self, parent)
        self.welcome = w = QLabel('<p>'+_(
            'Double click a file in the left panel to start editing'
            ' it.'))
        self.addWidget(w)
        w.setWordWrap(True)
        w.setAlignment(Qt.AlignTop | Qt.AlignHCenter)

        self.container = c = QWidget(self)
        self.addWidget(c)
        l = c.l = QVBoxLayout(c)
        c.setLayout(l)
        l.setContentsMargins(0, 0, 0, 0)
        self.editor_tabs = t = QTabWidget(c)
        l.addWidget(t)
        t.setDocumentMode(True)
        t.setTabsClosable(True)
        t.setMovable(True)
        pal = self.palette()
        if pal.color(pal.WindowText).lightness() > 128:
            i = QImage(I('modified.png'))
            i.invertPixels()
            self.modified_icon = QIcon(QPixmap.fromImage(i))
        else:
            self.modified_icon = QIcon(I('modified.png'))
        self.editor_tabs.currentChanged.connect(self.current_editor_changed)
        self.editor_tabs.tabCloseRequested.connect(self._close_requested)
        self.search_panel = SearchPanel(self)
        l.addWidget(self.search_panel)
        self.restore_state()
        self.editor_tabs.tabBar().installEventFilter(self)
コード例 #17
0
ファイル: widget.py プロジェクト: elonchen/calibre
def create_icon(text, palette=None, sz=None, divider=2, fill='white'):
    if isinstance(fill, string_or_bytes):
        fill = QColor(fill)
    sz = sz or int(
        math.ceil(tprefs['toolbar_icon_size'] *
                  QApplication.instance().devicePixelRatio()))
    if palette is None:
        palette = QApplication.palette()
    img = QImage(sz, sz, QImage.Format_ARGB32)
    img.fill(Qt.transparent)
    p = QPainter(img)
    p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
    if fill is not None:
        qDrawShadeRect(p,
                       img.rect(),
                       palette,
                       fill=fill,
                       lineWidth=1,
                       midLineWidth=1)
    f = p.font()
    f.setFamily('Liberation Sans'), f.setPixelSize(int(
        sz // divider)), f.setBold(True)
    p.setFont(f), p.setPen(Qt.black)
    p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
    p.end()
    return QIcon(QPixmap.fromImage(img))
コード例 #18
0
ファイル: newmember.py プロジェクト: nintyning/onnuri
    def showPicture(self):
        fileName = DBConnectSingleton.instance.getPicPath(self.p_id)
        self.lbl_photo_loc.setText(fileName)
        if (len(fileName) is not 0):
            print(fileName)
        img = QImage(fileName)
        if(img.width() is 0 or img.height() is 0):
            msgBox = QMessageBox()
            msgBox.setText("The file is not exist.");
            msgBox.exec();
            return
        h = self.lbl_photo_view.height()
        w = self.lbl_photo_view.width()

        img_h = img.height()
        img_w = img.width()
        if (img_h > img_w):
            scale_factor = h / img_h
            img_h = h
            img_w *= scale_factor
        else:
            scale_factor = w / img_w
            img_w = w
            img_h *= scale_factor
        image = img.scaledToHeight(img_h)
        self.lbl_photo_view.setPixmap(QPixmap.fromImage(image))
コード例 #19
0
    def simgv_load_image_to_viewer(self, index):
        """
        Load an image to viewer. If the show feature points is checked, then load feature points as well.
        This option can be done only if the user has run a feature point method first.
        :param index: index of image to load.
        :return: Nothing
        """
        if self.draw_kp:
            img_rgb = self.image_list[index].img_get_img_rgb_with_feature_points()
            feature_point_number = len(self.image_list[index].feature_points.keypoints)
            self.ui_simple_img_viewer.label_feature_points_number.setText(str(feature_point_number))
        else:
            img_rgb = self.image_list[index].img_get_img_rgb()
            self.ui_simple_img_viewer.label_feature_points_number.clear()
        bytes_per_line = 3 * self.image_list[index].info.width
        q_img = QImage(img_rgb, self.image_list[index].info.width, self.image_list[index].info.height,
                                bytes_per_line, QImage.Format_RGB888)
        width = self.ui_simple_img_viewer.image_view.width()
        height = self.ui_simple_img_viewer.image_view.height()
        if q_img.width() < width or q_img.height() < height:
            width = q_img.width()
            height = q_img.height()
        size = QSize(width, height)
        pixmap = QPixmap()
        pixmap = pixmap.fromImage(q_img)
        pixmap = pixmap.scaled(size, self.Q_ASPECT_RATIO)
        self.ui_simple_img_viewer.image_view.setPixmap(pixmap)
        self.ui_simple_img_viewer.image_view.show()

        self.ui_simple_img_viewer.button_previous.setEnabled(self.UP)
        self.ui_simple_img_viewer.button_next.setEnabled(self.UP)
        if index == 0:
            self.ui_simple_img_viewer.button_previous.setEnabled(self.DOWN)
        if index == len(self.image_list) - 1:
            self.ui_simple_img_viewer.button_next.setEnabled(self.DOWN)
コード例 #20
0
ファイル: covers.py プロジェクト: MinghuiGao/calibre
def test(scale=0.5):
    from PyQt5.Qt import QLabel, QApplication, QPixmap, QMainWindow, QWidget, QScrollArea, QGridLayout
    app = QApplication([])
    mi = Metadata('xxx', ['Kovid Goyal', 'John Q. Doe', 'Author'])
    mi.series = 'A series of styles'
    m = QMainWindow()
    sa = QScrollArea(m)
    w = QWidget(m)
    sa.setWidget(w)
    l = QGridLayout(w)
    w.setLayout(l), l.setSpacing(30)
    labels = []
    for r, color in enumerate(sorted(default_color_themes)):
        for c, style in enumerate(sorted(all_styles())):
            mi.series_index = c + 1
            mi.title = 'An algorithmic cover [%s]' % color
            prefs = override_prefs(cprefs, override_color_theme=color, override_style=style)
            for x in ('cover_width', 'cover_height', 'title_font_size', 'subtitle_font_size', 'footer_font_size'):
                prefs[x] = int(scale * prefs[x])
            img = generate_cover(mi, prefs=prefs, as_qimage=True)
            la = QLabel()
            la.setPixmap(QPixmap.fromImage(img))
            l.addWidget(la, r, c)
            labels.append(la)
    m.setCentralWidget(sa)
    w.resize(w.sizeHint())
    m.show()
    app.exec_()
コード例 #21
0
ファイル: view.py プロジェクト: zyhong/calibre
 def failed_img(self):
     if self._failed_img is None:
         try:
             dpr = self.devicePixelRatioF()
         except AttributeError:
             dpr = self.devicePixelRatio()
         i = QImage(200, 150, QImage.Format_ARGB32)
         i.setDevicePixelRatio(dpr)
         i.fill(Qt.white)
         p = QPainter(i)
         r = i.rect().adjusted(10, 10, -10, -10)
         n = QPen(Qt.DashLine)
         n.setColor(Qt.black)
         p.setPen(n)
         p.drawRect(r)
         p.setPen(Qt.black)
         f = self.font()
         f.setPixelSize(20)
         p.setFont(f)
         p.drawText(r.adjusted(10, 0, -10, 0),
                    Qt.AlignCenter | Qt.TextWordWrap,
                    _('Image could not be rendered'))
         p.end()
         self._failed_img = QPixmap.fromImage(i)
     return self._failed_img
コード例 #22
0
def test(scale=0.25):
    from PyQt5.Qt import QLabel, QApplication, QPixmap, QMainWindow, QWidget, QScrollArea, QGridLayout
    app = QApplication([])
    mi = Metadata('xxx', ['Kovid Goyal', 'John & Doe', 'Author'])
    mi.series = 'A series of styles'
    m = QMainWindow()
    sa = QScrollArea(m)
    w = QWidget(m)
    sa.setWidget(w)
    l = QGridLayout(w)
    w.setLayout(l), l.setSpacing(30)
    labels = []
    for r, color in enumerate(sorted(default_color_themes)):
        for c, style in enumerate(sorted(all_styles())):
            mi.series_index = c + 1
            mi.title = 'An algorithmic cover [%s]' % color
            prefs = override_prefs(cprefs,
                                   override_color_theme=color,
                                   override_style=style)
            scale_cover(prefs, scale)
            img = generate_cover(mi, prefs=prefs, as_qimage=True)
            la = QLabel()
            la.setPixmap(QPixmap.fromImage(img))
            l.addWidget(la, r, c)
            labels.append(la)
    m.setCentralWidget(sa)
    w.resize(w.sizeHint())
    m.show()
    app.exec_()
コード例 #23
0
ファイル: book_info.py プロジェクト: bwhitenb5e/calibre
    def refresh(self, row, mi=None):
        if isinstance(row, QModelIndex):
            row = row.row()
        if row == self.current_row and mi is None:
            return
        mi = self.view.model().get_book_display_info(row) if mi is None else mi
        if mi is None:
            # Indicates books was deleted from library, or row numbers have
            # changed
            return

        self.previous_button.setEnabled(False if row == 0 else True)
        self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True)
        self.current_row = row
        self.setWindowTitle(mi.title)
        self.cover_pixmap = QPixmap.fromImage(mi.cover_data[1])
        try:
            dpr = self.devicePixelRatioF()
        except AttributeError:
            dpr = self.devicePixelRatio()
        self.cover_pixmap.setDevicePixelRatio(dpr)
        self.resize_cover()
        html = render_html(mi, self.css, True, self, all_fields=True)
        self.details.setHtml(html)
        self.marked = mi.marked
        self.cover.setBackgroundBrush(self.marked_brush if mi.marked else self.normal_brush)
        self.update_cover_tooltip()
コード例 #24
0
ファイル: SiteInfo.py プロジェクト: zy-sunshine/falkon-pyqt5
            def imageReplyCb():
                if self._imageReply.error() != QNetworkReply.NoError:
                    return

                # QByteArray
                data = self._imageReply.readAll()
                self._showPixmap(QPixmap.fromImage(QImage.fromData(data)))
コード例 #25
0
ファイル: covers.py プロジェクト: artbycrunk/calibre
def test(scale=0.25):
    from PyQt5.Qt import QLabel, QPixmap, QMainWindow, QWidget, QScrollArea, QGridLayout
    from calibre.gui2 import Application
    app = Application([])
    mi = Metadata('Unknown', ['Kovid Goyal', 'John & Doe', 'Author'])
    mi.series = 'A series & styles'
    m = QMainWindow()
    sa = QScrollArea(m)
    w = QWidget(m)
    sa.setWidget(w)
    l = QGridLayout(w)
    w.setLayout(l), l.setSpacing(30)
    scale *= w.devicePixelRatioF()
    labels = []
    for r, color in enumerate(sorted(default_color_themes)):
        for c, style in enumerate(sorted(all_styles())):
            mi.series_index = c + 1
            mi.title = 'An algorithmic cover [%s]' % color
            prefs = override_prefs(cprefs, override_color_theme=color, override_style=style)
            scale_cover(prefs, scale)
            img = generate_cover(mi, prefs=prefs, as_qimage=True)
            img.setDevicePixelRatio(w.devicePixelRatioF())
            la = QLabel()
            la.setPixmap(QPixmap.fromImage(img))
            l.addWidget(la, r, c)
            labels.append(la)
    m.setCentralWidget(sa)
    w.resize(w.sizeHint())
    m.show()
    app.exec_()
コード例 #26
0
ファイル: main.py プロジェクト: whtt/HandWritingRecognization
 def btn_recog_clicked(self):
     self.update()
     savePath = "./recog.jpg"
     image = self.__canvas.get_current_image()
     image.save(savePath)
     save_path = os.path.abspath(savePath)
     self.label_log.append("image saved in path:\n{}".format(save_path))
     method_text = self.__box_method.currentText()
     self.label_log.append('method: {}'.format(method_text))
     predict = self.METHOD_KERNEL.set_kernel(savePath, method_text)
     # pic = QTextImageFormat()
     # pic.setName('./feature_map.jpg')
     # pic.setHeight(100)
     # pic.setWidth(100)
     showImage = QImage('./feature_map.jpg').scaled(100, 100)
     self.feature_map.setPixmap(QPixmap.fromImage(showImage))
     # self.label_log.append('feature map:\n')
     # self.label_log.textCursor().insertImage('./feature_map.jpg')
     self.label_log.append("recognition result is: {}".format(predict))
     # self.label_log.moveCursor(QTextCursor.End)
     # self.label_log.textCursor().clearSelection()
     # del pic
     message = QMessageBox()
     message.setText("recognition result is: {}".format(predict))
     # message.addButton()
     message.exec_()
コード例 #27
0
 def on_tv_attendance_clicked(self):
     rowID = self.tv_attendance.currentIndex().row()
     image = self.queryModel.index(rowID, 11).data()
     bimage = base64.b64decode(image)
     fileimage = QImage.fromData(bimage)
     piximage = QPixmap.fromImage(fileimage)
     self.label_image.setPixmap(piximage)
     self.label_image.setScaledContents(True)
コード例 #28
0
 def undo(self):
     if self.__undo_num > 0:
         image = self.__undo_list[self.__undo_num - 1]
         self.__board = QPixmap.fromImage(image)
         self.update()
         self.__redo_list.append(self.__undo_list.pop())
         self.__redo_num += 1
         self.__undo_num -= 1
コード例 #29
0
ファイル: uarm_ui.py プロジェクト: vimior/UF-Debug-Tool
    def _set_common_top_ui(self):
        top_frame = QFrame()
        top_frame.setMaximumHeight(60)
        top_layout = QVBoxLayout(top_frame)
        self.layout.addWidget(top_frame)

        common_top_frame = QFrame()
        common_top_frame.setMinimumHeight(50)
        common_top_frame.setMaximumHeight(50)
        common_top_layout = QHBoxLayout(common_top_frame)
        top_layout.addWidget(common_top_frame)
        common_top_layout.addStretch(0)

        label = QLabel(i18n[self.lang]['Type'] + ':')
        self.label_type = QLabel('')
        self.label_type.setStyleSheet('''color: gray;font:bold;''')
        common_top_layout.addWidget(label)
        common_top_layout.addWidget(self.label_type)

        label = QLabel(i18n[self.lang]['Mode'] + ':')
        self.label_mode = QLabel('')
        self.label_mode.setStyleSheet('''color: gray;font:bold;''')
        common_top_layout.addWidget(label)
        common_top_layout.addWidget(self.label_mode)

        label = QLabel(i18n[self.lang]['HardwareVersion'] + ':')
        self.label_hard_version = QLabel('')
        self.label_hard_version.setStyleSheet('''color: gray;font:bold;''')
        common_top_layout.addWidget(label)
        common_top_layout.addWidget(self.label_hard_version)

        label = QLabel(i18n[self.lang]['FirmwareVersion'] + ':')
        self.label_firm_version = QLabel('')
        self.label_firm_version.setStyleSheet('''color: gray;font:bold;''')
        common_top_layout.addWidget(label)
        common_top_layout.addWidget(self.label_firm_version)

        label_1 = QLabel(i18n[self.lang]['Connected'] + ':')
        self.label_connected = QLabel()
        img = QImage()
        self.label_connected.setMaximumHeight(20)
        self.label_connected.setMaximumWidth(20)
        self.label_connected.setScaledContents(True)
        if img.load(disconnect_icon_path):
            self.label_connected.setPixmap(QPixmap.fromImage(img))

        self.lnt_addr = QLineEdit('COM12')
        self.lnt_addr.setMaximumWidth(50)
        self.lnt_addr.setMinimumWidth(30)
        self.btn_connect = QPushButton(i18n[self.lang]['Connect'])
        # self.btn_connect.setMaximumWidth(50)

        # common_top_layout.addStretch(0)
        common_top_layout.setSpacing(10)
        common_top_layout.addWidget(label_1)
        common_top_layout.addWidget(self.label_connected)
        common_top_layout.addWidget(self.lnt_addr)
        common_top_layout.addWidget(self.btn_connect)
コード例 #30
0
ファイル: open_with.py プロジェクト: WilliamRJohns/glacier.io
 def entry_to_item(entry, parent):
     icon = get_icon(entry.get('icon_file'), as_data=False)
     if icon is None:
         icon = entry_to_icon_text(entry)[0]
     else:
         icon = QPixmap.fromImage(icon)
     ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     ans.setToolTip(_('Application path:') + '\n' + entry['path'])
コード例 #31
0
ファイル: editor.py プロジェクト: xitiz007/photoEditor1.2
 def showImage(self):
     self.imageShow = self.image.convert("RGBA")
     data = self.imageShow.tobytes('raw', 'RGBA')
     img = QImage(data, self.imageShow.size[0], self.imageShow.size[1],
                  QImage.Format_RGBA8888)
     self.pixmap = QPixmap.fromImage(img)
     self.label.setPixmap(
         self.pixmap.scaled(self.label.size(), QtCore.Qt.IgnoreAspectRatio))
     self.label.setGeometry(200, 100, 900, 500)
コード例 #32
0
ファイル: open_with.py プロジェクト: JapaChin/calibre
 def entry_to_item(entry, parent):
     icon = get_icon(entry.get('icon_file'), as_data=False)
     if icon is None:
         icon = entry_to_icon_text(entry)[0]
     else:
         icon = QPixmap.fromImage(icon)
     ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
     ans.setData(ENTRY_ROLE, entry)
     ans.setToolTip(_('Application path:') + '\n' + entry['path'])
コード例 #33
0
 def winddir_rotation(self, x):
     im = Image.open('icons\\winddir.png')
     rot = im.rotate(-1 * self.winddirs[x] - 180,
                     resample=Image.BICUBIC,
                     expand=True)
     rot = rot.crop((0, 0, 128, 128))
     rot = ImageQt(rot)
     rot = QPixmap.fromImage(rot)
     rot = rot.scaled(64, 64)
     self.winddirimg.setPixmap(rot)
コード例 #34
0
ファイル: main.py プロジェクト: ADari-Ka/mapsAPI
 def update_image(self):
     """Get image from staticAPI"""
     response = requests.get(STATIC_API_URL, params=self.static_api_params)
     self.map_container.clear()
     if response is None:
         # Report an error
         self.map_container.setText("Connection Failed")
     else:
         # Set image
         img = QPixmap.fromImage(QImage.fromData(response.content))
         self.map_container.setPixmap(img)
コード例 #35
0
ファイル: gcode_ui.py プロジェクト: vimior/UF-Debug-Tool
 def load_image(self):
     fname = QFileDialog.getOpenFileName(self.main_ui.window, 'Open file',
                                         '', '*.svg')
     if fname and fname[0]:
         img = QImage()
         if img.load(fname[0]):
             self.label_img.setPixmap(QPixmap.fromImage(img))
             with open(fname[0], 'rb') as f:
                 self.handler.source = f.read()
                 self.handler.template = None
                 self.gcode = None
                 self.up_frame.show()
コード例 #36
0
ファイル: covers.py プロジェクト: tokot/calibre
 def update_preview(self):
     if self.ignore_changed:
         return
     w, h = self.preview_label.sizeHint().width(), self.preview_label.sizeHint().height()
     prefs = self.prefs_for_rendering
     hr = h / prefs['cover_height']
     for x in ('title', 'subtitle', 'footer'):
         attr = '%s_font_size' % x
         prefs[attr] = int(prefs[attr] * hr)
     prefs['cover_width'], prefs['cover_height'] = w, h
     img = generate_cover(self.mi, prefs=prefs, as_qimage=True)
     self.preview_label.setPixmap(QPixmap.fromImage(img))
コード例 #37
0
ファイル: caches.py プロジェクト: JimmXinu/calibre
    def __getitem__(self, key):
        ' Must be called in the GUI thread '
        with self.lock:
            self.clear_staging()
            ans = self.items.pop(key, False)  # pop() so that item is moved to the top
            if ans is not False:
                if isinstance(ans, QImage):
                    # Convert to QPixmap, since rendering QPixmap is much
                    # faster
                    ans = QPixmap.fromImage(ans)
                self.items[key] = ans

        return ans
コード例 #38
0
ファイル: uarm_ui.py プロジェクト: vimior/UF-Debug-Tool
 def update_connect_status(self, item):
     try:
         img = QImage()
         if item and self.status != 1:
             self.status = 1
             logger.info('connect to {} success'.format(self.handler.port))
             if img.load(connect_icon_path):
                 self.label_connected.setPixmap(QPixmap.fromImage(img))
                 self.btn_connect.setText(i18n[self.lang]['Disconnect'])
                 self.btn_connect.setStyleSheet('''color: red;font:bold;''')
             self.set_disable(False)
         elif not item and self.status != 0:
             self.status = 0
             logger.info('disconnect from {0} or failed connect {0}'.format(self.handler.port))
             self.handler.cmd_que.queue.clear()
             if img.load(disconnect_icon_path):
                 self.label_connected.setPixmap(QPixmap.fromImage(img))
                 self.btn_connect.setText(i18n[self.lang]['Connect'])
                 self.btn_connect.setStyleSheet('''color: green;font:bold;''')
             self.set_disable(True)
     except Exception as e:
         print(e)
コード例 #39
0
ファイル: covers.py プロジェクト: JimmXinu/calibre
 def update_preview(self):
     if self.ignore_changed:
         return
     dpr = getattr(self, 'devicePixelRatioF', self.devicePixelRatio)()
     w, h = int(dpr * self.preview_label.sizeHint().width()), int(dpr * self.preview_label.sizeHint().height())
     prefs = self.prefs_for_rendering
     hr = h / prefs['cover_height']
     for x in ('title', 'subtitle', 'footer'):
         attr = '%s_font_size' % x
         prefs[attr] = int(prefs[attr] * hr)
     prefs['cover_width'], prefs['cover_height'] = w, h
     img = generate_cover(self.mi, prefs=prefs, as_qimage=True)
     img.setDevicePixelRatio(dpr)
     self.preview_label.setPixmap(QPixmap.fromImage(img))
コード例 #40
0
ファイル: book_details.py プロジェクト: GaryMMugford/calibre
 def show_data(self, data):
     self.animation.stop()
     same_item = getattr(data, "id", True) == self.data.get("id", False)
     self.data = {"id": data.get("id", None)}
     if data.cover_data[1]:
         self.pixmap = QPixmap.fromImage(data.cover_data[1])
         if self.pixmap.isNull() or self.pixmap.width() < 5 or self.pixmap.height() < 5:
             self.pixmap = self.default_pixmap
     else:
         self.pixmap = self.default_pixmap
     self.do_layout()
     self.update()
     if not same_item and not config["disable_animations"] and self.isVisible():
         self.animation.start()
コード例 #41
0
ファイル: widget.py プロジェクト: Ralnoc/calibre
def create_icon(text, palette=None, sz=32, divider=2):
    if palette is None:
        palette = QApplication.palette()
    img = QImage(sz, sz, QImage.Format_ARGB32)
    img.fill(Qt.transparent)
    p = QPainter(img)
    p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
    qDrawShadeRect(p, img.rect(), palette, fill=QColor('#ffffff'), lineWidth=1, midLineWidth=1)
    f = p.font()
    f.setFamily('Liberation Sans'), f.setPixelSize(sz // divider), f.setBold(True)
    p.setFont(f), p.setPen(Qt.black)
    p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
    p.end()
    return QIcon(QPixmap.fromImage(img))
コード例 #42
0
ファイル: proceed.py プロジェクト: j-howell/calibre
    def start_show_animation(self):
        if self.rendered_pixmap is not None:
            return

        dpr = getattr(self, 'devicePixelRatioF', self.devicePixelRatio)()
        p = QImage(dpr * self.size(), QImage.Format_ARGB32_Premultiplied)
        p.setDevicePixelRatio(dpr)
        self.render(p)
        self.rendered_pixmap = QPixmap.fromImage(p)
        self.original_visibility = v = []
        for child in self.findChildren(QWidget):
            if child.isVisible():
                child.setVisible(False)
                v.append(child)
        self.show_animation.start()
コード例 #43
0
ファイル: flip.py プロジェクト: Aliminator666/calibre
    def initialize(self, image, forwards=True):
        '''
        Initialize the flipper, causes the flipper to show itself displaying
        the full `image`.

        :param image: The image to display as background
        :param forwards: If True flipper will flip forwards, otherwise
                         backwards

        '''
        self.flip_forwards = forwards
        self.before_image = QPixmap.fromImage(image)
        self.after_image = None
        self.setGeometry(0, 0, image.width(), image.height())
        self.setVisible(True)
コード例 #44
0
ファイル: image_popup.py プロジェクト: MarioJC/calibre
def render_svg(widget, path):
    img = QPixmap()
    rend = QSvgRenderer()
    if rend.load(path):
        dpr = getattr(widget, 'devicePixelRatioF', widget.devicePixelRatio)()
        sz = rend.defaultSize()
        h = (max_available_height() - 50)
        w = int(h * sz.height() / float(sz.width()))
        pd = QImage(w * dpr, h * dpr, QImage.Format_RGB32)
        pd.fill(Qt.white)
        p = QPainter(pd)
        rend.render(p)
        p.end()
        img = QPixmap.fromImage(pd)
        img.setDevicePixelRatio(dpr)
    return img
コード例 #45
0
ファイル: canvas.py プロジェクト: Ralnoc/calibre
 def load_pixmap(self):
     canvas_size = self.rect().width(), self.rect().height()
     if self.last_canvas_size != canvas_size:
         if self.last_canvas_size is not None and self.selection_state.rect is not None:
             self.selection_state.reset()
             # TODO: Migrate the selection rect
         self.last_canvas_size = canvas_size
         self.current_scaled_pixmap = None
     if self.current_scaled_pixmap is None:
         pwidth, pheight = self.last_canvas_size
         i = self.current_image
         width, height = i.width(), i.height()
         scaled, width, height = fit_image(width, height, pwidth, pheight)
         if scaled:
             i = self.current_image.scaled(width, height, transformMode=Qt.SmoothTransformation)
         self.current_scaled_pixmap = QPixmap.fromImage(i)
コード例 #46
0
ファイル: book_details.py プロジェクト: bwhitenb5e/calibre
 def update_cover(self, pmap=None, cdata=None):
     if pmap is None:
         pmap = QPixmap()
         pmap.loadFromData(cdata)
     if pmap.isNull():
         return
     if pmap.hasAlphaChannel():
         pmap = QPixmap.fromImage(blend_image(image_from_x(pmap)))
     self.pixmap = pmap
     self.do_layout()
     self.update()
     self.update_tooltip(getattr(self.parent(), 'current_path', ''))
     if not config['disable_animations']:
         self.animation.start()
     id_ = self.data.get('id', None)
     if id_ is not None:
         self.cover_changed.emit(id_, cdata or pixmap_to_data(pmap))
コード例 #47
0
ファイル: widget.py プロジェクト: davidfor/calibre
def create_icon(text, palette=None, sz=None, divider=2, fill='white'):
    if isinstance(fill, basestring):
        fill = QColor(fill)
    sz = sz or int(math.ceil(tprefs['toolbar_icon_size'] * QApplication.instance().devicePixelRatio()))
    if palette is None:
        palette = QApplication.palette()
    img = QImage(sz, sz, QImage.Format_ARGB32)
    img.fill(Qt.transparent)
    p = QPainter(img)
    p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
    if fill is not None:
        qDrawShadeRect(p, img.rect(), palette, fill=fill, lineWidth=1, midLineWidth=1)
    f = p.font()
    f.setFamily('Liberation Sans'), f.setPixelSize(int(sz // divider)), f.setBold(True)
    p.setFont(f), p.setPen(Qt.black)
    p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
    p.end()
    return QIcon(QPixmap.fromImage(img))
コード例 #48
0
ファイル: view.py プロジェクト: AtulKumar2/calibre
 def failed_img(self):
     if self._failed_img is None:
         i = QImage(200, 150, QImage.Format_ARGB32)
         i.fill(Qt.white)
         p = QPainter(i)
         r = i.rect().adjusted(10, 10, -10, -10)
         n = QPen(Qt.DashLine)
         n.setColor(Qt.black)
         p.setPen(n)
         p.drawRect(r)
         p.setPen(Qt.black)
         f = self.font()
         f.setPixelSize(20)
         p.setFont(f)
         p.drawText(r.adjusted(10, 0, -10, 0), Qt.AlignCenter | Qt.TextWordWrap, _('Image could not be rendered'))
         p.end()
         self._failed_img = QPixmap.fromImage(i)
     return self._failed_img
コード例 #49
0
ファイル: canvas.py プロジェクト: artbycrunk/calibre
 def load_pixmap(self):
     canvas_size = self.rect().width(), self.rect().height()
     if self.last_canvas_size != canvas_size:
         if self.last_canvas_size is not None and self.selection_state.rect is not None:
             self.selection_state.reset()
             # TODO: Migrate the selection rect
         self.last_canvas_size = canvas_size
         self.current_scaled_pixmap = None
     if self.current_scaled_pixmap is None:
         pwidth, pheight = self.last_canvas_size
         i = self.current_image
         width, height = i.width(), i.height()
         scaled, width, height = fit_image(width, height, pwidth, pheight)
         try:
             dpr = self.devicePixelRatioF()
         except AttributeError:
             dpr = self.devicePixelRatio()
         if scaled:
             i = self.current_image.scaled(int(dpr * width), int(dpr * height), transformMode=Qt.SmoothTransformation)
         self.current_scaled_pixmap = QPixmap.fromImage(i)
         self.current_scaled_pixmap.setDevicePixelRatio(dpr)