示例#1
0
    class ResultsGrid(QScrollArea):
        def __init__(self, parent=None):
            QScrollArea.__init__(self)
            self.setParent(parent)

            # Make QScrollArea transparent
            self.setStyleSheet(
                "QScrollArea { background-color: transparent } .QFrame { background-color: transparent }"
            )
            self.setWidgetResizable(True)
            self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

            # Add Touch Gestures to menu.
            QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)

            # Layout settings
            self.layout = QGridLayout()
            self.layout.setContentsMargins(0, 0, 0, 0)
            self.layout.setSpacing(0)

            # QScrollArea requires a separate QWidget to work properly
            frame = QFrame()
            frame.setLayout(self.layout)

            self.setWidget(frame)

        def clearResults(self):
            # Clear the results in the list
            while self.layout.count():
                item = self.layout.takeAt(0)
                if item.widget() is not None:
                    item.widget().deleteLater()

        def addResults(self, results):
            # Add the results to the list
            # results (list): list of python dict representing results details (playlist or song search)
            self.clearResults()
            for i in range(len(results)):
                item = self.ResultsGridItem(results[i], self)
                self.layout.addWidget(item, i // 6, i % 6)
            if results:
                self.layout.setRowStretch(self.layout.rowCount(), 1)
                self.layout.setColumnStretch(self.layout.columnCount(), 1)
            else:
                # If the results are empty, display no result
                label = QLabel("没有结果/No Result")
                label.setStyleSheet("color: white")
                label.setAlignment(Qt.AlignCenter)
                font = QFont()
                font.setPointSize(35)
                label.setFont(font)

                self.layout.addWidget(label)

        class ResultsGridItem(QToolButton):
            def __init__(self, result, parent=None):
                QToolButton.__init__(self)
                self.setParent(parent)
                self.result = result

                self.setContentsMargins(0, 0, 0, 0)
                # Button formatting
                self.setFixedSize(200, 240)
                self.setAutoRaise(True)
                # TODO: change with global themes
                self.setStyleSheet(
                    "QToolButton:pressed { background-color: rgba(255, 255, 255, 0.1)} QToolButton { background-color: rgba(255, 255, 255, 0.05); border: 1px solid white; color: white}"
                )

                # Set layout settings
                self.layout = QGridLayout()
                self.layout.setContentsMargins(0, 0, 0, 0)
                self.layout.setSpacing(0)

                if result["type"] == "artists":
                    # Artist image
                    self.formattedImage(self.window().artistPath +
                                        result["artist_path"])
                    self.formattedLabel(result["artist_name"])

                    # Favourite button
                    self.favouriteButton = QToolButton()
                    self.favouriteButton.setStyleSheet(
                        "QToolButton:pressed { background-color: rgb(31, 41, 75)} QToolButton { background-color: rgb(25, 33, 60);}"
                    )

                    # Toggle Favourite Icon depending on DB
                    if self.result["favourited"] == 0:
                        self.favouriteButton.isFavourited = False
                        self.favouriteButton.setIcon(QIcon("icons/star.svg"))
                    else:
                        self.favouriteButton.isFavourited = True
                        self.favouriteButton.setIcon(
                            QIcon("icons/star-yellow.svg"))
                    self.favouriteButton.setIconSize(QSize(30, 30))
                    self.favouriteButton.setFixedSize(70, 70)
                    self.favouriteButton.clicked.connect(self.clickedFavourite)
                    self.layout.addWidget(self.favouriteButton, 0, 0,
                                          Qt.AlignRight | Qt.AlignTop)

                    self.clicked.connect(self.clickedArtist)
                elif result["type"] == "languages":
                    # Language image
                    self.formattedImage(self.window().languagePath +
                                        result["language_path"])
                    self.formattedLabel(result["language_name"])
                    self.clicked.connect(self.clickedLanguage)

                self.setLayout(self.layout)

            def clickedFavourite(self):
                # Toggle Icon and DB state of song being favourited
                # For artists only
                if self.favouriteButton.isFavourited:
                    self.favouriteButton.isFavourited = False
                    self.favouriteButton.setIcon(QIcon("icons/star.svg"))
                else:
                    self.favouriteButton.isFavourited = True
                    self.favouriteButton.setIcon(
                        QIcon("icons/star-yellow.svg"))
                DB.setFavouriteArtist(self.result["artist_id"])

            def formattedImage(self, path):
                # Format an image given the path
                self.setIcon(QIcon(path))
                self.setIconSize(QSize(180, 180))

            def formattedLabel(self, text):
                # Format a label given text
                font = QFont()
                font.setPixelSize(18)
                self.setText(text)
                self.setFont(font)
                self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

            def clickedArtist(self):
                # Called when an Artist is clicked on
                self.window().content.addWidget(
                    WindowSearch(
                        "搜索全部/Search", self,
                        self.window().content.currentWidget().counter + 1,
                        self.result))
                self.window().content.setCurrentIndex(
                    self.window().content.currentWidget().counter + 1)

            def clickedLanguage(self):
                # Called when a Language is clicked on
                self.window().content.addWidget(
                    WindowSearch(
                        "搜索歌手/Artist Search",
                        self,
                        self.window().content.currentWidget().counter + 1,
                        self.result,
                        grid=True))
                self.window().content.setCurrentIndex(
                    self.window().content.currentWidget().counter + 1)
示例#2
0
class Ui_GridControls(object):
    def setupUi(self, GridControls):
        if not GridControls.objectName():
            GridControls.setObjectName(u"GridControls")
        GridControls.resize(400, 300)
        self.grid_layout = QGridLayout(GridControls)
        self.grid_layout.setObjectName(u"grid_layout")
        self.game_display = QGraphicsView(GridControls)
        self.game_display.setObjectName(u"game_display")

        self.grid_layout.addWidget(self.game_display, 0, 0, 5, 1)

        self.black_count = ScaledLabel(GridControls)
        self.black_count.setObjectName(u"black_count")
        sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.black_count.sizePolicy().hasHeightForWidth())
        self.black_count.setSizePolicy(sizePolicy)
        self.black_count.setScaledContents(True)
        self.black_count.setAlignment(Qt.AlignHCenter | Qt.AlignTop)

        self.grid_layout.addWidget(self.black_count, 1, 1, 1, 1)

        self.black_count_pixmap = ScaledLabel(GridControls)
        self.black_count_pixmap.setObjectName(u"black_count_pixmap")
        sizePolicy.setHeightForWidth(
            self.black_count_pixmap.sizePolicy().hasHeightForWidth())
        self.black_count_pixmap.setSizePolicy(sizePolicy)
        self.black_count_pixmap.setScaledContents(True)
        self.black_count_pixmap.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)

        self.grid_layout.addWidget(self.black_count_pixmap, 0, 1, 1, 1)

        self.white_count_pixmap = ScaledLabel(GridControls)
        self.white_count_pixmap.setObjectName(u"white_count_pixmap")
        sizePolicy.setHeightForWidth(
            self.white_count_pixmap.sizePolicy().hasHeightForWidth())
        self.white_count_pixmap.setSizePolicy(sizePolicy)
        self.white_count_pixmap.setScaledContents(True)
        self.white_count_pixmap.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)

        self.grid_layout.addWidget(self.white_count_pixmap, 0, 2, 1, 1)

        self.white_count = ScaledLabel(GridControls)
        self.white_count.setObjectName(u"white_count")
        sizePolicy.setHeightForWidth(
            self.white_count.sizePolicy().hasHeightForWidth())
        self.white_count.setSizePolicy(sizePolicy)
        self.white_count.setScaledContents(True)
        self.white_count.setAlignment(Qt.AlignHCenter | Qt.AlignTop)

        self.grid_layout.addWidget(self.white_count, 1, 2, 1, 1)

        self.player_pixmap = ScaledLabel(GridControls)
        self.player_pixmap.setObjectName(u"player_pixmap")
        sizePolicy.setHeightForWidth(
            self.player_pixmap.sizePolicy().hasHeightForWidth())
        self.player_pixmap.setSizePolicy(sizePolicy)
        self.player_pixmap.setScaledContents(True)
        self.player_pixmap.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)

        self.grid_layout.addWidget(self.player_pixmap, 2, 1, 1, 2)

        self.move_text = ScaledLabel(GridControls)
        self.move_text.setObjectName(u"move_text")
        sizePolicy.setHeightForWidth(
            self.move_text.sizePolicy().hasHeightForWidth())
        self.move_text.setSizePolicy(sizePolicy)
        self.move_text.setScaledContents(True)
        self.move_text.setAlignment(Qt.AlignHCenter | Qt.AlignTop)

        self.grid_layout.addWidget(self.move_text, 3, 1, 1, 2)

        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                          QSizePolicy.Expanding)

        self.grid_layout.addItem(self.verticalSpacer, 4, 1, 1, 2)

        self.grid_layout.setRowStretch(0, 1)
        self.grid_layout.setRowStretch(1, 1)
        self.grid_layout.setRowStretch(2, 5)
        self.grid_layout.setRowStretch(3, 1)
        self.grid_layout.setRowStretch(4, 5)
        self.grid_layout.setColumnStretch(0, 10)
        self.grid_layout.setColumnStretch(1, 1)
        self.grid_layout.setColumnStretch(2, 1)

        self.retranslateUi(GridControls)

        QMetaObject.connectSlotsByName(GridControls)

    # setupUi

    def retranslateUi(self, GridControls):
        GridControls.setWindowTitle(
            QCoreApplication.translate("GridControls", u"Form", None))
        self.black_count.setText(
            QCoreApplication.translate("GridControls", u"0", None))
        self.black_count_pixmap.setText(
            QCoreApplication.translate("GridControls", u"B", None))
        self.white_count_pixmap.setText(
            QCoreApplication.translate("GridControls", u"W", None))
        self.white_count.setText(
            QCoreApplication.translate("GridControls", u"0", None))
        self.player_pixmap.setText(
            QCoreApplication.translate("GridControls", u"Player", None))
        self.move_text.setText(
            QCoreApplication.translate("GridControls", u"to move", None))
