diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index f82b70509..3eb169625 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -35,7 +35,7 @@ jobs: shell: bash steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 path: hexrdgui @@ -44,9 +44,13 @@ jobs: uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true - python-version: '3.10' + python-version: '3.11' auto-activate-base: false + - name: Install EGL on Linux (PySide6 needs it) + if: ${{ matrix.config.name == 'Linux' }} + run: sudo apt-get install -y libegl1-mesa-dev + - name: Get version using git describe working-directory: hexrdgui run: echo "HEXRDGUI_GIT_DESCRIBE=$(git describe --tag)" >> $GITHUB_ENV @@ -89,34 +93,34 @@ jobs: - name: Upload InstallOutput.log if: ${{ failure() }} - uses: actions/upload-artifact@v2-preview + uses: actions/upload-artifact@v3 with: name: InstallOutput.log path: ${{ github.workspace }}/hexrdgui/packaging/_CPack_Packages/*/InstallOutput.log - name: Upload WIX log ( Windows only ) if: ${{ failure() && matrix.config.os == 'windows-latest'}} - uses: actions/upload-artifact@v2-preview + uses: actions/upload-artifact@v3 with: name: wix.log path: ${{ github.workspace }}/hexrdgui/packaging/_CPack_Packages/WIX/wix.log - name: Upload installer package - uses: actions/upload-artifact@v2-preview + uses: actions/upload-artifact@v3 with: name: HEXRDGUI-v${{env.VERSION}}.${{ matrix.config.package }} path: ${{ github.workspace }}/hexrdgui/packaging/HEXRDGUI-${{env.VERSION}}.${{ matrix.config.package }} - name: Upload installer package Zip ( Windows only ) if: ${{ matrix.config.os == 'windows-latest'}} - uses: actions/upload-artifact@v2-preview + uses: actions/upload-artifact@v3 with: name: HEXRDGUI-v${{env.VERSION}}.zip path: ${{ github.workspace }}/hexrdgui/packaging/HEXRDGUI-${{env.VERSION}}.zip - name: Upload the HEXRDGUI conda package ( PRs only ) if: github.ref != 'refs/heads/master' - uses: actions/upload-artifact@v2-preview + uses: actions/upload-artifact@v3 with: name: HEXRDGUI-${{ matrix.config.name }}-${{ env.HEXRDGUI_GIT_DESCRIBE }}.tar.bz2 path: ${{ github.workspace }}/hexrdgui/packaging/output/**/*.tar.bz2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ace167e70..d897337d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: [3.9, '3.10'] + python-version: ['3.10', '3.11'] config: - { name: "Linux", @@ -39,25 +39,29 @@ jobs: python-version: ${{ matrix.python-version }} - name: Checkout HEXRD - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: HEXRD/hexrd path: hexrd - name: Checkout HEXRDGUI - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: path: hexrdgui - name: Checkout examples - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: HEXRD/examples path: examples + - name: Install EGL on Linux (PySide6 needs it) + if: ${{ matrix.config.name == 'Linux' }} + run: sudo apt-get install -y libegl1-mesa-dev + - name: Set environment variable to work around setuptools/numpy issue run: echo 'SETUPTOOLS_USE_DISTUTILS=stdlib' >> $GITHUB_ENV - if: ${{ matrix.config.os == 'windows-latest'}} + if: ${{ matrix.config.name == 'Windows' }} - name: Install HEXRD run: | diff --git a/conda.recipe/conda_build_config.yaml b/conda.recipe/conda_build_config.yaml new file mode 100644 index 000000000..4d978d7db --- /dev/null +++ b/conda.recipe/conda_build_config.yaml @@ -0,0 +1,7 @@ +python: + - 3.11 +target_platform: + - linux-64 # [linux] + - osx-64 # [osx] + - osx-arm64 # [osx] + - win-64 # [win] diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 8379d2f0e..b212d8d06 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -8,32 +8,34 @@ source: build: number: {{ environ.get('GIT_DESCRIBE_NUMBER', 0) }} entry_points: - - hexrdgui = hexrd.ui.main:main + - hexrdgui = hexrdgui.main:main requirements: build: - - python=3.10 + - python {{ python }} # [build_platform != target_platform] + - cross-python_{{ target_platform }} # [build_platform != target_platform] + host: + - python {{ python }} - setuptools - setuptools_scm run: - python - - pyside2>=5.15 - - Pillow - - matplotlib - - importlib_resources - fabio - - pyyaml - hexrd=={{ hexrd_version }} + - matplotlib-base + - Pillow - pyhdf - - silx + - pyside6 + - pyyaml + - silx-base -test: +test: # [build_platform == target_platform] imports: - - hexrd.ui + - hexrdgui about: home: https://github.com/HEXRD/hexrdgui license: BSD license_family: BSD - summary: "Qt5 PySide2 based HEXRD GUI" + summary: "Qt6 PySide6 based HEXRD GUI" diff --git a/hexrd/__init__.py b/hexrd/__init__.py deleted file mode 100644 index 69e3be50d..000000000 --- a/hexrd/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) diff --git a/hexrd/ui/__init__.py b/hexrdgui/__init__.py similarity index 92% rename from hexrd/ui/__init__.py rename to hexrdgui/__init__.py index fe3b4a4f8..85f709310 100644 --- a/hexrd/ui/__init__.py +++ b/hexrdgui/__init__.py @@ -1,5 +1,5 @@ -from PySide2.QtCore import QEvent, QObject, Qt -from PySide2.QtWidgets import QDialog, QPushButton +from PySide6.QtCore import QEvent, QObject, Qt +from PySide6.QtWidgets import QDialog, QPushButton class EnterKeyFilter(QObject): diff --git a/hexrd/ui/about_dialog.py b/hexrdgui/about_dialog.py similarity index 82% rename from hexrd/ui/about_dialog.py rename to hexrdgui/about_dialog.py index ab0db449f..1fd0ae72e 100644 --- a/hexrd/ui/about_dialog.py +++ b/hexrdgui/about_dialog.py @@ -1,15 +1,15 @@ from importlib.metadata import version import sys -from PySide2.QtCore import Qt, QObject, QSize -from PySide2.QtSvg import QSvgWidget -from PySide2.QtWidgets import QTreeWidgetItem, QLabel -from PySide2.QtGui import QPixmap +from PySide6.QtCore import Qt, QObject, QSize +from PySide6.QtSvgWidgets import QSvgWidget +from PySide6.QtWidgets import QTreeWidgetItem, QLabel +from PySide6.QtGui import QPixmap import hexrd -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.resource_loader import load_resource +from hexrdgui.ui_loader import UiLoader +from hexrdgui.resource_loader import load_resource LOGO_HEIGHT = 80 @@ -24,7 +24,7 @@ def __init__(self, parent=None): self._populate_versions() def _populate_hexrd_logo(self): - data = load_resource(hexrd.ui.resources.icons, + data = load_resource(hexrdgui.resources.icons, 'hexrd.ico', binary=True) pixmap = QPixmap() pixmap.loadFromData(data, 'ico') @@ -36,7 +36,7 @@ def _calculate_size(self, size): return QSize(LOGO_HEIGHT/ratio, LOGO_HEIGHT) def _populate_logos(self): - data = load_resource(hexrd.ui.resources.icons, 'llnl_logo.svg', + data = load_resource(hexrdgui.resources.icons, 'llnl_logo.svg', binary=True) self.ui.logos_horizontal_layout.addStretch() @@ -47,7 +47,7 @@ def _populate_logos(self): self.ui.logos_horizontal_layout.addWidget(llnl, stretch=1) self.ui.logos_horizontal_layout.addStretch() - data = load_resource(hexrd.ui.resources.icons, + data = load_resource(hexrdgui.resources.icons, 'kitware_logo.svg', binary=True) kitware = QSvgWidget() @@ -57,7 +57,7 @@ def _populate_logos(self): self.ui.logos_horizontal_layout.addWidget(kitware, stretch=1) self.ui.logos_horizontal_layout.addStretch() - data = load_resource(hexrd.ui.resources.icons, + data = load_resource(hexrdgui.resources.icons, 'afrl_logo.png', binary=True) pixmap = QPixmap() @@ -78,7 +78,7 @@ def _populate_versions(self): "HEXRD", "NumPy", "SciPy", - "PySide2" + "PySide6" ] for package in packages: diff --git a/hexrd/ui/argument_parser.py b/hexrdgui/argument_parser.py similarity index 100% rename from hexrd/ui/argument_parser.py rename to hexrdgui/argument_parser.py diff --git a/hexrd/ui/async_runner.py b/hexrdgui/async_runner.py similarity index 85% rename from hexrd/ui/async_runner.py rename to hexrdgui/async_runner.py index 41aded8e4..ff895cd3d 100644 --- a/hexrd/ui/async_runner.py +++ b/hexrdgui/async_runner.py @@ -1,8 +1,8 @@ -from PySide2.QtCore import QThreadPool, QTimer -from PySide2.QtWidgets import QMessageBox +from PySide6.QtCore import QThreadPool, QTimer +from PySide6.QtWidgets import QMessageBox -from hexrd.ui.async_worker import AsyncWorker -from hexrd.ui.progress_dialog import ProgressDialog +from hexrdgui.async_worker import AsyncWorker +from hexrdgui.progress_dialog import ProgressDialog class AsyncRunner: @@ -10,8 +10,6 @@ class AsyncRunner: def __init__(self, parent): self.parent = parent - self.thread_pool = QThreadPool(parent) - self.progress_dialog = ProgressDialog(parent) # Some defaults... @@ -41,7 +39,7 @@ def run(self, f, *args, **kwargs): # have a segmentation fault. self.thread_pool.start(worker) - self.progress_dialog.exec_() + self.progress_dialog.exec() def on_worker_finished(self): self.reset_callbacks() @@ -67,4 +65,8 @@ def on_async_error(self, t): msg = f'An ERROR occurred: {exctype}: {value}.' msg_box = QMessageBox(QMessageBox.Critical, 'Error', msg) msg_box.setDetailedText(traceback) - msg_box.exec_() + msg_box.exec() + + @property + def thread_pool(self): + return QThreadPool.globalInstance() diff --git a/hexrd/ui/async_worker.py b/hexrdgui/async_worker.py similarity index 97% rename from hexrd/ui/async_worker.py rename to hexrdgui/async_worker.py index 608a5ed81..228a6db91 100644 --- a/hexrd/ui/async_worker.py +++ b/hexrdgui/async_worker.py @@ -1,7 +1,7 @@ # This class was modified from the following example online: # https://www.learnpyqt.com/courses/concurrent-execution/multithreading-pyqt-applications-qthreadpool/ -from PySide2.QtCore import QObject, QRunnable, Signal, Slot +from PySide6.QtCore import QObject, QRunnable, Signal, Slot import inspect import traceback diff --git a/hexrd/ui/azimuthal_overlay_editor.py b/hexrdgui/azimuthal_overlay_editor.py similarity index 94% rename from hexrd/ui/azimuthal_overlay_editor.py rename to hexrdgui/azimuthal_overlay_editor.py index 1d08be267..676212a08 100644 --- a/hexrd/ui/azimuthal_overlay_editor.py +++ b/hexrdgui/azimuthal_overlay_editor.py @@ -1,5 +1,5 @@ -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader class AzimuthalOverlayEditor: diff --git a/hexrd/ui/azimuthal_overlay_manager.py b/hexrdgui/azimuthal_overlay_manager.py similarity index 96% rename from hexrd/ui/azimuthal_overlay_manager.py rename to hexrdgui/azimuthal_overlay_manager.py index 91fa600e6..6e948f621 100644 --- a/hexrd/ui/azimuthal_overlay_manager.py +++ b/hexrdgui/azimuthal_overlay_manager.py @@ -1,16 +1,16 @@ import random -from PySide2.QtCore import Qt, QItemSelectionModel -from PySide2.QtWidgets import ( +from PySide6.QtCore import Qt, QItemSelectionModel +from PySide6.QtWidgets import ( QCheckBox, QComboBox, QHBoxLayout, QHeaderView, QSizePolicy, QTableWidgetItem, QWidget ) -from hexrd.ui import utils +from hexrdgui import utils -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.azimuthal_overlay_editor import AzimuthalOverlayEditor -from hexrd.ui.azimuthal_overlay_style_picker import AzimuthalOverlayStylePicker -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.azimuthal_overlay_editor import AzimuthalOverlayEditor +from hexrdgui.azimuthal_overlay_style_picker import AzimuthalOverlayStylePicker +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals import numpy as np @@ -272,7 +272,7 @@ def remove(self): def edit_style(self): self._style_picker = AzimuthalOverlayStylePicker(self.active_overlay, self.ui) - self._style_picker.exec_() + self._style_picker.exec() def show_legend(self, value): HexrdConfig().show_azimuthal_legend = value diff --git a/hexrd/ui/azimuthal_overlay_style_picker.py b/hexrdgui/azimuthal_overlay_style_picker.py similarity index 87% rename from hexrd/ui/azimuthal_overlay_style_picker.py rename to hexrdgui/azimuthal_overlay_style_picker.py index 1d71e7b05..f5b9fc78a 100644 --- a/hexrd/ui/azimuthal_overlay_style_picker.py +++ b/hexrdgui/azimuthal_overlay_style_picker.py @@ -1,10 +1,10 @@ -from PySide2.QtCore import QObject -from PySide2.QtGui import QColor -from PySide2.QtWidgets import QColorDialog +from PySide6.QtCore import QObject +from PySide6.QtGui import QColor +from PySide6.QtWidgets import QColorDialog -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals class AzimuthalOverlayStylePicker(QObject): @@ -23,9 +23,9 @@ def __init__(self, overlay, parent=None): self.setup_connections() self.update_gui() - def exec_(self): + def exec(self): self.ui.adjustSize() - return self.ui.exec_() + return self.ui.exec() def setup_connections(self): self.ui.color.pressed.connect(self.pick_color) @@ -72,7 +72,7 @@ def pick_color(self): color = sender.text() dialog = QColorDialog(QColor(color), self.ui) - if dialog.exec_(): + if dialog.exec(): sender.setText(dialog.selectedColor().name()) self.update_button_colors() self.update_config() diff --git a/hexrd/ui/beam_marker_style_editor.py b/hexrdgui/beam_marker_style_editor.py similarity index 91% rename from hexrd/ui/beam_marker_style_editor.py rename to hexrdgui/beam_marker_style_editor.py index 3905f9647..7698c77e6 100644 --- a/hexrd/ui/beam_marker_style_editor.py +++ b/hexrdgui/beam_marker_style_editor.py @@ -2,12 +2,12 @@ from matplotlib.markers import MarkerStyle -from PySide2.QtGui import QColor -from PySide2.QtWidgets import QColorDialog +from PySide6.QtGui import QColor +from PySide6.QtWidgets import QColorDialog -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals class BeamMarkerStyleEditor: @@ -80,7 +80,7 @@ def pick_color(self): color = w.text() dialog = QColorDialog(QColor(color), self.ui) - if dialog.exec_(): + if dialog.exec(): w.setText(dialog.selectedColor().name()) self.update_button_colors() self.update_config() diff --git a/hexrd/ui/brightness_contrast_editor.py b/hexrdgui/brightness_contrast_editor.py similarity index 98% rename from hexrd/ui/brightness_contrast_editor.py rename to hexrdgui/brightness_contrast_editor.py index a240e2eeb..0d7d92414 100644 --- a/hexrd/ui/brightness_contrast_editor.py +++ b/hexrdgui/brightness_contrast_editor.py @@ -1,17 +1,17 @@ import numpy as np from scipy.interpolate import interp1d -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import ( +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import ( QDialog, QDialogButtonBox, QMessageBox, QVBoxLayout ) from matplotlib.backends.backend_qt5agg import FigureCanvas from matplotlib.figure import Figure -from hexrd.ui.range_widget import RangeWidget -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals, reversed_enumerate +from hexrdgui.range_widget import RangeWidget +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals, reversed_enumerate NUM_INCREMENTS = 1000 @@ -397,7 +397,7 @@ def select_data_range(self): UiLoader().install_dialog_enter_key_filters(dialog) - if not dialog.exec_(): + if not dialog.exec(): # User canceled return diff --git a/hexrd/ui/cal_tree_view.py b/hexrdgui/cal_tree_view.py similarity index 96% rename from hexrd/ui/cal_tree_view.py rename to hexrdgui/cal_tree_view.py index 65e794ed1..195c97d3a 100644 --- a/hexrd/ui/cal_tree_view.py +++ b/hexrdgui/cal_tree_view.py @@ -1,17 +1,17 @@ -from PySide2.QtCore import QObject, QModelIndex, Qt -from PySide2.QtWidgets import ( +from PySide6.QtCore import QObject, QModelIndex, Qt +from PySide6.QtWidgets import ( QCheckBox, QMenu, QMessageBox, QStyledItemDelegate, QTreeView ) -from PySide2.QtGui import QCursor +from PySide6.QtGui import QCursor import numpy as np -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.tree_views.base_tree_item_model import BaseTreeItemModel -from hexrd.ui.tree_views.tree_item import TreeItem -from hexrd.ui.tree_views.value_column_delegate import ValueColumnDelegate -from hexrd.ui import constants -from hexrd.ui.utils import is_int +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.tree_views.base_tree_item_model import BaseTreeItemModel +from hexrdgui.tree_views.tree_item import TreeItem +from hexrdgui.tree_views.value_column_delegate import ValueColumnDelegate +from hexrdgui import constants +from hexrdgui.utils import is_int # Global constants FIXED = 0 @@ -231,7 +231,8 @@ def __init__(self, parent=None): def createEditor(self, parent, option, index): check = QCheckBox(parent) - check.toggled.connect(self.statusChanged) + # Only indicate the status has changed on user interaction + check.clicked.connect(self.statusChanged) return check @@ -304,7 +305,7 @@ def contextMenuEvent(self, event): menu.addSeparator() check = menu.addAction('Check All') uncheck = menu.addAction('Uncheck All') - action = menu.exec_(QCursor.pos()) + action = menu.exec(QCursor.pos()) if action == collapse: self.collapse_selection(item, index) diff --git a/hexrd/ui/calibration/__init__.py b/hexrdgui/calibration/__init__.py similarity index 100% rename from hexrd/ui/calibration/__init__.py rename to hexrdgui/calibration/__init__.py diff --git a/hexrd/ui/calibration/auto/__init__.py b/hexrdgui/calibration/auto/__init__.py similarity index 100% rename from hexrd/ui/calibration/auto/__init__.py rename to hexrdgui/calibration/auto/__init__.py diff --git a/hexrd/ui/calibration/auto/powder_calibration_dialog.py b/hexrdgui/calibration/auto/powder_calibration_dialog.py similarity index 96% rename from hexrd/ui/calibration/auto/powder_calibration_dialog.py rename to hexrdgui/calibration/auto/powder_calibration_dialog.py index cb5878e35..f810517da 100644 --- a/hexrd/ui/calibration/auto/powder_calibration_dialog.py +++ b/hexrdgui/calibration/auto/powder_calibration_dialog.py @@ -1,10 +1,10 @@ -from PySide2.QtCore import QTimer -from PySide2.QtWidgets import QMessageBox +from PySide6.QtCore import QTimer +from PySide6.QtWidgets import QMessageBox import numpy as np -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader class PowderCalibrationDialog: @@ -71,8 +71,8 @@ def update_config(self): options['pk_type'] = self.peak_fit_type options['bg_type'] = self.background_type - def exec_(self): - if not self.ui.exec_(): + def exec(self): + if not self.ui.exec(): return False self.update_config() diff --git a/hexrd/ui/calibration/auto/powder_runner.py b/hexrdgui/calibration/auto/powder_runner.py similarity index 94% rename from hexrd/ui/calibration/auto/powder_runner.py rename to hexrdgui/calibration/auto/powder_runner.py index fc93f71ca..c4b060b6a 100644 --- a/hexrd/ui/calibration/auto/powder_runner.py +++ b/hexrdgui/calibration/auto/powder_runner.py @@ -3,17 +3,17 @@ import numpy as np -from PySide2.QtCore import QObject, QTimer, Qt, Signal -from PySide2.QtWidgets import QCheckBox, QMessageBox +from PySide6.QtCore import QObject, QTimer, Qt, Signal +from PySide6.QtWidgets import QCheckBox, QMessageBox from hexrd.fitting.calibration import InstrumentCalibrator, PowderCalibrator -from hexrd.ui.async_runner import AsyncRunner -from hexrd.ui.constants import ViewType -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.utils import instr_to_internal_dict, masks_applied_to_panel_buffers +from hexrdgui.async_runner import AsyncRunner +from hexrdgui.constants import ViewType +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.utils import instr_to_internal_dict, masks_applied_to_panel_buffers -from hexrd.ui.calibration.auto import PowderCalibrationDialog +from hexrdgui.calibration.auto import PowderCalibrationDialog class PowderRunner(QObject): @@ -31,7 +31,7 @@ def clear(self): if hasattr(self, '_ask_if_lines_are_acceptable_box'): # Remove the box if it is still there... - self._ask_if_lines_are_acceptable_box.reject() + self._ask_if_lines_are_acceptable_box.hide() del self._ask_if_lines_are_acceptable_box def run(self): @@ -52,7 +52,7 @@ def validate(self): def _run(self): # First, have the user pick some options - if not PowderCalibrationDialog(self.material, self.parent).exec_(): + if not PowderCalibrationDialog(self.material, self.parent).exec(): # User canceled... return @@ -196,7 +196,7 @@ def update_config(self): msg = 'Optimization successful!' msg_box = QMessageBox(QMessageBox.Information, 'HEXRD', msg) msg_box.setDetailedText(self.results_message) - msg_box.exec_() + msg_box.exec() output_dict = instr_to_internal_dict(self.instr) diff --git a/hexrd/ui/calibration/calibration_runner.py b/hexrdgui/calibration/calibration_runner.py similarity index 96% rename from hexrd/ui/calibration/calibration_runner.py rename to hexrdgui/calibration/calibration_runner.py index ac02a985e..4c0a1151a 100644 --- a/hexrd/ui/calibration/calibration_runner.py +++ b/hexrdgui/calibration/calibration_runner.py @@ -6,8 +6,8 @@ import h5py import numpy as np -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import QFileDialog, QMessageBox +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import QFileDialog, QMessageBox from hexrd.crystallography import hklToStr from hexrd.fitting.calibration import ( @@ -15,27 +15,27 @@ ) from hexrd.instrument import unwrap_h5_to_dict -from hexrd.ui.calibration.auto import ( +from hexrdgui.calibration.auto import ( PowderCalibrationDialog, save_picks_to_overlay, ) -from hexrd.ui.calibration.laue_auto_picker_dialog import LaueAutoPickerDialog -from hexrd.ui.calibration.pick_based_calibration import run_calibration -from hexrd.ui.calibration.hkl_picks_tree_view_dialog import ( +from hexrdgui.calibration.laue_auto_picker_dialog import LaueAutoPickerDialog +from hexrdgui.calibration.pick_based_calibration import run_calibration +from hexrdgui.calibration.hkl_picks_tree_view_dialog import ( generate_picks_results, overlays_to_tree_format, HKLPicksTreeViewDialog, picks_cartesian_to_angles, tree_format_to_picks, ) -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.constants import OverlayType, ViewType -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.line_picker_dialog import LinePickerDialog -from hexrd.ui.select_item_dialog import SelectItemDialog -from hexrd.ui.utils import ( +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.constants import OverlayType, ViewType +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.line_picker_dialog import LinePickerDialog +from hexrdgui.select_item_dialog import SelectItemDialog +from hexrdgui.utils import ( array_index_in_list, instr_to_internal_dict, masks_applied_to_panel_buffers, unique_array_list ) -from hexrd.ui.utils.conversions import cart_to_angles -from hexrd.ui.utils.dicts import ensure_all_keys_match, ndarrays_to_lists +from hexrdgui.utils.conversions import cart_to_angles +from hexrdgui.utils.dicts import ensure_all_keys_match, ndarrays_to_lists class CalibrationRunner(QObject): @@ -85,8 +85,13 @@ def validate(self): raise Exception('There are no refinable parameters') def enable_focus_mode(self, b): - HexrdConfig().enable_canvas_focus_mode.emit(b) - HexrdConfig().enable_canvas_toolbar.emit(not b) + # FIXME: We must avoid using focus mode until we can be sure + # that this issue will not happen again: https://github.com/HEXRD/hexrdgui/issues/1556 + # We *cannot* allow the GUI to remain disabled after calibration. + + # HexrdConfig().enable_canvas_focus_mode.emit(b) + # HexrdConfig().enable_canvas_toolbar.emit(not b) + pass def clear_all_overlay_picks(self): for overlay in self.active_overlays: @@ -142,7 +147,7 @@ def pick_this_line(self): 'parent': self.canvas, } dialog = SelectItemDialog(**kwargs) - if not dialog.exec_(): + if not dialog.exec(): # User canceled self.restore_state() return @@ -744,7 +749,7 @@ def auto_pick_powder_points(self): material = overlay.material dialog = PowderCalibrationDialog(material, self.canvas) dialog.show_optimization_parameters(False) - if not dialog.exec_(): + if not dialog.exec(): # User canceled self.restore_state() return @@ -806,7 +811,7 @@ def auto_powder_pick_finished(self, auto_picks): def auto_pick_laue_points(self): overlay = self.active_overlay dialog = LaueAutoPickerDialog(overlay, self.canvas) - if not dialog.exec_(): + if not dialog.exec(): # User canceled self.restore_state() return diff --git a/hexrd/ui/calibration/cartesian_plot.py b/hexrdgui/calibration/cartesian_plot.py similarity index 98% rename from hexrd/ui/calibration/cartesian_plot.py rename to hexrdgui/calibration/cartesian_plot.py index 782815c6f..44533a76b 100644 --- a/hexrd/ui/calibration/cartesian_plot.py +++ b/hexrdgui/calibration/cartesian_plot.py @@ -8,11 +8,11 @@ from hexrd.gridutil import cellIndices -from hexrd.ui.constants import ViewType -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.overlays import update_overlay_data -from hexrd.ui.utils import format_memory_int +from hexrdgui.constants import ViewType +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.overlays import update_overlay_data +from hexrdgui.utils import format_memory_int from skimage import transform as tf diff --git a/hexrd/ui/calibration/display_plane.py b/hexrdgui/calibration/display_plane.py similarity index 100% rename from hexrd/ui/calibration/display_plane.py rename to hexrdgui/calibration/display_plane.py diff --git a/hexrd/ui/calibration/hedm/__init__.py b/hexrdgui/calibration/hedm/__init__.py similarity index 100% rename from hexrd/ui/calibration/hedm/__init__.py rename to hexrdgui/calibration/hedm/__init__.py diff --git a/hexrd/ui/calibration/hedm/calibration_options_dialog.py b/hexrdgui/calibration/hedm/calibration_options_dialog.py similarity index 94% rename from hexrd/ui/calibration/hedm/calibration_options_dialog.py rename to hexrdgui/calibration/hedm/calibration_options_dialog.py index 7cb179aa6..d1a94dfde 100644 --- a/hexrd/ui/calibration/hedm/calibration_options_dialog.py +++ b/hexrdgui/calibration/hedm/calibration_options_dialog.py @@ -1,9 +1,9 @@ -from PySide2.QtCore import QObject, Signal +from PySide6.QtCore import QObject, Signal -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.grains_viewer_dialog import GrainsViewerDialog -from hexrd.ui.reflections_table import ReflectionsTable -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.grains_viewer_dialog import GrainsViewerDialog +from hexrdgui.reflections_table import ReflectionsTable +from hexrdgui.ui_loader import UiLoader class HEDMCalibrationOptionsDialog(QObject): diff --git a/hexrd/ui/calibration/hedm/calibration_results_dialog.py b/hexrdgui/calibration/hedm/calibration_results_dialog.py similarity index 96% rename from hexrd/ui/calibration/hedm/calibration_results_dialog.py rename to hexrdgui/calibration/hedm/calibration_results_dialog.py index 5ed5b9aad..0d7e92f69 100644 --- a/hexrd/ui/calibration/hedm/calibration_results_dialog.py +++ b/hexrdgui/calibration/hedm/calibration_results_dialog.py @@ -1,12 +1,12 @@ -from PySide2.QtCore import Qt -from PySide2.QtWidgets import QSizePolicy +from PySide6.QtCore import Qt +from PySide6.QtWidgets import QSizePolicy from matplotlib.backends.backend_qt5agg import FigureCanvas from matplotlib.figure import Figure import numpy as np -from hexrd.ui.navigation_toolbar import NavigationToolbar -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.navigation_toolbar import NavigationToolbar +from hexrdgui.ui_loader import UiLoader DEFAULT_STYLE = 'rx' @@ -102,8 +102,8 @@ def setup_canvas(self): self.ax = ax self.canvas = canvas - def exec_(self): - return self.ui.exec_() + def exec(self): + return self.ui.exec() @property def selected_detector_key(self): diff --git a/hexrd/ui/calibration/hedm/calibration_runner.py b/hexrdgui/calibration/hedm/calibration_runner.py similarity index 98% rename from hexrd/ui/calibration/hedm/calibration_runner.py rename to hexrdgui/calibration/hedm/calibration_runner.py index 61cf60e2b..db158de3c 100644 --- a/hexrd/ui/calibration/hedm/calibration_runner.py +++ b/hexrdgui/calibration/hedm/calibration_runner.py @@ -1,21 +1,21 @@ import numpy as np -from PySide2.QtCore import QObject, Signal +from PySide6.QtCore import QObject, Signal from hexrd import constants as cnst, instrument from hexrd.fitting import calibration from hexrd.transforms import xfcapi -from hexrd.ui.calibration.hedm import ( +from hexrdgui.calibration.hedm import ( HEDMCalibrationOptionsDialog, HEDMCalibrationResultsDialog, ) -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.indexing.create_config import ( +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.indexing.create_config import ( create_indexing_config, OmegasNotFoundError ) -from hexrd.ui.message_box import MessageBox -from hexrd.ui.utils import instr_to_internal_dict +from hexrdgui.message_box import MessageBox +from hexrdgui.utils import instr_to_internal_dict class HEDMCalibrationRunner(QObject): @@ -164,7 +164,7 @@ def on_pull_spots_finished(self, spots_data_dict): 'parent': self.parent, } dialog = HEDMCalibrationResultsDialog(**kwargs) - if not dialog.exec_(): + if not dialog.exec(): return # Run optimization @@ -195,7 +195,7 @@ def on_pull_spots_finished(self, spots_data_dict): 'parent': self.parent, } dialog = HEDMCalibrationResultsDialog(**kwargs) - if not dialog.exec_(): + if not dialog.exec(): return # All done! Update the results. @@ -278,7 +278,7 @@ def on_pull_spots_finished(self, spots_data_dict): 'parent': self.parent, } dialog = HEDMCalibrationResultsDialog(**kwargs) - if not dialog.exec_(): + if not dialog.exec(): return # update calibration crystal params @@ -372,7 +372,7 @@ def update_config(self): 'parent': self.parent, } msg_box = MessageBox(**kwargs) - msg_box.exec_() + msg_box.exec() # Update rotation series parameters from the results for results, overlay in zip(self.results, self.active_overlays): diff --git a/hexrd/ui/calibration/hkl_picks_tree_view_dialog.py b/hexrdgui/calibration/hkl_picks_tree_view_dialog.py similarity index 92% rename from hexrd/ui/calibration/hkl_picks_tree_view_dialog.py rename to hexrdgui/calibration/hkl_picks_tree_view_dialog.py index 82ee30fd9..b8cb864a6 100644 --- a/hexrd/ui/calibration/hkl_picks_tree_view_dialog.py +++ b/hexrdgui/calibration/hkl_picks_tree_view_dialog.py @@ -6,18 +6,18 @@ from hexrd.crystallography import hklToStr -from PySide2.QtCore import QTimer -from PySide2.QtWidgets import QFileDialog, QMessageBox +from PySide6.QtCore import QTimer +from PySide6.QtWidgets import QFileDialog, QMessageBox from hexrd.instrument import unwrap_dict_to_h5, unwrap_h5_to_dict -from hexrd.ui.constants import ViewType -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.tree_views.hkl_picks_tree_view import HKLPicksTreeView -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils.conversions import angles_to_cart, cart_to_angles -from hexrd.ui.utils.dicts import ensure_all_keys_match, ndarrays_to_lists +from hexrdgui.constants import ViewType +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.tree_views.hkl_picks_tree_view import HKLPicksTreeView +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils.conversions import angles_to_cart, cart_to_angles +from hexrdgui.utils.dicts import ensure_all_keys_match, ndarrays_to_lists class HKLPicksTreeViewDialog: @@ -53,11 +53,11 @@ def update_gui(self): def on_finished(self): self.tree_view.clear_artists() - def exec_(self): - return self.ui.exec_() + def exec(self): + return self.ui.exec() - def exec_later(self): - QTimer.singleShot(0, lambda: self.exec_()) + def execlater(self): + QTimer.singleShot(0, lambda: self.exec()) def export_picks_clicked(self): selected_file, selected_filter = QFileDialog.getSaveFileName( diff --git a/hexrd/ui/calibration/laue_auto_picker_dialog.py b/hexrdgui/calibration/laue_auto_picker_dialog.py similarity index 94% rename from hexrd/ui/calibration/laue_auto_picker_dialog.py rename to hexrdgui/calibration/laue_auto_picker_dialog.py index 8e498dc0a..6738957fd 100644 --- a/hexrd/ui/calibration/laue_auto_picker_dialog.py +++ b/hexrdgui/calibration/laue_auto_picker_dialog.py @@ -1,9 +1,9 @@ -from PySide2.QtWidgets import QMessageBox +from PySide6.QtWidgets import QMessageBox import numpy as np -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader class LaueAutoPickerDialog: @@ -57,8 +57,8 @@ def update_config(self): options['use_blob_detection'] = self.ui.use_blob_detection.isChecked() options['blob_threshold'] = self.ui.blob_threshold.value() - def exec_(self): - if not self.ui.exec_(): + def exec(self): + if not self.ui.exec(): return False self.update_config() diff --git a/hexrd/ui/calibration/panel_buffer_dialog.py b/hexrdgui/calibration/panel_buffer_dialog.py similarity index 94% rename from hexrd/ui/calibration/panel_buffer_dialog.py rename to hexrdgui/calibration/panel_buffer_dialog.py index 0a804bafd..f0bd0101b 100644 --- a/hexrd/ui/calibration/panel_buffer_dialog.py +++ b/hexrdgui/calibration/panel_buffer_dialog.py @@ -1,16 +1,16 @@ import copy import os -from PySide2.QtCore import Signal, QObject -from PySide2.QtWidgets import QFileDialog, QMessageBox +from PySide6.QtCore import Signal, QObject, Qt +from PySide6.QtWidgets import QFileDialog, QMessageBox import matplotlib.pyplot as plt import numpy as np -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url CONFIG_MODE_BORDER = 'border' CONFIG_MODE_NUMPY = 'numpy' @@ -29,6 +29,10 @@ def __init__(self, detector, parent=None): loader = UiLoader() self.ui = loader.load_file('panel_buffer_dialog.ui') + # Keep the dialog in front + flags = self.ui.windowFlags() + self.ui.setWindowFlags(flags | Qt.Tool) + add_help_url(self.ui.button_box, 'configuration/instrument/#panel-buffer') diff --git a/hexrd/ui/calibration/pick_based_calibration.py b/hexrdgui/calibration/pick_based_calibration.py similarity index 100% rename from hexrd/ui/calibration/pick_based_calibration.py rename to hexrdgui/calibration/pick_based_calibration.py diff --git a/hexrd/ui/calibration/polar_plot.py b/hexrdgui/calibration/polar_plot.py similarity index 94% rename from hexrd/ui/calibration/polar_plot.py rename to hexrdgui/calibration/polar_plot.py index 1bb014f7f..3931b35d2 100644 --- a/hexrd/ui/calibration/polar_plot.py +++ b/hexrdgui/calibration/polar_plot.py @@ -5,11 +5,11 @@ from .polarview import PolarView -from hexrd.ui.constants import ViewType -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.overlays import update_overlay_data -from hexrd.ui.calibration.utils.maud_headers import header0, header, block_hdr +from hexrdgui.constants import ViewType +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.overlays import update_overlay_data +from hexrdgui.calibration.utils.maud_headers import header0, header, block_hdr def polar_viewer(): diff --git a/hexrd/ui/calibration/polarview.py b/hexrdgui/calibration/polarview.py similarity index 99% rename from hexrd/ui/calibration/polarview.py rename to hexrdgui/calibration/polarview.py index 2e7f7e393..a73ac4ca2 100644 --- a/hexrd/ui/calibration/polarview.py +++ b/hexrdgui/calibration/polarview.py @@ -12,8 +12,8 @@ ) from hexrd import instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.utils import SnipAlgorithmType, run_snip1d, snip_width_pixels +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.utils import SnipAlgorithmType, run_snip1d, snip_width_pixels tvec_c = ct.zeros_3 diff --git a/hexrd/ui/calibration/raw_iviewer.py b/hexrdgui/calibration/raw_iviewer.py similarity index 77% rename from hexrd/ui/calibration/raw_iviewer.py rename to hexrdgui/calibration/raw_iviewer.py index c6dcb0065..5a3c5fa87 100644 --- a/hexrd/ui/calibration/raw_iviewer.py +++ b/hexrdgui/calibration/raw_iviewer.py @@ -1,7 +1,7 @@ -from hexrd.ui.constants import ViewType -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.overlays import update_overlay_data +from hexrdgui.constants import ViewType +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.overlays import update_overlay_data def raw_iviewer(): diff --git a/hexrd/ui/calibration/stereo_plot.py b/hexrdgui/calibration/stereo_plot.py similarity index 96% rename from hexrd/ui/calibration/stereo_plot.py rename to hexrdgui/calibration/stereo_plot.py index e6b938e44..d71814a4f 100644 --- a/hexrd/ui/calibration/stereo_plot.py +++ b/hexrdgui/calibration/stereo_plot.py @@ -5,13 +5,13 @@ from hexrd import constants as ct from hexrd.rotations import mapAngle -from hexrd.ui.constants import ViewType -from hexrd.ui.create_hedm_instrument import ( +from hexrdgui.constants import ViewType +from hexrdgui.create_hedm_instrument import ( create_hedm_instrument, create_view_hedm_instrument ) -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.overlays import update_overlay_data -from hexrd.ui.utils.conversions import angles_to_stereo, cart_to_angles +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.overlays import update_overlay_data +from hexrdgui.utils.conversions import angles_to_stereo, cart_to_angles from .polarview import PolarView from .stereo_project import stereo_project, stereo_projection_of_polar_view diff --git a/hexrd/ui/calibration/stereo_project.py b/hexrdgui/calibration/stereo_project.py similarity index 100% rename from hexrd/ui/calibration/stereo_project.py rename to hexrdgui/calibration/stereo_project.py diff --git a/hexrd/ui/calibration/structureless/__init__.py b/hexrdgui/calibration/structureless/__init__.py similarity index 100% rename from hexrd/ui/calibration/structureless/__init__.py rename to hexrdgui/calibration/structureless/__init__.py diff --git a/hexrd/ui/calibration/structureless/calibration_dialog.py b/hexrdgui/calibration/structureless/calibration_dialog.py similarity index 96% rename from hexrd/ui/calibration/structureless/calibration_dialog.py rename to hexrdgui/calibration/structureless/calibration_dialog.py index 9252046a2..7e48da5e6 100644 --- a/hexrd/ui/calibration/structureless/calibration_dialog.py +++ b/hexrdgui/calibration/structureless/calibration_dialog.py @@ -1,18 +1,18 @@ import copy import yaml -from PySide2.QtCore import QObject, Qt, Signal -from PySide2.QtWidgets import QComboBox, QDoubleSpinBox, QMessageBox, QSpinBox +from PySide6.QtCore import QObject, Qt, Signal +from PySide6.QtWidgets import QComboBox, QDoubleSpinBox, QMessageBox, QSpinBox -from hexrd.ui import resource_loader -from hexrd.ui.tree_views.multi_column_dict_tree_view import ( +from hexrdgui import resource_loader +from hexrdgui.tree_views.multi_column_dict_tree_view import ( MultiColumnDictTreeItemModel, MultiColumnDictTreeView ) -from hexrd.ui.pinhole_correction_editor import PinholeCorrectionEditor -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui.pinhole_correction_editor import PinholeCorrectionEditor +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils.dialog import add_help_url -import hexrd.ui.resources.calibration +import hexrdgui.resources.calibration class StructurelessCalibrationDialog(QObject): @@ -241,7 +241,7 @@ def update_from_calibrator(self, calibrator): self.params_dict = calibrator.params def load_tree_view_mapping(self): - module = hexrd.ui.resources.calibration + module = hexrdgui.resources.calibration filename = 'structureless_params_tree_view.yml' text = resource_loader.load_resource(module, filename) self.yaml_tree_view = yaml.safe_load(text) diff --git a/hexrd/ui/calibration/structureless/picks_io.py b/hexrdgui/calibration/structureless/picks_io.py similarity index 100% rename from hexrd/ui/calibration/structureless/picks_io.py rename to hexrdgui/calibration/structureless/picks_io.py diff --git a/hexrd/ui/calibration/structureless/runner.py b/hexrdgui/calibration/structureless/runner.py similarity index 96% rename from hexrd/ui/calibration/structureless/runner.py rename to hexrdgui/calibration/structureless/runner.py index 369b41fee..c961b16f7 100644 --- a/hexrd/ui/calibration/structureless/runner.py +++ b/hexrdgui/calibration/structureless/runner.py @@ -5,22 +5,22 @@ import matplotlib.pyplot as plt import numpy as np -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import QFileDialog, QMessageBox +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import QFileDialog, QMessageBox from hexrd.fitting.calibration import StructureLessCalibrator -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.line_picker_dialog import LinePickerDialog -from hexrd.ui.markers import igor_marker -from hexrd.ui.select_item_dialog import SelectItemDialog -from hexrd.ui.tree_views import GenericPicksTreeViewDialog -from hexrd.ui.utils import instr_to_internal_dict -from hexrd.ui.utils.conversions import angles_to_cart, cart_to_angles -from hexrd.ui.utils.dialog import add_help_url -from hexrd.ui.utils.guess_instrument_type import guess_instrument_type -from hexrd.ui.utils.tth_distortion import apply_tth_distortion_if_needed +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.line_picker_dialog import LinePickerDialog +from hexrdgui.markers import igor_marker +from hexrdgui.select_item_dialog import SelectItemDialog +from hexrdgui.tree_views import GenericPicksTreeViewDialog +from hexrdgui.utils import instr_to_internal_dict +from hexrdgui.utils.conversions import angles_to_cart, cart_to_angles +from hexrdgui.utils.dialog import add_help_url +from hexrdgui.utils.guess_instrument_type import guess_instrument_type +from hexrdgui.utils.tth_distortion import apply_tth_distortion_if_needed from .calibration_dialog import StructurelessCalibrationDialog from .picks_io import load_picks_from_file, save_picks_to_file @@ -117,7 +117,7 @@ def choose_pick_method(self): 'parent': self.canvas, } dialog = SelectItemDialog(**kwargs) - if not dialog.exec_(): + if not dialog.exec(): # User canceled return diff --git a/hexrd/ui/calibration/utils/__init__.py b/hexrdgui/calibration/utils/__init__.py similarity index 100% rename from hexrd/ui/calibration/utils/__init__.py rename to hexrdgui/calibration/utils/__init__.py diff --git a/hexrd/ui/calibration/utils/maud_headers.py b/hexrdgui/calibration/utils/maud_headers.py similarity index 100% rename from hexrd/ui/calibration/utils/maud_headers.py rename to hexrdgui/calibration/utils/maud_headers.py diff --git a/hexrd/ui/calibration/wppf_options_dialog.py b/hexrdgui/calibration/wppf_options_dialog.py similarity index 97% rename from hexrd/ui/calibration/wppf_options_dialog.py rename to hexrdgui/calibration/wppf_options_dialog.py index 764cdd4ef..03757f75e 100644 --- a/hexrd/ui/calibration/wppf_options_dialog.py +++ b/hexrdgui/calibration/wppf_options_dialog.py @@ -4,8 +4,8 @@ import matplotlib.pyplot as plt import numpy as np -from PySide2.QtCore import Qt, QObject, QTimer, Signal -from PySide2.QtWidgets import ( +from PySide6.QtCore import Qt, QObject, QTimer, Signal +from PySide6.QtWidgets import ( QCheckBox, QFileDialog, QHBoxLayout, QMessageBox, QSizePolicy, QTableWidgetItem, QWidget ) @@ -20,13 +20,13 @@ _generate_default_parameters_Rietveld, ) -from hexrd.ui.dynamic_widget import DynamicWidget -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.scientificspinbox import ScientificDoubleSpinBox -from hexrd.ui.select_items_dialog import SelectItemsDialog -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals, clear_layout, has_nan -from hexrd.ui.wppf_style_picker import WppfStylePicker +from hexrdgui.dynamic_widget import DynamicWidget +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.scientificspinbox import ScientificDoubleSpinBox +from hexrdgui.select_items_dialog import SelectItemsDialog +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals, clear_layout, has_nan +from hexrdgui.wppf_style_picker import WppfStylePicker inverted_peakshape_dict = {v: k for k, v in peakshape_dict.items()} @@ -286,7 +286,7 @@ def select_materials(self): selected = self.selected_materials items = [(name, name in selected) for name in materials] dialog = SelectItemsDialog(items, self.ui) - if dialog.exec_() and self.selected_materials != dialog.selected_items: + if dialog.exec() and self.selected_materials != dialog.selected_items: self.selected_materials = dialog.selected_items self.update_params() @@ -531,7 +531,7 @@ def display_wppf_plot_toggled(self): def edit_plot_style(self): dialog = WppfStylePicker(self.ui) - dialog.ui.exec_() + dialog.ui.exec() def create_label(self, v): w = QTableWidgetItem(v) @@ -921,12 +921,12 @@ def dict_to_param(d): if __name__ == '__main__': - from PySide2.QtWidgets import QApplication + from PySide6.QtWidgets import QApplication app = QApplication() dialog = WppfOptionsDialog() - dialog.ui.exec_() + dialog.ui.exec() print(f'{dialog.method=}') print(f'{dialog.background_method=}') diff --git a/hexrd/ui/calibration/wppf_runner.py b/hexrdgui/calibration/wppf_runner.py similarity index 95% rename from hexrd/ui/calibration/wppf_runner.py rename to hexrdgui/calibration/wppf_runner.py index 8cb94a271..5f4df0168 100644 --- a/hexrd/ui/calibration/wppf_runner.py +++ b/hexrdgui/calibration/wppf_runner.py @@ -1,11 +1,11 @@ import copy -from PySide2.QtCore import QCoreApplication +from PySide6.QtCore import QCoreApplication from hexrd.wppf import Rietveld -from hexrd.ui.calibration.wppf_options_dialog import WppfOptionsDialog -from hexrd.ui.hexrd_config import HexrdConfig +from hexrdgui.calibration.wppf_options_dialog import WppfOptionsDialog +from hexrdgui.hexrd_config import HexrdConfig class WppfRunner: diff --git a/hexrd/ui/calibration_crystal_editor.py b/hexrdgui/calibration_crystal_editor.py similarity index 94% rename from hexrd/ui/calibration_crystal_editor.py rename to hexrdgui/calibration_crystal_editor.py index 82f7d0845..80764c941 100644 --- a/hexrd/ui/calibration_crystal_editor.py +++ b/hexrdgui/calibration_crystal_editor.py @@ -2,21 +2,21 @@ import numpy as np from numpy.linalg import LinAlgError -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import QFileDialog +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import QFileDialog from hexrd import instrument, matrixutil -from hexrd.ui.calibration_crystal_slider_widget import ( +from hexrdgui.calibration_crystal_slider_widget import ( CalibrationCrystalSliderWidget, WidgetMode as SliderWidgetMode ) -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.overlays.constants import crystal_refinement_labels -from hexrd.ui.select_grains_dialog import SelectGrainsDialog -from hexrd.ui.select_items_widget import SelectItemsWidget -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals, convert_angle_convention +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.overlays.constants import crystal_refinement_labels +from hexrdgui.select_grains_dialog import SelectGrainsDialog +from hexrdgui.select_items_widget import SelectItemsWidget +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals, convert_angle_convention class CalibrationCrystalEditor(QObject): @@ -281,7 +281,7 @@ def update_tab_gui(self): def load(self): dialog = SelectGrainsDialog(1, self.ui) - if not dialog.exec_(): + if not dialog.exec(): return self.load_from_grain(dialog.selected_grain) diff --git a/hexrd/ui/calibration_crystal_slider_widget.py b/hexrdgui/calibration_crystal_slider_widget.py similarity index 96% rename from hexrd/ui/calibration_crystal_slider_widget.py rename to hexrdgui/calibration_crystal_slider_widget.py index 6e46b4faa..9f690912d 100644 --- a/hexrd/ui/calibration_crystal_slider_widget.py +++ b/hexrdgui/calibration_crystal_slider_widget.py @@ -1,10 +1,10 @@ from enum import IntEnum -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import QProxyStyle, QStyle +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import QProxyStyle, QStyle -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals class SpinBoxStyle(QProxyStyle): diff --git a/hexrd/ui/calibration_slider_widget.py b/hexrdgui/calibration_slider_widget.py similarity index 98% rename from hexrd/ui/calibration_slider_widget.py rename to hexrdgui/calibration_slider_widget.py index b2c4ed4f4..0149db81b 100644 --- a/hexrd/ui/calibration_slider_widget.py +++ b/hexrdgui/calibration_slider_widget.py @@ -1,9 +1,9 @@ -from PySide2.QtCore import QObject +from PySide6.QtCore import QObject import numpy as np -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader class CalibrationSliderWidget(QObject): diff --git a/hexrd/ui/color_map_editor.py b/hexrdgui/color_map_editor.py similarity index 96% rename from hexrd/ui/color_map_editor.py rename to hexrdgui/color_map_editor.py index e9a75778b..8dde13c41 100644 --- a/hexrd/ui/color_map_editor.py +++ b/hexrdgui/color_map_editor.py @@ -5,12 +5,12 @@ import numpy as np -from hexrd.ui import constants -from hexrd.ui.brightness_contrast_editor import BrightnessContrastEditor -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.scaling import SCALING_OPTIONS -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui import constants +from hexrdgui.brightness_contrast_editor import BrightnessContrastEditor +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.scaling import SCALING_OPTIONS +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals class ColorMapEditor: @@ -159,7 +159,7 @@ def bc_editor_modified(self): self.range_edited() def update_mins_and_maxes(self): - # We can't do this in PySide2 for some reason: + # We can't do this in PySide6 for some reason: # self.ui.maximum.valueChanged.connect(self.ui.minimum.setMaximum) # self.ui.minimum.valueChanged.connect(self.ui.maximum.setMinimum) self.ui.maximum.setMinimum(self.ui.minimum.value()) diff --git a/hexrd/ui/config_dialog.py b/hexrdgui/config_dialog.py similarity index 92% rename from hexrd/ui/config_dialog.py rename to hexrdgui/config_dialog.py index 387c7bacd..b0d63a0fe 100644 --- a/hexrd/ui/config_dialog.py +++ b/hexrdgui/config_dialog.py @@ -1,7 +1,7 @@ -from PySide2.QtWidgets import QMessageBox +from PySide6.QtWidgets import QMessageBox -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader class ConfigDialog: @@ -14,9 +14,9 @@ def __init__(self, parent=None): def setup_connections(self): self.ui.accepted.connect(self.on_accepted) - def exec_(self): + def exec(self): self.update_gui() - self.ui.exec_() + self.ui.exec() def update_gui(self): self.max_cpus_ui = self.max_cpus_config diff --git a/hexrd/ui/constants.py b/hexrdgui/constants.py similarity index 100% rename from hexrd/ui/constants.py rename to hexrdgui/constants.py diff --git a/hexrd/ui/create_hedm_instrument.py b/hexrdgui/create_hedm_instrument.py similarity index 94% rename from hexrd/ui/create_hedm_instrument.py rename to hexrdgui/create_hedm_instrument.py index d4bfaa613..b1e21b055 100644 --- a/hexrd/ui/create_hedm_instrument.py +++ b/hexrdgui/create_hedm_instrument.py @@ -1,8 +1,8 @@ from hexrd import constants as ct from hexrd.instrument import HEDMInstrument -from hexrd.ui.constants import ViewType -from hexrd.ui.hexrd_config import HexrdConfig +from hexrdgui.constants import ViewType +from hexrdgui.hexrd_config import HexrdConfig def create_hedm_instrument(): diff --git a/hexrd/ui/create_polar_mask.py b/hexrdgui/create_polar_mask.py similarity index 94% rename from hexrd/ui/create_polar_mask.py rename to hexrdgui/create_polar_mask.py index f70723c2f..f7dd875fd 100644 --- a/hexrd/ui/create_polar_mask.py +++ b/hexrdgui/create_polar_mask.py @@ -2,11 +2,11 @@ from skimage.draw import polygon -from hexrd.ui.create_hedm_instrument import create_view_hedm_instrument -from hexrd.ui.calibration.polarview import PolarView -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.utils import add_sample_points -from hexrd.ui.utils.conversions import pixels_to_angles +from hexrdgui.create_hedm_instrument import create_view_hedm_instrument +from hexrdgui.calibration.polarview import PolarView +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.utils import add_sample_points +from hexrdgui.utils.conversions import pixels_to_angles def convert_raw_to_polar(det, line): diff --git a/hexrd/ui/create_raw_mask.py b/hexrdgui/create_raw_mask.py similarity index 90% rename from hexrd/ui/create_raw_mask.py rename to hexrdgui/create_raw_mask.py index ac5b93117..ea185f6aa 100644 --- a/hexrd/ui/create_raw_mask.py +++ b/hexrdgui/create_raw_mask.py @@ -2,11 +2,11 @@ from skimage.draw import polygon -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.utils import add_sample_points -from hexrd.ui.utils.conversions import angles_to_pixels -from hexrd.ui.utils.tth_distortion import apply_tth_distortion_if_needed +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.utils import add_sample_points +from hexrdgui.utils.conversions import angles_to_pixels +from hexrdgui.utils.tth_distortion import apply_tth_distortion_if_needed def apply_threshold_mask(): diff --git a/hexrd/ui/dev-guide.md b/hexrdgui/dev-guide.md similarity index 94% rename from hexrd/ui/dev-guide.md rename to hexrdgui/dev-guide.md index cef5fd51d..4f413655a 100644 --- a/hexrd/ui/dev-guide.md +++ b/hexrdgui/dev-guide.md @@ -60,7 +60,7 @@ when more generic categories are needed. UI Files -------- -One nice feature of PySide2 is that UI files can be loaded at runtime. +One nice feature of PySide6 is that UI files can be loaded at runtime. However, this comes with a few complications. Namely, there is no `setupUi()` function that can be called. This means that the object that owns the widget does not need to be the type of the widget. @@ -68,7 +68,7 @@ that owns the widget does not need to be the type of the widget. The design of the classes that contain widgets in this source code are usually as follows: ``` -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.ui_loader import UiLoader class SomeWidget: @@ -88,9 +88,9 @@ If your class needs to emit signals, two things must be done: A UI class that emits signals needs to be set up like the following: ``` -from PySide2.QtCore import Signal, QObject +from PySide6.QtCore import Signal, QObject -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.ui_loader import UiLoader class SomeWidget(QObject): @@ -109,7 +109,7 @@ class SomeWidget(QObject): For updating the GUI with internal config, the design pattern we typically use is as follows: ``` -from hexrd.ui.utils import block_signals +from hexrdgui.utils import block_signals ... @@ -134,11 +134,11 @@ is so that if an exception is raised, they will be unblocked automatically. Resources --------- -Resources are placed within the `hexrd.ui.resources` directory, and they +Resources are placed within the `hexrdgui.resources` directory, and they can be loaded like so: ``` -from hexrd.ui import resource_loader -text = resource_loader.load_resource(hexrd.ui.resources.some_path, +from hexrdgui import resource_loader +text = resource_loader.load_resource(hexrdgui.resources.some_path, 'file_name') ``` @@ -216,7 +216,7 @@ progress(int) # Emitted only if a progress callback was used, and it The `AsyncWorker` is used like the following: ``` -thread_pool = QThreadPool() # Probably should be a member variable +thread_pool = QThreadPool.globalInstance() worker = AsyncWorker(func_to_call) thread_pool.start(worker) diff --git a/hexrd/ui/dynamic_widget.py b/hexrdgui/dynamic_widget.py similarity index 94% rename from hexrd/ui/dynamic_widget.py rename to hexrdgui/dynamic_widget.py index bbcdc59fb..75f209666 100644 --- a/hexrd/ui/dynamic_widget.py +++ b/hexrdgui/dynamic_widget.py @@ -1,7 +1,7 @@ -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import QCheckBox, QDoubleSpinBox, QLabel, QSpinBox +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import QCheckBox, QDoubleSpinBox, QLabel, QSpinBox -from hexrd.ui.scientificspinbox import ScientificDoubleSpinBox +from hexrdgui.scientificspinbox import ScientificDoubleSpinBox class DynamicWidget(QObject): diff --git a/hexrd/ui/edit_colormap_list_dialog.py b/hexrdgui/edit_colormap_list_dialog.py similarity index 96% rename from hexrd/ui/edit_colormap_list_dialog.py rename to hexrdgui/edit_colormap_list_dialog.py index c5b52342a..20299d7c0 100644 --- a/hexrd/ui/edit_colormap_list_dialog.py +++ b/hexrdgui/edit_colormap_list_dialog.py @@ -1,8 +1,8 @@ -from PySide2.QtCore import QObject, Qt +from PySide6.QtCore import QObject, Qt -from hexrd.ui import constants -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader +from hexrdgui import constants +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader class EditColormapListDialog(QObject): diff --git a/hexrd/ui/fiber_pick_utils.py b/hexrdgui/fiber_pick_utils.py similarity index 100% rename from hexrd/ui/fiber_pick_utils.py rename to hexrdgui/fiber_pick_utils.py diff --git a/hexrd/ui/fix_pdb.py b/hexrdgui/fix_pdb.py similarity index 100% rename from hexrd/ui/fix_pdb.py rename to hexrdgui/fix_pdb.py diff --git a/hexrd/ui/grains_viewer_dialog.py b/hexrdgui/grains_viewer_dialog.py similarity index 91% rename from hexrd/ui/grains_viewer_dialog.py rename to hexrdgui/grains_viewer_dialog.py index 5e9f47240..71721052b 100644 --- a/hexrd/ui/grains_viewer_dialog.py +++ b/hexrdgui/grains_viewer_dialog.py @@ -1,8 +1,8 @@ -from PySide2.QtWidgets import QDialog, QVBoxLayout +from PySide6.QtWidgets import QDialog, QVBoxLayout -from hexrd.ui.indexing.grains_table_model import GrainsTableModel -from hexrd.ui.plot_grains import plot_grains -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.indexing.grains_table_model import GrainsTableModel +from hexrdgui.plot_grains import plot_grains +from hexrdgui.ui_loader import UiLoader class GrainsViewerWidget: diff --git a/hexrd/ui/hand_drawn_mask_dialog.py b/hexrdgui/hand_drawn_mask_dialog.py similarity index 90% rename from hexrd/ui/hand_drawn_mask_dialog.py rename to hexrdgui/hand_drawn_mask_dialog.py index deb27164e..82357cabd 100644 --- a/hexrd/ui/hand_drawn_mask_dialog.py +++ b/hexrdgui/hand_drawn_mask_dialog.py @@ -1,4 +1,4 @@ -from PySide2.QtCore import QObject, Signal, Qt +from PySide6.QtCore import QObject, Signal, Qt from itertools import cycle @@ -6,10 +6,10 @@ import matplotlib.pyplot as plt from matplotlib.widgets import Cursor -from hexrd.ui.hexrd_config import HexrdConfig +from hexrdgui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import add_sample_points +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import add_sample_points # TODO: How to handle image mode? Mode has changed byt the time the signal has been emitted. @@ -34,6 +34,10 @@ def __init__(self, canvas, parent): self.dets = [] self.det = None + self.bp_id = None + self.enter_id = None + self.exit_id = None + prop_cycle = plt.rcParams['axes.prop_cycle'] self.color_cycler = cycle(prop_cycle.by_key()['color']) @@ -47,6 +51,9 @@ def setup_connections(self): self.ui.rejected.connect(self.rejected) def setup_canvas_connections(self): + # Ensure previous canvas connections are disconnected + self.disconnect_canvas_connections() + self.bp_id = self.canvas.mpl_connect('button_press_event', self.button_pressed) self.enter_id = self.canvas.mpl_connect('axes_enter_event', @@ -54,6 +61,19 @@ def setup_canvas_connections(self): self.exit_id = self.canvas.mpl_connect('axes_leave_event', self.axes_exited) + def disconnect_canvas_connections(self): + if self.bp_id: + self.canvas.mpl_disconnect(self.bp_id) + self.bp_id = None + + if self.enter_id: + self.canvas.mpl_disconnect(self.enter_id) + self.enter_id = None + + if self.exit_id: + self.canvas.mpl_disconnect(self.exit_id) + self.exit_id = None + def move_dialog_to_left(self): # This moves the dialog to the left border of the parent ph = self.ui.parent().geometry().height() @@ -75,13 +95,8 @@ def clear(self): self.linebuilder = None self.cursor = None - self.canvas.mpl_disconnect(self.bp_id) - self.canvas.mpl_disconnect(self.enter_id) - self.canvas.mpl_disconnect(self.exit_id) + self.disconnect_canvas_connections() - self.bp_id = None - self.enter_id = None - self.exit_id = None self.dets.clear() self.canvas.draw() diff --git a/hexrd/ui/hand_picked_fibers_widget.py b/hexrdgui/hand_picked_fibers_widget.py similarity index 97% rename from hexrd/ui/hand_picked_fibers_widget.py rename to hexrdgui/hand_picked_fibers_widget.py index 50f9849f4..c0f0bb39a 100644 --- a/hexrd/ui/hand_picked_fibers_widget.py +++ b/hexrdgui/hand_picked_fibers_widget.py @@ -1,14 +1,14 @@ import numpy as np -from PySide2.QtCore import QItemSelectionModel, QObject, Qt, Signal -from PySide2.QtWidgets import QTableWidgetItem +from PySide6.QtCore import QItemSelectionModel, QObject, Qt, Signal +from PySide6.QtWidgets import QTableWidgetItem from hexrd.rotations import quatOfExpMap -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.fiber_pick_utils import _angles_from_orientation, _pick_to_fiber -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.fiber_pick_utils import _angles_from_orientation, _pick_to_fiber +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals class HandPickedFibersWidget(QObject): diff --git a/hexrd/ui/hexrd_config.py b/hexrdgui/hexrd_config.py similarity index 98% rename from hexrd/ui/hexrd_config.py rename to hexrdgui/hexrd_config.py index 29d8a6924..b498cbb36 100644 --- a/hexrd/ui/hexrd_config.py +++ b/hexrdgui/hexrd_config.py @@ -4,7 +4,7 @@ from pathlib import Path import sys -from PySide2.QtCore import Signal, QCoreApplication, QObject, QSettings, QTimer +from PySide6.QtCore import Signal, QCoreApplication, QObject, QSettings, QTimer import h5py import matplotlib @@ -18,15 +18,15 @@ from hexrd.rotations import RotMatEuler from hexrd.valunits import valWUnit -from hexrd.ui import constants -from hexrd.ui import overlays -from hexrd.ui import resource_loader -from hexrd.ui import utils -from hexrd.ui.singletons import QSingleton +from hexrdgui import constants +from hexrdgui import overlays +from hexrdgui import resource_loader +from hexrdgui import utils +from hexrdgui.singletons import QSingleton -import hexrd.ui.resources.calibration -import hexrd.ui.resources.indexing -import hexrd.ui.resources.materials +import hexrdgui.resources.calibration +import hexrdgui.resources.indexing +import hexrdgui.resources.materials # This is a singleton class that contains the configuration @@ -246,7 +246,7 @@ class HexrdConfig(QObject, metaclass=QSingleton): def __init__(self): # Should this have a parent? - super(HexrdConfig, self).__init__(None) + super().__init__(None) self.config = {} self.default_config = {} self.gui_yaml_dict = None @@ -555,14 +555,26 @@ def recurse(cur, config): recurse(v, config) + @property + def _q_settings_version(self): + # Keep track of a QSettings version so we can ignore versions + # that we might not be able to load. + return 1 + def save_settings(self): settings = QSettings() + settings.setValue('settings_version', self._q_settings_version) state = self.state_to_persist() self._save_state_to_settings(state, settings) def load_settings(self): settings = QSettings() + if settings.value('settings_version') != self._q_settings_version: + # The QSettings version is different (probably PySide6 is + # trying to load a PySide2 QSettings, which has issues) + # Ignore the settings, as there may be compatibility issues. + return state = self._load_state_from_settings(settings) self.load_from_state(state) @@ -663,36 +675,36 @@ def set_images_dir(self, images_dir): self.images_dir = images_dir def load_gui_yaml_dict(self): - text = resource_loader.load_resource(hexrd.ui.resources.calibration, + text = resource_loader.load_resource(hexrdgui.resources.calibration, 'yaml_to_gui.yml') self.gui_yaml_dict = yaml.load(text, Loader=yaml.FullLoader) def load_calibration_flags_order(self): - text = resource_loader.load_resource(hexrd.ui.resources.calibration, + text = resource_loader.load_resource(hexrdgui.resources.calibration, 'calibration_flags_order.yml') self.calibration_flags_order = yaml.load(text, Loader=yaml.FullLoader) def load_default_config(self): - text = resource_loader.load_resource(hexrd.ui.resources.calibration, + text = resource_loader.load_resource(hexrdgui.resources.calibration, 'default_instrument_config.yml') self.default_config['instrument'] = yaml.load(text, Loader=yaml.FullLoader) - text = resource_loader.load_resource(hexrd.ui.resources.indexing, + text = resource_loader.load_resource(hexrdgui.resources.indexing, 'default_indexing_config.yml') self.default_config['indexing'] = yaml.load(text, Loader=yaml.FullLoader) - yml = resource_loader.load_resource(hexrd.ui.resources.materials, + yml = resource_loader.load_resource(hexrdgui.resources.materials, 'materials_panel_defaults.yml') self.default_config['materials'] = yaml.load(yml, Loader=yaml.FullLoader) - text = resource_loader.load_resource(hexrd.ui.resources.calibration, + text = resource_loader.load_resource(hexrdgui.resources.calibration, 'default_image_config.yml') self.default_config['image'] = yaml.load(text, Loader=yaml.FullLoader) - text = resource_loader.load_resource(hexrd.ui.resources.calibration, + text = resource_loader.load_resource(hexrdgui.resources.calibration, 'default_calibration_config.yml') self.default_config['calibration'] = yaml.load(text, Loader=yaml.FullLoader) @@ -812,7 +824,7 @@ def intensity_corrected_images_dict(self): return images_dict # Some methods require an instrument. Go ahead and create one. - from hexrd.ui.create_hedm_instrument import create_hedm_instrument + from hexrdgui.create_hedm_instrument import create_hedm_instrument instr = create_hedm_instrument() if HexrdConfig().apply_pixel_solid_angle_correction: @@ -862,7 +874,7 @@ def images_dict(self): def raw_masks_dict(self): """Get a masks dict""" # We must ensure that we are using raw masks - from hexrd.ui.create_raw_mask import rebuild_raw_masks + from hexrdgui.create_raw_mask import rebuild_raw_masks prev_masks = copy.deepcopy(self.masks) try: rebuild_raw_masks() @@ -896,7 +908,7 @@ def masked_images_dict(self): def create_masked_images_dict(self, fill_value=0): """Get an images dict where masks have been applied""" - from hexrd.ui.create_hedm_instrument import create_hedm_instrument + from hexrdgui.create_hedm_instrument import create_hedm_instrument images_dict = self.images_dict instr = create_hedm_instrument() @@ -1013,7 +1025,7 @@ def read_file(f): return self.config['instrument'] def save_instrument_config(self, output_file): - from hexrd.ui.create_hedm_instrument import create_hedm_instrument + from hexrdgui.create_hedm_instrument import create_hedm_instrument styles = { '.yml': 'yaml', @@ -1563,14 +1575,14 @@ def rename_detector(self, old_name, new_name): @property def available_default_materials(self): - module = hexrd.ui.resources.materials + module = hexrdgui.resources.materials with resource_loader.path(module, 'materials.h5') as file_path: with h5py.File(file_path) as f: return list(f.keys()) # This section is for materials configuration def load_default_material(self, name): - module = hexrd.ui.resources.materials + module = hexrdgui.resources.materials materials = self.materials with resource_loader.path(module, 'materials.h5') as file_path: materials[name] = Material(name, file_path) @@ -2120,7 +2132,7 @@ def custom_polar_tth_distortion_object_serialized(self): def custom_polar_tth_distortion_object_serialized(self, v): obj = None if v is not None: - from hexrd.ui.polar_distortion_object import PolarDistortionObject + from hexrdgui.polar_distortion_object import PolarDistortionObject active = v['active'] obj = PolarDistortionObject.deserialize(v['serialized']) diff --git a/hexrd/ui/hidden_bar_tab_widget.py b/hexrdgui/hidden_bar_tab_widget.py similarity index 90% rename from hexrd/ui/hidden_bar_tab_widget.py rename to hexrdgui/hidden_bar_tab_widget.py index 0a04d8040..6a49b2b15 100644 --- a/hexrd/ui/hidden_bar_tab_widget.py +++ b/hexrdgui/hidden_bar_tab_widget.py @@ -1,5 +1,5 @@ -from PySide2.QtCore import QTimer -from PySide2.QtWidgets import QTabWidget +from PySide6.QtCore import QTimer +from PySide6.QtWidgets import QTabWidget class HiddenBarTabWidget(QTabWidget): diff --git a/hexrd/ui/image_calculator.py b/hexrdgui/image_calculator.py similarity index 100% rename from hexrd/ui/image_calculator.py rename to hexrdgui/image_calculator.py diff --git a/hexrd/ui/image_calculator_dialog.py b/hexrdgui/image_calculator_dialog.py similarity index 94% rename from hexrd/ui/image_calculator_dialog.py rename to hexrdgui/image_calculator_dialog.py index bf332d2f0..4b61e7bc4 100644 --- a/hexrd/ui/image_calculator_dialog.py +++ b/hexrdgui/image_calculator_dialog.py @@ -1,14 +1,14 @@ from pathlib import Path -from PySide2.QtCore import QCoreApplication, QObject, Signal -from PySide2.QtWidgets import QFileDialog, QInputDialog, QMessageBox +from PySide6.QtCore import QCoreApplication, QObject, Signal +from PySide6.QtWidgets import QFileDialog, QInputDialog, QMessageBox from hexrd import imageseries -from hexrd.ui.image_calculator import IMAGE_CALCULATOR_OPERATIONS -from hexrd.ui.image_file_manager import ImageFileManager -from hexrd.ui.progress_dialog import ProgressDialog -from hexrd.ui.ui_loader import UiLoader +from hexrdgui.image_calculator import IMAGE_CALCULATOR_OPERATIONS +from hexrdgui.image_file_manager import ImageFileManager +from hexrdgui.progress_dialog import ProgressDialog +from hexrdgui.ui_loader import UiLoader class ImageCalculatorDialog(QObject): diff --git a/hexrd/ui/image_canvas.py b/hexrdgui/image_canvas.py similarity index 98% rename from hexrd/ui/image_canvas.py rename to hexrdgui/image_canvas.py index a65e308f0..4b2fd5fa9 100644 --- a/hexrd/ui/image_canvas.py +++ b/hexrdgui/image_canvas.py @@ -1,8 +1,8 @@ import copy import math -from PySide2.QtCore import QThreadPool, QTimer, Signal, Qt -from PySide2.QtWidgets import QFileDialog, QMessageBox +from PySide6.QtCore import QThreadPool, QTimer, Signal, Qt +from PySide6.QtWidgets import QFileDialog, QMessageBox from matplotlib.backends.backend_qt5agg import FigureCanvas @@ -14,16 +14,16 @@ import numpy as np -from hexrd.ui.async_worker import AsyncWorker -from hexrd.ui.calibration.cartesian_plot import cartesian_viewer -from hexrd.ui.calibration.polar_plot import polar_viewer -from hexrd.ui.calibration.raw_iviewer import raw_iviewer -from hexrd.ui.calibration.stereo_plot import stereo_viewer -from hexrd.ui.constants import OverlayType, PolarXAxisType, ViewType -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.snip_viewer_dialog import SnipViewerDialog -from hexrd.ui import utils -from hexrd.ui.utils.conversions import ( +from hexrdgui.async_worker import AsyncWorker +from hexrdgui.calibration.cartesian_plot import cartesian_viewer +from hexrdgui.calibration.polar_plot import polar_viewer +from hexrdgui.calibration.raw_iviewer import raw_iviewer +from hexrdgui.calibration.stereo_plot import stereo_viewer +from hexrdgui.constants import OverlayType, PolarXAxisType, ViewType +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.snip_viewer_dialog import SnipViewerDialog +from hexrdgui import utils +from hexrdgui.utils.conversions import ( angles_to_stereo, cart_to_angles, cart_to_pixels, q_to_tth, tth_to_q, ) @@ -65,9 +65,6 @@ def __init__(self, parent=None, image_names=None): ) self.polar_res_config = HexrdConfig().config['image']['polar'].copy() - # Set up our async stuff - self.thread_pool = QThreadPool(parent) - if image_names is not None: self.load_images(image_names) @@ -103,6 +100,10 @@ def setup_connections(self): HexrdConfig().beam_energy_modified.connect( self.on_beam_energy_modified) + @property + def thread_pool(self): + return QThreadPool.globalInstance() + def __del__(self): # This is so that the figure can be cleaned up plt.close(self.figure) diff --git a/hexrd/ui/image_file_manager.py b/hexrdgui/image_file_manager.py similarity index 96% rename from hexrd/ui/image_file_manager.py rename to hexrdgui/image_file_manager.py index b0326948c..de9073143 100644 --- a/hexrd/ui/image_file_manager.py +++ b/hexrdgui/image_file_manager.py @@ -5,14 +5,14 @@ import yaml import h5py -from PySide2.QtWidgets import QMessageBox +from PySide6.QtWidgets import QMessageBox from hexrd import imageseries -from hexrd.ui import constants -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.load_hdf5_dialog import LoadHDF5Dialog -from hexrd.ui.singletons import Singleton +from hexrdgui import constants +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.load_hdf5_dialog import LoadHDF5Dialog +from hexrdgui.singletons import Singleton class ImageFileManager(metaclass=Singleton): @@ -172,7 +172,7 @@ def hdf5_path_exists(self, f): def path_prompt(self, f): path_dialog = LoadHDF5Dialog(f) if path_dialog.paths: - path_dialog.ui.exec_() + path_dialog.ui.exec() group, data, remember = path_dialog.results() self.path = [group, data] self.remember = remember diff --git a/hexrd/ui/image_load_manager.py b/hexrdgui/image_load_manager.py similarity index 96% rename from hexrd/ui/image_load_manager.py rename to hexrdgui/image_load_manager.py index 2c82df3f7..10beca8bc 100644 --- a/hexrd/ui/image_load_manager.py +++ b/hexrdgui/image_load_manager.py @@ -7,18 +7,18 @@ import numpy as np -from PySide2.QtCore import QObject, QThreadPool, Signal -from PySide2.QtWidgets import QMessageBox +from PySide6.QtCore import QObject, QThreadPool, Signal +from PySide6.QtWidgets import QMessageBox from hexrd import imageseries from hexrd.imageseries.omega import OmegaImageSeries -from hexrd.ui.async_worker import AsyncWorker -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.image_file_manager import ImageFileManager -from hexrd.ui.progress_dialog import ProgressDialog -from hexrd.ui.constants import * -from hexrd.ui.singletons import QSingleton +from hexrdgui.async_worker import AsyncWorker +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.image_file_manager import ImageFileManager +from hexrdgui.progress_dialog import ProgressDialog +from hexrdgui.constants import * +from hexrdgui.singletons import QSingleton class NoEmptyFramesException(Exception): @@ -37,9 +37,13 @@ class ImageLoadManager(QObject, metaclass=QSingleton): enable_transforms = Signal() def __init__(self): - super(ImageLoadManager, self).__init__(None) + super().__init__(None) self.transformed_images = False + @property + def thread_pool(self): + return QThreadPool.globalInstance() + def load_images(self, fnames): files = self.explict_selection(fnames) manual = False @@ -123,6 +127,9 @@ def match_selected_files(self, fnames, search): return files def read_data(self, files=None, data=None, ui_parent=None, **kwargs): + # Make sure this is reset to zero when data is being read + HexrdConfig().current_imageseries_idx = 0 + # When this is pressed read in a complete set of data for all detectors. # Run the imageseries processing in a background thread and display a # loading dialog @@ -140,7 +147,6 @@ def begin_processing(self, postprocess=False): self.live_update_status.emit(False) # Create threads and loading dialog - thread_pool = QThreadPool(self.ui_parent) progress_dialog = ProgressDialog(self.ui_parent) progress_dialog.setWindowTitle('Loading Processed Imageseries') self.progress_text.connect(progress_dialog.setLabelText) @@ -148,13 +154,13 @@ def begin_processing(self, postprocess=False): # Start processing in background worker = AsyncWorker(self.process_ims, postprocess) - thread_pool.start(worker) + self.thread_pool.start(worker) worker.signals.progress.connect(progress_dialog.setValue) # On completion load imageseries nd close loading dialog worker.signals.result.connect(self.finish_processing_ims) worker.signals.finished.connect(progress_dialog.accept) - progress_dialog.exec_() + progress_dialog.exec() def set_state(self, state=None): if state is None: diff --git a/hexrd/ui/image_mode_widget.py b/hexrdgui/image_mode_widget.py similarity index 98% rename from hexrd/ui/image_mode_widget.py rename to hexrdgui/image_mode_widget.py index 77a37bd4c..deb71b343 100644 --- a/hexrd/ui/image_mode_widget.py +++ b/hexrdgui/image_mode_widget.py @@ -2,14 +2,14 @@ import multiprocessing import numpy as np -from PySide2.QtCore import QObject, QTimer, Signal - -from hexrd.ui.azimuthal_overlay_manager import AzimuthalOverlayManager -from hexrd.ui.constants import PolarXAxisType, ViewType -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from PySide6.QtCore import QObject, QTimer, Signal + +from hexrdgui.azimuthal_overlay_manager import AzimuthalOverlayManager +from hexrdgui.constants import PolarXAxisType, ViewType +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals TAB_INDEX_TO_VIEW_MODE = { 0: ViewType.raw, diff --git a/hexrd/ui/image_series_toolbar.py b/hexrdgui/image_series_toolbar.py similarity index 94% rename from hexrd/ui/image_series_toolbar.py rename to hexrdgui/image_series_toolbar.py index d5be6ee34..4052fbb0f 100644 --- a/hexrd/ui/image_series_toolbar.py +++ b/hexrdgui/image_series_toolbar.py @@ -1,11 +1,11 @@ from pathlib import Path -from PySide2.QtCore import Qt -from PySide2.QtWidgets import QGridLayout, QLabel, QSlider, QSpinBox, QWidget -from PySide2.QtGui import QPixmap -from hexrd.ui import resource_loader +from PySide6.QtCore import Qt +from PySide6.QtWidgets import QGridLayout, QLabel, QSlider, QSpinBox, QWidget +from PySide6.QtGui import QPixmap +from hexrdgui import resource_loader -import hexrd.ui.resources.icons -from hexrd.ui.hexrd_config import HexrdConfig +import hexrdgui.resources.icons +from hexrdgui.hexrd_config import HexrdConfig class ImageSeriesInfoToolbar(QWidget): @@ -28,7 +28,7 @@ def setup_connections(self): def create_widget(self): self.widget = QWidget(self.parent()) - data = resource_loader.load_resource(hexrd.ui.resources.icons, + data = resource_loader.load_resource(hexrdgui.resources.icons, 'file.svg', binary=True) pixmap = QPixmap() pixmap.loadFromData(data, 'svg') diff --git a/hexrd/ui/image_stack_dialog.py b/hexrdgui/image_stack_dialog.py similarity index 98% rename from hexrd/ui/image_stack_dialog.py rename to hexrdgui/image_stack_dialog.py index b9d20ebce..e1df5644c 100644 --- a/hexrd/ui/image_stack_dialog.py +++ b/hexrdgui/image_stack_dialog.py @@ -3,14 +3,14 @@ import numpy as np from pathlib import Path -from PySide2.QtCore import QObject, Signal, Qt -from PySide2.QtWidgets import QFileDialog, QMessageBox, QTableWidgetItem, QTreeWidgetItem, QAbstractItemView - -from hexrd.ui.constants import MAXIMUM_OMEGA_RANGE -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.image_file_manager import ImageFileManager -from hexrd.ui.utils.dialog import add_help_url +from PySide6.QtCore import QObject, Signal, Qt +from PySide6.QtWidgets import QFileDialog, QMessageBox, QTableWidgetItem, QTreeWidgetItem, QAbstractItemView + +from hexrdgui.constants import MAXIMUM_OMEGA_RANGE +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.ui_loader import UiLoader +from hexrdgui.image_file_manager import ImageFileManager +from hexrdgui.utils.dialog import add_help_url class ImageStackDialog(QObject): diff --git a/hexrd/ui/image_tab_widget.py b/hexrdgui/image_tab_widget.py similarity index 96% rename from hexrd/ui/image_tab_widget.py rename to hexrdgui/image_tab_widget.py index dbc7cf05f..0be2f2d14 100644 --- a/hexrd/ui/image_tab_widget.py +++ b/hexrdgui/image_tab_widget.py @@ -1,15 +1,15 @@ -from PySide2.QtCore import Signal, Slot, Qt -from PySide2.QtWidgets import QMessageBox, QTabWidget, QHBoxLayout +from PySide6.QtCore import Signal, Slot, Qt +from PySide6.QtWidgets import QMessageBox, QTabWidget, QHBoxLayout import numpy as np -from hexrd.ui.constants import PAN, ViewType, ZOOM -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.image_canvas import ImageCanvas -from hexrd.ui.image_series_toolbar import ImageSeriesToolbar, ImageSeriesInfoToolbar -from hexrd.ui.navigation_toolbar import NavigationToolbar -from hexrd.ui.utils.conversions import stereo_to_angles, tth_to_q -from hexrd.ui import utils +from hexrdgui.constants import PAN, ViewType, ZOOM +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.image_canvas import ImageCanvas +from hexrdgui.image_series_toolbar import ImageSeriesToolbar, ImageSeriesInfoToolbar +from hexrdgui.navigation_toolbar import NavigationToolbar +from hexrdgui.utils.conversions import stereo_to_angles, tth_to_q +from hexrdgui import utils class ImageTabWidget(QTabWidget): @@ -434,7 +434,7 @@ def export_to_maud(self, filename): if __name__ == '__main__': import sys - from PySide2.QtWidgets import QApplication + from PySide6.QtWidgets import QApplication app = QApplication(sys.argv) diff --git a/hexrd/ui/indexing/README.md b/hexrdgui/indexing/README.md similarity index 100% rename from hexrd/ui/indexing/README.md rename to hexrdgui/indexing/README.md diff --git a/hexrd/ui/indexing/__init__.py b/hexrdgui/indexing/__init__.py similarity index 100% rename from hexrd/ui/indexing/__init__.py rename to hexrdgui/indexing/__init__.py diff --git a/hexrd/ui/indexing/create_config.py b/hexrdgui/indexing/create_config.py similarity index 96% rename from hexrd/ui/indexing/create_config.py rename to hexrdgui/indexing/create_config.py index 5224e1af3..5327b301f 100644 --- a/hexrd/ui/indexing/create_config.py +++ b/hexrdgui/indexing/create_config.py @@ -7,8 +7,8 @@ from hexrd.config.material import MaterialConfig from hexrd.config.instrument import Instrument as InstrumentConfig -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.hexrd_config import HexrdConfig +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.hexrd_config import HexrdConfig def get_indexing_material(): diff --git a/hexrd/ui/indexing/fit_grains_options_dialog.py b/hexrdgui/indexing/fit_grains_options_dialog.py similarity index 96% rename from hexrd/ui/indexing/fit_grains_options_dialog.py rename to hexrdgui/indexing/fit_grains_options_dialog.py index 7ddd227e0..986f8cd95 100644 --- a/hexrd/ui/indexing/fit_grains_options_dialog.py +++ b/hexrdgui/indexing/fit_grains_options_dialog.py @@ -1,24 +1,24 @@ from pathlib import Path -from PySide2.QtCore import ( +from PySide6.QtCore import ( QItemSelectionModel, QModelIndex, QObject, Qt, Signal) -from PySide2.QtWidgets import ( +from PySide6.QtWidgets import ( QDialogButtonBox, QFileDialog, QHeaderView, QMessageBox ) import numpy as np -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.indexing.grains_table_model import GrainsTableModel -from hexrd.ui.plot_grains import plot_grains -from hexrd.ui.reflections_table import ReflectionsTable -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.indexing.grains_table_model import GrainsTableModel +from hexrdgui.plot_grains import plot_grains +from hexrdgui.reflections_table import ReflectionsTable +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url -from hexrd.ui.indexing.fit_grains_tolerances_model import ( +from hexrdgui.indexing.fit_grains_tolerances_model import ( FitGrainsToleranceModel) -from hexrd.ui.indexing.utils import hkls_missing_in_list +from hexrdgui.indexing.utils import hkls_missing_in_list class FitGrainsOptionsDialog(QObject): diff --git a/hexrd/ui/indexing/fit_grains_results_dialog.py b/hexrdgui/indexing/fit_grains_results_dialog.py similarity index 97% rename from hexrd/ui/indexing/fit_grains_results_dialog.py rename to hexrdgui/indexing/fit_grains_results_dialog.py index 084b66a9c..4207da796 100644 --- a/hexrd/ui/indexing/fit_grains_results_dialog.py +++ b/hexrdgui/indexing/fit_grains_results_dialog.py @@ -12,20 +12,20 @@ from matplotlib.backends.backend_qt5agg import FigureCanvas from matplotlib.figure import Figure -from PySide2.QtCore import QObject, QTimer, Qt, Signal -from PySide2.QtWidgets import QFileDialog, QMenu, QMessageBox, QSizePolicy +from PySide6.QtCore import QObject, QTimer, Qt, Signal +from PySide6.QtWidgets import QFileDialog, QMenu, QMessageBox, QSizePolicy from hexrd.matrixutil import vecMVToSymm from hexrd.rotations import rotMatOfExpMap -from hexrd.ui import constants -from hexrd.ui.async_runner import AsyncRunner -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.indexing.grains_table_model import GrainsTableModel -from hexrd.ui.navigation_toolbar import NavigationToolbar -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui import constants +from hexrdgui.async_runner import AsyncRunner +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.indexing.grains_table_model import GrainsTableModel +from hexrdgui.navigation_toolbar import NavigationToolbar +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url COORDS_SLICE = slice(6, 9) @@ -753,8 +753,8 @@ def on_export_workflow_clicked(self): self.async_runner.run(self._save_workflow_files, selected_directory) if __name__ == '__main__': - from PySide2.QtCore import QCoreApplication - from PySide2.QtWidgets import QApplication + from PySide6.QtCore import QCoreApplication + from PySide6.QtWidgets import QApplication # User specifies grains.out file if (len(sys.argv) < 2): @@ -778,4 +778,4 @@ def on_export_workflow_clicked(self): dialog.ui.resize(1200, 800) dialog.finished.connect(app.quit) dialog.show() - app.exec_() + app.exec() diff --git a/hexrd/ui/indexing/fit_grains_select_dialog.py b/hexrdgui/indexing/fit_grains_select_dialog.py similarity index 94% rename from hexrd/ui/indexing/fit_grains_select_dialog.py rename to hexrdgui/indexing/fit_grains_select_dialog.py index 342692f1b..5abc06e4b 100644 --- a/hexrd/ui/indexing/fit_grains_select_dialog.py +++ b/hexrdgui/indexing/fit_grains_select_dialog.py @@ -2,13 +2,13 @@ import numpy as np -from PySide2.QtCore import QObject, Signal -from PySide2.QtWidgets import QFileDialog, QMessageBox +from PySide6.QtCore import QObject, Signal +from PySide6.QtWidgets import QFileDialog, QMessageBox -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.indexing.utils import generate_grains_table -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.indexing.utils import generate_grains_table +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals class FitGrainsSelectDialog(QObject): diff --git a/hexrd/ui/indexing/fit_grains_tolerances_model.py b/hexrdgui/indexing/fit_grains_tolerances_model.py similarity index 98% rename from hexrd/ui/indexing/fit_grains_tolerances_model.py rename to hexrdgui/indexing/fit_grains_tolerances_model.py index a3ffa7f90..b406b4cf9 100644 --- a/hexrd/ui/indexing/fit_grains_tolerances_model.py +++ b/hexrdgui/indexing/fit_grains_tolerances_model.py @@ -1,4 +1,4 @@ -from PySide2.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal +from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal class FitGrainsToleranceModel(QAbstractTableModel): diff --git a/hexrd/ui/indexing/fit_grains_tree_view_dialog.py b/hexrdgui/indexing/fit_grains_tree_view_dialog.py similarity index 71% rename from hexrd/ui/indexing/fit_grains_tree_view_dialog.py rename to hexrdgui/indexing/fit_grains_tree_view_dialog.py index db0dbaf5b..05f3b89dd 100644 --- a/hexrd/ui/indexing/fit_grains_tree_view_dialog.py +++ b/hexrdgui/indexing/fit_grains_tree_view_dialog.py @@ -1,5 +1,5 @@ -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.tree_views.dict_tree_view import DictTreeViewDialog +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.tree_views.dict_tree_view import DictTreeViewDialog class FitGrainsTreeViewDialog(DictTreeViewDialog): diff --git a/hexrd/ui/indexing/grains_table_model.py b/hexrdgui/indexing/grains_table_model.py similarity index 98% rename from hexrd/ui/indexing/grains_table_model.py rename to hexrdgui/indexing/grains_table_model.py index 79168e54d..cb0cfb5b9 100644 --- a/hexrd/ui/indexing/grains_table_model.py +++ b/hexrdgui/indexing/grains_table_model.py @@ -1,6 +1,6 @@ import numpy as np -from PySide2.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal +from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal class GrainsTableModel(QAbstractTableModel): diff --git a/hexrd/ui/indexing/grains_table_view.py b/hexrdgui/indexing/grains_table_view.py similarity index 94% rename from hexrd/ui/indexing/grains_table_view.py rename to hexrdgui/indexing/grains_table_view.py index e08422c54..b5aeced39 100644 --- a/hexrd/ui/indexing/grains_table_view.py +++ b/hexrdgui/indexing/grains_table_view.py @@ -1,14 +1,14 @@ import numpy as np -from PySide2.QtCore import QSortFilterProxyModel, Qt, Signal -from PySide2.QtGui import QCursor -from PySide2.QtWidgets import QMenu, QMessageBox, QTableView +from PySide6.QtCore import QSortFilterProxyModel, Qt, Signal +from PySide6.QtGui import QCursor +from PySide6.QtWidgets import QMenu, QMessageBox, QTableView -from hexrd.ui.async_runner import AsyncRunner -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.indexing.create_config import create_indexing_config -from hexrd.ui.indexing.view_spots_dialog import ViewSpotsDialog -from hexrd.ui.table_selector_widget import TableSingleRowSelectorDialog +from hexrdgui.async_runner import AsyncRunner +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.indexing.create_config import create_indexing_config +from hexrdgui.indexing.view_spots_dialog import ViewSpotsDialog +from hexrdgui.table_selector_widget import TableSingleRowSelectorDialog # Sortable columns are grain id, completeness, chi^2, and t_vec_c @@ -55,7 +55,7 @@ def add_actions(d): if not actions: return super().contextMenuEvent(event) - action_chosen = menu.exec_(QCursor.pos()) + action_chosen = menu.exec(QCursor.pos()) if action_chosen is None: # No action chosen @@ -157,7 +157,7 @@ def select_tolerance_id(self): dialog.table.horizontal_headers = headers dialog.setWindowTitle('Select tolerances to use') - if not dialog.exec_(): + if not dialog.exec(): return False self.selected_tol_id = dialog.selected_row diff --git a/hexrd/ui/indexing/indexing_results_dialog.py b/hexrdgui/indexing/indexing_results_dialog.py similarity index 95% rename from hexrd/ui/indexing/indexing_results_dialog.py rename to hexrdgui/indexing/indexing_results_dialog.py index 143b5bf9c..b81e8de47 100644 --- a/hexrd/ui/indexing/indexing_results_dialog.py +++ b/hexrdgui/indexing/indexing_results_dialog.py @@ -4,19 +4,19 @@ from matplotlib.figure import Figure import numpy as np -from PySide2.QtCore import Signal, QObject, Qt, QTimer -from PySide2.QtWidgets import QSizePolicy +from PySide6.QtCore import Signal, QObject, Qt, QTimer +from PySide6.QtWidgets import QSizePolicy from hexrd.transforms import xfcapi -from hexrd.ui.color_map_editor import ColorMapEditor -from hexrd.ui.create_hedm_instrument import create_hedm_instrument -from hexrd.ui.grains_viewer_dialog import GrainsViewerDialog -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.navigation_toolbar import NavigationToolbar -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui.color_map_editor import ColorMapEditor +from hexrdgui.create_hedm_instrument import create_hedm_instrument +from hexrdgui.grains_viewer_dialog import GrainsViewerDialog +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.navigation_toolbar import NavigationToolbar +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url class IndexingResultsDialog(QObject): @@ -78,9 +78,9 @@ def show_all_grains_toggled(self): self.update_enable_states() self.update_spots() - def exec_(self): + def exec(self): self.update_plot() - self.ui.exec_() + self.ui.exec() def show(self): self.update_plot() diff --git a/hexrd/ui/indexing/indexing_tree_view_dialog.py b/hexrdgui/indexing/indexing_tree_view_dialog.py similarity index 77% rename from hexrd/ui/indexing/indexing_tree_view_dialog.py rename to hexrdgui/indexing/indexing_tree_view_dialog.py index bb1ebb92f..e2821431e 100644 --- a/hexrd/ui/indexing/indexing_tree_view_dialog.py +++ b/hexrdgui/indexing/indexing_tree_view_dialog.py @@ -1,11 +1,11 @@ import yaml -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.resource_loader import load_resource -from hexrd.ui.tree_views.dict_tree_view import DictTreeViewDialog -from hexrd.ui.utils import lazy_property +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.resource_loader import load_resource +from hexrdgui.tree_views.dict_tree_view import DictTreeViewDialog +from hexrdgui.utils import lazy_property -import hexrd.ui.resources.indexing as indexing_resources +import hexrdgui.resources.indexing as indexing_resources class IndexingTreeViewDialog(DictTreeViewDialog): diff --git a/hexrd/ui/indexing/ome_maps_select_dialog.py b/hexrdgui/indexing/ome_maps_select_dialog.py similarity index 94% rename from hexrd/ui/indexing/ome_maps_select_dialog.py rename to hexrdgui/indexing/ome_maps_select_dialog.py index 6a95ed1c0..9228ba8c1 100644 --- a/hexrd/ui/indexing/ome_maps_select_dialog.py +++ b/hexrdgui/indexing/ome_maps_select_dialog.py @@ -1,13 +1,13 @@ import os -from PySide2.QtCore import Signal, QObject -from PySide2.QtWidgets import QFileDialog, QMessageBox - -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.reflections_table import ReflectionsTable -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from PySide6.QtCore import Signal, QObject +from PySide6.QtWidgets import QFileDialog, QMessageBox + +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.reflections_table import ReflectionsTable +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url class OmeMapsSelectDialog(QObject): diff --git a/hexrd/ui/indexing/ome_maps_viewer_dialog.py b/hexrdgui/indexing/ome_maps_viewer_dialog.py similarity index 97% rename from hexrd/ui/indexing/ome_maps_viewer_dialog.py rename to hexrdgui/indexing/ome_maps_viewer_dialog.py index 645aff3d1..0a3c34a83 100644 --- a/hexrd/ui/indexing/ome_maps_viewer_dialog.py +++ b/hexrdgui/indexing/ome_maps_viewer_dialog.py @@ -6,8 +6,8 @@ import numpy as np import yaml -from PySide2.QtCore import Signal, QObject, QTimer, Qt -from PySide2.QtWidgets import ( +from PySide6.QtCore import Signal, QObject, QTimer, Qt +from PySide6.QtWidgets import ( QCheckBox, QComboBox, QDoubleSpinBox, QFileDialog, QMessageBox, QSizePolicy, QSpinBox ) @@ -18,19 +18,19 @@ ) from hexrd.imageutil import find_peaks_2d -from hexrd.ui import resource_loader +from hexrdgui import resource_loader -from hexrd.ui.color_map_editor import ColorMapEditor -from hexrd.ui.hand_picked_fibers_widget import HandPickedFibersWidget -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.navigation_toolbar import NavigationToolbar -from hexrd.ui.select_items_widget import SelectItemsWidget -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui.color_map_editor import ColorMapEditor +from hexrdgui.hand_picked_fibers_widget import HandPickedFibersWidget +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.navigation_toolbar import NavigationToolbar +from hexrdgui.select_items_widget import SelectItemsWidget +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url -import hexrd.ui.constants -import hexrd.ui.resources.indexing +import hexrdgui.constants +import hexrdgui.resources.indexing DEFAULT_FWHM = filter_stdev_DFLT * sigma_to_fwhm @@ -247,7 +247,7 @@ def validate(self): raise ValidationException(msg) def setup_widget_paths(self): - text = resource_loader.load_resource(hexrd.ui.resources.indexing, + text = resource_loader.load_resource(hexrdgui.resources.indexing, 'gui_config_maps.yml') self.gui_config_maps = yaml.load(text, Loader=yaml.FullLoader) diff --git a/hexrd/ui/indexing/run.py b/hexrdgui/indexing/run.py similarity index 94% rename from hexrd/ui/indexing/run.py rename to hexrdgui/indexing/run.py index 9e69a2e99..329ad3fe5 100644 --- a/hexrd/ui/indexing/run.py +++ b/hexrdgui/indexing/run.py @@ -2,8 +2,8 @@ import numpy as np -from PySide2.QtCore import QObject, QThreadPool, Qt, Signal -from PySide2.QtWidgets import QMessageBox +from PySide6.QtCore import QObject, QThreadPool, Qt, Signal +from PySide6.QtWidgets import QMessageBox from hexrd import indexer, instrument from hexrd.cli.find_orientations import write_scored_orientations @@ -15,20 +15,20 @@ from hexrd.fitgrains import fit_grains from hexrd.xrdutil import EtaOmeMaps -from hexrd.ui.async_worker import AsyncWorker -from hexrd.ui.hexrd_config import HexrdConfig -from hexrd.ui.indexing.create_config import ( +from hexrdgui.async_worker import AsyncWorker +from hexrdgui.hexrd_config import HexrdConfig +from hexrdgui.indexing.create_config import ( create_indexing_config, get_indexing_material ) -from hexrd.ui.indexing.fit_grains_options_dialog import FitGrainsOptionsDialog -from hexrd.ui.indexing.fit_grains_results_dialog import FitGrainsResultsDialog -from hexrd.ui.indexing.fit_grains_select_dialog import FitGrainsSelectDialog -from hexrd.ui.indexing.indexing_results_dialog import IndexingResultsDialog -from hexrd.ui.indexing.ome_maps_select_dialog import OmeMapsSelectDialog -from hexrd.ui.indexing.ome_maps_viewer_dialog import OmeMapsViewerDialog -from hexrd.ui.indexing.utils import generate_grains_table, hkls_missing_in_list -from hexrd.ui.progress_dialog import ProgressDialog -from hexrd.ui.utils import format_big_int +from hexrdgui.indexing.fit_grains_options_dialog import FitGrainsOptionsDialog +from hexrdgui.indexing.fit_grains_results_dialog import FitGrainsResultsDialog +from hexrdgui.indexing.fit_grains_select_dialog import FitGrainsSelectDialog +from hexrdgui.indexing.indexing_results_dialog import IndexingResultsDialog +from hexrdgui.indexing.ome_maps_select_dialog import OmeMapsSelectDialog +from hexrdgui.indexing.ome_maps_viewer_dialog import OmeMapsViewerDialog +from hexrdgui.indexing.utils import generate_grains_table, hkls_missing_in_list +from hexrdgui.progress_dialog import ProgressDialog +from hexrdgui.utils import format_big_int class Runner(QObject): @@ -40,7 +40,6 @@ def __init__(self, parent=None): super().__init__(parent) self.parent = parent - self.thread_pool = QThreadPool(self.parent) self.progress_dialog = ProgressDialog(self.parent) self.clear_cancel_tracker() @@ -50,6 +49,10 @@ def setup_connections(self): self.progress_text.connect(self.progress_dialog.setLabelText) self.accept_progress_signal.connect(self.progress_dialog.accept) + @property + def thread_pool(self): + return QThreadPool.globalInstance() + def update_progress_text(self, text): self.progress_text.emit(text) @@ -67,7 +70,7 @@ def on_async_error(self, t): msg = f'An ERROR occurred: {exctype}: {value}.' msg_box = QMessageBox(QMessageBox.Critical, 'Error', msg) msg_box.setDetailedText(traceback) - msg_box.exec_() + msg_box.exec() def reset_cancel_tracker(self): self.cancel_tracker = CancelTracker() @@ -178,7 +181,7 @@ def ome_maps_selected(self): worker.signals.result.connect(self.ome_maps_loaded) worker.signals.error.connect(self.on_async_error) worker.signals.finished.connect(self.accept_progress) - self.progress_dialog.exec_() + self.progress_dialog.exec() def run_eta_ome_maps(self, config): self.ome_maps = generate_eta_ome_maps(config, save=False) @@ -239,7 +242,7 @@ def ome_maps_viewed(self): worker.signals.result.connect(self.orientation_fibers_generated) worker.signals.error.connect(self.on_async_error) - self.progress_dialog.exec_() + self.progress_dialog.exec() def generate_orientation_fibers(self, config): # Generate the orientation fibers @@ -321,9 +324,13 @@ def indexer_finished(self): worker = AsyncWorker(self.run_cluster_functions) self.thread_pool.start(worker) - worker.signals.result.connect(self.confirm_indexing_results, - Qt.QueuedConnection) - worker.signals.finished.connect(self.accept_progress) + def on_finished(): + # Since this is a QueuedConnection, we must accept the progress + # before proceeding. + self.accept_progress() + self.confirm_indexing_results() + + worker.signals.result.connect(on_finished, Qt.QueuedConnection) worker.signals.error.connect(self.on_async_error) @property @@ -520,7 +527,7 @@ def fit_grains_options_accepted(self): self.progress_dialog.cancel_visible = True self.progress_dialog.cancel_clicked.connect(self.on_cancel_clicked) - self.progress_dialog.exec_() + self.progress_dialog.exec() def run_fit_grains(self): cfg = create_indexing_config() diff --git a/hexrd/ui/indexing/spot_montage.py b/hexrdgui/indexing/spot_montage.py similarity index 100% rename from hexrd/ui/indexing/spot_montage.py rename to hexrdgui/indexing/spot_montage.py diff --git a/hexrd/ui/indexing/utils.py b/hexrdgui/indexing/utils.py similarity index 100% rename from hexrd/ui/indexing/utils.py rename to hexrdgui/indexing/utils.py diff --git a/hexrd/ui/indexing/view_spots_dialog.py b/hexrdgui/indexing/view_spots_dialog.py similarity index 96% rename from hexrd/ui/indexing/view_spots_dialog.py rename to hexrdgui/indexing/view_spots_dialog.py index 65864396c..0fb4eab91 100644 --- a/hexrd/ui/indexing/view_spots_dialog.py +++ b/hexrdgui/indexing/view_spots_dialog.py @@ -1,5 +1,5 @@ -from PySide2.QtCore import Qt -from PySide2.QtWidgets import QSizePolicy +from PySide6.QtCore import Qt +from PySide6.QtWidgets import QSizePolicy from matplotlib.backends.backend_qt5agg import FigureCanvas from matplotlib.figure import Figure @@ -7,13 +7,13 @@ from hexrd.instrument import centers_of_edge_vec -from hexrd.ui.indexing.spot_montage import ( +from hexrdgui.indexing.spot_montage import ( create_labels, extract_hkls_from_spots_data, montage, SPOTS_DATA_MAP ) -from hexrd.ui.navigation_toolbar import NavigationToolbar -from hexrd.ui.ui_loader import UiLoader -from hexrd.ui.utils import block_signals -from hexrd.ui.utils.dialog import add_help_url +from hexrdgui.navigation_toolbar import NavigationToolbar +from hexrdgui.ui_loader import UiLoader +from hexrdgui.utils import block_signals +from hexrdgui.utils.dialog import add_help_url class ViewSpotsDialog: @@ -322,7 +322,7 @@ def _find_data(all_spots, grain_id, det_key, gvec_id, peak_id): import pickle import sys - from PySide2.QtWidgets import QApplication + from PySide6.QtWidgets import QApplication if len(sys.argv) < 2: sys.exit('Usage: