Show running time in the jobs view dialog.

This commit is contained in:
Kovid Goyal 2008-03-05 21:46:01 +00:00
parent b652baf825
commit 442dc19956

View File

@ -12,15 +12,14 @@
## You should have received a copy of the GNU General Public License along ## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from libprs500.gui2 import error_dialog import traceback, logging, collections, time
import traceback, logging, collections
from PyQt4.QtCore import QAbstractTableModel, QMutex, QObject, SIGNAL, Qt, \ from PyQt4.QtCore import QAbstractTableModel, QMutex, QObject, SIGNAL, Qt, \
QVariant, QThread, QSettings QVariant, QThread, QSettings
from PyQt4.QtGui import QIcon, QDialog from PyQt4.QtGui import QIcon, QDialog
from libprs500 import detect_ncpus from libprs500 import detect_ncpus
from libprs500.gui2 import NONE from libprs500.gui2 import NONE, error_dialog
from libprs500.parallel import Server from libprs500.parallel import Server
from libprs500.gui2.dialogs.job_view_ui import Ui_Dialog from libprs500.gui2.dialogs.job_view_ui import Ui_Dialog
@ -51,9 +50,11 @@ class Job(QThread):
self.is_locked = False self.is_locked = False
self.log = self.exception = self.last_traceback = None self.log = self.exception = self.last_traceback = None
self.connect_done_signal() self.connect_done_signal()
self.start_time = None
def start(self): def start(self):
self.start_time = time.time()
QThread.start(self, self._priority) QThread.start(self, self._priority)
def progress_update(self, val): def progress_update(self, val):
@ -181,6 +182,7 @@ class JobManager(QAbstractTableModel):
self.finished_jobs.appendleft(job) self.finished_jobs.appendleft(job)
if job.result != self.process_server.KILL_RESULT: if job.result != self.process_server.KILL_RESULT:
job.notify() job.notify()
job.running_time = time.time() - job.start_time
self.emit(SIGNAL('job_done(int)'), job.id) self.emit(SIGNAL('job_done(int)'), job.id)
refresh = True refresh = True
@ -213,6 +215,8 @@ class JobManager(QAbstractTableModel):
self.reset() self.reset()
if len(self.running_jobs) == 0: if len(self.running_jobs) == 0:
self.emit(SIGNAL('no_more_jobs()')) self.emit(SIGNAL('no_more_jobs()'))
for i in range(len(self.running_jobs)):
self.emit(SIGNAL('dataChanged(QModelIndex, QModelIndex)'), self.index(i, 3), self.index(i, 3))
finally: finally:
self.update_lock.unlock() self.update_lock.unlock()
@ -278,7 +282,7 @@ class JobManager(QAbstractTableModel):
return len(self.running_jobs) + len(self.waiting_jobs) + len(self.finished_jobs) return len(self.running_jobs) + len(self.waiting_jobs) + len(self.finished_jobs)
def columnCount(self, parent): def columnCount(self, parent):
return 3 return 4
def headerData(self, section, orientation, role): def headerData(self, section, orientation, role):
if role != Qt.DisplayRole: if role != Qt.DisplayRole:
@ -287,6 +291,7 @@ class JobManager(QAbstractTableModel):
if section == 0: text = _("Job") if section == 0: text = _("Job")
elif section == 1: text = _("Status") elif section == 1: text = _("Status")
elif section == 2: text = _("Progress") elif section == 2: text = _("Progress")
elif section == 3: text = _('Running time')
return QVariant(text) return QVariant(text)
else: else:
return QVariant(section+1) return QVariant(section+1)
@ -321,6 +326,9 @@ class JobManager(QAbstractTableModel):
if col == 2: if col == 2:
p = str(job.percent_done) + r'%' if job.percent_done > 0 else _('Unavailable') p = str(job.percent_done) + r'%' if job.percent_done > 0 else _('Unavailable')
return QVariant(p) return QVariant(p)
if col == 3:
rtime = job.running_time if hasattr(job, 'running_time') else time.time() - job.start_time
return QVariant('%dm %ds'%(int(rtime)//60, int(rtime)%60))
if role == Qt.DecorationRole and col == 0: if role == Qt.DecorationRole and col == 0:
if status == 1: if status == 1:
return self.wait_icon return self.wait_icon
@ -336,8 +344,7 @@ class JobManager(QAbstractTableModel):
for i in range(len(self.running_jobs)): for i in range(len(self.running_jobs)):
job = self.running_jobs[i] job = self.running_jobs[i]
if job.id == id: if job.id == id:
index = self.index(i, 2) self.emit(SIGNAL('dataChanged(QModelIndex, QModelIndex)'), self.index(i, 2), self.index(i, 3))
self.emit(SIGNAL('dataChanged(QModelIndex, QModelIndex)'), index, index)
break break
def kill_job(self, row, gui_parent): def kill_job(self, row, gui_parent):