def _create_box_in_grid(self) -> QGroupBox:
     group_box = QGroupBox(self.parent)
     group_box.setObjectName(f"Box with index {self._current_last_index}")
     self._elements.append(group_box)
     self._add_element_to_grid(group_box)
     self._current_last_index += 1
     return group_box
Exemplo n.º 2
0
    def _create_categories_boxes(self, size_policy):
        self._boxes_for_category = {}

        current_row = 0
        for major_item_category in iterate_enum(ItemCategory):
            if not major_item_category.is_major_category and major_item_category != ItemCategory.ENERGY_TANK:
                continue

            category_button = QToolButton(self.major_items_box)
            category_button.setGeometry(QRect(20, 30, 24, 21))
            category_button.setText("+")

            category_label = QLabel(self.major_items_box)
            category_label.setSizePolicy(size_policy)
            category_label.setText(major_item_category.long_name)

            category_box = QGroupBox(self.major_items_box)
            category_box.setSizePolicy(size_policy)
            category_box.setObjectName(f"category_box {major_item_category}")

            category_layout = QGridLayout(category_box)
            category_layout.setObjectName(f"category_layout {major_item_category}")

            self.major_items_layout.addWidget(category_button, 2 * current_row + 1, 0, 1, 1)
            self.major_items_layout.addWidget(category_label, 2 * current_row + 1, 1, 1, 1)
            self.major_items_layout.addWidget(category_box, 2 * current_row + 2, 0, 1, 2)
            self._boxes_for_category[major_item_category] = category_box, category_layout, {}

            category_button.clicked.connect(partial(_toggle_box_visibility, category_button, category_box))
            category_box.setVisible(False)
            current_row += 1
Exemplo n.º 3
0
class Ui_dlgAddUser(QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi()

    def setupUi(self):
        self.setObjectName("dlgAddUser")
        self.resize(335, 154)
        self.setWindowFlags(Qt.MSWindowsFixedSizeDialogHint)
        self.gridLayout = QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.groupBox = QGroupBox(self)
        self.groupBox.setObjectName("groupBox")
        self.verticalLayout = QVBoxLayout(self.groupBox)
        self.verticalLayout.setObjectName("verticalLayout")
        self.leFullName = QLineEdit(self.groupBox)
        self.leFullName.setObjectName("leFullName")
        self.verticalLayout.addWidget(self.leFullName)
        self.leUsuario = QLineEdit(self.groupBox)
        self.leUsuario.setObjectName("leUsuario")
        self.verticalLayout.addWidget(self.leUsuario)
        self.lePassword = QLineEdit(self.groupBox)
        self.lePassword.setObjectName("lePassword")
        self.lePassword.setEchoMode(QLineEdit.Password)
        self.verticalLayout.addWidget(self.lePassword)
        self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                 QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.pbAddUser = QPushButton(self)
        self.pbAddUser.setObjectName("pbAddUser")
        self.horizontalLayout.addWidget(self.pbAddUser)
        self.pbCancel = QPushButton(self)
        self.pbCancel.setObjectName("pbCancel")
        self.horizontalLayout.addWidget(self.pbCancel)
        self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 1)

        self.retranslateUi()
        QMetaObject.connectSlotsByName(self)

    def retranslateUi(self):
        self.setWindowTitle(
            QApplication.translate("dlgAddUser", "Dialog", None, -1))
        self.groupBox.setTitle(
            QApplication.translate("dlgAddUser", "GroupBox", None, -1))
        self.leFullName.setPlaceholderText(
            QApplication.translate("dlgAddUser", "Ingresar nombre completo",
                                   None, -1))
        self.leUsuario.setPlaceholderText(
            QApplication.translate("dlgAddUser", "Ingrese nombre de usuario",
                                   None, -1))
        self.lePassword.setPlaceholderText(
            QApplication.translate("dlgAddUser", "Ingrese su clave", None, -1))
        self.pbAddUser.setText(
            QApplication.translate("dlgAddUser", "Add user", None, -1))
        self.pbCancel.setText(
            QApplication.translate("dlgAddUser", "Cancel", None, -1))
Exemplo n.º 4
0
    def __create_vertical_section(self, group_name):
        # Setup layout
        groupbox = QGroupBox(group_name)
        groupbox.setObjectName(group_name)
        vertical_layout = QVBoxLayout()
        groupbox.setLayout(vertical_layout)

        '''
        Add widgets
        '''
        # Add file selection/loading widgets
        file_select_organizer = QHBoxLayout()
        text_input = QLineEdit() # Does this need a name yet?
        file_select_button = QPushButton("...")
        file_select_organizer.addWidget(text_input)
        file_select_organizer.addWidget(file_select_button)
        # Add the section we just made to layout
        vertical_layout.addLayout(file_select_organizer)

        # add listview for excel pages
        excel_label = QLabel("Excel Workbook Pages")
        excel_sheets = QListView()
        excel_sheets.setEditTriggers(QAbstractItemView.NoEditTriggers)
        excel_label_model = QStandardItemModel()
        excel_sheets.setModel(excel_label_model)

        vertical_layout.addWidget(excel_label)
        vertical_layout.addWidget(excel_sheets)


        # add listview for column headers
        variable_label = QLabel("Merge on column:")
        variables = QListView()
        variables.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.columns[group_name] = variables
        variables_model = QStandardItemModel()
        variables.setModel(variables_model)
        vertical_layout.addWidget(variable_label)
        vertical_layout.addWidget(variables)

        '''
        Connect Functions
        '''
        # Connect File dialog to file selection
        file_select_button.clicked.connect(lambda: self.openFileNameDialog(text_input, excel_label_model, group_name))
        # Connect listview to populate listview for column headers
        excel_sheets.clicked.connect(lambda x: self.populateColumns(x, excel_label_model, variables_model, group_name))

        return groupbox
Exemplo n.º 5
0
    def _create_categories_boxes(self, item_database: ItemDatabase,
                                 size_policy):
        self._boxes_for_category = {}

        categories = set()
        for major_item in item_database.major_items.values():
            if not major_item.required:
                categories.add(major_item.item_category)

        all_categories = list(iterate_enum(ItemCategory))

        current_row = 0
        for major_item_category in sorted(
                categories, key=lambda it: all_categories.index(it)):
            category_button = QToolButton(self.major_items_box)
            category_button.setGeometry(QRect(20, 30, 24, 21))
            category_button.setText("+")

            category_label = QLabel(self.major_items_box)
            category_label.setSizePolicy(size_policy)
            category_label.setText(major_item_category.long_name)

            category_box = QGroupBox(self.major_items_box)
            category_box.setSizePolicy(size_policy)
            category_box.setObjectName(f"category_box {major_item_category}")

            category_layout = QGridLayout(category_box)
            category_layout.setObjectName(
                f"category_layout {major_item_category}")

            self.major_items_layout.addWidget(category_button,
                                              2 * current_row + 1, 0, 1, 1)
            self.major_items_layout.addWidget(category_label,
                                              2 * current_row + 1, 1, 1, 1)
            self.major_items_layout.addWidget(category_box,
                                              2 * current_row + 2, 0, 1, 2)
            self._boxes_for_category[
                major_item_category] = category_box, category_layout, {}

            category_button.clicked.connect(
                partial(_toggle_box_visibility, category_button, category_box))
            category_box.setVisible(False)
            current_row += 1
Exemplo n.º 6
0
    def _create_categories_boxes(self, item_database: ItemDatabase, size_policy):
        self._boxes_for_category = {}

        categories = set()
        for major_item in item_database.major_items.values():
            if not major_item.required:
                categories.add(major_item.item_category)

        all_categories = list(iterate_enum(ItemCategory))
        for major_item_category in sorted(categories, key=lambda it: all_categories.index(it)):
            category_box = QGroupBox(self.scroll_area_contents)
            category_box.setTitle(major_item_category.long_name)
            category_box.setSizePolicy(size_policy)
            category_box.setObjectName(f"category_box {major_item_category}")

            category_layout = QGridLayout(category_box)
            category_layout.setObjectName(f"category_layout {major_item_category}")

            self.item_pool_layout.addWidget(category_box)
            self._boxes_for_category[major_item_category] = category_box, category_layout, {}
    def __init__(self):
        super(LayoutColorTest, self).__init__()
        main_layout = QVBoxLayout(self)

        box = QGroupBox()
        box.setObjectName("my_box")
        main_layout.addWidget(box)
        box_layout = QVBoxLayout(box)

        button = QPushButton("Click")
        box_layout.addWidget(button)

        box = QGroupBox()
        box.setObjectName("my_box2")
        main_layout.addWidget(box)
        box_layout = QVBoxLayout(box)

        button = QPushButton("Click")
        box_layout.addWidget(button)

        self.apply_style()
