示例#1
0
 def unselectAllWidgets(self):
     for k, items in redRObjects.getIconsByTab().items():
         #print k
         for item in items:
             #print item
             item.setSelected(0)
     self.scene().update()
示例#2
0
 def unselectAllWidgets(self):
     for k, items in redRObjects.getIconsByTab().items():
         #print k
         for item in items:
             #print item
             item.setSelected(0)
     self.scene().update()
    def updateLinePos(self, newPos):
        if self.startWidget == None and self.endWidget == None: return
        
        if self.startWidget != None:   func = "getDistToLeftEdgePoint"
        else:                          func = "getDistToRightEdgePoint"
        
        schema = self.canvasDlg.schema
        view = schema.activeTab()
        
        self.widget = None
        widgets = view.getItemsAtPos(newPos, CanvasWidget)
        if widgets:
            self.widget = widgets[0]
        else:
            dists = [(getattr(w, func)(newPos), w) for w in redRObjects.getIconsByTab([redRObjects.activeTabName()])[redRObjects.activeTabName()]]
            dists.sort()
            if dists and dists[0][0] < 20:
                self.widget = dists[0][1]
        
        if self.startWidget: pos = self.startWidget.getRightEdgePoint()
        else:                pos = self.endWidget.getLeftEdgePoint()

        if self.widget not in [self.startWidget, self.endWidget]: 
            if self.startWidget == None and self.widget.instance().outputs: newPos = self.widget.getRightEdgePoint()
            elif self.endWidget == None and self.widget.instance().inputs:  newPos = self.widget.getLeftEdgePoint()
        
        self.setLine(pos.x(), pos.y(), newPos.x(), newPos.y())
示例#4
0
    def updateLinePos(self, newPos):
        if self.startWidget == None and self.endWidget == None: return

        if self.startWidget != None: func = "getDistToLeftEdgePoint"
        else: func = "getDistToRightEdgePoint"

        schema = self.canvasDlg.schema
        view = schema.activeTab()

        self.widget = None
        widgets = view.getItemsAtPos(newPos, CanvasWidget)
        if widgets:
            self.widget = widgets[0]
        else:
            dists = [
                (getattr(w, func)(newPos), w)
                for w in redRObjects.getIconsByTab(
                    [redRObjects.activeTabName()])[redRObjects.activeTabName()]
            ]
            dists.sort()
            if dists and dists[0][0] < 20:
                self.widget = dists[0][1]

        if self.startWidget: pos = self.startWidget.getRightEdgePoint()
        else: pos = self.endWidget.getLeftEdgePoint()

        if self.widget not in [self.startWidget, self.endWidget]:
            if self.startWidget == None and self.widget.instance().outputs:
                newPos = self.widget.getRightEdgePoint()
            elif self.endWidget == None and self.widget.instance().inputs:
                newPos = self.widget.getLeftEdgePoint()

        self.setLine(pos.x(), pos.y(), newPos.x(), newPos.y())
示例#5
0
def minimumY():
    y = 0
    for w in redRObjects.getIconsByTab(redRObjects.activeTabName())[redRObjects.activeTabName()]:
        if w.y() > y:
            y = w.y()
    if y != 0:
        y += 30
    return y
示例#6
0
def minimumY():
    y = 0
    for w in redRObjects.getIconsByTab(
            redRObjects.activeTabName())[redRObjects.activeTabName()]:
        if w.y() > y:
            y = w.y()
    if y != 0:
        y += 30
    return y
