def refreshToolTips(self): lines = redRObjects.lines() for l in lines.values(): if l.outWidget.instance() == self: l.refreshToolTip()
def save(filename = None, template = False, copy = False, pipe = False): global _schemaName global schemaPath global notesTextWidget #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, '%s' % filename) if filename == None and not copy: filename = os.path.join(schemaPath, _schemaName) elif copy: filename = os.path.join(redREnviron.directoryNames['tempDir'], 'copy.rrts') #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'Saveing file as name %s' % filename) progressBar = startProgressBar( _('Saving ')+unicode(os.path.basename(filename)), _('Saving ')+unicode(os.path.basename(filename)), len(redRObjects.instances())+len(redRObjects.lines())+3) progress = 0 # create xml document (doc, schema, header, widgets, lines, settings, required, tabs, saveTagsList, saveDescription) = makeXMLDoc() """!@#$ Is this still required? If packages request R libraries then we don't really need to install them again, we just need to resolve the packages.""" requiredRLibraries = {} #save widgets tempWidgets = redRObjects.instances(wantType = 'dict') ## all of the widget instances, these are not the widget icons """This is where we save the instances to the file.""" print 'Saving widget instances ', tempWidgets (widgets, settingsDict, requireRedRLibraries) = saveInstances(tempWidgets, widgets, doc, progressBar) # save tabs and the icons and the channels if not copy or template: #tabs.setAttribute('tabNames', unicode(self.canvasTabs.keys())) for t in redRObjects.tabNames(): temp = doc.createElement('tab') temp.setAttribute('name', t) ## set all of the widget icons on the tab widgetIcons = doc.createElement('widgetIcons') for wi in redRObjects.getIconsByTab(t)[t]: ## extract only the list for this tab thus the [t] syntax saveIcon(widgetIcons, wi, doc) temp.appendChild(widgetIcons) ## append the widgetIcons XML to the global XML tabs.appendChild(temp) ## save the global settings ## if notesTextWidget: globalData.setGlobalData('Notes', 'globalNotes', unicode(notesTextWidget.toHtml())) settingsDict['_globalData'] = cPickle.dumps(globalData.globalData,2) settingsDict['_requiredPackages'] = cPickle.dumps({'R': requiredRLibraries.keys(),'RedR': requireRedRLibraries},2) #print requireRedRLibraries file = open(os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), "wt") file.write(unicode(settingsDict)) file.close() if template: taglist = unicode(tempDialog.tagsList.text()) tempDescription = unicode(tempDialog.descriptionEdit.toPlainText()) saveTagsList.setAttribute("tagsList", taglist) saveDescription.setAttribute("tempDescription", tempDescription) xmlText = doc.toprettyxml() progress += 1 progressBar.setValue(progress) if not template and not copy and not pipe: tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") tempR = os.path.join(redREnviron.directoryNames['tempDir'], "tmp.RData").replace('\\','/') file = open(tempschema, "wt") file.write(xmlText.encode('utf-8', 'replace')) file.close() doc.unlink() progressBar.setLabelText('Saving Data...') progress += 1 progressBar.setValue(progress) RSession.Rcommand('save.image("' + tempR + '")') # save the R data createZipFile(filename,[],[redREnviron.directoryNames['tempDir']])# collect the files that are in the tempDir and save them into the zip file. elif template: tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") file = open(tempschema, "wt") file.write(xmlText) file.close() zout = zipfile.ZipFile(filename, "w") zout.write(tempschema,"tempSchema.tmp") zout.write(os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'),'settings.pickle') zout.close() doc.unlink() elif copy: tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") file = open(tempschema, "wt") file.write(xmlText) file.close() zout = zipfile.ZipFile(filename, "w") zout.write(tempschema,"tempSchema.tmp") zout.write(os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'),'settings.pickle') zout.close() doc.unlink() loadTemplate(filename) progress += 1 progressBar.setValue(progress) progressBar.close() if os.path.splitext(filename)[1].lower() == ".rrs": (schemaPath, schemaName) = os.path.split(filename) redREnviron.settings["saveSchemaDir"] = schemaPath canvasDlg.toolbarFunctions.addToRecentMenu(filename) canvasDlg.setCaption(schemaName) redRLog.log(redRLog.REDRCORE, redRLog.INFO, 'Document Saved Successfully to %s' % filename) return True
def makeTemplate(filename, copy = False): ## this is different from saving. We want to make a special file that only has the selected widgets, their connections, and settings. No R data or tabs are saved. if not copy: tempDialog = TemplateDialog() tempDialog.exec_() tempdoc = Document() ## generates the main document type. tempXML = tempdoc.createElement("TemplateXML") saveTagsList = tempdoc.createElement("TagsList") saveDescription = tempdoc.createElement("saveDescription") templateName = tempdoc.createElement('Name') tempXML.appendChild(saveTagsList) tempXML.appendChild(saveDescription) tempXML.appendChild(templateName) taglist = unicode(tempDialog.tagsList.text()) tempDescription = unicode(tempDialog.descriptionEdit.toPlainText()) tempName = unicode(tempDialog.nameEdit.text()) saveTagsList.setAttribute("tagsList", taglist) saveDescription.setAttribute("tempDescription", tempDescription) templateName.setAttribute("name", tempName) tempdoc.appendChild(tempXML) print tempdoc.toprettyxml() activeIcons = collectIcons() progressBar = startProgressBar( _('Saving ')+unicode(os.path.basename(filename)), _('Saving ')+unicode(os.path.basename(filename)), len(redRObjects.instances(wantType = 'list'))+len(redRObjects.lines().values())+3) progress = 0 # create xml document (doc, schema, header, widgets, lines, settings, required, tabs, saveTagsList, saveDescription) = makeXMLDoc() requiredRLibraries = {} # save the widgets tempWidgets = {} for w in activeIcons: tempWidgets[w.instanceID] = w.instance() (widgets, settingsDict, requireRedRLibraries) = saveInstances(tempWidgets, widgets, doc, progressBar) #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'orngDoc makeTemplate; selected widgets: %s' % sw) temp = doc.createElement('tab') temp.setAttribute('name', 'template') ## set all of the widget icons on the tab widgetIcons = doc.createElement('widgetIcons') for wi in activeIcons: saveIcon(widgetIcons, wi, doc) temp.appendChild(widgetIcons) ## append the widgetIcons XML to the global XML tabs.appendChild(temp) ## save the global settings ## settingsDict['_globalData'] = cPickle.dumps(globalData.globalData,2) settingsDict['_requiredPackages'] = cPickle.dumps({'R': requiredRLibraries.keys(),'RedR': requireRedRLibraries},2) file = open(os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), "wt") file.write(unicode(settingsDict)) file.close() xmlText = doc.toprettyxml() progress += 1 progressBar.setValue(progress) tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") file = open(tempschema, "wt") file.write(xmlText) file.close() zout = zipfile.ZipFile(filename, "w") zout.write(tempschema,"tempSchema.tmp") zout.write(os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'),'settings.pickle') if not copy: with open(os.path.join(redREnviron.directoryNames['tempDir'], 'template.xml'), 'w') as f: f.write(tempdoc.toprettyxml()) zout.write(os.path.join(redREnviron.directoryNames['tempDir'], 'template.xml'), 'template.xml') zout.close() doc.unlink() if copy: loadTemplate(filename) progress += 1 progressBar.setValue(progress) progressBar.close() return True
def save(filename=None, template=False, copy=False, pipe=False): global _schemaName global schemaPath global notesTextWidget #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, '%s' % filename) if filename == None and not copy: filename = os.path.join(schemaPath, _schemaName) elif copy: filename = os.path.join(redREnviron.directoryNames['tempDir'], 'copy.rrts') #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'Saveing file as name %s' % filename) progressBar = startProgressBar( _('Saving ') + unicode(os.path.basename(filename)), _('Saving ') + unicode(os.path.basename(filename)), len(redRObjects.instances()) + len(redRObjects.lines()) + 3) progress = 0 # create xml document (doc, schema, header, widgets, lines, settings, required, tabs, saveTagsList, saveDescription) = makeXMLDoc() requiredRLibraries = {} #save widgets tempWidgets = redRObjects.instances( wantType='dict' ) ## all of the widget instances, these are not the widget icons (widgets, settingsDict, requireRedRLibraries) = saveInstances(tempWidgets, widgets, doc, progressBar) # save tabs and the icons and the channels if not copy or template: #tabs.setAttribute('tabNames', unicode(self.canvasTabs.keys())) for t in redRObjects.tabNames(): temp = doc.createElement('tab') temp.setAttribute('name', t) ## set all of the widget icons on the tab widgetIcons = doc.createElement('widgetIcons') for wi in redRObjects.getIconsByTab( t )[t]: ## extract only the list for this tab thus the [t] syntax saveIcon(widgetIcons, wi, doc) # tabLines = doc.createElement('tabLines') # for line in self.widgetLines(t)[t]: # saveLine(tabLines, line) temp.appendChild( widgetIcons) ## append the widgetIcons XML to the global XML #temp.appendChild(tabLines) ## append the tabLines XML to the global XML tabs.appendChild(temp) ## save the global settings ## if notesTextWidget: globalData.setGlobalData('Notes', 'globalNotes', unicode(notesTextWidget.toHtml())) settingsDict['_globalData'] = cPickle.dumps(globalData.globalData, 2) settingsDict['_requiredPackages'] = cPickle.dumps( { 'R': requiredRLibraries.keys(), 'RedR': requireRedRLibraries }, 2) #print requireRedRLibraries file = open( os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), "wt") file.write(unicode(settingsDict)) file.close() if template: taglist = unicode(tempDialog.tagsList.text()) tempDescription = unicode(tempDialog.descriptionEdit.toPlainText()) saveTagsList.setAttribute("tagsList", taglist) saveDescription.setAttribute("tempDescription", tempDescription) xmlText = doc.toprettyxml() progress += 1 progressBar.setValue(progress) if not template and not copy and not pipe: tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") tempR = os.path.join(redREnviron.directoryNames['tempDir'], "tmp.RData").replace('\\', '/') file = open(tempschema, "wt") file.write(xmlText) file.close() doc.unlink() progressBar.setLabelText('Saving Data...') progress += 1 progressBar.setValue(progress) RSession.Rcommand('save.image("' + tempR + '")') # save the R data createZipFile( filename, [], [redREnviron.directoryNames['tempDir']] ) # collect the files that are in the tempDir and save them into the zip file. elif template: tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") file = open(tempschema, "wt") file.write(xmlText) file.close() zout = zipfile.ZipFile(filename, "w") zout.write(tempschema, "tempSchema.tmp") zout.write( os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), 'settings.pickle') zout.close() doc.unlink() elif copy: tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") file = open(tempschema, "wt") file.write(xmlText) file.close() zout = zipfile.ZipFile(filename, "w") zout.write(tempschema, "tempSchema.tmp") zout.write( os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), 'settings.pickle') zout.close() doc.unlink() loadTemplate(filename) progress += 1 progressBar.setValue(progress) progressBar.close() if os.path.splitext(filename)[1].lower() == ".rrs": (schemaPath, schemaName) = os.path.split(filename) redREnviron.settings["saveSchemaDir"] = schemaPath canvasDlg.toolbarFunctions.addToRecentMenu(filename) canvasDlg.setCaption(schemaName) redRLog.log(redRLog.REDRCORE, redRLog.INFO, 'Document Saved Successfully to %s' % filename) return True
def makeTemplate(filename=None, copy=False): ## this is different from saving. We want to make a special file that only has the selected widgets, their connections, and settings. No R data or tabs are saved. if copy and len(_tempWidgets) == 0: return elif len(_tempWidgets) == 0: mb = QMessageBox( _("Save Template"), _("No widgets are selected.\nTemplates require widgets to be selected before saving as template." ), QMessageBox.Information, QMessageBox.Ok | QMessageBox.Default, QMessageBox.No | QMessageBox.Escape, QMessageBox.NoButton) mb.exec_() return if not copy: if not filename: redRLog.log( redRLog.REDRCORE, redRLog.ERROR, _('orngDoc in makeTemplate; no filename specified, this is highly irregular!! Exiting from template save.' )) return tempDialog = TemplateDialog() if tempDialog.exec_() == QDialog.Rejected: return else: filename = redREnviron.directoryNames['tempDir'] + '/copy.rrts' progressBar = startProgressBar( _('Saving ') + unicode(os.path.basename(filename)), _('Saving ') + unicode(os.path.basename(filename)), len(redRObjects.instances(wantType='list')) + len(redRObjects.lines().values()) + 3) progress = 0 # create xml document (doc, schema, header, widgets, lines, settings, required, tabs, saveTagsList, saveDescription) = makeXMLDoc() requiredRLibraries = {} # save the widgets tempWidgets = {} if copy: for w in _tempWidgets: tempWidgets[w.instanceID] = w.instance() else: for w in redRObjects.activeTab().getSelectedWidgets(): tempWidgets[w.instanceID] = w.instance() (widgets, settingsDict, requireRedRLibraries) = saveInstances(tempWidgets, widgets, doc, progressBar) # save the icons and the lines sw = redRObjects.activeTab().getSelectedWidgets() #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'orngDoc makeTemplate; selected widgets: %s' % sw) temp = doc.createElement('tab') temp.setAttribute('name', 'template') ## set all of the widget icons on the tab widgetIcons = doc.createElement('widgetIcons') for wi in sw: saveIcon(widgetIcons, wi, doc) # tabLines = doc.createElement('tabLines') # for line in redRObjects.getLinesByTab()[redRObjects.activeTabName()]: # redRLog.log(redRLog.REDRCORE, redRLog.INFO, 'orngDoc makeTemplate; checking line %s, inWidget %s, outWidget %s' % (line, line.inWidget, line.outWidget)) # if (line.inWidget not in sw) or (line.outWidget not in sw): # continue # saveLine(tabLines, line) temp.appendChild( widgetIcons) ## append the widgetIcons XML to the global XML #temp.appendChild(tabLines) ## append the tabLines XML to the global XML tabs.appendChild(temp) ## save the global settings ## settingsDict['_globalData'] = cPickle.dumps(globalData.globalData, 2) settingsDict['_requiredPackages'] = cPickle.dumps( { 'R': requiredRLibraries.keys(), 'RedR': requireRedRLibraries }, 2) #print requireRedRLibraries file = open( os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), "wt") file.write(unicode(settingsDict)) file.close() if not copy: taglist = unicode(tempDialog.tagsList.text()) tempDescription = unicode(tempDialog.descriptionEdit.toPlainText()) saveTagsList.setAttribute("tagsList", taglist) saveDescription.setAttribute("tempDescription", tempDescription) xmlText = doc.toprettyxml() progress += 1 progressBar.setValue(progress) tempschema = os.path.join(redREnviron.directoryNames['tempDir'], "tempSchema.tmp") file = open(tempschema, "wt") file.write(xmlText) file.close() zout = zipfile.ZipFile(filename, "w") zout.write(tempschema, "tempSchema.tmp") zout.write( os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'), 'settings.pickle') zout.close() doc.unlink() if copy: loadTemplate(filename) progress += 1 progressBar.setValue(progress) progressBar.close() #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, _('Template saved successfully')) return True