Exemplo n.º 8
0
class DataBrowserMain(QWidget):
    sliceUpdated = Signal(int, int, int, int)

    def __init__(self, parent):
        super(DataBrowserMain, self).__init__(parent)

        # data import
        self.brkraw_obj = self.parent().brkraw_obj
        self.selectedScan = None
        self.selectedScanTR = None

        self.set_viewer_frame()
        self.set_controller_frame()
        self.set_gridlayouts()
        self.set_font()
        # self.set_palette()  # TODO
        self.set_size()
        self.set_objectnames()
        self.set_texts()
        self.ratio_container = []
        self.init_connection()
        self.inactivate_widgets()  # Inactivate during startup

    def init_connection(self):
        self.parent().dataSelected.connect(
            self.selectScanEvent)  # run selectScanEvent when data selected
        self.event_timer = QTimer()
        self.event_timer.timeout.connect(self.sliceUpdateEvent)  #
        self.sliceUpdated.connect(self.updateImage)

        self.xaxis_slider.valueChanged.connect(self.xaxis_spinbox.setValue)
        self.xaxis_spinbox.valueChanged.connect(self.xaxis_slider.setValue)
        self.yaxis_slider.valueChanged.connect(self.yaxis_spinbox.setValue)
        self.yaxis_spinbox.valueChanged.connect(self.yaxis_slider.setValue)
        self.zaxis_slider.valueChanged.connect(self.zaxis_spinbox.setValue)
        self.zaxis_spinbox.valueChanged.connect(self.zaxis_slider.setValue)
        self.frame_slider.valueChanged.connect(self.frame_spinbox.setValue)
        self.frame_spinbox.valueChanged.connect(self.frame_slider.setValue)

        self.axial_view.pointed.connect(self.axialview_pointing_event)
        self.sagittal_view.pointed.connect(self.sagittalview_pointing_event)
        self.coronal_view.pointed.connect(self.coronalview_pointing_event)

        self.connect_sliders_to_update()

    def sagittalview_pointing_event(self, pos_x, pos_y, meta):
        max_x = self.yaxis_slider.maximum()
        max_y = self.zaxis_slider.maximum()

        # print(pos_x, pos_y, max_x, max_y)
        self.yaxis_slider.setValue(int(max_x * pos_x))
        self.zaxis_slider.setValue(max_y - int(max_y * pos_y))
        # print(int(max_x * pos_x), int(max_y * pos_y))

    def axialview_pointing_event(self, pos_x, pos_y, meta):
        max_x = self.yaxis_slider.maximum()
        max_y = self.xaxis_slider.maximum()

        # print(pos_x, pos_y, max_x, max_y)
        self.yaxis_slider.setValue(int(max_x * pos_x))
        self.xaxis_slider.setValue(int(max_y * pos_y))
        # print(int(max_x * pos_x), int(max_y * pos_y))

    def coronalview_pointing_event(self, pos_x, pos_y, meta):
        max_x = self.xaxis_slider.maximum()
        max_y = self.zaxis_slider.maximum()

        # print(pos_x, pos_y, max_x, max_y)
        self.xaxis_slider.setValue(int(max_x * pos_x))
        self.zaxis_slider.setValue(max_y - int(max_y * pos_y))
        # print(int(max_x * pos_x), int(max_y * pos_y))

    def sliderChangeEvent(self):
        self.event_timer.start(10)

    def sliceUpdateEvent(self):
        # This will executed only when timer timeout
        x = self.xaxis_slider.value()
        y = self.yaxis_slider.value()
        z = self.zaxis_slider.value()
        t = self.frame_slider.value()
        self.sliceUpdated.emit(x, y, z, t)
        self.event_timer.stop()

    @staticmethod
    def slice_data(dataobj, slice_orient, slice_num):
        if slice_orient == 'axial':
            sliced_data = dataobj[:, :, slice_num]
        elif slice_orient == 'sagittal':
            sliced_data = dataobj[:, slice_num, ::-1]
        elif slice_orient == 'coronal':
            sliced_data = dataobj[slice_num, :, ::-1]
        else:
            popup_error_dialog(UnexpectedError.message)
            return None
        return sliced_data

    def updateImage(self, x, y, z, frame):
        if len(self.selectedScan.shape) == 4:
            dataobj = self.selectedScan[:, :, :, frame]
        else:
            dataobj = self.selectedScan[...]

        data_xy = self.slice_data(dataobj, 'axial', z)
        data_yz = self.slice_data(dataobj, 'sagittal', x)
        data_xz = self.slice_data(dataobj, 'coronal', y)
        ratio_xy, ratio_yz, ratio_xz = self.ratio_container
        # ratio_xy, ratio_yz, ratio_xz = 1, 1, 1

        qm_xy = convert_arr2qpixmap(data_xy, ratio_xy)
        qm_yz = convert_arr2qpixmap(data_yz, ratio_yz)
        qm_xz = convert_arr2qpixmap(data_xz, ratio_xz)

        self.axial_view.setPixmap(qm_xy)
        self.sagittal_view.setPixmap(qm_yz)
        self.coronal_view.setPixmap(qm_xz)

    def selectScanEvent(self, delivery_package: list):
        """ this event is occurring when a scan selected on scanlist """
        self.axial_view.setEnabled(True)
        self.sagittal_view.setEnabled(True)
        self.coronal_view.setEnabled(True)
        self.selectedScan, affine, resol, self.selectedScanTR, is_localizer = delivery_package
        self.selectedScanTR /= 1000

        from slfmri.imgman import reorient_to_ras, determine_slice_plane
        slice_plane_ref = dict(sagittal=0, coronal=1, axial=2)

        if is_localizer:
            img_container = dict()
            for i, aff in enumerate(affine):
                size = config.get('ImageViewer', 'size')
                data = self.selectedScan[..., i]
                slice_plane = determine_slice_plane(2, aff, resol)
                ras_data, ras_resol = reorient_to_ras(data[:, :, np.newaxis],
                                                      aff, resol)
                slice_axis = slice_plane_ref[slice_plane]
                ras_data = ras_data.mean(slice_axis)
                ras_resol = np.delete(ras_resol, slice_axis)
                qpixmap = convert_arr2qpixmap(ras_data, ras_resol, size)
                img_container[slice_plane] = qpixmap

            self.update_axisview(img_container)
        else:
            # other than localizer
            self.init_data(self.selectedScan)
            matrix_size = np.asarray(self.selectedScan.shape)
            resol = np.asarray(resol)
            fov = matrix_size[:3] * resol
            self.ratio_container = [
                fov[0] / fov[1], fov[1] / fov[2], fov[0] / fov[2]
            ]
            # reset value
            init_x, init_y, init_z = (np.asarray(self.selectedScan.shape[:3]) /
                                      2.0).astype(int)
            init_f = 0

            self.disconnect_sliders_to_update()
            self.xaxis_slider.setValue(init_x)
            self.yaxis_slider.setValue(init_y)
            self.zaxis_slider.setValue(init_z)
            self.frame_slider.setValue(init_f)
            self.connect_sliders_to_update()
            self.updateImage(init_x, init_y, init_z, init_f)

    def connect_sliders_to_update(self):
        # connect to check slice update
        self.xaxis_slider.valueChanged.connect(self.sliderChangeEvent)
        self.yaxis_slider.valueChanged.connect(self.sliderChangeEvent)
        self.zaxis_slider.valueChanged.connect(self.sliderChangeEvent)
        self.frame_slider.valueChanged.connect(self.sliderChangeEvent)

    def disconnect_sliders_to_update(self):
        # disconnect to check slice update
        self.xaxis_slider.valueChanged.disconnect(self.sliderChangeEvent)
        self.yaxis_slider.valueChanged.disconnect(self.sliderChangeEvent)
        self.zaxis_slider.valueChanged.disconnect(self.sliderChangeEvent)
        self.frame_slider.valueChanged.disconnect(self.sliderChangeEvent)

    def init_data(self, dataobj):
        self.slicecontrol_pane.setEnabled(True)
        dim = len(dataobj.shape)
        if dim == 3:
            size_x, size_y, size_z = dataobj.shape
            size_frame = None
        elif dim == 4:
            size_x, size_y, size_z, size_frame = dataobj.shape
        else:
            popup_error_dialog(UnexpectedError.message)
            return None

        # init sliders and spinboxes
        self.xaxis_slider.setRange(0, size_x - 1)
        self.yaxis_slider.setRange(0, size_y - 1)
        self.zaxis_slider.setRange(0, size_z - 1)

        self.xaxis_spinbox.setRange(0, size_x - 1)
        self.yaxis_spinbox.setRange(0, size_y - 1)
        self.zaxis_spinbox.setRange(0, size_z - 1)

        if dim == 3:
            self.frame_label.setDisabled(True)
            self.frame_slider.setDisabled(True)
            self.frame_spinbox.setDisabled(True)
        else:
            self.frame_label.setEnabled(True)
            self.frame_slider.setEnabled(True)
            self.frame_spinbox.setEnabled(True)
            self.frame_slider.setRange(0, size_frame - 1)
            self.frame_spinbox.setRange(0, size_frame - 1)

    def update_axisview(self, img_container: dict):
        for view_plane, pixmap in img_container.items():
            if view_plane == 'axial':
                self.axial_view.setPixmap(pixmap)
            elif view_plane == 'sagittal':
                self.sagittal_view.setPixmap(pixmap)
            else:
                self.coronal_view.setPixmap(pixmap)

    def inactivate_widgets(self):
        self.slicecontrol_pane.setDisabled(True)
        self.graph_frame.setDisabled(True)

    def set_navigationmode(self):
        # mouse click will navigate slice.
        pass

    def set_drawingmode(self):
        # roi drawing function
        pass

    def mask_data_handler(self):
        # mask later handler
        pass

    def slider_event_related(self):
        # slider for slicing.
        pass

    def set_viewer_frame(self):
        self.imageframe = QFrame(self)
        self.axial_view = SliceViewer(self.imageframe)
        self.axial_view.setDisabled(True)
        self.sagittal_view = SliceViewer(self.imageframe)
        self.sagittal_view.setDisabled(True)
        self.coronal_view = SliceViewer(self.imageframe)
        self.coronal_view.setDisabled(True)

        # TODO: Will reactivate these on later version
        # self.axial_title = QLabel(self.imageframe)
        # self.coronal_title = QLabel(self.imageframe)
        # self.sagittal_title = QLabel(self.imageframe)
        #
        # self.axialL_label = QLabel(self.imageframe)
        # self.axialA_label = QLabel(self.imageframe)
        # self.axialR_label = QLabel(self.imageframe)
        # self.axialP_label = QLabel(self.imageframe)
        #
        # self.sagittalS_label = QLabel(self.imageframe)
        # self.sagittalA_label = QLabel(self.imageframe)
        # self.sagittalI_label = QLabel(self.imageframe)
        # self.sagittalP_label = QLabel(self.imageframe)
        #
        # self.coronalL_label = QLabel(self.imageframe)
        # self.coronalS_label = QLabel(self.imageframe)
        # self.coronalR_label = QLabel(self.imageframe)
        # self.coronalI_label = QLabel(self.imageframe)
        #
        # self.axial_title.setTextFormat(Qt.MarkdownText)
        # self.axialL_label.setTextFormat(Qt.MarkdownText)
        # self.axialA_label.setTextFormat(Qt.MarkdownText)
        # self.axialR_label.setTextFormat(Qt.MarkdownText)
        # self.axialP_label.setTextFormat(Qt.MarkdownText)
        #
        # self.sagittal_title.setTextFormat(Qt.MarkdownText)
        # self.sagittalS_label.setTextFormat(Qt.MarkdownText)
        # self.sagittalA_label.setTextFormat(Qt.MarkdownText)
        # self.sagittalI_label.setTextFormat(Qt.MarkdownText)
        # self.sagittalP_label.setTextFormat(Qt.MarkdownText)
        #
        # self.coronal_title.setTextFormat(Qt.MarkdownText)
        # self.coronalL_label.setTextFormat(Qt.MarkdownText)
        # self.coronalS_label.setTextFormat(Qt.MarkdownText)
        # self.coronalR_label.setTextFormat(Qt.MarkdownText)
        # self.coronalI_label.setTextFormat(Qt.MarkdownText)
        #
        # self.axial_title.setAlignment(Qt.AlignCenter)
        # self.axialL_label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
        # self.axialA_label.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)
        # self.axialR_label.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter)
        # self.axialP_label.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
        #
        # self.sagittal_title.setAlignment(Qt.AlignCenter)
        # self.sagittalS_label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
        # self.sagittalA_label.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)
        # self.sagittalI_label.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter)
        # self.sagittalP_label.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
        #
        # self.coronal_title.setAlignment(Qt.AlignCenter)
        # self.coronalL_label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
        # self.coronalS_label.setAlignment(Qt.AlignBottom | Qt.AlignHCenter)
        # self.coronalR_label.setAlignment(Qt.AlignLeading | Qt.AlignLeft | Qt.AlignVCenter)
        # self.coronalI_label.setAlignment(Qt.AlignHCenter | Qt.AlignTop)

    def set_controller_frame(self):
        self.controller_frame = QFrame(self)
        self.slicecontrol_pane = QGroupBox(self.controller_frame)
        self.frame_spinbox = QSpinBox(self.slicecontrol_pane)

        self.xaxis_label = QLabel(self.slicecontrol_pane)
        self.yaxis_label = QLabel(self.slicecontrol_pane)
        self.zaxis_label = QLabel(self.slicecontrol_pane)
        self.frame_label = QLabel(self.slicecontrol_pane)

        self.xaxis_slider = QSlider(self.slicecontrol_pane)
        self.yaxis_slider = QSlider(self.slicecontrol_pane)
        self.zaxis_slider = QSlider(self.slicecontrol_pane)
        self.frame_slider = QSlider(self.slicecontrol_pane)

        self.xaxis_spinbox = QSpinBox(self.slicecontrol_pane)
        self.yaxis_spinbox = QSpinBox(self.slicecontrol_pane)
        self.zaxis_spinbox = QSpinBox(self.slicecontrol_pane)

        self.graph_frame = QFrame(self)
        self.graph_view = pg.PlotWidget(self.graph_frame)
        self.graph_view.setBackground('w')

        # TODO: Will reactivate these on later version
        # self.graph_view = QGraphicsView(self.graph_frame)
        # self.graphcontrol_pane = QGroupBox(self.graph_frame)
        # self.addmask_button = QPushButton(self.graphcontrol_pane)
        # self.removemask_button = QPushButton(self.graphcontrol_pane)
        # self.mask_listview = QListView(self.graphcontrol_pane)
        # self.savepng_button = QPushButton(self.graphcontrol_pane)
        # self.savecsv_button = QPushButton(self.graphcontrol_pane)

        self.axial_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.sagittal_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.coronal_view.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

        self.xaxis_slider.setOrientation(Qt.Horizontal)
        self.yaxis_slider.setOrientation(Qt.Horizontal)
        self.zaxis_slider.setOrientation(Qt.Horizontal)
        self.frame_slider.setOrientation(Qt.Horizontal)

        self.slicecontrol_pane.setAlignment(Qt.AlignCenter)
        self.xaxis_label.setAlignment(Qt.AlignCenter)
        self.yaxis_label.setAlignment(Qt.AlignCenter)
        self.zaxis_label.setAlignment(Qt.AlignCenter)
        self.frame_label.setAlignment(Qt.AlignCenter)
        # TODO: Will reactivate these on later version
        # self.graphcontrol_pane.setAlignment(Qt.AlignCenter)

    def set_size(self):
        size = int(config.get('ImageViewer', 'size'))
        self.imageframe.setLineWidth(0)
        self.axial_view.setMinimumSize(QSize(size, size))
        self.axial_view.setMaximumSize(QSize(size, size))
        self.axial_view.setLineWidth(0)
        self.sagittal_view.setMinimumSize(QSize(size, size))
        self.sagittal_view.setMaximumSize(QSize(size, size))
        self.sagittal_view.setLineWidth(0)
        self.coronal_view.setMinimumSize(QSize(size, size))
        self.coronal_view.setMaximumSize(QSize(size, size))
        self.coronal_view.setLineWidth(0)

        # TODO: Will reactivate these on later version
        # self.axialL_label.setMinimumSize(QSize(20, 0))
        # self.axialA_label.setMinimumSize(QSize(0, 20))
        # self.axialR_label.setMinimumSize(QSize(20, 0))
        # self.axialP_label.setMinimumSize(QSize(0, 20))
        # self.sagittalS_label.setMinimumSize(QSize(20, 0))
        # self.sagittalA_label.setMinimumSize(QSize(0, 20))
        # self.sagittalI_label.setMinimumSize(QSize(20, 0))
        # self.sagittalP_label.setMinimumSize(QSize(0, 20))
        # self.coronalL_label.setMinimumSize(QSize(20, 0))
        # self.coronalS_label.setMinimumSize(QSize(0, 20))
        # self.coronalR_label.setMinimumSize(QSize(20, 0))
        # self.coronalI_label.setMinimumSize(QSize(0, 20))

        self.controller_frame.setMinimumSize(QSize(300, 300))
        self.controller_frame.setMaximumSize(QSize(400, 300))
        self.graph_frame.setMinimumSize(QSize(0, 300))
        self.graph_frame.setMaximumSize(QSize(4000, 4000))
        self.graph_view.setMaximumSize(QSize(4000, 600))

        # TODO: Will reactivate these on later version
        # self.graphcontrol_pane.setMinimumSize(QSize(300, 0))
        # self.graphcontrol_pane.setMaximumSize(QSize(300, 4000))
        # self.addmask_button.setMinimumSize(QSize(30, 0))
        # self.addmask_button.setMaximumSize(QSize(30, 4000))
        # self.removemask_button.setMinimumSize(QSize(30, 0))
        # self.removemask_button.setMaximumSize(QSize(30, 4000))

    def set_font(self):
        self.arial_8 = QFont()
        self.arial_8.setFamily(u"Arial")
        self.arial_8.setPointSize(8)
        self.setFont(self.arial_8)
        # TODO: Will reactivate these on later version
        # self.axial_title.setFont(self.arial_8)
        # self.coronal_title.setFont(self.arial_8)
        # self.sagittal_title.setFont(self.arial_8)
        # self.axialL_label.setFont(self.arial_8)
        # self.axialA_label.setFont(self.arial_8)
        # self.axialR_label.setFont(self.arial_8)
        # self.axialP_label.setFont(self.arial_8)
        # self.sagittalS_label.setFont(self.arial_8)
        # self.sagittalA_label.setFont(self.arial_8)
        # self.sagittalI_label.setFont(self.arial_8)
        # self.sagittalP_label.setFont(self.arial_8)
        # self.coronalL_label.setFont(self.arial_8)
        # self.coronalS_label.setFont(self.arial_8)
        # self.coronalR_label.setFont(self.arial_8)
        # self.coronalI_label.setFont(self.arial_8)
        self.slicecontrol_pane.setFont(self.arial_8)

        # TODO: Will reactivate these on later version
        # self.xaxis_label.setFont(self.arial_8)
        # self.yaxis_label.setFont(self.arial_8)
        # self.zaxis_label.setFont(self.arial_8)
        # self.frame_label.setFont(self.arial_8)
        # self.graphcontrol_pane.setFont(self.arial_8)
        # self.addmask_button.setFont(self.arial_8)
        # self.removemask_button.setFont(self.arial_8)
        # self.savepng_button.setFont(self.arial_8)
        # self.savecsv_button.setFont(self.arial_8)

    def set_palette(self):
        # Brush
        gray_text = QBrush(QColor(171, 171, 171, 255))
        gray_text.setStyle(Qt.SolidPattern)
        black_background = QBrush(QColor(0, 0, 0, 255))
        black_background.setStyle(Qt.SolidPattern)

        self.orientation_label_palette = QPalette()
        self.orientation_label_palette.setBrush(QPalette.Active,
                                                QPalette.WindowText, gray_text)
        self.orientation_label_palette.setBrush(QPalette.Inactive,
                                                QPalette.WindowText, gray_text)
        self.orientation_label_palette.setBrush(QPalette.Disabled,
                                                QPalette.WindowText, gray_text)
        self.ortho_viewer_palette = QPalette()
        self.ortho_viewer_palette.setBrush(QPalette.Active, QPalette.Base,
                                           black_background)
        self.ortho_viewer_palette.setBrush(QPalette.Inactive, QPalette.Base,
                                           black_background)
        self.ortho_viewer_palette.setBrush(QPalette.Disabled, QPalette.Base,
                                           black_background)

        self.axialA_label.setPalette(self.orientation_label_palette)
        self.axialL_label.setPalette(self.orientation_label_palette)
        self.axialR_label.setPalette(self.orientation_label_palette)
        self.axialP_label.setPalette(self.orientation_label_palette)
        self.axial_view.setPalette(self.ortho_viewer_palette)
        self.sagittalS_label.setPalette(self.orientation_label_palette)
        self.sagittalA_label.setPalette(self.orientation_label_palette)
        self.sagittalI_label.setPalette(self.orientation_label_palette)
        self.sagittalP_label.setPalette(self.orientation_label_palette)
        self.sagittal_view.setPalette(self.ortho_viewer_palette)
        self.coronalL_label.setPalette(self.orientation_label_palette)
        self.coronalS_label.setPalette(self.orientation_label_palette)
        self.coronalR_label.setPalette(self.orientation_label_palette)
        self.coronalI_label.setPalette(self.orientation_label_palette)
        self.coronal_view.setPalette(self.ortho_viewer_palette)

    def set_gridlayouts(self):
        self.axial_gridLayout = QGridLayout()
        self.coronal_gridLayout = QGridLayout()
        self.sagittal_gridLayout = QGridLayout()
        self.imagecont_gridLayout = QGridLayout(self.slicecontrol_pane)
        self.imageframe_gridLayout = QGridLayout(self.imageframe)
        # self.graphcontrol_gridLayout = QGridLayout(self.graphcontrol_pane)
        self.verticalLayout = QVBoxLayout(self.controller_frame)
        self.horizontalLayout = QHBoxLayout(self.graph_frame)
        self.main_gridLayout = QGridLayout(self)
        # TODO: Will reactivate these on later version
        # self.imageframe_gridLayout.addWidget(self.axial_title, 0, 1, 1, 1)
        # self.imageframe_gridLayout.addWidget(self.coronal_title, 0, 2, 1, 1)
        # self.imageframe_gridLayout.addWidget(self.sagittal_title, 0, 0, 1, 1)
        # self.axial_gridLayout.addWidget(self.axialL_label, 1, 0, 1, 1)
        # self.axial_gridLayout.addWidget(self.axialA_label, 0, 1, 1, 1)
        # self.axial_gridLayout.addWidget(self.axialR_label, 1, 2, 1, 1)
        # self.axial_gridLayout.addWidget(self.axialP_label, 2, 1, 1, 1)
        self.axial_gridLayout.addWidget(self.axial_view, 1, 1, 1, 1)
        # self.sagittal_gridLayout.addWidget(self.sagittalS_label, 1, 0, 1, 1)
        # self.sagittal_gridLayout.addWidget(self.sagittalA_label, 0, 1, 1, 1)
        # self.sagittal_gridLayout.addWidget(self.sagittalI_label, 1, 2, 1, 1)
        # self.sagittal_gridLayout.addWidget(self.sagittalP_label, 2, 1, 1, 1)
        self.sagittal_gridLayout.addWidget(self.sagittal_view, 1, 1, 1, 1)
        # self.coronal_gridLayout.addWidget(self.coronalL_label, 1, 0, 1, 1)
        # self.coronal_gridLayout.addWidget(self.coronalS_label, 0, 1, 1, 1)
        # self.coronal_gridLayout.addWidget(self.coronalR_label, 1, 2, 1, 1)
        # self.coronal_gridLayout.addWidget(self.coronalI_label, 2, 1, 1, 1)
        self.coronal_gridLayout.addWidget(self.coronal_view, 1, 1, 1, 1)
        self.imagecont_gridLayout.addWidget(self.xaxis_label, 0, 0, 1, 1)
        self.imagecont_gridLayout.addWidget(self.xaxis_slider, 0, 1, 1, 1)
        self.imagecont_gridLayout.addWidget(self.xaxis_spinbox, 0, 2, 1, 1)
        self.imagecont_gridLayout.addWidget(self.yaxis_label, 1, 0, 1, 1)
        self.imagecont_gridLayout.addWidget(self.yaxis_slider, 1, 1, 1, 1)
        self.imagecont_gridLayout.addWidget(self.yaxis_spinbox, 1, 2, 1, 1)
        self.imagecont_gridLayout.addWidget(self.zaxis_label, 2, 0, 1, 1)
        self.imagecont_gridLayout.addWidget(self.zaxis_slider, 2, 1, 1, 1)
        self.imagecont_gridLayout.addWidget(self.zaxis_spinbox, 2, 2, 1, 1)
        self.imagecont_gridLayout.addWidget(self.frame_label, 3, 0, 1, 1)
        self.imagecont_gridLayout.addWidget(self.frame_slider, 3, 1, 1, 1)
        self.imagecont_gridLayout.addWidget(self.frame_spinbox, 3, 2, 1, 1)
        self.imageframe_gridLayout.addLayout(self.axial_gridLayout, 1, 1, 1, 1)
        self.imageframe_gridLayout.addLayout(self.coronal_gridLayout, 1, 2, 1,
                                             1)
        self.imageframe_gridLayout.addLayout(self.sagittal_gridLayout, 1, 0, 1,
                                             1)
        # self.graphcontrol_gridLayout.addWidget(self.addmask_button, 3, 0, 1, 1)
        # self.graphcontrol_gridLayout.addWidget(self.removemask_button, 3, 1, 1, 1)
        # self.graphcontrol_gridLayout.addWidget(self.mask_listview, 0, 0, 1, 5)
        # self.graphcontrol_gridLayout.addWidget(self.savepng_button, 3, 4, 1, 1)
        # self.graphcontrol_gridLayout.addWidget(self.savecsv_button, 3, 3, 1, 1)
        self.verticalLayout.addWidget(self.slicecontrol_pane)
        self.horizontalLayout.addWidget(self.graph_view)
        # self.horizontalLayout.addWidget(self.graphcontrol_pane)
        self.main_gridLayout.addWidget(self.imageframe, 0, 0, 1, 2)
        self.main_gridLayout.addWidget(self.controller_frame, 1, 0, 1, 1)
        self.main_gridLayout.addWidget(self.graph_frame, 1, 1, 1, 1)

    def set_objectnames(self):
        self.setObjectName(u"data_browser")
        self.imageframe.setObjectName(u"image_frame")
        self.axial_gridLayout.setObjectName(u"axial_gridLayout")
        self.coronal_gridLayout.setObjectName(u"coronal_gridLayout")
        self.sagittal_gridLayout.setObjectName(u"sagittal_gridLayout")
        # TODO: Will reactivate these on later version
        # self.axial_title.setObjectName(u"axial_label")
        # self.coronal_title.setObjectName(u"coronal_label")
        # self.sagittal_title.setObjectName(u"sagittal_label")
        self.axial_view.setObjectName(u"axial_view")
        self.sagittal_view.setObjectName(u"sagittal_view")
        self.coronal_view.setObjectName(u"coronal_view")
        # self.axialL_label.setObjectName(u"axialL_label")
        # self.axialR_label.setObjectName(u"axialR_label")
        # self.axialA_label.setObjectName(u"axialA_label")
        # self.axialP_label.setObjectName(u"axialP_label")
        # self.sagittalS_label.setObjectName(u"sagittalS_label")
        # self.sagittalA_label.setObjectName(u"sagittalA_label")
        # self.sagittalI_label.setObjectName(u"sagittalI_label")
        # self.sagittalP_label.setObjectName(u"sagittalP_label")
        # self.coronalL_label.setObjectName(u"coronalL_label")
        # self.coronalS_label.setObjectName(u"coronalS_label")
        # self.coronalR_label.setObjectName(u"coronalR_label")
        # self.coronalI_label.setObjectName(u"coronalI_label")
        self.controller_frame.setObjectName(u"controller_frame")
        self.slicecontrol_pane.setObjectName(u"slicecontrol_pane")
        self.xaxis_label.setObjectName(u"xaxis_label")
        self.xaxis_slider.setObjectName(u"xaxis_slider")
        self.xaxis_spinbox.setObjectName(u"xaxis_spinbox")
        self.yaxis_label.setObjectName(u"yaxis_label")
        self.yaxis_slider.setObjectName(u"yaxis_slider")
        self.yaxis_spinbox.setObjectName(u"yaxis_spinbox")
        self.zaxis_label.setObjectName(u"zaxis_label")
        self.zaxis_slider.setObjectName(u"zaxis_slider")
        self.zaxis_spinbox.setObjectName(u"zaxis_spinbox")
        self.frame_label.setObjectName(u"frame_label")
        self.frame_slider.setObjectName(u"frame_slider")
        self.frame_spinbox.setObjectName(u"frame_spinbox")
        self.graph_frame.setObjectName(u"graph_frame")
        self.graph_view.setObjectName(u"graph_view")
        # TODO: Will reactivate these on later version
        # self.graphcontrol_pane.setObjectName(u"graphcontrol_pane")
        # self.addmask_button.setObjectName(u"addmask_button")
        # self.removemask_button.setObjectName(u"removemask_button")
        # self.mask_listview.setObjectName(u"mask_listview")
        # self.savepng_button.setObjectName(u"savepng_button")
        # self.savecsv_button.setObjectName(u"savecsv_button")
        self.imagecont_gridLayout.setObjectName(u"imagecont_gridLayout")
        self.imageframe_gridLayout.setObjectName(u"imageframe_gridLayout")
        # self.graphcontrol_gridLayout.setObjectName(u"graphcontrol_gridLayout")
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.main_gridLayout.setObjectName(u"main_gridLayout")
        QMetaObject.connectSlotsByName(self)

    def set_texts(self):
        self.setWindowTitle(u"Data Browser")
        # TODO: Will reactivate these on later version
        # self.axial_title.setText(u"**Axial**")
        # self.coronal_title.setText(u"**Coronal**")
        # self.sagittal_title.setText(u"**Sagittal**")
        # self.sagittalS_label.setText(u"**S**")
        # self.sagittalA_label.setText(u"**A**")
        # self.sagittalI_label.setText(u"**I**")
        # self.sagittalP_label.setText(u"**P**")
        # self.axialL_label.setText(u"**L**")
        # self.axialA_label.setText(u"**A**")
        # self.axialR_label.setText(u"**R**")
        # self.axialP_label.setText( u"**P**")
        # self.coronalL_label.setText(u"**L**")
        # self.coronalS_label.setText(u"**S**")
        # self.coronalR_label.setText(u"**R**")
        # self.coronalI_label.setText(u"**I**")
        self.slicecontrol_pane.setTitle(u"Slice Control Pane")
        self.xaxis_label.setText(u"x")
        self.yaxis_label.setText(u"y")
        self.zaxis_label.setText(u"z")
        self.frame_label.setText(u"Frame")
        # TODO: Will reactivate these on later version
        # self.graphcontrol_pane.setTitle(u"Graph Control Pane")
        # self.addmask_button.setText(u"+")
        # self.removemask_button.setText(u"-")
        # self.savepng_button.setText(u"toPNG")
        # self.savecsv_button.setText(u"toCSV")

    def plot_timecourse(self, x, y):
        self.graph_frame.setEnabled(True)
        self.graph_view.clear()
        pen = pg.mkPen(color=(255, 0, 0))
        if x is None:
            x = [0]
            y = [y]
            self.graph_view.plot(x, y, pen=pen, symbol='o')
        else:
            self.graph_view.plot(x, y, pen=pen)

    def get_coord(self):
        x = self.xaxis_slider.value()
        y = self.yaxis_slider.value()
        z = self.zaxis_slider.value()
        return (x, y, z)
Exemplo n.º 9
0
class Ui_GroupBox(object):
    def setupUi(self, GroupBox):
        if not GroupBox.objectName():
            GroupBox.setObjectName(u"GroupBox")
        GroupBox.resize(535, 520)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(GroupBox.sizePolicy().hasHeightForWidth())
        GroupBox.setSizePolicy(sizePolicy)
        self.verticalLayout_2 = QVBoxLayout(GroupBox)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.groupBox_occupancy_histogram = QGroupBox(GroupBox)
        self.groupBox_occupancy_histogram.setObjectName(
            u"groupBox_occupancy_histogram")
        self.verticalLayout = QVBoxLayout(self.groupBox_occupancy_histogram)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.label_56 = QLabel(self.groupBox_occupancy_histogram)
        self.label_56.setObjectName(u"label_56")
        self.label_56.setMaximumSize(QSize(16777215, 16777215))
        self.label_56.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout.addWidget(self.label_56)

        self.lineEdit_bins = QLineEdit(self.groupBox_occupancy_histogram)
        self.lineEdit_bins.setObjectName(u"lineEdit_bins")
        self.lineEdit_bins.setMinimumSize(QSize(50, 0))
        self.lineEdit_bins.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout.addWidget(self.lineEdit_bins)

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

        self.horizontalLayout.addItem(self.horizontalSpacer_3)

        self.label_55 = QLabel(self.groupBox_occupancy_histogram)
        self.label_55.setObjectName(u"label_55")
        self.label_55.setMaximumSize(QSize(16777215, 16777215))
        self.label_55.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout.addWidget(self.label_55)

        self.lineEdit_minimum = QLineEdit(self.groupBox_occupancy_histogram)
        self.lineEdit_minimum.setObjectName(u"lineEdit_minimum")
        self.lineEdit_minimum.setMinimumSize(QSize(50, 0))
        self.lineEdit_minimum.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout.addWidget(self.lineEdit_minimum)

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

        self.horizontalLayout.addItem(self.horizontalSpacer_2)

        self.label_17 = QLabel(self.groupBox_occupancy_histogram)
        self.label_17.setObjectName(u"label_17")
        self.label_17.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout.addWidget(self.label_17)

        self.lineEdit_maximum = QLineEdit(self.groupBox_occupancy_histogram)
        self.lineEdit_maximum.setObjectName(u"lineEdit_maximum")
        self.lineEdit_maximum.setMinimumSize(QSize(50, 0))
        self.lineEdit_maximum.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout.addWidget(self.lineEdit_maximum)

        self.verticalLayout.addLayout(self.horizontalLayout)

        self.horizontalLayout_7 = QHBoxLayout()
        self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
        self.checkBox_cumulative_histogram = QCheckBox(
            self.groupBox_occupancy_histogram)
        self.checkBox_cumulative_histogram.setObjectName(
            u"checkBox_cumulative_histogram")

        self.horizontalLayout_7.addWidget(self.checkBox_cumulative_histogram)

        self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Fixed,
                                               QSizePolicy.Minimum)

        self.horizontalLayout_7.addItem(self.horizontalSpacer_12)

        self.checkBox_stacked_histogram = QCheckBox(
            self.groupBox_occupancy_histogram)
        self.checkBox_stacked_histogram.setObjectName(
            u"checkBox_stacked_histogram")

        self.horizontalLayout_7.addWidget(self.checkBox_stacked_histogram)

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

        self.horizontalLayout_7.addItem(self.horizontalSpacer_11)

        self.verticalLayout.addLayout(self.horizontalLayout_7)

        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.checkBox_color_segments_occupancy = QCheckBox(
            self.groupBox_occupancy_histogram)
        self.checkBox_color_segments_occupancy.setObjectName(
            u"checkBox_color_segments_occupancy")
        self.checkBox_color_segments_occupancy.setChecked(True)

        self.horizontalLayout_6.addWidget(
            self.checkBox_color_segments_occupancy)

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

        self.horizontalLayout_6.addItem(self.horizontalSpacer_9)

        self.verticalLayout.addLayout(self.horizontalLayout_6)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                            QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer)

        self.pushButton_save_occupancy = QPushButton(
            self.groupBox_occupancy_histogram)
        self.pushButton_save_occupancy.setObjectName(
            u"pushButton_save_occupancy")

        self.horizontalLayout_2.addWidget(self.pushButton_save_occupancy)

        self.pushButton_plot_occupancy = QPushButton(
            self.groupBox_occupancy_histogram)
        self.pushButton_plot_occupancy.setObjectName(
            u"pushButton_plot_occupancy")
        self.pushButton_plot_occupancy.setAutoDefault(False)

        self.horizontalLayout_2.addWidget(self.pushButton_plot_occupancy)

        self.verticalLayout.addLayout(self.horizontalLayout_2)

        self.verticalLayout_2.addWidget(self.groupBox_occupancy_histogram)

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

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.groupBox_nb_connections = QGroupBox(GroupBox)
        self.groupBox_nb_connections.setObjectName(u"groupBox_nb_connections")
        self.verticalLayout_3 = QVBoxLayout(self.groupBox_nb_connections)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.checkBox_color_segments_timeseries = QCheckBox(
            self.groupBox_nb_connections)
        self.checkBox_color_segments_timeseries.setObjectName(
            u"checkBox_color_segments_timeseries")
        self.checkBox_color_segments_timeseries.setChecked(True)

        self.horizontalLayout_5.addWidget(
            self.checkBox_color_segments_timeseries)

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

        self.horizontalLayout_5.addItem(self.horizontalSpacer_7)

        self.verticalLayout_3.addLayout(self.horizontalLayout_5)

        self.horizontalLayout_4 = QHBoxLayout()
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.horizontalSpacer_5 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_4.addItem(self.horizontalSpacer_5)

        self.pushButton_save_timeseries = QPushButton(
            self.groupBox_nb_connections)
        self.pushButton_save_timeseries.setObjectName(
            u"pushButton_save_timeseries")

        self.horizontalLayout_4.addWidget(self.pushButton_save_timeseries)

        self.pushButton_plot_timeseries = QPushButton(
            self.groupBox_nb_connections)
        self.pushButton_plot_timeseries.setObjectName(
            u"pushButton_plot_timeseries")
        self.pushButton_plot_timeseries.setAutoDefault(False)

        self.horizontalLayout_4.addWidget(self.pushButton_plot_timeseries)

        self.verticalLayout_3.addLayout(self.horizontalLayout_4)

        self.verticalLayout_2.addWidget(self.groupBox_nb_connections)

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

        self.verticalLayout_2.addItem(self.verticalSpacer)

        self.groupBox_joint_occupancy = QGroupBox(GroupBox)
        self.groupBox_joint_occupancy.setObjectName(
            u"groupBox_joint_occupancy")
        self.verticalLayout_4 = QVBoxLayout(self.groupBox_joint_occupancy)
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.horizontalLayout_10 = QHBoxLayout()
        self.horizontalLayout_10.setObjectName(u"horizontalLayout_10")
        self.radioButton_scatter = QRadioButton(self.groupBox_joint_occupancy)
        self.radioButton_scatter.setObjectName(u"radioButton_scatter")
        self.radioButton_scatter.setChecked(True)

        self.horizontalLayout_10.addWidget(self.radioButton_scatter)

        self.label_3 = QLabel(self.groupBox_joint_occupancy)
        self.label_3.setObjectName(u"label_3")

        self.horizontalLayout_10.addWidget(self.label_3)

        self.lineEdit_scatter_size = QLineEdit(self.groupBox_joint_occupancy)
        self.lineEdit_scatter_size.setObjectName(u"lineEdit_scatter_size")
        self.lineEdit_scatter_size.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_10.addWidget(self.lineEdit_scatter_size)

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

        self.horizontalLayout_10.addItem(self.horizontalSpacer_10)

        self.verticalLayout_4.addLayout(self.horizontalLayout_10)

        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.radioButton_heatmap = QRadioButton(self.groupBox_joint_occupancy)
        self.radioButton_heatmap.setObjectName(u"radioButton_heatmap")

        self.horizontalLayout_3.addWidget(self.radioButton_heatmap)

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

        self.horizontalLayout_3.addItem(self.horizontalSpacer_4)

        self.pushButton_save_jo = QPushButton(self.groupBox_joint_occupancy)
        self.pushButton_save_jo.setObjectName(u"pushButton_save_jo")

        self.horizontalLayout_3.addWidget(self.pushButton_save_jo)

        self.pushButton_plot_jo = QPushButton(self.groupBox_joint_occupancy)
        self.pushButton_plot_jo.setObjectName(u"pushButton_plot_jo")
        self.pushButton_plot_jo.setAutoDefault(False)

        self.horizontalLayout_3.addWidget(self.pushButton_plot_jo)

        self.verticalLayout_4.addLayout(self.horizontalLayout_3)

        self.verticalLayout_2.addWidget(self.groupBox_joint_occupancy)

        self.retranslateUi(GroupBox)

        QMetaObject.connectSlotsByName(GroupBox)

    # setupUi

    def retranslateUi(self, GroupBox):
        GroupBox.setWindowTitle(
            QCoreApplication.translate("GroupBox", u"GroupBox", None))
        self.groupBox_occupancy_histogram.setTitle(
            QCoreApplication.translate("GroupBox", u"Occupancy histogram",
                                       None))
        self.label_56.setText(
            QCoreApplication.translate("GroupBox", u"# of bins", None))
        self.lineEdit_bins.setText(
            QCoreApplication.translate("GroupBox", u"10", None))
        self.label_55.setText(
            QCoreApplication.translate("GroupBox", u"min. occupancy", None))
        self.lineEdit_minimum.setText(
            QCoreApplication.translate("GroupBox", u"0.0", None))
        self.label_17.setText(
            QCoreApplication.translate("GroupBox", u"max. occupancy", None))
        self.lineEdit_maximum.setText(
            QCoreApplication.translate("GroupBox", u"1.0", None))
        self.checkBox_cumulative_histogram.setText(
            QCoreApplication.translate("GroupBox", u"cumulative", None))
        self.checkBox_stacked_histogram.setText(
            QCoreApplication.translate("GroupBox", u"stacked", None))
        #if QT_CONFIG(tooltip)
        self.checkBox_color_segments_occupancy.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Toggle if histogram bars are colored by segment or molecule. With colors turned on, comparing to other analyses is not possible.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.checkBox_color_segments_occupancy.setText(
            QCoreApplication.translate("GroupBox", u"color by segment", None))
        self.pushButton_save_occupancy.setText(
            QCoreApplication.translate("GroupBox", u"Data", None))
        #if QT_CONFIG(tooltip)
        self.pushButton_plot_occupancy.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p>Compute histogram of H bond occupancies. Counts the number of H bonds with an occupancy equal or greater than the respective value.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.pushButton_plot_occupancy.setText(
            QCoreApplication.translate("GroupBox", u"Plot", None))
        self.groupBox_nb_connections.setTitle(
            QCoreApplication.translate("GroupBox",
                                       u"Number of connections time series",
                                       None))
        #if QT_CONFIG(tooltip)
        self.checkBox_color_segments_timeseries.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Toggle if histogram bars are colored by segment or molecule. With colors turned on, comparing to other analyses is not possible.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.checkBox_color_segments_timeseries.setText(
            QCoreApplication.translate("GroupBox", u"color by segment", None))
        self.pushButton_save_timeseries.setText(
            QCoreApplication.translate("GroupBox", u"Data", None))
        #if QT_CONFIG(tooltip)
        self.pushButton_plot_timeseries.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Compute the number of H bonds per frame.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.pushButton_plot_timeseries.setText(
            QCoreApplication.translate("GroupBox", u"Plot", None))
        self.groupBox_joint_occupancy.setTitle(
            QCoreApplication.translate("GroupBox", u"Joint Occupancy", None))
        self.radioButton_scatter.setText(
            QCoreApplication.translate("GroupBox", u"scatter plot", None))
        self.label_3.setText(
            QCoreApplication.translate("GroupBox", u"with dot size", None))
        self.lineEdit_scatter_size.setText(
            QCoreApplication.translate("GroupBox", u"1", None))
        self.lineEdit_scatter_size.setPlaceholderText(
            QCoreApplication.translate("GroupBox", u"0 - 100", None))
        self.radioButton_heatmap.setText(
            QCoreApplication.translate("GroupBox", u"heatmap", None))
        self.pushButton_save_jo.setText(
            QCoreApplication.translate("GroupBox", u"Data", None))
        #if QT_CONFIG(tooltip)
        self.pushButton_plot_jo.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Compute the joint occupancy of the H bond network. The joint occupancy is true, if all H bonds of the network are present in a frame and false otherwise.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.pushButton_plot_jo.setText(
            QCoreApplication.translate("GroupBox", u"Plot", None))
Exemplo n.º 10
0
class Ui_GroupBox(object):
    def setupUi(self, GroupBox):
        if not GroupBox.objectName():
            GroupBox.setObjectName(u"GroupBox")
        GroupBox.resize(528, 576)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(GroupBox.sizePolicy().hasHeightForWidth())
        GroupBox.setSizePolicy(sizePolicy)
        self.verticalLayout_2 = QVBoxLayout(GroupBox)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.groupBox = QGroupBox(GroupBox)
        self.groupBox.setObjectName(u"groupBox")
        self.verticalLayout_4 = QVBoxLayout(self.groupBox)
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.horizontalLayout_7 = QHBoxLayout()
        self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
        self.horizontalSpacer_7 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_7.addItem(self.horizontalSpacer_7)

        self.pushButton_degree_save = QPushButton(self.groupBox)
        self.pushButton_degree_save.setObjectName(u"pushButton_degree_save")

        self.horizontalLayout_7.addWidget(self.pushButton_degree_save)

        self.verticalLayout_4.addLayout(self.horizontalLayout_7)

        self.verticalLayout_2.addWidget(self.groupBox)

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

        self.verticalLayout_2.addItem(self.verticalSpacer_2)

        self.groupBox_degree = QGroupBox(GroupBox)
        self.groupBox_degree.setObjectName(u"groupBox_degree")
        self.verticalLayout_3 = QVBoxLayout(self.groupBox_degree)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.radioButton_betweenness = QRadioButton(self.groupBox_degree)
        self.radioButton_betweenness.setObjectName(u"radioButton_betweenness")

        self.horizontalLayout_2.addWidget(self.radioButton_betweenness)

        self.radioButton_degree = QRadioButton(self.groupBox_degree)
        self.radioButton_degree.setObjectName(u"radioButton_degree")
        self.radioButton_degree.setChecked(True)

        self.horizontalLayout_2.addWidget(self.radioButton_degree)

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

        self.horizontalLayout_2.addItem(self.horizontalSpacer_5)

        self.verticalLayout_3.addLayout(self.horizontalLayout_2)

        self.checkBox_averaged_frames = QCheckBox(self.groupBox_degree)
        self.checkBox_averaged_frames.setObjectName(
            u"checkBox_averaged_frames")
        self.checkBox_averaged_frames.setChecked(True)

        self.verticalLayout_3.addWidget(self.checkBox_averaged_frames)

        self.checkBox_normalized = QCheckBox(self.groupBox_degree)
        self.checkBox_normalized.setObjectName(u"checkBox_normalized")

        self.verticalLayout_3.addWidget(self.checkBox_normalized)

        self.groupBox_per_residue = QGroupBox(self.groupBox_degree)
        self.groupBox_per_residue.setObjectName(u"groupBox_per_residue")
        self.groupBox_per_residue.setCheckable(True)
        self.verticalLayout = QVBoxLayout(self.groupBox_per_residue)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.label_2 = QLabel(self.groupBox_per_residue)
        self.label_2.setObjectName(u"label_2")

        self.horizontalLayout_6.addWidget(self.label_2)

        self.comboBox = QComboBox(self.groupBox_per_residue)
        self.comboBox.setObjectName(u"comboBox")

        self.horizontalLayout_6.addWidget(self.comboBox)

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

        self.horizontalLayout_6.addItem(self.horizontalSpacer_2)

        self.verticalLayout.addLayout(self.horizontalLayout_6)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.label_10 = QLabel(self.groupBox_per_residue)
        self.label_10.setObjectName(u"label_10")
        self.label_10.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout.addWidget(self.label_10)

        self.lineEdit_degree_residue_ids = QLineEdit(self.groupBox_per_residue)
        self.lineEdit_degree_residue_ids.setObjectName(
            u"lineEdit_degree_residue_ids")

        self.horizontalLayout.addWidget(self.lineEdit_degree_residue_ids)

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

        self.horizontalLayout.addItem(self.horizontalSpacer_6)

        self.verticalLayout.addLayout(self.horizontalLayout)

        self.verticalLayout_3.addWidget(self.groupBox_per_residue)

        self.groupBox_histogram = QGroupBox(self.groupBox_degree)
        self.groupBox_histogram.setObjectName(u"groupBox_histogram")
        self.groupBox_histogram.setCheckable(True)
        self.groupBox_histogram.setChecked(False)
        self.verticalLayout_5 = QVBoxLayout(self.groupBox_histogram)
        self.verticalLayout_5.setObjectName(u"verticalLayout_5")
        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.label_56 = QLabel(self.groupBox_histogram)
        self.label_56.setObjectName(u"label_56")
        self.label_56.setMaximumSize(QSize(16777215, 16777215))
        self.label_56.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout_3.addWidget(self.label_56)

        self.lineEdit_bins = QLineEdit(self.groupBox_histogram)
        self.lineEdit_bins.setObjectName(u"lineEdit_bins")
        self.lineEdit_bins.setMinimumSize(QSize(50, 0))
        self.lineEdit_bins.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_3.addWidget(self.lineEdit_bins)

        self.label_55 = QLabel(self.groupBox_histogram)
        self.label_55.setObjectName(u"label_55")
        self.label_55.setMaximumSize(QSize(16777215, 16777215))
        self.label_55.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout_3.addWidget(self.label_55)

        self.lineEdit_minimum = QLineEdit(self.groupBox_histogram)
        self.lineEdit_minimum.setObjectName(u"lineEdit_minimum")
        self.lineEdit_minimum.setMinimumSize(QSize(50, 0))
        self.lineEdit_minimum.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_3.addWidget(self.lineEdit_minimum)

        self.label_17 = QLabel(self.groupBox_histogram)
        self.label_17.setObjectName(u"label_17")
        self.label_17.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                   | Qt.AlignVCenter)

        self.horizontalLayout_3.addWidget(self.label_17)

        self.lineEdit_maximum = QLineEdit(self.groupBox_histogram)
        self.lineEdit_maximum.setObjectName(u"lineEdit_maximum")
        self.lineEdit_maximum.setMinimumSize(QSize(50, 0))
        self.lineEdit_maximum.setMaximumSize(QSize(50, 16777215))

        self.horizontalLayout_3.addWidget(self.lineEdit_maximum)

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

        self.horizontalLayout_3.addItem(self.horizontalSpacer_3)

        self.verticalLayout_5.addLayout(self.horizontalLayout_3)

        self.horizontalLayout_8 = QHBoxLayout()
        self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
        self.checkBox_cumulative_histogram = QCheckBox(self.groupBox_histogram)
        self.checkBox_cumulative_histogram.setObjectName(
            u"checkBox_cumulative_histogram")

        self.horizontalLayout_8.addWidget(self.checkBox_cumulative_histogram)

        self.horizontalSpacer_12 = QSpacerItem(40, 20, QSizePolicy.Fixed,
                                               QSizePolicy.Minimum)

        self.horizontalLayout_8.addItem(self.horizontalSpacer_12)

        self.checkBox_stacked_histogram = QCheckBox(self.groupBox_histogram)
        self.checkBox_stacked_histogram.setObjectName(
            u"checkBox_stacked_histogram")

        self.horizontalLayout_8.addWidget(self.checkBox_stacked_histogram)

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

        self.horizontalLayout_8.addItem(self.horizontalSpacer_11)

        self.verticalLayout_5.addLayout(self.horizontalLayout_8)

        self.horizontalLayout_9 = QHBoxLayout()
        self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
        self.checkBox_color_segments_occupancy = QCheckBox(
            self.groupBox_histogram)
        self.checkBox_color_segments_occupancy.setObjectName(
            u"checkBox_color_segments_occupancy")
        self.checkBox_color_segments_occupancy.setChecked(True)

        self.horizontalLayout_9.addWidget(
            self.checkBox_color_segments_occupancy)

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

        self.horizontalLayout_9.addItem(self.horizontalSpacer_9)

        self.verticalLayout_5.addLayout(self.horizontalLayout_9)

        self.verticalLayout_3.addWidget(self.groupBox_histogram)

        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                            QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer)

        self.pushButton_degree_plot = QPushButton(self.groupBox_degree)
        self.pushButton_degree_plot.setObjectName(u"pushButton_degree_plot")
        self.pushButton_degree_plot.setAutoDefault(False)

        self.horizontalLayout_5.addWidget(self.pushButton_degree_plot)

        self.verticalLayout_3.addLayout(self.horizontalLayout_5)

        self.verticalLayout_2.addWidget(self.groupBox_degree)

        self.retranslateUi(GroupBox)

        QMetaObject.connectSlotsByName(GroupBox)

    # setupUi

    def retranslateUi(self, GroupBox):
        GroupBox.setWindowTitle(
            QCoreApplication.translate("GroupBox", u"GroupBox", None))
        self.groupBox.setTitle(
            QCoreApplication.translate("GroupBox", u"All centrality measures",
                                       None))
        self.pushButton_degree_save.setText(
            QCoreApplication.translate("GroupBox", u"Data", None))
        self.groupBox_degree.setTitle(
            QCoreApplication.translate("GroupBox", u"Plots", None))
        self.radioButton_betweenness.setText(
            QCoreApplication.translate("GroupBox", u"betweenness centrality",
                                       None))
        self.radioButton_degree.setText(
            QCoreApplication.translate("GroupBox", u"degree centrality", None))
        #if QT_CONFIG(tooltip)
        self.checkBox_averaged_frames.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Toggle, if absolute number of connections or time averaged number of connections are used.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.checkBox_averaged_frames.setText(
            QCoreApplication.translate("GroupBox", u"average across frames",
                                       None))
        self.checkBox_normalized.setText(
            QCoreApplication.translate("GroupBox", u"normalized", None))
        self.groupBox_per_residue.setTitle(
            QCoreApplication.translate("GroupBox", u"Per Residue", None))
        self.label_2.setText(
            QCoreApplication.translate("GroupBox", u"segment: ", None))
        self.label_10.setText(
            QCoreApplication.translate("GroupBox", u"residue ids: ", None))
        self.lineEdit_degree_residue_ids.setPlaceholderText(
            QCoreApplication.translate("GroupBox", u"e.g. 0-12, 20, 70-90",
                                       None))
        self.groupBox_histogram.setTitle(
            QCoreApplication.translate("GroupBox", u"Histogram", None))
        self.label_56.setText(
            QCoreApplication.translate("GroupBox", u"# of bins", None))
        self.lineEdit_bins.setText(
            QCoreApplication.translate("GroupBox", u"10", None))
        self.label_55.setText(
            QCoreApplication.translate("GroupBox", u"min. value", None))
        self.lineEdit_minimum.setText(
            QCoreApplication.translate("GroupBox", u"0.0", None))
        self.label_17.setText(
            QCoreApplication.translate("GroupBox", u"max. value", None))
        self.lineEdit_maximum.setText(
            QCoreApplication.translate("GroupBox", u"1.0", None))
        self.checkBox_cumulative_histogram.setText(
            QCoreApplication.translate("GroupBox", u"cumulative", None))
        self.checkBox_stacked_histogram.setText(
            QCoreApplication.translate("GroupBox", u"stacked", None))
        #if QT_CONFIG(tooltip)
        self.checkBox_color_segments_occupancy.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Toggle if histogram bars are colored by segment or molecule. With colors turned on, comparing to other analyses is not possible.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.checkBox_color_segments_occupancy.setText(
            QCoreApplication.translate("GroupBox", u"color by segment", None))
        #if QT_CONFIG(tooltip)
        self.pushButton_degree_plot.setToolTip(
            QCoreApplication.translate(
                "GroupBox",
                u"<html><head/><body><p align=\"justify\">Compute the number of H bonds per residue. Results are colored by segment.</p></body></html>",
                None))
        #endif // QT_CONFIG(tooltip)
        self.pushButton_degree_plot.setText(
            QCoreApplication.translate("GroupBox", u"Plot", None))
