Skip to content

Allow item access/item assignment to Surfaces (2946) #1494

Open
@GalacticEmperor1

Description

@GalacticEmperor1

Issue №2946 opened by lordmauve at 2021-12-23 13:51:11

Surfaces don't feel like very Pythonic objects.

Why not directly allow accessing pixels via __getitem__/__setitem__ instead of get_at()/set_at()?

surf[5, 5] = 255, 255, 255

So, sure, you can do this with pygame.surfarray if you have numpy, but that's a big dependency. And you can do it with PixelArray... but why do you need a separate class to do that? (Also PixelArray doesn't behave enough like numpy, it just feels a little clumsy).

Also I don't exactly understand the details of locking, but why not follow the context manager protocol?

with surf:
    surf[5, 5] = 255, 255, 255
```<hr>

#  Comments

# # #  **[ankith26](https://github.com/ankith26)* commented at 2021-12-31 04:26:17*

Interesting ideas indeed. As I understand locking, it is redundant for most kinds of surfaces these days, but having a context manager API for it is cool.
In addition to this, some of the get/set functions in the `Surface` class can also be updated with `property` stuff

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions