Skip to content

Commit

Permalink
fixes for python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
JoschD committed Jul 3, 2023
1 parent 89a58f9 commit 1e344a2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
22 changes: 11 additions & 11 deletions omc3_gui/segment_by_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"))
4 changes: 3 additions & 1 deletion omc3_gui/segment_by_segment_matcher/constants.py
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 14 additions & 5 deletions omc3_gui/segment_by_segment_matcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions omc3_gui/segment_by_segment_matcher/result_view.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions omc3_gui/segment_by_segment_matcher/selection.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions omc3_gui/segment_by_segment_matcher/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1e344a2

Please sign in to comment.