def mouseReleaseEvent(self, ev): point = self.mapToScene(ev.pos()) if self.widgetSelectionRect: self.widgetSelectionRect.hide() self.scene().removeItem(self.widgetSelectionRect) self.widgetSelectionRect = None # if we are moving a widget if self.bWidgetDragging: validPos = True for item in self.getSelectedWidgets(): items = self.scene().collidingItems(item) validPos = validPos and (self.findItemTypeCount( items, orngCanvasItems.CanvasWidget) == 0) for item in self.getSelectedWidgets(): if not validPos: item.restorePosition() item.updateTooltip() item.setAllLinesFinished(True) orngHistory.logChangeWidgetPosition( self.doc.schemaID, id(item), (item.widgetInfo.category, item.widgetInfo.name), item.x(), item.y()) # if we are drawing line elif self.tempLine: # show again the empty input/output boxes for widget in self.doc.widgets: widget.resetLeftRightEdges() start = self.tempLine.startWidget or self.tempLine.widget end = self.tempLine.endWidget or self.tempLine.widget self.tempLine.remove() self.tempLine = None # we must check if we have really connected some output to input if start and end and start != end: self.doc.addLine(start, end) else: state = [ self.doc.widgets[i].widgetInfo.name for i in range(min(len(self.doc.widgets), 5)) ] predictedWidgets = orngHistory.predictWidgets(state, 20) if start: orngTabs.categoriesPopup.updatePredictedWidgets( predictedWidgets, 'inputClasses', start.widgetInfo.outputClasses) orngTabs.categoriesPopup.updateWidgetsByInputs( start.widgetInfo) else: orngTabs.categoriesPopup.updatePredictedWidgets( predictedWidgets, 'outputClasses', end.widgetInfo.inputClasses) orngTabs.categoriesPopup.updateWidgesByOutputs( end.widgetInfo) newCoords = QPoint(ev.globalPos()) orngTabs.categoriesPopup.updateMenu() action = orngTabs.categoriesPopup.exec_( newCoords - QPoint(0, orngTabs.categoriesPopup.categoriesYOffset)) if action and hasattr(action, "widgetInfo"): xOff = -48 * bool(end) newWidget = self.doc.addWidget(action.widgetInfo, point.x() + xOff, point.y() - 24) if newWidget != None: self.doc.addLine(start or newWidget, end or newWidget) elif ev.button() == Qt.RightButton: activeItem = self.scene().itemAt(point) diff = self.mouseDownPosition - point if not activeItem and ( diff.x()**2 + diff.y()**2 ) < 25: # if no active widgets and we pressed and released mouse at approx same position newCoords = QPoint(ev.globalPos()) orngTabs.categoriesPopup.showAllWidgets() state = [ self.doc.widgets[i].widgetInfo.name for i in range(min(len(self.doc.widgets), 5)) ] predictedWidgets = orngHistory.predictWidgets(state, 20) orngTabs.categoriesPopup.updatePredictedWidgets( predictedWidgets, 'inputClasses') orngTabs.categoriesPopup.updateMenu() height = sum([ orngTabs.categoriesPopup.actionGeometry(action).height() for action in orngTabs.categoriesPopup.actions() ]) action = orngTabs.categoriesPopup.exec_( newCoords - QPoint(0, orngTabs.categoriesPopup.categoriesYOffset)) if action and hasattr(action, "widgetInfo"): newWidget = self.doc.addWidget(action.widgetInfo, point.x(), point.y()) self.scene().update() self.bWidgetDragging = False return QGraphicsView.mouseReleaseEvent(self, ev)
def mouseReleaseEvent(self, ev): point = self.mapToScene(ev.pos()) if self.widgetSelectionRect: self.widgetSelectionRect.hide() self.scene().removeItem(self.widgetSelectionRect) self.widgetSelectionRect = None # if we are moving a widget if self.bWidgetDragging: validPos = True for item in self.getSelectedWidgets(): items = self.scene().collidingItems(item) validPos = validPos and (self.findItemTypeCount(items, orngCanvasItems.CanvasWidget) == 0) for item in self.getSelectedWidgets(): if not validPos: item.restorePosition() item.updateTooltip() item.setAllLinesFinished(True) orngHistory.logChangeWidgetPosition(self.doc.schemaID, id(item), (item.widgetInfo.category, item.widgetInfo.name), item.x(), item.y()) # if we are drawing line elif self.tempLine: # show again the empty input/output boxes for widget in self.doc.widgets: widget.resetLeftRightEdges() start = self.tempLine.startWidget or self.tempLine.widget end = self.tempLine.endWidget or self.tempLine.widget # self.tempLine.hide() self.tempLine.remove() self.tempLine = None # we must check if we have really connected some output to input if start and end and start != end: if self.doc.signalManager.signalProcessingInProgress: # TODO: Remove this check when signal manager handles out of sync signals QMessageBox.information( self, "Orange Canvas", "Unable to connect widgets while signal processing is in progress. Please wait.") else: self.doc.addLine(start, end) else: state = [self.doc.widgets[i].widgetInfo.name for i in range(min(len(self.doc.widgets), 5))] predictedWidgets = orngHistory.predictWidgets(state, 20) if start: orngTabs.categoriesPopup.updatePredictedWidgets(predictedWidgets, 'inputClasses', start.widgetInfo.outputClasses) orngTabs.categoriesPopup.updateWidgetsByInputs(start.widgetInfo) else: orngTabs.categoriesPopup.updatePredictedWidgets(predictedWidgets, 'outputClasses', end.widgetInfo.inputClasses) orngTabs.categoriesPopup.updateWidgesByOutputs(end.widgetInfo) newCoords = QPoint(ev.globalPos()) orngTabs.categoriesPopup.updateMenu() action = orngTabs.categoriesPopup.exec_(newCoords- QPoint(0, orngTabs.categoriesPopup.categoriesYOffset)) if action and hasattr(action, "widgetInfo"): xOff = -48 * bool(end) newWidget = self.doc.addWidget(action.widgetInfo, point.x()+xOff, point.y()-24) if newWidget != None: if self.doc.signalManager.signalProcessingInProgress: QMessageBox.information( self, "Orange Canvas", "Unable to connect widgets while signal processing is in progress. Please wait.") else: self.doc.addLine(start or newWidget, end or newWidget) elif ev.button() == Qt.RightButton: activeItem = self.scene().itemAt(point) diff = self.mouseDownPosition - point if not activeItem and (diff.x()**2 + diff.y()**2) < 25: # if no active widgets and we pressed and released mouse at approx same position newCoords = QPoint(ev.globalPos()) orngTabs.categoriesPopup.showAllWidgets() state = [self.doc.widgets[i].widgetInfo.name for i in range(min(len(self.doc.widgets), 5))] predictedWidgets = orngHistory.predictWidgets(state, 20) orngTabs.categoriesPopup.updatePredictedWidgets(predictedWidgets, 'inputClasses') orngTabs.categoriesPopup.updateMenu() height = sum([orngTabs.categoriesPopup.actionGeometry(action).height() for action in orngTabs.categoriesPopup.actions()]) action = orngTabs.categoriesPopup.exec_(newCoords - QPoint(0, orngTabs.categoriesPopup.categoriesYOffset)) if action and hasattr(action, "widgetInfo"): newWidget = self.doc.addWidget(action.widgetInfo, point.x(), point.y()) self.scene().update() self.bWidgetDragging = False # self.doc.canvasDlg.widgetPopup.setEnabled(len(self.getSelectedWidgets()) == 1) return QGraphicsView.mouseReleaseEvent(self, ev)