Project

General

Profile

Actions

Implementing the Image Fusion GUI

View>mainpage>MainPage.py

This file is responsible for displaying the main window of the OnkoDICOM program. In order to implement both the button that opens the image fusion window and the tab to which the user can view the image fusion, the tab must be implemented here. Due to the similar nature of the DICOMView.py, the code was copied and refactored so that the mainpage folder contains an ImageFusionView.py. This file is responsible for displaying the Image Fusion tab.

To create the button to activate Image Fusion, a button is created in the ActionHandler.py file within the Controller folder.

# Image Fusion Action
        self.icon_image_fusion = QtGui.QIcon()
        self.icon_image_fusion.addPixmap(
            QtGui.QPixmap(resource_path("res/images/btn-icons/image_fusion_purple_icon.png")),
            QtGui.QIcon.Normal,
            QtGui.QIcon.On
        )
        self.action_image_fusion = QtGui.QAction()
        self.action_image_fusion.setIcon(self.icon_image_fusion)
        self.action_image_fusion.setIconVisibleInMenu(True)
        self.action_image_fusion.setText("Image Fusion")
        self.action_image_fusion.triggered.connect(self.image_fusion_handler)

While created, this is not displayed just yet. To display the button, one must go to the src>View>mainpage>ToolBar.py

self.addSeparator()
self.addAction(self.action_handler.action_image_fusion)

Has been added on line 158. Once the button is pressed, the function "image_fusion_handler", will be constructed to open the patient window for selecting an image to fuse with.

GUIController

This class is responsible for handling the events once the user has selected the image-fusion icon in the toolbar. The event is connected with the method defined on line: 98 in the GUIController

self.action_handler.action_image_fusion.triggered.connect(self.open_image_fusion)

Where it connects to the function as shown below. This is present on line:118.


# Testing for Image Fusion
    def open_image_fusion(self):
        print("Start of GUI Controller Image Fusion Method")

        # PatientDictContainer is instanstiated from the Singleton pattern
        patient_dict_container = PatientDictContainer()
        print(patient_dict_container.path)
        self.image_fusion_window = ImageFusionController(patient_dict_container.path)
        self.image_fusion_window.show_basic_selection()
        print("End of GUI Controller Image Fusion Method")

Even though PatientDictContainer is instantiated within this function, due to the Singleton pattern (I believe), the "new" instance refers to the existing PatientDictContainer that has been initialized before, as the program started. This becomes useful in retrieving the path to the patient directory only. The ImagefusionController refers to another Controller class created within the Controller folder.

ImageFusionController

For the time being, the Controller is creating in such a way to loosely couples the ImageFusionWindow GUI. While not necessary for the time being in development, this could potentially aid in providing an ease of refactoring further down the line.

class ImageFusionWindow(QtWidgets.QMainWindow, UIImageFusionWindow):

    def __init__(self, default_directory=None):
        QtWidgets.QMainWindow.__init__(self)

        self.setup_ui(self)
        self.open_patient_directory_input_box.setText(default_directory)
        self.scan_directory_for_patient()

class ImageFusionController:
    def __init__(self, default_directory=None):
        self.image_fusion_window = QtWidgets.QMainWindow()
        self.filepath_to_patient = default_directory

    def show_basic_selection(self):
        self.image_fusion_window = ImageFusionWindow(self.filepath_to_patient)
        self.image_fusion_window.show()

Updated by Peter Qian almost 4 years ago · 3 revisions