码迷,mamicode.com
首页 > 其他好文 > 详细

????????????

时间:2015-07-16 19:30:08      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:

import sys

import os

import utils

 

 

from PyQt4 import QtGui,QtCore

 

 

class SlideShowPics(QtGui.QMainWindow):

 

    """ SlideShowPics class defines the methods for UI and

        working logic

    """

    def __init__(self, imgLst, parent=None):

        super(SlideShowPics, self).__init__(parent)

        # self._path = path

        self._imageCache = []

        self._imagesInList = imgLst

        self._pause = False

        self._count = 0

        self.animFlag = True

        self.updateTimer = QtCore.QTimer()

        self.connect(self.updateTimer, QtCore.SIGNAL("timeout()"), self.nextImage)

        self.prepairWindow()

        self.nextImage()

 

    def prepairWindow(self):

        # Centre UI

        screen = QtGui.QDesktopWidget().screenGeometry(self)

        size = self.geometry()

        self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)

        self.setStyleSheet("QWidget{}")

        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

        self.buildUi()

        self.showFullScreen()

        self.playPause()

 

    def buildUi(self):

        self.label = QtGui.QLabel()

        self.label.setAlignment(QtCore.Qt.AlignCenter)

        self.setCentralWidget(self.label)

 

    def nextImage(self):

        """ switch to next image or previous image

        """

        if self._imagesInList:

            if self._count == len(self._imagesInList):

                self._count = 0

 

            self.showImageByPath(

                    self._imagesInList[self._count])

 

            if self.animFlag:

                self._count += 1

            else:

                self._count -= 1

 

 

    def showImageByPath(self, path):

        if path:

            image = QtGui.QImage(path)

            pp = QtGui.QPixmap.fromImage(image)

            self.label.setPixmap(pp.scaled(

                    self.label.size(),

                    QtCore.Qt.KeepAspectRatio,

                    QtCore.Qt.SmoothTransformation))

 

    def playPause(self):

        if not self._pause:

            self._pause = True

            self.updateTimer.start(2500)

            return self._pause

        else:

            self._pause = False

            self.updateTimer.stop()

 

    def keyPressEvent(self, keyevent):

        """ Capture key to exit, next image, previous image,

            on Escape , Key Right and key left respectively.

        """

        event = keyevent.key()

        if event == QtCore.Qt.Key_Escape:

            self.close()

        if event == QtCore.Qt.Key_Left:

            self.animFlag = False

            self.nextImage()

        if event == QtCore.Qt.Key_Right:

            self.animFlag = True

            self.nextImage()

        if event == 32:

            self._pause = self.playPause()

 

def main(paths):

    if isinstance(paths, list):

        imgLst = utils.imageFilePaths(paths)

    elif isinstance(paths, str):

        imgLst =  utils.imageFilePaths([paths])

    else:

        print " You can either enter a list of paths or single path"

    app = QtGui.QApplication(sys.argv)

    if imgLst:

        window =  SlideShowPics(imgLst)

        window.show()

        window.raise_()

        app.exec_()

    else:

        msgBox = QtGui.QMessageBox()

        msgBox.setText("No Image found in any of the paths below\n\n%s" % paths)

        msgBox.setStandardButtons(msgBox.Cancel | msgBox.Open);

        if msgBox.exec_() == msgBox.Open:

            main(str(QtGui.QFileDialog.getExistingDirectory(None, 

                "Select Directory to SlideShow",

                os.getcwd())))

 

if __name__ == ‘__main__‘:

    curntPaths = os.getcwd()

    if len(sys.argv) > 1:

        curntPaths = sys.argv[1:]

    main(curntPaths)

 

????????????

标签:

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4207365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!