Skip to content

Fix: Connect cancel button to self.reject in ProgressDialog (Fixes #135)#1288

Open
MohamedSharfan wants to merge 1 commit intoenthought:mainfrom
MohamedSharfan:fix-progress-dialog-cancel
Open

Fix: Connect cancel button to self.reject in ProgressDialog (Fixes #135)#1288
MohamedSharfan wants to merge 1 commit intoenthought:mainfrom
MohamedSharfan:fix-progress-dialog-cancel

Conversation

@MohamedSharfan
Copy link

Fixes issue #135 where the Cancel button in ProgressDialog (Qt backend) would close the window but fail to update the _user_cancelled flag.

Changes

Updated _create_buttons to connect rejected signal to self.reject instead of dialog.reject.

Updated reject method signature to accept optional event argument to handle signal inputs.

Verification Ran python -m unittest pyface.ui.qt4.tests.test_progress_dialog and confirmed tests pass.

Copilot AI review requested due to automatic review settings January 15, 2026 11:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug in the Qt backend's ProgressDialog where the Cancel button would close the dialog window but fail to properly set the _user_cancelled flag, causing the cancellation to not be recognized by the application.

Changes:

  • Modified the Cancel button connection to call the custom self.reject method instead of the default dialog.reject
  • Added an optional event parameter to the reject method to handle signal inputs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

buttons.rejected.connect(dialog.reject)
buttons.rejected.connect(self.reject)
self._connections_to_remove.append(
(buttons.rejected, dialog.reject)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The handler stored in _connections_to_remove should be self.reject to match the actual connected handler on line 204. Currently, dialog.reject is stored, which means the signal disconnection in the destroy() method will attempt to disconnect the wrong handler, potentially leaving the connection active and causing memory leaks.

Suggested change
(buttons.rejected, dialog.reject)
(buttons.rejected, self.reject)

Copilot uses AI. Check for mistakes.
# -------------------------------------------------------------------------

def reject(self, event):
def reject(self, event = None):
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

There should be no space before the equal sign in the default parameter assignment. According to PEP 8, the correct format is "event=None" not "event = None".

Copilot uses AI. Check for mistakes.
Comment on lines 203 to 207
if self.can_cancel:
buttons.rejected.connect(dialog.reject)
buttons.rejected.connect(self.reject)
self._connections_to_remove.append(
(buttons.rejected, dialog.reject)
)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

This PR fixes a critical bug where the Cancel button doesn't properly set the _user_cancelled flag, but there's no test coverage for this behavior. Consider adding a test that verifies clicking the cancel button properly sets _user_cancelled to True and that the update method returns the correct cancellation status.

Copilot uses AI. Check for mistakes.
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.

2 participants