Skip to content

Instantly share code, notes, and snippets.

@sanfx
Created November 17, 2013 10:45
Show Gist options
  • Select an option

  • Save sanfx/7511832 to your computer and use it in GitHub Desktop.

Select an option

Save sanfx/7511832 to your computer and use it in GitHub Desktop.
PyQt4 based slideShow , currently in evolving stage.
class SlideShowPics(QtGui.QWidget):
"""docstring for SlideShowPics"""
def __init__(self, path):
super(SlideShowPics, self).__init__()
QtGui.QWidget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
self._path = path
self.setStyleSheet("QWidget{background-color: #000000;}")
self.animFlag = True
self.pause = False
self.buildUi()
self.showFullScreen()
self.count = 0
self.nextImage()
self.updateTimer = QtCore.QTimer()
self.connect(self.updateTimer, QtCore.SIGNAL("timeout()"), self.nextImage)
self.playPause()
def allImages(self):
return tuple(os.path.join(self._path,each) for each in os.listdir(self._path)
if os.path.isfile(os.path.join(self._path,each)) and each.endswith('png') or each.endswith('jpg'))
def nextImage(self):
if self.allImages():
if self.count != len(self.allImages()):
image = QtGui.QImage(self.allImages()[self.count])
pp = QtGui.QPixmap.fromImage(image)
self.label.setPixmap(pp.scaled(self.label.size(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))
else:
self.count = 0
if self.animFlag:
self.count += 1
else:
self.count -= 1
def keyPressEvent(self, keyevent):
""" Capture key to execute and exit
on Enter and Escape respectively.
"""
if keyevent.key() == QtCore.Qt.Key_Escape:
self.close()
if keyevent.key() == QtCore.Qt.Key_Left:
self.animFlag = False
self.nextImage()
if keyevent.key() == QtCore.Qt.Key_Right:
self.animFlag = True
self.nextImage()
if keyevent.key() == 32:
self.pause = self.playPause()
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 buildUi(self):
filename = self._path
self.layout = QtGui.QHBoxLayout()
self.label = QtGui.QLabel()
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.layout.addWidget(self.label)
self.setLayout(self.layout)
def main():
curntPath = os.getcwd()
if any(each.endswith('png') or each.endswith('jpg') for each in os.listdir(curntPath)):
app = QtGui.QApplication(sys.argv)
window = SlideShowPics(curntPath)
window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
window.activateWindow()
window.show()
app.exec_()
else:
print "No Image found in %s" % os.getcwd()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment