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
I think I found a bug in context_menu: here's the scenario:
I am creating a context menu which I'm using on nodes of a TreeView, and had a crash that appeared randomly.
I'm using the same context menu instance for all the nodes of my TreeView.
The context menu is initially added to the top layout, which is a FloatLayout object, here is the code:
(note I had to add some code to fix a weird behaviour as well, which is apprently not related, I don't know if it's because I'm not using it the right way or if it's a bug)
class TreeContextMenu(ContextMenu):
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
app= App.get_running_app()
rw = app.root
self.cancel_handler_widget = rw
rw.add_widget(self)
# bug workaround (otherwise keep showing the menu in the bottom) ?
self.visible = True
self.hide()
when calling the menu (on right click on the nodes of my treeview with super().show(*app.root_window.mouse_pos)), I had the following crash, but only in some circumstances:
[...]/context_menu.py", line 211, in show_submenu
self.get_submenu().show(*self._root_parent.to_local(x, y))
AttributeError: 'NoneType' object has no attribute 'to_local'
I figured out it was because root_context_menu.parent was None in get_context_menu_root_parent method of ContextMenu.
The following code seems to fix the problem, using root_context_menu.orig_parent if root_context_menu.parent is None:
def get_context_menu_root_parent(self):
"""
Return the bounding box widget for positioning sub menus. By default it's root context menu's parent.
"""
if self.bounding_box_widget is not None:
return self.bounding_box_widget
root_context_menu = self._get_root_context_menu()
# --------------------------------------------- #
# ORIGINAL CODE
# --------------------------------------------- #
#return root_context_menu.bounding_box_widget if root_context_menu.bounding_box_widget else root_context_menu.parent
# --------------------------------------------- #
# FIX
# --------------------------------------------- #
if root_context_menu.bounding_box_widget:
return root_context_menu.bounding_box_widget
else:
if root_context_menu.parent is None:
assert root_context_menu.orig_parent
return root_context_menu.orig_parent
return root_context_menu.parent
Thanks
The text was updated successfully, but these errors were encountered:
Hi,
I think I found a bug in
context_menu
: here's the scenario:I am creating a context menu which I'm using on nodes of a TreeView, and had a crash that appeared randomly.
I'm using the same context menu instance for all the nodes of my TreeView.
The context menu is initially added to the top layout, which is a
FloatLayout
object, here is the code:(note I had to add some code to fix a weird behaviour as well, which is apprently not related, I don't know if it's because I'm not using it the right way or if it's a bug)
when calling the menu (on right click on the nodes of my treeview with
super().show(*app.root_window.mouse_pos)
), I had the following crash, but only in some circumstances:I figured out it was because
root_context_menu.parent
wasNone
inget_context_menu_root_parent
method ofContextMenu
.The following code seems to fix the problem, using
root_context_menu.orig_parent
ifroot_context_menu.parent
isNone
:Thanks
The text was updated successfully, but these errors were encountered: