Skip to content

class Handle Fix allowing dict to be passed for handlePen and removing hard reset for width and cosmetic attributes#2907

Merged
j9ac9k merged 3 commits intopyqtgraph:masterfrom
pdmkdz:handle_pen_roi
Apr 20, 2024
Merged

class Handle Fix allowing dict to be passed for handlePen and removing hard reset for width and cosmetic attributes#2907
j9ac9k merged 3 commits intopyqtgraph:masterfrom
pdmkdz:handle_pen_roi

Conversation

@pdmkdz
Copy link
Copy Markdown
Contributor

@pdmkdz pdmkdz commented Dec 23, 2023

Adding ability to modify handlePen for class ROI removing hard coded defaults for mkPen width=0 and cosmetic=True in ROI.py class Handle. Keeping width=0 and cosmetic=True as default for assignation without customization.

Fixes #1960
Fixes #2765

This will allow to pass a dictionary for pen customization when needed due to visibility.

@pdmkdz
Copy link
Copy Markdown
Contributor Author

pdmkdz commented Dec 23, 2023

New PR removed all the unnecessary changes to other files.

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Dec 24, 2023

The cosmetic=True can be dropped because pg.mkPen defaults to making cosmetic pens.

From what I understand, pen widths of 0 are a holdover from Qt4 days. It is supposed to be equivalent to width=1 and cosmetic=True; in which case, even the width=0 can be dropped because pg.mkPen defaults to width=1.

That said, leaving width=0 is the safe option.

Note: pen widths of zero forces code that need to know about pen widths to handle the special case of zero.

@pdmkdz
Copy link
Copy Markdown
Contributor Author

pdmkdz commented Jan 4, 2024

Considered there is a single failure maybe removing the 0 and setting to 1 is best?
While I am not prone to fight the cosmetic = True drop, I like the idea to see the width set to a default together with the color.
Let me know if I need to update this.

@pdmkdz
Copy link
Copy Markdown
Contributor Author

pdmkdz commented Jan 4, 2024

New commit removing those unnecessary default attributes values, I tested on my own app and worked perfectly.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 14, 2024

Hi @pdmkdz, thanks for the PR, sorry this has sat idle so long.

The main issue I have with this PR is that we are specifying a mutable object as a default parameter in a function declaration. This is one of the main python gotchas which can cause really confusing behavior.

Throughout the library it's common to use an immutable object (boolean, None, etc) and have an if-conditional that assigns the appropriate attribute to the dictionary. I think passing in a dict to that argument is fine, it just can't have a dict as a default value.

@pdmkdz
Copy link
Copy Markdown
Contributor Author

pdmkdz commented Mar 11, 2024 via email

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Mar 11, 2024

No, there's still a {} dictionary.

    def __init__(self, radius, typ=None, pen={'color': (200, 200, 220)},

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Apr 20, 2024

Hi @pdmkdz

Thanks for the PR, I hope you don't mind me adding a commit to your branch, I wanted to get your PR into the next release, so I thought I would just make the small change myself. Thanks for your contribution to the library!

@j9ac9k j9ac9k merged commit 6a2eb01 into pyqtgraph:master Apr 20, 2024
@pdmkdz
Copy link
Copy Markdown
Contributor Author

pdmkdz commented Apr 20, 2024

Happy to help, my very first around here 😊

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

Labels

None yet

Projects

None yet

3 participants