-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
137 lines (107 loc) · 3.35 KB
/
app.py
File metadata and controls
137 lines (107 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import sys
import os
import utils
import time
import random
import get_photos
from PyQt4 import QtGui, QtCore
class SlideShowPics(QtGui.QMainWindow):
""" SlideShowPics class defines the methods for UI and
working logic
"""
def __init__(self, root_path, parent=None):
super(SlideShowPics, self).__init__(parent)
# self._path = path
self.move_timer_time = 150
self.next_timer = 10000
self.move_x = True
self.move_y = True
self.photos = get_photos.get_photos(root_path)
self._pause = False
self._count = 0
self.animFlag = True
self.updateTimer = QtCore.QTimer()
self.connect(self.updateTimer, QtCore.SIGNAL("timeout()"), self.nextImage)
self.moveTimer = QtCore.QTimer()
self.connect(self.moveTimer, QtCore.SIGNAL("timeout()"), self.move_label)
self.prepairWindow()
self.nextImage()
def prepairWindow(self):
# Centre UI
screen = QtGui.QDesktopWidget().screenGeometry(self)
#print 'screen: %s' % screen
size = self.geometry()
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
self.setStyleSheet("QWidget{background-color: #000000;}")
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
"""
image_path = self.photos.get_next()
print 'image_path: %s' % image_path
self.showImageByPath(image_path)
if self.animFlag:
self._count += 1
else:
self._count -= 1
self.moveTimer.start(self.move_timer_time)
def move_label(self):
x = 1 if self.move_x else -1
y = 1 if self.move_y else -1
self.label.move(self.label.x() + x, self.label.y() + y)
QtGui.QApplication.processEvents()
def showImageByPath(self, path):
if path:
self.image = QtGui.QImage(path)
self.pp_orignal = QtGui.QPixmap.fromImage(self.image)
w_p_10 = self.label.size().width() + (self.label.size().width() * .1)
h_p_10 = self.label.size().height() + (self.label.size().height() * .1)
print w_p_10, h_p_10
self.pp = self.pp_orignal.scaled(w_p_10, h_p_10, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
self.label.setPixmap(self.pp)
QtGui.QApplication.processEvents()
self.move_x = bool(random.getrandbits(1))
self.move_y = bool(random.getrandbits(1))
print 'self.label.size(): %s' % self.label.size()
def playPause(self):
if not self._pause:
self._pause = True
self.updateTimer.start(self.next_timer)
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):
app = QtGui.QApplication(sys.argv)
window = SlideShowPics(paths)
window.show()
window.raise_()
app.exec_()
if __name__ == '__main__':
#curntPaths = os.getcwd()
#if len(sys.argv) > 1:
#curntPaths = sys.argv[1:]
root_path = '/media/blake/BLAKE KEYS/Photos'
main(root_path)