~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/gui2/status.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
class BookInfoDisplay(QWidget):
12
12
    class BookCoverDisplay(QLabel):
13
 
        
 
13
 
14
14
        WIDTH = 81
15
15
        HEIGHT = 108
16
 
        
 
16
 
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)
26
 
            
27
 
        
 
26
 
 
27
 
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)
34
 
             
 
34
 
35
35
            try:
36
36
                aspect_ratio = pixmap.width()/float(pixmap.height())
37
37
            except ZeroDivisionError:
38
38
                aspect_ratio = 1
39
39
            self.setMaximumWidth(int(aspect_ratio*self.HEIGHT))
40
 
        
 
40
 
41
41
        def sizeHint(self):
42
42
            return QSize(self.__class__.WIDTH, self.__class__.HEIGHT)
43
 
        
44
 
    
 
43
 
 
44
 
45
45
    class BookDataDisplay(QLabel):
46
46
        def __init__(self):
47
47
            QLabel.__init__(self)
48
48
            self.setText('')
49
49
            self.setWordWrap(True)
50
50
            self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
51
 
            
 
51
 
52
52
        def mouseReleaseEvent(self, ev):
53
53
            self.emit(SIGNAL('mr(int)'), 1)
54
 
            
 
54
 
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
61
 
    
 
61
 
62
62
    def __init__(self, clear_message):
63
63
        QWidget.__init__(self)
64
64
        self.setCursor(Qt.PointingHandCursor)
74
74
        self.data = {}
75
75
        self.setVisible(False)
76
76
        self._layout.setAlignment(self.cover_display, Qt.AlignTop|Qt.AlignLeft)
77
 
        
 
77
 
78
78
    def mouseReleaseEvent(self, ev):
79
79
        self.emit(SIGNAL('show_book_info()'))
80
 
    
 
80
 
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')))
84
84
        else:
85
85
            self.cover_display.setPixmap(self.cover_display.default_pixmap)
86
 
            
 
86
 
87
87
        rows = u''
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>')
100
 
        
 
100
 
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)
125
125
        movie.start()
126
126
        movie.setPaused(True)
127
127
        self.jobs_dialog.jobs_view.restore_column_widths()
128
 
        
129
 
        
 
128
 
 
129
 
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()
138
138
 
139
139
class CoverFlowButton(QToolButton):
140
 
    
 
140
 
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)
152
 
        
 
152
 
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)
156
 
        
 
156
 
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)
160
 
        
 
160
 
161
161
class TagViewButton(QToolButton):
162
 
    
 
162
 
163
163
    def __init__(self, parent=None):
164
164
        QToolButton.__init__(self, parent)
165
165
        self.setIconSize(QSize(80, 80))
170
170
        self.setCheckable(True)
171
171
        self.setChecked(False)
172
172
        self.setAutoRaise(True)
173
 
    
 
173
 
174
174
 
175
175
class StatusBar(QStatusBar):
176
 
    
 
176
 
177
177
    def __init__(self, jobs_dialog, systray=None):
178
178
        QStatusBar.__init__(self)
179
179
        self.systray = systray
192
192
        self.addWidget(self.scroll_area, 100)
193
193
        self.setMinimumHeight(120)
194
194
        self.setMaximumHeight(120)
195
 
        
196
 
    
 
195
 
 
196
 
197
197
    def reset_info(self):
198
198
        self.book_info.show_data({})
199
 
        
 
199
 
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)
209
209
        return ret
210
 
    
 
210
 
211
211
    def jobs(self):
212
212
        src = qstring_to_unicode(self.movie_button.jobs.text())
213
213
        return int(re.search(r'\d+', src).group())
214
 
        
 
214
 
215
215
    def show_book_info(self):
216
216
        self.emit(SIGNAL('show_book_info()'))
217
 
    
 
217
 
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()
222
 
        nnum = num + 1
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)
227
 
            
228
 
    def job_done(self, running):
 
226
 
 
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)
234
 
        if running == 0:
 
233
        if nnum == 0:
235
234
            self.no_more_jobs()
236
 
            
 
235
 
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)
242
 
        
 
241
 
243
242
if __name__ == '__main__':
244
243
    # Used to create the animated status icon
245
244
    from PyQt4.Qt import QApplication, QPainter, QSvgRenderer, QColor
280
279
                os.remove(file)
281
280
    import sys
282
281
    create_mng(sys.argv[1])
283
 
        
 
282