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

Source: Internet
Author: User

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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.