Exemplo n.º 11
0
class Ui_dlg_new_tool(object):
    def setupUi(self, dlg_new_tool):
        if not dlg_new_tool.objectName():
            dlg_new_tool.setObjectName(u"dlg_new_tool")
        dlg_new_tool.resize(570, 463)
        dlg_new_tool.setModal(True)
        self.gridLayout_2 = QGridLayout(dlg_new_tool)
        self.gridLayout_2.setObjectName(u"gridLayout_2")
        self.gridLayout = QGridLayout()
        self.gridLayout.setObjectName(u"gridLayout")
        self.te_description = QTextEdit(dlg_new_tool)
        self.te_description.setObjectName(u"te_description")

        self.gridLayout.addWidget(self.te_description, 3, 0, 1, 6)

        self.label = QLabel(dlg_new_tool)
        self.label.setObjectName(u"label")

        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)

        self.lbl_file_exists = QLabel(dlg_new_tool)
        self.lbl_file_exists.setObjectName(u"lbl_file_exists")
        self.lbl_file_exists.setPixmap(QPixmap(u"../resources/OK.png"))

        self.gridLayout.addWidget(self.lbl_file_exists, 0, 5, 1, 1)

        self.label_5 = QLabel(dlg_new_tool)
        self.label_5.setObjectName(u"label_5")

        self.gridLayout.addWidget(self.label_5, 0, 3, 1, 1)

        self.chk_mask_required = QCheckBox(dlg_new_tool)
        self.chk_mask_required.setObjectName(u"chk_mask_required")

        self.gridLayout.addWidget(self.chk_mask_required, 5, 0, 1, 6)

        self.label_4 = QLabel(dlg_new_tool)
        self.label_4.setObjectName(u"label_4")

        self.gridLayout.addWidget(self.label_4, 0, 2, 1, 1)

        self.le_tool_name = QLineEdit(dlg_new_tool)
        self.le_tool_name.setObjectName(u"le_tool_name")

        self.gridLayout.addWidget(self.le_tool_name, 0, 1, 1, 1)

        self.label_3 = QLabel(dlg_new_tool)
        self.label_3.setObjectName(u"label_3")

        self.gridLayout.addWidget(self.label_3, 1, 3, 1, 1)

        self.le_file_name = QLineEdit(dlg_new_tool)
        self.le_file_name.setObjectName(u"le_file_name")
        self.le_file_name.setReadOnly(True)

        self.gridLayout.addWidget(self.le_file_name, 0, 4, 1, 1)

        self.label_6 = QLabel(dlg_new_tool)
        self.label_6.setObjectName(u"label_6")
        font = QFont()
        font.setPointSize(8)
        self.label_6.setFont(font)

        self.gridLayout.addWidget(self.label_6, 1, 2, 1, 1)

        self.le_class_name = QLineEdit(dlg_new_tool)
        self.le_class_name.setObjectName(u"le_class_name")
        self.le_class_name.setReadOnly(True)

        self.gridLayout.addWidget(self.le_class_name, 1, 4, 1, 1)

        self.label_2 = QLabel(dlg_new_tool)
        self.label_2.setObjectName(u"label_2")

        self.gridLayout.addWidget(self.label_2, 2, 0, 1, 6)

        self.label_7 = QLabel(dlg_new_tool)
        self.label_7.setObjectName(u"label_7")

        self.gridLayout.addWidget(self.label_7, 4, 0, 1, 1)

        self.le_package_name = QLineEdit(dlg_new_tool)
        self.le_package_name.setObjectName(u"le_package_name")

        self.gridLayout.addWidget(self.le_package_name, 4, 1, 1, 5)

        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 2)

        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.groupBox = QGroupBox(dlg_new_tool)
        self.groupBox.setObjectName(u"groupBox")
        self.groupBox.setCheckable(False)
        self.verticalLayout = QVBoxLayout(self.groupBox)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.rb_output_image = QRadioButton(self.groupBox)
        self.rb_output_image.setObjectName(u"rb_output_image")
        self.rb_output_image.setChecked(True)

        self.verticalLayout.addWidget(self.rb_output_image)

        self.rb_output_mask = QRadioButton(self.groupBox)
        self.rb_output_mask.setObjectName(u"rb_output_mask")

        self.verticalLayout.addWidget(self.rb_output_mask)

        self.rb_output_data = QRadioButton(self.groupBox)
        self.rb_output_data.setObjectName(u"rb_output_data")

        self.verticalLayout.addWidget(self.rb_output_data)

        self.rb_output_none = QRadioButton(self.groupBox)
        self.rb_output_none.setObjectName(u"rb_output_none")

        self.verticalLayout.addWidget(self.rb_output_none)

        self.verticalLayout_4.addWidget(self.groupBox)

        self.gb_pipeline_tool_groups = QGroupBox(dlg_new_tool)
        self.gb_pipeline_tool_groups.setObjectName(u"gb_pipeline_tool_groups")

        self.verticalLayout_4.addWidget(self.gb_pipeline_tool_groups)

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

        self.verticalLayout_4.addItem(self.verticalSpacer)

        self.gridLayout_2.addLayout(self.verticalLayout_4, 1, 0, 1, 1)

        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.groupBox_2 = QGroupBox(dlg_new_tool)
        self.groupBox_2.setObjectName(u"groupBox_2")
        self.verticalLayout_2 = QVBoxLayout(self.groupBox_2)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.rb_rt_yes = QRadioButton(self.groupBox_2)
        self.rb_rt_yes.setObjectName(u"rb_rt_yes")

        self.verticalLayout_2.addWidget(self.rb_rt_yes)

        self.rb_rt_no = QRadioButton(self.groupBox_2)
        self.rb_rt_no.setObjectName(u"rb_rt_no")
        self.rb_rt_no.setChecked(True)

        self.verticalLayout_2.addWidget(self.rb_rt_no)

        self.rb_rt_widget = QRadioButton(self.groupBox_2)
        self.rb_rt_widget.setObjectName(u"rb_rt_widget")

        self.verticalLayout_2.addWidget(self.rb_rt_widget)

        self.rb_rt_property = QRadioButton(self.groupBox_2)
        self.rb_rt_property.setObjectName(u"rb_rt_property")

        self.verticalLayout_2.addWidget(self.rb_rt_property)

        self.verticalLayout_3.addWidget(self.groupBox_2)

        self.gb_no_pipeline_tool_groups = QGroupBox(dlg_new_tool)
        self.gb_no_pipeline_tool_groups.setObjectName(u"gb_no_pipeline_tool_groups")

        self.verticalLayout_3.addWidget(self.gb_no_pipeline_tool_groups)

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

        self.verticalLayout_3.addItem(self.verticalSpacer_2)

        self.gridLayout_2.addLayout(self.verticalLayout_3, 1, 1, 1, 1)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalSpacer = QSpacerItem(
            40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum
        )

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.bt_save = QPushButton(dlg_new_tool)
        self.bt_save.setObjectName(u"bt_save")

        self.horizontalLayout.addWidget(self.bt_save)

        self.bt_cancel = QPushButton(dlg_new_tool)
        self.bt_cancel.setObjectName(u"bt_cancel")

        self.horizontalLayout.addWidget(self.bt_cancel)

        self.gridLayout_2.addLayout(self.horizontalLayout, 2, 1, 1, 1)

        self.gridLayout_2.setColumnStretch(0, 1)
        self.gridLayout_2.setColumnStretch(1, 1)

        self.retranslateUi(dlg_new_tool)

        QMetaObject.connectSlotsByName(dlg_new_tool)

    # setupUi

    def retranslateUi(self, dlg_new_tool):
        dlg_new_tool.setWindowTitle(
            QCoreApplication.translate("dlg_new_tool", u"New tool wizard", None)
        )
        self.te_description.setPlaceholderText(
            QCoreApplication.translate(
                "dlg_new_tool",
                u"Write your tool's description here.\\nYou can use HTML tags",
                None,
            )
        )
        self.label.setText(
            QCoreApplication.translate("dlg_new_tool", u"Tool name:", None)
        )
        self.lbl_file_exists.setText("")
        self.label_5.setText(
            QCoreApplication.translate("dlg_new_tool", u"File name:", None)
        )
        self.chk_mask_required.setText(
            QCoreApplication.translate("dlg_new_tool", u"Requires mask in input", None)
        )
        self.label_4.setText(u"\ud83e\udc62")
        self.label_6.setText(u"\ud83e\udc62")
        self.label_3.setText(
            QCoreApplication.translate("dlg_new_tool", u"Class name", None)
        )
        self.label_2.setText(
            QCoreApplication.translate("dlg_new_tool", u"Description:", None)
        )
        self.label_7.setText(
            QCoreApplication.translate("dlg_new_tool", u"Package:", None)
        )
        self.groupBox.setTitle(
            QCoreApplication.translate("dlg_new_tool", u"Output:", None)
        )
        self.rb_output_image.setText(
            QCoreApplication.translate("dlg_new_tool", u"Image", None)
        )
        self.rb_output_mask.setText(
            QCoreApplication.translate("dlg_new_tool", u"Mask", None)
        )
        self.rb_output_data.setText(
            QCoreApplication.translate("dlg_new_tool", u"Data", None)
        )
        self.rb_output_none.setText(
            QCoreApplication.translate("dlg_new_tool", u"None", None)
        )
        self.gb_pipeline_tool_groups.setTitle(
            QCoreApplication.translate(
                "dlg_new_tool", u"Groups that can be added to pipelines", None
            )
        )
        self.groupBox_2.setTitle(
            QCoreApplication.translate("dlg_new_tool", u"Real time:", None)
        )
        self.rb_rt_yes.setText(QCoreApplication.translate("dlg_new_tool", u"Yes", None))
        self.rb_rt_no.setText(QCoreApplication.translate("dlg_new_tool", u"No", None))
        self.rb_rt_widget.setText(
            QCoreApplication.translate("dlg_new_tool", u"Widget", None)
        )
        self.rb_rt_property.setText(
            QCoreApplication.translate("dlg_new_tool", u"Property", None)
        )
        self.gb_no_pipeline_tool_groups.setTitle(
            QCoreApplication.translate(
                "dlg_new_tool", u"Groups forbiden in pipelines", None
            )
        )
        self.bt_save.setText(QCoreApplication.translate("dlg_new_tool", u"Save", None))
        self.bt_cancel.setText(
            QCoreApplication.translate("dlg_new_tool", u"Close", None)
        )
Exemplo n.º 12
0
class MyDockWidget(cutter.CutterDockWidget):
    def __init__(self, parent, action):
        super(MyDockWidget, self).__init__(parent, action)
        self.setObjectName("Capa explorer")
        self.setWindowTitle("Capa explorer")

        self._config = CutterBindings.Configuration.instance()
        self.model_data = CapaExplorerDataModel()

        self.range_model_proxy = CapaExplorerRangeProxyModel()
        self.range_model_proxy.setSourceModel(self.model_data)
        self.search_model_proxy = CapaExplorerSearchProxyModel()
        self.search_model_proxy.setSourceModel(self.range_model_proxy)

        self.create_view_tabs()
        self.create_tree_tab_ui()
        self.create_view_attack()

        self.connect_signals()
        self.setWidget(self.tabs)
        self.show()

    def create_view_tabs(self):

        # Create tabs container
        self.tabs = QTabWidget()

        # Create the tabs
        self.tab_attack = QWidget(self.tabs)
        self.tab_tree_w_model = QWidget(self.tabs)

        self.tabs.addTab(self.tab_tree_w_model, "Tree View")
        self.tabs.addTab(self.tab_attack, "MITRE")

        # Add load button
        self.btn_load_capa_results = QPushButton()
        self.btn_load_capa_results.setText("Load capa JSON")
        self.btn_load_capa_results.setStyleSheet(
            "margin-bottom: 2px;margin-right:2px")
        self.btn_load_capa_results.clicked.connect(self.load_file)

        self.tabs.setCornerWidget(self.btn_load_capa_results)

    def create_tree_tab_ui(self):
        self.capa_tree_view_layout = QVBoxLayout()
        self.capa_tree_view_layout.setAlignment(Qt.AlignTop)

        self.chk_fcn_scope = QCheckBox("Limit to Current function")
        #TODO: reset state on load file
        self.chk_fcn_scope.setChecked(False)
        self.chk_fcn_scope.stateChanged.connect(
            self.slot_checkbox_limit_by_changed)

        self.input_search = QLineEdit()
        self.input_search.setStyleSheet("margin:0px; padding:0px;")
        self.input_search.setPlaceholderText("search...")
        self.input_search.textChanged.connect(
            self.slot_limit_results_to_search)

        self.filter_controls_container = QGroupBox()
        self.filter_controls_container.setObjectName("scope")
        self.filter_controls_container.setFlat(True)
        self.filter_controls_container.setStyleSheet(
            "#scope{border:0px; padding:0px; margin:0px;subcontrol-origin: padding; subcontrol-position: left top;}"
        )
        self.filter_controls_layout = QHBoxLayout(
            self.filter_controls_container)
        self.filter_controls_layout.setContentsMargins(0, 0, 0, 0)
        self.filter_controls_layout.addWidget(self.input_search)
        self.filter_controls_layout.addWidget(self.chk_fcn_scope)

        self.view_tree = CapaExplorerQtreeView(self.search_model_proxy)
        self.view_tree.setModel(self.search_model_proxy)

        # Make it look a little nicer when no results are loaded
        self.view_tree.header().setStretchLastSection(True)

        self.capa_tree_view_layout.addWidget(self.filter_controls_container)
        self.capa_tree_view_layout.addWidget(self.view_tree)
        self.tab_tree_w_model.setLayout(self.capa_tree_view_layout)

    def create_view_attack(self):
        table_headers = [
            "ATT&CK Tactic",
            "ATT&CK Technique ",
        ]
        table = QTableWidget()
        table.setColumnCount(len(table_headers))
        table.verticalHeader().setVisible(False)
        table.setSortingEnabled(False)
        table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        table.setFocusPolicy(Qt.NoFocus)
        table.setSelectionMode(QAbstractItemView.NoSelection)
        table.setHorizontalHeaderLabels(table_headers)
        table.horizontalHeader().setDefaultAlignment(Qt.AlignLeft)
        table.horizontalHeader().setStretchLastSection(True)
        table.setShowGrid(False)
        table.horizontalHeader().setSectionResizeMode(
            0, QHeaderView.ResizeToContents)
        table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
        #table.setStyleSheet("QTableWidget::item { padding: 25px; }")

        attack_view_layout = QVBoxLayout()
        attack_view_layout.setAlignment(Qt.AlignTop)

        self.attack_table = table

        attack_view_layout.addWidget(self.attack_table)
        self.tab_attack.setLayout(attack_view_layout)

        return table

    def connect_signals(self):

        QObject.connect(cutter.core(), SIGNAL("functionRenamed(RVA, QString)"),
                        self.model_data.refresh_function_names)
        QObject.connect(cutter.core(), SIGNAL("functionsChanged()"),
                        self.model_data.refresh_function_names)
        QObject.connect(cutter.core(), SIGNAL("seekChanged(RVA)"),
                        self.signal_shim_slot_checkbox_limit_by_changed)

    def render_new_table_header_item(self, text):
        """create new table header item with our style
        @param text: header text to display
        """
        item = QTableWidgetItem(text)
        item.setForeground(self._config.getColor("graph.true"))
        font = QFont()
        font.setBold(True)
        item.setFont(font)
        return item

    def fill_attack_table(self, rules):
        tactics = collections.defaultdict(set)
        for key, rule in rules.items():
            if not rule["meta"].get("att&ck"):
                continue

            for attack in rule["meta"]["att&ck"]:
                tactic, _, rest = attack.partition("::")
            if "::" in rest:
                technique, _, rest = rest.partition("::")
                subtechnique, _, id = rest.rpartition(" ")
                tactics[tactic].add((technique, subtechnique, id))
            else:
                technique, _, id = rest.rpartition(" ")
                tactics[tactic].add((technique, id))

        column_one = []
        column_two = []

        for (tactic, techniques) in sorted(tactics.items()):
            column_one.append(tactic.upper())
            # add extra space when more than one technique
            column_one.extend(["" for i in range(len(techniques) - 1)])

            for spec in sorted(techniques):
                if len(spec) == 2:
                    technique, id = spec
                    column_two.append("%s %s" % (technique, id))
                elif len(spec) == 3:
                    technique, subtechnique, id = spec
                    column_two.append("%s::%s %s" %
                                      (technique, subtechnique, id))
                else:
                    raise RuntimeError("unexpected ATT&CK spec format")

        self.attack_table.setRowCount(max(len(column_one), len(column_two)))

        for (row, value) in enumerate(column_one):
            self.attack_table.setItem(row, 0,
                                      self.render_new_table_header_item(value))

        for (row, value) in enumerate(column_two):
            self.attack_table.setItem(row, 1, QTableWidgetItem(value))

    def slot_limit_results_to_search(self, text):
        """limit tree view results to search matches
        reset view after filter to maintain level 1 expansion
        """
        self.search_model_proxy.set_query(text)
        self.view_tree.reset_ui(should_sort=False)

    def signal_shim_slot_checkbox_limit_by_changed(self):
        if self.chk_fcn_scope.isChecked():
            self.slot_checkbox_limit_by_changed(Qt.Checked)

    def slot_checkbox_limit_by_changed(self, state):
        """slot activated if checkbox clicked
        if checked, configure function filter if screen location is located in function, otherwise clear filter
        @param state: checked state
        """
        invoke_reset = True

        if state == Qt.Checked:
            minbound, maxbound = util.get_function_boundries_at_current_location(
            )

            if self.range_model_proxy.min_ea == minbound and self.range_model_proxy.max_ea == maxbound:
                # Seek only changed within current function, avoid resetting tree
                invoke_reset = False

            self.limit_results_to_function((minbound, maxbound))
        else:
            self.range_model_proxy.reset_address_range_filter()

        if invoke_reset:
            self.view_tree.reset_ui()

    def limit_results_to_function(self, f):
        """add filter to limit results to current function
        adds new address range filter to include function bounds, allowing basic blocks matched within a function
        to be included in the results
        @param f: (tuple (maxbound, minbound))
        """
        if f:
            self.range_model_proxy.add_address_range_filter(f[0], f[1])
        else:
            # if function not exists don't display any results (assume address never -1)
            self.range_model_proxy.add_address_range_filter(-1, -1)

    def log(self, msg):
        """log to cutter console

        @param msg: message to log
        """
        cutter.message(f"[CAPAExplorer]: {msg}")

    def load_file(self):

        # Disable load button during loading
        self.btn_load_capa_results.setEnabled(False)

        filename = QFileDialog.getOpenFileName()
        path = filename[0]

        if len(path):

            try:
                data = util.load_capa_json(path)

                self.fill_attack_table(data['rules'])
                self.model_data.clear()
                self.model_data.render_capa_doc(data)

                # Restore ability to scroll on last column
                self.view_tree.header().setStretchLastSection(False)

                self.view_tree.slot_resize_columns_to_content()
            except Exception as e:
                util.log('Could not load json file.')
        else:
            util.log('No file selected.')

        self.btn_load_capa_results.setEnabled(True)
