Пример #1
0
    def create_buttons(self):
        """
        Create buttons to create and delete ROIs from isodose.
        """
        # Buttons
        self.window.add_new_roi = QtWidgets.QPushButton(self.window.widget)
        self.window.delete_roi = QtWidgets.QPushButton(self.window.widget)

        # Set cursor
        self.window.add_new_roi.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.window.delete_roi.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))

        # Set visibility
        self.window.add_new_roi.setVisible(False)
        self.window.delete_roi.setVisible(False)

        # Set style
        self.window.add_new_roi.setProperty("QPushButtonClass",
                                            "success-button")
        self.window.delete_roi.setProperty("QPushButtonClass", "fail-button")

        # Set text
        _translate = QtCore.QCoreApplication.translate
        self.window.add_new_roi.setText(
            _translate("Add_On_Options", "Add new Isodose"))
        self.window.delete_roi.setText(
            _translate("Add_On_Options", "Remove Isodose"))
Пример #2
0
    def create_change_default_directory_frame(self):
        config = Configuration()
        default_directory = None
        try:
            default_directory = config.get_default_directory()
        except SqlError:
            config.set_up_config_db()
            QtWidgets.QMessageBox.critical(
                self.window, "Config file error",
                """Failed to access configuration file.
                \nConfiguration file recreated with no default directory.
                \nPlease update your default directory.""")

        self.window.change_default_directory_frame = QtWidgets.QFrame()
        self.window.change_default_directory_frame.setVisible(False)
        self.change_default_directory_vertical_layout = QtWidgets.QVBoxLayout()
        self.change_default_directory_prompt = QtWidgets.QLabel()
        self.change_default_directory_prompt.setAlignment(QtCore.Qt.AlignLeft)
        self.change_default_directory_prompt.setVisible(True)
        self.change_default_directory_prompt.setText(
            "Default directory's path:")
        self.change_default_directory_vertical_layout.addWidget(
            self.change_default_directory_prompt)
        # Create a horizontal box to hold the input box for the
        # directory and the choose button
        self.change_default_directory_input_horizontal_box = \
            QtWidgets.QHBoxLayout()

        # Create a textbox to contain the path to the directory that
        # contains the DICOM files
        self.change_default_directory_input_box = \
            UIChangeDefaultDirDragAndDropEvent(self)
        self.change_default_directory_input_box.setCursorPosition(0)
        self.change_default_directory_input_box.setText(default_directory)
        self.change_default_directory_input_horizontal_box.addWidget(
            self.change_default_directory_input_box)

        # Create a choose button to open the file dialog
        self.change_default_directory_button = QtWidgets.QPushButton()
        self.change_default_directory_button.setText("Change")
        self.change_default_directory_button.resize(
            self.change_default_directory_button.sizeHint().width(),
            self.change_default_directory_input_box.height())
        self.change_default_directory_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.change_default_directory_input_horizontal_box.addWidget(
            self.change_default_directory_button)
        self.change_default_directory_button.clicked.connect(
            self.change_button_clicked)

        # Create a widget to hold the input fields
        self.change_default_directory_input_widget = QtWidgets.QWidget()
        self.change_default_directory_input_horizontal_box.setStretch(0, 4)
        self.change_default_directory_input_widget.setLayout(
            self.change_default_directory_input_horizontal_box)
        self.change_default_directory_vertical_layout.addWidget(
            self.change_default_directory_input_widget, 1, QtCore.Qt.AlignTop)

        self.window.change_default_directory_frame.setLayout(
            self.change_default_directory_vertical_layout)
Пример #3
0
    def _submit_neutron(self) -> None:
        """Submit a neutron plotter request to spansh."""
        log.info("Submitting neutron job.")
        self._abort_request()

        self._current_network_reply = SpanshReplyTracker(self)
        self._current_network_reply.make_request(
            SPANSH_API_URL + "/route",
            params={
                "efficiency": self.spansh_neutron_tab.efficiency_spin.value,
                "range": self.spansh_neutron_tab.range_spin.value,
                "from": self.spansh_neutron_tab.source_edit.text,
                "to": self.spansh_neutron_tab.target_edit.text,
            },
            finished_callback=partial(
                self._current_network_reply.spansh_neutron_callback,
                error_callback=self._spansh_error_callback,
                delay_iterator=create_request_delay_iterator(),
                result_callback=partial(self.emit_and_close,
                                        self.selected_journal,
                                        route_index=1),
            ),
        )
        self.cursor = QtGui.QCursor(QtCore.Qt.CursorShape.BusyCursor)
        self.switch_submit_abort()
Пример #4
0
 def on_item_triggered(self, pos: QPoint):
     index = self.fileTreeView.indexAt(pos)
     if index == EssModelIndex():
         return
     item = get_item_by_index(index.sibling(index.row(), 0),
                              self.__ess_file_model)
     self.__trigger_menu = TriggerMenu(self, item)
     if item.ss_type == "project":
         self.__trigger_menu.enable_slots(
             open_in_folder=self.open_in_folder,
             rename=self.rename,
         )
     elif item.ss_type == "file":
         self.__trigger_menu.enable_slots(
             open_in_folder=self.open_in_folder,
             edit=self.try_edit,
             checkout=self.try_checkout,
             checkin=self.try_checkin,
             uncheckout=self.try_uncheckout,
             rename=self.rename,
         )
     else:
         raise RuntimeError()
     self.__trigger_menu.move(QtGui.QCursor().pos())
     self.__trigger_menu.show()
Пример #5
0
    def _assign_from_reply(self, reply: QtNetwork.QNetworkReply) -> None:
        """Decode the spansh JSON reply and display the data to the user."""
        self.cursor = QtGui.QCursor(QtCore.Qt.CursorShape.BusyCursor)
        self._current_network_request = None

        try:
            data = json_from_network_req(reply, json_error_key="error")
        except NetworkError as e:
            if (e.error_type is
                    QtNetwork.QNetworkReply.NetworkError.OperationCanceledError
                ):
                return

            if e.reply_error is not None:
                message = _("Received error from Spansh: {}").format(
                    e.reply_error)
            else:
                # Fall back to Qt error message if spansh didn't respond
                message = e.error_message
            self._status_callback.show_message(message, 10_000)
        else:
            self.system_name_result_label.text = data["system"]["name"]
            self.distance_result_label.text = (format(
                data["system"]["distance"], ".2f").rstrip("0").rstrip(".") +
                                               " Ly")

            self.x_result_label.text = (format(data["system"]["x"],
                                               ".2f").rstrip("0").rstrip("."))
            self.y_result_label.text = (format(data["system"]["y"],
                                               ".2f").rstrip("0").rstrip("."))
            self.z_result_label.text = (format(data["system"]["z"],
                                               ".2f").rstrip("0").rstrip("."))
Пример #6
0
    def run_context_menu(self, pos):
        curr_obj = self.table.get_current_object()
        if (curr_obj is None) or (not isinstance(curr_obj, RootModel)):
            return

        menu = QtWidgets.QMenu(self.table_view)
        menu.addAction("Delete", lambda x=curr_obj: self.delete_root_row(x))
        menu.exec_(QtGui.QCursor().pos())
Пример #7
0
 def _abort_request(self) -> None:
     """Abort the current network request, if any."""
     if self._current_network_reply is not None:
         self._current_network_reply.abort()
         self.switch_submit_abort()
         self._show_status_message("Cancelled route plot.", 2_500)
     self._current_network_reply = None
     self.cursor = QtGui.QCursor(QtCore.Qt.CursorShape.ArrowCursor)
Пример #8
0
 def create_cancel_button(self):
     """
     Create CANCEL button for the whole window.
     """
     self.cancel_button = QtWidgets.QPushButton(self.widget)
     self.cancel_button.setCursor(
         QtGui.QCursor(QtCore.Qt.PointingHandCursor))
     _translate = QtCore.QCoreApplication.translate
     self.cancel_button.setText(_translate("Add_On_Options", "Cancel"))
Пример #9
0
 def create_apply_button(self):
     """
     Create APPLY button to save all changes made.
     """
     self.apply_button = QtWidgets.QPushButton(self.widget)
     self.apply_button.setCursor(QtGui.QCursor(
         QtCore.Qt.PointingHandCursor))
     _translate = QtCore.QCoreApplication.translate
     self.apply_button.setText(_translate("Add_On_Options", "Apply"))
Пример #10
0
    def create_buttons(self):
        """
        Create a button to add a new window view and delete a window view
        """
        self.window.add_new_window = QtWidgets.QPushButton(self.window.widget)
        self.window.delete_window = QtWidgets.QPushButton(self.window.widget)

        self.window.add_new_window.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.window.add_new_window.setVisible(False)
        self.window.delete_window.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.window.delete_window.setVisible(False)

        _translate = QtCore.QCoreApplication.translate
        self.window.add_new_window.setText(
            _translate("Add_On_Options", "Add New Window"))
        self.window.delete_window.setText(
            _translate("Add_On_Options", "Delete Window"))
Пример #11
0
 def create_edit_button(self):
     """
     Create Edit button.
     """
     self.Edit_button = QtWidgets.QPushButton()
     self.Edit_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
     icon_edit = QtGui.QIcon()
     icon_edit.addPixmap(
         QtGui.QPixmap(resource_path('res/images/btn-icons/draw_icon.png')),
         QtGui.QIcon.Normal, QtGui.QIcon.On)
     self.Edit_button.setIcon(icon_edit)
Пример #12
0
    def create_add_button(self):
        """
        Create a button to create a new ROI from isodose.
        """
        self.window.add_new_roi = QtWidgets.QPushButton(self.window.widget)
        self.window.add_new_roi.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.window.add_new_roi.setVisible(False)

        _translate = QtCore.QCoreApplication.translate
        self.window.add_new_roi.setText(
            _translate("Add_On_Options", "Add new Isodose"))
Пример #13
0
 def create_add_button(self):
     """
     Create a button to add a new standard volume name.
     """
     self.window.add_standard_volume_name = QtWidgets.QPushButton(
         self.window.widget)
     self.window.add_standard_volume_name.setCursor(
         QtGui.QCursor(QtCore.Qt.PointingHandCursor))
     self.window.add_standard_volume_name.setVisible(False)
     _translate = QtCore.QCoreApplication.translate
     self.window.add_standard_volume_name.setText(
         _translate("Add_On_Options", "Add Standard Name"))
Пример #14
0
 def create_import_csv_button(self):
     """
     Create a button to import a csv of standard organs.
     """
     self.window.import_organ_csv = QtWidgets.QPushButton(
         self.window.widget)
     self.window.import_organ_csv.setCursor(
         QtGui.QCursor(QtCore.Qt.PointingHandCursor))
     self.window.import_organ_csv.setVisible(False)
     _translate = QtCore.QCoreApplication.translate
     self.window.import_organ_csv.setText(
         _translate("Add_On_Options", "Import Spreadsheet"))
