def _updateExportButtons(self, *args): """Called when at least one dataset became 'unready', so we have to disable the export button.""" all_ready = True # Enable/disable the appropriate export buttons in the table. # Use ThunkEvents to ensure that this happens in the Gui thread. for row, slot in enumerate( self.topLevelOperator.ImageToExport ): all_ready &= slot.ready() export_button = self.batchOutputTableWidget.cellWidget( row, Column.Action ) if export_button is not None: executable_event = ThunkEvent( partial(export_button.setEnabled, slot.ready()) ) QApplication.instance().postEvent( self, executable_event ) # Disable the "Export all" button unless all slots are ready. executable_event = ThunkEvent( partial(self.drawer.exportAllButton.setEnabled, all_ready) ) QApplication.instance().postEvent( self, executable_event )
def exportSlots(self, laneViewList): try: # Set the busy flag so the workflow knows not to allow # upstream changes or shell changes while we're exporting self.parentApplet.busy = True self.parentApplet.appletStateUpdateRequested.emit() # Disable our own gui QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self.drawer, False))) QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self, False))) # Start with 1% so the progress bar shows up self.progressSignal.emit(0) self.progressSignal.emit(1) def signalFileProgress(slotIndex, percent): self.progressSignal.emit( (100 * slotIndex + percent) / len(laneViewList)) # Client hook self.parentApplet.prepare_for_entire_export() for i, opLaneView in enumerate(laneViewList): lane_index = self.topLevelOperator.innerOperators.index( opLaneView) logger.debug("Exporting result {}".format(i)) # If the operator provides a progress signal, use it. slotProgressSignal = opLaneView.progressSignal slotProgressSignal.subscribe(partial(signalFileProgress, i)) try: # Client hook self.parentApplet.prepare_lane_for_export(lane_index) # Export the image opLaneView.run_export() # Client hook if self.parentApplet.postprocessCanCheckForExistingFiles(): exportSuccessful = self.parentApplet.post_process_lane_export( lane_index, checkOverwriteFiles=True) if not exportSuccessful: userSelection = [None] self.showOverwriteQuestion(userSelection) if userSelection[0]: self.parentApplet.post_process_lane_export( lane_index, checkOverwriteFiles=False) else: self.parentApplet.post_process_lane_export(lane_index) except Exception as ex: if opLaneView.ExportPath.ready(): msg = "Failed to generate export file: \n" msg += opLaneView.ExportPath.value msg += "\n{}".format(ex) else: msg = "Failed to generate export file." msg += "\n{}".format(ex) log_exception(logger, msg) self.showExportError(msg) # We're finished with this file. self.progressSignal.emit(100 * (i + 1) / float(len(laneViewList))) # Client hook self.parentApplet.post_process_entire_export() # Ensure the shell knows we're really done. self.progressSignal.emit(100) except: # Cancel our progress. self.progressSignal.emit(0, True) raise finally: # We're not busy any more. Tell the workflow. self.parentApplet.busy = False self.parentApplet.appletStateUpdateRequested.emit() # Re-enable our own gui QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self.drawer, True))) QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self, True)))
def exportSlots(self, laneViewList): try: # Set the busy flag so the workflow knows not to allow # upstream changes or shell changes while we're exporting self.parentApplet.busy = True self.parentApplet.appletStateUpdateRequested.emit() # Disable our own gui QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self.drawer, False))) QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self, False))) # Start with 1% so the progress bar shows up self.progressSignal.emit(0) self.progressSignal.emit(1) def signalFileProgress(slotIndex, percent): self.progressSignal.emit( (100 * slotIndex + percent) / len(laneViewList)) for i, opLaneView in enumerate(laneViewList): logger.debug("Exporting result {}".format(i)) # If the operator provides a progress signal, use it. slotProgressSignal = opLaneView.progressSignal slotProgressSignal.subscribe(partial(signalFileProgress, i)) try: opLaneView.run_export() except Exception as ex: if opLaneView.ExportPath.ready(): msg = "Failed to generate export file: \n" msg += opLaneView.ExportPath.value msg += "\n{}".format(ex) else: msg = "Failed to generate export file." msg += "\n{}".format(ex) log_exception(logger, msg) self.showExportError(msg) # We're finished with this file. self.progressSignal.emit(100 * (i + 1) / float(len(laneViewList))) # Ensure the shell knows we're really done. self.progressSignal.emit(100) except: # Cancel our progress. self.progressSignal.emit(0, True) raise finally: # We're not busy any more. Tell the workflow. self.parentApplet.busy = False self.parentApplet.appletStateUpdateRequested.emit() # Re-enable our own gui QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self.drawer, True))) QApplication.instance().postEvent( self, ThunkEvent(partial(self.setEnabledIfAlive, self, True)))