示例#3
0
    def createMessageGroupBox(self):
        self.messageGroupBox = QGroupBox("Balloon Message")

        self.typeLabel = QLabel("Type:")

        self.typeComboBox = QComboBox()
        self.typeComboBox.addItem("None", QSystemTrayIcon.NoIcon)
        self.typeComboBox.addItem(
            self.style().standardIcon(QStyle.SP_MessageBoxInformation),
            "Information",
            QSystemTrayIcon.Information,
        )
        self.typeComboBox.addItem(
            self.style().standardIcon(QStyle.SP_MessageBoxWarning),
            "Warning",
            QSystemTrayIcon.Warning,
        )
        self.typeComboBox.addItem(
            self.style().standardIcon(QStyle.SP_MessageBoxCritical),
            "Critical",
            QSystemTrayIcon.Critical,
        )
        self.typeComboBox.addItem(QIcon(), "Custom icon", -1)
        self.typeComboBox.setCurrentIndex(1)

        self.durationLabel = QLabel("Duration:")

        self.durationSpinBox = QSpinBox()
        self.durationSpinBox.setRange(5, 60)
        self.durationSpinBox.setSuffix(" s")
        self.durationSpinBox.setValue(15)

        self.durationWarningLabel = QLabel(
            "(some systems might ignore this hint)")
        self.durationWarningLabel.setIndent(10)

        self.titleLabel = QLabel("Title:")
        self.titleEdit = QLineEdit("Cannot connect to network")
        self.bodyLabel = QLabel("Body:")

        self.bodyEdit = QTextEdit()
        self.bodyEdit.setPlainText(
            "Don't believe me. Honestly, I don't have a clue."
            "\nClick this balloon for details.")

        self.showMessageButton = QPushButton("Show Message")
        self.showMessageButton.setDefault(True)

        messageLayout = QGridLayout()
        messageLayout.addWidget(self.typeLabel, 0, 0)
        messageLayout.addWidget(self.typeComboBox, 0, 1, 1, 2)
        messageLayout.addWidget(self.durationLabel, 1, 0)
        messageLayout.addWidget(self.durationSpinBox, 1, 1)
        messageLayout.addWidget(self.durationWarningLabel, 1, 2, 1, 3)
        messageLayout.addWidget(self.titleLabel, 2, 0)
        messageLayout.addWidget(self.titleEdit, 2, 1, 1, 4)
        messageLayout.addWidget(self.bodyLabel, 3, 0)
        messageLayout.addWidget(self.bodyEdit, 3, 1, 2, 4)
        messageLayout.addWidget(self.showMessageButton, 5, 4)
        messageLayout.setColumnStretch(3, 1)
        messageLayout.setRowStretch(4, 1)
        self.messageGroupBox.setLayout(messageLayout)
