pannal / plex-for-kodi

Unoffical Plex for Kodi add-on releases.
GNU General Public License v2.0
237 stars 30 forks source link

Move item selected in jumplist to the top #85

Closed bowlingbeeg closed 5 months ago

bowlingbeeg commented 5 months ago

GHI (If applicable): #

Description:

I tried to explain in the comments what this does but basically when the jumplist is used the code will move by the OVERCOMMIT stride past the item we want and then back to the item we want. This shifts the row with the item we want up to the top of the panel. It will then request the current chunk and if needed the next chunk. It uses the OVERCOMMIT value to determine if the items are still in the current chunk or the next one.

It's a little bit of a hack but I like the results. Let me know what you think.

Checklist:

pannal commented 5 months ago

Thanks!

pannal commented 5 months ago

It looks a bit wonky but I think it works well enough.

Why did you remove CHUNK_OVERCOMMIT from the LibraryWindow class, though? Even if it's not needed there, it's the base class, so it should have a default.

Edit: That's considered best practice and confuses introspective IDEs. I'll fix it.

bowlingbeeg commented 5 months ago

The problem is that it doesn't work. If you set it in the base class it always uses the base class value and never the child class. I don't know python that well so I don't understand why it does it that way but it was obvious in testing.

pannal commented 5 months ago

Ah because it's a special case with the base class being a MultiWindow. I'll see what I can do.

pannal commented 5 months ago

Yeah, this in MultiWindow doesn't trigger in this case:

    def __getattr__(self, name):
        return getattr(self._current, name)

As accessing self.CHUNK_OVERCOMMIT in this instance doesn't trigger __getattr__, thus it retrieves the value from itself. PostersWindow is not an overloaded class of MultiWindow, the handling is a bit weird.

I'm fixing this using:

getattr(self._current, "CHUNK_OVERCOMMIT", self.CHUNK_OVERCOMMIT)

Whereas self._current holds the current window instance inside a MultiWindow.

Taken from the PyDoc:

Called when the default attribute access fails with an [AttributeError](https://docs.python.org/3/library/exceptions.html#AttributeError) (either [__getattribute__()](https://docs.python.org/3/reference/datamodel.html#object.__getattribute__) raises an [AttributeError](https://docs.python.org/3/library/exceptions.html#AttributeError) because name is not an instance attribute or an attribute in the class tree for self; or [__get__()](https://docs.python.org/3/reference/datamodel.html#object.__get__) of a name property raises [AttributeError](https://docs.python.org/3/library/exceptions.html#AttributeError)). This method should either return the (computed) attribute value or raise an [AttributeError](https://docs.python.org/3/library/exceptions.html#AttributeError) exception.

One would need to rewrite this to use __getattribute__, but that's a whole different beast.