3
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
4
__docformat__ = 'restructuredtext en'
7
Module to implement the Cover Flow feature
12
from PyQt4.QtGui import QImage, QSizePolicy
13
from PyQt4.QtCore import Qt, QSize, SIGNAL, QObject
15
from calibre import plugins
16
from calibre.gui2 import config
17
pictureflow, pictureflowerror = plugins['pictureflow']
19
if pictureflow is not None:
20
class EmptyImageList(pictureflow.FlowImages):
22
pictureflow.FlowImages.__init__(self)
24
class FileSystemImages(pictureflow.FlowImages):
26
def __init__(self, dirpath):
27
pictureflow.FlowImages.__init__(self)
30
for f in os.listdir(dirpath):
31
f = os.path.join(dirpath, f)
34
self.images.append(img)
35
self.captions.append(os.path.basename(f))
38
return len(self.images)
40
def image(self, index):
41
return self.images[index]
43
def caption(self, index):
44
return self.captions[index]
46
def currentChanged(self, index):
47
print 'current changed:', index
49
class DatabaseImages(pictureflow.FlowImages):
51
def __init__(self, model, buffer=20):
52
pictureflow.FlowImages.__init__(self)
54
QObject.connect(self.model, SIGNAL('modelReset()'), self.reset)
57
return self.model.count()
59
def caption(self, index):
60
return self.model.title(index)
63
self.emit(SIGNAL('dataChanged()'))
65
def image(self, index):
66
return self.model.cover(index)
70
class CoverFlow(pictureflow.PictureFlow):
72
def __init__(self, height=300, parent=None, text_height=25):
73
pictureflow.PictureFlow.__init__(self, parent,
74
config['cover_flow_queue_length']+1)
75
self.setSlideSize(QSize(int(2/3. * height), height))
76
self.setMinimumSize(QSize(int(2.35*0.67*height), (5/3.)*height+text_height))
77
self.setFocusPolicy(Qt.WheelFocus)
78
self.setSizePolicy(QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum))
80
def wheelEvent(self, ev):
91
FileSystemImages = None
93
def main(args=sys.argv):
96
if __name__ == '__main__':
97
from PyQt4.QtGui import QApplication, QMainWindow
98
app = QApplication([])
101
cf.resize(cf.minimumSize())
102
w.resize(cf.minimumSize()+QSize(30, 20))
104
model = FileSystemImages(sys.argv[1])
106
cf.connect(cf, SIGNAL('currentChanged(int)'), model.currentChanged)
107
w.setCentralWidget(cf)
110
cf.setFocus(Qt.OtherFocusReason)
111
sys.exit(app.exec_())