mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05:00 
			
		
		
		
	Implement #3834 (Feature Request - Active Job Count in Tray Tooltip)
This commit is contained in:
		
							parent
							
								
									d3b61d9094
								
							
						
					
					
						commit
						b5fcc2466b
					
				@ -11,7 +11,7 @@ from Queue import Empty, Queue
 | 
			
		||||
 | 
			
		||||
from PyQt4.Qt import QAbstractTableModel, QVariant, QModelIndex, Qt, \
 | 
			
		||||
    QTimer, SIGNAL, QIcon, QDialog, QAbstractItemDelegate, QApplication, \
 | 
			
		||||
    QSize, QStyleOptionProgressBarV2, QString, QStyle
 | 
			
		||||
    QSize, QStyleOptionProgressBarV2, QString, QStyle, QToolTip
 | 
			
		||||
 | 
			
		||||
from calibre.utils.ipc.server import Server
 | 
			
		||||
from calibre.utils.ipc.job import ParallelJob
 | 
			
		||||
@ -57,6 +57,28 @@ class JobManager(QAbstractTableModel):
 | 
			
		||||
        else:
 | 
			
		||||
            return QVariant(section+1)
 | 
			
		||||
 | 
			
		||||
    def show_tooltip(self, arg):
 | 
			
		||||
        widget, pos = arg
 | 
			
		||||
        QToolTip.showText(pos, self.get_tooltip())
 | 
			
		||||
 | 
			
		||||
    def get_tooltip(self):
 | 
			
		||||
        running_jobs = [j for j in self.jobs if j.run_state == j.RUNNING]
 | 
			
		||||
        waiting_jobs = [j for j in self.jobs if j.run_state == j.WAITING]
 | 
			
		||||
        lines = [_('There are %d running jobs:')%len(running_jobs)]
 | 
			
		||||
        for job in running_jobs:
 | 
			
		||||
            desc = job.description
 | 
			
		||||
            if not desc:
 | 
			
		||||
                desc = _('Unknown job')
 | 
			
		||||
            p = 100. if job.is_finished else job.percent
 | 
			
		||||
            lines.append('%s:  %.0f%% done'%(desc, p))
 | 
			
		||||
        lines.extend(['', _('There are %d waiting jobs:')%len(waiting_jobs)])
 | 
			
		||||
        for job in waiting_jobs:
 | 
			
		||||
            desc = job.description
 | 
			
		||||
            if not desc:
 | 
			
		||||
                desc = _('Unknown job')
 | 
			
		||||
            lines.append(desc)
 | 
			
		||||
        return '\n'.join(['calibre', '']+ lines)
 | 
			
		||||
 | 
			
		||||
    def data(self, index, role):
 | 
			
		||||
        try:
 | 
			
		||||
            if role not in (Qt.DisplayRole, Qt.DecorationRole):
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ from PyQt4.Qt import Qt, SIGNAL, QObject, QCoreApplication, QUrl, QTimer, \
 | 
			
		||||
                     QModelIndex, QPixmap, QColor, QPainter, QMenu, QIcon, \
 | 
			
		||||
                     QToolButton, QDialog, QDesktopServices, QFileDialog, \
 | 
			
		||||
                     QSystemTrayIcon, QApplication, QKeySequence, QAction, \
 | 
			
		||||
                     QMessageBox, QStackedLayout
 | 
			
		||||
                     QMessageBox, QStackedLayout, QHelpEvent
 | 
			
		||||
from PyQt4.QtSvg import QSvgRenderer
 | 
			
		||||
 | 
			
		||||
from calibre import  prints, patheq
 | 
			
		||||
@ -89,6 +89,18 @@ class Listener(Thread):
 | 
			
		||||
        except:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
class SystemTrayIcon(QSystemTrayIcon):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, icon, parent):
 | 
			
		||||
        QSystemTrayIcon.__init__(self, icon, parent)
 | 
			
		||||
 | 
			
		||||
    def event(self, ev):
 | 
			
		||||
        if ev.type() == ev.ToolTip:
 | 
			
		||||
            evh = QHelpEvent(ev)
 | 
			
		||||
            self.emit(SIGNAL('tooltip_requested(PyQt_PyObject)'),
 | 
			
		||||
                    (self, evh.globalPos()))
 | 
			
		||||
            return True
 | 
			
		||||
        return QSystemTrayIcon.event(self, ev)
 | 
			
		||||
 | 
			
		||||
class Main(MainWindow, Ui_MainWindow, DeviceGUI):
 | 
			
		||||
    'The main GUI'
 | 
			
		||||
@ -144,8 +156,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
 | 
			
		||||
        self.device_connected = False
 | 
			
		||||
        self.viewers = collections.deque()
 | 
			
		||||
        self.content_server = None
 | 
			
		||||
        self.system_tray_icon = QSystemTrayIcon(QIcon(I('library.png')), self)
 | 
			
		||||
        self.system_tray_icon = SystemTrayIcon(QIcon(I('library.png')), self)
 | 
			
		||||
        self.system_tray_icon.setToolTip('calibre')
 | 
			
		||||
        self.connect(self.system_tray_icon,
 | 
			
		||||
                SIGNAL('tooltip_requested(PyQt_PyObject)'),
 | 
			
		||||
                self.job_manager.show_tooltip)
 | 
			
		||||
        if not config['systray_icon']:
 | 
			
		||||
            self.system_tray_icon.hide()
 | 
			
		||||
        else:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user