def __updateBackgroundPixmap(self, colors): """Updates the background image buffer based on the given colors @type colors: list<QBrush> @param colors: List of job background colors""" # Could draw it the max size and allow the resize on drawPixmap # that way the same buffer is always used assert threading.currentThread().getName() == "MainThread" buffer = QtGui.QPixmap(self.contentsRect().size()) buffer.fill(self.__baseColor) if colors: painter = QtGui.QPainter() painter.begin(buffer) try: rect = buffer.rect() # Number of jobs amount = len(colors) # Number of pixels per job ratio = float(rect.height())/amount for index, color in enumerate(colors): if color: painter.fillRect(rect.adjusted(0, ratio * index, 0, -(ratio * (amount - index - 1))), color) finally: painter.end() del painter self.__background = buffer
def redirect(self): ''' Redirect the selected procs to the target job, after running a few checks to verify it's safe to do that. @postcondition: The selected procs are redirected to the target job ''' # Get selected items items = [ self.__model.item(row) for row in range(0, self.__model.rowCount()) ] selected_items = [ item for item in items if item.checkState() == QtCore.Qt.Checked ] if not selected_items: # Nothing selected, exit self.__warn('You have not selected anything to redirect.') return # Get the Target Job job_name = self.__controls.getJob() if not job_name: # No target job, exit self.__warn('You must have a job name selected.') return job = None try: job = opencue.api.findJob(job_name) except opencue.EntityNotFoundException: # Target job finished, exit self.__warn_and_stop('The job you\'re trying to redirect to ' 'appears to be no longer in the cue!') return # Gather Selected Procs procs_by_alloc = self.__get_selected_procs_by_alloc(selected_items) show_name = job.show() for alloc, procs in procs_by_alloc.items(): if not self.__is_cross_show_safe(procs, show_name): # Cross-show return if not self.__is_burst_safe(alloc, procs, show_name): # At burst return # Redirect errors = [] for item in selected_items: entry = self.__hosts.get(str(item.text())) procs = entry["procs"] try: host = entry["host"] host.redirectToJob(procs, job) except Exception, e: errors.append(str(e)) item.setIcon(QtGui.QIcon(QtGui.QPixmap(":retry.png"))) item.setEnabled(False)