def __init__(self, renderController, parent=None): super(RenderParameterWidget, self).__init__(parent=parent) self.renderController = renderController self.renderController.visualizationChanged.connect(self.visualizationLoaded) self.paramWidget = None self.visTypeComboBox = QComboBox() for visualizationType in self.renderController.visualizationTypes: self.visTypeComboBox.addItem(visualizationType) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setSpacing(10) layout.setContentsMargins(10, 0, 10, 0) if len(self.renderController.visualizationTypes) > 1: layout.addWidget(QLabel("Visualization type:"), 0, 0) layout.addWidget(self.visTypeComboBox, 0, 1) self.setLayout(layout) self.scrollArea = QScrollArea() self.scrollArea.setFrameShape(QFrame.NoFrame) self.scrollArea.setAutoFillBackground(False) self.scrollArea.setAttribute(Qt.WA_TranslucentBackground) self.scrollArea.setWidgetResizable(True) self.visTypeComboBox.currentIndexChanged.connect(self.visTypeComboBoxChanged)
def __init__(self): super(PointsWidget, self).__init__() self.landmarkWidgets = [] self.activeIndex = 0 self.scrollArea = QScrollArea(self) self.scrollArea.setFrameShape(QFrame.NoFrame) self.scrollArea.setAutoFillBackground(False) self.scrollArea.setAttribute(Qt.WA_TranslucentBackground) self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollArea.setWidgetResizable(True) landmarkLocationsLayout = QGridLayout() landmarkLocationsLayout.setSpacing(0) landmarkLocationsLayout.setContentsMargins(0, 0, 0, 0) landmarkLocationsLayout.setAlignment(Qt.AlignTop) self.landmarkLocationsWidget = QWidget() Style.styleWidgetForTab(self.landmarkLocationsWidget) self.landmarkLocationsWidget.setLayout(landmarkLocationsLayout) self.scrollArea.setWidget(self.landmarkLocationsWidget) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.scrollArea) self.setLayout(layout)
def getParameterWidget(self): matrixLayout = QGridLayout() matrixLayout.setAlignment(Qt.AlignTop) matrixLayout.setContentsMargins(0, 0, 0, 0) matrixLayout.setSpacing(5) matrixLayout.addWidget(QLabel("Transformation matrix:"), 0, 0, 1, 4) self.m1Edits = [QLineEdit() for _ in range(4)] self.m2Edits = [QLineEdit() for _ in range(4)] self.m3Edits = [QLineEdit() for _ in range(4)] self.m4Edits = [QLineEdit() for _ in range(4)] self.initLineEdits(self.m1Edits, matrixLayout, 1, 0) self.initLineEdits(self.m2Edits, matrixLayout, 2, 0) self.initLineEdits(self.m3Edits, matrixLayout, 3, 0) self.initLineEdits(self.m4Edits, matrixLayout, 4, 0) expandingWidget = QWidget() expandingWidget.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) matrixLayout.addWidget(expandingWidget, 5, 0, 1, 4) matrixWidget = QWidget() matrixWidget.setLayout(matrixLayout) self.transformUpdated( self.renderWidget.transformations.completeTransform()) return matrixWidget
def __init__(self): super(TwoStepLandmarkWidget, self).__init__() self.textFrame = QTextEdit("<p>Place your mouse over the desired " "landmark point. Press 'Space' to shoot a ray through the volume. " "Move the volume around and move the mouse to move the locator. " "Press 'Space' again to define the final place of the landmark.</p>" "<p>You can also use the ray profile to define the landmark's location.</p>") self.textFrame.setReadOnly(True) self.textFrame.setFrameShape(QFrame.NoFrame) self.textFrame.setAutoFillBackground(False) self.textFrame.setAttribute(Qt.WA_TranslucentBackground) self.textFrame.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.textFrame.setStyleSheet("background: #aaa") self.histogramWidget = TrackingHistogramWidget() self.histogramWidget.setMinimumHeight(100) self.histogramWidget.setVisible(False) self.button = QPushButton("Pick current landmark position") self.button.clicked.connect(self.applyButtonClicked) self.button.setVisible(False) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.textFrame) layout.addWidget(self.histogramWidget) layout.addWidget(self.button) self.setLayout(layout)
def initUI(self): title = QLabel('Title') author = QLabel('Author') review = QLabel('Review') titleEdit = QLineEdit() authorEdit = QLineEdit() reviewEdit = QTextEdit() btnOk = QtGui.QPushButton('OK') btnCancel = QtGui.QPushButton('Cancel') btnCancel.clicked.connect(self.close) hbox = QtGui.QHBoxLayout() hbox.addStretch(1) hbox.addWidget(btnOk) hbox.addWidget(btnCancel) grid = QGridLayout() grid.setSpacing(10) grid.addWidget(title, 1, 0) grid.addWidget(titleEdit, 1, 1) grid.addWidget(author, 2, 0) grid.addWidget(authorEdit, 2, 1) grid.addWidget(review, 3, 0) grid.addWidget(reviewEdit, 3, 1, 5, 1) grid.addLayout(hbox, 8, 1) self.setLayout(grid) self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Review') self.setWindowIcon(QtGui.QIcon('kpdf.png')) self.show()
def __init__(self): super(TransferFunctionWidget, self).__init__() self.nodes = [] self.lines = [] self.histogram = Histogram() self.histogram.enabled = False # Create a histogram widget for the background of the transfer function editor self.histogramWidget = HistogramWidget() self.histogramWidget.setHistogram(self.histogram) self.histogramWidget.setAxeMode(bottom=HistogramWidget.AxeClear, left=HistogramWidget.AxeLog) self.histogramWidget.update() self.histogramWidget._histogramItem.delegate = self Style.styleWidgetForTab(self.histogramWidget) # Invisible item that catches mouse events on top of the histogram self.transferfunctionItem = TransferFunctionItem() self.transferfunctionItem.setZValue(250) self.transferfunctionItem.delegate = self self.histogramWidget.addItem(self.transferfunctionItem) # Create a widget for editing the selected node of the transfer function self.nodeItemWidget = NodeItemWidget() self.nodeItemWidget.setEnabled(False) self.nodeItemWidget.nodeUpdated.connect(self.updateNode) self.nodeItemWidget.removePoint.connect(self.removePoint) layout = QGridLayout() layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.histogramWidget, 0, 0) layout.addWidget(self.nodeItemWidget, 1, 0) self.setLayout(layout)
def __init__(self): super(TwoStepLandmarkWidget, self).__init__() self.textFrame = QTextEdit( "<p>Place your mouse over the desired " "landmark point. Press 'Space' to shoot a ray through the volume. " "Move the volume around and move the mouse to move the locator. " "Press 'Space' again to define the final place of the landmark.</p>" "<p>You can also use the ray profile to define the landmark's location.</p>" ) self.textFrame.setReadOnly(True) self.textFrame.setFrameShape(QFrame.NoFrame) self.textFrame.setAutoFillBackground(False) self.textFrame.setAttribute(Qt.WA_TranslucentBackground) self.textFrame.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.textFrame.setStyleSheet("background: #aaa") self.histogramWidget = TrackingHistogramWidget() self.histogramWidget.setMinimumHeight(100) self.histogramWidget.setVisible(False) self.button = QPushButton("Pick current landmark position") self.button.clicked.connect(self.applyButtonClicked) self.button.setVisible(False) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.textFrame) layout.addWidget(self.histogramWidget) layout.addWidget(self.button) self.setLayout(layout)
def __init__(self, *args, **kwargs ): self.uiInfoPath = Window.infoBaseDir + '/Widget_ctlListGroup.json' QWidget.__init__( self, *args, **kwargs ) mainLayout = QVBoxLayout( self ) buttonLayout = QHBoxLayout() gridLayout = QGridLayout() mainLayout.addLayout( buttonLayout ) mainLayout.addLayout( gridLayout ) gridLayout.setSpacing(5) gridLayout.setVerticalSpacing(5) b_addList = QPushButton( "Add List" ) b_removeList = QPushButton( "Remove List" ) buttonLayout.addWidget( b_addList ) buttonLayout.addWidget( b_removeList ) w_ctlList = Widget_ctlList() gridLayout.addWidget( w_ctlList ) self.__gridLayout = gridLayout QtCore.QObject.connect( b_addList, QtCore.SIGNAL( "clicked()" ), self.addList ) QtCore.QObject.connect( b_removeList, QtCore.SIGNAL( "clicked()" ), self.removeList ) self.loadInfo()
def __init__(self, width, height, grid): super(GameOfLifeWidget, self).__init__() self.setWindowTitle('Game Of Life') layout = QGridLayout() layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) main_layout = QVBoxLayout() self.buttons = [] self.grid = grid self.width = width self.height = height self.timer = QTimer() self.timer.setInterval(INTERVAL) self.timer.timeout.connect(self._handle_timeout) self.start_button = QPushButton("Start") self.start_button.clicked.connect(self._handle_start) self.clear_button = QPushButton("Clear") self.clear_button.clicked.connect(self._handle_clear) main_layout.addLayout(layout) main_layout.addWidget(self.start_button) main_layout.addWidget(self.clear_button) self.setLayout(main_layout) for y_pos in range(height): row = [] self.buttons.append(row) for x_pos in range(width): button = QPushButton() row.append(button) button.setMaximumWidth(20) button.setMaximumHeight(20) button.clicked.connect(self._handle_click) layout.addWidget(button, y_pos, x_pos) self._update_gui()
def __init__(self): super(RenderWidget, self).__init__() # Default volume renderer self.renderer = vtkRenderer() self.renderer.SetBackground2(0.4, 0.4, 0.4) self.renderer.SetBackground(0.1, 0.1, 0.1) self.renderer.SetGradientBackground(True) self.renderer.SetLayer(0) # Overlay renderer which is synced with the default renderer self.rendererOverlay = vtkRenderer() self.rendererOverlay.SetLayer(1) self.rendererOverlay.SetInteractive(0) self.renderer.GetActiveCamera().AddObserver("ModifiedEvent", self._syncCameras) self.rwi = QVTKRenderWindowInteractor(parent=self) self.rwi.SetInteractorStyle(vtkInteractorStyleTrackballCamera()) self.rwi.GetRenderWindow().AddRenderer(self.renderer) self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay) self.rwi.GetRenderWindow().SetNumberOfLayers(2) self.rwi.SetDesiredUpdateRate(0) self.imagePlaneWidgets = [vtkImagePlaneWidget() for i in range(3)] for index in range(3): self.imagePlaneWidgets[index].DisplayTextOn() self.imagePlaneWidgets[index].SetInteractor(self.rwi) # Disable the margin for free rotation self.imagePlaneWidgets[index].SetMarginSizeX(0.0) self.imagePlaneWidgets[index].SetMarginSizeY(0.0) self.mapper = vtkOpenGLGPUVolumeRayCastMapper() self.mapper.SetAutoAdjustSampleDistances(1) self.volume = None self.imageData = None self.VolumeVisualization = None self.shouldResetCamera = False self.gridItems = [] self.orientationGridItems = [] self.clippingBox = ClippingBox() self.clippingBox.setWidget(self) # Keep track of the base and user transforms self.baseTransform = vtkTransform() self.userTransform = vtkTransform() self.setMinimumWidth(340) self.setMinimumHeight(340) layout = QGridLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.rwi, 0, 0) self.setLayout(layout)
def __CreateGrid(self): g1 = QGridLayout() self.centralWidget().setLayout(g1) g1.setSpacing(5) bold = QFont() bold.setBold(True) self.__AddGridLabel(g1, 'Source Directory:', QFont(), 0, 0, -1) self.__AddGridLabel(g1, 'Archive Directory:', QFont(), 1, 0, -1) self.__AddGridLabel(g1, 'Target Directory:', QFont(), 2, 0, -1) self.__AddGridLabel(g1, 'Max Number of Videos:', QFont(), 3, 0, -1) self.__AddGridLabel(g1, 'Video File Types:', QFont(), 3, 2, -1) #self.__AddGridLabel(g1, 'Max Run Time in Hours:', QFont(), 4, 2, -1) g1.addWidget(self.qleSourceDir, 0, 1, 1, 3) g1.addWidget(self.qleArchiveDir, 1, 1, 1, 3) g1.addWidget(self.qleDestinationDir, 2, 1, 1, 3) g1.addWidget(self.qleMaxVidsCap, 3, 1) g1.addWidget(self.qleVideoTypes, 3, 3) #g1.addWidget(self.qleRunTimeMax, 4, 3) g1.addWidget(self.qpbRun, 10, 3, alignment = -1) g1.addWidget(QLabel('', self), 4, 0,) # Empty Column As Separator g1.addWidget(QLabel('', self), 5, 0,) # Empty Column As Separator self.__AddGridLabel(g1, 'Videos Completed:', bold, 5, 0, -1) self.__AddGridLabel(g1, 'Start Time:', bold, 5, 2, -1) self.__AddGridLabel(g1, 'Videos In Progress:', bold, 6, 0, -1) self.__AddGridLabel(g1, 'Time Remaining:', bold, 7, 2, -1) self.__AddGridLabel(g1, 'Target Space Left:', bold, 7, 0, -1) self.__AddGridLabel(g1, 'Archive Space Left:', bold, 8, 0, -1) self.__AddGridLabel(g1, 'End Time:', bold, 6, 2, -1) self.__AddGridLabel(g1, 'Processing Speed:', bold, 8, 2, -1) g1.addWidget(self.qlVidsDone, 5, 1,) g1.addWidget(self.qlVidsInProgress, 6, 1) g1.addWidget(self.qlStartTime, 5, 3,) g1.addWidget(self.qlEndTime, 6, 3,) g1.addWidget(self.qlTimeLeft, 7, 3,) g1.addWidget(self.qlDestinationSpace, 7, 1,) g1.addWidget(self.qlArcSpace, 8, 1,) g1.addWidget(self.qlProcessingSpeed, 8, 3,) g1.addWidget(self.qpbSourceDir, 0, 4,) g1.addWidget(self.qpbArchiveDir, 1, 4,) g1.addWidget(self.qpbTargetDir, 2, 4,) self.show
def getParameterWidget(self): titleLabel = QLabel(self.transformation.name) paramWidget = ParameterWidget() paramWidget.parameterModel.setTransformation(self.transformation) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.setAlignment(Qt.AlignTop) layout.addWidget(titleLabel) layout.addWidget(paramWidget) widget = QWidget() widget.setLayout(layout) return widget
def __init__(self): super(SliceViewerWidget, self).__init__() self.color = [1, 1, 1] self.renderer = vtkRenderer() self.renderer.SetBackground(0.0, 0.0, 0.0) self.renderer.SetLayer(0) # Overlay renderer which is synced with the default renderer self.rendererOverlay = vtkRenderer() self.rendererOverlay.SetLayer(1) self.rendererOverlay.SetInteractive(0) self.renderer.GetActiveCamera().AddObserver("ModifiedEvent", self._syncCameras) self.rwi = QVTKRenderWindowInteractor(parent=self) self.rwi.SetInteractorStyle(vtkInteractorStyleUser()) self.rwi.GetRenderWindow().AddRenderer(self.renderer) self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay) self.rwi.GetRenderWindow().SetNumberOfLayers(2) # Set camera to parallel camera = self.renderer.GetActiveCamera() camera.SetParallelProjection(1) # Add new observers for mouse wheel self.AddObserver(self.rwi, "CharEvent", self.charTyped) self.AddObserver(self.rwi, "MouseWheelBackwardEvent", self.mouseWheelChanged) self.AddObserver(self.rwi, "MouseWheelForwardEvent", self.mouseWheelChanged) self.AddObserver(self.rwi, "MouseMoveEvent", self.mouseMovedEvent, 1) self.picker = vtkCellPicker() self.picker.SetTolerance(1e-6) self.locator = [] self.setStyleSheet("background-color: #333") layout = QGridLayout() layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.rwi) self.setLayout(layout)
def __init__(self): super(SliceViewerWidget, self).__init__() self.color = [1, 1, 1] self.renderer = vtkRenderer() self.renderer.SetBackground2(0.4, 0.4, 0.4) self.renderer.SetBackground(0.1, 0.1, 0.1) self.renderer.SetGradientBackground(True) self.renderer.SetLayer(0) # Overlay renderer which is synced with the default renderer self.rendererOverlay = vtkRenderer() self.rendererOverlay.SetLayer(1) self.rendererOverlay.SetInteractive(0) self.renderer.GetActiveCamera().AddObserver("ModifiedEvent", self._syncCameras) self.rwi = QVTKRenderWindowInteractor(parent=self) self.rwi.SetInteractorStyle(vtkInteractorStyleUser()) self.rwi.GetRenderWindow().AddRenderer(self.renderer) self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay) self.rwi.GetRenderWindow().SetNumberOfLayers(2) # Set camera to parallel camera = self.renderer.GetActiveCamera() camera.SetParallelProjection(1) # Add new observers for mouse wheel self.AddObserver(self.rwi, "CharEvent", self.charTyped) self.AddObserver(self.rwi, "MouseWheelBackwardEvent", self.mouseWheelChanged) self.AddObserver(self.rwi, "MouseWheelForwardEvent", self.mouseWheelChanged) self.AddObserver(self.rwi, "MouseMoveEvent", self.mouseMovedEvent, 1) self.picker = vtkCellPicker() self.picker.SetTolerance(1e-6) # Known state of mouse (maybe can ask the event as well...) self.leftButtonPressed = False self.locator = [] layout = QGridLayout() layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.rwi) self.setLayout(layout)
def __init__(self): super(ColorWidget, self).__init__() self.label = QLabel() self.color = [1.0, 1.0, 1.0] buttonLayout = QHBoxLayout() buttonLayout.setContentsMargins(8, 0, 0, 0) self.buttonWidget = QWidget() self.buttonWidget.setLayout(buttonLayout) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(self.label, 0, 0) layout.addWidget(self.buttonWidget, 0, 1) self.setLayout(layout)
def __init__(self): super(SliceCompareViewerWidget, self).__init__() self.renderer = vtkRenderer() self.renderer.SetBackground(0.0, 0.0, 0.0) self.renderer.SetLayer(0) # Overlay renderer which is synced with the default renderer self.rendererOverlay = vtkRenderer() self.rendererOverlay.SetLayer(1) self.rendererOverlay.SetInteractive(0) self.renderer.GetActiveCamera().AddObserver("ModifiedEvent", self._syncCameras) self.rwi = QVTKRenderWindowInteractor(parent=self) self.rwi.SetInteractorStyle(vtkInteractorStyleUser()) self.rwi.GetRenderWindow().AddRenderer(self.renderer) self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay) self.rwi.GetRenderWindow().SetNumberOfLayers(2) # Set camera to parallel camera = self.renderer.GetActiveCamera() camera.SetParallelProjection(1) # Add new observers for mouse wheel self.AddObserver(self.rwi, "CharEvent", self.charTyped) self.AddObserver(self.rwi, "MouseWheelBackwardEvent", self.mouseWheelChanged) self.AddObserver(self.rwi, "MouseWheelForwardEvent", self.mouseWheelChanged) self.AddObserver(self.rwi, "MouseMoveEvent", self.mouseMovedEvent, 1) self.picker = vtkCellPicker() self.picker.SetTolerance(1e-6) self.locator = [] self.setStyleSheet("background-color: #333") layout = QGridLayout() layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.rwi) self.setLayout(layout)
def __init__(self): super(SurfaceLandmarkWidget, self).__init__() self.textFrame = QTextEdit("<p>Hold your mouse over the volume " "to move the locator. To create a landmark, press 'Space'.</p>" "<p>When you want to proceed to the following landmark, " "click the 'Done' button behind the landmark pair in the " "center of the window.</p>") self.textFrame.setReadOnly(True) self.textFrame.setFrameShape(QFrame.NoFrame) self.textFrame.setAutoFillBackground(False) self.textFrame.setAttribute(Qt.WA_TranslucentBackground) self.textFrame.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.textFrame.setStyleSheet("background: #aaa") layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.textFrame) self.setLayout(layout)
def __init__(self): super(RenderWidget, self).__init__() self.renderer = vtkRenderer() self.renderer.SetBackground2(0.4, 0.4, 0.4) self.renderer.SetBackground(0.1, 0.1, 0.1) self.renderer.SetGradientBackground(True) self.rwi = QVTKRenderWindowInteractor(parent=self) self.rwi.SetInteractorStyle(vtkInteractorStyleTrackballCamera()) self.rwi.GetRenderWindow().AddRenderer(self.renderer) # -964.384 cloth # -656.56 skin # 20.144 Muscle # 137.168 Vascular stuff # 233.84 (Brittle) Bones # 394.112 Bones # What is the value for steel/implants? self.sections = [ -3000.0, -964.384, -656.56, 20.144, 137.168, 233.84, 394.112, 6000.0 ] self.sectionsOpacity = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] # sectionColors should be specified for each boundary # Just like opacity should be tweaked. A section can have any slope / configuration self.sectionColors = [ (1.0, 1.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 0.7, 0.6), (1.0, 0.2, 0.2), (1.0, 0.9, 0.7), (0.9, 1.0, 0.9) ] self.renderType = None self.imageData = None layout = QGridLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.rwi, 0, 0) self.setLayout(layout)
def __init__(self, parent=None): QWidget.__init__(self, parent) # Widgets, layouts and signals self._group = QButtonGroup() layout = QGridLayout() layout.setSpacing(0) for i in range(18): layout.setColumnMinimumWidth(i, 40) layout.setColumnStretch(i, 0) for i in list(range(7)) + [8, 9]: layout.setRowMinimumHeight(i, 40) layout.setRowStretch(i, 0) ## Element for z, position in _ELEMENT_POSITIONS.items(): widget = ElementPushButton(z) widget.setCheckable(True) layout.addWidget(widget, *position) self._group.addButton(widget, z) ## Labels layout.addWidget(QLabel(''), 7, 0) # Dummy layout.addWidget(QLabel('*'), 5, 2, Qt.AlignCenter) layout.addWidget(QLabel('*'), 8, 2, Qt.AlignCenter) layout.addWidget(QLabel('**'), 6, 2, Qt.AlignCenter) layout.addWidget(QLabel('**'), 9, 2, Qt.AlignCenter) for row in [0, 1, 2, 3, 4, 5, 6, 8, 9]: layout.setRowStretch(row, 1) self.setLayout(layout) # Signals self._group.buttonClicked.connect(self.selectionChanged) # Default self.setColorFunction(_category_color_function)
def __init__(self): super(SurfaceLandmarkWidget, self).__init__() self.textFrame = QTextEdit( "<p>Hold your mouse over the volume " "to move the locator. To create a landmark, press 'Space'.</p>" "<p>When you want to proceed to the following landmark, " "click the 'Done' button behind the landmark pair in the " "center of the window.</p>") self.textFrame.setReadOnly(True) self.textFrame.setFrameShape(QFrame.NoFrame) self.textFrame.setAutoFillBackground(False) self.textFrame.setAttribute(Qt.WA_TranslucentBackground) self.textFrame.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.textFrame.setStyleSheet("background: #aaa") layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.textFrame) self.setLayout(layout)
def getParameterWidget(self): matrixLayout = QGridLayout() matrixLayout.setAlignment(Qt.AlignTop) matrixLayout.setContentsMargins(0, 0, 0, 0) matrixLayout.setSpacing(5) matrixLayout.addWidget(QLabel("Transformation matrix:"), 0, 0, 1, 4) self.m1Edits = [QLineEdit() for _ in range(4)] self.m2Edits = [QLineEdit() for _ in range(4)] self.m3Edits = [QLineEdit() for _ in range(4)] self.m4Edits = [QLineEdit() for _ in range(4)] self.initLineEdits(self.m1Edits, matrixLayout, 1, 0) self.initLineEdits(self.m2Edits, matrixLayout, 2, 0) self.initLineEdits(self.m3Edits, matrixLayout, 3, 0) self.initLineEdits(self.m4Edits, matrixLayout, 4, 0) expandingWidget = QWidget() expandingWidget.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) matrixLayout.addWidget(expandingWidget, 5, 0, 1, 4) matrixWidget = QWidget() matrixWidget.setLayout(matrixLayout) self.transformUpdated(self.renderWidget.transformations.completeTransform()) return matrixWidget
def __init__(self, widgets): super(CompareWidget, self).__init__() self.setStyleSheet("background-color: #333") fixedDataTitleWidget = self.createLabel("Fixed data", "#f80") movingDataTitleWidget = self.createLabel("Moving data", "#4bf") # Labels for underneath the compare widget fixedLabel = self.createLabel("Fixed", "#f80") fixedLabel.setAlignment(Qt.AlignRight) centerLabel = self.createLabel("+", "#fff") movingLabel = self.createLabel("Moving", "#4bf") movingLabel.setAlignment(Qt.AlignLeft) horLayout = QHBoxLayout() horLayout.setContentsMargins(0, 0, 0, 0) horLayout.addStretch(1) horLayout.addWidget(fixedLabel) horLayout.addWidget(centerLabel) horLayout.addWidget(movingLabel) horLayout.addStretch(1) combinedTextWidget = QWidget() combinedTextWidget.setLayout(horLayout) layout = QGridLayout() layout.setSpacing(15) layout.setContentsMargins(15, 15, 15, 15) for i in range(len(widgets)): widget = widgets[i] layout.addWidget(widget, 0, i) layout.addWidget(fixedDataTitleWidget, 1, 0) layout.addWidget(combinedTextWidget, 1, 1) layout.addWidget(movingDataTitleWidget, 1, 2) self.setLayout(layout)
def __init__(self): QFrame.__init__(self) self._color = [220, 220, 220] self._font = QFont() self._font.setPixelSize(10) self._pen = QPen(QColor(100, 100, 100, 255)) self.label = QLabel() self.label.setWordWrap(True) self.label.setFont(self._font) self.label.setMaximumWidth(300) self.label.setMaximumHeight(36) self.label.setMinimumHeight(36) layout = QGridLayout() layout.setSpacing(0) layout.addWidget(self.label) self.setLayout(layout) self.setMinimumWidth(360) self.setMaximumWidth(360)
def createElements(self): """ Creates the widgets and docks of which the main window is composed. """ self.mainWindow = QMainWindow() projectController = ProjectController.Instance() self.transformTool = None # Render widgets self.fixedDataWidget = RenderWidget() self.movingDataWidget = RenderWidget() self.multiDataWidget = MultiRenderWidget() self.fixedRenderController = RenderController(self.fixedDataWidget, "fixed") self.movingRenderController = RenderController(self.movingDataWidget, "moving") self.multiRenderController = MultiRenderController( self.multiDataWidget) # Give references of the render controllers to the project controller projectController.fixedRenderController = self.fixedRenderController projectController.movingRenderController = self.movingRenderController projectController.multiRenderController = self.multiRenderController # Render properties widgets sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(1) self.fixedPropWidget = RenderPropWidget(self.fixedRenderController, parent=self) self.fixedPropWidget.setSizePolicy(sizePolicy) self.fixedPropWidget.setFileChangedSignal( projectController.fixedFileChanged) self.fixedPropWidget.setLoadDataSlot(self.loadFixedDataSetFile) self.movingPropWidget = RenderPropWidget(self.movingRenderController, parent=self) self.movingPropWidget.setSizePolicy(sizePolicy) self.movingPropWidget.setFileChangedSignal( projectController.movingFileChanged) self.movingPropWidget.setLoadDataSlot(self.loadMovingDataSetFile) self.multiPropWidget = MultiRenderPropWidget( self.multiRenderController, parent=self) self.multiPropWidget.setSizePolicy(sizePolicy) self.verticalSplitter = QSplitter() self.verticalSplitter.setOrientation(Qt.Vertical) # Create the layouts fixedDataTitleWidget = TitleWidget("Fixed volume") multiDataTitleWidget = TitleWidget("Fixed + Moving") movingDataTitleWidget = TitleWidget("Moving volume") fixedLayout = QGridLayout() fixedLayout.setSpacing(0) fixedLayout.setContentsMargins(0, 0, 0, 0) fixedLayout.addWidget(fixedDataTitleWidget) fixedLayout.addWidget(self.fixedDataWidget) fixedWidget = QWidget() fixedWidget.setLayout(fixedLayout) multiLayout = QGridLayout() multiLayout.setSpacing(0) multiLayout.setContentsMargins(0, 0, 0, 0) multiLayout.addWidget(multiDataTitleWidget) multiLayout.addWidget(self.multiDataWidget) multiWidget = QWidget() multiWidget.setLayout(multiLayout) movingLayout = QGridLayout() movingLayout.setSpacing(0) movingLayout.setContentsMargins(0, 0, 0, 0) movingLayout.addWidget(movingDataTitleWidget) movingLayout.addWidget(self.movingDataWidget) movingWidget = QWidget() movingWidget.setLayout(movingLayout) horizontalSplitter = QSplitter() horizontalSplitter.setOrientation(Qt.Horizontal) horizontalSplitter.addWidget(fixedWidget) horizontalSplitter.addWidget(multiWidget) horizontalSplitter.addWidget(movingWidget) propsLayout = QHBoxLayout() propsLayout.setSpacing(1) propsLayout.setContentsMargins(0, 0, 0, 0) propsLayout.addWidget(self.fixedPropWidget) propsLayout.addWidget(self.multiPropWidget) propsLayout.addWidget(self.movingPropWidget) propsWidget = QWidget() propsWidget.setMinimumHeight(245) propsWidget.setMaximumHeight(350) propsWidget.setLayout(propsLayout) self.verticalSplitter.addWidget(horizontalSplitter) self.verticalSplitter.addWidget(propsWidget) self.verticalSplitter.setStretchFactor(0, 2) self.verticalSplitter.setStretchFactor(1, 1) self.setCentralWidget(self.verticalSplitter)
def __init__(self): super(HighwaySimulatorGui, self).__init__() centralTab = QTabWidget() mainWidget = QWidget() self.resultsWidget = HighwayAnalyzeWidget() centralTab.addTab(mainWidget, 'Run') centralTab.addTab(self.resultsWidget, 'Analyze') self.setCentralWidget(centralTab) centralLayout = QVBoxLayout() #centralLayout.setSpacing(0) centralLayout.setAlignment(Qt.AlignTop) gridWidget = QWidget() gridLayout = QGridLayout() gridLayout.setSpacing(0) gridWidget.setLayout(gridLayout) mainWidget.setLayout(centralLayout) self.options = dict() # GENERAL generalGroup = QGroupBox('General Settings') generalGroup.setLayout(QVBoxLayout()) generalGroup.layout().setSpacing(0) self.pathOption = SimpleOption('path','Output Path','/home/thomas/Dropbox/Keio/research/results/') generalGroup.layout().addWidget(self.pathOption) self.scenarioOption = SimpleComboboxOption('scenario','Scenario',1, False, 'vanet-highway-test-thomas','vanet-highway-scenario2') self.scenarioOption.combo.currentIndexChanged[int].connect(self.scenarioChanged) generalGroup.layout().addWidget(self.scenarioOption) self.options['time'] = SimpleSpinOption('time','Simulation Time (sec.)',1500,True) self.options['time'].setRange(0,3000) self.options['mix'] = SimpleSpinOption('mix','Percentage of cars compare to trucks (%)',80,True) self.options['mix'].setRange(0,100) self.options['gap'] = SimpleSpinOption('gap','Average Gap (m.)',5) self.options['gap'].setRange(1,2000) self.options['lane'] = SimpleSpinOption('lane','Number of Lanes',2,True) self.options['lane'].setRange(2,4) self.options['spl'] = SimpleSpinOption('spl','Speed Limit (km/h)',130,True) self.options['spl'].setRange(1,200) for widget in ('time','mix','gap','lane','spl'): generalGroup.layout().addWidget(self.options[widget]) gridLayout.addWidget(generalGroup,0,0) # TRAFFIC trafficGroup = QGroupBox('Traffic Settings') trafficGroup.setLayout(QVBoxLayout()) trafficGroup.layout().setSpacing(0) # m/s = (km/h)*1000/3600 self.options['vel1'] = SimpleSpinOption('vel1','Average Speed (km/h)',105,True) self.options['vel1'].setRange(5,150) self.options['dis'] = SimpleComboboxOption('dis','Speed Distribution Model',3, False, 'Uniform','Exponential','Normal','Log Normal') self.options['spstd'] = SimpleSpinOption('spstd','Speed Distribution Variance',1.0) self.options['spstd'].setRange(0,50) self.options['flow1'] = SimpleSpinOption('flow1','Traffic Flow Mean (veh/s)',1.0) self.options['flow1'].setRange(0.1,50.0) self.options['std1'] = SimpleSpinOption('std1','Traffic Flow Variance',0.8) self.options['std1'].setRange(0.1,50.0) self.options['maxflow'] = SimpleSpinOption('maxflow','Traffic Maximum Flow (veh/s)',5) self.options['maxflow'].setRange(0.1,50.0) # Scenar 2 self.options['avgdist'] = SimpleSpinOption('avgdist','Average Distance (m)',100) self.options['avgdist'].setRange(1,10000) self.options['avgspeed'] = SimpleSpinOption('avgspeed','Average Speed (km/h)',105) self.options['avgspeed'].setRange(1,10000) self.options['despeed'] = SimpleSpinOption('despeed','Desired Speed (km/h)',130) self.options['despeed'].setRange(1,10000) self.options['ambumaxspeed'] = SimpleSpinOption('ambumaxspeed','Ambu Max Speed (km/h)',165) self.options['ambumaxspeed'].setRange(1,10000) self.options['ambuinitspeed'] = SimpleSpinOption('ambuinitspeed','Ambu Initial Speed (km/h)',130) self.options['ambuinitspeed'].setRange(1,10000) for widget in ('vel1','dis','spstd','flow1','std1','maxflow', 'avgdist', 'avgspeed', 'despeed', 'ambumaxspeed', 'ambuinitspeed'): trafficGroup.layout().addWidget(self.options[widget]) self.scenarioChanged(self.scenarioOption.combo.currentIndex()) gridLayout.addWidget(trafficGroup,0,1) # VANET vanetGroup = QGroupBox('VANET Settings') vanetGroup.setLayout(QVBoxLayout()) vanetGroup.layout().setSpacing(0) # self.options['prate'] = SimpleSpinOption('prate','Penetration Rate of VANET (%)',100,True) # self.options['prate'].setRange(0,100) self.options['prate'] = 0 # start with 0 self.options['pw'] = SimpleSpinOption('pw','Transmission Power (dBm)',21.5) self.options['pw'].setRange(10,50) #for widget in ('prate','pw'): for widget in ('pw',): vanetGroup.layout().addWidget(self.options[widget]) gridLayout.addWidget(vanetGroup,1,0) # BATCH SETTINGS batchGroup = QGroupBox("Batch Settings") batchGroup.setLayout(QVBoxLayout()) self.gapPrateOption = SimpleSpinOption('gapPrate', 'VANET percentage rate gap', 10, integer=True) self.sameSimuTimesOption = SimpleSpinOption('sameSimuTimes', 'How many times the same simulation', 100, integer=True) batchGroup.layout().setSpacing(0) batchGroup.layout().addWidget(self.gapPrateOption) batchGroup.layout().addWidget(self.sameSimuTimesOption) gridLayout.addWidget(batchGroup,1,1) # START SIMU centralLayout.addWidget(gridWidget) self.startButton = QPushButton('START') self.startButton.clicked.connect(self.startSimu) centralLayout.addWidget(self.startButton) self.progressBar = QProgressBar() centralLayout.addWidget(self.progressBar) self.shutdownWhenDone = QCheckBox('Shutdown when done') self.actionWhenDone = QComboBox() self.actionWhenDone.addItems(['When finished... do nothing', 'When finished... shutdown the computer', 'When finished... Re-run the simulations!']) self.actionWhenDone.setCurrentIndex(int(QSettings().value('actionWhenDone', 0))) centralLayout.addWidget(self.actionWhenDone) self.infoLabel = QLabel() centralLayout.addWidget(self.infoLabel) # LOG self.logText = QTextBrowser() self.logText.setFont(QFont('Century Gothic', 7)) centralLayout.addWidget(self.logText) self.setWindowTitle('Nishimura Lab | Highway Simulation') #self.resize(520,len(self.options)*60+100) #self.resultFile = open('/home/thomas/Dropbox/Keio/research/results/summary.txt', 'a') #self.resultFile = os.path.join(self.pathOption.getValue(), 'summary.txt') self.logFile = os.path.join(self.pathOption.getValue(), 'results_'+os.uname()[1]+'.log')
class TransformationParameterWidget(QWidget): """ TransformationParameterWidget """ def __init__(self): super(TransformationParameterWidget, self).__init__() self.cancelButton = QPushButton("Cancel") self.cancelButton.clicked.connect(self.cancelButtonClicked) self.applyButton = QPushButton("Apply") self.applyButton.clicked.connect(self.applyButtonClicked) self.mainLayout = QGridLayout() self.mainLayout.setSpacing(0) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.widget = QWidget() self.widget.setLayout(self.mainLayout) self.showControls(False) self.transformationWidget = None layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.addWidget(self.widget, 0, 0, 1, 2) layout.addWidget(self.cancelButton, 1, 0) layout.addWidget(self.applyButton, 1, 1) self.setLayout(layout) def setTransformationTool(self, transformationTool): self.transformationTool = transformationTool self.cleanUpTransformWidget() self.transformationWidget = self.transformationTool.getParameterWidget() self.mainLayout.addWidget(self.transformationWidget) self.showControls(True) @Slot() def cancelButtonClicked(self): """ Cancels the transform and hides the apply / cancel buttons """ self.showControls(False) self.cleanUpTransformWidget() self.transformationTool.cancelTransform() self.transformationTool.cleanUp() self.transformationTool = None @Slot() def applyButtonClicked(self): """ Applies the transform and hides the apply / cancel buttons """ self.showControls(False) self.cleanUpTransformWidget() self.transformationTool.applyTransform() self.transformationTool.cleanUp() self.transformationTool = None def showControls(self, show): self.widget.setVisible(show) self.applyButton.setVisible(show) self.cancelButton.setVisible(show) def cleanUpTransformWidget(self): item = self.mainLayout.takeAt(0) if item: item.widget().deleteLater()
def initUI(self): ''' Method to setup the buttons/entries of the Gui ''' self.dateFrame = dateFrame( ); # Initialize the dateFrame self.iopLabel = QLabel('IOP Number'); # Initialize Entry widget for the IOP name self.iopName = QLineEdit(); # Initialize Entry widget for the IOP name self.stationLabel = QLabel('Station Name'); # Initialize Entry widget for the IOP name self.stationName = QLineEdit(); # Initialize Entry widget for the IOP name self.sourceButton = QPushButton('Source Directory'); # Initialize button for selecting the source directory self.destButton = QPushButton('Destination Directory'); # Initialize button for selecting the destination directory self.sourcePath = QLineEdit(''); # Initialize entry widget that will display the source directory path self.destPath = QLineEdit(''); # Initialize entry widget that will display the destination directory path self.sourceSet = indicator(); # Initialize an indictor that will appear when the source path is set self.destSet = indicator(); # Initialize an indictor that will appear when the destination path is set self.sourcePath.setEnabled( False ); # Disable the sourcePath widget; that way no one can manually edit it self.destPath.setEnabled( False ); # Disable the destPath widget; that way no one can manually edit it self.sourcePath.hide(); # Hide the source directory path self.destPath.hide(); # Hide the destination directory path self.sourceSet.hide(); # Hide the source directory indicator self.destSet.hide(); # Hide the destination directory indicator self.sourceButton.clicked.connect( self.select_source ); # Set method to run when the source button is clicked self.destButton.clicked.connect( self.select_dest ); # Set method to run when the destination button is clicked self.copyButton = QPushButton( 'Copy Files' ); # Create 'Copy Files' button self.copyButton.clicked.connect( self.copy_files ); # Set method to run when 'Copy Files' button is clicked self.copyButton.setEnabled(False); # Set enabled state to False; cannot click until after the source and destination directories set self.copySucces = indicator(); # Initialize an indictor that will appear when the copy complete successfuly self.copySucces.hide(); self.procButton = QPushButton( 'Process Files' ); # Create 'Process Files' button self.procButton.clicked.connect( self.proc_files ); # Set method to run when 'Process Files' button is clicked self.procButton.setEnabled(False); # Set enabled state to False; cannot click until after 'Copy Files' completes self.procSucces = indicator(); # Initialize an indictor that will appear when the processing complete successfuly self.procSucces.hide(); self.genButton = QPushButton( 'Generate Sounding' ); # Create 'Generate Sounding' button self.genButton.clicked.connect( self.gen_sounding ); # Set method to run when 'Generate Sounding' button is clicked self.genButton.setEnabled(False); # Set enabled state to False; cannot click until after 'Process Files' completes self.genSucces = indicator(); # Initialize an indictor that will appear when the sounding generation complete successfuly self.genSucces.hide(); self.uploadButton = QPushButton( 'FTP Upload' ); # Create 'FTP Upload' button self.uploadButton.clicked.connect( self.ftp_upload ); # Set method to run when 'FTP Upload' button is clicked self.uploadButton.setEnabled(False); # Set enabled state to False; cannot click until after 'Generate Sounding' completes self.uploadSucces = indicator(); # Initialize an indictor that will appear when the ftp upload complete successfuly self.uploadSucces.hide(); self.checkButton = QPushButton( 'Check website' ); # Create 'Check website' button self.checkButton.clicked.connect( self.check_site ); # Set method to run when 'Check website' button is clicked self.checkButton.setEnabled(False); # Set enabled state to False; cannot click until after 'FTP Upload' completes self.resetButton = QPushButton( 'Reset' ); # Create 'Check website' button self.resetButton.clicked.connect( self.reset_values ); # Set method to run when 'Check website' button is clicked versionLabel = QLabel( 'version: {}'.format(__version__) ); # Version label versionLabel.setAlignment( Qt.AlignHCenter ); # Set alignment to center log_handler = QLogger( ); # Initialize a QLogger logging.Handler object logging.getLogger('Meso1819').addHandler( log_handler ); # Get the Meso1819 root logger and add the handler to it grid = QGridLayout(); # Initialize grid layout grid.setSpacing(10); # Set spacing to 10 for i in range(4): grid.setColumnStretch(i, 0); # Set column stretch for ith column grid.setColumnMinimumWidth(i, 60); # Set column min width for ith column grid.setColumnStretch(4, 0); # Set column stretch for 5th column grid.setColumnMinimumWidth(4, 20); # Set column min width for 5th column grid.setRowStretch(1, 0); # Set column stretch for 5th column grid.setRowStretch(3, 0); # Set column stretch for 5th column grid.setRowMinimumHeight(1, 25); # Set column min width for 5th column grid.setRowMinimumHeight(3, 25); # Set column min width for 5th column grid.addWidget( self.sourceButton, 0, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.sourceSet, 0, 4, 1, 1 ); # Place a widget in the grid grid.addWidget( self.sourcePath, 1, 0, 1, 5 ); # Place a widget in the grid grid.addWidget( self.destButton, 2, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.destSet, 2, 4, 1, 1 ); # Place a widget in the grid grid.addWidget( self.destPath, 3, 0, 1, 5 ); # Place a widget in the grid grid.addWidget( self.iopLabel, 4, 0, 1, 2 ); # Place a widget in the grid grid.addWidget( self.iopName, 5, 0, 1, 2 ); # Place a widget in the grid grid.addWidget( self.stationLabel, 4, 2, 1, 2 ); # Place a widget in the grid grid.addWidget( self.stationName, 5, 2, 1, 2 ); # Place a widget in the grid grid.addWidget( self.dateFrame, 6, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.copyButton, 7, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.copySucces, 7, 4, 1, 1 ); # Place a widget in the grid grid.addWidget( self.procButton, 8, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.procSucces, 8, 4, 1, 1 ); # Place a widget in the grid grid.addWidget( self.genButton, 9, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.genSucces, 9, 4, 1, 1 ); # Place a widget in the grid grid.addWidget( self.uploadButton, 10, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.uploadSucces, 10, 4, 1, 1 ); # Place a widget in the grid grid.addWidget( self.checkButton, 11, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( self.resetButton, 12, 0, 1, 4 ); # Place a widget in the grid grid.addWidget( log_handler.frame, 0, 6, 13, 1); grid.addWidget( versionLabel, 20, 0, 1, 7) centralWidget = QWidget(); # Create a main widget centralWidget.setLayout( grid ); # Set the main widget's layout to the grid self.setCentralWidget(centralWidget); # Set the central widget of the base class to the main widget self.show( ); # Show the main widget
def getParameterWidget(self): """ Returns a widget with sliders / fields with which properties of this volume property can be adjusted. :rtype: QWidget """ self.lowerBoundSlider = SliderFloatWidget() self.lowerBoundSlider.setName("Lower:") self.lowerBoundSlider.setRange([self.minimum, self.maximum]) self.lowerBoundSlider.setValue(self.lowerBound) self.lowerBoundSlider.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.lowerBoundSlider.valueChanged.connect(self.valueChanged) self.upperBoundSlider = SliderFloatWidget() self.upperBoundSlider.setName("Upper:") self.upperBoundSlider.setRange([self.minimum, self.maximum]) self.upperBoundSlider.setValue(self.upperBound) self.upperBoundSlider.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.upperBoundSlider.valueChanged.connect(self.valueChanged) layoutGroup = QGridLayout() layoutGroup.setAlignment(Qt.AlignTop) layoutGroup.setContentsMargins(5, 0, 0, 0) layoutGroup.setSpacing(0) layoutGroup.addWidget(self.lowerBoundSlider) layoutGroup.addWidget(self.upperBoundSlider) groupbox = QGroupBox("Thresholds:") groupbox.setLayout(layoutGroup) self.opacitySlider = SliderFloatWidget() self.opacitySlider.setName("Opacity:") self.opacitySlider.setRange([0.0, 1.0]) self.opacitySlider.setValue(self.opacity) self.opacitySlider.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.opacitySlider.valueChanged.connect(self.valueChanged) self.colorChooser = ColorChoiceWidget() self.colorChooser.setName("Color:") self.colorChooser.setColors(self.colors) self.colorChooser.setColor(self.color) self.colorChooser.setMinimumHeight( self.upperBoundSlider.sizeHint().height()) self.colorChooser.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.colorChooser.valueChanged.connect(self.valueChanged) otherLayoutGroup = QGridLayout() otherLayoutGroup.setAlignment(Qt.AlignTop) otherLayoutGroup.setContentsMargins(5, 0, 0, 0) otherLayoutGroup.setSpacing(0) otherLayoutGroup.addWidget(self.opacitySlider) # otherLayoutGroup.addWidget(self.colorChooser) # otherBox = QGroupBox("Color and opacity:") otherBox = QGroupBox() otherBox.setLayout(otherLayoutGroup) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setContentsMargins(0, 0, 0, 0) layout.setHorizontalSpacing(0) layout.addWidget(groupbox) layout.addWidget(otherBox) widget = QWidget() widget.setLayout(layout) try: from ColumnResizer import ColumnResizer self.columnResizer = ColumnResizer() self.columnResizer.addWidgetsFromLayout( self.lowerBoundSlider.layout(), 0) self.columnResizer.addWidgetsFromLayout( self.upperBoundSlider.layout(), 0) self.columnResizer.addWidgetsFromLayout(self.colorChooser.layout(), 0) self.columnResizer.addWidgetsFromLayout( self.opacitySlider.layout(), 0) self.otherColRes = ColumnResizer() self.otherColRes.addWidgetsFromLayout( self.lowerBoundSlider.layout(), 2) self.otherColRes.addWidgetsFromLayout( self.upperBoundSlider.layout(), 2) self.otherColRes.addWidgetsFromLayout(self.opacitySlider.layout(), 2) except Exception, e: print e
def setFile(self, fileName): """ Slot that reads properties of the dataset and displays them in a few widgets. """ if fileName is None: return self.fileName = fileName # Read info from dataset # TODO: read out the real world dimensions in inch or cm # TODO: scalar type (int, float, short, etc.) imageReader = DataReader() imageData = imageReader.GetImageData(fileName) directory, name = os.path.split(fileName) dimensions = imageData.GetDimensions() minimum, maximum = imageData.GetScalarRange() scalarType = imageData.GetScalarTypeAsString() bins = DataAnalyzer.histogramForData(imageData, 256) self.histogram = Histogram() self.histogram.bins = bins self.histogram.enabled = True self.histogramWidget = HistogramWidget() self.histogramWidget.setMinimumHeight(100) self.histogramWidget.setHistogram(self.histogram) self.histogramWidget.setAxeMode(bottom=HistogramWidget.AxeClear, left=HistogramWidget.AxeLog) Style.styleWidgetForTab(self.histogramWidget) nameText = name dimsText = "(" + str(dimensions[0]) + ", " + str(dimensions[1]) + ", " + str(dimensions[2]) + ")" voxsText = str(dimensions[0] * dimensions[1] * dimensions[2]) rangText = "[" + str(minimum) + " : " + str(maximum) + "]" typeText = scalarType layout = self.layout() if not layout: # Create a new layout layout = QGridLayout() layout.setAlignment(Qt.AlignTop) # Create string representations nameLabels = [] nameLabels.append(QLabel("File name:")) nameLabels.append(QLabel("Dimensions:")) nameLabels.append(QLabel("Voxels:")) nameLabels.append(QLabel("Range:")) nameLabels.append(QLabel("Data type:")) for label in nameLabels: label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) # Create 'dynamic' labels self.labelTitle = QLabel(nameText) self.labelDimensions = QLabel(dimsText) self.labelVoxels = QLabel(voxsText) self.labelRange = QLabel(rangText) self.labelType = QLabel(typeText) index = 0 for label in nameLabels: layout.addWidget(label, index, 0) index += 1 layout.addWidget(self.labelTitle, 0, 1) layout.addWidget(self.labelDimensions, 1, 1) layout.addWidget(self.labelVoxels, 2, 1) layout.addWidget(self.labelRange, 3, 1) layout.addWidget(self.labelType, 4, 1) layout.addWidget(self.histogramWidget, 5, 0, 1, 2) widget = QWidget() widget.setLayout(layout) Style.styleWidgetForTab(widget) self.scrollArea.setWidget(widget) scrollLayout = QGridLayout() scrollLayout.setSpacing(0) scrollLayout.setContentsMargins(0, 0, 0, 0) scrollLayout.addWidget(self.scrollArea) self.setLayout(scrollLayout) else: # Just update the text for the 'dynamic' labels self.labelTitle.setText(nameText) self.labelDimensions.setText(dimsText) self.labelVoxels.setText(voxsText) self.labelRange.setText(rangText) self.labelType.setText(typeText)
def getParameterWidget(self): """ Returns a widget with sliders / fields with which properties of this volume property can be adjusted. :rtype: QWidget """ self.lowerBoundSlider = SliderFloatWidget() self.lowerBoundSlider.setName("Lower:") self.lowerBoundSlider.setRange([self.minimum, self.maximum]) self.lowerBoundSlider.setValue(self.lowerBound) self.lowerBoundSlider.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.lowerBoundSlider.valueChanged.connect(self.valueChanged) self.upperBoundSlider = SliderFloatWidget() self.upperBoundSlider.setName("Upper:") self.upperBoundSlider.setRange([self.minimum, self.maximum]) self.upperBoundSlider.setValue(self.upperBound) self.upperBoundSlider.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.upperBoundSlider.valueChanged.connect(self.valueChanged) layoutGroup = QGridLayout() layoutGroup.setAlignment(Qt.AlignTop) layoutGroup.setContentsMargins(5, 0, 0, 0) layoutGroup.setSpacing(0) layoutGroup.addWidget(self.lowerBoundSlider) layoutGroup.addWidget(self.upperBoundSlider) groupbox = QGroupBox("Thresholds:") groupbox.setLayout(layoutGroup) self.opacitySlider = SliderFloatWidget() self.opacitySlider.setName("Opacity:") self.opacitySlider.setRange([0.0, 1.0]) self.opacitySlider.setValue(self.opacity) self.opacitySlider.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.opacitySlider.valueChanged.connect(self.valueChanged) self.colorChooser = ColorChoiceWidget() self.colorChooser.setName("Color:") self.colorChooser.setColors(self.colors) self.colorChooser.setColor(self.color) self.colorChooser.setMinimumHeight(self.upperBoundSlider.sizeHint().height()) self.colorChooser.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.colorChooser.valueChanged.connect(self.valueChanged) otherLayoutGroup = QGridLayout() otherLayoutGroup.setAlignment(Qt.AlignTop) otherLayoutGroup.setContentsMargins(5, 0, 0, 0) otherLayoutGroup.setSpacing(0) otherLayoutGroup.addWidget(self.opacitySlider) # otherLayoutGroup.addWidget(self.colorChooser) # otherBox = QGroupBox("Color and opacity:") otherBox = QGroupBox() otherBox.setLayout(otherLayoutGroup) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.setContentsMargins(0, 0, 0, 0) layout.setHorizontalSpacing(0) layout.addWidget(groupbox) layout.addWidget(otherBox) widget = QWidget() widget.setLayout(layout) try: from ColumnResizer import ColumnResizer self.columnResizer = ColumnResizer() self.columnResizer.addWidgetsFromLayout(self.lowerBoundSlider.layout(), 0) self.columnResizer.addWidgetsFromLayout(self.upperBoundSlider.layout(), 0) self.columnResizer.addWidgetsFromLayout(self.colorChooser.layout(), 0) self.columnResizer.addWidgetsFromLayout(self.opacitySlider.layout(), 0) self.otherColRes = ColumnResizer() self.otherColRes.addWidgetsFromLayout(self.lowerBoundSlider.layout(), 2) self.otherColRes.addWidgetsFromLayout(self.upperBoundSlider.layout(), 2) self.otherColRes.addWidgetsFromLayout(self.opacitySlider.layout(), 2) except Exception, e: print e
def __init__(self): super(MultiRenderWidget, self).__init__() # Default volume renderer self.renderer = vtkRenderer() self.renderer.SetBackground2(0.4, 0.4, 0.4) self.renderer.SetBackground(0.1, 0.1, 0.1) self.renderer.SetGradientBackground(True) self.renderer.SetInteractive(1) self.renderer.SetLayer(0) # Overlay renderer which is synced with the default renderer self.rendererOverlay = vtkRenderer() self.rendererOverlay.SetLayer(1) self.rendererOverlay.SetInteractive(0) self.renderer.GetActiveCamera().AddObserver("ModifiedEvent", self._syncCameras) self.rwi = QVTKRenderWindowInteractor(parent=self) self.rwi.SetInteractorStyle(vtkInteractorStyleTrackballCamera()) self.rwi.GetRenderWindow().AddRenderer(self.renderer) self.rwi.GetRenderWindow().AddRenderer(self.rendererOverlay) self.rwi.GetRenderWindow().SetNumberOfLayers(2) self.rwi.SetDesiredUpdateRate(0) self._imagePlaneWidgets = [vtkImagePlaneWidget() for i in range(3)] for index in range(3): self._imagePlaneWidgets[index].DisplayTextOn() self._imagePlaneWidgets[index].SetInteractor(self.rwi) self.mapper = vtkOpenGLGPUMultiVolumeRayCastMapper() self.mapper.SetBlendModeToComposite() self.volume = vtkVolume() self.volume.SetMapper(self.mapper) self.renderer.AddViewProp(self.volume) self.fixedGridItems = [] self.movingGridItems = [] self.orientationGridItems = [] # Create two empty datasets self.fixedImageData = CreateEmptyImageData() self.movingImageData = CreateEmptyImageData() self.fixedVolumeProperty = vtkVolumeProperty() self.movingVolumeProperty = vtkVolumeProperty() color, opacityFunction = CreateEmptyFunctions() self.fixedVolumeProperty.SetColor(color) self.fixedVolumeProperty.SetScalarOpacity(opacityFunction) self.movingVolumeProperty.SetColor(color) self.movingVolumeProperty.SetScalarOpacity(opacityFunction) self.visualization = None # MultiVolumeVisualization self.clippingBox = ClippingBox() self.clippingBox.setWidget(self) self.mapper.SetInputData(0, self.fixedImageData) self.mapper.SetInputData(1, self.movingImageData) self._transformations = TransformationList() self._transformations.transformationChanged.connect(self.updateTransformation) self._shouldResetCamera = False self.setMinimumWidth(340) self.setMinimumHeight(340) layout = QGridLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.rwi, 0, 0) self.setLayout(layout)