示例#4
0
class UIMainWindow:
    """
    The central class responsible for initializing most of the values stored
    in the PatientDictContainer model and defining the visual layout of the
    main window of OnkoDICOM. No class has access to the attributes
    belonging to this class, except for the class's ActionHandler, which is
    used to trigger actions within the main window. Components of this class
    (i.e. QWidget child classes such as StructureTab, DicomView, DicomTree,
    etc.) should not be able to reference this class, and rather should
    exist independently and only be able to communicate with the
    PatientDictContainer model. If a component needs to communicate with
    another component, that should be accomplished by emitting signals
    within that components, and having the slots for those signals within
    this class (as demonstrated by the update_views() method of this class).
    If a class needs to trigger one of the actions defined in the
    ActionHandler, then the instance of the ActionHandler itself can safely
    be passed into the class.
    """
    pyradi_trigger = QtCore.Signal(str, dict, str)

    # Connect to GUIController
    image_fusion_main_window = QtCore.Signal()

    def setup_ui(self, main_window_instance):
        self.main_window_instance = main_window_instance
        self.call_class = MainPageCallClass()
        self.add_on_options_controller = AddOptions(self)

        ##########################################
        #  IMPLEMENTATION OF THE MAIN PAGE VIEW  #
        ##########################################
        if platform.system() == 'Darwin':
            self.stylesheet_path = "res/stylesheet.qss"
        else:
            self.stylesheet_path = "res/stylesheet-win-linux.qss"
        self.stylesheet = open(resource_path(self.stylesheet_path)).read()
        window_icon = QIcon()
        window_icon.addPixmap(QPixmap(resource_path(
            "res/images/icon.ico")), QIcon.Normal, QIcon.Off)
        self.main_window_instance.setMinimumSize(1080, 700)
        self.main_window_instance.setObjectName("MainOnkoDicomWindowInstance")
        self.main_window_instance.setWindowIcon(window_icon)
        self.main_window_instance.setStyleSheet(self.stylesheet)

        self.setup_central_widget()
        self.setup_actions()

        # Create SUV2ROI object and connect signals
        self.suv2roi = SUV2ROI()
        self.suv2roi_progress_window = \
            ProgressWindow(self.main_window_instance,
                           QtCore.Qt.WindowTitleHint |
                           QtCore.Qt.WindowCloseButtonHint)
        self.suv2roi_progress_window.signal_loaded.connect(
            self.on_loaded_suv2roi)

    def setup_actions(self):
        if hasattr(self, 'toolbar'):
            self.main_window_instance.removeToolBar(self.toolbar)
        self.action_handler = ActionHandler(self)
        self.menubar = MenuBar(self.action_handler)
        self.main_window_instance.setMenuBar(self.menubar)
        self.toolbar = Toolbar(self.action_handler)
        self.main_window_instance.addToolBar(
            QtCore.Qt.TopToolBarArea, self.toolbar)
        self.main_window_instance.setWindowTitle("OnkoDICOM")

    def setup_central_widget(self):
        patient_dict_container = PatientDictContainer()
        self.central_widget = QtWidgets.QWidget()
        self.central_widget_layout = QVBoxLayout()

        self.patient_bar = PatientBar()

        splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)

        # Left panel contains stuctures tab, isodoses tab,
        # and structure information
        self.left_panel = QtWidgets.QTabWidget()
        self.left_panel.setMinimumWidth(300)
        self.left_panel.setMaximumWidth(500)

        # Add structures tab to left panel
        if not hasattr(self, 'structures_tab'):
            self.structures_tab = StructureTab()
            self.structures_tab.request_update_structures.connect(
                self.update_views)
        else:
            self.structures_tab.update_ui()
        self.left_panel.addTab(self.structures_tab, "Structures")

        if patient_dict_container.has_modality("rtdose"):
            self.isodoses_tab = IsodoseTab()
            self.isodoses_tab.request_update_isodoses.connect(
                self.update_views)
            self.isodoses_tab.request_update_ui.connect(
                self.structures_tab.fixed_container_structure_modified)
            self.left_panel.addTab(self.isodoses_tab, "Isodoses")
        elif hasattr(self, 'isodoses_tab'):
            del self.isodoses_tab

        # Right panel contains the different tabs of DICOM view, DVH,
        # clinical data, DICOM tree
        self.right_panel = QtWidgets.QTabWidget()

        # Create a Dicom View containing single-slice and 3-slice views
        self.dicom_view = DicomStackedWidget(self.format_data)

        roi_color_dict = self.structures_tab.color_dict if hasattr(
            self, 'structures_tab') else None
        iso_color_dict = self.isodoses_tab.color_dict if hasattr(
            self, 'isodoses_tab') else None
        self.dicom_single_view = DicomAxialView(
            roi_color=roi_color_dict, iso_color=iso_color_dict)
        self.dicom_axial_view = DicomAxialView(
            is_four_view=True, roi_color=roi_color_dict, iso_color=iso_color_dict,
            metadata_formatted=True, cut_line_color=QtGui.QColor(255, 0, 0))
        self.dicom_sagittal_view = DicomSagittalView(
            roi_color=roi_color_dict, iso_color=iso_color_dict,
            cut_line_color=QtGui.QColor(0, 255, 0))
        self.dicom_coronal_view = DicomCoronalView(
            roi_color=roi_color_dict, iso_color=iso_color_dict,
            cut_line_color=QtGui.QColor(0, 0, 255))
        self.three_dimension_view = DicomView3D()

        # Rescale the size of the scenes inside the 3-slice views
        self.dicom_axial_view.zoom = INITIAL_FOUR_VIEW_ZOOM
        self.dicom_sagittal_view.zoom = INITIAL_FOUR_VIEW_ZOOM
        self.dicom_coronal_view.zoom = INITIAL_FOUR_VIEW_ZOOM
        self.dicom_axial_view.update_view(zoom_change=True)
        self.dicom_sagittal_view.update_view(zoom_change=True)
        self.dicom_coronal_view.update_view(zoom_change=True)

        self.dicom_four_views = QWidget()
        self.dicom_four_views_layout = QGridLayout()
        for i in range(2):
            self.dicom_four_views_layout.setColumnStretch(i, 1)
            self.dicom_four_views_layout.setRowStretch(i, 1)
        self.dicom_four_views_layout.addWidget(self.dicom_axial_view, 0, 0)
        self.dicom_four_views_layout.addWidget(self.dicom_sagittal_view, 0, 1)
        self.dicom_four_views_layout.addWidget(self.dicom_coronal_view, 1, 0)
        self.dicom_four_views_layout.addWidget(self.three_dimension_view, 1, 1)
        self.dicom_four_views.setLayout(self.dicom_four_views_layout)

        self.dicom_view.addWidget(self.dicom_four_views)
        self.dicom_view.addWidget(self.dicom_single_view)
        self.dicom_view.setCurrentWidget(self.dicom_single_view)

        # Add DICOM View to right panel as a tab
        self.right_panel.addTab(self.dicom_view, "DICOM View")

        # Add PETVT View to right panel as a tab
        self.pet_ct_tab = PetCtView()
        self.right_panel.addTab(self.pet_ct_tab, "PET/CT View")

        # Add DVH tab to right panel as a tab
        if patient_dict_container.has_modality("rtdose"):
            self.dvh_tab = DVHTab()
            self.right_panel.addTab(self.dvh_tab, "DVH")
        elif hasattr(self, 'dvh_tab'):
            del self.dvh_tab

        # Add DICOM Tree View tab
        self.dicom_tree = DicomTreeView()
        self.right_panel.addTab(self.dicom_tree, "DICOM Tree")

        # Connect SUV2ROI signal to handler function
        self.dicom_single_view.suv2roi_signal.connect(self.perform_suv2roi)

        # Add clinical data tab
        self.call_class.display_clinical_data(self.right_panel)

        splitter.addWidget(self.left_panel)
        splitter.addWidget(self.right_panel)

        # Create footer
        self.footer = QtWidgets.QWidget()
        self.create_footer()

        # Set layout
        self.central_widget_layout.addWidget(self.patient_bar)
        self.central_widget_layout.addWidget(splitter)
        self.central_widget_layout.addWidget(self.footer)

        self.central_widget.setLayout(self.central_widget_layout)
        self.main_window_instance.setCentralWidget(self.central_widget)

    def create_footer(self):
        self.footer.setFixedHeight(15)
        layout_footer = QtWidgets.QHBoxLayout(self.footer)
        layout_footer.setContentsMargins(0, 0, 0, 0)

        label_footer = QtWidgets.QLabel("@OnkoDICOM2021")
        label_footer.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignRight)

        layout_footer.addWidget(label_footer)

    def update_views(self, update_3d_window=False):
        """
        This function is a slot for signals to request the updating of the
        DICOM View and DVH tabs in order to reflect changes made by other
        components of the main window (for example, when a structure in the
        structures tab is selected, this method needs to be called in order
        for the DICOM view window to be updated to show the new region of
        interest.

        :param update_3d_window: a boolean to mark if 3d model
        needs to be updated
        """

        self.dicom_single_view.update_view()
        self.dicom_axial_view.update_view()
        self.dicom_coronal_view.update_view()
        self.dicom_sagittal_view.update_view()

        if update_3d_window:
            self.three_dimension_view.update_view()

        if hasattr(self, 'dvh_tab'):
            self.dvh_tab.update_plot()

        if hasattr(self, 'pet_ct_tab'):
            if self.pet_ct_tab.initialised:
                self.pet_ct_tab.update_view()

        if hasattr(self, 'image_fusion_view'):
            if self.image_fusion_view_axial is not None:
                self.image_fusion_single_view.update_view()
                self.image_fusion_view_axial.update_view()
                self.image_fusion_view_coronal.update_view()
                self.image_fusion_view_sagittal.update_view()

    def toggle_cut_lines(self):
        if self.dicom_axial_view.horizontal_view is None or \
                self.dicom_axial_view.vertical_view is None or \
                self.dicom_coronal_view.horizontal_view is None or \
                self.dicom_coronal_view.vertical_view is None or \
                self.dicom_sagittal_view.horizontal_view is None or \
                self.dicom_sagittal_view.vertical_view is None:
            self.dicom_axial_view.set_views(self.dicom_coronal_view,
                                            self.dicom_sagittal_view)
            self.dicom_coronal_view.set_views(self.dicom_axial_view,
                                              self.dicom_sagittal_view)
            self.dicom_sagittal_view.set_views(self.dicom_axial_view,
                                               self.dicom_coronal_view)
        else:
            self.dicom_axial_view.set_views(None, None)
            self.dicom_coronal_view.set_views(None, None)
            self.dicom_sagittal_view.set_views(None, None)

        if hasattr(self, 'image_fusion_view'):
            if self.image_fusion_view is not None:
                if self.image_fusion_view_axial.horizontal_view is None or \
                        self.image_fusion_view_axial.vertical_view is None or \
                        self.image_fusion_view_coronal.horizontal_view is None \
                        or self.image_fusion_view_coronal.vertical_view is None \
                        or \
                        self.image_fusion_view_sagittal.horizontal_view is None \
                        or \
                        self.image_fusion_view_sagittal.vertical_view is None:
                    self.image_fusion_view_axial.set_views(
                        self.image_fusion_view_coronal,
                        self.image_fusion_view_sagittal)
                    self.image_fusion_view_coronal.set_views(
                        self.image_fusion_view_axial,
                        self.image_fusion_view_sagittal)

                    self.image_fusion_view_sagittal.set_views(
                        self.image_fusion_view_axial,
                        self.image_fusion_view_coronal)
                else:
                    self.image_fusion_view_axial.set_views(None, None)
                    self.image_fusion_view_coronal.set_views(None, None)
                    self.image_fusion_view_sagittal.set_views(None, None)

    def zoom_in(self, is_four_view, image_reg_single, image_reg_four):
        """
        This function calls the zooming in function on the four view's views
        or the single view depending on what view is showing on screen.
        is_four_view: Whether the four view is showing
        """
        if is_four_view:
            self.dicom_axial_view.zoom_in()
            self.dicom_coronal_view.zoom_in()
            self.dicom_sagittal_view.zoom_in()
        else:
            self.dicom_single_view.zoom_in()

        if image_reg_single:
            self.image_fusion_single_view.zoom_in()

        if image_reg_four:
            self.image_fusion_view_axial.zoom_in()
            self.image_fusion_view_coronal.zoom_in()
            self.image_fusion_view_sagittal.zoom_in()

        if self.pet_ct_tab.initialised:
            self.pet_ct_tab.zoom_in()

    def zoom_out(self, is_four_view, image_reg_single, image_reg_four):
        """
        This function calls the zooming out function on the four view's
        views or the single view depending on what view is showing on screen.
        is_four_view: Whether the four view is showing
        """
        if is_four_view:
            self.dicom_axial_view.zoom_out()
            self.dicom_coronal_view.zoom_out()
            self.dicom_sagittal_view.zoom_out()
        else:
            self.dicom_single_view.zoom_out()

        if image_reg_single:
            self.image_fusion_single_view.zoom_out()

        if image_reg_four:
            self.image_fusion_view_axial.zoom_out()
            self.image_fusion_view_coronal.zoom_out()
            self.image_fusion_view_sagittal.zoom_out()

        if self.pet_ct_tab.initialised:
            self.pet_ct_tab.zoom_out()

    def format_data(self, size):
        """
        This function is used to update the meta data's font size and margin
        based on the height and width of the viewports.
        size: The size of the DicomStackedWidget
        """
        self.dicom_axial_view.format_metadata(size)

    def create_image_fusion_tab(self):
        """
        This function is used to create the tab for image fusion.
        Function checks if the moving dict container contains rtss to
        load rtss. Views are created and stacked into three window view.
        """
        # Set a flag for Zooming
        self.action_handler.has_image_registration_four = True

        # Instance of Moving Model
        moving_dict_container = MovingDictContainer()

        if moving_dict_container.has_modality("rtss"):
            if len(self.structures_tab.rois.items()) == 0:
                self.structures_tab.update_ui(moving=True)
            # else:
            # TODO: Display both ROIs in the same tab

        self.image_fusion_single_view \
            = ImageFusionAxialView()

        self.image_fusion_view = QStackedWidget()
        self.image_fusion_view_axial = ImageFusionAxialView(
            metadata_formatted=False,
            cut_line_color=QtGui.QColor(255, 0, 0))
        self.image_fusion_view_sagittal = ImageFusionSagittalView(
            cut_line_color=QtGui.QColor(0, 255, 0))
        self.image_fusion_view_coronal = ImageFusionCoronalView(
            cut_line_color=QtGui.QColor(0, 0, 255))
        self.image_fusion_roi_transfer_option_view = ROITransferOptionView(
            self.structures_tab.fixed_container_structure_modified,
            self.structures_tab.moving_container_structure_modified)

        # Rescale the size of the scenes inside the 3-slice views
        self.image_fusion_view_axial.zoom = INITIAL_FOUR_VIEW_ZOOM
        self.image_fusion_view_sagittal.zoom = INITIAL_FOUR_VIEW_ZOOM
        self.image_fusion_view_coronal.zoom = INITIAL_FOUR_VIEW_ZOOM
        self.image_fusion_view_axial.update_view(zoom_change=True)
        self.image_fusion_view_sagittal.update_view(zoom_change=True)
        self.image_fusion_view_coronal.update_view(zoom_change=True)

        self.image_fusion_four_views = QWidget()
        self.image_fusion_four_views_layout = QGridLayout()
        for i in range(2):
            self.image_fusion_four_views_layout.setColumnStretch(i, 1)
            self.image_fusion_four_views_layout.setRowStretch(i, 1)
        self.image_fusion_four_views_layout.addWidget(
            self.image_fusion_view_axial, 0, 0)
        self.image_fusion_four_views_layout.addWidget(
            self.image_fusion_view_sagittal, 0, 1)
        self.image_fusion_four_views_layout.addWidget(
            self.image_fusion_view_coronal, 1, 0)

        self.image_fusion_four_views_layout.addWidget(
            self.image_fusion_roi_transfer_option_view, 1, 1
        )
        self.image_fusion_four_views.setLayout(
            self.image_fusion_four_views_layout)

        self.image_fusion_view.addWidget(self.image_fusion_four_views)
        self.image_fusion_view.addWidget(self.image_fusion_single_view)
        self.image_fusion_view.setCurrentWidget(self.image_fusion_four_views)

        # Add Image Fusion Tab
        self.right_panel.addTab(self.image_fusion_view, "Image Fusion")
        self.right_panel.setCurrentWidget(self.image_fusion_view)

        # Update the Add On Option GUI
        self.add_on_options_controller.update_ui()

    def perform_suv2roi(self):
        """
        Performs the SUV2ROI process.
        """
        # Get patient weight - needs to run first as GUI cannot run in
        # threads, like the ProgressBar
        patient_dict_container = PatientDictContainer()
        dataset = patient_dict_container.dataset[0]
        self.suv2roi.get_patient_weight(dataset)
        if self.suv2roi.patient_weight is None:
            return

        # Start the SUV2ROI process
        self.suv2roi_progress_window.start(self.suv2roi.start_conversion)

    def on_loaded_suv2roi(self):
        """
        Called when progress bar has finished. Closes the progress
        window and refreshes the main screen.
        """
        if self.suv2roi.suv2roi_status:
            patient_dict_container = PatientDictContainer()
            self.structures_tab.fixed_container_structure_modified((
                patient_dict_container.get('dataset_rtss'), {"draw": None}))
        else:
            # Alert user that SUV2ROI failed and for what reason
            if self.suv2roi.failure_reason == "UNIT":
                failure_reason = \
                    "PET units are not Bq/mL. OnkoDICOM can currently only\n" \
                    "perform SUV2ROI on PET images stored in these units."
            elif self.suv2roi.failure_reason == "DECY":
                failure_reason = \
                    "PET is not decay corrected. OnkoDICOM can currently " \
                    "only\nperform SUV2ROI on PET images that are decay " \
                    "corrected."
            else:
                failure_reason = "The SUV2ROI process has failed."
            button_reply = \
                QtWidgets.QMessageBox(
                    QtWidgets.QMessageBox.Icon.Warning,
                    "SUV2ROI Failed",
                    failure_reason,
                    QtWidgets.QMessageBox.StandardButton.Ok, self)
            button_reply.button(
                QtWidgets.QMessageBox.StandardButton.Ok).setStyleSheet(
                self.stylesheet)
            button_reply.exec_()

        # Close progress window
        self.suv2roi_progress_window.close()
