Provide better activity stats in the status bar

Partial solution to PICARD-478
This commit is contained in:
Sophist
2013-06-03 20:47:00 +01:00
parent 0482724b5b
commit df40b37b2d
3 changed files with 40 additions and 2 deletions

View File

@@ -82,6 +82,7 @@ from picard.webservice import XmlWebService
class Tagger(QtGui.QApplication):
file_state_changed = QtCore.pyqtSignal(int)
tagger_stats_changed = QtCore.pyqtSignal()
listen_port_changed = QtCore.pyqtSignal(int)
cluster_added = QtCore.pyqtSignal(Cluster)
cluster_removed = QtCore.pyqtSignal(Cluster)
@@ -610,6 +611,19 @@ class Tagger(QtGui.QApplication):
def num_files(self):
return len(self.files)
def num_saves(self):
return len(self.save_queue)
def num_unmatched_files(self):
return len(self.unmatched_files)
def num_unmatched_clusters(self):
return len(self.clusters)
def num_albums(self):
return len(self.albums)
def help():
print """Usage: %s [OPTIONS] [FILE] [FILE] ...

View File

@@ -65,6 +65,7 @@ class MainWindow(QtGui.QMainWindow):
self.selected_objects = []
self.ignore_selection_changes = False
self.setupUi()
self.num_pending_files = 0
def setupUi(self):
self.setWindowTitle(_("MusicBrainz Picard"))
@@ -216,13 +217,25 @@ class MainWindow(QtGui.QMainWindow):
self.statusBar().addPermanentWidget(self.file_counts_label)
self.statusBar().addPermanentWidget(self.listening_label)
self.tagger.file_state_changed.connect(self.update_statusbar_files)
self.tagger.tagger_stats_changed.connect(self.update_statusbar_stats)
self.tagger.listen_port_changed.connect(self.update_statusbar_listen_port)
self.update_statusbar_files(0)
def update_statusbar_files(self, num_pending_files):
"""Updates the status bar information."""
self.file_counts_label.setText(_(" Files: %(files)d, Pending Files: %(pending)d ")
% {"files": self.tagger.num_files(), "pending": num_pending_files})
self.num_pending_files = num_pending_files
self.update_statusbar_stats()
def update_statusbar_stats(self):
"""Updates the status bar information."""
self.file_counts_label.setText(_(" Files: %(files)d, Unmatched: %(unmatch)d, Albums: %(albums)d, Clusters: %(clusters)d, Pending: %(pending)d, Web: %(web)d ")
% {"files": self.tagger.num_files(),
"pending": self.num_pending_files,
"albums": self.tagger.num_albums(),
"unmatch": self.tagger.num_unmatched_files(),
"clusters": self.tagger.num_unmatched_clusters(),
"web": self.tagger.xmlws.num_web_tasks(),
})
def update_statusbar_listen_port(self, listen_port):
self.listening_label.setVisible(True)

View File

@@ -287,6 +287,7 @@ class XmlWebService(QtCore.QObject):
log.debug("Last request to %s was %d ms ago, starting another one", key, last_ms)
d = request_delay
queue.popleft()()
self.tagger.tagger_stats_changed.emit()
else:
d = request_delay - last_ms
log.debug("Waiting %d ms before starting another request to %s", d, key)
@@ -310,6 +311,7 @@ class XmlWebService(QtCore.QObject):
queues[key].append(func)
if not self._timer.isActive():
self._timer.start(0)
self.tagger.tagger_stats_changed.emit()
return (key, func, priority)
def remove_task(self, task):
@@ -322,6 +324,15 @@ class XmlWebService(QtCore.QObject):
queue.remove(func)
except:
pass
self.tagger.tagger_stats_changed.emit()
def num_web_tasks(self):
count = 0
for key in self._high_priority_queues:
count += len(self._high_priority_queues[key])
for key in self._low_priority_queues:
count += len(self._low_priority_queues[key])
return count
def _get_by_id(self, entitytype, entityid, handler, inc=[], params=[], priority=False, important=False, mblogin=False):
host = config.setting["server_host"]