class CreationWindow(QWidget):

    # Layer buttons vector
    __layerVector = []

    # Deleting mode
    __deleteMode = False

    # Connecting mode
    __connectingMode = False

    # Layer parameters box
    __parametersShown = False

    # Last layer that opened the parameters window
    __currentLayer = None

    # Last layer that opened connecting mode
    __connectingLayer = None

    # Lines
    __lines = []

    # Done signal
    done = Signal()

    # Dataset
    dataset = None

    @Slot()
    def closeParameters(self):
        # Closing parameters window
        if self.__parametersShown:
            self.__parametersShown = False
            self.__layerParametersGroupBox.hide()
            self.__layerOutputLineEdit.setText(str(""))
            self.__currentLayer = None

    @Slot()
    def acceptParameters(self):
        # Setting new layer parameters
        if self.__layerOutputLineEdit.text():
            self.__currentLayer.setOutput(
                int(self.__layerOutputLineEdit.text()))
        self.__currentLayer.setActivation(self.__activationMenu.currentIndex())
        if self.__kernelRowsLineEdit.text():
            self.__currentLayer.kernelRows = int(
                self.__kernelRowsLineEdit.text())
        if self.__kernelColumnLineEdit.text():
            self.__currentLayer.kernelColumns = int(
                self.__kernelColumnLineEdit.text())

    @Slot()
    def layerAction(self):
        # Deleting the layer if delete mode is on
        if self.__deleteMode:
            address = id(self.sender())
            self.sender().deleteLater()
            line1 = -1
            line2 = -1
            # Removing layer from current layers list
            for i in range(len(self.__layerVector)):
                if id(self.__layerVector[i]) == address:
                    del self.__layerVector[i]
                    break
            # Removing layer from lines list
            for i in range(len(self.__lines)):
                if id(self.__lines[i][0].parentWidget()) == address:
                    self.__lines[i][1].setConnected(False)
                    line1 = i
                elif id(self.__lines[i][1].parentWidget()) == address:
                    self.__lines[i][0].setConnected(False)
                    line2 = i
            if line1 != -1:
                del self.__lines[line1]
            if line2 != -1:
                del self.__lines[line2]
        # Showing parameters window if delete mode is off
        elif self.sender().text()[:2] != "In" and self.sender().text(
        )[:2] != "Ou" and self.sender().text()[:2] != "Fl":
            self.__currentLayer = self.sender()
            if self.sender().text()[:13] == "Convolutional":
                self.__kernelRowsGroupBox.show()
                self.__kernelColumnGroupBox.show()
                self.__activationGroupBox.show()
                self.__layerOutputGroupBox.hide()
            else:
                self.__layerOutputGroupBox.show()
                self.__activationGroupBox.show()
                self.__kernelRowsGroupBox.hide()
                self.__kernelColumnGroupBox.hide()
            self.__layerOutputLineEdit.setText(str(self.sender().output()))
            self.__activationMenu.setCurrentIndex(self.sender().activation())
            if not self.__parametersShown:
                self.__layerParametersGroupBox.show()
                self.__layerParametersGroupBox.raise_()
                self.__parametersShown = True

    @Slot()
    def reset(self):
        # Deleting all layers in the list and clearing it
        if self.__layerVector:
            for i in range(len(self.__layerVector)):
                self.__layerVector[i].deleteLater()
            del self.__layerVector[:]
        # Clearing lines list
        del self.__lines[:]
        # Hiding the parameters window
        self.__layerParametersGroupBox.hide()

    @Slot()
    def confirm(self):
        # Checking and confirming model
        self.modelList = []
        input = False
        tmp = 0
        # Checking network name
        if not self.networkName.text():
            ret = QMessageBox.warning(self, "Network name",
                                      "Enter a name for the neural network",
                                      QMessageBox.Ok)
            return
        # If no layers are connected
        if not self.__lines:
            ret = QMessageBox.warning(self, "Invalid model",
                                      "No layer connected", QMessageBox.Ok)
            return
        # If one or more layers are not connected
        elif len(self.__lines) != len(self.__layerVector) - 1:
            ret = QMessageBox.warning(self, "Invalid model",
                                      "Some layers are unconnected",
                                      QMessageBox.Ok)
            return
        else:
            # Finding the input layer
            for line in self.__lines:
                if line[0].parentWidget().text()[:5] == "Input":
                    self.modelList.append(line[0].parentWidget())
                    self.modelList.append(line[1].parentWidget())
                    tmp = id(line[1].parentWidget())
                    input = True
            # If there is no input
            if not input:
                ret = QMessageBox.warning(self, "Invalid model",
                                          "No input layer found",
                                          QMessageBox.Ok)
                return
            # Adding all the layers to a list
            while len(self.modelList) != len(self.__lines) + 1:
                for line in self.__lines:
                    if id(line[0].parentWidget()) == tmp:
                        self.modelList.append(line[1].parentWidget())
                        tmp = id(line[1].parentWidget())

            # If there is no output
            if self.modelList[-1].text()[:6] != "Output":
                ret = QMessageBox.warning(self, "Invalid model",
                                          "No output layer found",
                                          QMessageBox.Ok)
                return
            del self.modelList[-1]
            # Checking layers
            c = 0
            for x in self.modelList:
                if isinstance(self.dataset, pd.DataFrame):
                    if x.text()[:2] == "Co":
                        ret = QMessageBox.warning(
                            self, "Convolutional layer",
                            "Cannot put a convolutional layer. Dataset is alphanumerical",
                            QMessageBox.Ok)
                        return
                    elif x.text()[:2] == "Fl":
                        ret = QMessageBox.warning(
                            self, "Flatten layer",
                            "Cannot put a flatten layer. Dataset is alphanumerical",
                            QMessageBox.Ok)
                        return
                if x.text()[:2] == "Co" and self.modelList[
                        c - 1].text()[:2] == "De":
                    ret = QMessageBox.warning(
                        self, "Dense layer",
                        "A dense layer cannot be followed by a convolutional layer",
                        QMessageBox.Ok)
                    return
                if x.text(
                )[:2] == "Fl" and self.modelList[c - 1].text()[:2] != "Co":
                    ret = QMessageBox.warning(
                        self, "Flatten layer",
                        "A flatten layer must always be preceded by a convolutional layer",
                        QMessageBox.Ok)
                    return
                if x.text()[:2] == "Co" and (
                        self.modelList[c + 1].text()[:2] != "Fl"
                        and self.modelList[c + 1].text()[:2] != "Co"):
                    ret = QMessageBox.warning(
                        self, "Convolutional layer",
                        "A convolutional layer must always be followed by a flatten or convolutional layer",
                        QMessageBox.Ok)
                    return
                if x.text()[:2] == "De" and not x.output():
                    ret = QMessageBox.warning(
                        self, "Layer output number",
                        "Please select an output number for each layer",
                        QMessageBox.Ok)
                    return
                if x.text()[:2] == "Co" and (not x.kernelColumns
                                             or not x.kernelRows):
                    ret = QMessageBox.warning(
                        self, "Kernel size",
                        "Please select a kernel size for convolutional layers",
                        QMessageBox.Ok)
                    return
                c = c + 1

            # Emit signal to switch the window
            self.done.emit()

    @Slot()
    def connectLayer(self):
        # Activating connecting mode (line following cursor)
        if not self.__connectingMode:
            if not self.sender().isConnected():
                self.__connectingMode = True
                self.__connectingLayer = self.sender()
        else:
            parent_1 = id(self.__connectingLayer.parentWidget())
            parent_2 = id(self.sender().parentWidget())
            connectingLayerType = self.__connectingLayer.objectName()
            senderLayerType = self.sender().objectName()
            # Checking if the connection works
            # Can't connect an already connected layer
            # parent_1 != parent_2 : Can't connect the input and output of the same layer
            # Can only connect an Input with an Output or an Output with an Input
            if not self.sender().isConnected() and (parent_1 != parent_2) and (
                (connectingLayerType == "input"
                 and senderLayerType == "output") or
                (connectingLayerType == "output"
                 and senderLayerType == "input")):
                # Connecting the two buttons
                if connectingLayerType == "input":
                    self.__lines.append(
                        [self.sender(), self.__connectingLayer])
                else:
                    self.__lines.append(
                        [self.__connectingLayer,
                         self.sender()])
                self.__connectingLayer.setConnected(True)
                self.sender().setConnected(True)
                # Deactivating connecting mode and reseting last layer clicked
                self.__connectingMode = False
                self.__connectingLayer = None

    @Slot()
    def createLayer(self):
        # Creating the layer
        layer = LayerButton(self.sender().text(), self)
        layer.setFont(QFont("BebasNeue", 20, QFont.Bold))
        layer.setGeometry(400, 220, 180, 80)
        layer.setObjectName("layer")
        # Layer icon settings
        layer.setIcon(QIcon(self.sender().icon()))
        layer.setIconSize(QSize(30, 30))
        # Hiding the input/output button on an Input/Output Layer
        if layer.text()[:5] == "Input":
            layer.inputButton.hide()
        elif layer.text()[:6] == "Output":
            layer.outputButton.hide()
        # Setting the cursor accordingly
        if not self.__deleteMode:
            layer.setCursor(Qt.PointingHandCursor)
        else:
            layer.setCursor(Qt.CrossCursor)
        # Connecting the layer to its slots
        layer.clicked.connect(self.layerAction)
        layer.inputButton.clicked.connect(self.connectLayer)
        layer.outputButton.clicked.connect(self.connectLayer)
        # Showing the layer
        layer.show()
        # Adding the layer to the list of current layers
        self.__layerVector.append(layer)
        # Raising the parameters groupbox on top of the screen
        self.__layerParametersGroupBox.raise_()

    # Initialiazing the window
    def __init__(self, dataset, *args, **kwargs):
        super(CreationWindow, self).__init__(*args, **kwargs)

        # Initializing dataset
        self.dataset = dataset

        # Loading Fonts
        QFontDatabase.addApplicationFont("fonts/BebasNeue-Light.ttf")

        # Accepting drag & drops
        self.setAcceptDrops(True)

        # Window Settings
        self.setFixedSize(1280, 720)
        self.setWindowTitle("Neural network creation")
        background = QPixmap("images/grid")
        palette = QPalette()
        palette.setBrush(QPalette.Background, background)
        self.setPalette(palette)
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.setAutoFillBackground(True)

        # Enabling mouse tracking
        self.setMouseTracking(True)

        # Creating graphics scene
        #self.__scene = QGraphicsScene(300, 120, 980, 600, self)
        #self.__scene.addLine(400, 500, 600, 650, QPen(Qt.yellow, 10))
        #self.__liveFeedView = QGraphicsView()
        #self.__liveFeedView.setScene(self.__scene)

        # Stylesheet Settings
        styleFile = QFile("stylesheets/creation.qss")
        styleFile.open(QFile.ReadOnly)
        style = str(styleFile.readAll())
        self.setStyleSheet(style)

        # Network name line edit
        self.networkName = QLineEdit(self)
        self.networkName.setPlaceholderText("Enter neural network name")

        # Netwok name label
        self.__networkNameLabel = QLabel("Neural network name : ", self)
        self.__networkNameLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))
        self.__networkNameLabel.setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.__networkNameLabel.setBuddy(self.networkName)

        # Accept/Reset buttons
        self.__topRightButtons = []
        for x in range(2):
            self.__topRightButtons.append(x)
            self.__topRightButtons[x] = QPushButton("Bouton ici", self)
            self.__topRightButtons[x].setCursor(Qt.PointingHandCursor)
            self.__topRightButtons[x].setIconSize(QSize(35, 35))
            self.__topRightButtons[x].setFont(
                QFont("BebasNeue", 10, QFont.Bold))

        # Customising accept/reset buttons
        self.__topRightButtons[0].setText("Reset")
        self.__topRightButtons[0].setIcon(QIcon("images/reset_icon"))
        self.__topRightButtons[1].setText("Confirm")
        self.__topRightButtons[1].setIcon(QIcon("images/check_icon"))

        # Connecting accept/reset buttons
        self.__topRightButtons[0].clicked.connect(self.reset)
        self.__topRightButtons[1].clicked.connect(self.confirm)

        # Go back button
        self.goBackButton = QPushButton("Back", self)
        self.goBackButton.setObjectName("retour")

        # Connecting go back button
        self.goBackButton.clicked.connect(self.reset)

        # Customising go back button
        self.goBackButton.setCursor(Qt.PointingHandCursor)
        self.goBackButton.setIcon(QIcon("images/goback_icon"))
        self.goBackButton.setIconSize(QSize(30, 30))
        self.goBackButton.setFont(QFont("BebasNeue", 20, QFont.Bold))

        # Layer selection buttons
        self.__layerButtons = []
        for x in range(5):
            self.__layerButtons.append(x)
            self.__layerButtons[x] = QPushButton(self)
            self.__layerButtons[x].setCursor(Qt.PointingHandCursor)
            self.__layerButtons[x].setFont(QFont("BebasNeue", 10, QFont.Bold))
            self.__layerButtons[x].clicked.connect(self.createLayer)

        # Layer buttons names
        self.__layerButtons[0].setText("Input layer")
        self.__layerButtons[1].setText("Output layer")
        self.__layerButtons[2].setText("Dense layer")
        self.__layerButtons[3].setText("Flatten layer")
        self.__layerButtons[4].setText("Convolutional layer")

        # Layer buttons icons
        for x in range(5):
            icon = "images/layer_icon_"
            self.__layerButtons[x].setIcon(QIcon(icon + str(x)))
            self.__layerButtons[x].setIconSize(QSize(45, 45))

        # Top buttons layout settings
        self.__buttonLayout = QHBoxLayout(self)
        self.__buttonGroupBox = QGroupBox(self)
        self.__buttonGroupBox.setGeometry(780, -15, 500, 120)
        self.__buttonLayout.addWidget(self.__topRightButtons[0])
        self.__buttonLayout.addWidget(self.__topRightButtons[1])
        self.__buttonGroupBox.setLayout(self.__buttonLayout)

        # Network name form layout settings
        self.__networkNameLayout = QFormLayout(self)
        self.__networkNameGroupBox = QGroupBox(self)
        self.__networkNameGroupBox.setGeometry(300, -15, 480, 120)
        self.__networkNameLayout.addWidget(self.__networkNameLabel)
        self.__networkNameLayout.addWidget(self.networkName)
        self.__networkNameGroupBox.setLayout(self.__networkNameLayout)

        # Layer buttons layout settings
        self.__layerButtonLayout = QVBoxLayout(self)
        self.__layerButtonGroupBox = QGroupBox("Layer selection", self)
        self.__layerButtonGroupBox.setGeometry(0, -15, 300, 735)
        for x in range(5):
            self.__layerButtonLayout.addWidget(self.__layerButtons[x])
        self.__layerButtonLayout.addWidget(self.goBackButton)
        self.__layerButtonGroupBox.setLayout(self.__layerButtonLayout)

        # Parameters window settings
        # Layer output label
        self.__layerOutputLabel = QLabel("Output number", self)
        self.__layerOutputLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))
        # Layer output line edit
        self.__layerOutputLineEdit = QLineEdit(self)
        self.__layerOutputLineEdit.setValidator(QIntValidator(0, 1000, self))
        # Layer output form settings
        self.__layerOutputLayout = QFormLayout(self)
        self.__layerOutputGroupBox = QGroupBox(self)
        self.__layerOutputLayout.addWidget(self.__layerOutputLabel)
        self.__layerOutputLayout.addWidget(self.__layerOutputLineEdit)
        self.__layerOutputGroupBox.setLayout(self.__layerOutputLayout)
        # Activation function label
        self.__activationLabel = QLabel("Activation function", self)
        self.__activationLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))
        # Activation function menu
        self.__activationMenu = QComboBox(self)
        self.__activationMenu.addItems(
            ['Sigmoid', 'Tanh', 'Rectified Linear Unit', 'Softmax'])
        # Activation function form settings
        self.__activationLayout = QFormLayout(self)
        self.__activationGroupBox = QGroupBox(self)
        self.__activationLayout.addWidget(self.__activationLabel)
        self.__activationLayout.addWidget(self.__activationMenu)
        self.__activationGroupBox.setLayout(self.__activationLayout)
        # Close window button
        self.__closeButton = QPushButton(self)
        self.__closeButton.setObjectName("close")
        self.__closeButton.setCursor(Qt.PointingHandCursor)
        self.__closeButton.setIcon(QIcon("images/close_icon"))
        self.__closeButton.setIconSize(QSize(35, 35))
        self.__closeButton.clicked.connect(self.closeParameters)
        # Accept changes button
        self.__acceptButton = QPushButton(self)
        self.__acceptButton.setObjectName("accept")
        self.__acceptButton.setCursor(Qt.PointingHandCursor)
        self.__acceptButton.setIcon(QIcon("images/accept_icon"))
        self.__acceptButton.setIconSize(QSize(35, 35))
        self.__acceptButton.clicked.connect(self.acceptParameters)
        # Close/Accept buttons layout
        self.__bottomButtonsLayout = QHBoxLayout(self)
        self.__bottomButtonsGroupBox = QGroupBox(self)
        self.__bottomButtonsLayout.addWidget(self.__closeButton)
        self.__bottomButtonsLayout.addWidget(self.__acceptButton)
        self.__bottomButtonsGroupBox.setLayout(self.__bottomButtonsLayout)
        # Kernel rows label
        self.__kernelRowsLabel = QLabel("Kernel rows", self)
        self.__kernelRowsLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))
        # Kernel rows line edit
        self.__kernelRowsLineEdit = QLineEdit(self)
        self.__kernelRowsLineEdit.setValidator(QIntValidator(0, 1000, self))
        # Kernel rows form layout
        self.__kernelRowsLayout = QFormLayout(self)
        self.__kernelRowsLayout.addWidget(self.__kernelRowsLabel)
        self.__kernelRowsLayout.addWidget(self.__kernelRowsLineEdit)
        # Kernel rows group box
        self.__kernelRowsGroupBox = QGroupBox(self)
        self.__kernelRowsGroupBox.setLayout(self.__kernelRowsLayout)
        self.__kernelRowsGroupBox.hide()
        # Kernel columns label
        self.__kernelColumnLabel = QLabel("Kernel columns", self)
        self.__kernelColumnLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))
        # Kernel columns line edit
        self.__kernelColumnLineEdit = QLineEdit(self)
        self.__kernelColumnLineEdit.setValidator(QIntValidator(0, 1000, self))
        # Kernel columns form layout
        self.__kernelColumnLayout = QFormLayout(self)
        self.__kernelColumnLayout.addWidget(self.__kernelColumnLabel)
        self.__kernelColumnLayout.addWidget(self.__kernelColumnLineEdit)
        # Kernel columns group box
        self.__kernelColumnGroupBox = QGroupBox(self)
        self.__kernelColumnGroupBox.setLayout(self.__kernelColumnLayout)
        self.__kernelColumnGroupBox.hide()
        # Layer parameters group box
        self.__layerParametersGroupBox = QGroupBox(self)
        self.__layerParametersGroupBox.setObjectName("parameters")
        self.__layerParametersGroupBox.setGeometry(960, 88, 320, 550)
        self.__layerParametersLayout = QVBoxLayout(self)
        self.__layerParametersLayout.addWidget(self.__layerOutputGroupBox)
        self.__layerParametersLayout.addWidget(self.__activationGroupBox)
        self.__layerParametersLayout.addWidget(self.__kernelRowsGroupBox)
        self.__layerParametersLayout.addWidget(self.__kernelColumnGroupBox)
        self.__layerParametersLayout.addWidget(self.__bottomButtonsGroupBox)
        self.__layerParametersGroupBox.setLayout(self.__layerParametersLayout)
        self.__layerParametersGroupBox.hide()
        self.__layerParametersGroupBox.raise_()

    # Overloading dragEnterEvent method
    def dragEnterEvent(self, e):
        e.accept()

    # Overloading dropEvent method
    def dropEvent(self, e):
        # Getting the event source
        button = QDropEvent.source(e)
        # Calculating the new coordinates
        new_x = e.pos().x() - button.getCursorX()
        new_y = e.pos().y() - button.getCursorY()
        # Moving the button if it is still in frame
        if new_x > 350 and new_y > 120 and new_x < 1100 and new_y < 640:
            position = QPoint(new_x, new_y)
            button.move(position)
            e.setDropAction(Qt.MoveAction)
            e.accept()

    # Overloading keyPressEvent to activate/deactivate deleting mode
    def keyPressEvent(self, ev):
        # Activating delete mode when pressing delete key
        if not self.__deleteMode and ev.key() == Qt.Key_Delete:
            self.setCursor(Qt.CrossCursor)
            self.__deleteMode = True
            for i in range(len(self.__layerVector)):
                self.__layerVector[i].setCursor(Qt.CrossCursor)
        # Deactivating delete mode when pressing escape key
        elif self.__deleteMode and ev.key() == Qt.Key_Escape:
            self.setCursor(Qt.ArrowCursor)
            self.__deleteMode = False
            for i in range(len(self.__layerVector)):
                self.__layerVector[i].setCursor(Qt.PointingHandCursor)
        # Deactivating connecting mode when pressing escape key
        if self.__connectingMode and ev.key() == Qt.Key_Escape:
            self.__connectingMode = False

    # Overloading mouse press event to unfocus QLineEdit
    def mousePressEvent(self, event):
        focused_widget = QApplication.focusWidget()
        if isinstance(focused_widget, QLineEdit):
            focused_widget.clearFocus()
        QWidget.mousePressEvent(self, event)
        if self.__deleteMode:
            i = 0
            for line in self.__lines:
                # Getting the line equation
                slope = (line[0].y() + line[0].parentWidget().y() -
                         line[1].y() - line[1].parentWidget().y()
                         ) / float(line[0].x() + line[0].parentWidget().x() -
                                   line[1].x() - line[1].parentWidget().x())
                point_slope = line[0].y() + line[0].parentWidget().y(
                ) + 20 - slope * (line[0].x() + line[0].parentWidget().x() +
                                  20)
                # Checking if the coordinates of the mouse click are on the line
                if event.pos().y() < int(
                        slope * event.pos().x() + point_slope +
                        3) and event.pos().y() > int(slope * event.pos().x() +
                                                     point_slope - 3):
                    # Delete the line here
                    self.__lines[i][0].setConnected(False)
                    self.__lines[i][1].setConnected(False)
                    self.__lines.remove(line)
                i = i + 1

    # Overloading mouse move event to change the cursor if its out of frame
    def mouseMoveEvent(self, ev):
        if self.__deleteMode:
            if ev.pos().x() < 325 or ev.pos().y() < 120:
                self.setCursor(Qt.ArrowCursor)
            else:
                self.setCursor(Qt.CrossCursor)
        if self.__connectingMode:
            if ev.pos().x() < 340 or ev.pos().y() < 130:
                self.__connectingMode = False

    # Drawing lines
    def paintEvent(self, e):
        painter = QPainter(self)
        painter.setPen(QPen(QColor(145, 18, 9), 10))
        if self.__connectingMode:
            layerPoint = QPoint(
                self.__connectingLayer.x() +
                self.__connectingLayer.parentWidget().x() + 20,
                self.__connectingLayer.y() +
                self.__connectingLayer.parentWidget().y() + 20)
            painter.drawLine(layerPoint, self.mapFromGlobal(QCursor.pos()))
            self.update()
        if self.__lines:
            for line in self.__lines:
                point1 = QPoint(line[0].x() + line[0].parentWidget().x() + 20,
                                line[0].y() + line[0].parentWidget().y() + 20)
                point2 = QPoint(line[1].x() + line[1].parentWidget().x() + 20,
                                line[1].y() + line[1].parentWidget().y() + 20)
                self.update()
                painter.drawLine(point1, point2)