Пример #15
0
 def _make_nearest_request(self) -> None:
     """Make a request to Spansh's nearest endpoint with the values from spinboxes."""
     self._abort_request()
     self._current_network_request = make_network_request(
         SPANSH_API_URL + "/nearest",
         params={
             "x": self.x_spinbox.value,
             "y": self.y_spinbox.value,
             "z": self.z_spinbox.value,
         },
         finished_callback=self._assign_from_reply,
     )
     self.cursor = QtGui.QCursor(QtCore.Qt.CursorShape.BusyCursor)
Пример #16
0
 def create_save_button(self):
     """
     Create Save Button.
     """
     self.Save_button = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
     self.Save_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
     icon_save = QtGui.QIcon()
     icon_save.addPixmap(
         QtGui.QPixmap(resource_path('res/images/btn-icons/save_icon.png')),
         QtGui.QIcon.Normal,
         QtGui.QIcon.On
     )
     self.Save_button.setIcon(icon_save)
Пример #17
0
    def __init__(self, item_id=None, label=None, *args, **kwargs):
        super(Preset, self).__init__(*args, **kwargs)
        self.label = label or ""
        self.item_id = item_id or ""
        self.setToolTip(self.item_id)
        self.main_layout = QtWidgets.QHBoxLayout(self)
        self.main_layout.setContentsMargins(5, 5, 5, 5)
        self.main_layout.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignTop)

        self._build_ui()
        self._layout()
        self._setup_ui()
        self.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Пример #18
0
    def __init__(self, item_id=None, label=None, *args, **kwargs):
        super(Item, self).__init__(*args, **kwargs)
        self.label = label or ""
        self.item_id = item_id or ""
        self.setToolTip(self.item_id)
        self.setMinimumSize(QtCore.QSize(ITEM_SIZE, ITEM_SIZE))
        self.setMaximumSize(QtCore.QSize(ITEM_SIZE, ITEM_SIZE))
        self.main_layout = QtWidgets.QVBoxLayout(self)
        self.main_layout.setContentsMargins(5, 5, 5, 5)
        self.main_layout.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignTop)

        self._build_ui()
        self._layout()
        self.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
Пример #19
0
    def create_buttons(self):
        """
        Create buttons to create and delete ROIs from isodose.
        """
        # Button layout
        self.button_layout = QtWidgets.QHBoxLayout()

        # Buttons
        self.add_new_roi = QtWidgets.QPushButton(self)
        self.delete_roi = QtWidgets.QPushButton(self)

        # Set cursor
        self.add_new_roi.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.delete_roi.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))

        # Set button class
        self.add_new_roi.setProperty("QPushButtonClass", "success-button")
        self.delete_roi.setProperty("QPushButtonClass", "fail-button")

        # Set button stylesheet
        self.add_new_roi.setStyleSheet(self.stylesheet)
        self.delete_roi.setStyleSheet(self.stylesheet)

        # Set text
        _translate = QtCore.QCoreApplication.translate
        self.add_new_roi.setText(
            _translate("Add_On_Options", "Add new Isodose"))
        self.delete_roi.setText(_translate("Add_On_Options", "Remove Isodose"))

        # Add buttons to the layout
        self.button_layout.addWidget(self.delete_roi)
        self.button_layout.addWidget(self.add_new_roi)
        self.main_layout.addLayout(self.button_layout)

        # Connect button clicked events to functions
        self.add_new_roi.clicked.connect(self.new_isodose)
        self.delete_roi.clicked.connect(self.remove_isodose)
Пример #20
0
    def _build_ui(self):
        # Main
        self.main_widget = QtWidgets.QFrame(self)
        self.main_layout = QtWidgets.QVBoxLayout(self.main_widget)
        self.main_layout.setContentsMargins(5, 5, 5, 5)

        # Search
        self.top_bar_frame = QtWidgets.QFrame(self)
        self.top_bar_layout = QtWidgets.QHBoxLayout(self.top_bar_frame)
        self.top_bar_layout.setContentsMargins(0, 0, 0, 0)
        self.search_lineedit = QtWidgets.QLineEdit(self.top_bar_frame)
        self.search_lineedit.setPlaceholderText("Search...")
        self.refresh_presets_button = QtWidgets.QPushButton(self.top_bar_frame)
        self.refresh_presets_button.setIcon(QtGui.QIcon(":TOP_BAR_REFRESH"))
        self.refresh_presets_button.setObjectName("refresh_button")
        self.refresh_presets_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.refresh_presets_button.setToolTip("Refresh Presets")

        # Tab widget
        self.tab_widget = QtWidgets.QTabWidget(self.main_widget)

        self.search_scroll = QtWidgets.QScrollArea(self.main_widget)
        self.search_scroll.setWidgetResizable(True)
        self.search_scroll.setVisible(False)

        self.search_tab_widget = QtWidgets.QTabWidget(self.search_scroll)
        self.search_scroll.setWidget(self.search_tab_widget)

        # Search Parts
        self.search_parts_scroll = QtWidgets.QScrollArea(
            self.search_tab_widget)
        self.search_parts_scroll.setWidgetResizable(True)
        self.search_parts_frame = QtWidgets.QFrame(self.search_parts_scroll)
        self.search_frame_layout = FlowLayout(parent=self.search_parts_frame)
        self.search_parts_scroll.setWidget(self.search_parts_frame)
        self.search_tab_widget.addTab(self.search_parts_scroll, "Parts")

        # Search presets
        self.search_presets_scroll = QtWidgets.QScrollArea(
            self.search_tab_widget)
        self.search_presets_scroll.setWidgetResizable(True)
        self.search_presets_frame = QtWidgets.QFrame(
            self.search_presets_scroll)
        self.search_presets_layout = QtWidgets.QVBoxLayout(
            self.search_presets_frame)
        self.search_presets_layout.setAlignment(QtCore.Qt.AlignTop)
        self.search_presets_scroll.setWidget(self.search_presets_frame)
        self.search_tab_widget.addTab(self.search_presets_scroll, "Presets")
Пример #21
0
    def __init__(self, label=None, layout="flow", *args, **kwargs):
        super(CollapsableFrame, self).__init__(*args, **kwargs)
        self.main_layout = QtWidgets.QVBoxLayout(self)
        self.main_layout.setContentsMargins(1, 1, 1, 1)

        self.label = label or ""
        self.button = QtWidgets.QPushButton(self.label, self)
        self.button.clicked.connect(self.toggle_visibility)
        self.button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.inner_frame = QtWidgets.QFrame(self)
        if layout == "flow":
            self.inner_frame_layout = FlowLayout(self.inner_frame)
        if layout == "vertical":
            self.inner_frame_layout = QtWidgets.QVBoxLayout(self.inner_frame)
        self.inner_frame_layout.setAlignment(QtCore.Qt.AlignLeft)
        self.inner_frame_layout.setContentsMargins(5, 5, 5, 5)
        self.main_layout.addWidget(self.button)
        self.main_layout.addWidget(self.inner_frame)
Пример #22
0
    def contextMenuEvent(self, event):
        cursor = QtGui.QCursor()
        # origin = self.mapFromGlobal(cursor.pos())
        pos = self.mapFromGlobal(cursor.pos())
        item = self.itemAt(event.pos())

        if item:
            if isinstance(item, Node):

                print("Found Node", item)

                menu = QtWidgets.QMenu(self)

                hello_action = QtWidgets.QAction("Hello", self)

                menu.addAction(hello_action)
                action = menu.exec_(self.mapToGlobal(pos))

                if action == hello_action:
                    print("Hello")
Пример #23
0
def atomic_widget_factory(component: str, title: str):
    """
    Factory function for generating various subclasses of `PySide6.QtWidgets.QWidget` pre-configured for application display.

    Parameters
    ----------
    1. **component**: ``str``
        Allowable values: `title`, `subtitle`, `heading`, `label`, `error`, `text`, `splash`, `calculate-button`, `clear-button`, `hide-button`, `download-button`, `source-button`, `package-button`, `documentation-button`, `button`, `save-dialog`, `table`, `table-item`, `figure`, `menu-bar`. If `component=None` is provided, a `PySide6.QtWidgets.QWidget` will be constructed with a `PySide6.QtWidgets.QHBoxLayout` will be returned.
    """
    if component in ['title', 'subtitle', 'heading', 'label', 'error', 'text']:
        widget = QtWidgets.QLabel(title)
        if component in ['title', 'subtitle', 'label']:
            widget.setAlignment(QtCore.Qt.AlignTop)
        elif component in ['heading']:
            widget.setAlignment(QtCore.Qt.AlignLeft)
        elif component in ['error']:
            widget.setAlignment(QtCore.Qt.AlignHCenter)
        elif component in ['text']:
            widget.setAlignment(QtCore.Qt.AlignBottom)
        widget.setObjectName(component)

    elif component in ['splash']:
        widget = QtWidgets.QLabel(utilities.load_html_template(component))
        widget.setAlignment(QtCore.Qt.AlignTop)
        widget.setSizePolicy(QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Maximum))
        widget.setWordWrap(True)
        widget.setOpenExternalLinks(True)

    elif component in ['calculate-button', 'clear-button', 'hide-button',
                       'download-button', 'source-button', 'package-button',
                       'documentation-button', 'button']:
        # buttons with text
        if format not in ['hide-button', 'download-button', 'source-button']:
            widget = QtWidgets.QPushButton(title)
            widget.setSizePolicy(QtWidgets.QSizePolicy(
                QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Maximum))

        # icon buttons
        else:
            widget = QtWidgets.QPushButton()
            widget.setSizePolicy(QtWidgets.QSizePolicy(
                QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum))
            if component == 'hide-button':
                widget.setToolTip('Hide')
            elif component == 'download-button':
                widget.setToolTip('Save As')
            elif component == 'source-button':
                widget.setToolTip('View Source')
            elif component == 'package-button':
                widget.setToolTip('View PyPi Package')
            elif component == 'documentation-button':
                widget.setToolTip('View Documentation')

        widget.setAutoDefault(True)
        widget.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        widget.setObjectName(component)

    elif component in ['save-dialog']:
        widget = QtWidgets.QFileDialog()
        widget.setFileMode(QtWidgets.QFileDialog.AnyFile)
        widget.setViewMode(QtWidgets.QFileDialog.Detail)
        widget.setNameFilter(title)
        widget.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)

    elif component == 'table':
        widget = QtWidgets.QTableWidget()
        widget.setHorizontalHeader(QtWidgets.QHeaderView(QtCore.Qt.Horizontal))
        widget.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
        widget.setVerticalHeader(QtWidgets.QHeaderView(QtCore.Qt.Vertical))
        widget.setSizeAdjustPolicy(
            QtWidgets.QAbstractScrollArea.AdjustToContents)
        widget.setSizePolicy(QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum))
        # widget.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
        widget.setObjectName(component)

    elif component == 'table-item':
        widget = QtWidgets.QTableWidgetItem(title)
        widget.setTextAlignment(QtCore.Qt.AlignHCenter)

    elif component == 'figure':
        widget = QtWidgets.QLabel()
        widget.setAlignment(QtCore.Qt.AlignCenter)
        widget.setSizePolicy(QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding))
        widget.setObjectName(component)

    elif component == 'menu-bar':
        widget = QtWidgets.QMenuBar(title)

    else:
        widget = QtWidgets.QWidget()
        widget.setLayout(QtWidgets.QHBoxLayout())
        widget.setSizePolicy(QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum))

    return widget
Пример #24
0
    def setup_ui(self, first_time_welcome_window_instance):
        self.filepath = ""
        if platform.system() == 'Darwin':
            self.stylesheet_path = "res/stylesheet.qss"
        else:
            self.stylesheet_path = "res/stylesheet-win-linux.qss"

        window_icon = QtGui.QIcon()
        window_icon.addPixmap(
            QtGui.QPixmap(resource_path("res/images/icon.ico")),
            QtGui.QIcon.Normal, QtGui.QIcon.Off)  # adding icon
        first_time_welcome_window_instance.setObjectName(
            "FirstTimeWelcomeWindowInstance")
        first_time_welcome_window_instance.setWindowIcon(window_icon)
        first_time_welcome_window_instance.setFixedSize(840, 530)

        # Create a vertical layout to manage layout in a vertical manner
        self.window_vertical_layout_box = QVBoxLayout()
        self.window_vertical_layout_box.setObjectName(
            "FirstTimeWelcomeWindowInstanceVerticalLayoutBox")

        # Create a horizontal box to hold the Onko logo & welcome message
        self.first_time_welcome_logo_message_horizontal_box = QHBoxLayout()
        self.first_time_welcome_logo_message_horizontal_box.setObjectName(
            "FirstTimeWelcomeLogoMessageBox")

        # Set up the Logo Holder
        self.logo_holder = QtWidgets.QHBoxLayout()
        self.first_time_welcome_logo = QtWidgets.QLabel()
        self.first_time_welcome_logo.setPixmap(
            QtGui.QPixmap(resource_path("res/images/image.png")))
        self.first_time_welcome_logo.setScaledContents(True)
        self.first_time_welcome_logo.setObjectName(
            "FirstTimeWelcomeWindowLogo")
        self.first_time_welcome_logo.setFixedSize(240, 130)
        self.logo_holder.addWidget(self.first_time_welcome_logo)
        self.first_time_welcome_logo_message_horizontal_box.addLayout(
            self.logo_holder)

        # Create a vertical box to hold the welcome message
        self.first_time_welcome_message_vertical_box = QVBoxLayout()
        self.first_time_welcome_message_vertical_box.setObjectName(
            "FirstTimeWelcomeWindowWelcomeMessage")

        # Set up the Label
        self.first_time_welcome_message_label = QtWidgets.QLabel()
        self.first_time_welcome_message_label.setObjectName(
            "FirstTimeWelcomeWindowLabel")
        self.first_time_welcome_message_label.setAlignment(Qt.AlignLeft)
        self.first_time_welcome_message_vertical_box.addWidget(
            self.first_time_welcome_message_label)

        # Set up the Slogan
        self.first_time_welcome_message_slogan = QtWidgets.QLabel()
        self.first_time_welcome_message_slogan.setObjectName(
            "FirstTimeWelcomeWindowSlogan")
        self.first_time_welcome_message_slogan.setAlignment(Qt.AlignLeft)
        self.first_time_welcome_message_slogan.setWordWrap(True)
        self.first_time_welcome_message_vertical_box.addWidget(
            self.first_time_welcome_message_slogan)

        self.first_time_welcome_message_slogan_widget = QWidget()
        self.first_time_welcome_message_slogan_widget.setLayout(
            self.first_time_welcome_message_vertical_box)
        self.first_time_welcome_logo_message_horizontal_box.addWidget(
            self.first_time_welcome_message_slogan_widget)

        self.first_time_welcome_logo_message_widget = QWidget()
        self.first_time_welcome_logo_message_widget.setLayout(
            self.first_time_welcome_logo_message_horizontal_box)
        self.window_vertical_layout_box.addWidget(
            self.first_time_welcome_logo_message_widget)

        # Create a label to prompt the user to enter the path to the default directory
        self.first_time_welcome_default_dir_prompt = QtWidgets.QLabel()
        self.first_time_welcome_default_dir_prompt.setObjectName(
            "FirstTimeWelcomeWindowPrompt")
        self.first_time_welcome_default_dir_prompt.setAlignment(Qt.AlignLeft)
        self.window_vertical_layout_box.addWidget(
            self.first_time_welcome_default_dir_prompt)

        # Create a horizontal box to hold the input box for the directory and the choose button
        self.first_time_welcome_input_horizontal_box = QHBoxLayout()
        self.first_time_welcome_input_horizontal_box.setObjectName(
            "FirstTimeWelcomeWindowInputHorizontalBox")

        # Create a textbox to contain the path to the default directory
        self.first_time_welcome_input_box = UIFirstTimeUserDragAndDropEvent(
            self)

        self.first_time_welcome_input_box.setObjectName(
            "FirstTimeWelcomeWindowInputBox")
        self.first_time_welcome_input_box.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.first_time_welcome_input_horizontal_box.addWidget(
            self.first_time_welcome_input_box)

        # Create a choose button to open the file dialog
        self.first_time_welcome_choose_button = QPushButton()
        self.first_time_welcome_choose_button.setObjectName(
            "FirstTimeWelcomeWindowChooseButton")
        self.first_time_welcome_choose_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.first_time_welcome_choose_button.resize(
            self.first_time_welcome_choose_button.sizeHint().width(),
            self.first_time_welcome_input_box.height())
        self.first_time_welcome_choose_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.first_time_welcome_input_horizontal_box.addWidget(
            self.first_time_welcome_choose_button)
        self.first_time_welcome_choose_button.clicked.connect(
            self.choose_button_clicked)

        # Create a widget to hold the input field
        self.first_time_welcome_input_widget = QWidget()
        self.first_time_welcome_input_horizontal_box.setStretch(0, 4)
        self.first_time_welcome_input_widget.setLayout(
            self.first_time_welcome_input_horizontal_box)
        self.window_vertical_layout_box.addWidget(
            self.first_time_welcome_input_widget)
        self.window_vertical_layout_box.addStretch(1)

        # Create widgets for the clinical data CSV file path
        self.clinical_data_csv_dir_label = QtWidgets.QLabel()
        self.clinical_data_csv_dir_label.setObjectName("ClinicalDataCSVPrompt")
        self.clinical_data_csv_dir_label.setAlignment(Qt.AlignLeft)
        self.window_vertical_layout_box.addWidget(
            self.clinical_data_csv_dir_label)

        # Create a horizontal box to hold the input box for the
        # directory and the choose button
        self.clinical_data_csv_horizontal_box = QHBoxLayout()
        self.clinical_data_csv_horizontal_box.setObjectName(
            "ClinicalDataCSVHorizontalBox")

        # Create a textbox to contain the path to the default directory
        self.clinical_data_csv_input_box = \
            UIFirstTimeUserDragAndDropEvent(self)

        self.clinical_data_csv_input_box.setObjectName(
            "ClinicalDataCSVInputBox")
        self.clinical_data_csv_input_box.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.clinical_data_csv_horizontal_box.addWidget(
            self.clinical_data_csv_input_box)

        # Create a choose button to open the file dialog
        self.clinical_data_csv_choose_button = QPushButton()
        self.clinical_data_csv_choose_button.setObjectName(
            "ClinicalDataCSVChooseButton")
        self.clinical_data_csv_choose_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.clinical_data_csv_choose_button.resize(
            self.clinical_data_csv_choose_button.sizeHint().width(),
            self.clinical_data_csv_input_box.height())
        self.clinical_data_csv_choose_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.clinical_data_csv_horizontal_box.addWidget(
            self.clinical_data_csv_choose_button)
        self.clinical_data_csv_choose_button.clicked.connect(
            self.change_clinical_data_csv_button_clicked)

        # Create a widget to hold the input field
        self.clinical_data_input_widget = QWidget()
        self.clinical_data_csv_horizontal_box.setStretch(0, 4)
        self.clinical_data_input_widget.setLayout(
            self.clinical_data_csv_horizontal_box)
        self.window_vertical_layout_box.addWidget(
            self.clinical_data_input_widget)
        self.window_vertical_layout_box.addStretch(1)

        # Create a horizontal box to hold the Skip and Confirm button
        self.first_time_window_configure_actions_horizontal_box = QHBoxLayout()
        self.first_time_window_configure_actions_horizontal_box.setObjectName(
            "FirstTimeWelcomeWindowConfigureActionsHorizontalBox")
        self.first_time_window_configure_actions_horizontal_box.addStretch(1)

        # Add a button to skip the configuration setting
        self.skip_button = QPushButton()
        self.skip_button.setObjectName("SkipButton")
        self.skip_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.skip_button.resize(self.skip_button.sizeHint().width(),
                                self.skip_button.sizeHint().height())
        self.skip_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.skip_button.setProperty("QPushButtonClass", "fail-button")
        self.first_time_window_configure_actions_horizontal_box.addWidget(
            self.skip_button)

        # Add a button to save the default directory
        self.save_dir_button = QPushButton()
        self.save_dir_button.setObjectName("SaveDirButton")
        self.save_dir_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.save_dir_button.resize(self.save_dir_button.sizeHint().width(),
                                    self.save_dir_button.sizeHint().height())
        self.save_dir_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.save_dir_button.clicked.connect(self.save_options)
        self.save_dir_button.setProperty("QPushButtonClass", "success-button")
        self.first_time_window_configure_actions_horizontal_box.addWidget(
            self.save_dir_button)

        # Create a widget to house all of the actions button for first-time window
        self.first_time_window_configure_actions_widget = QWidget()
        self.first_time_window_configure_actions_widget.setLayout(
            self.first_time_window_configure_actions_horizontal_box)
        self.window_vertical_layout_box.addWidget(
            self.first_time_window_configure_actions_widget)

        self.first_time_window_instance_central_widget = QWidget()
        self.first_time_window_instance_central_widget.setLayout(
            self.window_vertical_layout_box)
        first_time_welcome_window_instance.setCentralWidget(
            self.first_time_window_instance_central_widget)

        # Set the current stylesheet to the instance and connect it back to the caller through slot
        _stylesheet = open(resource_path(self.stylesheet_path)).read()
        first_time_welcome_window_instance.setStyleSheet(_stylesheet)
        self.retranslate_ui(first_time_welcome_window_instance)
        QtCore.QMetaObject.connectSlotsByName(
            first_time_welcome_window_instance)
