Skip to content

4759 broken copy to clipboard - #4761

Open
payno wants to merge 4 commits into
mainfrom
4759-broken-copy-to-clipboard
Open

payno wants to merge 4 commits into
mainfrom
4759-broken-copy-to-clipboard

Conversation

@payno

@payno payno commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

PR summary

close #4759 and also improve code by checking upstream the file format.

AI Disclosure

  • No AI used
  • Claude used.

@payno payno linked an issue Oct 27, 2026 that may be closed by this pull request
@payno
payno force-pushed the 4759-broken-copy-to-clipboard branch from 02d5ebd to 58de998 Compare October 27, 2026 12:54
return True
return super().saveGraph(filename=filename, fileFormat=fileFormat, dpi=dpi)
if fileFormat is None:
fileFormat = _deduceGraphFormat(filename)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was missing

if fileFormat is None:
fileFormat = _deduceGraphFormat(filename)
if fileFormat != "png":
return super().saveGraph(filename=filename, fileFormat=fileFormat, dpi=dpi)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

AI replaces the f fileFormat == "png" by f fileFormat != "png". And I agree this is a bit simpler to read. So I let as it was.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed

Comment on lines +529 to +537
buffer = qt.QBuffer()
buffer.open(qt.QIODevice.WriteOnly)
try:
if not image.save(buffer, "png"):
return False
filename.write(bytes(buffer.data()))
finally:
buffer.close()
return True

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the fix of the bug.

I didn't created a context manager because it seems simpler IMO. But can be discussed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feels weird that we don't already have a util for this. I feel that we are doing similar things elsewhere.

yield plot


@pytest.mark.parametrize("fileFormat", ["png", None])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The None part of those test are testing the calls to _deduceGraphFormat. Not clear to me if this is over-killed or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is good to test for None but it should be a specific test IMO

@payno payno changed the title DARFT: 4759 broken copy to clipboard 4759 broken copy to clipboard Oct 27, 2026
@payno
payno requested a review from a team October 27, 2026 13:09
self.assertEqual(self.plot.isKeepDataAspectRatio(), isKeepAspectRatio)


@pytest.fixture(params=[PlotWidget, PlotWindow])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is a specific test_plotwidget file so perhaps the test for PlotWidget should live there?

yield plot


@pytest.mark.parametrize("fileFormat", ["png", None])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is good to test for None but it should be a specific test IMO



@pytest.mark.skipif(not qt.HAS_SVG, reason="QtSvg not available")
@pytest.mark.parametrize("fileFormat", ["svg", None])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if fileFormat is png here?

Comment on lines +222 to +223
"""Test saveGraph fails when format cannot be deduced"""
assert not plotWithImage.saveGraph(BytesIO())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should it fail silenty or raise an error?

"""Returns the file format from the filename extension."""
if not isinstance(filename, str):
return None
return filename.split(".")[-1].lower()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return filename.split(".")[-1].lower()
return filename.rsplit(".")[-1].lower()

Comment on lines +529 to +537
buffer = qt.QBuffer()
buffer.open(qt.QIODevice.WriteOnly)
try:
if not image.save(buffer, "png"):
return False
filename.write(bytes(buffer.data()))
finally:
buffer.close()
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feels weird that we don't already have a util for this. I feel that we are doing similar things elsewhere.

if fileFormat is None:
fileFormat = _deduceGraphFormat(filename)
if fileFormat != "png":
return super().saveGraph(filename=filename, fileFormat=fileFormat, dpi=dpi)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed

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.

broken copy to Clipboard

2 participants