当前位置: 首页>>代码示例>>Python>>正文


Python QImage.load方法代码示例

本文整理汇总了Python中PyQt4.Qt.QImage.load方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.load方法的具体用法?Python QImage.load怎么用?Python QImage.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.Qt.QImage的用法示例。


在下文中一共展示了QImage.load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _populate_covers

# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import load [as 别名]
    def _populate_covers(self):
        '''
        Display calibre cover for both unless mismatch
        '''
        def _fetch_marvin_cover(border_width=0):
            '''
            Retrieve LargeCoverJpg from cache
            '''
            #self._log_location('border_width: {0}'.format(border_width))
            con = sqlite3.connect(self.marvin_db_path)
            with con:
                con.row_factory = sqlite3.Row

                # Fetch Hash from mainDb
                cover_cur = con.cursor()
                cover_cur.execute('''SELECT
                                      Hash
                                     FROM Books
                                     WHERE ID = '{0}'
                                  '''.format(self.book_id))
                row = cover_cur.fetchone()

            book_hash = row[b'Hash']
            large_covers_subpath = self.connected_device._cover_subpath(size="large")
            cover_path = '/'.join([large_covers_subpath, '%s.jpg' % book_hash])
            stats = self.parent.ios.exists(cover_path)
            if stats:
                self._log("fetching large cover from cache")
                #self._log("cover size: {:,} bytes".format(int(stats['st_size'])))
                cover_bytes = self.parent.ios.read(cover_path, mode='rb')
                m_image = QImage()
                m_image.loadFromData(cover_bytes)

                if border_width:
                    # Construct a QPixmap with oversized yellow background
                    m_image = m_image.scaledToHeight(
                        self.COVER_ICON_SIZE - border_width * 2,
                        Qt.SmoothTransformation)

                    self.m_pixmap = QPixmap(
                        QSize(m_image.width() + border_width * 2,
                              m_image.height() + border_width * 2))

                    m_painter = QPainter(self.m_pixmap)
                    m_painter.setRenderHints(m_painter.Antialiasing)

                    m_painter.fillRect(self.m_pixmap.rect(), self.MISMATCH_COLOR)
                    m_painter.drawImage(border_width,
                                        border_width,
                                        m_image)
                else:
                    m_image = m_image.scaledToHeight(
                        self.COVER_ICON_SIZE,
                        Qt.SmoothTransformation)

                    self.m_pixmap = QPixmap(
                        QSize(m_image.width(),
                              m_image.height()))

                    m_painter = QPainter(self.m_pixmap)
                    m_painter.setRenderHints(m_painter.Antialiasing)

                    m_painter.drawImage(0, 0, m_image)

                self.marvin_cover.setPixmap(self.m_pixmap)
            else:
                # No cover available, use generic
                self._log("No cached cover, using generic")
                pixmap = QPixmap()
                pixmap.load(I('book.png'))
                pixmap = pixmap.scaled(self.COVER_ICON_SIZE,
                                       self.COVER_ICON_SIZE,
                                       aspectRatioMode=Qt.KeepAspectRatio,
                                       transformMode=Qt.SmoothTransformation)
                self.marvin_cover.setPixmap(pixmap)

        self.calibre_cover.setMaximumSize(QSize(self.COVER_ICON_SIZE, self.COVER_ICON_SIZE))
        self.calibre_cover.setText('')
        self.calibre_cover.setScaledContents(False)

        self.marvin_cover.setMaximumSize(QSize(self.COVER_ICON_SIZE, self.COVER_ICON_SIZE))
        self.marvin_cover.setText('')
        self.marvin_cover.setScaledContents(False)

        if self.cid:
            db = self.opts.gui.current_db
            if 'cover_hash' not in self.mismatches:
                mi = db.get_metadata(self.cid, index_is_id=True, get_cover=True, cover_as_data=True)

                c_image = QImage()
                if mi.has_cover:
                    c_image.loadFromData(mi.cover_data[1])
                    c_image = c_image.scaledToHeight(self.COVER_ICON_SIZE,
                                                     Qt.SmoothTransformation)
                    self.c_pixmap = QPixmap(QSize(c_image.width(),
                                                  c_image.height()))
                    c_painter = QPainter(self.c_pixmap)
                    c_painter.setRenderHints(c_painter.Antialiasing)
                    c_painter.drawImage(0, 0, c_image)
                else:
#.........这里部分代码省略.........
开发者ID:DuskyRose,项目名称:calibre-marvin-manager,代码行数:103,代码来源:view_metadata.py

示例2: Slideshow

# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import load [as 别名]
class Slideshow(Slide):
    '''
    basic slideshow class for FabLabInfo
    '''

    imgList = list()

    def __init__(self, parent = None):
        '''
        Constructor
        '''
        super(Slideshow, self).__init__(parent)
        #self.setStyleSheet("background: #000;")
        
        self.imageLabel = QLabel()
        self.imageLabel.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        self.imageLabel.setParent(self)
        self.validityChecker = QImage()
        
        self.slideIterator = 0
        self.interval = 1
        self.timer.timeout.connect(self.nextImage)
        self.fileList = list()
        self.currIndex = 0
        
        self.layout = QHBoxLayout()
        self.layout.setMargin(0)
        self.layout.addWidget(self.imageLabel)
        self.layout.setAlignment(self.imageLabel, Qt.AlignHCenter)
        self.setLayout(self.layout)
        
    def setup(self, imgFolder, interval=10, cacheSize=10):
        ''' setup the slide for it's display routine '''
        
        self.interval = interval
        self.cacheSize = cacheSize
        self.fileList = glob(imgFolder + "/*.jpg")
        
        while len(self.imgList) < self.cacheSize:
            if self.validityChecker.load(self.fileList[self.currIndex%len(self.fileList)]):
                self.imgList.append(self.validityChecker)
                print("Image file found - caching it")
            self.currIndex += 1

    
    def run(self):
        ''' run the widgets display routine '''
        
        self.timer.start(self.interval*1000)
        self.nextImage()
        
    def nextImage(self):
        ''' take image from list and scale it 
        to height of parent widget
        (which should be QMainWindow). 
        Then generate a pixmap from the scaled 
        image and display it on a QLabel'''
    
        image = self.imgList[(self.currIndex+1)%len(self.imgList)]
            
        currImage = QPixmap.fromImage(image.scaledToHeight(self.parentWidget().height(), Qt.SmoothTransformation))
        self.imageLabel.setPixmap(currImage)
        
        if self.validityChecker.load(self.fileList[self.currIndex%len(self.fileList)]):
            self.imgList[self.currIndex%len(self.imgList)] = self.validityChecker
            print("Preloading next image")
    
        self.currIndex += 1
        
    def stop(self):
        Slide.stop(self)
        self.timer.stop()
        self.currIndex=0

    def shutdown(self):
        qWarning("Shutting down Slideshow-Module, this will purge all loaded images! \nTo pause, use stop() instead")
        Slide.shutdown(self)
        self.timer.stop()
        self.imgList.clear()
        self.fileList.clear()
        self.currIndex=0
开发者ID:fluetke,项目名称:fablab-info,代码行数:83,代码来源:Slideshow.py


注:本文中的PyQt4.Qt.QImage.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。