11
11
class BookInfoDisplay(QWidget):
12
12
class BookCoverDisplay(QLabel):
17
17
def __init__(self, coverpath=':/images/book.svg'):
18
18
QLabel.__init__(self)
19
19
self.default_pixmap = QPixmap(coverpath).scaled(self.__class__.WIDTH,
23
23
self.setScaledContents(True)
24
24
self.setMaximumHeight(self.HEIGHT)
25
25
self.setPixmap(self.default_pixmap)
28
28
def setPixmap(self, pixmap):
29
29
width, height = fit_image(pixmap.width(), pixmap.height(),
30
30
self.WIDTH, self.HEIGHT)[1:]
31
31
self.setMaximumHeight(height)
32
32
self.setMaximumWidth(width)
33
33
QLabel.setPixmap(self, pixmap)
36
36
aspect_ratio = pixmap.width()/float(pixmap.height())
37
37
except ZeroDivisionError:
39
39
self.setMaximumWidth(int(aspect_ratio*self.HEIGHT))
41
41
def sizeHint(self):
42
42
return QSize(self.__class__.WIDTH, self.__class__.HEIGHT)
45
45
class BookDataDisplay(QLabel):
46
46
def __init__(self):
47
47
QLabel.__init__(self)
49
49
self.setWordWrap(True)
50
50
self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
52
52
def mouseReleaseEvent(self, ev):
53
53
self.emit(SIGNAL('mr(int)'), 1)
55
55
WEIGHTS = collections.defaultdict(lambda : 100)
56
56
WEIGHTS[_('Path')] = 0
57
57
WEIGHTS[_('Formats')] = 1
58
58
WEIGHTS[_('Comments')] = 2
59
59
WEIGHTS[_('Series')] = 3
60
60
WEIGHTS[_('Tags')] = 4
62
62
def __init__(self, clear_message):
63
63
QWidget.__init__(self)
64
64
self.setCursor(Qt.PointingHandCursor)
75
75
self.setVisible(False)
76
76
self._layout.setAlignment(self.cover_display, Qt.AlignTop|Qt.AlignLeft)
78
78
def mouseReleaseEvent(self, ev):
79
79
self.emit(SIGNAL('show_book_info()'))
81
81
def show_data(self, data):
82
82
if data.has_key('cover'):
83
83
self.cover_display.setPixmap(QPixmap.fromImage(data.pop('cover')))
85
85
self.cover_display.setPixmap(self.cover_display.default_pixmap)
88
88
self.book_data.setText('')
89
89
self.data = data.copy()
97
97
txt = txt.decode(preferred_encoding, 'replace')
98
98
rows += u'<tr><td><b>%s:</b></td><td>%s</td></tr>'%(key, txt)
99
99
self.book_data.setText(u'<table>'+rows+u'</table>')
101
101
self.clear_message()
102
102
self.book_data.updateGeometry()
103
103
self.updateGeometry()
113
113
self.movie = movie
114
114
self.layout().addWidget(self.movie_widget)
115
115
self.jobs = QLabel('<b>'+_('Jobs:')+' 0')
116
self.jobs.setAlignment(Qt.AlignHCenter|Qt.AlignBottom)
116
self.jobs.setAlignment(Qt.AlignHCenter|Qt.AlignBottom)
117
117
self.layout().addWidget(self.jobs)
118
118
self.layout().setAlignment(self.jobs, Qt.AlignHCenter)
119
119
self.jobs.setMargin(0)
126
126
movie.setPaused(True)
127
127
self.jobs_dialog.jobs_view.restore_column_widths()
130
130
def mouseReleaseEvent(self, event):
131
131
if self.jobs_dialog.isVisible():
132
132
self.jobs_dialog.jobs_view.write_settings()
137
137
self.jobs_dialog.jobs_view.restore_column_widths()
139
139
class CoverFlowButton(QToolButton):
141
141
def __init__(self, parent=None):
142
142
QToolButton.__init__(self, parent)
143
143
self.setIconSize(QSize(80, 80))
149
149
self.connect(self, SIGNAL('toggled(bool)'), self.adjust_tooltip)
150
150
self.adjust_tooltip(False)
151
151
self.setCursor(Qt.PointingHandCursor)
153
153
def adjust_tooltip(self, on):
154
154
tt = _('Click to turn off Cover Browsing') if on else _('Click to browse books by their covers')
155
155
self.setToolTip(tt)
157
157
def disable(self, reason):
158
158
self.setDisabled(True)
159
159
self.setToolTip(_('<p>Browsing books by their covers is disabled.<br>Import of pictureflow module failed:<br>')+reason)
161
161
class TagViewButton(QToolButton):
163
163
def __init__(self, parent=None):
164
164
QToolButton.__init__(self, parent)
165
165
self.setIconSize(QSize(80, 80))
192
192
self.addWidget(self.scroll_area, 100)
193
193
self.setMinimumHeight(120)
194
194
self.setMaximumHeight(120)
197
197
def reset_info(self):
198
198
self.book_info.show_data({})
200
200
def showMessage(self, msg, timeout=0):
201
201
ret = QStatusBar.showMessage(self, msg, timeout)
202
202
if self.systray is not None and not config['disable_tray_notification']:
207
207
msg = msg.encode('utf-8')
208
208
self.systray.showMessage('calibre', msg, self.systray.Information, 10000)
212
212
src = qstring_to_unicode(self.movie_button.jobs.text())
213
213
return int(re.search(r'\d+', src).group())
215
215
def show_book_info(self):
216
216
self.emit(SIGNAL('show_book_info()'))
218
218
def job_added(self, nnum):
219
219
jobs = self.movie_button.jobs
220
220
src = qstring_to_unicode(jobs.text())
221
221
num = self.jobs()
223
222
text = src.replace(str(num), str(nnum))
224
223
jobs.setText(text)
225
224
if self.movie_button.movie.state() == QMovie.Paused:
226
225
self.movie_button.movie.setPaused(False)
228
def job_done(self, running):
227
def job_done(self, nnum):
229
228
jobs = self.movie_button.jobs
230
229
src = qstring_to_unicode(jobs.text())
231
230
num = self.jobs()
232
text = src.replace(str(num), str(running))
231
text = src.replace(str(num), str(nnum))
233
232
jobs.setText(text)
235
234
self.no_more_jobs()
237
236
def no_more_jobs(self):
238
237
if self.movie_button.movie.state() == QMovie.Running:
239
238
self.movie_button.movie.jumpToFrame(0)
240
239
self.movie_button.movie.setPaused(True)
241
240
QCoreApplication.instance().alert(self, 5000)
243
242
if __name__ == '__main__':
244
243
# Used to create the animated status icon
245
244
from PyQt4.Qt import QApplication, QPainter, QSvgRenderer, QColor