def closeVistrail(self, vistrailView=None, quiet=False): """ closeVistrail(vistrailView: QVistrailView, quiet: bool) -> bool Close the current active vistrail """ if hasattr(self, "canCancelClose"): canCancel = self.canCancelClose else: canCancel = True if not vistrailView: vistrailView = self.currentWidget() vistrailView.flush_changes() if vistrailView: if not quiet and vistrailView.controller.changed: text = vistrailView.controller.name if text=='': text = 'Untitled%s'%core.system.vistrails_default_file_type() text = ('Vistrail ' + QtCore.Qt.escape(text) + ' contains unsaved changes.\n Do you want to ' 'save changes before closing it?') if canCancel: res = QtGui.QMessageBox.information(getBuilderWindow(), 'Vistrails', text, '&Save', '&Discard', 'Cancel', 0, 2) else: res = QtGui.QMessageBox.information(getBuilderWindow(), 'Vistrails', text, '&Save', '&Discard') else: res = 1 if res == 0: locator = vistrailView.controller.locator if locator is None: class_ = FileLocator() else: class_ = type(locator) return self.save_vistrail(class_) elif res == 2: return False self.removeVistrailView(vistrailView) if self.count()==0: self.emit(QtCore.SIGNAL('currentVistrailChanged'), None) self.emit(QtCore.SIGNAL('versionSelectionChange'), -1) if vistrailView == self._first_view: self._first_view = None return True
def QVTS_keyPressEvent(self, event): selectedItems = self.selectedItems() versions = [item.id for item in selectedItems if type(item)== gui.version_view.QGraphicsVersionItem and not item.text.hasFocus()] if (self.controller and len(versions)>0 and event.key() in [QtCore.Qt.Key_F]): self.controller.focus_current_version_in_view() if (getBuilderWindow() and len(versions)>0 and event.key() in [QtCore.Qt.Key_A]): getBuilderWindow().resetView() qt_super(gui.version_view.QVersionTreeScene, self).keyPressEvent(event)
def updateFrameSlider(self, value): """ Highlight the frame without contents when the user moved """ if self.controller and len(self.frames)>0: if self.lastVersion==-1: self.lastVersion = self.controller.current_version builderWindow = getBuilderWindow() builderWindow.changeVersionWithoutUpdatingApp(self.frames[value])
def getInfoFromPipeline(self): """ getInfoFromPipeline() -> (string array,string array) get operations and descriptions from pipeline """ controller=getBuilderWindow().viewManager.currentWidget().controller descriptions = [controller.vistrail.get_description(v) for v in controller.vistrail.actionMap.keys()] ops = controller.extract_ops_per_version(0,controller.current_version) return (descriptions,ops)
def __init__(self): """ __init__() -> None """ """ extract the vistrail dates """ self.dates=[] for action in getBuilderWindow().viewManager.currentWidget().controller.vistrail.actions: dt=datetime.datetime.strptime(action.date,'%d %b %Y %H:%M:%S') self.dates.append(time.mktime(dt.timetuple())+dt.microsecond/1000000.0)
def QVTV_new_init(self, parent=None): original_QVTV_init(self, parent) self.canSelectBackground = False self.canSelectRectangle = False self.setScene(QPlaybackVersionTreeScene(self)) self.selectingIndicator = None self.descriptionWidget = getBuilderWindow().descriptionWidget self.isMultiSelecting = False self.multiSelectionLabel = '' self.multiSelectionMessages = None self.multiSelectionCount = 0 self.currentSelectionStep = 0
def closeVistrail(self, vistrailView=None, quiet=False): """ closeVistrail(vistrailView: QVistrailView, quiet: bool) -> bool Close the current active vistrail """ if not vistrailView: vistrailView = self.currentWidget() vistrailView.flush_changes() if vistrailView: if not quiet and vistrailView.controller.changed: text = vistrailView.controller.name if text=='': text = 'Untitled%s'%core.system.vistrails_default_file_type() text = ('Vistrail ' + QtCore.Qt.escape(text) + ' contains unsaved changes.\n Do you want to ' 'save changes before closing it?') res = QtGui.QMessageBox.information(getBuilderWindow(), 'Vistrails', text, '&Save', '&Discard', 'Cancel', 0, 2) else: res = 1 locator = vistrailView.controller.locator if res == 0: if locator is None: class_ = FileLocator() else: class_ = type(locator) locator = self.save_vistrail(class_) if not locator: return False elif res == 2: return False vistrailView.controller.close_vistrail(locator) self.removeVistrailView(vistrailView) if self.count()==0: self.emit(QtCore.SIGNAL('currentVistrailChanged'), None) self.emit(QtCore.SIGNAL('versionSelectionChange'), -1) if vistrailView == self._first_view: self._first_view = None return True
def __init__(self): """ __init__() -> None """ """ extract the vistrail dates """ dates=[] for action in getBuilderWindow().viewManager.currentWidget().controller.vistrail.actions: dt=datetime.datetime.strptime(action.date,'%d %b %Y %H:%M:%S') dates.append(time.mktime(dt.timetuple())+dt.microsecond/1000000.0) """ compute the time differences """ self.diffs=[] if len(dates)>0: dates=sorted(dates) for i in range(len(dates)-1): diff=dates[i+1]-dates[i] if diff<=self.timeDiffThreshold: self.diffs.append(diff)
def getInfoFromPipeline(self): """ getInfoFromPipeline() -> (string array,string array) get operations and descriptions from pipeline """ controller=getBuilderWindow().viewManager.currentWidget().controller ops=[] descriptions=controller.vistrail.descriptionMap.values() moduleIds=sorted(controller.current_pipeline.modules.keys()) for mId in moduleIds: module=controller.current_pipeline.modules[mId] localOps=[] descritpion='' for function in module.functions: if function.name=='value': o=urllib.unquote(module.functions[function.id].params[0].strValue) localOps.append(unpickleOperations(o)) if len(localOps)>0: ops.append(localOps[0][0]) return (descriptions,ops)
def updateTimeHistogram(self): """ updateTimeHistogram() -> None FIXME: Does not use session ids yet like the text statistics do """ """ extract the vistrail dates """ dates=[] for action in getBuilderWindow().viewManager.currentWidget().controller.vistrail.actions: dt=datetime.datetime.strptime(action.date,'%d %b %Y %H:%M:%S') dates.append(time.mktime(dt.timetuple())+dt.microsecond/1000000.0) """ compute bounds and counts """ histogramBounds=[] histogramCounts=[] if len(dates)>0: leftBound=min(dates) rightBound=max(dates) self.histogramView.initData(dates,leftBound,rightBound,leftBound,rightBound)
def doneMultiSelection(self, successful, versions): """ doneMultiSelection(successful: bool) -> None Handled the selection is done. successful specifies if the selection was completed or aborted by users. """ versionView = self.getVersionView() self.disconnect(versionView, QtCore.SIGNAL('doneMultiSelection'), self.doneMultiSelection) if successful: currentVersions = versions valid = True try: valid = self.controller.vistrail.actionChain(currentVersions[1], currentVersions[0])!=[] except: valid = False if valid: self.setCurrentVersions(currentVersions[0],currentVersions[1]) else: successful = False QtGui.QMessageBox.critical(getBuilderWindow(), 'Invalid versions', 'The selected versions cannot be used for playback. ' \ 'The end version must be a descendant of the start' \ 'version. The selection has been canceled.') if not successful: self.setCurrentVersions(*self.previousVersions) versionView.setIndicatorVersions(self.previousVersions[0],self.previousVersions[1],-1) versionView.acquireMultiSelection('Playback') versionView.setIndicatorsVisible(True,True,False) self.setEnabled(True) # Mac Qt bug: For some reason these widgets need to be enabled individually self.frameSlider.setEnabled(True) self.frameLabel.setEnabled(True) self.speedAction.setEnabled(True) self.stop()
def updateTimeDiffHistogram(self): """ updateTimeDiffHistogram() -> None FIXME: Does not use session ids yet like the text statistics do """ """ extract the vistrail dates """ dates=[] for action in getBuilderWindow().viewManager.currentWidget().controller.vistrail.actions: dt=datetime.datetime.strptime(action.date,'%d %b %Y %H:%M:%S') dates.append(time.mktime(dt.timetuple())+dt.microsecond/1000000.0) """ compute the time differences """ if len(dates)>0: dates=sorted(dates) diffs=[] for i in range(len(dates)-1): diff=dates[i+1]-dates[i] if diff<=self.timeDiffThreshold: diffs.append(diff) """ compute bounds and counts """ if len(diffs)>0: leftBound=0 rightBound=max(diffs) mean=0 for diff in diffs: mean+=diff mean/=len(diffs) stddev=0 for diff in diffs: stddev+=(diff-mean)*(diff-mean) stddev=math.sqrt(stddev/len(diffs)) self.histogramView.initData(diffs,leftBound,rightBound,leftBound,2*stddev)
def extract_file(self, filename, extractDir, zipFilename, mediaType): if filename == None or extractDir == None or zipFilename == None: return 1 afile = os.path.join(extractDir, mediaType, filename) if os.path.exists(afile): return 0 try: zf = zipfile.ZipFile(zipFilename, 'r') except: raise Exception('Error opening file!\nThe file may be invalid or you\nmay have insufficient permissions.') getBuilderWindow().startProgress('Opening...') sourceZip = zipfile.ZipFile(zipFilename) for name in sourceZip.namelist(): if name.find(filename) != -1: getBuilderWindow().updateProgress(0.5) sourceZip.extract(name, extractDir) break getBuilderWindow().endProgress() return 0
def __init__(self, filePath, dialogFlags, defaultDir=''): from gui.utils import getBuilderWindow parent=getBuilderWindow() flags = QtCore.Qt.WindowStaysOnTopHint modal = True if core.system.systemType in ['Darwin']: flags = flags | QtCore.Qt.Sheet modal = False else: flags = flags | QtCore.Qt.MSWindowsFixedSizeDialogHint QtGui.QDialog.__init__(self, parent, flags) self.setModal(modal) self.setSizeGripEnabled(False) self.textLayout = QtGui.QHBoxLayout() self.appIcon = QtGui.QLabel(self) pixmap = QtGui.QPixmap(CurrentTheme.APPLICATION_PIXMAP) pixmap = pixmap.scaled(64,64) self.appIcon.setPixmap(pixmap) self.textLayout.addWidget(self.appIcon) self.textContent=QtGui.QVBoxLayout() self.textLayout.addLayout(self.textContent) self.textContent.addWidget(QtGui.QLabel('The file',self)) label=QtGui.QLabel(filePath,self) self.textContent.addWidget(label) if len(filePath)>80: label.setWordWrap(True) font=QtGui.QFont(label.font()) font.setFamily('Courier') label.setFont(font) #label=QtGui.QPlainTextEdit(filePath,self) #self.textContent.addWidget(label) #label.setReadOnly(True) #if len(filePath)>80: # label.setLineWrapMode(QPlainTextEdit.WidgetWidth) #else: # label.setLineWrapMode self.textContent.addWidget(\ QtGui.QLabel('is referenced but could not be found.')) self.buttonLayout=QtGui.QHBoxLayout() self.buttonLayout.addStretch() browseButton=QtGui.QPushButton('Browse File',self) browseButton.setDefault(True) self.buttonLayout.addWidget(browseButton) self.connect(browseButton,QtCore.SIGNAL('clicked()'), self.browseButtonPressed) if dialogFlags&2: browseDirButton=QtGui.QPushButton('Browse Directory', self) self.buttonLayout.addWidget(browseDirButton) self.connect(browseDirButton,QtCore.SIGNAL('clicked()'), self.browseDirButtonPressed) ignoreButton=QtGui.QPushButton('Ignore Missing File',self) self.buttonLayout.addWidget(ignoreButton) self.connect(ignoreButton,QtCore.SIGNAL('clicked()'), self.ignoreButtonPressed) if dialogFlags&1: ignoreAllButton=QtGui.QPushButton('Ignore All', self) self.buttonLayout.addWidget(ignoreAllButton) self.connect(ignoreAllButton,QtCore.SIGNAL('clicked()'), self.ignoreAllButtonPressed) #cancelButton=QtGui.QPushButton('Cancel',self) #self.buttonLayout.addWidget(cancelButton) #self.connect(cancelButton,QtCore.SIGNAL('clicked()'), # self.cancelButtonPressed) self.dialogLayout = QtGui.QVBoxLayout() self.dialogLayout.addLayout(self.textLayout) self.dialogLayout.addLayout(self.buttonLayout) self.setLayout(self.dialogLayout) self.filePath=filePath self.defaultDir=defaultDir self.result=None self.resultPath=None
def compute(self, start_version, end_version): """ updateTimeTotals(start_version:int, end_version:int) -> None Calculate the total time for the user across sessions. If start and end versions are not valid, compute for all actions. """ controller = getBuilderWindow().viewManager.currentWidget().controller title = "" actions = [] if start_version < 0 or end_version < 0: title = 'Time Statistics' actions = controller.vistrail.actions else: title = 'Sequence Time Statistics: ' + str(start_version) + ' -> ' + str(end_version) actions = controller.vistrail.actionChain(end_version, start_version) self.setWindowTitle(title) for (uLabel, aLabel, tLabel) in self.entries: uLabel.hide() aLabel.hide() tLabel.hide() total_stats={} active_stats={} previous_time = None previous_session = None for action in actions: dt = datetime.datetime.strptime(action.date, '%d %b %Y %H:%M:%S') current_time = time.mktime(dt.timetuple())+dt.microsecond/1000000.0 if previous_time and action.session == previous_session: diff = current_time-previous_time if total_stats.has_key(action.user): total_stats[action.user] += diff else: total_stats[action.user] = diff if diff <= 60: # ignore anything more than a minute if active_stats.has_key(action.user): active_stats[action.user] += diff else: active_stats[action.user] = diff previous_session = action.session previous_time = current_time # Add a zero time if there is only one action if len(actions) == 1: total_stats[actions[0].user] = 0 active_stats[actions[0].user] = 0 # Reuse the widgets added to the layout because deleting them # does not seem to actually clear them from the dialog row = 2 for (u,t) in total_stats.iteritems(): tt = self.getTimeString(t) # find active stats for the same user if active_stats.has_key(u): at = active_stats[u] att = self.getTimeString(at) else: att = self.getTimeString(0) if len(self.entries) < row-1: uLabel = QtGui.QLabel(u) aLabel = QtGui.QLabel(att) tLabel = QtGui.QLabel(tt) self.gridLayout.addWidget(uLabel, row, 0, QtCore.Qt.AlignLeft) self.gridLayout.addWidget(aLabel, row, 1, QtCore.Qt.AlignHCenter) self.gridLayout.addWidget(tLabel, row, 2, QtCore.Qt.AlignHCenter) self.entries.append((uLabel,aLabel,tLabel)) else: (uLabel,aLabel,tLabel) = self.entries[row-2] uLabel.setText(u) aLabel.setText(att) tLabel.setText(tt) uLabel.show() aLabel.show() tLabel.show() row+=1 self.update()
if b: basename += ".b" else: basename += ".a" zf.write(f, basename, zipfile.ZIP_DEFLATED) zf.close() currentFolder = [] except Exception, e: # Allow autosaves to fail silently if filename.find('vt_autosaves') <0: raise Exception('Error writing file!\nThe file may be invalid or you\nmay have insufficient permissions.') getBuilderWindow().updateProgress(0.95) # Remove temporary files for f in zip_fnames: os.unlink(f) getBuilderWindow().endProgress() return vistrail def new_open_vistrail_from_zip_xml(filename): """open_vistrail_from_zip_xml(filename) -> Vistrail Open a vistrail from a zip compressed format. It expects that the file inside archive has name vistrail """
def new_open_vistrail_from_zip_xml_old(filename): """open_vistrail_from_zip_xml(filename) -> Vistrail Open a vistrail from a zip compressed format. It expects that the file inside archive has name vistrail """ try: zf = zipfile.ZipFile(filename, 'r') except: raise Exception('Error opening file!\nThe file may be invalid or you\nmay have insufficient permissions.') getBuilderWindow().startProgress('Opening...') ####################################################### #Audio and Video sourceZip = zipfile.ZipFile(filename) tmp_audio_dir = tempfile.mkdtemp(prefix="VTAudio") audio_dir = os.path.join(tmp_audio_dir) tmp_video_dir = tempfile.mkdtemp(prefix="VTVideo") video_dir = os.path.join(tmp_video_dir) for name in sourceZip.namelist(): if name.find('.mp3') != -1 or name.find('.wav') != -1 or name.find('.ogg') != -1 or \ name.find('.mpc') != -1 or name.find('.flac') != -1 or name.find('.au') != -1 or \ name.find('.raw') != -1 or name.find('.dct') != -1 or name.find('.aac') != -1 or \ name.find('.m4a') != -1 or name.find('.wma') != -1 or \ name.find('.amr') != -1 or name.find('.awb'): if name.startswith('audio/VTAudio') == True: sourceZip.extract(name, tmp_audio_dir) if name.find('.3g2') != -1 or name.find('.3gp') != -1 or name.find('.amv') != -1 or \ name.find('.asf') != -1 or name.find('.asx') != -1 or name.find('.avi') != -1 or \ name.find('.wmv') != -1 or name.find('.vob') != -1 or name.find('.wwf') != -1 or \ name.find('.rm') != -1 or name.find('.mpg') != -1 or name.find('.mov') != -1 or \ name.find('.flv') != -1 or name.find('.mp4'): if name.startswith('video/VTVideo') == True: sourceZip.extract(name, tmp_video_dir) # Unzip vistrail (file_, xmlfname) = tempfile.mkstemp(suffix='.xml') os.close(file_) file(xmlfname, 'w').write(zf.read('vistrail')) vistrail = open_vistrail_from_xml(xmlfname) vistrail.db_audio_dir = os.path.join(tmp_audio_dir) vistrail.db_video_dir = os.path.join(tmp_video_dir) os.unlink(xmlfname) getBuilderWindow().updateProgress(0.3) # Unzip data file (bfile_, binfname) = tempfile.mkstemp() os.close(bfile_) file(binfname, 'wb').write(zf.read('data')) vistrail.binary_data = array.array('c') bsize = os.path.getsize(binfname) vt_bin_file = open(binfname, 'rb') vistrail.binary_data.fromfile(vt_bin_file, bsize) vt_bin_file.close() os.unlink(binfname) getBuilderWindow().updateProgress(0.7) # Unzip save data namelist = zf.namelist() vistrail.saved_files = [] for name in namelist: if name != "vistrail" and name != "data" and \ not name.startswith("audio" + os.sep) and not name.startswith("video" + os.sep) and not name.startswith("audio") and not name.startswith("video"): # Filename has a '.b' or '.a' appended to it so we know # how to write it. In Python 2.6 or later, we should just use # zipFile.extractAll instead of zipFile.read (basename,ext) = os.path.splitext(name) sfilename = core.system.temporary_save_file(os.path.basename(basename)) print "sfilename, ", sfilename print "name, ", name if ext == ".b": file(sfilename, 'wb').write(zf.read(name)) else: file(sfilename, 'w').write(zf.read(name)) vistrail.saved_files.append((sfilename, ext)) getBuilderWindow().endProgress() temp_audio_Dir = vistrail.db_audio_dir temp_video_Dir = vistrail.db_video_dir return vistrail
def new_save_vistrail_to_zip_xml(vistrail, filename): # Dumb hack to figure out if we are autosaving if filename.find('vt_autosaves') > 0: getBuilderWindow().startProgress('Autosaving...') else: getBuilderWindow().startProgress('Saving...') # Write the vistrail file to disk (file_, xmlfname) = tempfile.mkstemp(suffix='.xml') os.close(file_) save_vistrail_to_xml(vistrail,xmlfname) vt_fname = os.path.join(os.path.dirname(xmlfname), 'vistrail') if os.path.exists(vt_fname): os.remove(vt_fname) os.rename(xmlfname, vt_fname) zip_fnames = [vt_fname, ] #Audio Dir ################################################### zip_audio_folder = [] audio_dir = vistrail.db_audio_dir zip_audio_folder.append(audio_dir) ################################################### #Video Dir ################################################### zip_video_folder = [] video_dir = vistrail.db_video_dir zip_video_folder.append(video_dir) ################################################### getBuilderWindow().updateProgress(0.2) # Save binary data (bin_file, bin_filename) = tempfile.mkstemp(suffix='.bin') os.close(bin_file) bfile = open(bin_filename, "wb") vistrail.binary_data.tofile(bfile) bfile.close() bin_fname = os.path.join(os.path.dirname(bin_filename), 'data') if os.path.exists(bin_fname): os.remove(bin_fname) os.rename(bin_filename, bin_fname) zip_fnames.append(bin_fname) getBuilderWindow().updateProgress(0.5) if vistrail.log is not None and len(vistrail.log.workflow_execs) > 0: if vistrail.log_filename is None: (log_file, log_filename) = tempfile.mkstemp(suffix='.xml') os.close(log_file) log_file = open(log_filename, "wb") else: log_filename = vistrail.log_filename log_file = open(log_filename, 'ab') print "+++ ", log_filename print "*** ", log_file if not hasattr(log_file, "write"): print "no!!!" # append log to log_file for workflow_exec in vistrail.log.workflow_execs: daoList = getVersionDAO(currentVersion) daoList.save_to_xml(workflow_exec, log_file, {}, currentVersion) log_file.close() log_fname = os.path.join(os.path.dirname(log_filename), 'log') if os.path.exists(log_fname): os.remove(log_fname) os.rename(log_filename, log_fname) zip_fnames.append(log_fname) try: zf = zipfile.ZipFile(file=filename,mode='w', allowZip64=True) # Add standard vistrails files for f in zip_fnames: zf.write(f,os.path.basename(f),zipfile.ZIP_DEFLATED) if zip_audio_folder[0] != None: if os.path.isdir(zip_audio_folder[0]) == True: for d in zip_audio_folder: addFolderToZipFile(zf, d, "audio") if zip_video_folder[0] != None: if os.path.isdir(zip_video_folder[0]) == True: for v in zip_video_folder: addFolderToZipFile(zf, v, "video") getBuilderWindow().updateProgress(0.75) # Add saved files. Append indicator of file type because it needed # when extracting the zip on Windows for (f,b) in vistrail.saved_files: basename = os.path.join("vt_saves",os.path.basename(f)) if b: basename += ".b" else: basename += ".a" zf.write(f, basename, zipfile.ZIP_DEFLATED) zf.close() currentFolder = [] except Exception, e: # Allow autosaves to fail silently if filename.find('vt_autosaves') <0: raise Exception('Error writing file!\nThe file may be invalid or you\nmay have insufficient permissions.')
def savePreferences(self): """ Map all widget values back to App Preferences """ num_versions = self.numberOfVisibleVersionsSB.value() num_snapshot = self.numSnapshotTB.value() snap_enabled = 1 if self.snapShotCB.checkState() == QtCore.Qt.Unchecked: snap_enabled = 0 file_store = 1 if self.fileStoreCB.checkState() == QtCore.Qt.Unchecked: file_store = 0 autosave_enabled = 1 if self.autosaveCB.checkState() == QtCore.Qt.Unchecked: autosave_enabled = 0 autosave_delay = self.autosaveDelayTB.value() if self.alwaysOnTopCB.checkState() == QtCore.Qt.Unchecked: getBuilderWindow().setWindowFlags(getBuilderWindow().windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint) getBuilderWindow().show() always_on_top = 0 else: getBuilderWindow().setWindowFlags(getBuilderWindow().windowFlags() | QtCore.Qt.WindowStaysOnTopHint) getBuilderWindow().show() always_on_top = 1 controller = getBuilderWindow().viewManager.currentWidget().controller controller.set_num_versions_always_shown(num_versions) reset_autosave = autosave_enabled != int( CaptureAPI.getPreference("VisTrailsAutosaveEnabled") ) or autosave_delay != int(CaptureAPI.getPreference("VisTrailsAutosaveDelay")) if CaptureAPI.getPreference("VisTrailsNumberOfVisibleVersions") is not None: CaptureAPI.setPreference("VisTrailsNumberOfVisibleVersions", str(num_versions)) if CaptureAPI.getPreference("VisTrailsSnapshotCount") is not None: CaptureAPI.setPreference("VisTrailsSnapshotCount", str(num_snapshot)) if CaptureAPI.getPreference("VisTrailsSnapshotEnabled") is not None: CaptureAPI.setPreference("VisTrailsSnapshotEnabled", str(snap_enabled)) if CaptureAPI.getPreference("VisTrailsAutosaveEnabled") is not None: CaptureAPI.setPreference("VisTrailsAutosaveEnabled", str(autosave_enabled)) if CaptureAPI.getPreference("VisTrailsAutosaveDelay") is not None: CaptureAPI.setPreference("VisTrailsAutosaveDelay", str(autosave_delay)) if CaptureAPI.getPreference("VisTrailsStoreFiles") is not None: CaptureAPI.setPreference("VisTrailsStoreFiles", str(file_store)) if CaptureAPI.getPreference("VisTrailsAlwaysOnTop") is not None: CaptureAPI.setPreference("VisTrailsAlwaysOnTop", str(always_on_top)) if reset_autosave: controller.reset_autosave_timer() try: CaptureAPI.savePreferences() except: print "Warning: could not save preferences"
def __init__(self, parent=None): """ Construct a simple dialog layout """ QtGui.QDialog.__init__(self, parent) self.setWindowTitle("Provenance Explorer Preferences") layout = QtGui.QVBoxLayout(self) self.setLayout(layout) # vistrails window always on top self.alwaysOnTopCB = QtGui.QCheckBox("Plug-in window always on top") state = CaptureAPI.getPreference("VisTrailsAlwaysOnTop") if state is not None: state = int(CaptureAPI.getPreference("VisTrailsAlwaysOnTop")) if state: self.alwaysOnTopCB.setCheckState(QtCore.Qt.Checked) else: self.alwaysOnTopCB.setCheckState(QtCore.Qt.Unchecked) layout.addWidget(self.alwaysOnTopCB) # The number of visible versions edit box self.numberOfVisibleVersionsSB = QtGui.QSpinBox() if CaptureAPI.getPreference("VisTrailsNumberOfVisibleVersions") is not None: novLayout = QtGui.QHBoxLayout() layout.addLayout(novLayout) novLayout.setMargin(0) novLabel = QtGui.QLabel("Number of recent versions visible") novLayout.addWidget(novLabel) novLayout.addWidget(self.numberOfVisibleVersionsSB) self.numberOfVisibleVersionsSB.setRange(0, 1000) self.numberOfVisibleVersionsSB.setValue(int(CaptureAPI.getPreference("VisTrailsNumberOfVisibleVersions"))) novLayout.addStretch() # Enabling snapshots self.snapShotCB = QtGui.QCheckBox("Take state snapshots") self.numSnapshotTB = QtGui.QSpinBox() state = CaptureAPI.getPreference("VisTrailsSnapshotEnabled") if state is not None: layout.addSpacing(10) state = int(CaptureAPI.getPreference("VisTrailsSnapshotEnabled")) if state: self.snapShotCB.setCheckState(QtCore.Qt.Checked) else: self.snapShotCB.setCheckState(QtCore.Qt.Unchecked) layout.addWidget(self.snapShotCB) self.connect(self.snapShotCB, QtCore.SIGNAL("clicked()"), self.updateState) # The number of actions before a snapshot if CaptureAPI.getPreference("VisTrailsSnapshotCount") is not None: nosLayout = QtGui.QHBoxLayout() layout.addLayout(nosLayout) nosLayout.setMargin(0) nosLabel = QtGui.QLabel("Number of actions between snapshots") nosLayout.addWidget(nosLabel) nosLayout.addWidget(self.numSnapshotTB) self.numSnapshotTB.setRange(0, 1000) self.numSnapshotTB.setValue(int(CaptureAPI.getPreference("VisTrailsSnapshotCount"))) self.numSnapshotTB.setEnabled(state) nosLayout.addStretch() # Enabling Autosave self.autosaveCB = QtGui.QCheckBox("Autosave") self.autosaveDelayTB = QtGui.QSpinBox() state = CaptureAPI.getPreference("VisTrailsAutosaveEnabled") if state is not None: layout.addSpacing(10) state = int(CaptureAPI.getPreference("VisTrailsAutosaveEnabled")) if state: self.autosaveCB.setCheckState(QtCore.Qt.Checked) else: self.autosaveCB.setCheckState(QtCore.Qt.Unchecked) layout.addWidget(self.autosaveCB) self.connect(self.autosaveCB, QtCore.SIGNAL("clicked()"), self.updateState) # The delay in minutes between autosaves if CaptureAPI.getPreference("VisTrailsAutosaveDelay") is not None: adLayout = QtGui.QHBoxLayout() layout.addLayout(adLayout) adLayout.setMargin(0) adLabel = QtGui.QLabel("Minutes between autosave") adLayout.addWidget(adLabel) adLayout.addWidget(self.autosaveDelayTB) self.autosaveDelayTB.setRange(1, 100) self.autosaveDelayTB.setValue(int(CaptureAPI.getPreference("VisTrailsAutosaveDelay"))) self.autosaveDelayTB.setEnabled(state) adLayout.addStretch() # Store files in vt self.fileStoreCB = QtGui.QCheckBox("Store opened and imported files in vistrail") if CaptureAPI.getPreference("VisTrailsStoreFiles") is not None: layout.addSpacing(10) state = int(CaptureAPI.getPreference("VisTrailsStoreFiles")) if state: self.fileStoreCB.setCheckState(QtCore.Qt.Checked) else: self.fileStoreCB.setCheckState(QtCore.Qt.Unchecked) layout.addWidget(self.fileStoreCB) # A space layout.addSpacing(10) layout.addStretch() # Then the buttons bLayout = QtGui.QHBoxLayout() layout.addLayout(bLayout) bLayout.addStretch() self.saveButton = QtGui.QPushButton("Save") bLayout.addWidget(self.saveButton) self.cancelButton = QtGui.QPushButton("Cancel") bLayout.addWidget(self.cancelButton) bLayout.addStretch() # Connect buttons to dialog handlers self.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.accept) self.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), self.reject) controller = getBuilderWindow().viewManager.currentWidget().controller controller.set_num_versions_always_shown(self.numberOfVisibleVersionsSB.value()) # Reader specific GUI if CaptureAPI.isReadOnly(): self.autosaveCB.setText("Autosave (Pro)") self.autosaveCB.setEnabled(False) adLabel.setText("Minutes between autosave (Pro)") adLabel.setEnabled(False) self.autosaveDelayTB.setEnabled(False) self.fileStoreCB.setText("Store opened and imported files in vistrail (Pro)") self.fileStoreCB.setEnabled(False) self.snapShotCB.setText("Take state snapshots (Pro)") self.snapShotCB.setEnabled(False) nosLabel.setText("Number of actions between snapshots (Pro)") nosLabel.setEnabled(False) self.numSnapshotTB.setEnabled(False)
# that the Maya plugin makes its capture api available. # We have to do this even before the patcher gets imported!! from plugin.app import CaptureAPI sys.modules['CaptureAPI'] = CaptureAPI # do this early so we always use the patched modules import plugin.patcher import gui.application from gui.utils import getBuilderWindow # start vistrails app = gui.application.start_application_without_init() builderWindow = getBuilderWindow() if not builderWindow: print "no builder window???" else: # startup whatever the capture api needs to run CaptureAPI.start(builderWindow) # Let QT take over. app.exec_()