You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My app has some MDNavigationRailItem only and set anchor is top, KivyMD is crashed with message “attributeError: ‘NoneType’ object has no attribute 'y'”.
Reproduce Code
These are almost same of document's example expect add "anchor: 'top"
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "/media/mnishi/opt/ws-sf/ui/md-nrail.py", line 51, in <module>
MDRailApp().run()
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivy/app.py", line 956, in run
runTouchApp()
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivy/base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivy/base.py", line 339, in mainloop
self.idle()
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivy/base.py", line 379, in idle
Clock.tick()
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivy/clock.py", line 733, in tick
self.post_idle(ts, self.idle())
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivy/clock.py", line 776, in post_idle
self._process_events()
File "kivy/_clock.pyx", line 620, in kivy._clock.CyClockBase._process_events
File "kivy/_clock.pyx", line 653, in kivy._clock.CyClockBase._process_events
File "kivy/_clock.pyx", line 649, in kivy._clock.CyClockBase._process_events
File "kivy/_clock.pyx", line 218, in kivy._clock.ClockEvent.tick
File "/media/mnishi/opt/ws-sf/ui/.venv/lib/python3.12/site-packages/kivymd/uix/navigationrail/navigationrail.py", line 770, in set_top_pos
anchor_button.y
AttributeError: 'NoneType' object has no attribute 'y'
cause
MDNavigationRail.py decide anchor y value by _check_anchor() method.
if both MenuButton and FacButton are nothing, anchor_button set None in _check_anchor().
work around
I’m not sure the correct anchor y criteria, so I patch based on height of MDNavigationRail.
def _check_anchor(self, *args):
def set_top_pos(*args):
anchor_y = 0
if (
self.fab_button
and not self.menu_button
or self.fab_button
and self.menu_button
):
anchor_button = self.fab_button
anchor_y = self.fab_button.y
elif self.menu_button and not self.fab_button:
anchor_y = self.menu_button.y
# both MenuButton and FabButton dose not exist CASE
else:
anchor_y = self.height
self.ids.box_items.y = (
anchor_y
- (len(self.ids.box_items.children) * dp(56))
- dp(56)
)
if self.anchor == "center":
self.ids.box_items.pos_hint = {"center_y": 0.5}
elif self.anchor == "top":
Clock.schedule_once(set_top_pos)
elif self.anchor == "bottom":
self.ids.box_items.y = dp(56)
if self.anchor == "center":
self.ids.box_items.pos_hint = {"center_y": 0.5}
elif self.anchor == "top":
Clock.schedule_once(set_top_pos)
elif self.anchor == "bottom":
self.ids.box_items.y = dp(56)
Description of the Bug
My app has some MDNavigationRailItem only and set anchor is top, KivyMD is crashed with message “attributeError: ‘NoneType’ object has no attribute 'y'”.
Reproduce Code
These are almost same of document's example expect add "anchor: 'top"
log
cause
MDNavigationRail.py decide anchor y value by _check_anchor() method.
if both MenuButton and FacButton are nothing, anchor_button set None in _check_anchor().
work around
I’m not sure the correct anchor y criteria, so I patch based on height of MDNavigationRail.
$ diff kivymd/kivymd/uix/navigationrail/navigationrail.py ./navigationrail.py
Versions
The text was updated successfully, but these errors were encountered: