How to get the Gramps genealogical object a widget belongs to?

I enter specific “technical” data in Notes. This data has a dedicated format described by abstract rules. I want to right-click on it to trigger actions.

This is inspired by URLs in Notes where hovering the mouse displays a tooltip and right-clicking will jump to the destination (through a context menu or Ctl-click).

I have added a regexp in gramps/gui/widgets/styledtexteditor.py and activated it with a call to method match_add(…). It works and I can retrieve it in method do_match_changed(…).

Next step is to create a tooltip. But I need other “environment” data which obviously is not in the styled text buffer. To probe the data I must first find which Note record owns this StyledTextEditor object (the parent).

  1. How can I find it?
  2. Once I have computed the tooltip, how do I return it to the StyledTextEditor in an orderly manner?
    Would signals be an appropriate track? Notably to invalidate detection as a “false positive” when the construct is not allowed (Note has not the allowed type).

EDIT 1:
Method get_parent() called on StyledTextEditor object allows me to reach the ScrolledWindow hosting the full GUI for the editor. From there, can I get the “Gramps genealogical” object it is associated with?

EDIT 2:
Exploring the get_parent() chain, I end up on a Gtk.Dialog() object. This dialog is created in _local_init(self) method of the various editxxx.py modules.

My knowledge of GTK is next to zero. Do you know if there is an available property in dialog objects for free use? If such a property exists, I can store the relevant Gramps object (pointer) in it when it is created and this solves one problem.

1 Like

I think I have a lead. Gramps creators had long term view even if they didn’t foresee
all possible implications. Thanks to all of them.

The ManagedWindow feature has a function get_item_from_window(self, window) which explores the tracking list to find a ManagedWindow handling the argument.

But since I deal with Gramps UI (not simply GTK UI), I must access a widget (item?) which has Gramps UI information attached to it.

  1. find a Gramps UI’ed widget in the parent hierarchy with find_parent_with_attr(self, attr=“uistate”). This returns a GTK widget. Let’s call it uiw.
  2. From there, retrieve the ManagedWindow with mw = uiw.uistate.gwm.get_item_from_window(self.get_toplevel())
  3. As a ManagedWindow, the associated Gramps object is property obj

This is preliminary investigation. I follow the track to see if I can achieve my goal.

1 Like

The module by @kku running the Help for SuperTool may be of interest. It builds content of a floating window from a JSON file also has hotlink targets and tooltip content. It builds context menus based on the rows.