示例#7
0
    def mousePressEvent(self, ev):
        ev.accept() # we always want to accept the event
        self.scene().update()
        self.mouseDownPosition = self.mapToScene(ev.pos())
        
        if self.widgetSelectionRect:
            self.widgetSelectionRect.hide()
            self.widgetSelectionRect = None
        #print ev.modifiers()
        if not ev.modifiers() == Qt.ControlModifier:
        #if not self.controlHeld:
            self.unselectAllWidgets()  ## should clear the selections ahead of time KRC
        # do we start drawing a connection line
        if ev.button() == Qt.LeftButton:
            widgets = [item for item in redRObjects.getIconsByTab(self.name)[self.name] if item.mouseInsideRightChannel(self.mouseDownPosition)] + [item for item in self.doc.widgets() if item.mouseInsideLeftChannel(self.mouseDownPosition)]           
            if widgets:
                self.tempWidget = widgets[0]
                #if not self.doc.signalManager.signalProcessingInProgress:   # if we are processing some signals, don't allow to add lines
                self.unselectAllWidgets()
                self.tempLine = orngCanvasItems.TempCanvasLine(self.doc.canvasDlg, self.scene())
                if self.tempWidget.getDistToLeftEdgePoint(self.mouseDownPosition) < self.tempWidget.getDistToRightEdgePoint(self.mouseDownPosition):
                    self.tempLine.setEndWidget(self.tempWidget)
                    for widget in self.doc.widgets():
                        widget.canConnect(widget, self.tempWidget)
                else:
                    self.tempLine.setStartWidget(self.tempWidget)
                    for widget in self.doc.widgets():
                        widget.canConnect(self.tempWidget, widget)
                                                        
                self.scene().update()
                self.doc.canvasDlg.widgetPopup.setEnabled(len(self.getSelectedWidgets()) == 1)
                return
            
        activeItem = self.scene().itemAt(self.mouseDownPosition)
        if not activeItem:
            self.tempWidget = None
            self.widgetSelectionRect = QGraphicsRectItem(QRectF(self.mouseDownPosition, self.mouseDownPosition), None, self.scene())
            self.widgetSelectionRect.setZValue(-100)
            self.widgetSelectionRect.show()
            self.unselectAllWidgets()
            for k, v in redRObjects.getIconsByTab().items():
                for i in v:
                    i.setPossibleConnection(False)
        # we clicked on a widget or on a line
        else:
            #redRLog.log(redRLog.REDRCORE, redRLog.DEBUG, _('Active item %s') % activeItem)
            if type(activeItem) in [orngCanvasItems.CanvasWidget]:# if we clicked on a widget          
                #print activeItem, _('An item was clicked')
                self.tempWidget = activeItem

                ## if it was a ghost widget we need to do something
                # print type(self.tempWidget)
                
                # if isinstance(self.tempWidget, orngCanvasItems.GhostWidget) and self.tempWidget.ghost:
                    # self.tempWidget.convertToCanvasWidget()
                # did we click inside the boxes to draw connections
                if ev.button() == Qt.LeftButton:
                    self.bWidgetDragging = True
                    if ev.modifiers() == Qt.ControlModifier:
                        activeItem.setSelected(not activeItem.isSelected())
                    elif activeItem.isSelected() == 0:
                        self.unselectAllWidgets()
                        activeItem.setSelected(1) # set the active widget to be selected

                    for w in self.getSelectedWidgets():
                        w.savePosition()
                        w.setAllLinesFinished(False)

                # is we clicked the right mouse button we show the popup menu for widgets
                elif ev.button() == Qt.RightButton:
                    self.unselectAllWidgets()
                    activeItem.setSelected(1)
                    self.doc.canvasDlg.widgetPopup.popup(ev.globalPos())
                else:
                    self.unselectAllWidgets()

            # if we right clicked on a line we show a popup menu
            elif type(activeItem) == orngCanvasItems.CanvasLine and ev.button() == Qt.RightButton:
                self.unselectAllWidgets()
                self.selectedLine = activeItem
                self.lineEnabledAction.setChecked(self.selectedLine.getEnabled())
                self.linePopup.popup(ev.globalPos())
            else:
                self.unselectAllWidgets()

        self.doc.canvasDlg.widgetPopup.setEnabled(len(self.getSelectedWidgets()) == 1)
        self.scene().update()
示例#8
0
 def selectAllWidgets(self):
     for k, items in redRObjects.getIconsByTab().items():
         for item in items:
             item.setSelected(1)
     self.scene().update()
示例#9
0
    def mousePressEvent(self, ev):
        self.scene().update()
        self.mouseDownPosition = self.mapToScene(ev.pos())

        if self.widgetSelectionRect:
            self.widgetSelectionRect.hide()
            self.widgetSelectionRect = None
        if not self.controlHeld:
            self.unselectAllWidgets(
            )  ## should clear the selections ahead of time KRC
        # do we start drawing a connection line
        if ev.button() == Qt.LeftButton:
            widgets = [
                item for item in self.doc.widgets()
                if item.mouseInsideRightChannel(self.mouseDownPosition)
            ] + [
                item for item in self.doc.widgets()
                if item.mouseInsideLeftChannel(self.mouseDownPosition)
            ]
            if widgets:
                self.tempWidget = widgets[0]
                if not self.doc.signalManager.signalProcessingInProgress:  # if we are processing some signals, don't allow to add lines
                    self.unselectAllWidgets()
                    self.tempLine = orngCanvasItems.TempCanvasLine(
                        self.doc.canvasDlg, self.scene())
                    if self.tempWidget.getDistToLeftEdgePoint(
                            self.mouseDownPosition
                    ) < self.tempWidget.getDistToRightEdgePoint(
                            self.mouseDownPosition):
                        self.tempLine.setEndWidget(self.tempWidget)
                        for widget in self.doc.widgets():
                            widget.canConnect(widget, self.tempWidget)
                    else:
                        self.tempLine.setStartWidget(self.tempWidget)
                        for widget in self.doc.widgets():
                            widget.canConnect(self.tempWidget, widget)

                self.scene().update()
                self.doc.canvasDlg.widgetPopup.setEnabled(
                    len(self.getSelectedWidgets()) == 1)
                return

        activeItem = self.scene().itemAt(self.mouseDownPosition)
        if not activeItem:
            self.tempWidget = None
            self.widgetSelectionRect = QGraphicsRectItem(
                QRectF(self.mouseDownPosition, self.mouseDownPosition), None,
                self.scene())
            self.widgetSelectionRect.setZValue(-100)
            self.widgetSelectionRect.show()
            self.unselectAllWidgets()
            for k, v in redRObjects.getIconsByTab().items():
                for i in v:
                    i.setPossibleConnection(False)
        # we clicked on a widget or on a line
        else:
            #redRLog.log(redRLog.REDRCORE, redRLog.DEBUG, _('Active item %s') % activeItem)
            if type(activeItem) in [orngCanvasItems.CanvasWidget
                                    ]:  # if we clicked on a widget
                #print activeItem, _('An item was clicked')
                self.tempWidget = activeItem

                ## if it was a ghost widget we need to do something
                # print type(self.tempWidget)

                # if isinstance(self.tempWidget, orngCanvasItems.GhostWidget) and self.tempWidget.ghost:
                # self.tempWidget.convertToCanvasWidget()
                # did we click inside the boxes to draw connections
                if ev.button() == Qt.LeftButton:
                    self.bWidgetDragging = True
                    if self.doc.ctrlPressed:
                        activeItem.setSelected(not activeItem.isSelected())
                    elif activeItem.isSelected() == 0:
                        self.unselectAllWidgets()
                        activeItem.setSelected(
                            1)  # set the active widget to be selected

                    for w in self.getSelectedWidgets():
                        w.savePosition()
                        w.setAllLinesFinished(False)

                # is we clicked the right mouse button we show the popup menu for widgets
                elif ev.button() == Qt.RightButton:
                    self.unselectAllWidgets()
                    activeItem.setSelected(1)
                    self.doc.canvasDlg.widgetPopup.popup(ev.globalPos())
                else:
                    self.unselectAllWidgets()

            # if we right clicked on a line we show a popup menu
            elif type(activeItem) == orngCanvasItems.CanvasLine and ev.button(
            ) == Qt.RightButton:
                self.unselectAllWidgets()
                self.selectedLine = activeItem
                self.lineEnabledAction.setChecked(
                    self.selectedLine.getEnabled())
                self.linePopup.popup(ev.globalPos())
            else:
                self.unselectAllWidgets()

        self.doc.canvasDlg.widgetPopup.setEnabled(
            len(self.getSelectedWidgets()) == 1)
        self.scene().update()
示例#10
0
 def selectAllWidgets(self):
     for k, items in redRObjects.getIconsByTab().items():
         for item in items:
             item.setSelected(1)
     self.scene().update()
示例#11
0
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
示例#12
0
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