Skip to content

Commit

Permalink
try to fix popup
Browse files Browse the repository at this point in the history
save popup menu in self.menu
call "popup" depending on gtk version
  • Loading branch information
vantu5z committed May 29, 2019
1 parent 1f2492d commit dfab772
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions GraphView/graphview.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ def __init__(self, view, dbstate, uistate):
# Gtk style context for scrollwindow to operate with theme colors
self.sw_style_context = scrolled_win.get_style_context()

# used for popup menu, prevent destroy menu as local variable
self.menu = None

def set_person_to_focus(self, handle):
"""
Set person that will focus (once) after graph rebuilding.
Expand Down Expand Up @@ -944,7 +947,8 @@ def button_press(self, item, target, event):
return False

if button == 3:
PopupMenu(self, kind='background').show_menu(event)
self.menu = PopupMenu(self, kind='background')
self.menu.show_menu(event)
return True

return False
Expand Down Expand Up @@ -1043,9 +1047,11 @@ def select_node(self, item, target, event):

elif button == 3 and node_class: # right mouse
if node_class == 'node':
PopupMenu(self, 'person', handle).show_menu(event)
self.menu = PopupMenu(self, 'person', handle)
self.menu.show_menu(event)
elif node_class == 'familynode':
PopupMenu(self, 'family', handle).show_menu(event)
self.menu = PopupMenu(self, 'family', handle)
self.menu.show_menu(event)

elif button == 2: # middle mouse
# to enter in scroll mode (we should change "item" to root item)
Expand Down Expand Up @@ -2543,10 +2549,17 @@ def show_menu(self, event=None):
"""
Show popup menu.
"""
# new from gtk 3.22:
# self.popup_at_pointer(event)
self.popup(None, None, None, None,
event.get_button()[1], event.time)
if (Gtk.MAJOR_VERSION >= 3) and (Gtk.MINOR_VERSION >= 22):
# new from gtk 3.22:
self.popup_at_pointer(event)
else:
if event:
self.popup(None, None, None, None,
event.get_button()[1], event.time)
else:
self.popup(None, None, None, None,
0, Gtk.get_current_event_time())
#self.popup(None, None, None, None, 0, 0)

def background_menu(self):
"""
Expand Down

0 comments on commit dfab772

Please sign in to comment.