diff --git a/omc3_gui/segment_by_segment.py b/omc3_gui/segment_by_segment.py index bf33681..deb07e8 100644 --- a/omc3_gui/segment_by_segment.py +++ b/omc3_gui/segment_by_segment.py @@ -4,39 +4,39 @@ from qtpy import QtWidgets -from omc3_gui.segment_by_segment_matcher.constants import LHC_MODES +from omc3_gui.segment_by_segment_matcher.constants import LHC_YEARS from omc3_gui.segment_by_segment_matcher.main import SbSGuiMainController from omc3_gui.utils import log_handler LOGGER = logging.getLogger(__name__) -def main(lhc_mode=None, match_path=None, input_dir=None): +def main(lhc_year=None, match_path=None, input_dir=None): app = QtWidgets.QApplication(sys.argv) app.setStyle("fusion") main_controller = SbSGuiMainController() - if match_path is None or lhc_mode is None: - lhc_mode, match_path = main_controller.ask_for_initial_config( - lhc_mode, + if match_path is None or lhc_year is None: + lhc_year, match_path = main_controller.ask_for_initial_config( + lhc_year, match_path, ) - if match_path is None or lhc_mode is None: + if match_path is None or lhc_year is None: return match_path = Path(match_path) log_handler.add_file_handler(match_path) - if lhc_mode not in LHC_MODES: - raise ValueError(f"Invalid lhc mode, must be one of {LHC_MODES!s}") + if lhc_year not in LHC_YEARS: + raise ValueError(f"Invalid lhc mode, must be one of {LHC_YEARS!s}") LOGGER.info("-------------------- ") LOGGER.info("Configuration:") - LOGGER.info(f"- LHC mode: {lhc_mode!s}") + LOGGER.info(f"- LHC year: {lhc_year!s}") LOGGER.info(f"- Match output path: {match_path!s}") LOGGER.info("-------------------- ") main_controller.set_match_path(match_path) - main_controller.set_lhc_mode(lhc_mode) + main_controller.set_lhc_mode(lhc_year) main_controller.set_input_dir(input_dir) main_controller.show_view() sys.exit(app.exec_()) if __name__ == "__main__": - main(lhc_mode="lhcb1", match_path=Path("/mnt/volume/jdilly/temp/")) + main(lhc_year="2018", match_path=Path("/mnt/volume/jdilly/temp/")) diff --git a/omc3_gui/segment_by_segment_matcher/constants.py b/omc3_gui/segment_by_segment_matcher/constants.py index 4115ff5..7ee5311 100644 --- a/omc3_gui/segment_by_segment_matcher/constants.py +++ b/omc3_gui/segment_by_segment_matcher/constants.py @@ -1,3 +1,5 @@ from omc3.model.accelerators import lhc -LHC_MODES = ["lhcb1", "lhcb2"] +MACHINE_OUTPUT_FOLDERS = ["LHCB1", "LHCB2"] + +LHC_YEARS = lhc.Lhc.get_parameters()["year"]["choices"] diff --git a/omc3_gui/segment_by_segment_matcher/main.py b/omc3_gui/segment_by_segment_matcher/main.py index 52bfe1b..b07be91 100644 --- a/omc3_gui/segment_by_segment_matcher/main.py +++ b/omc3_gui/segment_by_segment_matcher/main.py @@ -9,7 +9,11 @@ from omc3_gui.segment_by_segment_matcher.selection import SbSGuiMatcherTypeSelection from omc3_gui.segment_by_segment_matcher.widgets import InitialConfigPopup, LogDialog from omc3_gui.segment_by_segment_matcher.result_view import SbSGuiMatchResultView -from accwidgets.app_frame import ApplicationFrame + +try: + from accwidgets.app_frame import ApplicationFrame +except ImportError: + from qtpy.QtWidgets import QMainWindow as ApplicationFrame LOGGER = logging.getLogger(__name__) @@ -19,7 +23,12 @@ class SbSGuiMain(ApplicationFrame): WINDOW_TITLE = "Segment-by-Segment matcher GUI" def __init__(self, controller, *args, **kwargs): - super().__init__(*args, **kwargs) + kwargs["use_log_console"] = kwargs.get("use_log_console", True) + try: + super().__init__(*args, **kwargs) # CERN Application Frame + except TypeError: + del kwargs["use_log_console"] + super().__init__(*args, **kwargs) # QT Main window self._controller = controller self._active_background_dialog = None @@ -47,7 +56,7 @@ def _build_gui(self): view_menu = main_menu.addMenu("View") view_menu.addAction(self._get_tile_windows_action()) view_menu.addAction(self._get_cascade_windows_action()) - if self.log_console: + if getattr(self, "log_console"): self.log_console.console.expanded = False self.log_console.setFeatures( self.log_console.DockWidgetClosable | self.log_console.DockWidgetMovable @@ -206,7 +215,7 @@ def __init__(self, message, parent=None): class SbSGuiMainController(object): def __init__(self): - self._view = SbSGuiMain(self, use_log_console=True) + self._view = SbSGuiMain(self) self._match_path = None self._possible_measurements = {1: [], 2: []} self._input_dir = None @@ -403,7 +412,7 @@ def edit_corrections_file(self): self._watch_dir(self._match_path) def _watch_dir(self, directory): - self._active_watcher = QFileSystemWatcher([directory]) + self._active_watcher = QFileSystemWatcher([str(directory)]) self._active_watcher.directoryChanged.connect(self._match_dir_changed) def _launch_text_editor(self, file_path): diff --git a/omc3_gui/segment_by_segment_matcher/result_view.py b/omc3_gui/segment_by_segment_matcher/result_view.py index 870dd57..6458143 100644 --- a/omc3_gui/segment_by_segment_matcher/result_view.py +++ b/omc3_gui/segment_by_segment_matcher/result_view.py @@ -1,5 +1,5 @@ -from PyQt5 import QtWidgets -from PyQt5 import QtCore +from qtpy import QtWidgets +from qtpy import QtCore from matplotlib.backends.backend_qt5agg import ( FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolbar, diff --git a/omc3_gui/segment_by_segment_matcher/selection.py b/omc3_gui/segment_by_segment_matcher/selection.py index 1da2e6a..5af7401 100644 --- a/omc3_gui/segment_by_segment_matcher/selection.py +++ b/omc3_gui/segment_by_segment_matcher/selection.py @@ -1,6 +1,6 @@ import os -from PyQt5 import QtWidgets -from PyQt5.QtCore import Qt +from qtpy import QtWidgets +from qtpy.QtCore import Qt from omc3_gui.segment_by_segment_matcher.models.coupling import MatcherModelCoupling from omc3_gui.segment_by_segment_matcher.models.phase import MatcherModelPhase from omc3_gui.segment_by_segment_matcher.models.amplitude import MatcherModelAmp diff --git a/omc3_gui/segment_by_segment_matcher/widgets.py b/omc3_gui/segment_by_segment_matcher/widgets.py index 60b8a61..19c90de 100644 --- a/omc3_gui/segment_by_segment_matcher/widgets.py +++ b/omc3_gui/segment_by_segment_matcher/widgets.py @@ -81,14 +81,15 @@ def __init__(self, lhc_mode, match_path, parent=None): main_layout = QtWidgets.QVBoxLayout(self) self._lhc_mode_combo = QtWidgets.QComboBox() - self._lhc_mode_combo.addItems(constants.LHC_MODES) + self._lhc_mode_combo.addItems(constants.LHC_YEARS) if lhc_mode is not None: - if lhc_mode not in constants.LHC_MODES: - raise ValueError("Invalid lhc mode, must be one of " + - str(constants.LHC_MODES)) + if lhc_mode not in constants.LHC_YEARS: + raise ValueError( + f"Invalid lhc mode, must be one of {constants.LHC_YEARS!s}" + ) else: self._lhc_mode_combo.setCurrentIndex( - constants.LHC_MODES.index(lhc_mode) + constants.LHC_YEARS.index(lhc_mode) ) main_layout.addWidget(self._lhc_mode_combo) diff --git a/setup.py b/setup.py index 4287c90..3a6a51a 100644 --- a/setup.py +++ b/setup.py @@ -18,14 +18,14 @@ # Dependencies for the package itself DEPENDENCIES = [ f"omc3[optional]>={ABOUT_OMC3_GUI['__omc3_version__']}", - "PyQt5>=5.15.7", # Keep PyQT5 for now, until acc-py updates + "qtpy>=2.3.1", # runs with either PySide2/6 or PyQt5/6 ] # Extra dependencies EXTRA_DEPENDENCIES = { "cern": [ f"omc3[cern]>={ABOUT_OMC3_GUI['__omc3_version__']}", - # "accwidgets[app_frame,rbac,log_console,screenshot,graph]", + "accwidgets[app_frame,log_console]", # app_frame,rbac,log_console,screenshot,graph ], "test": [ "pytest>=5.2",