def _init_options_group_box(self) -> None: """Creates the group of training options.""" self._options_group_box = QGroupBox("Options") options_layout = QGridLayout() left_options = QGridLayout() right_options = QGridLayout() self._lists['data'] = QListWidget() self._lists['data'].setSelectionMode( QtWidgets.QAbstractItemView.SingleSelection) self._lists['data'].currentTextChanged.connect(self._refresh_pandas) self._lists['type'] = QComboBox() for dt in IngestTypes: self._lists['type'].addItem(dt.value) self._refresh_lists() self._lists['type'].currentTextChanged.connect(self._type_changed) validator = QRegularExpressionValidator(r'^[\w\-. ]+$') cat_validator = QRegularExpressionValidator(r'^[0-9]\d*$') dataset_label = QLabel("Avaliable Datasets:") search_type_label = QLabel("Symbol/Search Type:") search_label = QLabel("Symbol/Search Term:") name_label = QLabel("Dataset Name:") cat_label = QLabel("Trends Category Code:") left_options.addWidget(dataset_label, 0, 0) left_options.addWidget(self._lists['data'], 1, 0) right_options.addWidget(search_type_label, 0, 0) right_options.addWidget(self._lists['type'], 1, 0) self._txt_var['ds_name'] = QLineEdit() self._txt_var['data_search'] = QLineEdit() self._txt_var['search_cat'] = QLineEdit() self._txt_var['ds_name'].setValidator(validator) self._txt_var['data_search'].setValidator(validator) self._txt_var['search_cat'].setValidator(cat_validator) self._txt_var['search_cat'].setPlaceholderText('0') right_options.addWidget(search_label, 2, 0) right_options.addWidget(self._txt_var['data_search'], 3, 0) right_options.addWidget(name_label, 4, 0) right_options.addWidget(self._txt_var['ds_name'], 5, 0) right_options.addWidget(cat_label, 6, 0) right_options.addWidget(self._txt_var['search_cat'], 7, 0) options_layout.addLayout(left_options, 0, 0) options_layout.addLayout(right_options, 0, 1) options_layout.setColumnStretch(0, 1) self._options_group_box.setLayout(options_layout)
def __init__(self, parent=None): super(AddDialogWidget, self).__init__(parent) nameLabel = QLabel("Name") addressLabel = QLabel("Address") buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.nameText = QLineEdit() self.addressText = QTextEdit() grid = QGridLayout() grid.setColumnStretch(1, 2) grid.addWidget(nameLabel, 0, 0) grid.addWidget(self.nameText, 0, 1) grid.addWidget(addressLabel, 1, 0, Qt.AlignLeft | Qt.AlignTop) grid.addWidget(self.addressText, 1, 1, Qt.AlignLeft) layout = QVBoxLayout() layout.addLayout(grid) layout.addWidget(buttonBox) self.setLayout(layout) self.setWindowTitle("Add a Contact") buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject)
class TableWidget(QWidget): def __init__(self): QWidget.__init__(self) self.model = CustomTableModel() self.table_view = QTableView() self.table_view.setModel(self.model) self.table_view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table_view.verticalHeader().setSectionResizeMode(QHeaderView.Stretch) self.chart = QtCharts.QChart() self.chart.setAnimationOptions(QtCharts.QChart.AllAnimations) self.series = QtCharts.QLineSeries() self.series.setName("Line 1") self.mapper = QtCharts.QVXYModelMapper(self) self.mapper.setXColumn(0) self.mapper.setYColumn(1) self.mapper.setSeries(self.series) self.mapper.setModel(self.model) self.chart.addSeries(self.series) # for storing color hex from the series seriesColorHex = "#000000" # get the color of the series and use it for showing the mapped area seriesColorHex = "{}".format(self.series.pen().color().name()) self.model.add_mapping(seriesColorHex, QRect(0, 0, 2, self.model.rowCount())) # series 2 self.series = QtCharts.QLineSeries() self.series.setName("Line 2") self.mapper = QtCharts.QVXYModelMapper(self) self.mapper.setXColumn(2) self.mapper.setYColumn(3) self.mapper.setSeries(self.series) self.mapper.setModel(self.model) self.chart.addSeries(self.series) # get the color of the series and use it for showing the mapped area seriesColorHex = "{}".format(self.series.pen().color().name()) self.model.add_mapping(seriesColorHex, QRect(2, 0, 2, self.model.rowCount())) self.chart.createDefaultAxes() self.chart_view = QtCharts.QChartView(self.chart) self.chart_view.setRenderHint(QPainter.Antialiasing) self.chart_view.setMinimumSize(640, 480) # create main layout self.main_layout = QGridLayout() self.main_layout.addWidget(self.table_view, 1, 0) self.main_layout.addWidget(self.chart_view, 1, 1) self.main_layout.setColumnStretch(1, 1) self.main_layout.setColumnStretch(0, 0) self.setLayout(self.main_layout)
def __init__(self, parent, data): super(SegmentsWidget, self).__init__(parent) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setVerticalSpacing(1) layout.setHorizontalSpacing(UIContext.getScaledWindowSize(16, 16).width()) self.segments = [] for segment in data.segments: if segment.readable or segment.writable or segment.executable: self.segments.append(segment) self.segments.sort(key = lambda segment: segment.start) row = 0 for segment in self.segments: begin = "0x%x" % segment.start end = "0x%x" % segment.end permissions = "" if segment.readable: permissions += "r" else: permissions += "-" if segment.writable: permissions += "w" else: permissions += "-" if segment.executable: permissions += "x" else: permissions += "-" rangeLayout = QHBoxLayout() rangeLayout.setContentsMargins(0, 0, 0, 0) beginLabel = headers.ClickableAddressLabel(begin) dashLabel = QLabel("-") dashLabel.setFont(binaryninjaui.getMonospaceFont(self)) endLabel = headers.ClickableAddressLabel(end) rangeLayout.addWidget(beginLabel) rangeLayout.addWidget(dashLabel) rangeLayout.addWidget(endLabel) layout.addLayout(rangeLayout, row, 0) permissionsLabel = QLabel(permissions) permissionsLabel.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(permissionsLabel, row, 1) row += 1 layout.setColumnStretch(2, 1) self.setLayout(layout)
def _init_options_group_box(self) -> None: """Creates the group of training options.""" self._options_group_box = QGroupBox("Options") options_layout = QGridLayout() left_options = QGridLayout() right_options = QGridLayout() self._lists['data'] = QListWidget() self._lists['data'].setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self._lists['target'] = QComboBox() self._lists['f_target'] = QComboBox() self._lists['target'].currentTextChanged.connect( self._refresh_f_target_list) self._refresh_lists() dataset_label = QLabel("Datasets:") targets_label = QLabel("Targets:") f_target_label = QLabel("Target Feature:") left_options.addWidget(dataset_label, 0, 0) left_options.addWidget(self._lists['data'], 1, 0) right_options.addWidget(targets_label, 0, 0) right_options.addWidget(self._lists['target'], 1, 0) right_options.addWidget(f_target_label, 2, 0) right_options.addWidget(self._lists['f_target'], 3, 0) right_options.addLayout(self._init_num_options_group_box(), 4, 0) name_validator = QRegularExpressionValidator(r'^[\w\-. ]+$') name_label = QLabel("Model Name:") self._txt_var['model_name'] = QLineEdit() self._txt_var['model_name'].setValidator(name_validator) right_options.addWidget(name_label, 5, 0) right_options.addWidget(self._txt_var['model_name'], 6, 0) options_layout.addLayout(left_options, 0, 0) options_layout.addLayout(right_options, 0, 1) options_layout.setColumnStretch(0, 1) self._options_group_box.setLayout(options_layout)
def __init__(self, parent, header): super(HeaderWidget, self).__init__(parent) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setVerticalSpacing(1) row = 0 col = 0 for field in header.fields: name = field[0] value = field[1] fieldType = "" if len(field) > 2: fieldType = field[2] layout.addWidget(QLabel(name + ": "), row, col * 3) if isinstance(value, list): for i in range(0, len(value)): if fieldType == "ptr": label = ClickableAddressLabel(value[i]) elif fieldType == "code": label = ClickableCodeLabel(value[i]) else: label = QLabel(value[i]) label.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(label, row, col * 3 + 1) row += 1 else: if fieldType == "ptr": label = ClickableAddressLabel(value) elif fieldType == "code": label = ClickableCodeLabel(value) else: label = QLabel(value) label.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(label, row, col * 3 + 1) row += 1 if (header.columns > 1) and (row >= header.rows_per_column) and ( (col + 1) < header.columns): row = 0 col += 1 for col in range(1, header.columns): layout.setColumnMinimumWidth( col * 3 - 1, UIContext.getScaledWindowSize(20, 20).width()) layout.setColumnStretch(header.columns * 3 - 1, 1) self.setLayout(layout)
def createOptionsGroupBox(self): self.optionsGroupBox = QGroupBox("Options") buttonsOrientationLabel = QLabel("Orientation of buttons:") buttonsOrientationComboBox = QComboBox() buttonsOrientationComboBox.addItem("Horizontal", Qt.Horizontal) buttonsOrientationComboBox.addItem("Vertical", Qt.Vertical) buttonsOrientationComboBox.currentIndexChanged[int].connect( self.buttonsOrientationChanged) self.buttonsOrientationComboBox = buttonsOrientationComboBox optionsLayout = QGridLayout() optionsLayout.addWidget(buttonsOrientationLabel, 0, 0) optionsLayout.addWidget(self.buttonsOrientationComboBox, 0, 1) optionsLayout.setColumnStretch(2, 1) self.optionsGroupBox.setLayout(optionsLayout)
class InfoWidget(QWidget): """Display basic file information in a table (two columns). Parameters ---------- values : dict Each key/value pair in this dict will be displayed in a row, separated by a colon. """ def __init__(self, values=None): super().__init__() vbox = QVBoxLayout(self) self.grid = QGridLayout() self.grid.setColumnStretch(1, 1) vbox.addLayout(self.grid) vbox.addStretch(1) self.set_values(values) def set_values(self, values=None): """Set values (and overwrite existing values). Parameters ---------- values : dict Each key/value pair in this dict is displayed in a row separated by a colon. """ self.clear() if values: for row, (key, value) in enumerate(values.items()): left = QLabel(str(key) + ":") right = QLabel(str(value)) right.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed) self.grid.addWidget(left, row, 0) self.grid.addWidget(right, row, 1) def clear(self): """Clear all values.""" item = self.grid.takeAt(0) while item: item.widget().deleteLater() del item item = self.grid.takeAt(0)
def _create_options_group_box(self) -> QGroupBox: """Returns the group of prediction options.""" options_group_box = QGroupBox("Options") options_layout = QGridLayout() left_options = QGridLayout() right_options = QGridLayout() date_label = QLabel("Target Date:") self._target_date = QCalendarWidget() left_options.addWidget(date_label, 0, 0) left_options.addWidget(self._target_date, 1, 0, 1, 3) left_options.setColumnStretch(0, 1) self._model = QComboBox() self._model_info = QPlainTextEdit() self._model_info.setReadOnly(True) self._model.currentTextChanged.connect(self._refresh_model_info) self._refresh_lists() models_label = QLabel("Models:") info_label = QLabel("Model Information:") right_options.addWidget(models_label, 0, 0) right_options.addWidget(self._model, 1, 0) right_options.addWidget(info_label, 2, 0) right_options.addWidget(self._model_info, 3, 0) options_layout.addLayout(left_options, 0, 0) options_layout.addLayout(right_options, 0, 1) options_group_box.setLayout(options_layout) return options_group_box
class UIMainWindow: """ The central class responsible for initializing most of the values stored in the PatientDictContainer model and defining the visual layout of the main window of OnkoDICOM. No class has access to the attributes belonging to this class, except for the class's ActionHandler, which is used to trigger actions within the main window. Components of this class (i.e. QWidget child classes such as StructureTab, DicomView, DicomTree, etc.) should not be able to reference this class, and rather should exist independently and only be able to communicate with the PatientDictContainer model. If a component needs to communicate with another component, that should be accomplished by emitting signals within that components, and having the slots for those signals within this class (as demonstrated by the update_views() method of this class). If a class needs to trigger one of the actions defined in the ActionHandler, then the instance of the ActionHandler itself can safely be passed into the class. """ pyradi_trigger = QtCore.Signal(str, dict, str) # Connect to GUIController image_fusion_main_window = QtCore.Signal() def setup_ui(self, main_window_instance): self.main_window_instance = main_window_instance self.call_class = MainPageCallClass() self.add_on_options_controller = AddOptions(self) ########################################## # IMPLEMENTATION OF THE MAIN PAGE VIEW # ########################################## if platform.system() == 'Darwin': self.stylesheet_path = "res/stylesheet.qss" else: self.stylesheet_path = "res/stylesheet-win-linux.qss" self.stylesheet = open(resource_path(self.stylesheet_path)).read() window_icon = QIcon() window_icon.addPixmap(QPixmap(resource_path( "res/images/icon.ico")), QIcon.Normal, QIcon.Off) self.main_window_instance.setMinimumSize(1080, 700) self.main_window_instance.setObjectName("MainOnkoDicomWindowInstance") self.main_window_instance.setWindowIcon(window_icon) self.main_window_instance.setStyleSheet(self.stylesheet) self.setup_central_widget() self.setup_actions() # Create SUV2ROI object and connect signals self.suv2roi = SUV2ROI() self.suv2roi_progress_window = \ ProgressWindow(self.main_window_instance, QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint) self.suv2roi_progress_window.signal_loaded.connect( self.on_loaded_suv2roi) def setup_actions(self): if hasattr(self, 'toolbar'): self.main_window_instance.removeToolBar(self.toolbar) self.action_handler = ActionHandler(self) self.menubar = MenuBar(self.action_handler) self.main_window_instance.setMenuBar(self.menubar) self.toolbar = Toolbar(self.action_handler) self.main_window_instance.addToolBar( QtCore.Qt.TopToolBarArea, self.toolbar) self.main_window_instance.setWindowTitle("OnkoDICOM") def setup_central_widget(self): patient_dict_container = PatientDictContainer() self.central_widget = QtWidgets.QWidget() self.central_widget_layout = QVBoxLayout() self.patient_bar = PatientBar() splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal) # Left panel contains stuctures tab, isodoses tab, # and structure information self.left_panel = QtWidgets.QTabWidget() self.left_panel.setMinimumWidth(300) self.left_panel.setMaximumWidth(500) # Add structures tab to left panel if not hasattr(self, 'structures_tab'): self.structures_tab = StructureTab() self.structures_tab.request_update_structures.connect( self.update_views) else: self.structures_tab.update_ui() self.left_panel.addTab(self.structures_tab, "Structures") if patient_dict_container.has_modality("rtdose"): self.isodoses_tab = IsodoseTab() self.isodoses_tab.request_update_isodoses.connect( self.update_views) self.isodoses_tab.request_update_ui.connect( self.structures_tab.fixed_container_structure_modified) self.left_panel.addTab(self.isodoses_tab, "Isodoses") elif hasattr(self, 'isodoses_tab'): del self.isodoses_tab # Right panel contains the different tabs of DICOM view, DVH, # clinical data, DICOM tree self.right_panel = QtWidgets.QTabWidget() # Create a Dicom View containing single-slice and 3-slice views self.dicom_view = DicomStackedWidget(self.format_data) roi_color_dict = self.structures_tab.color_dict if hasattr( self, 'structures_tab') else None iso_color_dict = self.isodoses_tab.color_dict if hasattr( self, 'isodoses_tab') else None self.dicom_single_view = DicomAxialView( roi_color=roi_color_dict, iso_color=iso_color_dict) self.dicom_axial_view = DicomAxialView( is_four_view=True, roi_color=roi_color_dict, iso_color=iso_color_dict, metadata_formatted=True, cut_line_color=QtGui.QColor(255, 0, 0)) self.dicom_sagittal_view = DicomSagittalView( roi_color=roi_color_dict, iso_color=iso_color_dict, cut_line_color=QtGui.QColor(0, 255, 0)) self.dicom_coronal_view = DicomCoronalView( roi_color=roi_color_dict, iso_color=iso_color_dict, cut_line_color=QtGui.QColor(0, 0, 255)) self.three_dimension_view = DicomView3D() # Rescale the size of the scenes inside the 3-slice views self.dicom_axial_view.zoom = INITIAL_FOUR_VIEW_ZOOM self.dicom_sagittal_view.zoom = INITIAL_FOUR_VIEW_ZOOM self.dicom_coronal_view.zoom = INITIAL_FOUR_VIEW_ZOOM self.dicom_axial_view.update_view(zoom_change=True) self.dicom_sagittal_view.update_view(zoom_change=True) self.dicom_coronal_view.update_view(zoom_change=True) self.dicom_four_views = QWidget() self.dicom_four_views_layout = QGridLayout() for i in range(2): self.dicom_four_views_layout.setColumnStretch(i, 1) self.dicom_four_views_layout.setRowStretch(i, 1) self.dicom_four_views_layout.addWidget(self.dicom_axial_view, 0, 0) self.dicom_four_views_layout.addWidget(self.dicom_sagittal_view, 0, 1) self.dicom_four_views_layout.addWidget(self.dicom_coronal_view, 1, 0) self.dicom_four_views_layout.addWidget(self.three_dimension_view, 1, 1) self.dicom_four_views.setLayout(self.dicom_four_views_layout) self.dicom_view.addWidget(self.dicom_four_views) self.dicom_view.addWidget(self.dicom_single_view) self.dicom_view.setCurrentWidget(self.dicom_single_view) # Add DICOM View to right panel as a tab self.right_panel.addTab(self.dicom_view, "DICOM View") # Add PETVT View to right panel as a tab self.pet_ct_tab = PetCtView() self.right_panel.addTab(self.pet_ct_tab, "PET/CT View") # Add DVH tab to right panel as a tab if patient_dict_container.has_modality("rtdose"): self.dvh_tab = DVHTab() self.right_panel.addTab(self.dvh_tab, "DVH") elif hasattr(self, 'dvh_tab'): del self.dvh_tab # Add DICOM Tree View tab self.dicom_tree = DicomTreeView() self.right_panel.addTab(self.dicom_tree, "DICOM Tree") # Connect SUV2ROI signal to handler function self.dicom_single_view.suv2roi_signal.connect(self.perform_suv2roi) # Add clinical data tab self.call_class.display_clinical_data(self.right_panel) splitter.addWidget(self.left_panel) splitter.addWidget(self.right_panel) # Create footer self.footer = QtWidgets.QWidget() self.create_footer() # Set layout self.central_widget_layout.addWidget(self.patient_bar) self.central_widget_layout.addWidget(splitter) self.central_widget_layout.addWidget(self.footer) self.central_widget.setLayout(self.central_widget_layout) self.main_window_instance.setCentralWidget(self.central_widget) def create_footer(self): self.footer.setFixedHeight(15) layout_footer = QtWidgets.QHBoxLayout(self.footer) layout_footer.setContentsMargins(0, 0, 0, 0) label_footer = QtWidgets.QLabel("@OnkoDICOM2021") label_footer.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignRight) layout_footer.addWidget(label_footer) def update_views(self, update_3d_window=False): """ This function is a slot for signals to request the updating of the DICOM View and DVH tabs in order to reflect changes made by other components of the main window (for example, when a structure in the structures tab is selected, this method needs to be called in order for the DICOM view window to be updated to show the new region of interest. :param update_3d_window: a boolean to mark if 3d model needs to be updated """ self.dicom_single_view.update_view() self.dicom_axial_view.update_view() self.dicom_coronal_view.update_view() self.dicom_sagittal_view.update_view() if update_3d_window: self.three_dimension_view.update_view() if hasattr(self, 'dvh_tab'): self.dvh_tab.update_plot() if hasattr(self, 'pet_ct_tab'): if self.pet_ct_tab.initialised: self.pet_ct_tab.update_view() if hasattr(self, 'image_fusion_view'): if self.image_fusion_view_axial is not None: self.image_fusion_single_view.update_view() self.image_fusion_view_axial.update_view() self.image_fusion_view_coronal.update_view() self.image_fusion_view_sagittal.update_view() def toggle_cut_lines(self): if self.dicom_axial_view.horizontal_view is None or \ self.dicom_axial_view.vertical_view is None or \ self.dicom_coronal_view.horizontal_view is None or \ self.dicom_coronal_view.vertical_view is None or \ self.dicom_sagittal_view.horizontal_view is None or \ self.dicom_sagittal_view.vertical_view is None: self.dicom_axial_view.set_views(self.dicom_coronal_view, self.dicom_sagittal_view) self.dicom_coronal_view.set_views(self.dicom_axial_view, self.dicom_sagittal_view) self.dicom_sagittal_view.set_views(self.dicom_axial_view, self.dicom_coronal_view) else: self.dicom_axial_view.set_views(None, None) self.dicom_coronal_view.set_views(None, None) self.dicom_sagittal_view.set_views(None, None) if hasattr(self, 'image_fusion_view'): if self.image_fusion_view is not None: if self.image_fusion_view_axial.horizontal_view is None or \ self.image_fusion_view_axial.vertical_view is None or \ self.image_fusion_view_coronal.horizontal_view is None \ or self.image_fusion_view_coronal.vertical_view is None \ or \ self.image_fusion_view_sagittal.horizontal_view is None \ or \ self.image_fusion_view_sagittal.vertical_view is None: self.image_fusion_view_axial.set_views( self.image_fusion_view_coronal, self.image_fusion_view_sagittal) self.image_fusion_view_coronal.set_views( self.image_fusion_view_axial, self.image_fusion_view_sagittal) self.image_fusion_view_sagittal.set_views( self.image_fusion_view_axial, self.image_fusion_view_coronal) else: self.image_fusion_view_axial.set_views(None, None) self.image_fusion_view_coronal.set_views(None, None) self.image_fusion_view_sagittal.set_views(None, None) def zoom_in(self, is_four_view, image_reg_single, image_reg_four): """ This function calls the zooming in function on the four view's views or the single view depending on what view is showing on screen. is_four_view: Whether the four view is showing """ if is_four_view: self.dicom_axial_view.zoom_in() self.dicom_coronal_view.zoom_in() self.dicom_sagittal_view.zoom_in() else: self.dicom_single_view.zoom_in() if image_reg_single: self.image_fusion_single_view.zoom_in() if image_reg_four: self.image_fusion_view_axial.zoom_in() self.image_fusion_view_coronal.zoom_in() self.image_fusion_view_sagittal.zoom_in() if self.pet_ct_tab.initialised: self.pet_ct_tab.zoom_in() def zoom_out(self, is_four_view, image_reg_single, image_reg_four): """ This function calls the zooming out function on the four view's views or the single view depending on what view is showing on screen. is_four_view: Whether the four view is showing """ if is_four_view: self.dicom_axial_view.zoom_out() self.dicom_coronal_view.zoom_out() self.dicom_sagittal_view.zoom_out() else: self.dicom_single_view.zoom_out() if image_reg_single: self.image_fusion_single_view.zoom_out() if image_reg_four: self.image_fusion_view_axial.zoom_out() self.image_fusion_view_coronal.zoom_out() self.image_fusion_view_sagittal.zoom_out() if self.pet_ct_tab.initialised: self.pet_ct_tab.zoom_out() def format_data(self, size): """ This function is used to update the meta data's font size and margin based on the height and width of the viewports. size: The size of the DicomStackedWidget """ self.dicom_axial_view.format_metadata(size) def create_image_fusion_tab(self): """ This function is used to create the tab for image fusion. Function checks if the moving dict container contains rtss to load rtss. Views are created and stacked into three window view. """ # Set a flag for Zooming self.action_handler.has_image_registration_four = True # Instance of Moving Model moving_dict_container = MovingDictContainer() if moving_dict_container.has_modality("rtss"): if len(self.structures_tab.rois.items()) == 0: self.structures_tab.update_ui(moving=True) # else: # TODO: Display both ROIs in the same tab self.image_fusion_single_view \ = ImageFusionAxialView() self.image_fusion_view = QStackedWidget() self.image_fusion_view_axial = ImageFusionAxialView( metadata_formatted=False, cut_line_color=QtGui.QColor(255, 0, 0)) self.image_fusion_view_sagittal = ImageFusionSagittalView( cut_line_color=QtGui.QColor(0, 255, 0)) self.image_fusion_view_coronal = ImageFusionCoronalView( cut_line_color=QtGui.QColor(0, 0, 255)) self.image_fusion_roi_transfer_option_view = ROITransferOptionView( self.structures_tab.fixed_container_structure_modified, self.structures_tab.moving_container_structure_modified) # Rescale the size of the scenes inside the 3-slice views self.image_fusion_view_axial.zoom = INITIAL_FOUR_VIEW_ZOOM self.image_fusion_view_sagittal.zoom = INITIAL_FOUR_VIEW_ZOOM self.image_fusion_view_coronal.zoom = INITIAL_FOUR_VIEW_ZOOM self.image_fusion_view_axial.update_view(zoom_change=True) self.image_fusion_view_sagittal.update_view(zoom_change=True) self.image_fusion_view_coronal.update_view(zoom_change=True) self.image_fusion_four_views = QWidget() self.image_fusion_four_views_layout = QGridLayout() for i in range(2): self.image_fusion_four_views_layout.setColumnStretch(i, 1) self.image_fusion_four_views_layout.setRowStretch(i, 1) self.image_fusion_four_views_layout.addWidget( self.image_fusion_view_axial, 0, 0) self.image_fusion_four_views_layout.addWidget( self.image_fusion_view_sagittal, 0, 1) self.image_fusion_four_views_layout.addWidget( self.image_fusion_view_coronal, 1, 0) self.image_fusion_four_views_layout.addWidget( self.image_fusion_roi_transfer_option_view, 1, 1 ) self.image_fusion_four_views.setLayout( self.image_fusion_four_views_layout) self.image_fusion_view.addWidget(self.image_fusion_four_views) self.image_fusion_view.addWidget(self.image_fusion_single_view) self.image_fusion_view.setCurrentWidget(self.image_fusion_four_views) # Add Image Fusion Tab self.right_panel.addTab(self.image_fusion_view, "Image Fusion") self.right_panel.setCurrentWidget(self.image_fusion_view) # Update the Add On Option GUI self.add_on_options_controller.update_ui() def perform_suv2roi(self): """ Performs the SUV2ROI process. """ # Get patient weight - needs to run first as GUI cannot run in # threads, like the ProgressBar patient_dict_container = PatientDictContainer() dataset = patient_dict_container.dataset[0] self.suv2roi.get_patient_weight(dataset) if self.suv2roi.patient_weight is None: return # Start the SUV2ROI process self.suv2roi_progress_window.start(self.suv2roi.start_conversion) def on_loaded_suv2roi(self): """ Called when progress bar has finished. Closes the progress window and refreshes the main screen. """ if self.suv2roi.suv2roi_status: patient_dict_container = PatientDictContainer() self.structures_tab.fixed_container_structure_modified(( patient_dict_container.get('dataset_rtss'), {"draw": None})) else: # Alert user that SUV2ROI failed and for what reason if self.suv2roi.failure_reason == "UNIT": failure_reason = \ "PET units are not Bq/mL. OnkoDICOM can currently only\n" \ "perform SUV2ROI on PET images stored in these units." elif self.suv2roi.failure_reason == "DECY": failure_reason = \ "PET is not decay corrected. OnkoDICOM can currently " \ "only\nperform SUV2ROI on PET images that are decay " \ "corrected." else: failure_reason = "The SUV2ROI process has failed." button_reply = \ QtWidgets.QMessageBox( QtWidgets.QMessageBox.Icon.Warning, "SUV2ROI Failed", failure_reason, QtWidgets.QMessageBox.StandardButton.Ok, self) button_reply.button( QtWidgets.QMessageBox.StandardButton.Ok).setStyleSheet( self.stylesheet) button_reply.exec_() # Close progress window self.suv2roi_progress_window.close()
class ResultsGrid(QScrollArea): def __init__(self, parent=None): QScrollArea.__init__(self) self.setParent(parent) # Make QScrollArea transparent self.setStyleSheet( "QScrollArea { background-color: transparent } .QFrame { background-color: transparent }" ) self.setWidgetResizable(True) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) # Add Touch Gestures to menu. QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture) # Layout settings self.layout = QGridLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) # QScrollArea requires a separate QWidget to work properly frame = QFrame() frame.setLayout(self.layout) self.setWidget(frame) def clearResults(self): # Clear the results in the list while self.layout.count(): item = self.layout.takeAt(0) if item.widget() is not None: item.widget().deleteLater() def addResults(self, results): # Add the results to the list # results (list): list of python dict representing results details (playlist or song search) self.clearResults() for i in range(len(results)): item = self.ResultsGridItem(results[i], self) self.layout.addWidget(item, i // 6, i % 6) if results: self.layout.setRowStretch(self.layout.rowCount(), 1) self.layout.setColumnStretch(self.layout.columnCount(), 1) else: # If the results are empty, display no result label = QLabel("没有结果/No Result") label.setStyleSheet("color: white") label.setAlignment(Qt.AlignCenter) font = QFont() font.setPointSize(35) label.setFont(font) self.layout.addWidget(label) class ResultsGridItem(QToolButton): def __init__(self, result, parent=None): QToolButton.__init__(self) self.setParent(parent) self.result = result self.setContentsMargins(0, 0, 0, 0) # Button formatting self.setFixedSize(200, 240) self.setAutoRaise(True) # TODO: change with global themes self.setStyleSheet( "QToolButton:pressed { background-color: rgba(255, 255, 255, 0.1)} QToolButton { background-color: rgba(255, 255, 255, 0.05); border: 1px solid white; color: white}" ) # Set layout settings self.layout = QGridLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) if result["type"] == "artists": # Artist image self.formattedImage(self.window().artistPath + result["artist_path"]) self.formattedLabel(result["artist_name"]) # Favourite button self.favouriteButton = QToolButton() self.favouriteButton.setStyleSheet( "QToolButton:pressed { background-color: rgb(31, 41, 75)} QToolButton { background-color: rgb(25, 33, 60);}" ) # Toggle Favourite Icon depending on DB if self.result["favourited"] == 0: self.favouriteButton.isFavourited = False self.favouriteButton.setIcon(QIcon("icons/star.svg")) else: self.favouriteButton.isFavourited = True self.favouriteButton.setIcon( QIcon("icons/star-yellow.svg")) self.favouriteButton.setIconSize(QSize(30, 30)) self.favouriteButton.setFixedSize(70, 70) self.favouriteButton.clicked.connect(self.clickedFavourite) self.layout.addWidget(self.favouriteButton, 0, 0, Qt.AlignRight | Qt.AlignTop) self.clicked.connect(self.clickedArtist) elif result["type"] == "languages": # Language image self.formattedImage(self.window().languagePath + result["language_path"]) self.formattedLabel(result["language_name"]) self.clicked.connect(self.clickedLanguage) self.setLayout(self.layout) def clickedFavourite(self): # Toggle Icon and DB state of song being favourited # For artists only if self.favouriteButton.isFavourited: self.favouriteButton.isFavourited = False self.favouriteButton.setIcon(QIcon("icons/star.svg")) else: self.favouriteButton.isFavourited = True self.favouriteButton.setIcon( QIcon("icons/star-yellow.svg")) DB.setFavouriteArtist(self.result["artist_id"]) def formattedImage(self, path): # Format an image given the path self.setIcon(QIcon(path)) self.setIconSize(QSize(180, 180)) def formattedLabel(self, text): # Format a label given text font = QFont() font.setPixelSize(18) self.setText(text) self.setFont(font) self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) def clickedArtist(self): # Called when an Artist is clicked on self.window().content.addWidget( WindowSearch( "搜索全部/Search", self, self.window().content.currentWidget().counter + 1, self.result)) self.window().content.setCurrentIndex( self.window().content.currentWidget().counter + 1) def clickedLanguage(self): # Called when a Language is clicked on self.window().content.addWidget( WindowSearch( "搜索歌手/Artist Search", self, self.window().content.currentWidget().counter + 1, self.result, grid=True)) self.window().content.setCurrentIndex( self.window().content.currentWidget().counter + 1)
def __init__(self, parent, data): super(SectionsWidget, self).__init__(parent) layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setVerticalSpacing(1) layout.setHorizontalSpacing(UIContext.getScaledWindowSize(16, 16).width()) maxNameLen = 0 for section in data.sections.values(): if len(section.name) > maxNameLen: maxNameLen = len(section.name) if maxNameLen > 32: maxNameLen = 32 self.sections = [] for section in data.sections.values(): if section.semantics != SectionSemantics.ExternalSectionSemantics: self.sections.append(section) self.sections.sort(key = lambda section: section.start) row = 0 for section in self.sections: name = section.name if len(name) > maxNameLen: name = name[:maxNameLen - 1] + "…" begin = "0x%x" % section.start end = "0x%x" % section.end typeName = section.type permissions = "" if data.is_offset_readable(section.start): permissions += "r" else: permissions += "-" if data.is_offset_writable(section.start): permissions += "w" else: permissions += "-" if data.is_offset_executable(section.start): permissions += "x" else: permissions += "-" semantics = "" if section.semantics == SectionSemantics.ReadOnlyCodeSectionSemantics: semantics = "Code" elif section.semantics == SectionSemantics.ReadOnlyDataSectionSemantics: semantics = "Read-only Data" elif section.semantics == SectionSemantics.ReadWriteDataSectionSemantics: semantics = "Writable Data" nameLabel = QLabel(name) nameLabel.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(nameLabel, row, 0) rangeLayout = QHBoxLayout() rangeLayout.setContentsMargins(0, 0, 0, 0) beginLabel = headers.ClickableAddressLabel(begin) dashLabel = QLabel("-") dashLabel.setFont(binaryninjaui.getMonospaceFont(self)) endLabel = headers.ClickableAddressLabel(end) rangeLayout.addWidget(beginLabel) rangeLayout.addWidget(dashLabel) rangeLayout.addWidget(endLabel) layout.addLayout(rangeLayout, row, 1) permissionsLabel = QLabel(permissions) permissionsLabel.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(permissionsLabel, row, 2) typeLabel = QLabel(typeName) typeLabel.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(typeLabel, row, 3) semanticsLabel = QLabel(semantics) semanticsLabel.setFont(binaryninjaui.getMonospaceFont(self)) layout.addWidget(semanticsLabel, row, 4) row += 1 layout.setColumnStretch(5, 1) self.setLayout(layout)
class Ui_GridControls(object): def setupUi(self, GridControls): if not GridControls.objectName(): GridControls.setObjectName(u"GridControls") GridControls.resize(400, 300) self.grid_layout = QGridLayout(GridControls) self.grid_layout.setObjectName(u"grid_layout") self.game_display = QGraphicsView(GridControls) self.game_display.setObjectName(u"game_display") self.grid_layout.addWidget(self.game_display, 0, 0, 5, 1) self.black_count = ScaledLabel(GridControls) self.black_count.setObjectName(u"black_count") sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.black_count.sizePolicy().hasHeightForWidth()) self.black_count.setSizePolicy(sizePolicy) self.black_count.setScaledContents(True) self.black_count.setAlignment(Qt.AlignHCenter | Qt.AlignTop) self.grid_layout.addWidget(self.black_count, 1, 1, 1, 1) self.black_count_pixmap = ScaledLabel(GridControls) self.black_count_pixmap.setObjectName(u"black_count_pixmap") sizePolicy.setHeightForWidth( self.black_count_pixmap.sizePolicy().hasHeightForWidth()) self.black_count_pixmap.setSizePolicy(sizePolicy) self.black_count_pixmap.setScaledContents(True) self.black_count_pixmap.setAlignment(Qt.AlignBottom | Qt.AlignHCenter) self.grid_layout.addWidget(self.black_count_pixmap, 0, 1, 1, 1) self.white_count_pixmap = ScaledLabel(GridControls) self.white_count_pixmap.setObjectName(u"white_count_pixmap") sizePolicy.setHeightForWidth( self.white_count_pixmap.sizePolicy().hasHeightForWidth()) self.white_count_pixmap.setSizePolicy(sizePolicy) self.white_count_pixmap.setScaledContents(True) self.white_count_pixmap.setAlignment(Qt.AlignBottom | Qt.AlignHCenter) self.grid_layout.addWidget(self.white_count_pixmap, 0, 2, 1, 1) self.white_count = ScaledLabel(GridControls) self.white_count.setObjectName(u"white_count") sizePolicy.setHeightForWidth( self.white_count.sizePolicy().hasHeightForWidth()) self.white_count.setSizePolicy(sizePolicy) self.white_count.setScaledContents(True) self.white_count.setAlignment(Qt.AlignHCenter | Qt.AlignTop) self.grid_layout.addWidget(self.white_count, 1, 2, 1, 1) self.player_pixmap = ScaledLabel(GridControls) self.player_pixmap.setObjectName(u"player_pixmap") sizePolicy.setHeightForWidth( self.player_pixmap.sizePolicy().hasHeightForWidth()) self.player_pixmap.setSizePolicy(sizePolicy) self.player_pixmap.setScaledContents(True) self.player_pixmap.setAlignment(Qt.AlignBottom | Qt.AlignHCenter) self.grid_layout.addWidget(self.player_pixmap, 2, 1, 1, 2) self.move_text = ScaledLabel(GridControls) self.move_text.setObjectName(u"move_text") sizePolicy.setHeightForWidth( self.move_text.sizePolicy().hasHeightForWidth()) self.move_text.setSizePolicy(sizePolicy) self.move_text.setScaledContents(True) self.move_text.setAlignment(Qt.AlignHCenter | Qt.AlignTop) self.grid_layout.addWidget(self.move_text, 3, 1, 1, 2) self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.grid_layout.addItem(self.verticalSpacer, 4, 1, 1, 2) self.grid_layout.setRowStretch(0, 1) self.grid_layout.setRowStretch(1, 1) self.grid_layout.setRowStretch(2, 5) self.grid_layout.setRowStretch(3, 1) self.grid_layout.setRowStretch(4, 5) self.grid_layout.setColumnStretch(0, 10) self.grid_layout.setColumnStretch(1, 1) self.grid_layout.setColumnStretch(2, 1) self.retranslateUi(GridControls) QMetaObject.connectSlotsByName(GridControls) # setupUi def retranslateUi(self, GridControls): GridControls.setWindowTitle( QCoreApplication.translate("GridControls", u"Form", None)) self.black_count.setText( QCoreApplication.translate("GridControls", u"0", None)) self.black_count_pixmap.setText( QCoreApplication.translate("GridControls", u"B", None)) self.white_count_pixmap.setText( QCoreApplication.translate("GridControls", u"W", None)) self.white_count.setText( QCoreApplication.translate("GridControls", u"0", None)) self.player_pixmap.setText( QCoreApplication.translate("GridControls", u"Player", None)) self.move_text.setText( QCoreApplication.translate("GridControls", u"to move", None))
def __init__(self) -> None: super().__init__() layout = self._main_layout = QVBoxLayout() size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) size.setVerticalStretch(1) grid = QGridLayout() grid.setColumnStretch(3, 1) grid.addWidget(self._label("Bands:"), 0, 0) self.lat_bands_field = self._int_field( 0, 360, tooltip="Number of latitude bands" ) grid.addWidget(self.lat_bands_field, 0, 1) # Control for setting initial global average temperature grid.addWidget(self._label("Init. Temp:"), 1, 0) self.gat0_field = self._int_field( -100, 100, placeholder="°C", tooltip="Initial global average temperature, Celsius", ) grid.addWidget(self.gat0_field, 1, 1) # Control for setting range of solar multiplier values grid.addWidget(self._label("Solar Multiplier:"), 2, 0) ff = self._float_field field = self.min_sol_mult_field = ff( 0, 100, placeholder="Min", tooltip="Minimum Solar Constant multiplier", ) grid.addWidget(field, 2, 1) field = self.max_sol_mult_field = ff( 0, 100, placeholder="Max", tooltip="Maximum Solar Constant multiplier", ) grid.addWidget(field, 2, 2) # Control rate of lateral heat transfer: grid.addWidget(self._label("Transfer Coefficient:"), 3, 0) field = self.lhtc_field = ff( 0, 10, placeholder="W/m^2", tooltip="Latitudinal heat transport coefficient, W/m^2", ) grid.addWidget(field, 3, 1) layout.addLayout(grid) # Display of global average temperature vs. solar multiplier, # rising vs. falling chart = self.gatsm_chart = MousingChart() chart.setAnimationOptions(QtCharts.QChart.AllAnimations) chart_view = self.gatsm_view = QtCharts.QChartView(chart) chart_view.setRenderHint(QPainter.Antialiasing) size.setVerticalStretch(1) chart_view.setSizePolicy(size) chart_view.setMinimumSize(480, 320) self._main_layout.addWidget(chart_view) # Display of albedo by latitude band, for a given # point on the rising plot hbox = QHBoxLayout() hbox.addStretch(1) vbox1 = QVBoxLayout() vbox1.addWidget(self._label("Rising", Qt.AlignCenter)) vm = self.rising_vc = LatBandsVC() min_size = (192, 192) widget = vm.widget widget.setMinimumSize(*min_size) vbox1.addWidget(widget) hbox.addLayout(vbox1) hbox.addStretch(1) # Display of albedo by latitude band, for a given # point on the falling plot vbox2 = QVBoxLayout() vbox2.addWidget(self._label("Falling", Qt.AlignCenter)) vm = self.falling_vc = LatBandsVC() widget = vm.widget widget.setMinimumSize(*min_size) vbox2.addWidget(widget) hbox.addLayout(vbox2) hbox.addStretch(1) self._main_layout.addLayout(hbox) self.setLayout(self._main_layout)
class Ui_MainWindow(object): def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(911, 607) self.action_open = QAction(MainWindow) self.action_open.setObjectName(u"action_open") self.action_open.setVisible(False) self.action_comparison = QAction(MainWindow) self.action_comparison.setObjectName(u"action_comparison") self.action_comparison.setVisible(False) self.action_plot = QAction(MainWindow) self.action_plot.setObjectName(u"action_plot") self.action_training_session = QAction(MainWindow) self.action_training_session.setObjectName(u"action_training_session") self.action_training_session.setVisible(False) self.action_game = QAction(MainWindow) self.action_game.setObjectName(u"action_game") self.action_save = QAction(MainWindow) self.action_save.setObjectName(u"action_save") self.action_save.setVisible(False) self.action_save_log = QAction(MainWindow) self.action_save_log.setObjectName(u"action_save_log") self.action_save_log.setVisible(False) self.action_coordinates = QAction(MainWindow) self.action_coordinates.setObjectName(u"action_coordinates") self.action_coordinates.setCheckable(True) self.action_about = QAction(MainWindow) self.action_about.setObjectName(u"action_about") self.action_new_db = QAction(MainWindow) self.action_new_db.setObjectName(u"action_new_db") self.action_open_db = QAction(MainWindow) self.action_open_db.setObjectName(u"action_open_db") self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.verticalLayout_2 = QVBoxLayout(self.centralwidget) self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.stacked_widget = QStackedWidget(self.centralwidget) self.stacked_widget.setObjectName(u"stacked_widget") self.game_page = QWidget() self.game_page.setObjectName(u"game_page") self.gridLayout_3 = QGridLayout(self.game_page) self.gridLayout_3.setObjectName(u"gridLayout_3") self.connect4 = QPushButton(self.game_page) self.connect4.setObjectName(u"connect4") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.connect4.sizePolicy().hasHeightForWidth()) self.connect4.setSizePolicy(sizePolicy) self.gridLayout_3.addWidget(self.connect4, 0, 1, 1, 1) self.tic_tac_toe = QPushButton(self.game_page) self.tic_tac_toe.setObjectName(u"tic_tac_toe") sizePolicy1 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) sizePolicy1.setHorizontalStretch(0) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth( self.tic_tac_toe.sizePolicy().hasHeightForWidth()) self.tic_tac_toe.setSizePolicy(sizePolicy1) self.gridLayout_3.addWidget(self.tic_tac_toe, 0, 0, 1, 1) self.othello = QPushButton(self.game_page) self.othello.setObjectName(u"othello") sizePolicy.setHeightForWidth( self.othello.sizePolicy().hasHeightForWidth()) self.othello.setSizePolicy(sizePolicy) self.gridLayout_3.addWidget(self.othello, 1, 0, 1, 1) self.stacked_widget.addWidget(self.game_page) self.players_page = QWidget() self.players_page.setObjectName(u"players_page") self.verticalLayout = QVBoxLayout(self.players_page) self.verticalLayout.setObjectName(u"verticalLayout") self.player_layout = QGridLayout() self.player_layout.setObjectName(u"player_layout") self.searches_lock2 = QCheckBox(self.players_page) self.searches_lock2.setObjectName(u"searches_lock2") self.player_layout.addWidget(self.searches_lock2, 2, 4, 1, 1) self.player1 = QComboBox(self.players_page) self.player1.setObjectName(u"player1") sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) sizePolicy2.setHorizontalStretch(0) sizePolicy2.setVerticalStretch(0) sizePolicy2.setHeightForWidth( self.player1.sizePolicy().hasHeightForWidth()) self.player1.setSizePolicy(sizePolicy2) self.player_layout.addWidget(self.player1, 1, 1, 1, 1) self.cancel = QPushButton(self.players_page) self.cancel.setObjectName(u"cancel") self.player_layout.addWidget(self.cancel, 4, 0, 1, 1) self.searches_label1 = QLabel(self.players_page) self.searches_label1.setObjectName(u"searches_label1") sizePolicy3 = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) sizePolicy3.setHorizontalStretch(0) sizePolicy3.setVerticalStretch(0) sizePolicy3.setHeightForWidth( self.searches_label1.sizePolicy().hasHeightForWidth()) self.searches_label1.setSizePolicy(sizePolicy3) self.player_layout.addWidget(self.searches_label1, 1, 3, 1, 1) self.player2 = QComboBox(self.players_page) self.player2.setObjectName(u"player2") sizePolicy2.setHeightForWidth( self.player2.sizePolicy().hasHeightForWidth()) self.player2.setSizePolicy(sizePolicy2) self.player_layout.addWidget(self.player2, 2, 1, 1, 1) self.searches_lock1 = QCheckBox(self.players_page) self.searches_lock1.setObjectName(u"searches_lock1") self.player_layout.addWidget(self.searches_lock1, 1, 4, 1, 1) self.game_label = QLabel(self.players_page) self.game_label.setObjectName(u"game_label") sizePolicy4 = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy4.setHorizontalStretch(0) sizePolicy4.setVerticalStretch(0) sizePolicy4.setHeightForWidth( self.game_label.sizePolicy().hasHeightForWidth()) self.game_label.setSizePolicy(sizePolicy4) self.player_layout.addWidget(self.game_label, 0, 0, 1, 1) self.game_name = QLabel(self.players_page) self.game_name.setObjectName(u"game_name") self.player_layout.addWidget(self.game_name, 0, 1, 1, 4) self.searches_label2 = QLabel(self.players_page) self.searches_label2.setObjectName(u"searches_label2") self.player_layout.addWidget(self.searches_label2, 2, 3, 1, 1) self.player_label1 = QLabel(self.players_page) self.player_label1.setObjectName(u"player_label1") sizePolicy4.setHeightForWidth( self.player_label1.sizePolicy().hasHeightForWidth()) self.player_label1.setSizePolicy(sizePolicy4) self.player_layout.addWidget(self.player_label1, 1, 0, 1, 1) self.searches1 = QSpinBox(self.players_page) self.searches1.setObjectName(u"searches1") sizePolicy5 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy5.setHorizontalStretch(0) sizePolicy5.setVerticalStretch(0) sizePolicy5.setHeightForWidth( self.searches1.sizePolicy().hasHeightForWidth()) self.searches1.setSizePolicy(sizePolicy5) self.searches1.setMaximum(1000000) self.player_layout.addWidget(self.searches1, 1, 2, 1, 1) self.player_label2 = QLabel(self.players_page) self.player_label2.setObjectName(u"player_label2") self.player_layout.addWidget(self.player_label2, 2, 0, 1, 1) self.shuffle_players = QCheckBox(self.players_page) self.shuffle_players.setObjectName(u"shuffle_players") self.player_layout.addWidget(self.shuffle_players, 3, 1, 1, 4) self.searches2 = QSpinBox(self.players_page) self.searches2.setObjectName(u"searches2") sizePolicy5.setHeightForWidth( self.searches2.sizePolicy().hasHeightForWidth()) self.searches2.setSizePolicy(sizePolicy5) self.searches2.setMaximum(1000000) self.player_layout.addWidget(self.searches2, 2, 2, 1, 1) self.start = QPushButton(self.players_page) self.start.setObjectName(u"start") self.player_layout.addWidget(self.start, 4, 1, 1, 4) self.player_layout.setColumnStretch(1, 10) self.player_layout.setColumnStretch(2, 1) self.verticalLayout.addLayout(self.player_layout) self.stacked_widget.addWidget(self.players_page) self.humans_page = QWidget() self.humans_page.setObjectName(u"humans_page") self.gridLayout = QGridLayout(self.humans_page) self.gridLayout.setObjectName(u"gridLayout") self.close_humans = QPushButton(self.humans_page) self.close_humans.setObjectName(u"close_humans") sizePolicy4.setHeightForWidth( self.close_humans.sizePolicy().hasHeightForWidth()) self.close_humans.setSizePolicy(sizePolicy4) self.gridLayout.addWidget(self.close_humans, 1, 1, 1, 1) self.players_label = QLabel(self.humans_page) self.players_label.setObjectName(u"players_label") self.gridLayout.addWidget(self.players_label, 0, 0, 1, 1) self.new_human = QPushButton(self.humans_page) self.new_human.setObjectName(u"new_human") sizePolicy4.setHeightForWidth( self.new_human.sizePolicy().hasHeightForWidth()) self.new_human.setSizePolicy(sizePolicy4) self.gridLayout.addWidget(self.new_human, 1, 3, 1, 1) self.players_table = QTableWidget(self.humans_page) self.players_table.setObjectName(u"players_table") self.gridLayout.addWidget(self.players_table, 0, 1, 1, 3) self.spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.gridLayout.addItem(self.spacer, 1, 2, 1, 1) self.stacked_widget.addWidget(self.humans_page) self.rules_page = QWidget() self.rules_page.setObjectName(u"rules_page") self.gridLayout_4 = QGridLayout(self.rules_page) self.gridLayout_4.setObjectName(u"gridLayout_4") self.rules_text = QTextBrowser(self.rules_page) self.rules_text.setObjectName(u"rules_text") self.gridLayout_4.addWidget(self.rules_text, 0, 0, 1, 1) self.rules_close = QPushButton(self.rules_page) self.rules_close.setObjectName(u"rules_close") sizePolicy4.setHeightForWidth( self.rules_close.sizePolicy().hasHeightForWidth()) self.rules_close.setSizePolicy(sizePolicy4) self.gridLayout_4.addWidget(self.rules_close, 1, 0, 1, 1) self.stacked_widget.addWidget(self.rules_page) self.display_page = QWidget() self.display_page.setObjectName(u"display_page") self.gridLayout_2 = QGridLayout(self.display_page) self.gridLayout_2.setObjectName(u"gridLayout_2") self.toggle_review = QPushButton(self.display_page) self.toggle_review.setObjectName(u"toggle_review") sizePolicy4.setHeightForWidth( self.toggle_review.sizePolicy().hasHeightForWidth()) self.toggle_review.setSizePolicy(sizePolicy4) self.gridLayout_2.addWidget(self.toggle_review, 3, 2, 1, 1) self.move_history = QComboBox(self.display_page) self.move_history.setObjectName(u"move_history") sizePolicy6 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) sizePolicy6.setHorizontalStretch(1) sizePolicy6.setVerticalStretch(0) sizePolicy6.setHeightForWidth( self.move_history.sizePolicy().hasHeightForWidth()) self.move_history.setSizePolicy(sizePolicy6) self.gridLayout_2.addWidget(self.move_history, 3, 1, 1, 1) self.choices = QTableWidget(self.display_page) self.choices.setObjectName(u"choices") sizePolicy7 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy7.setHorizontalStretch(0) sizePolicy7.setVerticalStretch(0) sizePolicy7.setHeightForWidth( self.choices.sizePolicy().hasHeightForWidth()) self.choices.setSizePolicy(sizePolicy7) self.gridLayout_2.addWidget(self.choices, 1, 0, 1, 3) self.resume_here = QPushButton(self.display_page) self.resume_here.setObjectName(u"resume_here") sizePolicy5.setHeightForWidth( self.resume_here.sizePolicy().hasHeightForWidth()) self.resume_here.setSizePolicy(sizePolicy5) self.gridLayout_2.addWidget(self.resume_here, 3, 0, 1, 1) self.game_display = QLabel(self.display_page) self.game_display.setObjectName(u"game_display") self.gridLayout_2.addWidget(self.game_display, 0, 0, 1, 3) self.stacked_widget.addWidget(self.display_page) self.plot_strength_page = QWidget() self.plot_strength_page.setObjectName(u"plot_strength_page") self.gridLayout_5 = QGridLayout(self.plot_strength_page) self.gridLayout_5.setObjectName(u"gridLayout_5") self.label = QLabel(self.plot_strength_page) self.label.setObjectName(u"label") self.gridLayout_5.addWidget(self.label, 0, 0, 1, 1) self.plot_game = QComboBox(self.plot_strength_page) self.plot_game.setObjectName(u"plot_game") self.gridLayout_5.addWidget(self.plot_game, 0, 1, 1, 2) self.lineEdit = QLineEdit(self.plot_strength_page) self.lineEdit.setObjectName(u"lineEdit") self.gridLayout_5.addWidget(self.lineEdit, 2, 1, 1, 2) self.label_2 = QLabel(self.plot_strength_page) self.label_2.setObjectName(u"label_2") self.gridLayout_5.addWidget(self.label_2, 3, 0, 1, 1) self.lineEdit_2 = QLineEdit(self.plot_strength_page) self.lineEdit_2.setObjectName(u"lineEdit_2") self.gridLayout_5.addWidget(self.lineEdit_2, 3, 1, 1, 2) self.reset_plot = QPushButton(self.plot_strength_page) self.reset_plot.setObjectName(u"reset_plot") self.gridLayout_5.addWidget(self.reset_plot, 6, 2, 1, 1) self.start_stop_plot = QPushButton(self.plot_strength_page) self.start_stop_plot.setObjectName(u"start_stop_plot") self.gridLayout_5.addWidget(self.start_stop_plot, 6, 1, 1, 1) self.strengths_label = QLabel(self.plot_strength_page) self.strengths_label.setObjectName(u"strengths_label") self.gridLayout_5.addWidget(self.strengths_label, 2, 0, 1, 1) self.label_3 = QLabel(self.plot_strength_page) self.label_3.setObjectName(u"label_3") self.gridLayout_5.addWidget(self.label_3, 4, 0, 1, 1) self.lineEdit_3 = QLineEdit(self.plot_strength_page) self.lineEdit_3.setObjectName(u"lineEdit_3") self.gridLayout_5.addWidget(self.lineEdit_3, 4, 1, 1, 2) self.stacked_widget.addWidget(self.plot_strength_page) self.plot_history_page = QWidget() self.plot_history_page.setObjectName(u"plot_history_page") self.gridLayout_6 = QGridLayout(self.plot_history_page) self.gridLayout_6.setObjectName(u"gridLayout_6") self.label_4 = QLabel(self.plot_history_page) self.label_4.setObjectName(u"label_4") self.gridLayout_6.addWidget(self.label_4, 0, 0, 1, 1) self.history_game = QComboBox(self.plot_history_page) self.history_game.setObjectName(u"history_game") self.gridLayout_6.addWidget(self.history_game, 0, 1, 1, 1) self.gridLayout_6.setColumnStretch(0, 1) self.gridLayout_6.setColumnStretch(1, 8) self.stacked_widget.addWidget(self.plot_history_page) self.verticalLayout_2.addWidget(self.stacked_widget) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") self.menubar.setGeometry(QRect(0, 0, 911, 22)) self.menu_file = QMenu(self.menubar) self.menu_file.setObjectName(u"menu_file") self.menu_new = QMenu(self.menu_file) self.menu_new.setObjectName(u"menu_new") self.menu_view = QMenu(self.menubar) self.menu_view.setObjectName(u"menu_view") self.menu_help = QMenu(self.menubar) self.menu_help.setObjectName(u"menu_help") self.menu_rules = QMenu(self.menu_help) self.menu_rules.setObjectName(u"menu_rules") MainWindow.setMenuBar(self.menubar) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName(u"statusbar") MainWindow.setStatusBar(self.statusbar) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_view.menuAction()) self.menubar.addAction(self.menu_help.menuAction()) self.menu_file.addAction(self.menu_new.menuAction()) self.menu_file.addAction(self.action_open) self.menu_file.addAction(self.action_save) self.menu_file.addAction(self.action_save_log) self.menu_file.addAction(self.action_new_db) self.menu_file.addAction(self.action_open_db) self.menu_new.addAction(self.action_game) self.menu_new.addAction(self.action_comparison) self.menu_new.addAction(self.action_plot) self.menu_new.addAction(self.action_training_session) self.menu_view.addAction(self.action_coordinates) self.menu_help.addAction(self.action_about) self.menu_help.addAction(self.menu_rules.menuAction()) self.retranslateUi(MainWindow) self.stacked_widget.setCurrentIndex(2) QMetaObject.connectSlotsByName(MainWindow) # setupUi def retranslateUi(self, MainWindow): MainWindow.setWindowTitle( QCoreApplication.translate("MainWindow", u"MainWindow", None)) self.action_open.setText( QCoreApplication.translate("MainWindow", u"&Open...", None)) self.action_comparison.setText( QCoreApplication.translate("MainWindow", u"&Comparison", None)) self.action_plot.setText( QCoreApplication.translate("MainWindow", u"&Plot", None)) self.action_training_session.setText( QCoreApplication.translate("MainWindow", u"&Training Session", None)) self.action_game.setText( QCoreApplication.translate("MainWindow", u"&Game", None)) self.action_save.setText( QCoreApplication.translate("MainWindow", u"&Save...", None)) self.action_save_log.setText( QCoreApplication.translate("MainWindow", u"Save &Log...", None)) self.action_coordinates.setText( QCoreApplication.translate("MainWindow", u"Coordinates", None)) self.action_about.setText( QCoreApplication.translate("MainWindow", u"&About...", None)) self.action_new_db.setText( QCoreApplication.translate("MainWindow", u"New Player &Database...", None)) self.action_open_db.setText( QCoreApplication.translate("MainWindow", u"&Open Player Database...", None)) self.connect4.setText( QCoreApplication.translate("MainWindow", u"Connect 4", None)) self.tic_tac_toe.setText( QCoreApplication.translate("MainWindow", u"Tic Tac Toe", None)) self.othello.setText( QCoreApplication.translate("MainWindow", u"Othello", None)) self.searches_lock2.setText( QCoreApplication.translate("MainWindow", u"Lock", None)) self.cancel.setText( QCoreApplication.translate("MainWindow", u"Cancel", None)) self.searches_label1.setText( QCoreApplication.translate("MainWindow", u"searches", None)) self.searches_lock1.setText( QCoreApplication.translate("MainWindow", u"Lock", None)) self.game_label.setText( QCoreApplication.translate("MainWindow", u"Game:", None)) self.game_name.setText( QCoreApplication.translate("MainWindow", u"Chosen Game's Name", None)) self.searches_label2.setText( QCoreApplication.translate("MainWindow", u"searches", None)) self.player_label1.setText( QCoreApplication.translate("MainWindow", u"Player 1:", None)) self.player_label2.setText( QCoreApplication.translate("MainWindow", u"Player 2:", None)) self.shuffle_players.setText( QCoreApplication.translate("MainWindow", u"Shuffle Player Order", None)) self.start.setText( QCoreApplication.translate("MainWindow", u"Start", None)) self.close_humans.setText( QCoreApplication.translate("MainWindow", u"OK", None)) self.players_label.setText( QCoreApplication.translate("MainWindow", u"Players", None)) self.new_human.setText( QCoreApplication.translate("MainWindow", u"New", None)) self.rules_close.setText( QCoreApplication.translate("MainWindow", u"Close", None)) self.toggle_review.setText( QCoreApplication.translate("MainWindow", u"Review / Resume", None)) self.resume_here.setText( QCoreApplication.translate("MainWindow", u"Resume Here", None)) self.game_display.setText( QCoreApplication.translate("MainWindow", u"Game Display", None)) self.label.setText( QCoreApplication.translate("MainWindow", u"Game:", None)) #if QT_CONFIG(whatsthis) self.lineEdit.setWhatsThis("") #endif // QT_CONFIG(whatsthis) self.label_2.setText( QCoreApplication.translate("MainWindow", u"Opponent min:", None)) self.reset_plot.setText( QCoreApplication.translate("MainWindow", u"Reset", None)) self.start_stop_plot.setText( QCoreApplication.translate("MainWindow", u"Start / Stop", None)) self.strengths_label.setText( QCoreApplication.translate("MainWindow", u"Player Strengths:", None)) self.label_3.setText( QCoreApplication.translate("MainWindow", u"Opponent max:", None)) self.label_4.setText( QCoreApplication.translate("MainWindow", u"Game:", None)) self.menu_file.setTitle( QCoreApplication.translate("MainWindow", u"&File", None)) self.menu_new.setTitle( QCoreApplication.translate("MainWindow", u"&New", None)) self.menu_view.setTitle( QCoreApplication.translate("MainWindow", u"&View", None)) self.menu_help.setTitle( QCoreApplication.translate("MainWindow", u"&Help", None)) self.menu_rules.setTitle( QCoreApplication.translate("MainWindow", u"&Rules", None))
def __init__(self): QMainWindow.__init__(self) # Variaveis self.separador = ";" # Separador padrao de colunas em um arquivo txt ou csv self.selected = np.array([1, 24, 48, 96]).astype('timedelta64[h]') # selecionados ao iniciar o programa, modificavel. self.fileformat = '' # Reservado para o formato do arquivo a ser aberto. Pode ser .xlsx ou .odf. ou .csv e assim vai. # facilita o acesso a variavel. self.timedeltastr = ("1 Hora","2 Horas", "3 Horas", "4 Horas","12 Horas", "24 Horas", "48 Horas", "72 horas", "96 horas", "30 Dias") self.timedeltas = np.array([1, 2, 3, 4, 12, 24, 48, 72, 96, 24*30]).astype('timedelta64[h]') self.linktimedelta = dict([(self.timedeltas[x], self.timedeltastr[x]) for x in range(len(self.timedeltastr))]) self.datastring = ["DD/MM/AAAA",'AAAA/MM/DD', "AAAA-MM-DD", "DD-MM-AAAA"] self.dataformat = ["%d/%m/%Y", "%Y/%m/%d", "%Y-%m-%d", "%d-%m-%Y"] self.linkdata = dict([(self.datastring[x], self.dataformat[x]) for x in range(len(self.dataformat))]) self.timestring = ["hh:mm", "hh:mm:ss", "hh:mm:ss.ms"] self.timeformat = ["%H:%M", "%H:%M:%S", "%H:%M:%S.%f"] self.linktime = dict([(self.timestring[x], self.timeformat[x]) for x in range(len(self.timeformat))]) #Janela Principal widget = QWidget() self.setCentralWidget(widget) # Inicializa os Widgets self.folder = QLineEdit("Salvar Como...") self.path = QLineEdit("Abrir arquivo...") # buttonOpen = QPushButton('Abrir') buttonSave = QPushButton("Destino") Processar = QPushButton('Executar') Ajuda = QPushButton('Informações') # groupBox2 = QGroupBox("Delimitador") self.delimitador1 = QRadioButton("Ponto-Vírgula") self.delimitador2 = QRadioButton("Vírgula") self.delimitador3 = QRadioButton("Ponto") self.delimitador4 = QRadioButton("Tabulação") # checkGroup = QGroupBox("Mais opções") text3 = QPushButton("Configurações") text2 = QLabel("Formato da Data") text1 = QLabel("Formato da Hora") self.FormatoTime = QComboBox() self.FormatoTime.addItems(self.timestring) self.FormatoData = QComboBox() self.FormatoData.addItems(self.datastring) # text = QLabel("Por favor, selecione na tabela abaixo as colunas a utilizar:") self.ignore = QRadioButton("Possui Cabeçalho") # True se estiver selecionado, False caso nao # self.Tabela = QTableWidget(15,15) self.startTable() # Layouts MainLayout = QVBoxLayout() Gridlayout = QGridLayout() Gridlayout.addWidget(self.path, 0, 0) Gridlayout.addWidget(self.folder, 1, 0) Gridlayout.addWidget(buttonOpen, 0, 1) Gridlayout.addWidget(buttonSave, 1, 1) Gridlayout.addWidget(Processar, 0, 3) Gridlayout.addWidget(Ajuda, 1, 3) Gridlayout.setColumnStretch(0, 2) Gridlayout.setColumnStretch(3, 1) Gridlayout.setColumnMinimumWidth(2, 20) SecondLayout = QHBoxLayout() SecondLayout.addWidget(groupBox2) SecondLayout.addSpacing(40) SecondLayout.addWidget(checkGroup) # SepLayout = QVBoxLayout() SepLayout.addWidget(self.delimitador1) SepLayout.addWidget(self.delimitador2) SepLayout.addWidget(self.delimitador3) SepLayout.addWidget(self.delimitador4) # OptionsLayout = QVBoxLayout() OptionsLayout.addWidget(text3) OptionsLayout.addWidget(text2) OptionsLayout.addWidget(self.FormatoData) OptionsLayout.addWidget(text1) OptionsLayout.addWidget(self.FormatoTime) ThirdLayout = QVBoxLayout() ThirdLayout.addWidget(self.ignore) ThirdLayout.addWidget(text) MainLayout.addLayout(Gridlayout) MainLayout.addLayout(SecondLayout) MainLayout.addLayout(ThirdLayout) MainLayout.addWidget(self.Tabela) # Coloca o Layout principal na Janela widget.setLayout(MainLayout) # Comandos dos Widgets e edicoes. groupBox2.setLayout(SepLayout) self.delimitador1.setChecked(True) self.folder.setReadOnly(True) self.path.setReadOnly(True) checkGroup.setLayout(OptionsLayout) buttonOpen.clicked.connect(self.searchFile) buttonSave.clicked.connect(self.getNewFile) self.delimitador1.clicked.connect(self.updateDelimiter) self.delimitador2.clicked.connect(self.updateDelimiter) self.delimitador3.clicked.connect(self.updateDelimiter) self.delimitador4.clicked.connect(self.updateDelimiter) Ajuda.clicked.connect(self.help) Processar.clicked.connect(self.taskStart) text3.clicked.connect(self.openSubWindow) # Propriedades da janela principal height = 480 width = 640 myappid = 'GePlu.release1_0.0' # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) self.setWindowIcon(QIcon(r'images\icon6.ico')) self.setFixedSize(width, height) self.setWindowTitle("GePlu")
def __init__(self): super(Window, self).__init__() self.renderArea = RenderArea() self.shapeComboBox = QComboBox() self.shapeComboBox.addItem("Polygon", RenderArea.Polygon) self.shapeComboBox.addItem("Rectangle", RenderArea.Rect) self.shapeComboBox.addItem("Rounded Rectangle", RenderArea.RoundedRect) self.shapeComboBox.addItem("Ellipse", RenderArea.Ellipse) self.shapeComboBox.addItem("Pie", RenderArea.Pie) self.shapeComboBox.addItem("Chord", RenderArea.Chord) self.shapeComboBox.addItem("Path", RenderArea.Path) self.shapeComboBox.addItem("Line", RenderArea.Line) self.shapeComboBox.addItem("Polyline", RenderArea.Polyline) self.shapeComboBox.addItem("Arc", RenderArea.Arc) self.shapeComboBox.addItem("Points", RenderArea.Points) self.shapeComboBox.addItem("Text", RenderArea.Text) self.shapeComboBox.addItem("Pixmap", RenderArea.Pixmap) shapeLabel = QLabel("&Shape:") shapeLabel.setBuddy(self.shapeComboBox) self.penWidthSpinBox = QSpinBox() self.penWidthSpinBox.setRange(0, 20) self.penWidthSpinBox.setSpecialValueText("0 (cosmetic pen)") penWidthLabel = QLabel("Pen &Width:") penWidthLabel.setBuddy(self.penWidthSpinBox) self.penStyleComboBox = QComboBox() self.penStyleComboBox.addItem("Solid", Qt.SolidLine) self.penStyleComboBox.addItem("Dash", Qt.DashLine) self.penStyleComboBox.addItem("Dot", Qt.DotLine) self.penStyleComboBox.addItem("Dash Dot", Qt.DashDotLine) self.penStyleComboBox.addItem("Dash Dot Dot", Qt.DashDotDotLine) self.penStyleComboBox.addItem("None", Qt.NoPen) penStyleLabel = QLabel("&Pen Style:") penStyleLabel.setBuddy(self.penStyleComboBox) self.penCapComboBox = QComboBox() self.penCapComboBox.addItem("Flat", Qt.FlatCap) self.penCapComboBox.addItem("Square", Qt.SquareCap) self.penCapComboBox.addItem("Round", Qt.RoundCap) penCapLabel = QLabel("Pen &Cap:") penCapLabel.setBuddy(self.penCapComboBox) self.penJoinComboBox = QComboBox() self.penJoinComboBox.addItem("Miter", Qt.MiterJoin) self.penJoinComboBox.addItem("Bevel", Qt.BevelJoin) self.penJoinComboBox.addItem("Round", Qt.RoundJoin) penJoinLabel = QLabel("Pen &Join:") penJoinLabel.setBuddy(self.penJoinComboBox) self.brushStyleComboBox = QComboBox() self.brushStyleComboBox.addItem("Linear Gradient", Qt.LinearGradientPattern) self.brushStyleComboBox.addItem("Radial Gradient", Qt.RadialGradientPattern) self.brushStyleComboBox.addItem("Conical Gradient", Qt.ConicalGradientPattern) self.brushStyleComboBox.addItem("Texture", Qt.TexturePattern) self.brushStyleComboBox.addItem("Solid", Qt.SolidPattern) self.brushStyleComboBox.addItem("Horizontal", Qt.HorPattern) self.brushStyleComboBox.addItem("Vertical", Qt.VerPattern) self.brushStyleComboBox.addItem("Cross", Qt.CrossPattern) self.brushStyleComboBox.addItem("Backward Diagonal", Qt.BDiagPattern) self.brushStyleComboBox.addItem("Forward Diagonal", Qt.FDiagPattern) self.brushStyleComboBox.addItem("Diagonal Cross", Qt.DiagCrossPattern) self.brushStyleComboBox.addItem("Dense 1", Qt.Dense1Pattern) self.brushStyleComboBox.addItem("Dense 2", Qt.Dense2Pattern) self.brushStyleComboBox.addItem("Dense 3", Qt.Dense3Pattern) self.brushStyleComboBox.addItem("Dense 4", Qt.Dense4Pattern) self.brushStyleComboBox.addItem("Dense 5", Qt.Dense5Pattern) self.brushStyleComboBox.addItem("Dense 6", Qt.Dense6Pattern) self.brushStyleComboBox.addItem("Dense 7", Qt.Dense7Pattern) self.brushStyleComboBox.addItem("None", Qt.NoBrush) brushStyleLabel = QLabel("&Brush Style:") brushStyleLabel.setBuddy(self.brushStyleComboBox) otherOptionsLabel = QLabel("Other Options:") self.antialiasingCheckBox = QCheckBox("&Antialiasing") self.transformationsCheckBox = QCheckBox("&Transformations") self.shapeComboBox.activated.connect(self.shapeChanged) self.penWidthSpinBox.valueChanged.connect(self.penChanged) self.penStyleComboBox.activated.connect(self.penChanged) self.penCapComboBox.activated.connect(self.penChanged) self.penJoinComboBox.activated.connect(self.penChanged) self.brushStyleComboBox.activated.connect(self.brushChanged) self.antialiasingCheckBox.toggled.connect( self.renderArea.setAntialiased) self.transformationsCheckBox.toggled.connect( self.renderArea.setTransformed) mainLayout = QGridLayout() mainLayout.setColumnStretch(0, 1) mainLayout.setColumnStretch(3, 1) mainLayout.addWidget(self.renderArea, 0, 0, 1, 4) mainLayout.setRowMinimumHeight(1, 6) mainLayout.addWidget(shapeLabel, 2, 1, Qt.AlignRight) mainLayout.addWidget(self.shapeComboBox, 2, 2) mainLayout.addWidget(penWidthLabel, 3, 1, Qt.AlignRight) mainLayout.addWidget(self.penWidthSpinBox, 3, 2) mainLayout.addWidget(penStyleLabel, 4, 1, Qt.AlignRight) mainLayout.addWidget(self.penStyleComboBox, 4, 2) mainLayout.addWidget(penCapLabel, 5, 1, Qt.AlignRight) mainLayout.addWidget(self.penCapComboBox, 5, 2) mainLayout.addWidget(penJoinLabel, 6, 1, Qt.AlignRight) mainLayout.addWidget(self.penJoinComboBox, 6, 2) mainLayout.addWidget(brushStyleLabel, 7, 1, Qt.AlignRight) mainLayout.addWidget(self.brushStyleComboBox, 7, 2) mainLayout.setRowMinimumHeight(8, 6) mainLayout.addWidget(otherOptionsLabel, 9, 1, Qt.AlignRight) mainLayout.addWidget(self.antialiasingCheckBox, 9, 2) mainLayout.addWidget(self.transformationsCheckBox, 10, 2) self.setLayout(mainLayout) self.shapeChanged() self.penChanged() self.brushChanged() self.antialiasingCheckBox.setChecked(True) self.setWindowTitle("Basic Drawing")
def createMessageGroupBox(self): self.messageGroupBox = QGroupBox("Balloon Message") self.typeLabel = QLabel("Type:") self.typeComboBox = QComboBox() self.typeComboBox.addItem("None", QSystemTrayIcon.NoIcon) self.typeComboBox.addItem( self.style().standardIcon(QStyle.SP_MessageBoxInformation), "Information", QSystemTrayIcon.Information, ) self.typeComboBox.addItem( self.style().standardIcon(QStyle.SP_MessageBoxWarning), "Warning", QSystemTrayIcon.Warning, ) self.typeComboBox.addItem( self.style().standardIcon(QStyle.SP_MessageBoxCritical), "Critical", QSystemTrayIcon.Critical, ) self.typeComboBox.addItem(QIcon(), "Custom icon", -1) self.typeComboBox.setCurrentIndex(1) self.durationLabel = QLabel("Duration:") self.durationSpinBox = QSpinBox() self.durationSpinBox.setRange(5, 60) self.durationSpinBox.setSuffix(" s") self.durationSpinBox.setValue(15) self.durationWarningLabel = QLabel( "(some systems might ignore this hint)") self.durationWarningLabel.setIndent(10) self.titleLabel = QLabel("Title:") self.titleEdit = QLineEdit("Cannot connect to network") self.bodyLabel = QLabel("Body:") self.bodyEdit = QTextEdit() self.bodyEdit.setPlainText( "Don't believe me. Honestly, I don't have a clue." "\nClick this balloon for details.") self.showMessageButton = QPushButton("Show Message") self.showMessageButton.setDefault(True) messageLayout = QGridLayout() messageLayout.addWidget(self.typeLabel, 0, 0) messageLayout.addWidget(self.typeComboBox, 0, 1, 1, 2) messageLayout.addWidget(self.durationLabel, 1, 0) messageLayout.addWidget(self.durationSpinBox, 1, 1) messageLayout.addWidget(self.durationWarningLabel, 1, 2, 1, 3) messageLayout.addWidget(self.titleLabel, 2, 0) messageLayout.addWidget(self.titleEdit, 2, 1, 1, 4) messageLayout.addWidget(self.bodyLabel, 3, 0) messageLayout.addWidget(self.bodyEdit, 3, 1, 2, 4) messageLayout.addWidget(self.showMessageButton, 5, 4) messageLayout.setColumnStretch(3, 1) messageLayout.setRowStretch(4, 1) self.messageGroupBox.setLayout(messageLayout)
class SettingWidget(QWidget): settings_changed_signal = QtCore.Signal() def __init__(self, parent, settings=None, **kwargs): super().__init__(parent, **kwargs) self.setObjectName("settings_widget") self.group_box = QGroupBox("Настройки") self.layout = QGridLayout() self.layout.setObjectName('settings_layout') self.layout.setColumnStretch(0, 6) self.layout.setColumnStretch(1, 1) self.group_box.setLayout(self.layout) self.widgets = [] self.change_settings(settings) def change_settings(self, settings): # First clean up all previous items for i in range(self.layout.count()): self.layout.removeItem(self.layout.takeAt(0)) for w in self.widgets: w.deleteLater() self.widgets = [] if not settings: label = QLabel(self.parentWidget()) label.setObjectName("settings_empty_label") label.setText("Для данной операции настройки отсутствуют") label.setWordWrap(True) self.widgets.append(label) self.layout.addWidget(label, 0, 0) else: x = 0 for s in settings: if isinstance(s.type, range): label = QLabel(self.parentWidget()) label.setText(s.text) label.setWordWrap(True) self.widgets.append(label) self.layout.addWidget(label, x, 0) slider = QSlider(self.parentWidget()) slider.setOrientation(Qt.Horizontal) slider.setMinimum(s.type.start // s.type.step) slider.setMaximum(s.type.stop // s.type.step - 1) slider.setValue(s.value // s.type.step) self.layout.addWidget(slider, x + 1, 0) line_edit = QLineEdit(self.parentWidget()) line_edit.setText(str(s.value)) self.layout.addWidget(line_edit, x + 1, 1) slider.valueChanged.connect( partial(self.slider_change, line_edit, s)) line_edit.returnPressed.connect( partial(self.line_edit_change, slider, line_edit, s)) self.widgets.append(slider) self.widgets.append(line_edit) x += 2 elif s.type == bool: checkbox = QCheckBox(self.parentWidget()) checkbox.setText('\n'.join(wrap(s.text, 40))) checkbox.setChecked(s.value) checkbox.clicked.connect( partial(self.checkbox_changed, checkbox, s)) self.layout.addWidget(checkbox, x, 0) self.widgets.append(checkbox) x += 1 elif s.type in (int, float, str): pass def slider_change(self, line_edit: QLineEdit, settings_item, value): value *= settings_item.type.step if settings_item.value != value: line_edit.setText(str(value)) settings_item.value = value self.settings_changed_signal.emit() def line_edit_change(self, slider: QSlider, line_edit: QLineEdit, settings_item): value = line_edit.text() try: if settings_item.type == int or isinstance(settings_item.type, range): value = int(value) elif settings_item.type == float: value = float(value) if isinstance(settings_item.type, range) and value not in settings_item.type: raise ValueError except ValueError: line_edit.setText(str(settings_item.value)) return if settings_item.value != value: settings_item.value = value if slider is not None: slider.setValue(value // settings_item.type.step) self.settings_changed_signal.emit() def checkbox_changed(self, checkbox: QCheckBox, settings_item): if settings_item.value != checkbox.isChecked(): settings_item.value = checkbox.isChecked() self.settings_changed_signal.emit()
class MainWindow(QMainWindow): def __init__(self, stages: list[Stage], *args, **kwargs): QMainWindow.__init__(self, *args, **kwargs) if not self.objectName(): self.setObjectName("MainWindow") self.resize(800, 600) size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setWindowTitle("Interfan") self.central_widget = QWidget(self) self.central_widget.setObjectName("central_widget") self.main_horizontal_layout = QHBoxLayout(self.central_widget) self.main_horizontal_layout.setObjectName("main_horizontal_layout") self.left_grid_layout = QGridLayout() self.left_grid_layout.setObjectName("left_grid_layout") self.slice_slider = QSlider(self.central_widget) self.slice_slider.setObjectName("slice_slider") self.slice_slider.setEnabled(False) self.slice_slider.setOrientation(Qt.Horizontal) self.left_grid_layout.addWidget(self.slice_slider, 1, 0, 1, 1) self.slice_label = QLabel(self.central_widget) self.slice_label.setObjectName("slice_label") self.slice_label.setGeometry(QRect(0, 10, 58, 18)) self.slice_label.setText("0") self.left_grid_layout.addWidget(self.slice_label, 1, 1, 1, 1) self.main_image_scene = QGraphicsScene() self.main_image_view = QGraphicsView(self.main_image_scene) self.main_image_view.setObjectName("main_image_view") self.left_grid_layout.addWidget(self.main_image_view, 0, 0, 1, 1) self.slice_image_scene = QGraphicsScene() self.slice_image_view = QGraphicsView(self.slice_image_scene) self.slice_image_view.setObjectName("slice_image_view") self.left_grid_layout.addWidget(self.slice_image_view, 0, 1, 1, 1) self.left_grid_layout.setRowStretch(0, 12) self.left_grid_layout.setRowStretch(1, 1) self.left_grid_layout.setColumnStretch(0, 6) self.left_grid_layout.setColumnStretch(1, 1) self.main_horizontal_layout.addLayout(self.left_grid_layout) self.right_vertical_layout = QVBoxLayout() self.right_vertical_layout.setObjectName("right_vertical_layout") self.settings_widget = SettingWidget(self.central_widget) self.right_vertical_layout.addWidget(self.settings_widget.group_box) self.proceed_button = QPushButton(self.central_widget) self.proceed_button.setObjectName("proceed_button") self.proceed_button.setText("Выполнить") self.proceed_button.setEnabled(False) self.right_vertical_layout.addWidget(self.proceed_button) self.right_down_layout = QHBoxLayout() self.right_down_layout.setObjectName("right_down_layout") self.stages_layout = QVBoxLayout() self.stages_layout.setObjectName("stages_layout") self.stages_label = QLabel(self.central_widget) self.stages_label.setObjectName("stages_label") self.stages_label.setText("Этапы") self.stages_layout.addWidget(self.stages_label, 1) self.stages_radio_buttons = [] for s in stages: rb = QRadioButton(self.central_widget) rb.setObjectName("stages_radio_button") rb.setEnabled(False) rb.setText(s.name) self.stages_layout.addWidget(rb, 1) self.stages_radio_buttons.append(rb) self.stages_radio_buttons[0].setEnabled(True) self.stages_radio_buttons[0].setChecked(True) self.set_stage(stages[0]) self.right_down_layout.addLayout(self.stages_layout) self.history_layout = QVBoxLayout() self.history_layout.setObjectName("history_layout") self.history_header_layout = QHBoxLayout() self.history_header_layout.setObjectName("history_header_layout") self.history_label = QLabel(self.central_widget) self.history_label.setObjectName("history_label") self.history_label.setText("История операций") self.history_header_layout.addWidget(self.history_label) self.history_minus_button = QToolButton(self.central_widget) self.history_minus_button.setObjectName("history_minus_button") self.history_minus_button.setEnabled(False) self.history_minus_button.setText("-") self.history_header_layout.addWidget(self.history_minus_button) self.history_header_layout.setStretch(0, 8) self.history_header_layout.setStretch(1, 1) self.history_layout.addLayout(self.history_header_layout) self.history_list_view = QListView(self.central_widget) self.history_list_view.setObjectName("history_list_view") self.history_layout.addWidget(self.history_list_view) self.history_script_button = QPushButton(self.central_widget) self.history_script_button.setObjectName("history_script_button") self.history_script_button.setText("Просмотреть как скрипт") self.history_layout.addWidget(self.history_script_button) self.right_down_layout.addLayout(self.history_layout) self.right_down_layout.setStretch(0, 1) self.right_down_layout.setStretch(1, 1) self.right_vertical_layout.addLayout(self.right_down_layout) self.right_vertical_layout.setStretch(0, 1) self.right_vertical_layout.setStretch(1, 0) self.right_vertical_layout.setStretch(2, 1) self.main_horizontal_layout.addLayout(self.right_vertical_layout) self.main_horizontal_layout.setStretch(0, 1) self.main_horizontal_layout.setStretch(1, 1) self.setCentralWidget(self.central_widget) self.menu_bar = QMenuBar(self) self.menu_bar.setObjectName("menu_bar") self.menu_bar.setGeometry(QRect(0, 0, 800, 30)) self.menu = QMenu(self.menu_bar) self.menu.setObjectName("men") self.menu.setTitle("Меню") self.setMenuBar(self.menu_bar) self.open_file = QAction(self) self.open_file.setObjectName("open_file") self.open_file.setText("Открыть файл") self.menu.addAction(self.open_file) self.status_bar = QStatusBar(self) self.status_bar.setObjectName("status_bar") self.setStatusBar(self.status_bar) self.menu_bar.addAction(self.menu.menuAction()) QMetaObject.connectSlotsByName(self) def set_stage(self, stage: Stage): self.settings_widget.change_settings(stage.settings)
class UITransferROIWindow: def setup_ui(self, transfer_roi_window_instance, signal_roi_transferred_to_fixed_container, signal_roi_transferred_to_moving_container): self.patient_dict_container = PatientDictContainer() self.moving_dict_container = MovingDictContainer() self.fixed_image_initial_rois = self.patient_dict_container.get("rois") self.moving_image_initial_rois = self.moving_dict_container.get("rois") self.transfer_roi_window_instance = transfer_roi_window_instance self.signal_roi_transferred_to_fixed_container = \ signal_roi_transferred_to_fixed_container self.signal_roi_transferred_to_moving_container = \ signal_roi_transferred_to_moving_container self.fixed_to_moving_rois = {} self.moving_to_fixed_rois = {} self.add_suffix = True self.progress_window = ProgressWindow( self, QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint) self.progress_window.setFixedSize(250, 100) self.progress_window.signal_loaded \ .connect(self.onTransferRoiFinished) self.progress_window.signal_error.connect(self.onTransferRoiError) self.init_layout() def retranslate_ui(self, transfer_roi_window_instance): _translate = QtCore.QCoreApplication.translate transfer_roi_window_instance.setWindowTitle( _translate("TransferRoiWindowInstance", "OnkoDICOM - Transfer Region of Interest")) self.add_suffix_checkbox.setText( _translate("AddSuffixCheckBox", "Add Suffix")) self.patient_A_label.setText( _translate("PatientAROILabel", "First Image Set ROIs")) self.patient_B_label.setText( _translate("PatientBROILabel", "Second Image Set ROIs")) self.transfer_all_rois_to_patient_B_button.setText( _translate("ROITransferToBButton", "All")) self.transfer_all_rois_to_patient_A_button.setText( _translate("ROITransferToAButton", "All")) self.save_button.setText(_translate("SaveButton", "Save")) self.reset_button.setText(_translate("ResetButton", "Reset")) def init_layout(self): """ Initialize the layout for the Transfer ROI Window. """ if platform.system() == 'Darwin': self.stylesheet_path = "res/stylesheet.qss" else: self.stylesheet_path = "res/stylesheet-win-linux.qss" stylesheet = open(resource_path(self.stylesheet_path)).read() window_icon = QIcon() window_icon.addPixmap(QPixmap(resource_path("res/images/icon.ico")), QIcon.Normal, QIcon.Off) self.transfer_roi_window_instance.setObjectName( "TransferRoiWindowInstance") self.transfer_roi_window_instance.setWindowIcon(window_icon) # Creating a grid layout to hold all elements self.transfer_roi_window_grid_layout = QGridLayout() self.transfer_roi_window_grid_layout.setColumnStretch(0, 1) self.transfer_roi_window_grid_layout.setColumnStretch(1, 1) self.transfer_roi_window_grid_layout.setColumnStretch(2, 1) self.init_patient_labels() self.init_transfer_arrow_buttons() self.init_patient_A_initial_roi_list() self.init_patient_B_rois_to_A_layout() self.init_patient_A_rois_to_B_layout() self.init_patient_B_initial_roi_list() self.init_add_suffix_checkbox() self.init_save_and_reset_button_layout() # Create a new central widget to hold the grid layout self.transfer_roi_window_instance_central_widget = QWidget() self.transfer_roi_window_instance_central_widget.setLayout( self.transfer_roi_window_grid_layout) self.retranslate_ui(self.transfer_roi_window_instance) self.transfer_roi_window_instance.setStyleSheet(stylesheet) self.transfer_roi_window_instance.setCentralWidget( self.transfer_roi_window_instance_central_widget) QtCore.QMetaObject.connectSlotsByName( self.transfer_roi_window_instance) def init_transfer_arrow_buttons(self): """ Initialize the layout for arrow buttons """ self.transfer_all_rois_to_patient_B_button = QPushButton() self.transfer_all_rois_to_patient_B_button.setObjectName( "ROITransferToBButton") transfer_all_rois_to_patient_B_icon = QtGui.QIcon() transfer_all_rois_to_patient_B_icon.addPixmap( QtGui.QPixmap( resource_path('res/images/btn-icons/forward_slide_icon.png')), QtGui.QIcon.Normal, QtGui.QIcon.On) self.transfer_all_rois_to_patient_B_button \ .setIcon(transfer_all_rois_to_patient_B_icon) self.transfer_all_rois_to_patient_B_button.clicked.connect( self.transfer_all_rois_to_patient_B_button_clicked) self.transfer_roi_window_grid_layout.addWidget( self.transfer_all_rois_to_patient_B_button, 1, 1) self.transfer_all_rois_to_patient_A_button = QPushButton() self.transfer_all_rois_to_patient_A_button.setObjectName( "ROITransferToAButton") self.transfer_all_rois_to_patient_A_button.setMaximumWidth(100) transfer_all_rois_to_patient_A_icon = QtGui.QIcon() transfer_all_rois_to_patient_A_icon.addPixmap( QtGui.QPixmap( resource_path('res/images/btn-icons/backward_slide_icon.png')), QtGui.QIcon.Normal, QtGui.QIcon.On) self.transfer_all_rois_to_patient_A_button \ .setIcon(transfer_all_rois_to_patient_A_icon) self.transfer_all_rois_to_patient_A_button.clicked.connect( self.transfer_all_rois_to_patient_A_button_clicked) self.transfer_roi_window_grid_layout.addWidget( self.transfer_all_rois_to_patient_A_button, 2, 1) def transfer_all_rois_to_patient_B_button_clicked(self): """ This function is triggered when the right arrow button is clicked. """ self.fixed_to_moving_rois.clear() self.patient_A_rois_to_B_list_widget.clear() for i in range(0, len(self.fixed_image_initial_rois)): self.patient_A_initial_roi_double_clicked( self.patient_A_initial_rois_list_widget.item(i)) def transfer_all_rois_to_patient_A_button_clicked(self): """ This function is triggered when the left arrow button is clicked. """ self.moving_to_fixed_rois.clear() self.patient_B_rois_to_A_list_widget.clear() for i in range(0, len(self.moving_image_initial_rois)): self.patient_B_initial_roi_double_clicked( self.patient_B_initial_rois_list_widget.item(i)) def init_add_suffix_checkbox(self): """ Initialize the layout for add suffix checkbox """ self.add_suffix_checkbox = QCheckBox() self.add_suffix_checkbox.setObjectName("AddSuffixCheckBox") self.add_suffix_checkbox.setChecked(self.add_suffix) self.add_suffix_checkbox.clicked.connect( self.add_suffix_checkbox_clicked) self.transfer_roi_window_grid_layout.addWidget( self.add_suffix_checkbox, 3, 0) def init_patient_labels(self): """ Initialize the layout for two patient labels """ self.patient_A_label = QLabel() self.patient_A_label.setObjectName("PatientAROILabel") self.patient_A_label.setMinimumHeight(50) self.patient_A_label.setAlignment(Qt.AlignCenter) self.patient_A_label.setStyleSheet( "QLabel { background-color : green; color : white; " "font-size: 15pt; font-weight: bold;}") self.patient_B_label = QLabel() self.patient_B_label.setObjectName("PatientBROILabel") self.patient_B_label.setMinimumHeight(50) self.patient_B_label.setAlignment(Qt.AlignCenter) self.patient_B_label.setStyleSheet( "QLabel { background-color : red; color : white; " "font-size: 15pt; font-weight: bold;}") self.transfer_roi_window_grid_layout.addWidget(self.patient_A_label, 0, 0) self.transfer_roi_window_grid_layout.addWidget(self.patient_B_label, 0, 2) def init_save_and_reset_button_layout(self): """ Initialize the layout for save and reset buttons """ self.reset_and_save_buttons_layout = QHBoxLayout() self.reset_button = QPushButton() self.reset_button.setObjectName("ResetButton") self.reset_button.clicked.connect(self.reset_clicked) self.save_button = QPushButton() self.save_button.setObjectName("SaveButton") self.save_button.setDisabled(True) self.save_button.clicked.connect(self.transfer_roi_clicked) self.reset_and_save_buttons_layout.setAlignment(Qt.AlignRight) self.reset_and_save_buttons_layout.addWidget(self.reset_button) self.reset_and_save_buttons_layout.addWidget(self.save_button) # Create a widget to hold Reset and Save buttons self.reset_and_save_button_central_widget = QWidget() self.reset_and_save_button_central_widget.setLayout( self.reset_and_save_buttons_layout) self.transfer_roi_window_grid_layout.addWidget( self.reset_and_save_button_central_widget, 3, 2) def add_suffix_checkbox_clicked(self): """ This function is triggered when the add suffix checkbox is clicked """ self.add_suffix = self.add_suffix_checkbox.isChecked() def init_patient_B_rois_to_A_layout(self): """ Initialize the layout for transfer rois from B to A container """ # Create scrolling area widget to contain the content. self.patient_B_rois_to_A_list_widget = QListWidget(self) self.transfer_roi_window_grid_layout \ .addWidget(self.patient_B_rois_to_A_list_widget, 2, 0) self.patient_B_rois_to_A_list_widget.itemDoubleClicked.connect( self.patient_B_to_A_rois_double_clicked) def init_patient_A_rois_to_B_layout(self): """ Initialize the layout for transfer rois from A to B container """ self.patient_A_rois_to_B_list_widget = QListWidget(self) self.transfer_roi_window_grid_layout \ .addWidget(self.patient_A_rois_to_B_list_widget, 1, 2) self.patient_A_rois_to_B_list_widget.itemDoubleClicked.connect( self.patient_A_to_B_rois_double_clicked) def init_patient_A_initial_roi_list(self): """ Initialize the layout for patient A's roi list """ self.patient_A_initial_rois_list_widget = QListWidget(self) self.patient_A_initial_rois_list_widget.itemDoubleClicked.connect( self.patient_A_initial_roi_double_clicked) for idx in self.fixed_image_initial_rois: roi_label = QListWidgetItem( self.fixed_image_initial_rois[idx]['name']) roi_label.setForeground(Qt.darkGreen) roi_label.setData(Qt.UserRole, self.fixed_image_initial_rois[idx]) self.patient_A_initial_rois_list_widget.addItem(roi_label) self.transfer_roi_window_grid_layout.addWidget( self.patient_A_initial_rois_list_widget, 1, 0) def init_patient_B_initial_roi_list(self): """ Initialize the layout for patient B's roi list """ self.patient_B_initial_rois_list_widget = QListWidget(self) self.patient_B_initial_rois_list_widget.itemDoubleClicked.connect( self.patient_B_initial_roi_double_clicked) for idx in self.moving_image_initial_rois: roi_label = QListWidgetItem( self.moving_image_initial_rois[idx]['name']) roi_label.setForeground(Qt.red) roi_label.setData(Qt.UserRole, self.moving_image_initial_rois[idx]) self.patient_B_initial_rois_list_widget.addItem(roi_label) self.transfer_roi_window_grid_layout.addWidget( self.patient_B_initial_rois_list_widget, 2, 2) def patient_A_to_B_rois_double_clicked(self, item): """ This function is triggered when a roi in "A to B" list is double-clicked. """ roi_to_remove = item.data(Qt.UserRole) to_delete_value = roi_to_remove['name'] self.fixed_to_moving_rois.pop(to_delete_value) self.patient_A_rois_to_B_list_widget.clear() for key, value in self.fixed_to_moving_rois.items(): roi_label = QListWidgetItem(value) roi_label.setForeground(Qt.red) roi_label.setData(Qt.UserRole, {'name': key}) self.patient_A_rois_to_B_list_widget.addItem(roi_label) if self.transfer_list_is_empty(): self.save_button.setDisabled(True) def patient_B_to_A_rois_double_clicked(self, item): """ This function is triggered when a roi in "B to A" list is double-clicked. """ roi_to_remove = item.data(Qt.UserRole) to_delete_value = roi_to_remove['name'] self.moving_to_fixed_rois.pop(to_delete_value) self.patient_B_rois_to_A_list_widget.clear() for key, value in self.moving_to_fixed_rois.items(): roi_label = QListWidgetItem(value) roi_label.setForeground(Qt.red) roi_label.setData(Qt.UserRole, {'name': key}) self.patient_B_rois_to_A_list_widget.addItem(roi_label) if self.transfer_list_is_empty(): self.save_button.setDisabled(True) def patient_A_initial_roi_double_clicked(self, item): """ This function is triggered when a roi in patient A's roi list is double-clicked. """ roi_to_add = item.data(Qt.UserRole) transferred_roi_name = roi_to_add['name'] # If the clicked roi is already transferred, return if transferred_roi_name in self.fixed_to_moving_rois.keys(): QMessageBox.about(self, "Transfer Failed", "Chosen ROI has already been transferred!") return # Create a set to store all current roi names in target patient # including both initial rois name and added roi names so far patient_B_initial_roi_name_list = set() for item in self.fixed_to_moving_rois.values(): patient_B_initial_roi_name_list.add(item) for idx in self.moving_image_initial_rois: patient_B_initial_roi_name_list.add( self.moving_image_initial_rois[idx]['name']) # Check if clicked roi name has duplicate # in patient B's initial roi names list if transferred_roi_name in patient_B_initial_roi_name_list: if self.add_suffix: transferred_roi_name = generate_non_duplicated_name( transferred_roi_name, patient_B_initial_roi_name_list) else: QMessageBox.about( self, "Transfer Failed", "Duplicated ROI name. " "Please consider adding suffix.") return # Add clicked roi to transferred list self.fixed_to_moving_rois[roi_to_add['name']] = transferred_roi_name roi_label = QListWidgetItem(transferred_roi_name) roi_label.setForeground(Qt.red) roi_label.setData(Qt.UserRole, roi_to_add) self.patient_A_rois_to_B_list_widget.addItem(roi_label) self.save_button.setDisabled(False) def patient_B_initial_roi_double_clicked(self, item): """ This function is triggered when a roi in patient B's roi list is double-clicked. """ roi_to_add = item.data(Qt.UserRole) transferred_roi_name = roi_to_add['name'] # If the clicked roi is already transferred, return if transferred_roi_name in self.moving_to_fixed_rois.keys(): QMessageBox.about(self, "Transfer Failed", "Chosen ROI has already been transferred!") return # Create a set to store all current roi names in target patient # including both initial rois name and added roi names so far patient_A_current_roi_name_list = set() for item in self.moving_to_fixed_rois.values(): patient_A_current_roi_name_list.add(item) for idx in self.fixed_image_initial_rois: patient_A_current_roi_name_list.add( self.fixed_image_initial_rois[idx]['name']) # Check if clicked roi name has duplicate in # target patient's roi names list if transferred_roi_name in patient_A_current_roi_name_list: # if add suffix is ticked, iteratively try adding suffix # from _A to _Z, stop when no duplicate found if self.add_suffix: transferred_roi_name = generate_non_duplicated_name( transferred_roi_name, patient_A_current_roi_name_list) else: QMessageBox.about( self, "Transfer Failed", "Duplicated ROI name. " "Please consider adding suffix.") return # Add clicked roi to transferred list self.moving_to_fixed_rois[roi_to_add['name']] = transferred_roi_name roi_label = QListWidgetItem(transferred_roi_name) roi_label.setForeground(Qt.red) roi_label.setData(Qt.UserRole, roi_to_add) self.patient_B_rois_to_A_list_widget.addItem(roi_label) self.save_button.setDisabled(False) def reset_clicked(self): """ This function is triggered when reset button is clicked. """ self.fixed_to_moving_rois.clear() self.moving_to_fixed_rois.clear() self.patient_A_rois_to_B_list_widget.clear() self.patient_B_rois_to_A_list_widget.clear() self.save_button.setDisabled(True) def transfer_list_is_empty(self): """ This function is to check if the transfer list is empty """ return len(self.fixed_to_moving_rois) == 0 \ and len(self.moving_to_fixed_rois) == 0 def save_clicked(self, interrupt_flag, progress_callback): """ This function is triggered when the save button is clicked. It contains all steps in the ROI transferring process. :param interrupt_flag: interrupt flag to stop process :param progress_callback: signal that receives the current progress of the loading. """ progress_callback.emit(("Converting images to sitk", 0)) # check if interrupt flag is set if not check_interrupt_flag(interrupt_flag): return False rtss = self.patient_dict_container.get("dataset_rtss") # get sitk for the fixed image dicom_image = read_dicom_image_to_sitk( self.patient_dict_container.filepaths) if not check_interrupt_flag(interrupt_flag): return False # get array of roi indexes from sitk images rois_images_fixed = transform_point_set_from_dicom_struct( dicom_image, rtss, self.fixed_to_moving_rois.keys(), spacing_override=None, interrupt_flag=interrupt_flag) moving_rtss = self.moving_dict_container.get("dataset_rtss") if not check_interrupt_flag(interrupt_flag): return False # get sitk for the moving image moving_dicom_image = read_dicom_image_to_sitk( self.moving_dict_container.filepaths) if not check_interrupt_flag(interrupt_flag): return False # get array of roi indexes from sitk images progress_callback \ .emit(("Retrieving ROIs from \nboth image sets", 20)) # check if interrupt flag is set if not check_interrupt_flag(interrupt_flag): return False if moving_rtss: rois_images_moving = transform_point_set_from_dicom_struct( moving_dicom_image, moving_rtss, self.moving_to_fixed_rois.keys(), spacing_override=None, interrupt_flag=interrupt_flag) else: rois_images_moving = ([], []) if not check_interrupt_flag(interrupt_flag): return False tfm = self.moving_dict_container.get("tfm") progress_callback.emit( ("Transfering ROIs from moving \nto fixed image set", 40)) # check if interrupt flag is set if not check_interrupt_flag(interrupt_flag): return False # transform roi from moving_dict to fixed_dict self.transfer_rois(self.moving_to_fixed_rois, tfm, dicom_image, rois_images_moving, self.patient_dict_container) progress_callback.emit( ("Transfering ROIs from fixed \nto moving image set", 60)) if not check_interrupt_flag(interrupt_flag): return False # transform roi from moving_dict to fixed_dict self.transfer_rois(self.fixed_to_moving_rois, tfm.GetInverse(), moving_dicom_image, rois_images_fixed, self.moving_dict_container) progress_callback.emit(("Saving ROIs to RTSS", 80)) # check if interrupt flag is set if not check_interrupt_flag(interrupt_flag): return False progress_callback.emit(("Reloading window", 90)) return True def transfer_roi_clicked(self): """ telling progress window to start ROI transfer """ self.progress_window.start(self.save_clicked) def onTransferRoiError(self, exception): """ This function is triggered when there is an error in the ROI transferring process. :param exception: exception thrown """ QMessageBox.about(self.progress_window, "Unable to transfer ROIs", "Please check your image set and ROI data.") self.progress_window.close() def onTransferRoiFinished(self, result): """ This function is triggered when ROI transferring process is finished. """ # emit changed dataset to structure_modified function and # auto_save_roi function if result[0] is True: if len(self.fixed_to_moving_rois) > 0: self.signal_roi_transferred_to_moving_container.emit( (self.moving_dict_container.get("dataset_rtss"), { "transfer": None })) if len(self.moving_to_fixed_rois) > 0: self.signal_roi_transferred_to_fixed_container.emit( (self.patient_dict_container.get("dataset_rtss"), { "transfer": None })) self.progress_window.close() QMessageBox.about(self.transfer_roi_window_instance, "Saved", "ROIs are successfully transferred!") else: QMessageBox.about(self.transfer_roi_window_instance, "Cancelled", "ROIs Transfer is cancelled.") self.closeWindow() def transfer_rois(self, transfer_dict, tfm, reference_image, original_roi_list, patient_dict_container): """ Converting (transferring) ROIs from one image set to another and save the transferred rois to rtss. :param transfer_dict: dictionary of rois to be transfer. key is original roi names, value is the name after transferred. :param original_roi_list: tuple of sitk rois from the base image. :param tfm: the tfm that contains information for transferring rois :param reference_image: the reference (base) image :param patient_dict_container: container of the transfer image set. """ for roi_name, new_roi_name in transfer_dict.items(): for index, name in enumerate(original_roi_list[1]): if name == roi_name: sitk_image = original_roi_list[0][index] new_contour = apply_linear_transform( input_image=sitk_image, transform=tfm, reference_image=reference_image, is_structure=True) contour = sitk.GetArrayViewFromImage(new_contour) contours = np.transpose(contour.nonzero()) self.save_roi_to_patient_dict_container( contours, new_roi_name, patient_dict_container) def save_roi_to_patient_dict_container(self, contours, roi_name, patient_dict_container): """ Save the transferred ROI to the corresponding rtss. :param contours: np array of coordinates of the ROI to be saved. :param roi_name: name of the ROI to be saved :param patient_dict_container: container of the transfer image set. """ pixels_coords_dict = {} slice_ids_dict = get_dict_slice_to_uid(patient_dict_container) total_slices = len(slice_ids_dict) for contour in contours: curr_slice_id = total_slices - contour[0] if curr_slice_id >= total_slices: curr_slice_id = 0 if curr_slice_id not in pixels_coords_dict: pixels_coords_dict[curr_slice_id] = [ tuple([contour[2], contour[1]]) ] else: pixels_coords_dict[curr_slice_id].append( tuple([contour[2], contour[1]])) rois_to_save = {} for key in pixels_coords_dict.keys(): coords = pixels_coords_dict[key] polygon_list = ROI.calculate_concave_hull_of_points(coords) if len(polygon_list) > 0: rois_to_save[key] = { 'ds': patient_dict_container.dataset[key], 'coords': polygon_list } roi_list = ROI.convert_hull_list_to_contours_data( rois_to_save, patient_dict_container) if len(roi_list) > 0: print("Saving ", roi_name) if isinstance(patient_dict_container, MovingDictContainer): new_rtss = ROI.create_roi( patient_dict_container.get("dataset_rtss"), roi_name, roi_list, rtss_owner="MOVING") self.moving_dict_container.set("dataset_rtss", new_rtss) self.moving_dict_container.set("rtss_modified", True) else: new_rtss = ROI.create_roi( patient_dict_container.get("dataset_rtss"), roi_name, roi_list) self.patient_dict_container.set("dataset_rtss", new_rtss) self.patient_dict_container.set("rtss_modified", True) def closeWindow(self): """ function to close transfer roi window """ self.close()
def __init__(self, db: SqlDB): super().__init__() self.setWidgetResizable(True) self.db = db self.icons = Icons() base = QWidget() base.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.setWidget(base) grid = QGridLayout() grid.setColumnStretch(0, 1) grid.setColumnStretch(1, 1) grid.setColumnStretch(2, 2) grid.setColumnStretch(3, 1) grid.setColumnStretch(4, 1) grid.setColumnStretch(5, 1) base.setLayout(grid) row = 0 # _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ # SUPPLIER Label supplier = QLabel('SUPPLIER') supplier.setStyleSheet( "QLabel {font-size:14pt; padding: 0 2px; background: #ddf;}") supplier.setFrameStyle(QFrame.StyledPanel | QFrame.Plain) grid.addWidget(supplier, row, 0, 1, 6) row += 1 # --------------------------------------------------------------------- # SUPPLIER NAME SHORT lab_name_supplier_short = QLabel('SHORT NAME') lab_name_supplier_short.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_name_supplier_short.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_name_supplier_short = QLineEdit() ent_name_supplier_short.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) but_name_supplier_short = QPushButton() but_name_supplier_short.setIcon(QIcon(self.icons.CHECK)) but_name_supplier_short.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) grid.addWidget(lab_name_supplier_short, row, 0) grid.addWidget(ent_name_supplier_short, row, 1) grid.addWidget(but_name_supplier_short, row, 5, 3, 1) row += 1 # --------------------------------------------------------------------- # SUPPLIER NAME FULL lab_name_supplier = QLabel('FULL NAME') lab_name_supplier.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_name_supplier.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_name_supplier = QLineEdit() ent_name_supplier.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) grid.addWidget(lab_name_supplier, row, 0) grid.addWidget(ent_name_supplier, row, 1, 1, 4) row += 1 # --------------------------------------------------------------------- # SUPPLIER NAME in local language lab_name_supplier_local = QLabel('Local NAME') lab_name_supplier_local.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_name_supplier_local.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_name_supplier_local = QLineEdit() ent_name_supplier_local.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) grid.addWidget(lab_name_supplier_local, row, 0) grid.addWidget(ent_name_supplier_local, row, 1, 1, 4) row += 1 # click on but_name_supplier_short but_name_supplier_short.clicked.connect( lambda: self.on_click_set_supplier(ent_name_supplier_short, ent_name_supplier, ent_name_supplier_local)) # _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ # PART Label part = QLabel('PART') part.setStyleSheet( "QLabel {font-size:14pt; padding: 0 2px; background: #ddf;}") part.setFrameStyle(QFrame.StyledPanel | QFrame.Plain) grid.addWidget(part, row, 0, 1, 6) row += 1 # --------------------------------------------------------------------- # PART NUMBER lab_num_part = QLabel('PART#') lab_num_part.setStyleSheet("QLabel {font-size:10pt; padding: 0 2px;}") lab_num_part.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_num_part = QLineEdit() ent_num_part.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) but_num_part = QPushButton() but_num_part.setIcon(QIcon(self.icons.CHECK)) but_num_part.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) grid.addWidget(lab_num_part, row, 0) grid.addWidget(ent_num_part, row, 1) grid.addWidget(but_num_part, row, 5, 5, 1) row += 1 # --------------------------------------------------------------------- # Original PART NUMBER lab_num_part_orig = QLabel('Orig. PART#') lab_num_part_orig.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;color: gray;}") lab_num_part_orig.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) combo_num_part_orig = QComboBox() combo_num_part_orig.setEnabled(False) combo_num_part_orig.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) check_num_part_orig = QCheckBox('use original drawing') check_num_part_orig.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) check_num_part_orig.stateChanged.connect( lambda: self.getPartsOptionCombo( lab_num_part_orig, combo_num_part_orig, check_num_part_orig)) grid.addWidget(lab_num_part_orig, row, 0) grid.addWidget(combo_num_part_orig, row, 1) grid.addWidget(check_num_part_orig, row, 2, 1, 3) row += 1 # --------------------------------------------------------------------- # PART Description lab_desc_part = QLabel('Description') lab_desc_part.setStyleSheet("QLabel {font-size:10pt; padding: 0 2px;}") lab_desc_part.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_desc_part = QLineEdit() ent_desc_part.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) grid.addWidget(lab_desc_part, row, 0) grid.addWidget(ent_desc_part, row, 1, 1, 4) row += 1 # --------------------------------------------------------------------- # PART Supplier lab_part_supplier = QLabel('Part Supplier') lab_part_supplier.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_part_supplier.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) combo_part_supplier = QComboBox() self.add_supplier_list_to_combo(combo_part_supplier) combo_part_supplier.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) grid.addWidget(lab_part_supplier, row, 0) grid.addWidget(combo_part_supplier, row, 1) row += 1 # --------------------------------------------------------------------- # Assy PART NUMBER lab_num_part_assy = QLabel('Assy PART#') lab_num_part_assy.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;color: gray;}") lab_num_part_assy.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) combo_num_part_assy = QComboBox() combo_num_part_assy.setEnabled(False) combo_num_part_assy.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) check_num_part_assy = QCheckBox('link to Assy') check_num_part_assy.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) #check_num_part_assy.stateChanged.connect( # lambda: self.getPartsOptionCombo( # lab_num_part_assy, # combo_num_part_assy, # check_num_part_assy # ) #) grid.addWidget(lab_num_part_assy, row, 0) grid.addWidget(combo_num_part_assy, row, 1) grid.addWidget(check_num_part_assy, row, 2, 1, 3) row += 1 # click on but_num_part but_num_part.clicked.connect(lambda: self.on_click_set_part( ent_num_part, combo_num_part_orig, check_num_part_orig, ent_desc_part, combo_part_supplier)) # _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ # Drawing Label drawing = QLabel('Drawing') drawing.setStyleSheet( "QLabel {font-size:14pt; padding: 0 2px; background: #ddf;}") drawing.setFrameStyle(QFrame.StyledPanel | QFrame.Plain) grid.addWidget(drawing, row, 0, 1, 6) row += 1 # --------------------------------------------------------------------- # PART Number lab_num_part_drawing = QLabel('Part#') lab_num_part_drawing.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_num_part_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) combo_num_part_drawing = QComboBox() combo_num_part_drawing.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) combo_num_part_drawing.setEnabled(False) self.getParts4Combo(combo_num_part_drawing) lab_num_supplier_drawing = QLabel() lab_num_supplier_drawing.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px; color:gray;}") lab_num_supplier_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) but_num_part_drawing = QPushButton() but_num_part_drawing.setIcon(QIcon(self.icons.CHECK)) but_num_part_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) grid.addWidget(lab_num_part_drawing, row, 0) grid.addWidget(combo_num_part_drawing, row, 1) grid.addWidget(lab_num_supplier_drawing, row, 2, 1, 3) grid.addWidget(but_num_part_drawing, row, 5, 4, 1) row += 1 # --------------------------------------------------------------------- # PART Drawing Description lab_num_desc_drawing = QLabel() lab_num_desc_drawing.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px; color:gray;}") lab_num_desc_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) grid.addWidget(lab_num_desc_drawing, row, 1, 1, 4) row += 1 self.part_selection_change(combo_num_part_drawing, lab_num_supplier_drawing, lab_num_desc_drawing) combo_num_part_drawing.currentIndexChanged.connect( lambda: self.part_selection_change(combo_num_part_drawing, lab_num_supplier_drawing, lab_num_desc_drawing)) # --------------------------------------------------------------------- # PART Drawing Revision lab_rev_drawing = QLabel('Revision') lab_rev_drawing.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_rev_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_rev_drawing = QLineEdit() ent_rev_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) grid.addWidget(lab_rev_drawing, row, 0) grid.addWidget(ent_rev_drawing, row, 1) row += 1 # --------------------------------------------------------------------- # PART Drawing file lab_file_drawing = QLabel('PDF file') lab_file_drawing.setStyleSheet( "QLabel {font-size:10pt; padding: 0 2px;}") lab_file_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) ent_file_drawing = QLineEdit() ent_file_drawing.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) but_file_drawing = QPushButton() but_file_drawing.setIcon(QIcon(self.icons.PDF)) but_file_drawing.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) grid.addWidget(lab_file_drawing, row, 0) grid.addWidget(ent_file_drawing, row, 1, 1, 3) grid.addWidget(but_file_drawing, row, 4) row += 1