Skip to content

Commit

Permalink
Refactor marker parameters dialog (#86)
Browse files Browse the repository at this point in the history
Modularize, cleanup.
  • Loading branch information
dweindl authored Jan 16, 2025
1 parent 51a8491 commit 5c45e5e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 101 deletions.
4 changes: 3 additions & 1 deletion src/ccompass/CCMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,9 @@ def run(self):
)

elif event == "-marker_parameters-":
self.model.marker_params = PPMS.PPMS_exec_marker(
from .marker_parameters_dialog import show_dialog

self.model.marker_params = show_dialog(
self.model.marker_params
)

Expand Down
100 changes: 0 additions & 100 deletions src/ccompass/PPMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,106 +67,6 @@ def NN_default():
return params_default


def PPMS_exec_marker(params_old):
if params_old["how"] == "exclude":
how_exclude = True
how_majority = False
elif params_old["how"] == "majority":
how_exclude = False
how_majority = True

if params_old["what"] == "unite":
what_unite = True
what_intersect = False
if params_old["what"] == "intersect":
what_unite = False
what_intersect = True

marker_params = copy.deepcopy(params_old)

layout_PMM = [
[
sg.Text("discrepancies:\t"),
sg.Checkbox(
"exclude\t",
key="--PMM_exclude--",
default=how_exclude,
enable_events=True,
),
sg.Checkbox(
"take majority",
key="--PMM_majority--",
default=how_majority,
enable_events=True,
),
],
[
sg.Text("selection:\t"),
sg.Checkbox(
"unite\t",
key="--PMM_unite--",
default=what_unite,
enable_events=True,
),
sg.Checkbox(
"intersect",
key="--PMM_intersect--",
default=what_intersect,
enable_events=True,
),
],
[
sg.Button(
"OK",
key="--PMM_accept--",
disabled=False,
enable_events=True,
button_color="dark green",
),
sg.Button(
"Cancel",
key="--PMM_cancel--",
disabled=False,
enable_events=True,
button_color="black",
),
],
]

window_PMM = sg.Window("Marker Parameters", layout_PMM, size=(400, 100))

while True:
event_PMM, values_PMM = window_PMM.read()

if event_PMM == "--PMM_exclude--":
marker_params["how"] = "esclude"
window_PMM["--PMM_exclude--"].Update(value=True)
window_PMM["--PMM_majority--"].Update(value=False)
if event_PMM == "--PMM_majority--":
marker_params["how"] = "majority"
window_PMM["--PMM_exclude--"].Update(value=False)
window_PMM["--PMM_majority--"].Update(value=True)
if event_PMM == "--PMM_unite--":
marker_params["what"] = "unite"
window_PMM["--PMM_unite--"].Update(value=True)
window_PMM["--PMM_intersect--"].Update(value=False)
if event_PMM == "--PMM_intersect--":
marker_params["what"] = "intersect"
window_PMM["--PMM_unite--"].Update(value=False)
window_PMM["--PMM_intersect--"].Update(value=True)

if event_PMM == sg.WIN_CLOSED or event_PMM == "--PMM_cancel--":
params = copy.deepcopy(params_old)
window_PMM.close()
break
if event_PMM == "--PMM_accept--":
params = copy.deepcopy(marker_params)
window_PMM.close()

# window_PMM.close()
return params


def PPMS_exec_TP(params_old):
tp_params = copy.deepcopy(params_old)

Expand Down
113 changes: 113 additions & 0 deletions src/ccompass/marker_parameters_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Dialog for setting marker processing parameters."""

import copy
from typing import Any

import FreeSimpleGUI as sg


def _create_window(marker_params: dict[str, Any]) -> sg.Window:
if marker_params["how"] == "exclude":
how_exclude = True
how_majority = False
elif marker_params["how"] == "majority":
how_exclude = False
how_majority = True
else:
raise ValueError("Invalid value for 'how' in marker parameters.")

if marker_params["what"] == "unite":
what_unite = True
what_intersect = False
elif marker_params["what"] == "intersect":
what_unite = False
what_intersect = True
else:
raise ValueError("Invalid value for 'what' in marker parameters.")

layout = [
[
sg.Text("discrepancies:\t"),
sg.Checkbox(
"exclude\t",
key="--PMM_exclude--",
default=how_exclude,
enable_events=True,
),
sg.Checkbox(
"take majority",
key="--PMM_majority--",
default=how_majority,
enable_events=True,
),
],
[
sg.Text("selection:\t"),
sg.Checkbox(
"unite\t",
key="--PMM_unite--",
default=what_unite,
enable_events=True,
),
sg.Checkbox(
"intersect",
key="--PMM_intersect--",
default=what_intersect,
enable_events=True,
),
],
[
sg.Button(
"OK",
key="--PMM_accept--",
disabled=False,
enable_events=True,
button_color="dark green",
),
sg.Button(
"Cancel",
key="--PMM_cancel--",
disabled=False,
enable_events=True,
button_color="black",
),
],
]

return sg.Window("Marker Parameters", layout, size=(400, 100))


def show_dialog(params_old: dict[str, Any]) -> dict[str, Any]:
"""Show dialog for setting marker processing parameters."""
marker_params = copy.deepcopy(params_old)
window = _create_window(marker_params)

while True:
event, values = window.read()

if event == sg.WIN_CLOSED or event == "--PMM_cancel--":
marker_params = copy.deepcopy(params_old)
break

if event == "--PMM_accept--":
break

if event == "--PMM_exclude--":
marker_params["how"] = "esclude"
window["--PMM_exclude--"].Update(value=True)
window["--PMM_majority--"].Update(value=False)
elif event == "--PMM_majority--":
marker_params["how"] = "majority"
window["--PMM_exclude--"].Update(value=False)
window["--PMM_majority--"].Update(value=True)
elif event == "--PMM_unite--":
marker_params["what"] = "unite"
window["--PMM_unite--"].Update(value=True)
window["--PMM_intersect--"].Update(value=False)
elif event == "--PMM_intersect--":
marker_params["what"] = "intersect"
window["--PMM_unite--"].Update(value=False)
window["--PMM_intersect--"].Update(value=True)

window.close()
return marker_params

0 comments on commit 5c45e5e

Please sign in to comment.