Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context menu #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/family_tree_view_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2025- Julien Lepiller <julien@lepiller.eu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#


from gi.repository import Gtk

from gramps.gen.const import GRAMPS_LOCALE
from gramps.gen.display.name import displayer as name_displayer
from gramps.gui.widgets.menuitem import add_menuitem

_ = GRAMPS_LOCALE.translation.gettext

class FamilyTreeViewMenu(Gtk.Menu):
def __init__(self, handle, ftv: "FamilyTreeView", typ):
super().__init__()
self.set_reserve_toggle_size(False)
self.ftv = ftv
self.handle = handle
self.typ = typ

if typ == 1: # person
add_menuitem(self, _("Edit"), self.handle, lambda obj: self.ftv.edit_person(obj.get_data()))
person = self.ftv.dbstate.db.get_person_from_handle(handle)
other = []
for associated in person.get_person_ref_list():
other.append(associated.get_reference_handle())
if other != []:
# build associated submenu
item = Gtk.MenuItem(label=_("Set associated person as active"))
submenu = Gtk.Menu()
submenu.set_reserve_toggle_size(False)
item.set_submenu(submenu)
item.show()
self.append(item)

for associated in other:
person = self.ftv.dbstate.db.get_person_from_handle(associated)
name = person.get_primary_name()
add_menuitem(submenu, name_displayer.display_name(name), associated, lambda obj: self.ftv.set_active_person(obj.get_data()))
elif typ == 2: # family
add_menuitem(self, _("Edit"), self.handle, lambda obj: self.ftv.edit_family(obj.get_data()))

def popup(self, event):
if event:
super().popup(None, None, None, None, event.get_button()[1], event.time)
19 changes: 19 additions & 0 deletions src/family_tree_view_widget_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

from family_tree_view_canvas_manager import FamilyTreeViewCanvasManager
from family_tree_view_info_box_manager import FamilyTreeViewInfoBoxManager
from family_tree_view_menu import FamilyTreeViewMenu
from family_tree_view_minimap_manager import FamilyTreeViewMinimapManager
from family_tree_view_panel_manager import FamilyTreeViewPanelManager
from family_tree_view_tree_builder import FamilyTreeViewTreeBuilder
Expand Down Expand Up @@ -322,12 +323,22 @@ def add_connection(self, x1, y1, x2, y2, ym=None, m=None, dashed=False, handle1=
def add_expander(self, x, y, ang, click_callback):
self.canvas_manager.add_expander(x, y, ang, click_callback)

def open_family_context_menu(self, event, person_handle):
menu = FamilyTreeViewMenu(person_handle, self.ftv, 2)
menu.popup(event)

def open_person_context_menu(self, event, person_handle):
menu = FamilyTreeViewMenu(person_handle, self.ftv, 1)
menu.popup(event)

# callbacks

def _cb_person_clicked(self, person_handle, event, x, person_generation, alignment):
is_single_click = True
if event.type == Gdk.EventType.BUTTON_PRESS:
action = self.ftv._config.get("interaction.familytreeview-person-single-click-action")
if event.button == 3: # right-click
action = 6 # popup menu
elif event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
action = self.ftv._config.get("interaction.familytreeview-person-double-click-action")
is_single_click = False
Expand All @@ -349,6 +360,9 @@ def _cb_person_clicked(self, person_handle, event, x, person_generation, alignme
elif action == 5: # set as home
function = self.ftv.set_home_person()
data = [person_handle, True] # also_set_active
elif action == 6: # open context menu
function = self.open_person_context_menu
data = [event, person_handle]
else:
return False

Expand All @@ -360,6 +374,8 @@ def _cb_family_clicked(self, family_handle, event, x, family_generation):
is_single_click = True
if event.type == Gdk.EventType.BUTTON_PRESS:
action = self.ftv._config.get("interaction.familytreeview-family-single-click-action")
if event.button == 3: # right-click
action = 4 # popup menu
elif event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
action = self.ftv._config.get("interaction.familytreeview-family-double-click-action")
is_single_click = False
Expand All @@ -375,6 +391,9 @@ def _cb_family_clicked(self, family_handle, event, x, family_generation):
elif action == 3: # edit
function = self.ftv.edit_family
data = [family_handle]
elif action == 4: # open context menu
function = self.open_family_context_menu
data = [event, family_handle]
else:
return False

Expand Down