示例#5
0
class MainWindow(QMainWindow):
    def __init__(self, stages: list[Stage], *args, **kwargs):
        QMainWindow.__init__(self, *args, **kwargs)
        if not self.objectName():
            self.setObjectName("MainWindow")
        self.resize(800, 600)
        size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        size_policy.setHorizontalStretch(0)
        size_policy.setVerticalStretch(0)
        size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(size_policy)
        self.setWindowTitle("Interfan")

        self.central_widget = QWidget(self)
        self.central_widget.setObjectName("central_widget")

        self.main_horizontal_layout = QHBoxLayout(self.central_widget)
        self.main_horizontal_layout.setObjectName("main_horizontal_layout")

        self.left_grid_layout = QGridLayout()
        self.left_grid_layout.setObjectName("left_grid_layout")

        self.slice_slider = QSlider(self.central_widget)
        self.slice_slider.setObjectName("slice_slider")
        self.slice_slider.setEnabled(False)
        self.slice_slider.setOrientation(Qt.Horizontal)

        self.left_grid_layout.addWidget(self.slice_slider, 1, 0, 1, 1)

        self.slice_label = QLabel(self.central_widget)
        self.slice_label.setObjectName("slice_label")
        self.slice_label.setGeometry(QRect(0, 10, 58, 18))
        self.slice_label.setText("0")
        self.left_grid_layout.addWidget(self.slice_label, 1, 1, 1, 1)

        self.main_image_scene = QGraphicsScene()
        self.main_image_view = QGraphicsView(self.main_image_scene)
        self.main_image_view.setObjectName("main_image_view")
        self.left_grid_layout.addWidget(self.main_image_view, 0, 0, 1, 1)

        self.slice_image_scene = QGraphicsScene()
        self.slice_image_view = QGraphicsView(self.slice_image_scene)
        self.slice_image_view.setObjectName("slice_image_view")
        self.left_grid_layout.addWidget(self.slice_image_view, 0, 1, 1, 1)

        self.left_grid_layout.setRowStretch(0, 12)
        self.left_grid_layout.setRowStretch(1, 1)
        self.left_grid_layout.setColumnStretch(0, 6)
        self.left_grid_layout.setColumnStretch(1, 1)

        self.main_horizontal_layout.addLayout(self.left_grid_layout)

        self.right_vertical_layout = QVBoxLayout()
        self.right_vertical_layout.setObjectName("right_vertical_layout")

        self.settings_widget = SettingWidget(self.central_widget)
        self.right_vertical_layout.addWidget(self.settings_widget.group_box)

        self.proceed_button = QPushButton(self.central_widget)
        self.proceed_button.setObjectName("proceed_button")
        self.proceed_button.setText("Выполнить")
        self.proceed_button.setEnabled(False)
        self.right_vertical_layout.addWidget(self.proceed_button)

        self.right_down_layout = QHBoxLayout()
        self.right_down_layout.setObjectName("right_down_layout")
        self.stages_layout = QVBoxLayout()
        self.stages_layout.setObjectName("stages_layout")

        self.stages_label = QLabel(self.central_widget)
        self.stages_label.setObjectName("stages_label")
        self.stages_label.setText("Этапы")
        self.stages_layout.addWidget(self.stages_label, 1)

        self.stages_radio_buttons = []
        for s in stages:
            rb = QRadioButton(self.central_widget)
            rb.setObjectName("stages_radio_button")
            rb.setEnabled(False)
            rb.setText(s.name)
            self.stages_layout.addWidget(rb, 1)
            self.stages_radio_buttons.append(rb)

        self.stages_radio_buttons[0].setEnabled(True)
        self.stages_radio_buttons[0].setChecked(True)
        self.set_stage(stages[0])

        self.right_down_layout.addLayout(self.stages_layout)

        self.history_layout = QVBoxLayout()
        self.history_layout.setObjectName("history_layout")
        self.history_header_layout = QHBoxLayout()
        self.history_header_layout.setObjectName("history_header_layout")

        self.history_label = QLabel(self.central_widget)
        self.history_label.setObjectName("history_label")
        self.history_label.setText("История операций")
        self.history_header_layout.addWidget(self.history_label)

        self.history_minus_button = QToolButton(self.central_widget)
        self.history_minus_button.setObjectName("history_minus_button")
        self.history_minus_button.setEnabled(False)
        self.history_minus_button.setText("-")
        self.history_header_layout.addWidget(self.history_minus_button)

        self.history_header_layout.setStretch(0, 8)
        self.history_header_layout.setStretch(1, 1)

        self.history_layout.addLayout(self.history_header_layout)

        self.history_list_view = QListView(self.central_widget)
        self.history_list_view.setObjectName("history_list_view")
        self.history_layout.addWidget(self.history_list_view)

        self.history_script_button = QPushButton(self.central_widget)
        self.history_script_button.setObjectName("history_script_button")
        self.history_script_button.setText("Просмотреть как скрипт")
        self.history_layout.addWidget(self.history_script_button)

        self.right_down_layout.addLayout(self.history_layout)

        self.right_down_layout.setStretch(0, 1)
        self.right_down_layout.setStretch(1, 1)

        self.right_vertical_layout.addLayout(self.right_down_layout)
        self.right_vertical_layout.setStretch(0, 1)
        self.right_vertical_layout.setStretch(1, 0)
        self.right_vertical_layout.setStretch(2, 1)

        self.main_horizontal_layout.addLayout(self.right_vertical_layout)
        self.main_horizontal_layout.setStretch(0, 1)
        self.main_horizontal_layout.setStretch(1, 1)

        self.setCentralWidget(self.central_widget)
        self.menu_bar = QMenuBar(self)
        self.menu_bar.setObjectName("menu_bar")
        self.menu_bar.setGeometry(QRect(0, 0, 800, 30))
        self.menu = QMenu(self.menu_bar)
        self.menu.setObjectName("men")
        self.menu.setTitle("Меню")
        self.setMenuBar(self.menu_bar)

        self.open_file = QAction(self)
        self.open_file.setObjectName("open_file")
        self.open_file.setText("Открыть файл")
        self.menu.addAction(self.open_file)

        self.status_bar = QStatusBar(self)
        self.status_bar.setObjectName("status_bar")
        self.setStatusBar(self.status_bar)

        self.menu_bar.addAction(self.menu.menuAction())

        QMetaObject.connectSlotsByName(self)

    def set_stage(self, stage: Stage):
        self.settings_widget.change_settings(stage.settings)