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 __init__(self, **kwargs): OWRpy.__init__(self, wantGUIDialog = 1, **kwargs) self.setRvariableNames(['summaryData']) """.. rrsignals::""" self.inputs.addInput('id1', _('Input Data Table'), [signals.base.TableView, signals.base.RDataFrame], self.dataset) self.data = {} # dict containing the table infromation self.dataParent = None self.showMetas = {} # key: id, value: (True/False, columnList) self.showMeta = 1 self.showAttributeLabels = 1 self.showDistributions = 1 self.distColorRgb = (220,220,220, 255) self.distColor = QColor(*self.distColorRgb) self.locale = QLocale() self.currentLinks = {} #R modifications self.currentData = None self.dataTableIndex = {} self.supressTabClick = False self.mylink = '' self.link = {} #The settings self.advancedOptions = redRGUI.base.tabWidget(self.GUIDialog, position = QTabWidget.West) #orientation = 'vertical') self.GUIDialog.layout().setAlignment(self.advancedOptions,Qt.AlignTop) diBox = self.advancedOptions.createTabPage(_("Data Information")) vbox = redRGUI.base.widgetBox(diBox) self.infoBox = redRGUI.base.groupBox(vbox, label=_("Data Information")) self.infoBox.setHidden(False) redRGUI.base.widgetLabel(self.infoBox, label = _("A summary of your data will be displayed below when data is available."), wordWrap = True) self.rowColCount = redRGUI.base.widgetLabel(self.infoBox) summaryBox = redRGUI.base.groupBox(vbox, label=_("Selected Data Summary")) self.customSummary = redRGUI.base.lineEdit(summaryBox, label = _('Custom Summary:'), toolTip = _('Place a custom summary function in here which will be added to the regular summary, use {Col} for the column number. Ex. mean({Col})')) self.summaryLabel = redRGUI.base.textEdit(summaryBox, label = _('Summary'),displayLabel=False) #saveTab = self.tabWidgeta.createTabPage('Save Data') sdBox = self.advancedOptions.createTabPage(_("Save Data")) saveTab = redRGUI.base.groupBox(sdBox,label=_('Save Data'),orientation='horizontal') #redRGUI.base.widgetLabel(saveTab, label=_("Saves the current table to a file.")) #redRGUI.base.button(saveTab, label=_("Set File"), callback = self.chooseDirectory) #self.fileName = redRGUI.base.widgetLabel(saveTab, label="") self.separator = redRGUI.base.comboBox(saveTab, label = 'Seperator:', items = [_('Comma'), _('Tab'), _('Space')], orientation = 'horizontal') save = redRGUI.base.button(saveTab, label=_("Save As File"), callback=self.writeFile, toolTip = _("Write the table to a text file.")) saveTab.layout().setAlignment(save,Qt.AlignRight) #links: linkBox = self.advancedOptions.createTabPage(_('Links to Websites'), canScroll = True) linksTab = redRGUI.base.groupBox(linkBox, _('Links to Websites')) self.linksListBox = redRGUI.base.listBox(linksTab,label=_('Links to Websites'),displayLabel=False) self.linksListBox.setSelectionMode(QAbstractItemView.ExtendedSelection) self.customLink = redRGUI.base.lineEdit(linksTab, label = _('Add Link:'), includeInReports=False) hbox = redRGUI.base.widgetBox(linksTab,orientation='horizontal') b = redRGUI.base.button(hbox, label = _('Add'), toolTip = _('Adds a link to the link section for interactive data exploration.\nThe link must have a marker for the row information in the form\n{column number}\n\nFor example:http://www.google.com/#q=%s, would do a search Google(TM) for whatever was in the cell you clicked.\nYou can test this if you want using the example.'), callback=self.addCustomLink) redRGUI.base.button(hbox, label = _('Clear Links'), toolTip = _('Clears the links from the links section'), callback = self.clearLinks) hbox.layout().setAlignment(Qt.AlignRight) redRGUI.base.widgetLabel(linksTab,label =""" Creating new links: http://www.ncbi.nlm.nih.gov/gene/{gene_id} - Here {gene_id} is a place holder and should be the column name in your table. - The value in that column and selected row will replace the place holder. """) #The table self.tableBox = redRGUI.base.widgetBox(self.controlArea) self.tableBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) #boxSettings = redRGUI.base.groupBox(self.advancedOptions, label = _("Settings")) self.table = redRGUI.base.filterTable(self.tableBox,label = _('Data Table'),displayLabel=False, sortable=True, filterable=True,selectionBehavior = QAbstractItemView.SelectItems, callback=self.itemClicked,selectionCallback=self.cellSelection) # self.table = filterTable2(self.tableBox, sortable=True, # filterable=True,selectionBehavior = QAbstractItemView.SelectItems, callback=self.itemClicked) ########################################################## # self.R('data <- data.frame(a=rnorm(1000),b=c("a","b","c","d","e"))') # self.data = 'iris' # self.table.setRTable(self.data) ########################################################## globalData.setGlobalData(self, 'links', [('http://www.google.com/search?q=%s', 'Google'), ('http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s', 'Wikipedia')]) self.setLinks()
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