Exemplo n.º 14
0
class Ui_GroupBox(object):
    def setupUi(self, GroupBox):
        if not GroupBox.objectName():
            GroupBox.setObjectName(u"GroupBox")
        GroupBox.resize(452, 296)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(GroupBox.sizePolicy().hasHeightForWidth())
        GroupBox.setSizePolicy(sizePolicy)
        self.verticalLayout = QVBoxLayout(GroupBox)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.groupBox = QGroupBox(GroupBox)
        self.groupBox.setObjectName(u"groupBox")
        self.verticalLayout_3 = QVBoxLayout(self.groupBox)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.verticalLayout_2.setContentsMargins(-1, 10, -1, -1)
        self.checkBox_asp_ser = QCheckBox(self.groupBox)
        self.checkBox_asp_ser.setObjectName(u"checkBox_asp_ser")

        self.verticalLayout_2.addWidget(self.checkBox_asp_ser)

        self.checkBox_ser_backbone = QCheckBox(self.groupBox)
        self.checkBox_ser_backbone.setObjectName(u"checkBox_ser_backbone")

        self.verticalLayout_2.addWidget(self.checkBox_ser_backbone)

        self.checkBox_glu_his = QCheckBox(self.groupBox)
        self.checkBox_glu_his.setObjectName(u"checkBox_glu_his")

        self.verticalLayout_2.addWidget(self.checkBox_glu_his)

        self.checkBox_his_his = QCheckBox(self.groupBox)
        self.checkBox_his_his.setObjectName(u"checkBox_his_his")

        self.verticalLayout_2.addWidget(self.checkBox_his_his)

        self.checkBox_asp_asn = QCheckBox(self.groupBox)
        self.checkBox_asp_asn.setObjectName(u"checkBox_asp_asn")

        self.verticalLayout_2.addWidget(self.checkBox_asp_asn)

        self.checkBox_his_ser = QCheckBox(self.groupBox)
        self.checkBox_his_ser.setObjectName(u"checkBox_his_ser")

        self.verticalLayout_2.addWidget(self.checkBox_his_ser)

        self.checkBox_asp_backbone = QCheckBox(self.groupBox)
        self.checkBox_asp_backbone.setObjectName(u"checkBox_asp_backbone")

        self.verticalLayout_2.addWidget(self.checkBox_asp_backbone)

        self.verticalLayout_3.addLayout(self.verticalLayout_2)

        self.verticalLayout.addWidget(self.groupBox)

        self.retranslateUi(GroupBox)

        QMetaObject.connectSlotsByName(GroupBox)

    # setupUi

    def retranslateUi(self, GroupBox):
        GroupBox.setWindowTitle(
            QCoreApplication.translate("GroupBox", u"GroupBox", None))
        self.groupBox.setTitle(
            QCoreApplication.translate("GroupBox", u"Detect motif", None))
        self.checkBox_asp_ser.setText(
            QCoreApplication.translate(
                "GroupBox",
                u"Asp/Glu carboxylate oxygen - Ser/Thr hydroxyl oxygen", None))
        self.checkBox_ser_backbone.setText(
            QCoreApplication.translate(
                "GroupBox",
                u"Ser-Thr  hydroxyl oxygen - backbone carbonyl oxygen", None))
        self.checkBox_glu_his.setText(
            QCoreApplication.translate(
                "GroupBox", u"Asp/Glu carboxylate oxygen - His ND1 or NE2",
                None))
        self.checkBox_his_his.setText(
            QCoreApplication.translate("GroupBox",
                                       u"His ND1 or NE2 - His ND1 or NE2",
                                       None))
        self.checkBox_asp_asn.setText(
            QCoreApplication.translate(
                "GroupBox", u"Asp/Glu carboxylate oxygen - Asn ND1 or OD2",
                None))
        self.checkBox_his_ser.setText(
            QCoreApplication.translate(
                "GroupBox", u"His ND1 or NE2 - Ser/Thr hydroxyl oxygen", None))
        self.checkBox_asp_backbone.setText(
            QCoreApplication.translate(
                "GroupBox", u"Asp/Glu carboxylate oxygen - backbone", None))
Exemplo n.º 15
0
class MyDockWidget(cutter.CutterDockWidget):
    def __init__(self, parent, action):
        super(MyDockWidget, self).__init__(parent, action)
        self.setObjectName("Capa explorer")
        self.setWindowTitle("Capa explorer")

        self._config = CutterBindings.Configuration.instance()
        self.model_data = CapaExplorerDataModel()

        self.range_model_proxy = CapaExplorerRangeProxyModel()
        self.range_model_proxy.setSourceModel(self.model_data)
        self.search_model_proxy = CapaExplorerSearchProxyModel()
        self.search_model_proxy.setSourceModel(self.range_model_proxy)

        self.create_view_tabs()
        self.create_menu()
        self.create_tree_tab_ui()
        self.create_view_attack()

        self.connect_signals()
        self.setWidget(self.tabs)
        self.show()

    def create_view_tabs(self):

        # Create tabs container
        self.tabs = QTabWidget()

        # Create the tabs
        self.tab_attack = QWidget(self.tabs)
        self.tab_tree_w_model = QWidget(self.tabs)

        self.tabs.addTab(self.tab_tree_w_model, "Tree View")
        self.tabs.addTab(self.tab_attack, "MITRE")

    def create_menu(self):
        # Define menu actions
        # Text, tooltip, function, enabled before file load
        self.disabled_menu_items = []

        menu_actions = [
            ("Load JSON file", '', self.cma_load_file, True),
            (),
            ("Auto rename functions",
             'Auto renames functions according to capa detections, can result in very long function names.',
             self.cma_analyze_and_rename, False),
            ("Create flags",
             'Creates flagspaces and flags from capa detections.',
             self.cma_create_flags, False),
            (),
            ("About", '', self.cma_display_about, True),
        ]

        self.capa_menu = QMenu()
        self.capa_menu.setToolTipsVisible(True)

        # Create qactions
        for action in menu_actions:
            if not len(action):
                # Create separator on empty
                self.capa_menu.addSeparator()
                continue

            a = QAction(self)
            a.setText(action[0])
            a.setToolTip(action[1])
            a.triggered.connect(action[2])
            a.setEnabled(action[3])
            if not action[3]:
                self.disabled_menu_items.append(a)
            self.capa_menu.addAction(a)

            # Create menu button
            font = QFont()
            font.setBold(True)
            self.btn_menu = QToolButton()
            self.btn_menu.setText('...')
            self.btn_menu.setFont(font)
            self.btn_menu.setPopupMode(QToolButton.InstantPopup)
            self.btn_menu.setMenu(self.capa_menu)
            self.btn_menu.setStyleSheet(
                'QToolButton::menu-indicator { image: none; }')
            self.tabs.setCornerWidget(self.btn_menu, corner=Qt.TopRightCorner)

    def create_tree_tab_ui(self):
        self.capa_tree_view_layout = QVBoxLayout()
        self.capa_tree_view_layout.setAlignment(Qt.AlignTop)

        self.chk_fcn_scope = QCheckBox("Limit to Current function")
        #TODO: reset state on load file
        self.chk_fcn_scope.setChecked(False)
        self.chk_fcn_scope.stateChanged.connect(
            self.slot_checkbox_limit_by_changed)

        self.input_search = QLineEdit()
        self.input_search.setStyleSheet("margin:0px; padding:0px;")
        self.input_search.setPlaceholderText("search...")
        self.input_search.textChanged.connect(
            self.slot_limit_results_to_search)

        self.filter_controls_container = QGroupBox()
        self.filter_controls_container.setObjectName("scope")
        self.filter_controls_container.setFlat(True)
        self.filter_controls_container.setStyleSheet(
            "#scope{border:0px; padding:0px; margin:0px;subcontrol-origin: padding; subcontrol-position: left top;}"
        )
        self.filter_controls_layout = QHBoxLayout(
            self.filter_controls_container)
        self.filter_controls_layout.setContentsMargins(0, 0, 0, 0)
        self.filter_controls_layout.addWidget(self.input_search)
        self.filter_controls_layout.addWidget(self.chk_fcn_scope)

        self.view_tree = CapaExplorerQtreeView(self.search_model_proxy)
        self.view_tree.setModel(self.search_model_proxy)

        # Make it look a little nicer when no results are loaded
        self.view_tree.header().setStretchLastSection(True)

        self.capa_tree_view_layout.addWidget(self.filter_controls_container)
        self.capa_tree_view_layout.addWidget(self.view_tree)
        self.tab_tree_w_model.setLayout(self.capa_tree_view_layout)

    def create_view_attack(self):
        table_headers = [
            "ATT&CK Tactic",
            "ATT&CK Technique ",
        ]
        table = QTableWidget()
        table.setColumnCount(len(table_headers))
        table.verticalHeader().setVisible(False)
        table.setSortingEnabled(False)
        table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        table.setFocusPolicy(Qt.NoFocus)
        table.setSelectionMode(QAbstractItemView.NoSelection)
        table.setHorizontalHeaderLabels(table_headers)
        table.horizontalHeader().setDefaultAlignment(Qt.AlignLeft)
        table.horizontalHeader().setStretchLastSection(True)
        table.setShowGrid(False)
        table.horizontalHeader().setSectionResizeMode(
            0, QHeaderView.ResizeToContents)
        table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
        #table.setStyleSheet("QTableWidget::item { padding: 25px; }")

        attack_view_layout = QVBoxLayout()
        attack_view_layout.setAlignment(Qt.AlignTop)

        self.attack_table = table

        attack_view_layout.addWidget(self.attack_table)
        self.tab_attack.setLayout(attack_view_layout)

        return table

    def connect_signals(self):

        QObject.connect(cutter.core(), SIGNAL("functionRenamed(RVA, QString)"),
                        self.model_data.refresh_function_names)
        QObject.connect(cutter.core(), SIGNAL("functionsChanged()"),
                        self.model_data.refresh_function_names)
        QObject.connect(cutter.core(), SIGNAL("seekChanged(RVA)"),
                        self.signal_shim_slot_checkbox_limit_by_changed)

    def render_new_table_header_item(self, text):
        """create new table header item with our style
        @param text: header text to display
        """
        item = QTableWidgetItem(text)
        item.setForeground(self._config.getColor("graph.true"))
        font = QFont()
        font.setBold(True)
        item.setFont(font)
        return item

    def fill_attack_table(self, rules):
        tactics = collections.defaultdict(set)
        for key, rule in rules.items():
            if not rule["meta"].get("att&ck"):
                continue

            for attack in rule["meta"]["att&ck"]:
                tactic, _, rest = attack.partition("::")
            if "::" in rest:
                technique, _, rest = rest.partition("::")
                subtechnique, _, id = rest.rpartition(" ")
                tactics[tactic].add((technique, subtechnique, id))
            else:
                technique, _, id = rest.rpartition(" ")
                tactics[tactic].add((technique, id))

        column_one = []
        column_two = []

        for (tactic, techniques) in sorted(tactics.items()):
            column_one.append(tactic.upper())
            # add extra space when more than one technique
            column_one.extend(["" for i in range(len(techniques) - 1)])

            for spec in sorted(techniques):
                if len(spec) == 2:
                    technique, id = spec
                    column_two.append("%s %s" % (technique, id))
                elif len(spec) == 3:
                    technique, subtechnique, id = spec
                    column_two.append("%s::%s %s" %
                                      (technique, subtechnique, id))
                else:
                    raise RuntimeError("unexpected ATT&CK spec format")

        self.attack_table.setRowCount(max(len(column_one), len(column_two)))

        for (row, value) in enumerate(column_one):
            self.attack_table.setItem(row, 0,
                                      self.render_new_table_header_item(value))

        for (row, value) in enumerate(column_two):
            self.attack_table.setItem(row, 1, QTableWidgetItem(value))

    def enable_menu_items_after_load(self):
        # enables menu actions after file is loaded
        for action in self.disabled_menu_items:
            action.setEnabled(True)

    def slot_limit_results_to_search(self, text):
        """limit tree view results to search matches
        reset view after filter to maintain level 1 expansion
        """
        self.search_model_proxy.set_query(text)
        self.view_tree.reset_ui(should_sort=False)

    def signal_shim_slot_checkbox_limit_by_changed(self):
        if self.chk_fcn_scope.isChecked():
            self.slot_checkbox_limit_by_changed(Qt.Checked)

    def slot_checkbox_limit_by_changed(self, state):
        """slot activated if checkbox clicked
        if checked, configure function filter if screen location is located in function, otherwise clear filter
        @param state: checked state
        """
        invoke_reset = True

        if state == Qt.Checked:
            minbound, maxbound = util.get_function_boundries_at_current_location(
            )

            if self.range_model_proxy.min_ea == minbound and self.range_model_proxy.max_ea == maxbound:
                # Seek only changed within current function, avoid resetting tree
                invoke_reset = False

            self.limit_results_to_function((minbound, maxbound))
        else:
            self.range_model_proxy.reset_address_range_filter()

        if invoke_reset:
            self.view_tree.reset_ui()

    def limit_results_to_function(self, f):
        """add filter to limit results to current function
        adds new address range filter to include function bounds, allowing basic blocks matched within a function
        to be included in the results
        @param f: (tuple (maxbound, minbound))
        """
        if f:
            self.range_model_proxy.add_address_range_filter(f[0], f[1])
        else:
            # if function not exists don't display any results (assume address never -1)
            self.range_model_proxy.add_address_range_filter(-1, -1)

    # --- Menu Actions

    def cma_analyze_and_rename(self):
        message_box = QMessageBox()

        message_box.setStyleSheet("QLabel{min-width: 370px;}")
        message_box.setStandardButtons(QMessageBox.Cancel | QMessageBox.Ok)
        message_box.setEscapeButton(QMessageBox.Cancel)
        message_box.setDefaultButton(QMessageBox.Ok)

        message_box.setWindowTitle('Warning')
        message_box.setText(
            'Depending on the size of the binary and the'
            ' amount of \n'
            'capa matches this feature can take some time to \n'
            'complete and might make the UI freeze temporarily.')
        message_box.setInformativeText('Are you sure you want to proceed ?')

        ret = message_box.exec_()

        # Ok = 1024
        if ret == 1024:
            self.model_data.auto_rename_functions()

    def cma_create_flags(self):
        self.model_data.create_flags()

    def cma_display_about(self):
        c = CAPAExplorerPlugin()

        info_text = ("{description}\n\n"
                     "https://github.com/ninewayhandshake/capa-explorer\n\n"
                     "Version: {version}\n"
                     "Author: {author}\n"
                     "License: Apache License 2.0\n").format(
                         version=c.version,
                         author=c.author,
                         description=c.description,
                     )

        text = CAPAExplorerPlugin().name
        message_box = QMessageBox()
        message_box.setStyleSheet("QLabel{min-width: 370px;}")

        message_box.setWindowTitle('About')
        message_box.setText(text)
        message_box.setInformativeText(info_text)
        message_box.setStandardButtons(QMessageBox.Close)

        for i in message_box.findChildren(QLabel):
            i.setFocusPolicy(Qt.NoFocus)

        message_box.exec_()

    def cma_load_file(self):

        filename = QFileDialog.getOpenFileName()
        path = filename[0]

        if len(path):
            try:
                data = util.load_capa_json(path)

                self.fill_attack_table(data['rules'])
                self.model_data.clear()
                self.model_data.render_capa_doc(data)

                # Restore ability to scroll on last column
                self.view_tree.header().setStretchLastSection(False)

                self.view_tree.slot_resize_columns_to_content()
                self.enable_menu_items_after_load()
            except Exception as e:
                util.log('Could not load json file.')
        else:
            util.log('No file selected.')
