mwerezak / DearPyGui-Obj

An object-oriented wrapper around DearPyGui
MIT License
45 stars 3 forks source link

Idea: set object names using index notation #23

Closed roger- closed 3 years ago

roger- commented 3 years ago

Instead of Window('Example') how about Window['Example']?

IMHO it looks cleaner to separate it, as in LineSeries['example'](data) but its sorta nonstandard (though you can think of LineSeries as a dictionary).

Amorano commented 3 years ago

why not just LineSeries.example.data ? If you are going to mangle the dict to serve as a command pattern, you may as well make it more pythonic?

You can simple override the getattr on a subclass of "dict" type to make a dot notation class all the way down.... again, if you are going to mangle it anyway =D

roger- commented 3 years ago

I don't know if dot vs index notation is more Pythonic, but the latter seems cleaner and would support invisible IDs (e.g. "##id").

I wouldn't call it mangling dict notation either as indexing isn't unique to dictionaries, and there's no need to nest it further as you just need to specify an ID with a single level.

Amorano commented 3 years ago

But it is mangling. You even said so much yourself. That is not "non-standard" that is abusing the dict object to behave like an actual Object. In either case it is simply an extension of the dict lookup Python already uses.

Invisible ids? Further mangling the object. This seems like a very specific implementation.

roger- commented 3 years ago

Invisible ids? Further mangling the object.

That's built into DearPyGui actually.

that is abusing the dict object

Indexing notation isn't exclusive to dicts.

But it is mangling. You even said so much yourself.

Given that the object id is an integral part of DearPyGui I think treating them in a special way is justifiable. The interpretation can be that LineSeries, etc. contains every possible LineSeries and you want a specific one that you're indexing.

mwerezak commented 3 years ago

Overloading the indexing operator "[]" like this really twists around the meaning of that operator into something most people won't expect, simply going off of the principle of "least surprises" it doesn't seem like a great idea.

mwerezak commented 3 years ago

I would really like to understand what the goal of this proposal is though, because it's not clear to me right now and maybe there's another way around it to achieve whatever it is that seems to be missing for you. Is there a way you can rephrase this as a statement about what's needed?

mwerezak commented 3 years ago

Given that the object id is an integral part of DearPyGui I think treating them in a special way is justifiable. The interpretation can be that LineSeries, etc. contains every possible LineSeries and you want a specific one that you're indexing.

Is this it? The ability to create LineSeries (or other DataSeries types) with a specific object id in a way that stands out?

Personally I feel that the named parameter syntax is the most appropriate way to do this e.g. LineSeries(object_id='example'). It stands out, the code itself says what you're doing (setting an object id on a new LineSeries), etc.

And for retrieval (the "specific one that you're indexing" in your second sentence) we already have a similar mechanism for widgets, the get_item_by_id() function. So for the sake of consistency I would create a similar function for DataSeries.

mwerezak commented 3 years ago

No response for 5 days.