def make_progress(msg,total_steps): progress = QProgressDialog(msg, None, 0, total_steps, None) progress.setWindowTitle("Horse") progress.setMinimumDuration(0) progress.setWindowModality(Qt.WindowModal) progress.setValue( progress.value() + 1) progress.show() return progress
def buildImageDataList(self): """ Build the image list with meta data to be constructed into pdf """ markerName = "" shotStatus = "" markerIndex = 1 self.fileList = [] self.tempFileDir = tempfile.gettempdir() numFiles = len(self.shotCutList) progress = QProgressDialog("Generating PDF...", "Cancel Export", 0, numFiles, hiero.ui.mainWindow()) progress.setWindowModality(Qt.WindowModal) tc = Timecode() timecodeStart = self.sequence.timecodeStart() timecodeDisplayMode = Timecode().kDisplayTimecode fps = self.sequence.framerate() count = 1 for shot in self.shotCutList: thumbPath = os.path.join(self.tempFileDir, "%s_%s.jpg" % (shot.name(), self.currentTimeString())) # Try and get a thumbnail, assuming the media is present etc... try: thumb = shot.thumbnail(shot.sourceIn()).save(thumbPath) except: shutil.copy(self.offlineLogoPath, thumbPath) if not os.path.isfile(thumbPath) or progress.wasCanceled(): self.cleanUpTempFiles() progress.cancel() break # This file list gets cleaned up after the PDF save finishes self.fileList += [thumbPath] dataDict = { "show": self.project, "sequence": self.sequence, "editVersion": "*Version*", "setup": "*setup*", "timeString": tc.timeToString(shot.timelineIn() + timecodeStart, fps, timecodeDisplayMode) + ", %if" % shot.duration(), "name": self.validString(shot.name()), "version": "*version*", "path": thumbPath, "track": self.validString(shot.parentTrack().name()), "shot": self.validString(shot.source().name()), "shotLabel": self.validString(shot.name()), "shotStatus": "*ShotStatus*", } self.imageDataList.append(dataDict) progress.setValue(count) count += 1
def buildImageDataList(self): """ Build the image list with meta data to be constructed into pdf """ markerName = "" shotStatus = "" markerIndex = 1 self.fileList = [] self.tempFileDir = tempfile.gettempdir() numFiles = len(self.shotCutList) progress = QProgressDialog("Generating PDF...", "Cancel Export", 0, numFiles, hiero.ui.mainWindow()) progress.setWindowModality(Qt.WindowModal) tc = Timecode() timecodeStart = self.sequence.timecodeStart() timecodeDisplayMode = Timecode().kDisplayTimecode fps = self.sequence.framerate() count = 1 for shot in self.shotCutList: thumbPath = os.path.join(self.tempFileDir,"%s_%s.jpg" % (shot.name(), self.currentTimeString())) thumbnailFrame = self.getThumbFrameForShot(shot) # Try and get a thumbnail, assuming the media is present etc... try: thumb = shot.thumbnail( thumbnailFrame ).save(thumbPath) except: shutil.copy(self.offlineLogoPath, thumbPath) if not os.path.isfile(thumbPath) or progress.wasCanceled(): self.cleanUpTempFiles() progress.cancel() break # This file list gets cleaned up after the PDF save finishes self.fileList += [thumbPath] dataDict = {'show':self.project, 'sequence':self.sequence, 'editVersion':"*Version*", 'setup':"*setup*", 'timeString': tc.timeToString(shot.timelineIn() + timecodeStart, fps, timecodeDisplayMode) + ", %if" % shot.duration(), 'name': self.validString(shot.name()), 'version':"*version*", 'path': thumbPath, 'track': self.validString(shot.parentTrack().name()), 'shot': self.validString(shot.source().name()), 'shotLabel': self.validString(shot.name()), 'shotStatus': "*ShotStatus*", } self.imageDataList.append(dataDict) progress.setValue(count) count += 1
def DownloadNotes(self, notebook_guid): #set progress dialog progress = QProgressDialog("Read data from server...", "Abort downloading", 0, 100) progress.setWindowModality(Qt.WindowModal) #read note data from server note_filter = NoteStore.NoteFilter() note_filter.notebookGuid = notebook_guid offset = 0 note_list = self.note_store.findNotes(self.authToken, note_filter, 0, 10000) full_note_list = note_list.notes progress.setMaximum(note_list.totalNotes + 1) while(len(full_note_list) < note_list.totalNotes): progress.setValue(offset) offset = offset + len(note_list.notes) note_list = self.note_store.findNotes(self.authToken, note_filter, offset, 10000) full_note_list.extend(note_list.notes) #set content of progress dialog progress.setMaximum(len(full_note_list)) progress.setLabelText("Downloading content of notebook...") #download the content of note if(not hasattr(self, 'note_list')): self.note_list = [] self.timestamp_list = dict() guid_list = [] else: guid_list = [note.guid for note in self.note_list] count = 0 for note in full_note_list: #load content if(note.guid not in guid_list): #add new note note.content = self.note_store.getNoteContent(self.authToken, note.guid) self.note_list.append(note) self.timestamp_list[note.guid] = [date.today(), 0] else: #update existed note note_index = guid_list.index(note.guid) if(self.note_list[note_index].updated < note.updated): self.note_list[note_index].content = self.note_store.getNoteContent(self.authToken, note.guid) #set counter progress.setValue(count) count = count + 1 if(progress.wasCanceled()): raise RuntimeError("Downloading was canceled") #save note_list to file saved_file = open(self.notebook_base_path + notebook_guid, 'w') pickle.dump(self.note_list, saved_file) saved_file.close() #save timestamp file timestamp_file = open(self.notebook_base_path + 'time_' + notebook_guid, 'w') pickle.dump(self.timestamp_list, timestamp_file) timestamp_file.close()
class UpdatesView(QDialog, Ui_UpdatesView): def __init__(self, parent, appargs): QDialog.__init__(self, parent) self.setupUi(self) self._app = esky.Esky(sys.executable, "http://10.78.55.218/pyrite/downloads") self._appargs = appargs self.connectActions() self.updateView() def connectActions(self): self.btnCheckForUpdates.clicked.connect(self.updateView) self.btnInstallUpdate.clicked.connect(self.installUpdate) self.btnClose.clicked.connect(self.reject) def updateView(self): self.lblCurrentVersion.setText("You are currently running Pyrite version:" " {0}".format(version.version)) update = self._app.find_update() if update is not None: self.lblAvailableUpdate.setText("Pyrite version {0} is available for" " download".format(update)) self.btnInstallUpdate.setEnabled(True) else: self.lblAvailableUpdate.setText("There are no new updates available at" " this time.") def installUpdate(self): try: # setup progress dialog self._progressDlg = QProgressDialog(self) self._progressDlg.setWindowModality(Qt.WindowModal) self._progressDlg.setAutoClose(True) self._progressDlg.setMinimum(0) self._progressDlg.setMaximum(100) self._progressDlg.setLabelText("Auto-Updating") self._progressDlg.setCancelButton(None) self._progressDlg.setValue(0) self._app.auto_update(self.autoUpdateCallback) appexe = esky.util.appexe_from_executable(sys.executable) os.execv(appexe, self._appargs) QMessageBox.information(None, "Updating", "Update complete!") self._app.cleanup() self._progressDlg.reset() sys.exit() except Exception, e: print("ERROR AUTO-UPDATING APP: {0}".format(e))
def doit(self): """Creates the report.""" d = QProgressDialog( self.tr("Generating Diagrams..."), self.tr("Cancel"), 0, len(self._connections) * len(self._diagramnames)) d.setWindowModality(Qt.WindowModal) d.show() aborted = False for c in self._connections: aborted = self._createDiagrams(c, d) d.hide() if not aborted: self._collectInterpretations() self._generateReport()
def load(self, fileNames): ''' unpickles data and add elements to tree view in case loading takes a while, a progress bar shows current status ''' progress = QProgressDialog("Loading files...", "Abort Copy", 0, len(fileNames), self) progress.setWindowModality(Qt.WindowModal) i = 0 for fileName in fileNames: with open(fileName, 'rb') as ifile: tmp = pickle.load(ifile) if os.path.isfile(fileName[:-2] + "oni"): tmp = tmp + (fileName[:-2]+"oni",) if isinstance(tmp, pyHPF.pyHPF): self.datas.append(tmp) else: self.datas.append(extendedPyHPF(tmp)) self.updateTree(fileName[-5:]) i+=1 progress.setValue(i)
def notifyRun(vcfPath, vcfAttributes, xAttribute, yAttribute, softFilters, forcedCategoricals, featurePaths): global canceled, splash, window splash = QProgressDialog("Loading %s" % os.path.split(vcfPath)[1], "Cancel", 0, 1000, parent=None) splash.setWindowModality(Qt.WindowModal) splash.setAutoReset(False) splash.setAutoClose(False) splash.show() canceled = False vData = variantData(vcfPath, vcfAttributes, forcedCategoricals) vParams = variantLoadingParameters(passFunction=vData.addVariant, rejectFunction=None, callbackArgs={}, tickFunction=tick, tickInterval=0.1, individualsToInclude=[], individualAppendString="", lociToInclude=None, mask=None, invertMask=False, attributesToInclude=None, attributeAppendString="", skipGenotypeAttributes=True, returnFileObject=False, alleleMatching=allele.STRICT, attemptRepairsWhenComparing=True) try: variantFile.parseVcfFile(vcfPath, vParams) except cancelButtonException: splash.close() window.window.show() return if softFilters == None: softFilters = {} for k in vData.axisLookups.iterkeys(): if k == xAttribute or k == yAttribute: if vData.axisLookups[k].hasNumeric: fivePercent = 0.05*(vData.axisLookups[k].maximum-vData.axisLookups[k].minimum) ranges = [(vData.axisLookups[k].maximum-fivePercent,vData.axisLookups[k].maximum)] else: ranges = None values = [] else: ranges = None values = None softFilters[k] = valueFilter(values=values, ranges=ranges, includeNone=True, includeBlank=True, includeInf=True, includeNaN=True, includeMissing=True, includeAlleleMasked=True, listMode=valueFilter.LIST_INCLUSIVE) intMan = interactionManager(vData,softFilters) # TODO fData = featureData(featurePaths) if canceled: splash.close() window.window.show() return splash.close() appWindow = appWidget(vData,fData,intMan,xAttribute,yAttribute) intMan.setApp(appWindow)
class setupApp: def __init__(self, params): loader = QUiLoader() infile = QFile("gui/ui/Setup.ui") infile.open(QFile.ReadOnly) self.window = loader.load(infile, None) self.loadPrefs() self.window.quitButton.clicked.connect(self.closeApp) self.window.saveButton.clicked.connect(self.savePrefs) self.window.runButton.clicked.connect(self.runSV) self.splash = QProgressDialog("Loading", "Cancel", 0, 100, parent=None) self.splash.setWindowModality(Qt.WindowModal) self.splash.setAutoReset(False) self.splash.setAutoClose(False) self.splash.hide() self.canceled = False self.window.show() self.runningApp = None def loadPrefs(self): infile = open(PREFS_FILE,'r') self.window.textEdit.setPlainText(infile.read()) infile.close() def savePrefs(self): outfile=open(PREFS_FILE,'w') outfile.write(self.window.textEdit.toPlainText()) outfile.close() def showProgressWidget(self, estimate=100, message="Loading..."): self.splash.setLabelText(message) self.splash.setMaximum(estimate) self.splash.setValue(0) self.splash.show() def tickProgressWidget(self, numTicks=1, message=None): if self.canceled: return if message != None: self.splash.setLabelText(message) newValue = min(self.splash.maximum(),numTicks+self.splash.value()) self.splash.setValue(newValue) self.canceled = self.splash.wasCanceled() return self.canceled def runSV(self, params=PREFS_FILE): self.savePrefs() self.window.hide() appPrefs = prefs.generateFromText(self.window.textEdit.toPlainText()) self.showProgressWidget(appPrefs.maxTicks, "Loading files...") self.canceled = False vData = appPrefs.loadDataObjects(callback=self.tickProgressWidget) if self.canceled: self.splash.hide() self.window.show() return self.showProgressWidget(vData.estimateTicks(), "Writing files...") success = vData.dumpVcfFile(path='/Users/Home/Desktop/chr3-seq_parsed.vcf',callback=self.tickProgressWidget) if not success: self.splash.hide() self.window.show() return sys.exit(0) # TODO write to file def closeApp(self): self.window.reject()
def go(self): global visWindow for k in Pedigree.REQUIRED_KEYS.keys(): t = self.overrides[k].currentText() if t == '': self.displayError("%s header is required." % k) return elif not t in self.header: self.displayError("%s doesn't exist in the input file." % t) return Pedigree.REQUIRED_KEYS[k] = t for k in Pedigree.RESERVED_KEYS.keys(): t = self.overrides[k].currentText() if self.window.programBox.currentText() == 'vis': if t == '': self.displayError("%s header is required." % k) return elif not t in self.header: self.displayError("%s doesn't exist in the input file." % t) return else: if t == '': t = k Pedigree.RESERVED_KEYS[k] = t try: if self.window.programBox.currentText() == 'vis': fileName = self.window.inputField.text() if fileName.lower().endswith('.gexf') or fileName.lower().endswith('.json'): raise Exception('.gexf and .json formats are not supported for the vis program. Use calculateD to create a .dat file.') ped = Pedigree(fileName, countAndCalculate=False, zeroMissing=self.window.zeroMissingBox.isChecked()) from resources.main_app import App self.window.hide() visWindow = App(ped) self.window.close() else: progress = QProgressDialog(u"Running...", u"Cancel", 0, NUM_TICKS, parent=None) progress.setWindowModality(Qt.WindowModal) progress.show() def tick(newMessage=None, increment=1): if progress.wasCanceled(): raise cancelException('Cancel clicked.') newValue = min(progress.maximum(),progress.value()+increment) progress.setValue(newValue) if newMessage != None: progress.setLabelText(newMessage) return True ped = Pedigree(self.window.inputField.text(), countAndCalculate=True, zeroMissing=self.window.zeroMissingBox.isChecked(), tickFunction=tick, numTicks=NUM_TICKS) progress.setLabelText('Writing File...') extension = os.path.splitext(self.window.outputField.text())[1].lower() if extension == '.gexf': edgeTypes = Pedigree.defaultEdgeTypes() nodeAttributeTypes = Pedigree.defaultNodeAttributeTypes() nodeAttributeTypes['is_root'] = gexf_node_attribute_mapper('is_root', attrType=gexf_node_attribute_mapper.BOOLEAN, defaultValue=False, validValues=[False,True]) ped.write_gexf(self.window.outputField.text(), edgeTypes, nodeAttributeTypes) elif extension == '.json': ped.write_json(self.window.outputField.text()) else: ped.write_egopama(self.window.outputField.text()) progress.close() self.window.inputField.setText(self.window.outputField.text()) self.window.outputField.setText("") self.window.programBox.setCurrentIndex(1) except Exception, e: if not isinstance(e, cancelException): self.displayError("An unexpected error occurred.",traceback.format_exc())
def reload(self, order_overview_widget, all_ops, all_operations, sort=1): # mainlog.debug("reload...") progress = QProgressDialog(_("Collecting data..."), None, 0, len(all_ops) + 3, order_overview_widget) progress.setWindowTitle("Horse") progress.setMinimumDuration(0) progress.setWindowModality(Qt.WindowModal) progress.setValue(progress.value() + 1) progress.show() for i in self.items(): self.removeItem(i) self.posts_offsets = dict() self.drawn_operations_data = dict() self.cursor = QGraphicsRectItem(0, 0, 50, 300) self.cursor.setBrush(QBrush(QColor(208, 208, 255, 255))) self.cursor.setPen(QPen(Qt.transparent)) self.addItem(self.cursor) bar_width = 8 bar_height = int(bar_width * 60.0 / 8.0) ascent = QFontMetrics(self.base_font).ascent() ascent_big = QFontMetrics(self.base_font_big).ascent() post_ops = {} # mainlog.debug("reload...2") # z = 0 # for op,order_part,parts in all_operations: # z = op.planned_hours # z = order_part.deadline # z = order_part.qty # z = order_part.human_identifier # all_operations = map(lambda i:i[0],all_operations) y = 0 for opdef in all_ops: progress.setValue(progress.value() + 1) operations = filter( lambda op: op.operation_definition_id == opdef. operation_definition_id, all_operations) # We're only interested in the effort/time that remains # to be put on an operation. We're only interested in # the future. # We want the oeprations that are either # - ongoing # - ready to start. # In all cases we're only interested in operations # that are "active" if sort == 1: operations = sorted( operations, key=lambda op: op.deadline or date(3000, 1, 1)) elif sort == 2: operations = sorted( operations, key=lambda op: op.planned_hours * op.qty - op.done_hours) else: # Don't sort pass maximum = 16.0 #float ! small_hours = 0 op_ndx = 0 current_x = 50 bar_drawn = False total_done_hours = total_estimated = 0 # -------------------------------------------------------------- # Started operations bars_line = BarsLine(16, bar_width, bar_height, current_x, y, self, order_overview_widget) total_hours_to_do = 0 for op in filter(lambda op: op.done_hours > 0, operations): hours_to_do = max( 0, op.planned_hours * op.qty - op.done_hours) # max protects against reporting errors total_hours_to_do += hours_to_do total_estimated += op.planned_hours * op.qty total_done_hours += op.done_hours bars_line.add_bar(hours_to_do, QBrush(Qt.green), self._operation_hoover_description(op), False, None) # op.production_file.order_part) # -------------------------------------------------------------- bars_line_unstarted_operations = BarsLine(16, bar_width, bar_height, current_x + 30, y, self, order_overview_widget) total_hours_to_do_on_unstarted_operations = 0 for op in filter(lambda op: op.done_hours == 0, operations): hours_to_do = op.planned_hours * op.qty total_hours_to_do_on_unstarted_operations += hours_to_do total_estimated += hours_to_do bars_line_unstarted_operations.add_bar( hours_to_do, QBrush(Qt.yellow), self._operation_hoover_description(op), False, None) #op.production_file.order_part) y_start = y total = total_hours_to_do + total_hours_to_do_on_unstarted_operations if total > 0: self.drawn_operations_data[ opdef.operation_definition_id] = "{}h".format( int(round(total_estimated))) gi = QGraphicsSimpleTextItem( _("{} - Estimated to do : {}h; done : {}h").format( opdef.description, int(round(total)), int(round(total_done_hours)))) gi.setFont(self.base_font_big) gi.setPos(0, y - gi.boundingRect().height()) self.addItem(gi) th = gi.boundingRect().height() gi = QGraphicsLineItem(-ascent_big, y, 1024 + 2 * ascent_big, y) gi.setPen(QPen(Qt.black)) self.addItem(gi) y += th else: continue y_bars = y if total_hours_to_do > 0: # There's something to draw head = QGraphicsSimpleTextItem(_("Started")) head.setFont(self.base_font) head.setPos(current_x, y) self.addItem(head) y += head.boundingRect().height() y += bar_height bars_line.set_start_pos(current_x, y) bars_line.finish_bar() foot = QGraphicsSimpleTextItem( _("{}h").format(int(total_hours_to_do + 0.5))) foot.setFont(self.base_font) foot.setPos(current_x, y) self.addItem(foot) y += foot.boundingRect().height() current_x = max(current_x + bars_line.estimate_width(), head.boundingRect().right(), foot.boundingRect().right()) bar_drawn = True if total_hours_to_do_on_unstarted_operations > 0: if bars_line_unstarted_operations.estimate_width( ) + current_x > 1200: x = 50 y += ascent_big else: y = y_bars x = current_x + 50 head = QGraphicsSimpleTextItem(_("Not started yet")) head.setFont(self.base_font) head.setPos(x, y) self.addItem(head) y += head.boundingRect().height() y += bar_height bars_line_unstarted_operations.set_start_pos(x, y) bars_line_unstarted_operations.finish_bar() foot = QGraphicsSimpleTextItem( _("{}h").format( int(total_hours_to_do_on_unstarted_operations + 0.5))) foot.setFont(self.base_font) foot.setPos(x, y) self.addItem(foot) y += foot.boundingRect().height() bar_drawn = True y += 3 * ascent_big r = self.sceneRect() self.posts_offsets[opdef.operation_definition_id] = \ QRectF(r.x() - 2*ascent_big, y_start - 1.5*ascent_big, r.width() + 4*ascent_big, (y - ascent_big) - (y_start - 1.5*ascent_big) ) y += ascent_big # mainlog.debug("reload...3") import functools max_width = functools.reduce(lambda acc, po: max(acc, po.width()), self.posts_offsets.values(), 0) map(lambda po: po.setWidth(max_width), self.posts_offsets.values()) # for r in self.posts_offsets.values(): # gi = QGraphicsLineItem(r.x(),r.y(),r.x()+r.width(),r.y()) # gi.setPen(QPen(Qt.lightGray)) # self.addItem(gi) progress.close()