Пример #25
0
    def setup_ui(self, open_patient_window_instance):
        if platform.system() == 'Darwin':
            self.stylesheet_path = "res/stylesheet.qss"
        else:
            self.stylesheet_path = "res/stylesheet-win-linux.qss"

        window_icon = QIcon()
        window_icon.addPixmap(QPixmap(resource_path("res/images/icon.ico")),
                              QIcon.Normal, QIcon.Off)
        open_patient_window_instance.setObjectName("OpenPatientWindowInstance")
        open_patient_window_instance.setWindowIcon(window_icon)
        open_patient_window_instance.resize(840, 530)

        # Create a vertical box for containing the other elements and layouts
        self.open_patient_window_instance_vertical_box = QVBoxLayout()
        self.open_patient_window_instance_vertical_box.setObjectName(
            "OpenPatientWindowInstanceVerticalBox")

        # Create a label to prompt the user to enter the path to the directory that contains the DICOM files
        self.open_patient_directory_prompt = QLabel()
        self.open_patient_directory_prompt.setObjectName(
            "OpenPatientDirectoryPrompt")
        self.open_patient_directory_prompt.setAlignment(Qt.AlignLeft)
        self.open_patient_window_instance_vertical_box.addWidget(
            self.open_patient_directory_prompt)

        # Create a horizontal box to hold the input box for the directory and the choose button
        self.open_patient_directory_input_horizontal_box = QHBoxLayout()
        self.open_patient_directory_input_horizontal_box.setObjectName(
            "OpenPatientDirectoryInputHorizontalBox")
        # Create a textbox to contain the path to the directory that contains the DICOM files
        self.open_patient_directory_input_box = UIOpenPatientWindowDragAndDropEvent(
            self)

        self.open_patient_directory_input_box.setObjectName(
            "OpenPatientDirectoryInputBox")
        self.open_patient_directory_input_box.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.open_patient_directory_input_box.returnPressed.connect(
            self.scan_directory_for_patient)
        self.open_patient_directory_input_horizontal_box.addWidget(
            self.open_patient_directory_input_box)

        # Create a choose button to open the file dialog
        self.open_patient_directory_choose_button = QPushButton()
        self.open_patient_directory_choose_button.setObjectName(
            "OpenPatientDirectoryChooseButton")
        self.open_patient_directory_choose_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.open_patient_directory_choose_button.resize(
            self.open_patient_directory_choose_button.sizeHint().width(),
            self.open_patient_directory_input_box.height())
        self.open_patient_directory_choose_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.open_patient_directory_input_horizontal_box.addWidget(
            self.open_patient_directory_choose_button)
        self.open_patient_directory_choose_button.clicked.connect(
            self.choose_button_clicked)
        # Create a widget to hold the input fields
        self.open_patient_directory_input_widget = QWidget()
        self.open_patient_directory_input_horizontal_box.setStretch(0, 4)
        self.open_patient_directory_input_widget.setLayout(
            self.open_patient_directory_input_horizontal_box)
        self.open_patient_window_instance_vertical_box.addWidget(
            self.open_patient_directory_input_widget)

        # Create a horizontal box to hold the stop button and direction to the user on where to select the patient
        self.open_patient_appear_prompt_and_stop_horizontal_box = QHBoxLayout()
        self.open_patient_appear_prompt_and_stop_horizontal_box.setObjectName(
            "OpenPatientAppearPromptAndStopHorizontalBox")
        # Create a label to show direction on where the files will appear
        self.open_patient_directory_appear_prompt = QLabel()
        self.open_patient_directory_appear_prompt.setObjectName(
            "OpenPatientDirectoryAppearPrompt")
        self.open_patient_directory_appear_prompt.setAlignment(Qt.AlignLeft)
        self.open_patient_appear_prompt_and_stop_horizontal_box.addWidget(
            self.open_patient_directory_appear_prompt)
        self.open_patient_appear_prompt_and_stop_horizontal_box.addStretch(1)
        # Create a button to stop searching
        self.open_patient_window_stop_button = QPushButton()
        self.open_patient_window_stop_button.setObjectName(
            "OpenPatientWindowStopButton")
        self.open_patient_window_stop_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.open_patient_window_stop_button.resize(
            self.open_patient_window_stop_button.sizeHint().width(),
            self.open_patient_window_stop_button.sizeHint().height())
        self.open_patient_window_stop_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.open_patient_window_stop_button.clicked.connect(
            self.stop_button_clicked)
        self.open_patient_window_stop_button.setProperty(
            "QPushButtonClass", "fail-button")
        self.open_patient_window_stop_button.setVisible(
            False)  # Button doesn't show until a search commences
        self.open_patient_appear_prompt_and_stop_horizontal_box.addWidget(
            self.open_patient_window_stop_button)
        # Create a widget to hold the layout
        self.open_patient_appear_prompt_and_stop_widget = QWidget()
        self.open_patient_appear_prompt_and_stop_widget.setLayout(
            self.open_patient_appear_prompt_and_stop_horizontal_box)
        self.open_patient_window_instance_vertical_box.addWidget(
            self.open_patient_appear_prompt_and_stop_widget)

        # Create a tree view list to list out all patients in the directory selected above
        self.open_patient_window_patients_tree = QTreeWidget()
        self.open_patient_window_patients_tree.setObjectName(
            "OpenPatientWindowPatientsTree")
        self.open_patient_window_patients_tree.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.open_patient_window_patients_tree.resize(
            self.open_patient_window_patients_tree.sizeHint().width(),
            self.open_patient_window_patients_tree.sizeHint().height())
        self.open_patient_window_patients_tree.setHeaderHidden(False)
        self.open_patient_window_patients_tree.setHeaderLabels([""])
        self.open_patient_window_patients_tree.itemChanged.connect(
            self.tree_item_changed)
        self.open_patient_window_instance_vertical_box.addWidget(
            self.open_patient_window_patients_tree)
        self.last_patient = None

        # Create a label to show what would happen if they select the patient
        self.open_patient_directory_result_label = QtWidgets.QLabel()
        self.open_patient_directory_result_label.setObjectName(
            "OpenPatientDirectoryResultLabel")
        self.open_patient_directory_result_label.setAlignment(Qt.AlignLeft)
        self.open_patient_window_instance_vertical_box.addWidget(
            self.open_patient_directory_result_label)

        # Create a horizontal box to hold the Cancel and Open button
        self.open_patient_window_patient_open_actions_horizontal_box = QHBoxLayout(
        )
        self.open_patient_window_patient_open_actions_horizontal_box.setObjectName(
            "OpenPatientWindowPatientOpenActionsHorizontalBox")
        self.open_patient_window_patient_open_actions_horizontal_box.addStretch(
            1)
        # Add a button to go back/exit from the application
        self.open_patient_window_exit_button = QPushButton()
        self.open_patient_window_exit_button.setObjectName(
            "OpenPatientWindowExitButton")
        self.open_patient_window_exit_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.open_patient_window_exit_button.resize(
            self.open_patient_window_stop_button.sizeHint().width(),
            self.open_patient_window_stop_button.sizeHint().height())
        self.open_patient_window_exit_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.open_patient_window_exit_button.clicked.connect(
            self.exit_button_clicked)
        self.open_patient_window_exit_button.setProperty(
            "QPushButtonClass", "fail-button")
        self.open_patient_window_patient_open_actions_horizontal_box.addWidget(
            self.open_patient_window_exit_button)

        # Add a button to confirm opening of the patient
        self.open_patient_window_confirm_button = QPushButton()
        self.open_patient_window_confirm_button.setObjectName(
            "OpenPatientWindowConfirmButton")
        self.open_patient_window_confirm_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.open_patient_window_confirm_button.resize(
            self.open_patient_window_confirm_button.sizeHint().width(),
            self.open_patient_window_confirm_button.sizeHint().height())
        self.open_patient_window_confirm_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.open_patient_window_confirm_button.setDisabled(True)
        self.open_patient_window_confirm_button.clicked.connect(
            self.confirm_button_clicked)
        self.open_patient_window_confirm_button.setProperty(
            "QPushButtonClass", "success-button")
        self.open_patient_window_patient_open_actions_horizontal_box.addWidget(
            self.open_patient_window_confirm_button)

        # Create a widget to house all of the actions button for open patient window
        self.open_patient_window_patient_open_actions_widget = QWidget()
        self.open_patient_window_patient_open_actions_widget.setLayout(
            self.open_patient_window_patient_open_actions_horizontal_box)
        self.open_patient_window_instance_vertical_box.addWidget(
            self.open_patient_window_patient_open_actions_widget)

        # Set the vertical box fourth element, the tree view, to stretch out as far as possible
        self.open_patient_window_instance_vertical_box.setStretch(
            3, 4)  # Stretch the treeview out as far as possible
        self.open_patient_window_instance_central_widget = QWidget()
        self.open_patient_window_instance_central_widget.setObjectName(
            "OpenPatientWindowInstanceCentralWidget")
        self.open_patient_window_instance_central_widget.setLayout(
            self.open_patient_window_instance_vertical_box)

        # Create threadpool for multithreading
        self.threadpool = QThreadPool()
        print("Multithreading with maximum %d threads" %
              self.threadpool.maxThreadCount())
        # Create interrupt event for stopping the directory search
        self.interrupt_flag = threading.Event()

        # Bind all texts into the buttons and labels
        self.retranslate_ui(open_patient_window_instance)
        # Set the central widget, ready for display
        open_patient_window_instance.setCentralWidget(
            self.open_patient_window_instance_central_widget)

        # Set the current stylesheet to the instance and connect it back to the caller through slot
        _stylesheet = open(resource_path(self.stylesheet_path)).read()
        open_patient_window_instance.setStyleSheet(_stylesheet)

        QtCore.QMetaObject.connectSlotsByName(open_patient_window_instance)
Пример #26
0
    def init_metadata(self):
        """
        Create and place metadata on the view widget.
        """
        # Position of the labels on the DICOM view.
        self.label_image_id.setAlignment(QtCore.Qt.AlignTop
                                         | QtCore.Qt.AlignTop)
        self.label_image_pos.setAlignment(QtCore.Qt.AlignTop
                                          | QtCore.Qt.AlignTop)
        self.label_wl.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignRight)
        self.label_image_size.setAlignment(QtCore.Qt.AlignBottom
                                           | QtCore.Qt.AlignBottom)
        self.label_zoom.setAlignment(QtCore.Qt.AlignBottom
                                     | QtCore.Qt.AlignBottom)
        self.label_patient_pos.setAlignment(QtCore.Qt.AlignRight
                                            | QtCore.Qt.AlignRight)

        # SUV2ROI button (only when PET is opened)
        patient_dict_container = PatientDictContainer()
        datasets = patient_dict_container.dataset
        pet_opened = False
        for ds in datasets:
            if datasets[ds].SOPClassUID == "1.2.840.10008.5.1.4.1.1.128":
                pet_opened = True
                break
        if pet_opened:
            icon_suv2roi = QtGui.QIcon()
            icon_suv2roi.addPixmap(
                QtGui.QPixmap(
                    resource_path("res/images/btn-icons/suv2roi.png")),
                QtGui.QIcon.Normal, QtGui.QIcon.On)
            self.button_suv2roi.setObjectName("SUV2ROI_Button")
            self.button_suv2roi.setIcon(icon_suv2roi)
            self.button_suv2roi.setToolTip("Convert SUVs to ROIs")
            self.button_suv2roi.setFixedSize(50, 50)
            self.button_suv2roi.setCursor(
                QtGui.QCursor(QtCore.Qt.PointingHandCursor))
            self.button_suv2roi.clicked.connect(self.suv2roi_handler)

        # Set all labels to white
        stylesheet = "QLabel { color : white; }"
        self.format_metadata_labels(stylesheet)

        # The following layout was originally accomplished using a QGridLayout with QSpaceItems to anchor the labels
        # to the corners of the DICOM view. This caused a reintroduction of the tedious memory issues that were fixed
        # with the restructure. The following was rewritten to not use QSpaceItems because they, for reasons unknown,
        # caused a memory leak resulting in the entire patient dictionary not being cleared from memory correctly,
        # leaving hundreds of additional megabytes unused in memory each time a new patient was opened.

        # Create a widget to contain the two top-left labels
        top_left_widget = QtWidgets.QWidget()
        top_left = QtWidgets.QVBoxLayout(top_left_widget)
        top_left.addWidget(self.label_image_id,
                           QtCore.Qt.AlignTop | QtCore.Qt.AlignTop)
        top_left.addWidget(self.label_image_pos,
                           QtCore.Qt.AlignTop | QtCore.Qt.AlignTop)

        # Create a widget to contain the top-right label
        top_right_widget = QtWidgets.QWidget()
        top_right = QtWidgets.QVBoxLayout(top_right_widget)
        top_right.addWidget(self.label_wl,
                            QtCore.Qt.AlignTop | QtCore.Qt.AlignTop)

        # Create a widget to contain the two top widgets
        top_widget = QtWidgets.QWidget()
        top = QtWidgets.QHBoxLayout(top_widget)
        # Set margin for axial view
        if self.metadata_formatted:
            top_widget.setFixedHeight(50)
            top_widget.setContentsMargins(0, 0, 0, 0)
            top.setContentsMargins(0, 0, 0, 0)
            top.setSpacing(0)
        else:
            top_widget.setFixedHeight(100)
        top.addWidget(top_left_widget,
                      QtCore.Qt.AlignLeft | QtCore.Qt.AlignLeft)
        top.addWidget(top_right_widget,
                      QtCore.Qt.AlignRight | QtCore.Qt.AlignRight)

        # Create a widget to contain the two bottom-left labels
        bottom_left_widget = QtWidgets.QWidget()
        bottom_left = QtWidgets.QVBoxLayout(bottom_left_widget)
        bottom_left.addWidget(self.label_image_size,
                              QtCore.Qt.AlignBottom | QtCore.Qt.AlignBottom)
        bottom_left.addWidget(self.label_zoom,
                              QtCore.Qt.AlignBottom | QtCore.Qt.AlignBottom)

        # Create a widget to contain the two bottom-right widgets
        bottom_right_widget = QtWidgets.QWidget()
        bottom_right = QtWidgets.QVBoxLayout(bottom_right_widget)
        bottom_right.setAlignment(QtCore.Qt.AlignRight)
        bottom_right.addWidget(self.label_patient_pos,
                               QtCore.Qt.AlignBottom | QtCore.Qt.AlignBottom)

        # Add the SUV2ROI button if PET opened and in single view
        if pet_opened and not self.is_four_view:
            bottom_right_button_layout = \
                QtWidgets.QHBoxLayout(bottom_right_widget)
            bottom_right_button_layout.addStretch(1)
            bottom_right_button_layout.addWidget(self.button_suv2roi)
            bottom_right.addLayout(bottom_right_button_layout)

        # Create a widget to contain the two bottom widgets
        bottom_widget = QtWidgets.QWidget()
        bottom = QtWidgets.QHBoxLayout(bottom_widget)
        # Set margin for axial view
        if self.metadata_formatted:
            bottom_widget.setFixedHeight(50)
            bottom_widget.setContentsMargins(0, 0, 0, 0)
            bottom.setContentsMargins(0, 0, 0, 0)
            bottom.setSpacing(0)
        else:
            bottom_widget.setFixedHeight(100)
        bottom.addWidget(bottom_left_widget,
                         QtCore.Qt.AlignLeft | QtCore.Qt.AlignLeft)
        bottom.addWidget(bottom_right_widget,
                         QtCore.Qt.AlignRight | QtCore.Qt.AlignRight)

        # Add the bottom and top widgets to the view
        self.metadata_layout.addWidget(top_widget,
                                       QtCore.Qt.AlignTop | QtCore.Qt.AlignTop)
        self.metadata_layout.addStretch()
        self.metadata_layout.addWidget(
            bottom_widget, QtCore.Qt.AlignBottom | QtCore.Qt.AlignBottom)
Пример #27
0
 def mouseReleaseEvent(self, event):
     self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
     # handle event
     super().mouseReleaseEvent(event)
