Repository: kivy/kivy

Issue:
Dropdown: Fix reposition in scrollview/recycleview
Fixes #7382

Maintainer merge checklist
* [x] Title is descriptive/clear for inclusion in release notes.
* [x] Applied a `Component: xxx` label.
* [ ] Applied the `api-deprecation` or `api-break` label.
* [ ] Applied the `release-highlight` label to be highlighted in release notes.
* [ ] Added to the milestone version it was merged into.
* [ ] **Unittests** are included in PR.
* [ ] Properly documented, including `versionadded`, `versionchanged` as needed.



Discussion:
thank you very much @tshirtman for your review and approval!!!

The change is small and logical and allows me to remove the workaround from my libraries... only the RTD/Sphinx check is failing - but I assume this has nothing to do with this PR as I've seen this recently on other PRs
Yes, the doc error happens on other PRs, so no worries.

I didn' test the code yet, but i don't see how this could have any bad effect¹, so i think we could merge it anyway, and fix later if something happens.

Do you think it's possible to make unit test showing what this bug fixes? It's probably more work than the change itself, but it would be nice to have.

¹ famous last words!
It is on my wishlist to dive into Kivy unit testing and add some unit tests
to the Kivy framework, but I'm currently very busy - so this will not
happen soon... sorry

Am So., 21. Feb. 2021 um 20:48 Uhr schrieb Gabriel Pettier <
notifications@github.com>:

> Yes, the doc error happens on other PRs, so no worries.
>
> I didn' test the code yet, but i don't see how this could have any bad
> effect*, so i think we could merge it anyway, and fix later if something
> happens.
>
> Do you think it's possible to make unit test showing what this bug fixes?
> It's probably more work than the change itself, but it would be nice to
> have.
>
>    - famous last words!
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/kivy/kivy/pull/7383#issuecomment-782924045>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AA4U63Q2LE7E6D7JAY636NLTAFWS7ANCNFSM4XZDMQTA>
> .
>

If I understood correctly, this checks whether there is no parent for the widget, meaning the widget is not part of the tree. However, while this shouldn't cause harm, I don't think it solves the issue fully!? What if the widget does have a parent, but the parent doesn't have a parent?

Perhaps a better check would be whether the widget's ultimate parent is Window (`win`)?
@matham: good point/finding.

Would it be ok for you to make a PR, changing the check (extended by the
last fix) to something like::

```
--- if not widget or not widget.parent or not win:
+++ if not widget or not widget.get_parent_window() or not win:
```
???


Am So., 14. März 2021 um 17:51 Uhr schrieb matham ***@***.***
>:

> If I understood correctly, this checks whether there is no parent for the
> widget, meaning the widget is not part of the tree. However, while this
> shouldn't cause harm, I don't think it solves the issue fully!? What if the
> widget does have a parent, but the parent doesn't have a parent?
>
> Perhaps a better check would be whether the widget's ultimate parent is
> Window (win)?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/kivy/kivy/pull/7383#issuecomment-798949139>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AA4U63XLLLZ36AX5GCNMZKLTDTZSBANCNFSM4XZDMQTA>
> .
>

>changing the check (extended by the last fix) to something like

Yeah, that seems like a good fix.
Thanks @matham!!!

The PR is on the way .... will push it in the next days.

Am So., 14. März 2021 um 20:36 Uhr schrieb matham ***@***.***
>:

> changing the check (extended by the last fix) to something like
>
> Yeah, that seems like a good fix.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/kivy/kivy/pull/7383#issuecomment-798975352>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AA4U63XOJQ24RXFGQP2SPI3TDUM55ANCNFSM4XZDMQTA>
> .
>


Resolving patch:
diff --git a/kivy/uix/dropdown.py b/kivy/uix/dropdown.py
--- a/kivy/uix/dropdown.py
+++ b/kivy/uix/dropdown.py
@@ -320,13 +320,14 @@ def _reposition(self, *largs):
         # calculate the coordinate of the attached widget in the window
         # coordinate system
         win = self._win
+        if not win:
+            return
         widget = self.attach_to
-        if not widget or not widget.parent or not win:
+        if not widget or not widget.get_parent_window():
             return
         wx, wy = widget.to_window(*widget.pos)
         wright, wtop = widget.to_window(widget.right, widget.top)
 
-        # set width and x
         if self.auto_width:
             self.width = wright - wx
 
@@ -357,7 +358,6 @@ def _reposition(self, *largs):
             # none of both top/bottom have enough place to display the
             # widget at the current size. Take the best side, and fit to
             # it.
-
             if h_top < h_bottom:
                 self.top = self.height = wy
             else:


Test patch: