Skip to content

[GUI] Epoch rejection menu and its three actions - #1047

Open
arnodelorme wants to merge 2 commits into
agent/issue-1024-eegplot-dialogfrom
agent/issue-1009-rejmenu-dialog
Open

arnodelorme wants to merge 2 commits into
agent/issue-1024-eegplot-dialogfrom
agent/issue-1009-rejmenu-dialog

Conversation

@arnodelorme

@arnodelorme arnodelorme commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Epoch rejection menu and its three actions · #1009, part of #875. Stack base PR #1046.

Epoched

Ica

Vertical control alignment

Combined rejection marks

Across 2 native openings, maximum vertical control displacement was 0.81 px. The largest difference in overall width was 4.86 px. Of 3 output comparisons, 3 met tolerance. Applied the amplitude calculation used by the rejection menu followed by its eeg_rejsuperpose action on 80 real epochs, using the clean common base. Raw outputs, commands and checks are in tools-extra/numeric-inputs/.

The open window now has Close (keep marks), Clear all marks, and Reject marked trials, with confirmation before removal. Qt tests exercise all three and check that the buttons remain reachable on a short screen.

Clean Linux checkouts on jamming. EEGLAB 5e0be87059098662dc9b50fb378f9002b0ef173a, EEGPrep 0b050dfa4982600cb266982ca48e42fc39cb52e2. Fixes #1009.

Full inventory report for the project team. pop_rejmenu (p. 77). PDF · Editable Word.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude

claude Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

PR #1047 was updated after the trigger (c2fb9c0 -> 0b050df). Push again or mention Claude to run on the latest version.

@arnodelorme arnodelorme left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was written by an AI assistant during a nightly check, not by Arno.

Code review

  • Overall assessment: needs changes
  • Highest-risk area: pop_rejmenu final actions, main window modal test compatibility, and dataset commit parity
  • Merge recommendation: needs changes

Blocking

  1. test_cancel_rejection_dialog_keeps_menus_history_and_dataset hangs forever on pop_rejmenu:ica
    • File:
      title=title,
      function_name="pop_rejmenu",
      eeglab_source="functions/adminfunc/pop_rejmenu.m",
      layout="supergui",
      skipline=False,
      addbuttons=False,
      minwidth=10,
      geometry=tuple(geometry),
      controls=tuple(controls),
      and
      action_ids = (
      "pop_eegthresh:ica",
      "pop_eegthresh:data",
      "pop_rejtrend:ica",
      "pop_jointprob:ica",
      "pop_rejkurt:ica",
      "pop_rejspec:ica",
      "pop_rejmenu:ica",
      )
      for action_id in action_ids:
      with self.subTest(action_id=action_id):
      session = EEGPrepSession()
      eeg = _demo_eeg(epoched=True, ica=True)
      session.store_current(eeg, command="")
      session.ALLCOM.clear()
      trials = int(eeg["trials"])
      data = np.array(eeg["data"], copy=True)
      window = build_main_window(session, all_menus=True, include_plugins=False)
      try:
      window.show()
      window.app.processEvents()
      before = _top_menu_state(window)
      self.assertEqual(
      [item[0] for item in before],
      ["File", "Edit", "Tools", "Plot", "Study", "Datasets", "Help"],
      )
      window.open_menu("Tools")
      action = _find_menu_action(window.window.menuBar(), action_id)
      self.assertIsNotNone(action, f"menu action {action_id} is missing")
      def cancel(app=window.app):
      dialog = app.activeModalWidget()
      button = dialog.findChild(QPushButton, "cancel") if dialog is not None else None
      if button is None:
      QTimer.singleShot(0, cancel)
      return
      # Dialog construction allocates enough to collect the menu
    • Why it matters: pop_rejmenu_dialog_spec now sets addbuttons=False and replaces the standard ok and cancel buttons with keep, clear, and reject. In tests/test_gui_main_window.py, test_cancel_rejection_dialog_keeps_menus_history_and_dataset still includes "pop_rejmenu:ica" and reschedules QTimer.singleShot(0, cancel) whenever dialog.findChild(QPushButton, "cancel") is None. Because pop_rejmenu no longer has a cancel button, the modal loop never exits and the main CI test job will time out once this branch targets develop.
    • Suggested fix: In test_cancel_rejection_dialog_keeps_menus_history_and_dataset, detect when dialog.objectName() == "pop_rejmenu" and dismiss it with dialog.reject() after gc.collect() (matching window close or Escape when no Cancel button exists).

Important

  1. REJECT MARKED TRIALS closes the dialog before checking for zero or all marked trials

    • File:
      elif callback.name == "submit_dialog":
      source = widgets[params["button"]]
      def submit():
      if "confirm" in params:
      answer = QtWidgets.QMessageBox.question(source, source.window().windowTitle(), params["confirm"])
      if answer != QtWidgets.QMessageBox.StandardButton.Yes:
      return
      source.setProperty(_VALUE_PROPERTY, True)
      source.window().accept()
      source.clicked.connect(submit)
      and
      if reject:
      flags = [1] * 7
      out, command = eeg_rejsuperpose(source, icacomp, *flags, return_com=True)
      commands.append(command)
      if reject and np.asarray((out.get("reject") or {}).get("rejglobal", [])).any():
      out, reject_command = pop_rejepoch(out, out["reject"]["rejglobal"], 0, return_com=True)
      commands.append(reject_command)
      return (out, " ".join(commands)) if return_com else out
    • Why it matters: submit_dialog prompts "Reject the marked trials?" and calls source.window().accept() unconditionally. When zero epochs are marked, EEGLAB (functions/adminfunc/pop_rejmenu.m, lines 184 to 192) superposes marks first, warns "No epoch selected...", and keeps pop_rejmenu open without asking for rejection confirmation. Here, the user is asked to confirm, the dialog closes, and pop_rejmenu silently returns without rejecting anything or warning. Conversely, when every epoch is marked, the dialog closes first and pop_rejepoch then raises ValueError, discarding the open window and any calculations made in that session.
    • Suggested fix: Validate mark counts inside the reject button action before prompting and accepting the dialog. Superpose marks on the working dataset first. If none are marked, show a warning message box and keep the dialog open. If all epochs are marked, show the empty dataset warning and keep the dialog open. Only prompt "Reject the marked trials?" and accept the dialog when 0 < marked < trials.
  2. Rejecting trials from pop_rejmenu in the main GUI overwrites ALLEEG[CURRENTSET] in place instead of committing via pop_newset

    • File:
      elif name == "pop_rejmenu":
      from eegprep.functions.popfunc.pop_rejmenu import pop_rejmenu
      out = pop_rejmenu(selection, _icacomp_from_variant(variant), return_com=True)
      elif name == "pop_selectcomps":
      from eegprep.functions.popfunc.pop_selectcomps import pop_selectcomps
      out = pop_selectcomps(selection, return_com=True)
      elif name == "pop_viewprops":
      from eegprep.plugins.ICLabel.pop_viewprops import pop_viewprops
      target_index = list(self.session.CURRENTSET)
      def commit_component_rejection(eeg_out: Any, _states: dict[int, bool]) -> None:
      with self.session.gui_action("pop_viewprops"):
      self._store_current_from_gui(eeg_out, command="", index=target_index)
      self._refresh()
      out = pop_viewprops(
      selection,
      typecomp=0 if variant == "components" else 1,
      reject_callback=commit_component_rejection,
      return_com=True,
      )
      else:
      self.show_coming_soon(name, parent)
      return
      if isinstance(out, tuple):
      eeg_out, command = out[0], out[1] if len(out) > 1 else ""
      else:
      eeg_out, command = out, ""
      if name == "pop_viewprops":
      self._add_history_from_gui(command)
      self._refresh()
      return
      if command:
      if name in _NEWSET_COMMIT_ACTIONS:
      self._commit_processed_dataset_from_gui(
      eeg_out, command=command, parent=parent, leading_command=leading_command
      )
      else:
      self._store_current_from_gui(eeg_out, command=command)
      self._refresh()
    • Why it matters: In EEGLAB (functions/adminfunc/pop_rejmenu.m, lines 188 to 200), CLOSE (KEEP MARKS) updates the current dataset in place (eeg_store), whereas REJECT MARKED TRIALS removes trials with pop_rejepoch and commits the reduced dataset via pop_newset. In MenuActionDispatcher._run_pop_function, pop_rejmenu is not in _NEWSET_COMMIT_ACTIONS and unconditionally calls _store_current_from_gui, so rejecting epochs from Tools > Reject data epochs > Reject data (all methods) overwrites the current dataset without running pop_newset (unlike pop_rejepoch at line 233 and pop_eegplot at lines 1407 to 1410).
    • Suggested fix: When pop_rejmenu returns with fewer trials than selection (or with pop_rejepoch in the command), commit eeg_out through self._commit_processed_dataset_from_gui(...) as pop_eegplot and pop_rejepoch do, keeping _store_current_from_gui(...) for mark updates that do not remove epochs.

Nits

  1. Packaged help resource pop_rejmenu.md still describes removed controls
    • File:
      Close (keep marks) retains calculations and their command history, then combines
      checked mark families into `EEG.reject.rejglobal` with `eeg_rejsuperpose`.
      Select Reject marked epochs when closing to remove those epochs with
      `pop_rejepoch`. Cancel discards changes made in this menu.
    • Why it matters: docs/source/api/preprocessing_and_artifacts.rst was updated for the three actions, but src/eegprep/resources/help/pop_rejmenu.md (pophelp('pop_rejmenu')) still tells users to check Reject marked epochs when closing and click Cancel, both of which were removed in this PR.
    • Suggested fix: Update src/eegprep/resources/help/pop_rejmenu.md to describe Close (keep marks), Clear all marks, and Reject marked trials.

Test gaps

  1. tests/test_gui_rejection_dialogs.py (test_rejection_menu_final_actions)
    • File:
      @pytest.mark.gui
      @pytest.mark.parametrize("action,remaining,marked", [("keep", 3, 1), ("clear", 3, 0), ("reject", 2, 0)])
      def test_rejection_menu_final_actions(qt_dialogs, monkeypatch, action, remaining, marked):
      box = qt_dialogs.qt.QtWidgets.QMessageBox
      monkeypatch.setattr(box, "question", lambda *_: box.StandardButton.Yes)
      eeg = _epoched_ica_eeg()
      class Renderer:
      def run(self, spec, initial_values=None):
      widgets = qt_dialogs.build(spec)
      if action == "clear":
      widgets["clear"].click()
      assert widgets["threshtrial"].text() == "0"
      widgets["keep" if action == "clear" else action].click()
      assert qt_dialogs.dialogs[-1].result() == qt_dialogs.qt.QtWidgets.QDialog.Accepted
      return {tag: qt_dialogs.qt._read_widget(widget) for tag, widget in widgets.items()}
      out = pop_rejmenu(eeg, renderer=Renderer())
      assert out["trials"] == remaining
      assert np.count_nonzero(out["reject"].get("rejthresh", [])) == marked
      assert eeg["trials"] == 3
      np.testing.assert_array_equal(eeg["reject"]["rejthresh"], [0, 1, 0])
    • Add a case where QMessageBox.question returns StandardButton.No on REJECT MARKED TRIALS, asserting the dialog remains open (result() != QDialog.Accepted) and reject does not record True.
    • Add cases for clicking REJECT MARKED TRIALS when zero epochs are marked and through MenuActionDispatcher.dispatch("pop_rejmenu:data").

EEGLAB parity notes

  • Opening geometry, section weights, Scroll Data labels on the probability and kurtosis rows, popup menu strings, checkbox toggling on rejstatus == 3, and forcing all mark flags on REJECT MARKED TRIALS match functions/adminfunc/pop_rejmenu.m. The two behavioral parity gaps are the zero marked trial warning and pop_newset commit on cb_reject noted under Important.

Tests run in a detached worktree at 0b050dfa4982600cb266982ca48e42fc39cb52e2:

  • tests/test_gui_rejection_dialogs.py: 28 passed, 1 deselected.
  • tests/test_rejection_workflows.py: 34 passed, 12 deselected.
  • tests/test_gui_geometry.py, tests/test_guifunc_primitives.py, tests/test_package_help.py, tests/test_stream6_rejection_numbers.py, tests/test_stream11_help_errors.py: 196 passed, 56 skipped (Linux reference MATLAB geometry), 8 deselected.
  • tests/test_gui_main_window.py (test_cancel_rejection_dialog_keeps_menus_history_and_dataset): hung indefinitely on pop_rejmenu:ica (canceled after 10 s).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant