Skip to content

Commit

Permalink
Refactor of ROIPropertiesTableWidget (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSullivan7 authored Feb 24, 2025
2 parents 51e83d2 + d85c5cd commit 65f8cf5
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 188 deletions.
2 changes: 1 addition & 1 deletion mantidimaging/gui/mvp_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX - License - Identifier: GPL-3.0-or-later
from __future__ import annotations

from .view import (BaseDialogView, BaseMainWindowView) # noqa: F401
from .view import (BaseDialogView, BaseMainWindowView, BaseWidget) # noqa: F401
from .presenter import BasePresenter # noqa: F401 # noqa:F821
11 changes: 10 additions & 1 deletion mantidimaging/gui/mvp_base/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from PyQt5 import QtCore
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QDialog, QApplication
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QDialog, QApplication, QWidget

from mantidimaging.gui.utility import compile_ui

Expand Down Expand Up @@ -83,3 +83,12 @@ def show_error_dialog(self, msg="") -> None:
:param msg: Error message string
"""
QMessageBox.critical(self, "Error", str(msg))


class BaseWidget(QWidget):

def __init__(self, parent, ui_file=None):
super().__init__(parent)

if ui_file is not None:
compile_ui(ui_file, self)
77 changes: 77 additions & 0 deletions mantidimaging/gui/ui/roi_properties_table_widget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ROIPropertiesTable</class>
<widget class="QWidget" name="ROIPropertiesTable">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>151</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="group_box">
<property name="title">
<string>ROI Properties</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="spin_left"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>y1, y2</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_1">
<property name="text">
<string>x1, x2</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="spin_right"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spin_top"/>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spin_bottom"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_width">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_height">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
45 changes: 7 additions & 38 deletions mantidimaging/gui/ui/spectrum_viewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -407,44 +407,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="roiPropertiesGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>200</height>
</size>
</property>
<property name="title">
<string>ROI Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QTableWidget" name="roiPropertiesTableWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>200</height>
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="ROIPropertiesTableWidget" name="roi_properties_widget" native="true"/>
</item>
<item>
<widget class="QWidget" name="experimentSetupGroupBox" native="true"/>
Expand Down Expand Up @@ -549,6 +512,12 @@
<extends>QTableView</extends>
<header>mantidimaging.gui.windows.spectrum_viewer.view</header>
</customwidget>
<customwidget>
<class>ROIPropertiesTableWidget</class>
<extends>QWidget</extends>
<header>mantidimaging.gui.windows.spectrum_viewer.view</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
4 changes: 2 additions & 2 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def handle_sample_change(self, uuid: UUID | None) -> None:
self.set_shuttercount_error()
self.show_new_sample()
self.view.on_visibility_change()
self.view.setup_roi_properties_spinboxes()

def reset_units_menu(self) -> None:
if self.model.tof_data is None:
Expand Down Expand Up @@ -185,8 +186,7 @@ def show_new_sample(self) -> None:
self.view.spectrum_widget.spectrum_plot_widget.add_range(*self.model.tof_plot_range)
self.view.spectrum_widget.spectrum_plot_widget.set_image_index_range_label(*self.model.tof_range)
self.view.auto_range_image()
if self.view.roi_properties_widget.roiPropertiesSpinBoxes:
self.view.set_roi_properties()
self.view.set_roi_properties()

def handle_range_slide_moved(self, tof_range: tuple[float, float] | tuple[int, int]) -> None:
self.model.tof_plot_range = tof_range
Expand Down
Loading

0 comments on commit 65f8cf5

Please sign in to comment.