def send(self, signalName, value):
     ## make sure that the name is actually in the outputs, if not throw an error.
     if not self.outputs.hasOutputName(signalName):
         redRLog.log(redRLog.REDRCORE, redRLog.ERROR, _("Warning! Signal '%s' is not a valid signal name for the '%s' widget. Please fix the signal name.") % (signalName, self.captionTitle))
         raise Exception(_('Signal name mismatch'))
     #print 'setting data in output'
     self.outputs.setOutputData(signalName, value) 
     self.outputs.processData(signalName)
     ## clear the warnings, info, and errors
     #print 'removing errors'
     self.removeError()
     self.removeInformation()
     self.removeWarning()
     self.refreshToolTips()
     #print 'writing ouptut'
     self.ROutput.setCursorToEnd()
     self.ROutput.append(_('\n##Data sent through the %s channel\n') % unicode(self.outputs.outputNames()[signalName])) #Keep track automatically of what R functions were performed.
     
     #print 'updating lines'
     redRObjects.updateLines()
示例#2
0
    def send(self, signalName, value):
        ## make sure that the name is actually in the outputs, if not throw an error.
        if not self.outputs.hasOutputName(signalName):
            redRLog.log(
                redRLog.REDRCORE, redRLog.ERROR,
                _("Warning! Signal '%s' is not a valid signal name for the '%s' widget. Please fix the signal name."
                  ) % (signalName, self.captionTitle))
            raise Exception(_('Signal name mismatch'))
        self.outputs.setOutputData(signalName, value)
        self.outputs.processData(signalName)
        ## clear the warnings, info, and errors
        self.removeError()
        self.removeInformation()
        self.removeWarning()
        self.refreshToolTips()
        self.ROutput.setCursorToEnd()
        self.ROutput.append(
            _('\n##Data sent through the %s channel\n') %
            unicode(self.outputs.outputNames()[signalName])
        )  #Keep track automatically of what R functions were performed.

        redRObjects.updateLines()
示例#3
0
 def connectSignal(self, signal, id, enabled = 1, process = True):
     try:
         redRLog.log(redRLog.REDRCORE, redRLog.DEBUG, _('Trying to connect signal and process.'))
         if id not in self.outputSignals.keys():
             redRLog.log(redRLog.REDRCORE, redRLog.WARNING, _('Signal Manager connectSignal: id not in output keys'))
             return False
         if not signal or signal == None:
             redRLog.log(redRLog.REDRCORE, redRLog.WARNING, _('Signal Manager connectSignal: no signal or signal is None'))
             return False
         self.outputSignals[id]['connections'][signal['id']] = {'signal':signal, 'enabled':enabled}
         # now send data through
         signal['parent'].inputs.addLink(signal['sid'], self.getSignal(id))
         redRObjects.addLine(self.parent, signal['parent'])
         if process:
             #print _('processing signal')
             self._processSingle(self.outputSignals[id], self.outputSignals[id]['connections'][signal['id']])
         return True
     except Exception as inst:
         redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
         redRLog.log(redRLog.REDRCORE, redRLog.ERROR, _('redRSignalManager connectSignal: error in connecting signal %s') % unicode(inst))
         return False
     redRLog.logConnection(self.parent.widgetInfo.fileName, signal['parent'].widgetInfo.fileName)
     redRObjects.updateLines()
示例#4
0
def loadDocument(filename, caption = None, freeze = 0, importing = 0):
    if not os.path.exists(filename):
        mb = QMessageBox(QMessageBox.Information, _("File Location Error"), 
_("""The file that you attempted to load can't be found.
This can happen if you moved the location of the file.

If you were loading a template please use the refresh registry button
(green and red arrows forming a circle) to resolve this.

If you were loading a file from the quick bar, please try loading using "Open"."""), 
                 buttons = QMessageBox.Ok | QMessageBox.Default)
        mb.exec_()
        return
    # declare globals
    global _schemaName
    global schemaPath
    global globalNotes
    global canvasDlg
    # inform user of document load
    redRLog.log(redRLog.REDRCORE, redRLog.INFO, _('Loading Document %s') % filename)
    import redREnviron
    
    ## set settings for pipeline, template, or schema
    if filename.split('.')[-1] in ['rrts']:
        tmp=True
        pipe = False
    elif filename.split('.')[-1] in ['rrs']:
        tmp=False
        pipe = False
    elif filename.split('.')[-1] in ['rrpipe']:         ## pipeline, no data but everything else there.
        pipe = True
        tmp = False
    else:
        QMessageBox.information(None, 'Red-R Error', 
        _('Cannot load file with extension %s') % unicode(filename.split('.')[-1]),  
        QMessageBox.Ok + QMessageBox.Default)
        return
    
    ## set the progress bar
    loadingProgressBar = startProgressBar(_('Loading %s') % unicode(os.path.basename(filename)),
    _('Loading %s') % unicode(filename), 2)
    
        
    # set cursor
    qApp.setOverrideCursor(Qt.WaitCursor)
    
    ## set the caption
    if os.path.splitext(filename)[1].lower() == ".rrs":
        schemaPath, _schemaName = os.path.split(filename)
        canvasDlg.setCaption(caption or _schemaName)
    if importing: # a normal load of the session
        _schemaName = ""

    loadingProgressBar.setLabelText(_('Loading Schema Data, please wait'))

    ### unzip the file ###
    
    zfile = zipfile.ZipFile( unicode(filename), "r" )
    for name in zfile.namelist():
        file(os.path.join(redREnviron.directoryNames['tempDir'],os.path.basename(name)), 'wb').write(zfile.read(name)) ## put the data into the tempdir for this session for each file that was in the temp dir for the last schema when saved.
    doc = parse(os.path.join(redREnviron.directoryNames['tempDir'],'tempSchema.tmp')) # load the doc data for the data in the temp dir.

    ## get info from the schema
    schema = doc.firstChild
    try:
        
        version = doc.getElementsByTagName("header")[0].getAttribute('version')
        if not version:
            redRLog.log(redRLog.REDRCORE, redRLog.WARNING, _('Version Tag Missing, using Red-R 1.80 loading specifications'))            ## we should move everything to the earlier versions of orngDoc for loading.
            loadDocument180(filename, caption = None, freeze = 0, importing = 0)
            loadingProgressBar.hide()
            loadingProgressBar.close()
            LOADINGINPROGRESS = False
            return
        else:
            print _('The version is:%s') % version
    except Exception as inst:
        redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
        redRLog.log(redRLog.REDRCORE, redRLog.WARNING, _('Error in loading the schema %s, reverting to load with 1.80 settings') % inst)
        loadDocument180(filename, caption = None, freeze = 0, importing = 0)
        loadingProgressBar.hide()
        loadingProgressBar.close()
        LOADINGINPROGRESS = False
        return
        
    ## extract the widgets and the tab settings
    widgets = schema.getElementsByTagName("widgets")[0]
    tabs = schema.getElementsByTagName("tabs")[0]
    
    
    #settings = schema.getElementsByTagName("settings")
    f = open(os.path.join(redREnviron.directoryNames['tempDir'],'settings.pickle'))
    settingsDict = eval(unicode(f.read()))
    f.close()
    
    
    ## load the required packages
    loadRequiredPackages(settingsDict['_requiredPackages'], loadingProgressBar = loadingProgressBar)
    
    ## make sure that there are no duplicate widgets.
    if not tmp and not pipe:
        ## need to load the r session before we can load the widgets because the signals will beed to check the classes on init.
        if not checkWidgetDuplication(widgets = widgets):
            QMessageBox.information(canvasDlg, _('Schema Loading Failed'), _('Duplicated widgets were detected between this schema and the active one.  Loading is not possible.'),  QMessageBox.Ok + QMessageBox.Default)
            LOADINGINPROGRESS = False
            return
        ## load the R session
        print 'Loading R session'
        RSession.Rcommand('load("' + os.path.join(redREnviron.directoryNames['tempDir'], "tmp.RData").replace('\\','/') +'")')
    
    
    loadingProgressBar.setLabelText(_('Loading Widgets'))
    loadingProgressBar.setMaximum(len(widgets.getElementsByTagName("widget"))+1)
    loadingProgressBar.setValue(0)
    
    """Load the widget instances.  We load widget instances for schemas and then load the tab data.  This is different for templates where the widget data is stored in the tab structure.  Because the settings are consolidated with the widgets on that level (or rather are accessible there too) we do the loading of widgets in templates with the tabs."""
    if not tmp:
        ## load the global data.
        globalData.globalData = cPickle.loads(settingsDict['_globalData'])
        if notesTextWidget and ('none' in globalData.globalData.keys()) and ('globalNotes' in globalData.globalData['none'].keys()):
            notesTextWidget.setHtml(globalData.globalData['none']['globalNotes']['data'])
    
        (loadedOkW, tempFailureTextW, settingsList) = loadWidgets(widgets = widgets, loadingProgressBar = loadingProgressBar, loadedSettingsDict = settingsDict, tmp = tmp)
    
    ## LOAD tabs
    #####  move through all of the tabs and load them.
    (loadedOkT, tempFailureTextT) = loadTabs(tabs = tabs, loadingProgressBar = loadingProgressBar, tmp = tmp, loadedSettingsDict = settingsDict)
    if not tmp:
        redRLog.log(10, 9,3,_('Setting Signals'))
        for widget in redRObjects.instances():
            redRLog.log(10, 9, 9, _('Setting Signals for %s') % widget)
            try:
                if widget.widgetID not in settingsDict.keys(): 
                    redRLog.log(redRLog.REDRCORE, redRLog.DEBUG, "widget id not in settings dict.keys(), keys are: %s" % str(settingsDict.keys()))
                    continue
                redRLog.log(redRLog.REDRCORE, redRLog.DEBUG, "setting widget outputs")
                widget.outputs.setOutputs(cPickle.loads(settingsDict[widget.widgetID]['outputs']), tmp)
            except Exception as inst:
                redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
                redRLog.log(1, 9, 1, _('Error setting signals %s, Settings are %s') % (inst, settingsDict[widget.widgetID].keys()))
    else:
        for widget in redRObjects.instances():
            if widget.tempID and widget.tempID in settingsDict.keys():
                redRLog.log(redRLog.REDRCORE, redRLog.DEBUG, "widget id not in settings dict.keys(), keys are: %s" % str(settingsDict.keys()))
                widget.outputs.setOutputs(cPickle.loads(settingsDict[widget.tempID]['outputs']), tmp)
    if pipe:        ## send none through all of the data.
        for w in redRObjects.instances():
            w.outputs.propogateNone(ask = False)
    for widget in redRObjects.instances():
        widget.tempID = None  ## we set the temp ID to none so that there won't be a conflict with other temp loading.
        
    ## some saved sessions may have widget instances that are available but that do not match to icons.  This shouldn't happen normally but if it does then we have instances that can persist without us knowing about it.  We clear those here.
    for i in redRObjects.instances():
        try:
            redRObjects.getWidgetByInstance(i)
        except:
            redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
            try:
                redRObjects.removeWidgetInstance(i)
            except: 
                redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
                pass
            
    """Clean Up"""
    qApp.restoreOverrideCursor() 
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    loadingProgressBar.hide()
    loadingProgressBar.close()
    print redRObjects._lines
    redRObjects.updateLines()
