diff --git a/cuegui/cuegui/JobMonitorTree.py b/cuegui/cuegui/JobMonitorTree.py index 8647d9df9..891540f42 100644 --- a/cuegui/cuegui/JobMonitorTree.py +++ b/cuegui/cuegui/JobMonitorTree.py @@ -66,6 +66,21 @@ def displayState(job): return "Dependency" return "In Progress" +def sortableKey(key, datetime_key): + """ + Returns a sortable key that sets apart similar keys using time_key + + @type key: string or int + @param key: A key used for sorting + @type datetime_key: int + @param datetime_key: Date time represented as an integer + @rtype: string or float + @return: datetime_key appended to key if key is a string, + the 0.datetime_key summed to key if key is an int + """ + if isinstance(key, int) and isinstance(datetime_key, int): + return float(str(key)+"."+str(datetime_key)) + return str(key) + str(datetime_key) class JobMonitorTree(cuegui.AbstractTreeWidget.AbstractTreeWidget): """Tree widget to display a list of monitored jobs.""" @@ -80,6 +95,7 @@ def __init__(self, parent): self.startColumnsForType(cuegui.Constants.TYPE_JOB) self.addColumn("Job", 470, id=1, data=lambda job: job.data.name, + sort=lambda job: sortableKey(job.data.name, job.data.start_time), tip="The name of the job: show-shot-user_uniqueName") self.addColumn("_Comment", 20, id=2, sort=lambda job: job.data.has_comment, @@ -93,6 +109,7 @@ def __init__(self, parent): # pylint: disable=unnecessary-lambda self.addColumn("State", 80, id=4, data=lambda job: displayState(job), + sort=lambda job: sortableKey(displayState(job), job.data.start_time), tip="The state of each job.\n" "In Progress \t The job is on the queue\n" "Failing \t The job has dead frames\n" @@ -101,28 +118,34 @@ def __init__(self, parent): self.addColumn("Done/Total", 90, id=5, data=lambda job: "%d of %d" % (job.data.job_stats.succeeded_frames, job.data.job_stats.total_frames), - sort=lambda job: job.data.job_stats.succeeded_frames, + sort=lambda job: sortableKey(job.data.job_stats.succeeded_frames, + job.data.start_time), tip="The number of succeeded frames vs the total number\n" "of frames in each job.") self.addColumn("Running", 60, id=6, data=lambda job: job.data.job_stats.running_frames, - sort=lambda job: job.data.job_stats.running_frames, + sort=lambda job: sortableKey(job.data.job_stats.running_frames, + job.data.start_time), tip="The number of running frames in each job,") self.addColumn("Dead", 50, id=7, data=lambda job: job.data.job_stats.dead_frames, - sort=lambda job: job.data.job_stats.dead_frames, + sort=lambda job: sortableKey(job.data.job_stats.dead_frames, + job.data.start_time), tip="Total number of dead frames in each job.") self.addColumn("Eaten", 50, id=8, data=lambda job: job.data.job_stats.eaten_frames, - sort=lambda job: job.data.job_stats.eaten_frames, + sort=lambda job: sortableKey(job.data.job_stats.eaten_frames, + job.data.start_time), tip="Total number of eaten frames in each job.") self.addColumn("Wait", 60, id=9, data=lambda job: job.data.job_stats.waiting_frames, - sort=lambda job: job.data.job_stats.waiting_frames, + sort=lambda job: sortableKey(job.data.job_stats.waiting_frames, + job.data.start_time), tip="The number of waiting frames in each job,") self.addColumn("MaxRss", 55, id=10, data=lambda job: cuegui.Utils.memoryToString(job.data.job_stats.max_rss), - sort=lambda job: job.data.job_stats.max_rss, + sort=lambda job: sortableKey(job.data.job_stats.max_rss, + job.data.start_time), tip="The maximum memory used any single frame in each job.") self.addColumn("Age", 50, id=11, data=lambda job: (cuegui.Utils.secondsToHHHMM((job.data.stop_time or