Пример #28
0
    def init_layout(self):
        """
        Initialize the layout for the DICOM View tab.
        Add the view widget and the slider in the layout.
        Add the whole container 'tab2_view' as a tab in the main page.
        """

        # Initialise a DrawROIWindow
        if platform.system() == 'Darwin':
            self.stylesheet_path = "res/stylesheet.qss"
        else:
            self.stylesheet_path = "res/stylesheet-win-linux.qss"
        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.draw_roi_window_instance.setObjectName("DrawRoiWindowInstance")
        self.draw_roi_window_instance.setWindowIcon(window_icon)

        # Creating a form box to hold all buttons and input fields
        self.draw_roi_window_input_container_box = QFormLayout()
        self.draw_roi_window_input_container_box. \
            setObjectName("DrawRoiWindowInputContainerBox")
        self.draw_roi_window_input_container_box. \
            setLabelAlignment(Qt.AlignLeft)

        # Create a label for denoting the ROI name
        self.roi_name_label = QLabel()
        self.roi_name_label.setObjectName("ROINameLabel")
        self.roi_name_line_edit = QLineEdit()
        # Create an input box for ROI name
        self.roi_name_line_edit.setObjectName("ROINameLineEdit")
        self.roi_name_line_edit.setSizePolicy(QSizePolicy.Minimum,
                                              QSizePolicy.Minimum)
        self.roi_name_line_edit.resize(
            self.roi_name_line_edit.sizeHint().width(),
            self.roi_name_line_edit.sizeHint().height())
        self.roi_name_line_edit.setEnabled(False)
        self.draw_roi_window_input_container_box. \
            addRow(self.roi_name_label, self.roi_name_line_edit)

        # Create horizontal box to store image slice number and backward,
        # forward buttons
        self.image_slice_number_box = QHBoxLayout()
        self.image_slice_number_box.setObjectName("ImageSliceNumberBox")

        # Create a label for denoting the Image Slice Number
        self.image_slice_number_label = QLabel()
        self.image_slice_number_label.setObjectName("ImageSliceNumberLabel")
        self.image_slice_number_box.addWidget(self.image_slice_number_label)
        # Create a line edit for containing the image slice number
        self.image_slice_number_line_edit = QLineEdit()
        self.image_slice_number_line_edit. \
            setObjectName("ImageSliceNumberLineEdit")
        self.image_slice_number_line_edit. \
            setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        self.image_slice_number_line_edit.resize(
            self.image_slice_number_line_edit.sizeHint().width(),
            self.image_slice_number_line_edit.sizeHint().height())

        self.image_slice_number_line_edit.setCursorPosition(0)
        self.image_slice_number_line_edit.setEnabled(False)
        self.image_slice_number_box. \
            addWidget(self.image_slice_number_line_edit)
        # Create a button to move backward to the previous image
        self.image_slice_number_move_backward_button = QPushButton()
        self.image_slice_number_move_backward_button. \
            setObjectName("ImageSliceNumberMoveBackwardButton")
        self.image_slice_number_move_backward_button.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
        self.image_slice_number_move_backward_button.resize(QSize(24, 24))
        self.image_slice_number_move_backward_button.clicked. \
            connect(self.onBackwardClicked)
        icon_move_backward = QtGui.QIcon()
        icon_move_backward.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/backward_slide_icon.png')))
        self.image_slice_number_move_backward_button.setIcon(
            icon_move_backward)
        self.image_slice_number_box. \
            addWidget(self.image_slice_number_move_backward_button)
        # Create a button to move forward to the next image
        self.image_slice_number_move_forward_button = QPushButton()
        self.image_slice_number_move_forward_button. \
            setObjectName("ImageSliceNumberMoveForwardButton")
        self.image_slice_number_move_forward_button.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
        self.image_slice_number_move_forward_button.resize(QSize(24, 24))
        self.image_slice_number_move_forward_button.clicked. \
            connect(self.onForwardClicked)
        icon_move_forward = QtGui.QIcon()
        icon_move_forward.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/forward_slide_icon.png')))
        self.image_slice_number_move_forward_button.setIcon(icon_move_forward)
        self.image_slice_number_box. \
            addWidget(self.image_slice_number_move_forward_button)

        self.draw_roi_window_input_container_box. \
            addRow(self.image_slice_number_box)

        # Create a horizontal box for containing the zoom function
        self.draw_roi_window_viewport_zoom_box = QHBoxLayout()
        self.draw_roi_window_viewport_zoom_box.setObjectName(
            "DrawRoiWindowViewportZoomBox")
        # Create a label for zooming
        self.draw_roi_window_viewport_zoom_label = QLabel()
        self.draw_roi_window_viewport_zoom_label. \
            setObjectName("DrawRoiWindowViewportZoomLabel")
        # Create an input box for zoom factor
        self.draw_roi_window_viewport_zoom_input = QLineEdit()
        self.draw_roi_window_viewport_zoom_input. \
            setObjectName("DrawRoiWindowViewportZoomInput")
        self.draw_roi_window_viewport_zoom_input. \
            setText("{:.2f}".format(self.zoom * 100) + "%")
        self.draw_roi_window_viewport_zoom_input.setCursorPosition(0)
        self.draw_roi_window_viewport_zoom_input.setEnabled(False)
        self.draw_roi_window_viewport_zoom_input. \
            setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        self.draw_roi_window_viewport_zoom_input.resize(
            self.draw_roi_window_viewport_zoom_input.sizeHint().width(),
            self.draw_roi_window_viewport_zoom_input.sizeHint().height())
        # Create 2 buttons for zooming in and out
        # Zoom In Button
        self.draw_roi_window_viewport_zoom_in_button = QPushButton()
        self.draw_roi_window_viewport_zoom_in_button. \
            setObjectName("DrawRoiWindowViewportZoomInButton")
        self.draw_roi_window_viewport_zoom_in_button.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
        self.draw_roi_window_viewport_zoom_in_button.resize(QSize(24, 24))
        self.draw_roi_window_viewport_zoom_in_button. \
            setProperty("QPushButtonClass", "zoom-button")
        icon_zoom_in = QtGui.QIcon()
        icon_zoom_in.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/zoom_in_icon.png')))
        self.draw_roi_window_viewport_zoom_in_button.setIcon(icon_zoom_in)
        self.draw_roi_window_viewport_zoom_in_button.clicked. \
            connect(self.onZoomInClicked)
        # Zoom Out Button
        self.draw_roi_window_viewport_zoom_out_button = QPushButton()
        self.draw_roi_window_viewport_zoom_out_button. \
            setObjectName("DrawRoiWindowViewportZoomOutButton")
        self.draw_roi_window_viewport_zoom_out_button.setSizePolicy(
            QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
        self.draw_roi_window_viewport_zoom_out_button.resize(QSize(24, 24))
        self.draw_roi_window_viewport_zoom_out_button. \
            setProperty("QPushButtonClass", "zoom-button")
        icon_zoom_out = QtGui.QIcon()
        icon_zoom_out.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/zoom_out_icon.png')))
        self.draw_roi_window_viewport_zoom_out_button.setIcon(icon_zoom_out)
        self.draw_roi_window_viewport_zoom_out_button.clicked. \
            connect(self.onZoomOutClicked)
        self.draw_roi_window_viewport_zoom_box. \
            addWidget(self.draw_roi_window_viewport_zoom_label)
        self.draw_roi_window_viewport_zoom_box. \
            addWidget(self.draw_roi_window_viewport_zoom_input)
        self.draw_roi_window_viewport_zoom_box. \
            addWidget(self.draw_roi_window_viewport_zoom_out_button)
        self.draw_roi_window_viewport_zoom_box. \
            addWidget(self.draw_roi_window_viewport_zoom_in_button)
        self.draw_roi_window_input_container_box. \
            addRow(self.draw_roi_window_viewport_zoom_box)

        self.init_cursor_radius_change_box()
        # Create field to toggle two options: Keep empty pixel or fill empty
        # pixel when using draw cursor
        self.toggle_keep_empty_pixel_box = QHBoxLayout()
        self.toggle_keep_empty_pixel_label = QLabel()
        self.toggle_keep_empty_pixel_label. \
            setObjectName("ToggleKeepEmptyPixelLabel")
        # Create input for min pixel size
        self.toggle_keep_empty_pixel_combo_box = QComboBox()
        self.toggle_keep_empty_pixel_combo_box.addItems(["Off", "On"])
        self.toggle_keep_empty_pixel_combo_box.setCurrentIndex(0)
        self.toggle_keep_empty_pixel_combo_box.setEnabled(False)
        self.toggle_keep_empty_pixel_combo_box. \
            setObjectName("ToggleKeepEmptyPixelComboBox")
        self.toggle_keep_empty_pixel_combo_box. \
            setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        self.toggle_keep_empty_pixel_combo_box.resize(
            self.toggle_keep_empty_pixel_combo_box.sizeHint().width(),
            self.toggle_keep_empty_pixel_combo_box.sizeHint().height())
        self.toggle_keep_empty_pixel_combo_box.currentIndexChanged.connect(
            self.toggle_keep_empty_pixel_box_index_changed)
        self.toggle_keep_empty_pixel_box. \
            addWidget(self.toggle_keep_empty_pixel_label)
        self.toggle_keep_empty_pixel_box. \
            addWidget(self.toggle_keep_empty_pixel_combo_box)
        self.draw_roi_window_input_container_box. \
            addRow(self.toggle_keep_empty_pixel_box)

        # Create a horizontal box for transect and draw button
        self.draw_roi_window_transect_draw_box = QHBoxLayout()
        self.draw_roi_window_transect_draw_box. \
            setObjectName("DrawRoiWindowTransectDrawBox")
        # Create a transect button
        self.image_slice_number_transect_button = QPushButton()
        self.image_slice_number_transect_button. \
            setObjectName("ImageSliceNumberTransectButton")
        self.image_slice_number_transect_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum))
        self.image_slice_number_transect_button.resize(
            self.image_slice_number_transect_button.sizeHint().width(),
            self.image_slice_number_transect_button.sizeHint().height())
        self.image_slice_number_transect_button.clicked. \
            connect(self.transect_handler)
        icon_transect = QtGui.QIcon()
        icon_transect.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/transect_icon.png')))
        self.image_slice_number_transect_button.setIcon(icon_transect)
        self.draw_roi_window_transect_draw_box. \
            addWidget(self.image_slice_number_transect_button)
        # Create a bounding box button
        self.image_slice_number_box_draw_button = QPushButton()
        self.image_slice_number_box_draw_button. \
            setObjectName("ImageSliceNumberBoxDrawButton")
        self.image_slice_number_box_draw_button.setSizePolicy(
            QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        self.image_slice_number_box_draw_button.resize(
            self.image_slice_number_box_draw_button.sizeHint().width(),
            self.image_slice_number_box_draw_button.sizeHint().height())
        self.image_slice_number_box_draw_button.clicked. \
            connect(self.onBoxDrawClicked)
        icon_box_draw = QtGui.QIcon()
        icon_box_draw.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/draw_bound_icon.png')))
        self.image_slice_number_box_draw_button.setIcon(icon_box_draw)
        self.draw_roi_window_transect_draw_box. \
            addWidget(self.image_slice_number_box_draw_button)
        # Create a draw button
        self.image_slice_number_draw_button = QPushButton()
        self.image_slice_number_draw_button. \
            setObjectName("ImageSliceNumberDrawButton")
        self.image_slice_number_draw_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum))
        self.image_slice_number_draw_button.resize(
            self.image_slice_number_draw_button.sizeHint().width(),
            self.image_slice_number_draw_button.sizeHint().height())
        self.image_slice_number_draw_button.clicked.connect(self.onDrawClicked)
        icon_draw = QtGui.QIcon()
        icon_draw.addPixmap(
            QtGui.QPixmap(resource_path('res/images/btn-icons/draw_icon.png')))
        self.image_slice_number_draw_button.setIcon(icon_draw)
        self.draw_roi_window_transect_draw_box. \
            addWidget(self.image_slice_number_draw_button)
        self.draw_roi_window_input_container_box. \
            addRow(self.draw_roi_window_transect_draw_box)

        # Create a contour preview button
        self.row_preview_layout = QtWidgets.QHBoxLayout()
        self.button_contour_preview = QtWidgets.QPushButton("Preview contour")
        self.button_contour_preview.clicked.connect(self.onPreviewClicked)
        self.row_preview_layout.addWidget(self.button_contour_preview)
        self.draw_roi_window_input_container_box. \
            addRow(self.row_preview_layout)
        icon_preview = QtGui.QIcon()
        icon_preview.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/preview_icon.png')))
        self.button_contour_preview.setIcon(icon_preview)

        # Create input line edit for alpha value
        self.label_alpha_value = QtWidgets.QLabel("Alpha value:")
        self.input_alpha_value = QtWidgets.QLineEdit("0.2")
        self.input_alpha_value. \
            setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        self.input_alpha_value.resize(
            self.input_alpha_value.sizeHint().width(),
            self.input_alpha_value.sizeHint().height())
        self.input_alpha_value.setValidator(
            QRegularExpressionValidator(
                QRegularExpression("^[0-9]*[.]?[0-9]*$")))
        self.draw_roi_window_input_container_box. \
            addRow(self.label_alpha_value, self.input_alpha_value)

        # Create a label for denoting the max internal hole size
        self.internal_hole_max_label = QLabel()
        self.internal_hole_max_label.setObjectName("InternalHoleLabel")

        # Create input for max internal hole size
        self.internal_hole_max_line_edit = QLineEdit()
        self.internal_hole_max_line_edit.setObjectName("InternalHoleInput")
        self.internal_hole_max_line_edit. \
            setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        self.internal_hole_max_line_edit.resize(
            self.internal_hole_max_line_edit.sizeHint().width(),
            self.internal_hole_max_line_edit.sizeHint().height())
        self.internal_hole_max_line_edit.setValidator(
            QRegularExpressionValidator(
                QRegularExpression("^[0-9]*[.]?[0-9]*$")))
        self.draw_roi_window_input_container_box.addRow(
            self.internal_hole_max_label, self.internal_hole_max_line_edit)

        # Create a label for denoting the isthmus width size
        self.isthmus_width_max_label = QLabel()
        self.isthmus_width_max_label.setObjectName("IsthmusWidthLabel")
        # Create input for max isthmus width size
        self.isthmus_width_max_line_edit = QLineEdit()
        self.isthmus_width_max_line_edit.setObjectName("IsthmusWidthInput")
        self.isthmus_width_max_line_edit.setSizePolicy(
            QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        self.isthmus_width_max_line_edit.resize(
            self.isthmus_width_max_line_edit.sizeHint().width(),
            self.isthmus_width_max_line_edit.sizeHint().height())
        self.isthmus_width_max_line_edit.setValidator(
            QRegularExpressionValidator(
                QRegularExpression("^[0-9]*[.]?[0-9]*$")))
        self.draw_roi_window_input_container_box.addRow(
            self.isthmus_width_max_label, self.isthmus_width_max_line_edit)

        # Create a label for denoting the minimum pixel density
        self.min_pixel_density_label = QLabel()
        self.min_pixel_density_label.setObjectName("MinPixelDensityLabel")
        # Create input for min pixel size
        self.min_pixel_density_line_edit = QLineEdit()
        self.min_pixel_density_line_edit.setObjectName("MinPixelDensityInput")
        self.min_pixel_density_line_edit.setSizePolicy(
            QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        self.min_pixel_density_line_edit.resize(
            self.min_pixel_density_line_edit.sizeHint().width(),
            self.min_pixel_density_line_edit.sizeHint().height())
        self.min_pixel_density_line_edit.setValidator(
            QRegularExpressionValidator(
                QRegularExpression("^[0-9]*[.]?[0-9]*$")))
        self.draw_roi_window_input_container_box.addRow(
            self.min_pixel_density_label, self.min_pixel_density_line_edit)

        # Create a label for denoting the minimum pixel density
        self.max_pixel_density_label = QLabel()
        self.max_pixel_density_label.setObjectName("MaxPixelDensityLabel")
        # Create input for min pixel size
        self.max_pixel_density_line_edit = QLineEdit()
        self.max_pixel_density_line_edit.setObjectName("MaxPixelDensityInput")
        self.max_pixel_density_line_edit. \
            setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
        self.max_pixel_density_line_edit.resize(
            self.max_pixel_density_line_edit.sizeHint().width(),
            self.max_pixel_density_line_edit.sizeHint().height())
        self.max_pixel_density_line_edit.setValidator(
            QRegularExpressionValidator(
                QRegularExpression("^[0-9]*[.]?[0-9]*$")))
        self.draw_roi_window_input_container_box.addRow(
            self.max_pixel_density_label, self.max_pixel_density_line_edit)

        # Create a button to clear the draw
        self.draw_roi_window_instance_action_reset_button = QPushButton()
        self.draw_roi_window_instance_action_reset_button. \
            setObjectName("DrawRoiWindowInstanceActionClearButton")
        self.draw_roi_window_instance_action_reset_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum))

        reset_button = self.draw_roi_window_instance_action_reset_button
        self.draw_roi_window_instance_action_reset_button.resize(
            reset_button.sizeHint().width(),
            reset_button.sizeHint().height())
        self.draw_roi_window_instance_action_reset_button.clicked. \
            connect(self.onResetClicked)
        self.draw_roi_window_instance_action_reset_button. \
            setProperty("QPushButtonClass", "fail-button")
        icon_clear_roi_draw = QtGui.QIcon()
        icon_clear_roi_draw.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/reset_roi_draw_icon.png')))
        self.draw_roi_window_instance_action_reset_button. \
            setIcon(icon_clear_roi_draw)
        self.draw_roi_window_input_container_box. \
            addRow(self.draw_roi_window_instance_action_reset_button)

        # Create a horizontal box for saving and cancel the drawing
        self.draw_roi_window_cancel_save_box = QHBoxLayout()
        self.draw_roi_window_cancel_save_box. \
            setObjectName("DrawRoiWindowCancelSaveBox")
        # Create an exit button to cancel the drawing
        # Add a button to go back/exit from the application
        self.draw_roi_window_instance_cancel_button = QPushButton()
        self.draw_roi_window_instance_cancel_button. \
            setObjectName("DrawRoiWindowInstanceCancelButton")
        self.draw_roi_window_instance_cancel_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum))
        self.draw_roi_window_instance_cancel_button.resize(
            self.draw_roi_window_instance_cancel_button.sizeHint().width(),
            self.draw_roi_window_instance_cancel_button.sizeHint().height())
        self.draw_roi_window_instance_cancel_button. \
            setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.draw_roi_window_instance_cancel_button.clicked. \
            connect(self.onCancelButtonClicked)
        self.draw_roi_window_instance_cancel_button. \
            setProperty("QPushButtonClass", "fail-button")
        icon_cancel = QtGui.QIcon()
        icon_cancel.addPixmap(
            QtGui.QPixmap(
                resource_path('res/images/btn-icons/cancel_icon.png')))
        self.draw_roi_window_instance_cancel_button.setIcon(icon_cancel)
        self.draw_roi_window_cancel_save_box. \
            addWidget(self.draw_roi_window_instance_cancel_button)
        # Create a save button to save all the changes
        self.draw_roi_window_instance_save_button = QPushButton()
        self.draw_roi_window_instance_save_button. \
            setObjectName("DrawRoiWindowInstanceSaveButton")
        self.draw_roi_window_instance_save_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum))
        self.draw_roi_window_instance_save_button.resize(
            self.draw_roi_window_instance_save_button.sizeHint().width(),
            self.draw_roi_window_instance_save_button.sizeHint().height())
        self.draw_roi_window_instance_save_button. \
            setProperty("QPushButtonClass", "success-button")
        icon_save = QtGui.QIcon()
        icon_save.addPixmap(
            QtGui.QPixmap(resource_path('res/images/btn-icons/save_icon.png')))
        self.draw_roi_window_instance_save_button.setIcon(icon_save)
        self.draw_roi_window_instance_save_button.clicked. \
            connect(self.onSaveClicked)
        self.draw_roi_window_cancel_save_box. \
            addWidget(self.draw_roi_window_instance_save_button)

        self.draw_roi_window_input_container_box. \
            addRow(self.draw_roi_window_cancel_save_box)

        # Creating a horizontal box to hold the ROI view and slider
        self.draw_roi_window_instance_view_box = QHBoxLayout()
        self.draw_roi_window_instance_view_box. \
            setObjectName("DrawRoiWindowInstanceViewBox")
        # Add View and Slider into horizontal box
        self.draw_roi_window_instance_view_box.addWidget(self.dicom_view)
        # Create a widget to hold the image slice box
        self.draw_roi_window_instance_view_widget = QWidget()
        self.draw_roi_window_instance_view_widget.setObjectName(
            "DrawRoiWindowInstanceActionWidget")
        self.draw_roi_window_instance_view_widget.setLayout(
            self.draw_roi_window_instance_view_box)

        # Create a horizontal box for containing the input fields and the
        # viewport
        self.draw_roi_window_main_box = QHBoxLayout()
        self.draw_roi_window_main_box.setObjectName("DrawRoiWindowMainBox")
        self.draw_roi_window_main_box. \
            addLayout(self.draw_roi_window_input_container_box, 1)
        self.draw_roi_window_main_box. \
            addWidget(self.draw_roi_window_instance_view_widget, 11)

        # Create a new central widget to hold the vertical box layout
        self.draw_roi_window_instance_central_widget = QWidget()
        self.draw_roi_window_instance_central_widget. \
            setObjectName("DrawRoiWindowInstanceCentralWidget")
        self.draw_roi_window_instance_central_widget.setLayout(
            self.draw_roi_window_main_box)

        self.retranslate_ui(self.draw_roi_window_instance)
        self.draw_roi_window_instance.setStyleSheet(stylesheet)
        self.draw_roi_window_instance. \
            setCentralWidget(self.draw_roi_window_instance_central_widget)
        QtCore.QMetaObject.connectSlotsByName(self.draw_roi_window_instance)
Пример #29
0
 def _abort_request(self) -> None:
     """Abort the currently running network request, if any."""
     if self._current_network_request is not None:
         self._current_network_request.abort()
     self.cursor = QtGui.QCursor(QtCore.Qt.CursorShape.ArrowCursor)
Пример #30
0
    def setup_ui(self, delete_roi_window_instance, regions_of_interest,
                 dataset_rtss, deleting_rois_structure_tuple):
        # Initialise the 2 lists for containing the ROI(s) that we are going to keep and delete respectively
        self.regions_of_interest_to_keep = []
        self.regions_of_interest_to_delete = []
        # This is for holding the original list of ROI(s)
        self.regions_of_interest_list = regions_of_interest
        # This is for holding the DICOM dataset of that specific patient
        self.dataset_rtss = dataset_rtss
        # Assigning new tuple for holding the deleting ROI(s)
        self.deleting_rois_structure_tuple = deleting_rois_structure_tuple

        # Initialise a DeleteROIWindow
        if platform.system() == 'Darwin':
            self.stylesheet_path = "res/stylesheet.qss"
        else:
            self.stylesheet_path = "res/stylesheet-win-linux.qss"
        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)
        delete_roi_window_instance.setObjectName("DeleteRoiWindowInstance")
        delete_roi_window_instance.setWindowIcon(window_icon)
        delete_roi_window_instance.resize(800, 606)

        # Create a vertical box to hold all widgets
        self.delete_roi_window_instance_vertical_box = QVBoxLayout()
        self.delete_roi_window_instance_vertical_box.setObjectName(
            "DeleteRoiWindowInstanceVerticalBox")

        # Create a label for holding the window's title
        self.delete_roi_window_title = QLabel()
        self.delete_roi_window_title.setObjectName("DeleteRoiWindowTitle")
        self.delete_roi_window_title.setProperty("QLabelClass", "window-title")
        self.delete_roi_window_title.setAlignment(Qt.AlignLeft)
        self.delete_roi_window_instance_vertical_box.addWidget(
            self.delete_roi_window_title)

        # Create a label for holding the instruction of how to delete the ROIs
        self.delete_roi_window_instruction = QLabel()
        self.delete_roi_window_instruction.setObjectName(
            "DeleteRoiWindowInstruction")
        self.delete_roi_window_instruction.setAlignment(Qt.AlignCenter)
        self.delete_roi_window_instance_vertical_box.addWidget(
            self.delete_roi_window_instruction)

        # Create a horizontal box for holding the 2 lists and the move left, move right buttons
        self.delete_roi_window_keep_and_delete_box = QHBoxLayout()
        self.delete_roi_window_keep_and_delete_box.setObjectName(
            "DeleteRoiWindowKeepAndDeleteBox")
        # ================================= KEEP BOX =================================
        # Create a vertical box for holding the label and the tree view for holding the ROIs that we are keeping
        self.delete_roi_window_keep_vertical_box = QVBoxLayout()
        self.delete_roi_window_keep_vertical_box.setObjectName(
            "DeleteRoiWindowKeepVerticalBox")
        # Create a label for the tree view with the list of ROIs to keep
        self.delete_roi_window_keep_tree_view_label = QLabel()
        self.delete_roi_window_keep_tree_view_label.setObjectName(
            "DeleteRoiWindowKeepTreeViewLabel")
        self.delete_roi_window_keep_tree_view_label.setProperty(
            "QLabelClass", ["tree-view-label", "tree-view-label-keep-delete"])
        self.delete_roi_window_keep_tree_view_label.setAlignment(
            Qt.AlignCenter)
        self.delete_roi_window_keep_tree_view_label.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.delete_roi_window_keep_tree_view_label.resize(
            self.delete_roi_window_keep_tree_view_label.sizeHint().width(),
            self.delete_roi_window_keep_tree_view_label.sizeHint().height())
        self.delete_roi_window_keep_vertical_box.addWidget(
            self.delete_roi_window_keep_tree_view_label)
        # Create a tree view for containing the list of ROIs to keep
        self.delete_roi_window_keep_tree_view = QTreeWidget()
        self.delete_roi_window_keep_tree_view.setObjectName(
            "DeleteRoiWindowKeepTreeView")
        self.delete_roi_window_keep_tree_view.setHeaderHidden(True)
        self.delete_roi_window_keep_tree_view.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.delete_roi_window_keep_tree_view.resize(
            self.delete_roi_window_keep_tree_view.sizeHint().width(),
            self.delete_roi_window_keep_tree_view.sizeHint().height())
        self.delete_roi_window_keep_vertical_box.addWidget(
            self.delete_roi_window_keep_tree_view)
        self.delete_roi_window_keep_vertical_box.setStretch(1, 4)
        # Create a widget to hold the keep vertical box
        self.delete_roi_window_keep_widget = QWidget()
        self.delete_roi_window_keep_widget.setObjectName(
            "DeleteRoiWindowKeepWidget")
        self.delete_roi_window_keep_widget.setLayout(
            self.delete_roi_window_keep_vertical_box)
        self.delete_roi_window_keep_and_delete_box.addStretch(1)
        self.delete_roi_window_keep_and_delete_box.addWidget(
            self.delete_roi_window_keep_widget)
        # ================================= KEEP BOX =================================

        # ================================= MOVE LEFT/RIGHT BOX =================================
        # Create a vertical box for holding the 2 buttons for moving left and right
        self.delete_roi_window_move_left_right_vertical_box = QVBoxLayout()
        self.delete_roi_window_move_left_right_vertical_box.setObjectName(
            "DeleteRoiWindowMoveLeftRightVerticalBox")
        # Create Move Right Button / Delete Button
        self.move_right_button = QPushButton()
        self.move_right_button.setObjectName("MoveRightButton")
        self.move_right_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.move_right_button.resize(
            self.move_right_button.sizeHint().width(),
            self.move_right_button.sizeHint().height())
        self.move_right_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.move_right_button.clicked.connect(
            self.move_right_button_onClicked)
        self.move_right_button.setProperty("QPushButtonClass", "fail-button")
        self.delete_roi_window_move_left_right_vertical_box.addStretch(1)
        self.delete_roi_window_move_left_right_vertical_box.addWidget(
            self.move_right_button)
        # Create Move Left Button / Keep Button
        self.move_left_button = QPushButton()
        self.move_left_button.setObjectName("MoveLeftButton")
        self.move_left_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.move_left_button.resize(self.move_left_button.sizeHint().width(),
                                     self.move_left_button.sizeHint().height())
        self.move_left_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.move_left_button.clicked.connect(self.move_left_button_onClicked)
        self.move_left_button.setProperty("QPushButtonClass", "success-button")
        self.delete_roi_window_move_left_right_vertical_box.addWidget(
            self.move_left_button)
        self.delete_roi_window_move_left_right_vertical_box.addStretch(1)
        # Create a widget for holding the 2 buttons
        self.delete_roi_window_move_left_right_widget = QWidget()
        self.delete_roi_window_move_left_right_widget.setObjectName(
            "DeleteRoiWindowMoveLeftRightWidget")
        self.delete_roi_window_move_left_right_widget.setLayout(
            self.delete_roi_window_move_left_right_vertical_box)
        self.delete_roi_window_keep_and_delete_box.addWidget(
            self.delete_roi_window_move_left_right_widget)
        # ================================= MOVE LEFT/RIGHT BOX =================================

        # ================================= DELETE BOX =================================
        # Create a vertical box for holding the label and the tree view for holding the ROIs that we are deleting
        self.delete_roi_window_delete_vertical_box = QVBoxLayout()
        self.delete_roi_window_delete_vertical_box.setObjectName(
            "DeleteRoiWindowDeleteVerticalBox")
        # Create a label for the tree view with the list of ROIs to delete
        self.delete_roi_window_delete_tree_view_label = QLabel()
        self.delete_roi_window_delete_tree_view_label.setObjectName(
            "DeleteRoiWindowDeleteTreeViewLabel")
        self.delete_roi_window_delete_tree_view_label.setProperty(
            "QLabelClass", ["tree-view-label", "tree-view-label-keep-delete"])
        self.delete_roi_window_delete_tree_view_label.setAlignment(
            Qt.AlignCenter)
        self.delete_roi_window_delete_tree_view_label.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.delete_roi_window_delete_tree_view_label.resize(
            self.delete_roi_window_delete_tree_view_label.sizeHint().width(),
            self.delete_roi_window_delete_tree_view_label.sizeHint().height())
        self.delete_roi_window_delete_vertical_box.addWidget(
            self.delete_roi_window_delete_tree_view_label)
        # Create a tree view for containing the list of ROIs to delete
        self.delete_roi_window_delete_tree_view = QTreeWidget()
        self.delete_roi_window_delete_tree_view.setObjectName(
            "DeleteRoiWindowDeleteTreeView")
        self.delete_roi_window_delete_tree_view.setHeaderHidden(True)
        self.delete_roi_window_delete_tree_view.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.delete_roi_window_delete_tree_view.resize(
            self.delete_roi_window_delete_tree_view.sizeHint().width(),
            self.delete_roi_window_delete_tree_view.sizeHint().height())
        self.delete_roi_window_delete_vertical_box.addWidget(
            self.delete_roi_window_delete_tree_view)
        self.delete_roi_window_delete_vertical_box.setStretch(1, 4)
        # Create a widget to hold the delete vertical box
        self.delete_roi_window_delete_widget = QWidget()
        self.delete_roi_window_delete_widget.setObjectName(
            "DeleteRoiWindowDeleteWidget")
        self.delete_roi_window_delete_widget.setLayout(
            self.delete_roi_window_delete_vertical_box)
        self.delete_roi_window_keep_and_delete_box.addWidget(
            self.delete_roi_window_delete_widget)
        self.delete_roi_window_keep_and_delete_box.addStretch(1)
        self.delete_roi_window_keep_and_delete_box.setStretch(1, 4)
        self.delete_roi_window_keep_and_delete_box.setStretch(3, 4)
        # ================================= DELETE BOX =================================
        # Create a widget to hold the keep and delete box
        self.delete_roi_window_keep_and_delete_widget = QWidget()
        self.delete_roi_window_keep_and_delete_widget.setObjectName(
            "DeleteRoiWindowKeepAndDeleteWidget")
        self.delete_roi_window_keep_and_delete_widget.setLayout(
            self.delete_roi_window_keep_and_delete_box)
        self.delete_roi_window_instance_vertical_box.addWidget(
            self.delete_roi_window_keep_and_delete_widget)

        # Create a horizontal box to hold 2 action buttons for this window
        self.delete_roi_window_action_buttons_box = QHBoxLayout()
        self.delete_roi_window_action_buttons_box.setObjectName(
            "DeleteRoiWindowActionButtonsBox")
        # Create the cancel button
        self.delete_roi_window_cancel_button = QPushButton()
        self.delete_roi_window_cancel_button.setObjectName(
            "DeleteRoiWindowCancelButton")
        self.delete_roi_window_cancel_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.delete_roi_window_cancel_button.resize(
            self.delete_roi_window_cancel_button.sizeHint().width(),
            self.delete_roi_window_cancel_button.sizeHint().height())
        self.delete_roi_window_cancel_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.delete_roi_window_cancel_button.clicked.connect(
            self.on_cancel_button_clicked)
        self.delete_roi_window_cancel_button.setProperty(
            "QPushButtonClass", "fail-button")
        self.delete_roi_window_action_buttons_box.addStretch(1)
        self.delete_roi_window_action_buttons_box.addWidget(
            self.delete_roi_window_cancel_button)
        # Create the confirm button
        self.delete_roi_window_confirm_button = QPushButton()
        self.delete_roi_window_confirm_button.setObjectName(
            "DeleteRoiWindowConfirmButton")
        self.delete_roi_window_confirm_button.setSizePolicy(
            QSizePolicy(QSizePolicy.MinimumExpanding,
                        QSizePolicy.MinimumExpanding))
        self.delete_roi_window_confirm_button.resize(
            self.delete_roi_window_confirm_button.sizeHint().width(),
            self.delete_roi_window_confirm_button.sizeHint().height())
        self.delete_roi_window_confirm_button.setCursor(
            QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.delete_roi_window_confirm_button.clicked.connect(
            self.confirm_button_onClicked)
        self.delete_roi_window_confirm_button.setEnabled(False)
        self.delete_roi_window_confirm_button.setProperty(
            "QPushButtonClass", "success-button")
        self.delete_roi_window_action_buttons_box.addWidget(
            self.delete_roi_window_confirm_button)
        # Create a widget to hold the action buttons
        self.delete_roi_window_action_buttons_widget = QWidget()
        self.delete_roi_window_action_buttons_widget.setObjectName(
            "DeleteRoiWindowActionButtonsWidget")
        self.delete_roi_window_action_buttons_widget.setLayout(
            self.delete_roi_window_action_buttons_box)
        self.delete_roi_window_instance_vertical_box.addWidget(
            self.delete_roi_window_action_buttons_widget)

        # Set text for all attributes
        self.retranslate_ui(delete_roi_window_instance)
        # Create a central widget to hold the vertical layout box
        self.delete_roi_window_instance_central_widget = QWidget()
        self.delete_roi_window_instance_central_widget.setObjectName(
            "DeleteRoiWindowInstanceCentralWidget")
        self.delete_roi_window_instance_central_widget.setLayout(
            self.delete_roi_window_instance_vertical_box)
        self.delete_roi_window_instance_vertical_box.setStretch(2, 4)
        # Set the central widget for the main window and style the window
        delete_roi_window_instance.setCentralWidget(
            self.delete_roi_window_instance_central_widget)
        delete_roi_window_instance.setStyleSheet(stylesheet)

        # Load the ROIs in
        self.display_rois_in_listViewKeep()
        # Set the selection mode to multi so that we can select multiple ROIs to delete
        self.delete_roi_window_keep_tree_view.setSelectionMode(
            QAbstractItemView.MultiSelection)
        self.delete_roi_window_delete_tree_view.setSelectionMode(
            QAbstractItemView.MultiSelection)

        QtCore.QMetaObject.connectSlotsByName(delete_roi_window_instance)