示例#5
0
def loadDocument(filename, caption=None, freeze=0, importing=0):
    global _schemaName
    global schemaPath
    global globalNotes
    redRLog.log(redRLog.REDRCORE, redRLog.INFO,
                _('Loading Document %s') % filename)
    import redREnviron
    if filename.split('.')[-1] in ['rrts']:
        tmp = True
        pipe = False
    elif filename.split('.')[-1] in ['rrs']:
        tmp = False
        pipe = False
    elif filename.split('.')[-1] in [
            'rrpipe'
    ]:  ## pipeline, no data but everything else there.
        pipe = True
        tmp = False
    else:
        QMessageBox.information(
            None, 'Red-R Error',
            _('Cannot load file with extension %s') %
            unicode(filename.split('.')[-1]),
            QMessageBox.Ok + QMessageBox.Default)
        return

    loadingProgressBar = startProgressBar(
        _('Loading %s') % unicode(os.path.basename(filename)),
        _('Loading %s') % unicode(filename), 2)

    # set cursor
    qApp.setOverrideCursor(Qt.WaitCursor)

    if os.path.splitext(filename)[1].lower() == ".rrs":
        schemaPath, _schemaName = os.path.split(filename)
        canvasDlg.setCaption(caption or _schemaName)
    if importing:  # a normal load of the session
        _schemaName = ""

    loadingProgressBar.setLabelText(_('Loading Schema Data, please wait'))

    ### unzip the file ###

    zfile = zipfile.ZipFile(unicode(filename), "r")
    for name in zfile.namelist():
        file(
            os.path.join(redREnviron.directoryNames['tempDir'],
                         os.path.basename(name)), 'wb'
        ).write(
            zfile.read(name)
        )  ## put the data into the tempdir for this session for each file that was in the temp dir for the last schema when saved.
    doc = parse(
        os.path.join(redREnviron.directoryNames['tempDir'], 'tempSchema.tmp')
    )  # load the doc data for the data in the temp dir.

    ## get info from the schema
    schema = doc.firstChild
    try:

        version = schema.getElementsByTagName("header")[0].getAttribute(
            'version')
        if not version:
            redRLog.log(
                redRLog.REDRCORE, redRLog.WARNING,
                _('Version Tag Missing, using Red-R 1.80 loading specifications'
                  )
            )  ## we should move everything to the earlier versions of orngDoc for loading.
            loadDocument180(filename, caption=None, freeze=0, importing=0)
            loadingProgressBar.hide()
            loadingProgressBar.close()
            return
        else:
            print _('The version is:%s') % version
    except Exception as inst:
        redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
        redRLog.log(
            redRLog.REDRCORE, redRLog.WARNING,
            _('Error in loading the schema %s, reverting to load with 1.80 settings'
              ) % inst)
        loadDocument180(filename, caption=None, freeze=0, importing=0)
        loadingProgressBar.hide()
        loadingProgressBar.close()
        return
    widgets = schema.getElementsByTagName("widgets")[0]
    tabs = schema.getElementsByTagName("tabs")[0]
    #settings = schema.getElementsByTagName("settings")
    f = open(
        os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'))
    settingsDict = eval(unicode(f.read()))
    f.close()

    ## load the required packages
    loadRequiredPackages(settingsDict['_requiredPackages'],
                         loadingProgressBar=loadingProgressBar)

    ## make sure that there are no duplicate widgets.
    if not tmp and not pipe:
        ## need to load the r session before we can load the widgets because the signals will beed to check the classes on init.
        if not checkWidgetDuplication(widgets=widgets):
            QMessageBox.information(
                canvasDlg, _('Schema Loading Failed'),
                _('Duplicated widgets were detected between this schema and the active one.  Loading is not possible.'
                  ), QMessageBox.Ok + QMessageBox.Default)

            return
        RSession.Rcommand('load("' +
                          os.path.join(redREnviron.directoryNames['tempDir'],
                                       "tmp.RData").replace('\\', '/') + '")')

    loadingProgressBar.setLabelText(_('Loading Widgets'))
    loadingProgressBar.setMaximum(
        len(widgets.getElementsByTagName("widget")) + 1)
    loadingProgressBar.setValue(0)
    if not tmp:
        globalData.globalData = cPickle.loads(settingsDict['_globalData'])
        if notesTextWidget and ('none' in globalData.globalData.keys()) and (
                'globalNotes' in globalData.globalData['none'].keys()):
            notesTextWidget.setHtml(
                globalData.globalData['none']['globalNotes']['data'])
        (loadedOkW,
         tempFailureTextW) = loadWidgets(widgets=widgets,
                                         loadingProgressBar=loadingProgressBar,
                                         loadedSettingsDict=settingsDict,
                                         tmp=tmp)

    ## LOAD tabs
    #####  move through all of the tabs and load them.
    (loadedOkT,
     tempFailureTextT) = loadTabs(tabs=tabs,
                                  loadingProgressBar=loadingProgressBar,
                                  tmp=tmp,
                                  loadedSettingsDict=settingsDict)
    if not tmp:
        redRLog.log(10, 9, 3, _('Setting Signals'))
        for widget in redRObjects.instances():
            redRLog.log(10, 9, 9, _('Setting Signals for %s') % widget)
            try:
                if widget.widgetID not in settingsDict.keys(): continue
                widget.outputs.setOutputs(
                    cPickle.loads(
                        settingsDict[widget.widgetID]['connections']), tmp)
            except Exception as inst:
                redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                            redRLog.formatException())
                redRLog.log(
                    1, 9, 1,
                    _('Error setting signals %s, Settings are %s') %
                    (inst, settingsDict[widget.widgetID].keys()))
    else:
        for widget in redRObjects.instances():
            if widget.tempID and widget.tempID in settingsDict.keys():
                widget.outputs.setOutputs(
                    cPickle.loads(settingsDict[widget.tempID]['connections']),
                    tmp)
    if pipe:  ## send none through all of the data.
        for w in redRObjects.instances():
            w.outputs.propogateNone(ask=False)
    for widget in redRObjects.instances():
        widget.tempID = None  ## we set the temp ID to none so that there won't be a conflict with other temp loading.

    ## some saved sessions may have widget instances that are available but that do not match to icons.  This shouldn't happen normally but if it does then we have instances that can persist without us knowing about it.  We clear those here.
    for i in redRObjects.instances():
        try:
            redRObjects.getWidgetByInstance(i)
        except:
            redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                        redRLog.formatException())
            try:
                redRObjects.removeWidgetInstance(i)
            except:
                redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                            redRLog.formatException())
                pass
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    loadingProgressBar.hide()
    loadingProgressBar.close()
    redRObjects.updateLines()