Exemplo n.º 16
0
class Window(QWidget):
    def __init__(self):
        super().__init__()

        # ----------style-------------
        self.font_type = "Arial"
        self.font_size = 10
        self.font_color = "#676767"
        self.font_size2 = 12
        self.font_color_black = "#f0f0f0"
        #---------------------------------
        self.text8 = QTextEdit()
        self.text8.setReadOnly(True)
        self.check_text = False
        self.gbox6 = QGroupBox()

        try:
            f = open("plotter.txt", "x+")
        except:
            f = open("plotter.txt", "r")

        self.s = f.readline()
        f.close
        if self.s == "":
            f = open("plotter.txt", "w")
            f.write("dark")
            f.close()
            self.s = "dark"
            self.information_dialog()

        else:
            self.gbox6.setStyleSheet(
                "border:None;background-color:rgba(255,255,255,0)")
            self.text8.setStyleSheet(
                "border:None;background-color:rgba(255,255,255,0)")
            self.gbox6.setTitle("")
            self.text8.setText("")

        np.seterr(invalid='raise')
        self.setWindowTitle("XGrapher")
        self.setGeometry(500, 400, 900, 600)
        self.setMinimumSize(900, 600)
        pg.setConfigOption('background', (255, 255, 255, 0))
        self.pw = pg.PlotWidget()
        self.pw.setXRange(0, 1)
        self.pw.setYRange(0, 1)
        self.pw.hideButtons()
        #---------------------------
        self.list_errors = []
        # --------------------------
        self.a = False
        self.b = False
        self.c = False
        # -------------------------
        self.d = False
        self.e = False
        self.f = False
        self.g = False
        self.after = False
        # -------------------------
        self.check1 = False
        self.check2 = False
        self.check3 = False
        self.check_dot = False
        self.check_neg = False
        self.check_xrange = False
        self.check_yrange = False
        # ------------Labels-----------------------------------------
        self.label1 = QLabel()
        self.label1.setText("F(x):")
        self.label2 = QLabel()
        self.label2.setText("Min(x):")
        self.label3 = QLabel()
        self.label3.setText("Max(x):")
        self.label4 = QLabel()
        self.label5 = QLabel()
        self.label5.setText("< x <")
        self.label6 = QLabel()
        self.label6.setText("< y <")
        # --------------------------texteditors------------------
        self.text1 = QLineEdit(self)
        self.text1.textChanged.connect(self.text1_response)
        self.text1.returnPressed.connect(self.focus_text1)
        self.text2 = QLineEdit(self)
        self.text2.textChanged.connect(self.text2_response)
        self.text2.returnPressed.connect(self.focus_text2)
        self.text3 = QLineEdit(self)
        self.text3.textChanged.connect(self.text3_response)
        self.text3.returnPressed.connect(self.focus_text3)
        self.text4 = QLineEdit()
        self.text4.textChanged.connect(self.text4_response)
        self.text4.returnPressed.connect(self.focus_text4)
        self.text5 = QLineEdit()
        self.text5.textChanged.connect(self.text5_response)
        self.text5.returnPressed.connect(self.focus_text5)
        self.text6 = QLineEdit()
        self.text6.textChanged.connect(self.text6_response)
        self.text6.returnPressed.connect(self.focus_text6)
        self.text7 = QLineEdit()
        self.text7.textChanged.connect(self.text7_response)
        self.text7.returnPressed.connect(self.focus_text7)
        # --------------------------------------------------------
        self.button_2 = QPushButton()
        self.button_2.clicked.connect(self.auto_mode)
        self.button_save = QPushButton("Export Graph")
        self.button_help = QPushButton()
        self.button_help.clicked.connect(self.information_dialog)
        # ----------------------RadioButtons----------------------
        self.rbutton1 = QRadioButton("Light")
        self.rbutton1.toggled.connect(self.light_mode)
        self.rbutton2 = QRadioButton("Dark")
        self.rbutton2.toggled.connect(self.dark_mode)
        # --------------------------------------------------------

        self.setIcon()
        self.center()
        self.input_box()
        self.plot_box()
        self.vbox = QHBoxLayout()
        self.vbox.addWidget(self.gbox5)
        self.vbox.addSpacing(5)
        self.vbox.addWidget(self.plot)
        # self.setStyleSheet("background-color:rgb(32,32,32);")
        # self.setStyleSheet("background-color:rgb(240,240,240);")
        self.setLayout(self.vbox)
        if self.s == "dark":
            self.rbutton2.setChecked(True)
        else:
            self.rbutton1.setChecked(True)

        if self.s == "dark":
            self.dark_mode()
        else:
            self.light_mode()
        self.show()

        # --------------------------------------evalute-------------------------------------------------------------------
        self.replacements = {
            'sin': 'np.sin',
            'cos': 'np.cos',
            'tan': 'np.tan',
            'arccos': 'np.arccos',
            'arcsin': 'np.arcsin',
            'arctan': 'np.arctan',
            'exp': 'np.exp',
            'sqrt': 'np.sqrt',
            'cbrt': 'np.cbrt',
            'ln': 'np.log',
            "cosh": "np.cosh",
            "sinh": "np.cosh",
            "tanh": "np.cosh"
        }

        self.allowed_words = [
            "x", "sin", "cos", "tan", "arccos", "arcsin", "arctan", "cosh",
            "sinh", "tanh", "exp", "sqrt", "cbrt", "log10", "ln"
        ]

        # ----------------------------------------------------------------------------------------------------------------
        self.after = True

    def setIcon(self):
        appIcon = QIcon("close.ico")
        self.setWindowIcon(appIcon)

    def center(self):
        qRect = self.frameGeometry()
        centerPoint = QDesktopWidget().availableGeometry().center()
        qRect.moveCenter(centerPoint)
        self.move(qRect.topLeft())

    def input_box(self):
        self.input = QGroupBox("Function")
        self.gbox = QGroupBox("Range")
        vbox_parent = QVBoxLayout()
        self.hbox_parent = QVBoxLayout()
        hbox1 = QHBoxLayout()
        hbox2 = QHBoxLayout()
        hbox3 = QHBoxLayout()
        hbox1.addWidget(self.label1)
        hbox1.addSpacing(17)
        hbox1.addWidget(self.text1)
        hbox2.addWidget(self.label2)
        hbox2.addSpacing(4)
        hbox2.addWidget(self.text2)
        hbox3.addWidget(self.label3)
        hbox3.addSpacing(0)
        hbox3.addWidget(self.text3)

        hbox_button = QHBoxLayout()

        hbox_button.addStretch(1)
        self.button = QPushButton("Reset")
        self.button.setFixedSize(70, 25)
        self.button.clicked.connect(self.reset)
        hbox_button.addWidget(self.button)

        vbox_parent.addLayout(hbox1)
        vbox_parent.addLayout(hbox2)
        vbox_parent.addLayout(hbox3)
        vbox_parent.addLayout(hbox_button)
        self.input.setLayout(vbox_parent)
        hbox4 = QHBoxLayout()
        hbox4.addWidget(self.text4)
        hbox4.addWidget(self.label5)
        hbox4.addWidget(self.text5)
        hbox5 = QHBoxLayout()
        hbox5.addWidget(self.text6)
        hbox5.addWidget(self.label6)
        hbox5.addWidget(self.text7)

        vbox3 = QVBoxLayout()
        vbox3.addWidget(self.button_2)
        vbox2 = QVBoxLayout()
        vbox2.addLayout(hbox4)
        vbox2.addLayout(hbox5)
        hbox6 = QHBoxLayout()
        hbox6.addLayout(vbox2)
        hbox6.addLayout(vbox3)
        self.gbox.setLayout(hbox6)
        #self.button_save.setFixedSize(200, 25)
        self.button_save.setFixedHeight(25)
        self.button_save.setFixedWidth(220)
        self.button_save.clicked.connect(self.export)
        hbox7 = QHBoxLayout()
        hbox7.addWidget(self.button_save)
        hbox7.addWidget(self.button_help)
        self.gbox3 = QGroupBox()
        self.gbox3.setFlat(True)
        self.gbox3.setStyleSheet("border: None")
        #self.gbox3.setLayout(hbox7)

        vbox3 = QVBoxLayout()
        vbox3.addWidget(self.gbox)
        self.gbox4 = QGroupBox("Status")
        hbox8 = QHBoxLayout()
        hbox8.addWidget(self.label4)
        self.gbox4.setLayout(hbox8)

        self.gbox_mode = QGroupBox("Style")
        vbox4 = QHBoxLayout()
        vbox4.addWidget(self.rbutton1)
        vbox4.addWidget(self.rbutton2)
        self.gbox_mode.setLayout(vbox4)

        hbox9 = QHBoxLayout()
        hbox9.addWidget(self.text8)
        self.gbox6.setLayout(hbox9)

        self.hbox_parent.addWidget(self.input)
        self.hbox_parent.addLayout(vbox3)
        self.hbox_parent.addLayout(hbox7)
        self.hbox_parent.addWidget(self.gbox6)

        self.hbox_parent.addWidget(self.gbox_mode)
        self.hbox_parent.addWidget(self.gbox4)
        self.gbox5 = QGroupBox()
        self.gbox5.setLayout(self.hbox_parent)

    def plot_box(self):
        self.plot = QGroupBox()
        layout = QVBoxLayout()
        self.pw.showGrid(True, True, 0.5)
        layout.addWidget(self.pw)
        self.plot.setLayout(layout)

    def text_restricted(self, str):
        if str != "":
            word = str[len(str) - 1]
            if re.match('[0-9-.]', word) is None:
                k = str.translate({ord(word): None})
                str = k
            if word == "-" and len(str) > 1:
                k = str[1:].translate({ord(word): None})
                str = str.replace(str[1:], k)
            if word == ".":
                i = 0
                for v in str:
                    if v == ".":
                        i += 1
                if i > 1:
                    str = str[0:len(str) - 1] + ""
            if word == ".":
                self.check_dot = True
        else:
            str = ""
        return str

    def text1_response(self):
        if self.check1 == False:
            self.a = True
            self.plotx()
        else:
            self.check1 = False

    def text2_response(self):
        self.text2.setText(self.text_restricted(self.text2.text()))
        if self.check2 == False:
            self.b = True
            self.plotx()
        else:
            self.check2 = False

    def text3_response(self):
        self.text3.setText(self.text_restricted(self.text3.text()))
        if self.check3 == False:
            self.c = True
            self.plotx()
        else:
            self.check3 = False

    def text4_response(self):
        self.text4.setText(self.text_restricted(self.text4.text()))
        self.xrange()

    def text5_response(self):
        self.text5.setText(self.text_restricted(self.text5.text()))
        self.xrange()

    def text6_response(self):
        self.text6.setText(self.text_restricted(self.text6.text()))
        self.yrange()

    def text7_response(self):
        self.text7.setText(self.text_restricted(self.text7.text()))
        self.yrange()

    def xrange(self):
        if self.text4.text() == "" and self.text5.text() == "":
            self.error("No X Min Range")
            self.error("No X Max Range")
            self.error("Invalid X Range")
            self.f = False
            self.check_xrange = False
            if self.text1.text() == "" or self.text2.text(
            ) == "" or self.text3.text() == "":
                self.pw.setXRange(0, 1)
            else:
                self.pw.enableAutoRange(axis='x')

        elif self.text4.text() != "" and self.text5.text() != "":
            self.check_xrange = True
            if float(self.text4.text()) >= float(self.text5.text()):
                self.error_add("Invalid X Range")
                self.f = True
            else:
                self.pw.setXRange(float(self.text4.text()),
                                  float(self.text5.text()))
                self.error("No X Min Range")
                self.error("No X Max Range")
                self.error("Invalid X Range")

                self.f = False
                self.plotx()
            if self.text6.text() == "" or self.text7.text() == "":
                self.pw.enableAutoRange(axis='y')
                self.pw.setAutoVisible(y=True)
        else:
            if self.text4.text() == "" and self.check_xrange == True:
                self.error_add("No X Min Range")
                self.f = True
                self.pw.setXRange(0, 1)
            if self.text5.text() == "" and self.check_xrange == True:
                self.error_add("No X Max Range")
                self.f = True
                self.pw.setXRange(0, 1)
            if self.text6.text() != "" and self.text7.text() != "":
                self.pw.enableAutoRange(axis='x')
                self.pw.setAutoVisible(x=True)
            else:
                if self.d == True or self.e == True:
                    self.pw.setYRange(0, 1)
                    self.pw.setXRange(0, 1)
                else:
                    self.pw.enableAutoRange()

    def yrange(self):
        if self.text6.text() == "" and self.text7.text() == "":
            self.error("No Y Min Range")
            self.error("No Y Max Range")
            self.error("Invalid Y Range")
            self.g = False
            self.check_yrange = False
            if self.text1.text() == "" or self.text2.text(
            ) == "" or self.text3.text() == "":
                self.pw.setYRange(0, 1)
            else:
                self.pw.enableAutoRange(axis='y')

        elif self.text6.text() != "" and self.text7.text() != "":
            self.check_yrange = True
            if float(self.text6.text()) >= float(self.text7.text()):
                self.error_add("Invalid Y Range")
                self.g = True
            else:
                self.pw.setYRange(float(self.text6.text()),
                                  float(self.text7.text()))
                self.error("No Y Min Range")
                self.error("No Y Max Range")
                self.error("Invalid Y Range")
                self.g = False
                self.plotx()
            if self.text4.text() == "" or self.text5.text() == "":
                self.pw.enableAutoRange(axis='x')
                self.pw.setAutoVisible(x=True)
        else:
            if self.text6.text() == "" and self.check_yrange == True:
                self.error_add("No Y Min Range")
                self.g = True
                self.pw.setYRange(0, 1)
            if self.text7.text() == "" and self.check_yrange == True:
                self.error_add("No Y Max Range")
                self.g = True
                self.pw.setYRange(0, 1)
            if self.text4.text() != "" and self.text5.text() != "":
                self.pw.enableAutoRange(axis='y')
                self.pw.setAutoVisible(y=True)
            else:
                if self.d == True or self.e == True:
                    self.pw.setYRange(0, 1)
                    self.pw.setXRange(0, 1)
                else:
                    self.pw.enableAutoRange()

    def string2func(self, str):
        if str != "" and self.a == True and self.b == True and self.c == True:
            self.error("No Function to draw")
            self.d = False
            for word in re.findall('[a-zA-Z_]+', str):
                if word not in self.allowed_words:
                    self.error_add("F(x) is not a Function of x")
                    self.d = True
                else:
                    self.d = False
                    self.error('F(x) is not a Function of x')
                if word in self.replacements:
                    str = str.replace(word, self.replacements[word])
            if "^" in str:
                str = str.replace("^", "**")
        elif str == "" and self.b == True and self.c == True:
            self.error_add("No Function to draw")
            self.d = True
            self.pw.clear()

        def func(x):
            if str != "" and self.text2.text() != "" and self.text3.text(
            ) != "" and self.d == False:
                if self.d == False:
                    try:
                        if np.inf in eval(str):
                            raise ZeroDivisionError
                        if -np.inf in eval(str):
                            raise ValueError
                    except ZeroDivisionError:
                        self.error_add("Cannot divide by Zero")
                        self.d = True
                    except FloatingPointError:
                        self.error_addd("Undefined")
                        self.d = True
                    except ValueError:
                        self.error_add("Math Error")
                        self.d = True
                    except:
                        self.error_add("Syntax Error")
                        self.d = True
                    else:
                        self.error("Cannot divide by Zero")
                        self.error("Undefined")
                        self.error("Math Error")
                        self.error("Syntax Error")
                        self.d = False

            return eval(str)

        return func

    def plotx(self):
        if self.text2.text() == "" and self.text3.text(
        ) == "" and self.text1.text(
        ) == "" and self.a == True and self.b == True and self.c == True:
            self.reset()
        func = self.string2func(self.text1.text())
        if self.a == True and self.b == True and self.c == True and self.text2.text(
        ) != "" and self.text3.text() != "" and self.text1.text(
        ) != "" and self.d == False:
            if (self.text4.text() == "" and self.text5.text() == "") and (
                    self.text6.text() == "" and self.text7.text() == ""):
                self.pw.enableAutoRange()
            self.pw.clear()

            if (self.text2.text() == "-" or self.text3.text() == "-"
                    or self.text3.text() == "." or self.text2.text() == "."):
                self.list_errors.append("Invalid Range")
                self.e = True
            else:
                min_num = float(self.text2.text())
                max_num = float(self.text3.text())
                if min_num >= max_num:
                    self.error_add("Invalid Range")
                    self.e = True
                else:
                    range = np.linspace(min_num, max_num, 2000)
                    if "x" not in self.text1.text(
                    ) and self.text1.text() != "":
                        try:
                            if self.s == "light":
                                self.pw.plot(range,
                                             np.ones(len(range)) *
                                             eval(self.text1.text()),
                                             pen=pg.mkPen(color=(140, 140,
                                                                 140),
                                                          width=2))
                            else:
                                self.pw.plot(range,
                                             np.ones(len(range)) *
                                             eval(self.text1.text()),
                                             pen=pg.mkPen(color="w", width=2))
                        except ZeroDivisionError:
                            self.error_add("Cannot divide by Zero")
                            self.d = True
                        except FloatingPointError:
                            self.error_add("Undefined")

                            self.d = True
                        except ValueError:
                            self.error_add("Math Error")

                            self.d = True
                        except:
                            self.error_add("Syntax Error")

                            self.d = True
                        else:
                            self.error("Cannot divide by Zero")
                            self.error("Undefined")
                            self.error("Math Error")
                            self.error("Syntax Error")
                            self.d = False
                    else:
                        y = func(range)
                        if self.s == "light":
                            self.pw.plot(range,
                                         y,
                                         pen=pg.mkPen(color=(140, 140, 140),
                                                      width=2))
                            self.error("Invalid Range")
                            self.error("No Min Value")
                            self.error("No Max Value")
                        else:
                            self.pw.plot(range,
                                         y,
                                         pen=pg.mkPen(color="w", width=2))
                            self.error("Invalid Range")
                            self.error("No Min Value")
                            self.error("No Max Value")
                        self.e = False
        else:
            if (self.text3.text() == "" and self.c == True):
                self.pw.clear()
                self.e = True
                self.error_add("No Max Value")
            elif (self.text3.text() != "" and self.c == True):
                self.error("No Max Value")
            if (self.text2.text() == "" and self.b == True):
                self.pw.clear()
                self.e = True
                self.error_add("No Min Value")
            elif (self.text2.text() != "" and self.b == True):
                self.error("No Min Value")

    def error(self, type):
        if type in self.list_errors:
            self.list_errors.remove(type)
        if len(self.list_errors) == 0:
            self.label4.setText("")
        else:
            self.label4.setText(self.list_errors[len(self.list_errors) - 1])

    def error_add(self, error):
        if error in self.list_errors:
            pass
        else:
            self.list_errors.append(error)
            self.label4.setText(self.list_errors[len(self.list_errors) - 1])

    def reset(self):
        self.pw.clear()
        if self.text4.text() == "" and self.text5.text(
        ) == "" and self.text6.text() == "" and self.text7.text() == "":
            self.pw.setXRange(0, 1)
            self.pw.setYRange(0, 1)
        self.check1 = True
        self.check2 = True
        self.check3 = True
        self.text1.setText("")
        self.text2.setText("")
        self.text3.setText("")
        self.a = False
        self.b = False
        self.c = False
        self.text1.setFocus()
        self.d = False
        self.e = False
        self.error("Invalid Range")
        self.error("No Min Value")
        self.error("No Max Value")
        self.error("Cannot divide by Zero")
        self.error("Undefined")
        self.error("Math Error")
        self.error("Syntax Error")
        self.error('F(x) is not a Function of x')
        self.error("No Function to draw")

    def focus_text1(self):
        self.text2.setFocus()

    def focus_text2(self):
        self.text3.setFocus()

    def focus_text3(self):
        self.text1.setFocus()

    def focus_text4(self):
        self.text5.setFocus()

    def focus_text5(self):
        self.text6.setFocus()

    def focus_text6(self):
        self.text7.setFocus()

    def focus_text7(self):
        self.text4.setFocus()

    def save(self):
        pass

    def information_dialog(self):
        if self.check_text == False:
            if self.s == "dark":
                self.gbox6.setTitle("Help")
                self.gbox6.setStyleSheet(
                    "QGroupBox {border: 2px solid #3d3d3d;background-color:#383838;color: "
                    + self.font_color_black + ";margin-top: 6px;}" +
                    "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
                )
                self.text8.setStyleSheet(
                    "border:None;background-color:#383838;border:None;color: "
                    + self.font_color_black)
                self.text8.setFont(
                    QFont(self.font_type, self.font_size, QFont.Normal))
                self.text8.setText("--> The following operators must be used when writting the function:\n( - + / ^ ( ) ).\n\n--> The program supports the following functions and must be written as:"
                                   "\nsin(x),cos(x),tan(x),arccos(x),\narcsin(x),arctan(x),cosh(x),sinh(x),\ntanh(x),exp(x),sqrt(X),cbrt(x),\n"
                                   "log10(x),ln(x) and polynomial and rational functions."
                                   "\n\n--> The 'A' button in the Range box sets the x-axis and y-axis ranges to the appropriate values according to the values of the function.\n\n" \
                                    "--> To close the Help box just click the help button beside the Export Graph.")
            else:
                self.gbox6.setTitle("Help")
                self.gbox6.setStyleSheet(
                    "QGroupBox {border: 2px solid #e6e6e6;background-color:#f5f6f7;color: "
                    + self.font_color + ";margin-top: 6px;}" +
                    "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
                )
                self.text8.setStyleSheet(
                    "border:None;background-color:#f5f6f7;color: " +
                    self.font_color)
                self.text8.setFont(
                    QFont(self.font_type, self.font_size, QFont.Normal))
                self.text8.setText("--> The following operators must be used when writting the function:\n( - + / ^ ( ) ).\n\n--> The program supports the following functions and must be written as:"
                                   "\nsin(x),cos(x),tan(x),arccos(x),\narcsin(x),arctan(x),cosh(x),sinh(x),\ntanh(x),exp(x),sqrt(X),cbrt(x),\n"
                                   "log10(x),ln(x) and polynomial and rational functions."
                                   "\n\n--> The 'A' button in the Range box sets the x-axis and y-axis ranges to the appropriate values according to the values of the function.\n\n" \
                                    "--> To close the Help box just click the help button beside the Export Graph.")
            self.check_text = True
        else:
            self.gbox6.setStyleSheet(
                "border:None;background-color:rgba(255,255,255,0)")
            self.text8.setStyleSheet(
                "border:None;background-color:rgba(255,255,255,0)")
            self.text8.setText("")
            self.gbox6.setTitle("")
            self.check_text = False

    def auto_mode(self):
        self.text4.setText("")
        self.text5.setText("")
        self.text6.setText("")
        self.text7.setText("")
        self.f = False
        self.g = False
        self.check_yrange == False
        self.check_xrange == False
        self.xrange()
        self.yrange()

    def dark_mode(self):
        self.input.setMaximumWidth(250)
        self.input.setFixedSize(250, 150)
        self.gbox.setMaximumWidth(250)
        self.gbox.setFixedSize(250, 90)
        self.gbox3.setMaximumWidth(250)
        self.gbox3.setFixedSize(250, 90)
        self.gbox4.setMaximumWidth(250)
        self.gbox4.setFixedSize(250, 45)
        self.gbox_mode.setMaximumWidth(250)
        self.gbox_mode.setFixedSize(250, 50)
        self.gbox5.setMaximumWidth(270)
        self.input.setObjectName("input")
        self.input.setStyleSheet(
            "QGroupBox#input{border: 2px solid #3d3d3d;background-color:#383838;color: "
            + self.font_color_black + ";margin-top: 6px;}" +
            "QGroupBox#input::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.gbox.setStyleSheet(
            "QGroupBox {border: 2px solid #3d3d3d;background-color:#383838;color: "
            + self.font_color_black + ";margin-top: 6px;}" +
            "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.gbox4.setStyleSheet(
            "QGroupBox {border: 2px solid #3d3d3d;background-color:#383838;color: "
            + self.font_color_black + ";margin-top: 6px;}" +
            "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.gbox_mode.setStyleSheet(
            "QGroupBox {border: 2px solid #3d3d3d;background-color:#383838;color: "
            + self.font_color_black + ";margin-top: 6px;}" +
            "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.plot.setStyleSheet("color: " + self.font_color)
        self.setStyleSheet("background-color:#202020")
        self.label1.setStyleSheet(
            "background-color:#383838;border:None;color: " +
            self.font_color_black)
        self.label2.setStyleSheet(
            "background-color:#383838;border:None;color:" +
            self.font_color_black)
        self.label3.setStyleSheet(
            "background-color:#383838;border:None;color:" +
            self.font_color_black)
        self.label4.setStyleSheet(
            "background-color:#383838;border:None;color:" +
            self.font_color_black)
        self.label5.setStyleSheet(
            "background-color:#383838;border:None;color:" +
            self.font_color_black)
        self.label6.setStyleSheet(
            "background-color:#383838;border:None;color:" +
            self.font_color_black)
        self.rbutton1.setStyleSheet("background-color:#383838;color:" +
                                    self.font_color_black)
        self.rbutton2.setStyleSheet("background-color:#383838;color:" +
                                    self.font_color_black)
        self.rbutton1.setFont(
            QFont(self.font_type, self.font_size, QFont.Normal))
        self.rbutton2.setFont(
            QFont(self.font_type, self.font_size, QFont.Normal))
        self.label1.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label2.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label3.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label4.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label5.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label6.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.text1.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.text2.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.text3.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.text4.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.text5.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.text6.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.text7.setStyleSheet(
            "border:1px solid #5b5b5b;background-color:#383838;color:" +
            self.font_color_black)
        self.button_save.setStyleSheet(
            " QPushButton{border: 1px solid #f0f0f0;Text-align:center;background:#333333; color:#f0f0f0}"
            "QPushButton::hover{border: 1px solid #f0f0f0;Text-align:center;background:#2c2c2c}"
            "QPushButton::Pressed{border: 1px solid #f0f0f0;Text-align:center;background:#3d3c3c}"
        )
        self.button.setStyleSheet(
            " QPushButton{border: 1px solid #f0f0f0;Text-align:center;background:#333333; color:#f0f0f0}"
            "QPushButton::hover{border: 1px solid #f0f0f0;Text-align:center;background:#2c2c2c}"
            "QPushButton::Pressed{border: 1px solid #f0f0f0;Text-align:center;background:#3d3c3c}"
        )
        self.text1.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text2.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text3.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text4.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text5.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text6.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text7.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.gbox5.setObjectName("GroupBox")
        self.gbox5.setStyleSheet(
            "QGroupBox#GroupBox{border: None;background-color:#383838}")
        f = open("plotter.txt", "w")
        f.write("dark")
        f.close()
        self.s = "dark"
        self.pw.setBackground(background=None)
        if self.after == True:
            self.plotx()
        pixmap1 = QPixmap("auto-button_dark.png")
        button_icon1 = QIcon(pixmap1)
        self.button_2.setStyleSheet("border:none;background-color:#383838")
        self.button_2.setIcon(button_icon1)
        pixmap2 = QPixmap("help_dark.png")
        button_icon2 = QIcon(pixmap2)
        self.button_help.setIcon(button_icon2)
        self.button_help.setStyleSheet("border:none;background-color:#383838")
        if self.check_text == True:
            self.gbox6.setStyleSheet(
                "QGroupBox {border: 2px solid #3d3d3d;background-color:#383838;color: "
                + self.font_color_black + ";margin-top: 6px;}" +
                "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
            )
            self.text8.setStyleSheet(
                "border:None;background-color:#383838;border:None;color: " +
                self.font_color_black)
            self.text8.setFont(
                QFont(self.font_type, self.font_size, QFont.Normal))

    def light_mode(self):
        self.input.setMaximumWidth(250)
        self.input.setFixedSize(250, 150)
        self.gbox.setMaximumWidth(250)
        self.gbox.setFixedSize(250, 90)
        self.gbox3.setMaximumWidth(250)
        self.gbox3.setFixedSize(250, 90)
        self.gbox4.setMaximumWidth(250)
        self.gbox4.setFixedSize(250, 45)
        self.gbox_mode.setMaximumWidth(250)
        self.gbox_mode.setFixedSize(250, 50)
        self.gbox5.setMaximumWidth(270)
        self.input.setObjectName("input")
        self.input.setStyleSheet(
            "QGroupBox#input{border: 2px solid #e6e6e6;background-color:#f5f6f7;color: "
            + self.font_color + ";margin-top: 6px;}" +
            "QGroupBox#input::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.gbox.setStyleSheet(
            "QGroupBox {border: 2px solid #e6e6e6;background-color:#f5f6f7;color: "
            + self.font_color + ";margin-top: 6px;}" +
            "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.gbox4.setStyleSheet(
            "QGroupBox {border: 2px solid #e6e6e6;background-color:#f5f6f7;color: "
            + self.font_color + ";margin-top: 6px;}" +
            "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.gbox_mode.setStyleSheet(
            "QGroupBox {border: 2px solid #e6e6e6;background-color:#f5f6f7;color: "
            + self.font_color + ";margin-top: 6px;}" +
            "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
        )
        self.plot.setStyleSheet("color: " + self.font_color)
        self.setStyleSheet("background-color:white;")
        self.label1.setStyleSheet("background-color:#f5f6f7;color: " +
                                  self.font_color)
        self.label2.setStyleSheet("background-color:#f5f6f7;color:" +
                                  self.font_color)
        self.label3.setStyleSheet("background-color:#f5f6f7;color:" +
                                  self.font_color)
        self.label4.setStyleSheet("background-color:#f5f6f7;color:" +
                                  self.font_color)
        self.label5.setStyleSheet("background-color:#f5f6f7;color:" +
                                  self.font_color)
        self.label6.setStyleSheet("background-color:#f5f6f7;color:" +
                                  self.font_color)
        self.rbutton1.setStyleSheet("background-color:#f5f6f7;color:" +
                                    self.font_color)
        self.rbutton2.setStyleSheet("background-color:#f5f6f7;color:" +
                                    self.font_color)
        self.rbutton1.setFont(
            QFont(self.font_type, self.font_size, QFont.Normal))
        self.rbutton2.setFont(
            QFont(self.font_type, self.font_size, QFont.Normal))
        self.label1.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label2.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label3.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label4.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label5.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.label6.setFont(QFont(self.font_type, self.font_size,
                                  QFont.Normal))
        self.text1.setStyleSheet("background-color:white")
        self.text2.setStyleSheet("background-color:white")
        self.text3.setStyleSheet("background-color:white")
        self.text4.setStyleSheet("background-color:white")
        self.text5.setStyleSheet("background-color:white")
        self.text6.setStyleSheet("background-color:white")
        self.text7.setStyleSheet("background-color:white")
        self.button_save.setStyleSheet(
            " QPushButton{border: 1px solid #adadad;Text-align:center;background:#e1e1e1; color:black}"
            "QPushButton::hover{border: 1px solid #adadad;Text-align:center;background:#d8d7d7}"
            "QPushButton::Pressed{border: 1px solid #adadad;Text-align:center;background:#f5f6f7}"
        )
        self.button.setStyleSheet(
            " QPushButton{border: 1px solid #adadad;Text-align:center;background:#e1e1e1; color:black}"
            "QPushButton::hover{border: 1px solid #adadad;Text-align:center;background:#d8d7d7}"
            "QPushButton::Pressed{border: 1px solid #adadad;Text-align:center;background:#f5f6f7}"
        )
        self.text1.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text2.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text3.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text4.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text5.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text6.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.text7.setFont(QFont(self.font_type, self.font_size, QFont.Normal))
        self.gbox5.setObjectName("GroupBox")
        self.gbox5.setStyleSheet(
            "QGroupBox#GroupBox{border: None;background-color:#f5f6f7}")
        f = open("plotter.txt", "w")
        f.write("light")
        f.close()
        self.s = "light"
        self.pw.setBackground(background=None)
        if self.after == True:
            self.plotx()
        pixmap2 = QPixmap("auto-button.png")
        button_icon2 = QIcon(pixmap2)
        self.button_2.setStyleSheet("border:none;background-color:#f5f6f7")
        self.button_2.setIcon(button_icon2)
        pixmap2 = QPixmap("help_light.png")
        button_icon2 = QIcon(pixmap2)
        self.button_help.setIcon(button_icon2)
        self.button_help.setStyleSheet("border:none;background-color:#f5f6f7")
        if self.check_text == True:
            self.gbox6.setStyleSheet(
                "QGroupBox {border: 2px solid #e6e6e6;background-color:#f5f6f7;color: "
                + self.font_color + ";margin-top: 6px;}" +
                "QGroupBox::title {subcontrol-origin:margin;left:8px;padding: 0px 0px 0px 0px;}"
            )
            self.text8.setStyleSheet(
                "border:None;background-color:#f5f6f7;color: " +
                self.font_color)
            self.text8.setFont(
                QFont(self.font_type, self.font_size, QFont.Normal))

    def export(self):
        self.exportdialog = exportDialog.ExportDialog(self.pw.plotItem.scene())
        name = QFileDialog.getSaveFileName(
            self, 'Save File', "",
            "PNG (*.PNG;*.PNG);;CSV (*.CSV);;SVG(*.SVG)", "",
            QFileDialog.Options())
        if name[0] != "":
            if "PNG" in name[1]:
                if self.s == "dark":
                    self.pw.setBackground(background=(0, 0, 0))
                else:
                    self.pw.setBackground(background=(255, 255, 255))
                exporter = pg.exporters.ImageExporter(self.pw.plotItem)
                exporter.export(name[0])
                self.pw.setBackground(background=None)
            elif "CSV" in name[1]:
                exporter = pg.exporters.CSVExporter(self.pw.plotItem)
                exporter.export(name[0])
            elif "SVG" in name[1]:
                if self.s == "dark":
                    self.pw.setBackground(background=(0, 0, 0))
                else:
                    self.pw.setBackground(background=(255, 255, 255))
                exporter = pg.exporters.SVGExporter(self.pw.plotItem)
                exporter.export(name[0])
                self.pw.setBackground(background=None)
Exemplo n.º 17
0
class TrainingWindow(QWidget):

    # Dataset
    __dataset = None

    # Netwok model
    __modelList = []

    # Start training
    @Slot()
    def startTraining(self):

        # Get split value
        split = 1 - float(
            (self.__datasetSplitComboBox.currentIndex() + 1) / 10.0)

        # Get split method
        if self.__datasetSplitRandom.isChecked():
            ((x_train, y_train),
             (x_test,
              y_test)) = self.network.random_split(self.__dataset, split)
        elif self.__datasetSplitRegular.isChecked():
            ((x_train, y_train),
             (x_test,
              y_test)) = self.network.regular_split(self.__dataset, split)

        # Get epochs number
        if not self.__epochsLineEdit.text():
            ret = QMessageBox.warning(self, "Epochs number",
                                      "Please enter the number of epochs",
                                      QMessageBox.Ok)
            return
        else:
            epochs = int(self.__epochsLineEdit.text())
            self.__xAxis.setRange(0, epochs)

        # Get learning rate value
        if not self.__learningRateLineEdit.text():
            ret = QMessageBox.warning(self, "Learning rate",
                                      "Please select a learning rate",
                                      QMessageBox.Ok)
            return
        else:
            learning_rate = float(self.__learningRateLineEdit.text().replace(
                ",", "."))
            if not learning_rate:
                ret = QMessageBox.warning(
                    self, "Learning rate",
                    "The learning rate cannot be equal to zero",
                    QMessageBox.Ok)
                return

        # Get learning rate mode
        if self.__learningRateCheckBox.isChecked():
            mode = 2
        else:
            mode = 1

        # Save before training
        ret = QMessageBox.question(
            self, "Network save",
            "Would you like to save the network before the training starts?",
            QMessageBox.Yes | QMessageBox.No)
        if ret == QMessageBox.Yes:
            save_matrix_neural_network(self.network, self.networkName)
            manual_save_model_neural_network(self.network, self.networkName)
            QMessageBox.information(self, "Network save",
                                    "Network successfully saved !",
                                    QMessageBox.Ok)

        # Clearing the graph
        self.__series.clear()

        # Starting training
        length = len(x_train)
        for i in range(epochs):
            err = 0
            training_accuracy = 0
            l_rate = self.network.Learning_rate_schedule(
                mode, epochs, epochs - i + 1, learning_rate)
            for j in range(length):
                outputs = x_train[j]
                for layer in self.network.layers:
                    outputs = layer.forward_propagation(outputs)
                err += self.network.loss(y_train[j], outputs)
                training_accuracy = training_accuracy + self.network.verification_of_prediction(
                    x_train, y_train, j)
                error = self.network.loss_prime(y_train[j], outputs)
                for layer in reversed(self.network.layers):
                    error = layer.backward_propagation(error, l_rate)
            err = err / length
            training_accuracy = training_accuracy / float(length)
            self.__epochNumberLabel.setText("Epoch : " + str(i + 1) + "/" +
                                            str(epochs))
            self.__trainingAccuracyLabel.setText("Taux de precision : " +
                                                 str(training_accuracy * 100) +
                                                 "%")
            # Appending values to the chart
            self.__series.append(i, training_accuracy * 100)
            self.__chartView.repaint()
            # Auto saving network
            save_matrix_neural_network(self.network,
                                       self.networkName + "_auto")
            manual_save_model_neural_network(self.network,
                                             self.networkName + "_auto")

        # Saving trained network
        ret = QMessageBox.question(
            self, "Network save",
            "Would you like to save the trained network? ",
            QMessageBox.Yes | QMessageBox.No)
        if ret == QMessageBox.Yes:
            save_matrix_neural_network(self.network, self.networkName)
            manual_save_model_neural_network(self.network, self.networkName)
            QMessageBox.information(self, "Network save",
                                    "Network successfully saved !",
                                    QMessageBox.Ok)

        # Evaluate network and show confusion matrix
        (self.test_accuracy,
         self.matrix) = self.network.evaluate(x_test, y_test)
        self.__confusionMatrixButton.show()

    # Showing the confusion matrix
    @Slot()
    def showStats(self):
        # Creating matrix window
        self.matrixWindow = QMainWindow()
        self.matrixWindow.setFixedSize(640, 480)

        key_list = list(self.__classes.keys())
        val_list = list(self.__classes.values())

        # Creating matrix table
        self.matrixTable = QTableWidget(
            len(self.matrix) + 1,
            len(self.matrix[0]) + 1)
        for i in range(len(self.matrix)):
            self.matrixTable.setItem(
                i + 1, 0, QTableWidgetItem(str(key_list[val_list.index(i)])))
            self.matrixTable.setItem(
                0, i + 1, QTableWidgetItem(str(key_list[val_list.index(i)])))

        for i in range(len(self.matrix)):
            for j in range(len(self.matrix[0])):
                self.matrixTable.setItem(
                    i + 1, j + 1, QTableWidgetItem(str(self.matrix[i][j])))

        # Printing test accuracy
        self.matrixLabel = QLabel(
            "Test accuracy : " + str(self.test_accuracy * 100) + "%", self)
        self.matrixLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))

        # Matrix window layout
        self.matrixLayout = QVBoxLayout()
        self.matrixLayout.addWidget(self.matrixTable)
        self.matrixLayout.addWidget(self.matrixLabel)

        # Matrix window groupbox
        self.matrixGroupBox = QGroupBox(self.matrixWindow)
        self.matrixGroupBox.setLayout(self.matrixLayout)

        # Showing the matrix window
        self.matrixWindow.setCentralWidget(self.matrixGroupBox)
        self.matrixWindow.show()

    def __init__(self, ds, classes, model, created, *args, **kwargs):
        super(TrainingWindow, self).__init__(*args, **kwargs)

        if created:
            # Initialising network
            self.network = Network()
            self.network.use(mean_squared_error, mean_squared_error_prime)
        else:
            self.network = model[0]

        # Getting inputs and outputs
        self.__dataset = ds
        self.__classes = classes
        #fill_missing_values(self.__dataset)
        #min_max_normalize_dataset(self.__dataset)
        ((x_train, y_train),
         (x_test, y_test)) = self.network.regular_split(self.__dataset, 0.5)

        # Getting inputs
        if len(x_train.shape) == 2:
            inputs = x_train.shape[1]
        else:
            inputs = x_train.shape[1:]
            first = inputs[0]
            second = inputs[1]
            third = inputs[2]

        # Getting expected outputs
        expected_output = y_train.shape[1]

        # Getting network name
        self.networkName = model[1]

        if created:
            # Getting model list
            self.__modelList = model[0]
            self.__modelList[0].setOutput(inputs)

            for i in range(1, len(self.__modelList)):
                # Getting the layer name
                name = self.__modelList[i].text(
                )[:len(self.__modelList[i].text()) - 6]
                activation = None
                activ_prime = None
                # Getting the activation function
                if self.__modelList[i].activation() == 0:
                    activation = sigmoid
                    activ_prime = sigmoid_prime
                elif self.__modelList[i].activation() == 1:
                    activation = tanh
                    activ_prime = tanh_prime
                elif self.__modelList[i].activation() == 2:
                    activation = rectified_linear_unit
                    activ_prime = rectified_linear_unit_prime
                elif self.__modelList[i].activation() == 3:
                    activation = softmax
                    activ_prime = softmax_prime
                # Adding layer to the network
                if name == "Dense":
                    if self.__modelList[i - 1].text()[:2] == "Fl":
                        self.network.add(
                            FullyConnectedLayer(first * second * third,
                                                self.__modelList[i].output()))
                        self.network.add(
                            ActivationLayer(activation, activ_prime))
                    else:
                        self.network.add(
                            FullyConnectedLayer(
                                self.__modelList[i - 1].output(),
                                self.__modelList[i].output()))
                        self.network.add(
                            ActivationLayer(activation, activ_prime))
                elif name == "Flatten":
                    self.network.add(FlattenLayer())
                elif name == "Convolutional":
                    self.network.add(
                        ConvLayer((first, second, third),
                                  (self.__modelList[i].kernelRows,
                                   self.__modelList[i].kernelColumns), 1))
                    self.network.add(ActivationLayer(activation, activ_prime))
                    first = first - self.__modelList[i].kernelRows + 1
                    second = second - self.__modelList[i].kernelColumns + 1

            self.network.add(
                FullyConnectedLayer(
                    self.__modelList[len(self.__modelList) - 1].output(),
                    expected_output))
            self.network.add(ActivationLayer(sigmoid, sigmoid_prime))

        # Loading Fonts
        QFontDatabase.addApplicationFont("fonts/BebasNeue-Light.ttf")

        # Window Settings
        self.setFixedSize(1280, 720)
        self.setWindowTitle("Training window")
        #background = QPixmap("images/menu")
        #palette = QPalette()
        #palette.setBrush(QPalette.Background, background)
        #self.setAttribute(Qt.WA_StyledBackground, True)
        #self.setPalette(palette)
        self.setAutoFillBackground(True)

        # Stylesheet Settings
        styleFile = QFile("stylesheets/training.qss")
        styleFile.open(QFile.ReadOnly)
        style = str(styleFile.readAll())
        self.setStyleSheet(style)

        # Title Settings
        self.title = QLabel("Training", self)
        self.title.setFont(QFont("BebasNeue", 30, QFont.Bold))
        self.title.setAlignment(Qt.AlignCenter)
        self.title.setGeometry(600, 10, 300, 120)

        # Epochs line edit settings
        self.__epochsLineEdit = QLineEdit(self)
        self.__epochsLineEdit.setValidator(QIntValidator(0, 100000, self))

        # Epochs label settings
        self.__epochsLabel = QLabel("Epoch number", self)
        self.__epochsLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))

        # Learning rate line edit settings
        self.__learningRateLineEdit = QLineEdit(self)
        self.__learningRateLineEdit.setValidator(
            QDoubleValidator(0.0, 1.0, 3, self))

        # Learning rate label settings
        self.__learningRateLabel = QLabel("Learning rate", self)
        self.__learningRateLabel.setFont(QFont("BebasNeue", 20, QFont.Bold))

        # Learning rate checkboxsettings (auto or not)
        self.__learningRateCheckBox = QCheckBox("Auto adjustment", self)
        self.__learningRateCheckBox.setFont(QFont("BebasNeue", 15, QFont.Bold))

        # Dataset split settings label
        self.__datasetSplitLabel = QLabel("Dataset split percentage", self)
        self.__datasetSplitLabel.setFont((QFont("BebasNeue", 20, QFont.Bold)))

        # Dataset split mode buttons
        self.__datasetSplitRegular = QRadioButton("Regular split")
        self.__datasetSplitRandom = QRadioButton("Random split")

        # Dataset split mode buttons groupbox
        self.__datasetSplitModeButtonsLayout = QHBoxLayout(self)
        self.__datasetSplitModeButtonsGroupBox = QGroupBox(self)
        self.__datasetSplitModeButtonsGroupBox.setObjectName("setting")
        self.__datasetSplitModeButtonsLayout.addWidget(
            self.__datasetSplitRegular)
        self.__datasetSplitModeButtonsLayout.addWidget(
            self.__datasetSplitRandom)
        self.__datasetSplitModeButtonsGroupBox.setLayout(
            self.__datasetSplitModeButtonsLayout)
        self.__datasetSplitRegular.setChecked(True)

        # Dataset split combo box settings
        self.__datasetSplitComboBox = QComboBox(self)
        self.__datasetSplitComboBox.addItems(
            ['90% - 10%', '80% - 20%', '70% - 30%', '60% - 40%'])

        # Dataset split form layout settings
        self.__datasetSplitLayout = QFormLayout(self)
        self.__datasetSplitGroupBox = QGroupBox(self)
        self.__datasetSplitGroupBox.setObjectName("setting")
        self.__datasetSplitLayout.addWidget(self.__datasetSplitLabel)
        self.__datasetSplitLayout.addWidget(self.__datasetSplitComboBox)
        self.__datasetSplitGroupBox.setLayout(self.__datasetSplitLayout)

        # Epochs form layout settings
        self.__epochsFormLayout = QFormLayout(self)
        self.__epochsGroupBox = QGroupBox(self)
        self.__epochsGroupBox.setObjectName("setting")
        self.__epochsFormLayout.addWidget(self.__epochsLabel)
        self.__epochsFormLayout.addWidget(self.__epochsLineEdit)
        self.__epochsGroupBox.setLayout(self.__epochsFormLayout)

        # Learning rate form layout settings
        self.__learningRateFormLayout = QFormLayout(self)
        self.__learningRateGroupBox = QGroupBox(self)
        self.__learningRateGroupBox.setObjectName("setting")
        self.__learningRateFormLayout.addWidget(self.__learningRateLabel)
        self.__learningRateFormLayout.addWidget(self.__learningRateCheckBox)
        self.__learningRateFormLayout.addWidget(self.__learningRateLineEdit)
        self.__learningRateGroupBox.setLayout(self.__learningRateFormLayout)

        # Epochs number label
        self.__epochNumberLabel = QLabel("Epoch : ", self)
        self.__epochNumberLabel.setFont((QFont("BebasNeue", 15, QFont.Bold)))

        # Training accuracy label
        self.__trainingAccuracyLabel = QLabel("Accuracy : ", self)
        self.__trainingAccuracyLabel.setFont((QFont("BebasNeue", 15,
                                                    QFont.Bold)))

        # Training stats layout
        self.__trainingStatsLayout = QVBoxLayout(self)
        self.__trainingStatsGroupBox = QGroupBox(self)
        self.__trainingStatsLayout.addWidget(self.__epochNumberLabel)
        self.__trainingStatsLayout.addWidget(self.__trainingAccuracyLabel)
        self.__trainingStatsGroupBox.setLayout(self.__trainingStatsLayout)
        self.__trainingStatsGroupBox.setGeometry(1000, -30, 300, 150)

        # Training button settings
        self.__trainingButton = QPushButton("Start", self)
        self.__trainingButton.setCursor(Qt.PointingHandCursor)
        self.__trainingButton.setFont((QFont("BebasNeue", 30, QFont.Bold)))
        self.__trainingButton.clicked.connect(self.startTraining)

        # Go back button
        self.goBackButton = QPushButton("Back", self)
        self.goBackButton.setObjectName("retour")

        # Customising go back button
        self.goBackButton.setCursor(Qt.PointingHandCursor)
        self.goBackButton.setIcon(QIcon("images/goback_icon"))
        self.goBackButton.setIconSize(QSize(30, 30))
        self.goBackButton.setFont(QFont("BebasNeue", 20, QFont.Bold))

        # Confusion matrix button
        self.__confusionMatrixButton = QPushButton("Show confusion matrix",
                                                   self)
        self.__confusionMatrixButton.setCursor(Qt.PointingHandCursor)
        self.__confusionMatrixButton.setFont((QFont("BebasNeue", 17,
                                                    QFont.Bold)))
        self.__confusionMatrixButton.clicked.connect(self.showStats)
        self.__confusionMatrixButton.setGeometry(420, 20, 250, 80)
        self.__confusionMatrixButton.hide()

        # Parameters group box settings
        self.__parametersGroupBox = QGroupBox("Training parameters", self)
        self.__parametersGroupBox.setObjectName("parameters")
        self.__parametersLayout = QVBoxLayout(self)
        self.__parametersLayout.addWidget(self.__epochsGroupBox)
        self.__parametersLayout.addWidget(self.__datasetSplitGroupBox)
        self.__parametersLayout.addWidget(
            self.__datasetSplitModeButtonsGroupBox)
        self.__parametersLayout.addWidget(self.__learningRateGroupBox)
        self.__parametersLayout.addWidget(self.__trainingButton)
        self.__parametersLayout.addWidget(self.goBackButton)
        self.__parametersGroupBox.setLayout(self.__parametersLayout)
        self.__parametersGroupBox.setGeometry(0, 0, 400, 720)

        # Chart axis settings
        self.__xAxis = QtCharts.QValueAxis()
        self.__xAxis.setRange(0, 5)

        self.__yAxis = QtCharts.QValueAxis()
        self.__yAxis.setRange(0, 100)

        # Chart settings
        self.__series = QtCharts.QLineSeries()
        self.__chart = QtCharts.QChart()
        self.__chart.addAxis(self.__xAxis, Qt.AlignBottom)
        self.__chart.addAxis(self.__yAxis, Qt.AlignLeft)
        self.__chart.addSeries(self.__series)
        self.__series.attachAxis(self.__xAxis)
        self.__series.attachAxis(self.__yAxis)
        self.__chart.setTitle("Accuracy")
        self.__chartView = QtCharts.QChartView(self.__chart)
        self.__chartView.setRenderHint(QPainter.Antialiasing)

        # Chart layout settings
        self.__chartLayout = QVBoxLayout(self)
        self.__chartGroupBox = QGroupBox(self)
        self.__chartGroupBox.setObjectName("chart")
        self.__chartLayout.addWidget(self.__chartView)
        self.__chartGroupBox.setLayout(self.__chartLayout)
        self.__chartGroupBox.setGeometry(390, 100, 900, 600)

        # Update timer settings
        #self.__timer = QTimer(self)
        #self.__timer.timeout.connect(self.autoSave)
        #self.__timer.start(1000)


#app = QApplication(sys.argv)
#window = TrainingWindow()
#window.show()
#app.exec_()