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).
How can I find it?
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.
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.
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.
From there, retrieve the ManagedWindow with mw = uiw.uistate.gwm.get_item_from_window(self.get_toplevel())
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.
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.
I don’t fully understand your problem. But since you are modifying Gramps code anyway, maybe you can ‘inject’ the Note object into the StyledTextEditor object. Something like
Create a set_note_object method in StyledTextEditor
Add this in the EditNote class: self.texteditor.set_note_object(self.obj)
@kmikkels and I are working on a gramplet where one of the context menu options is to create a new note and flow some content into it (composed from the indicated row of data).
Perhaps that could provide you some grist for the mill?
I am exploring a path to solve the “evanescent” nature of internet where even permalinks are not guaranteed to be permanent for ever. Maintaining all links related to citations, sources, repositories, persons, places, … is a daunting task. I try to minimise it by fragmenting the URLs into hierarchical bits so that fixing one bit is valid for all URLs referencing the bit (think of a change in hostname).
Fragments are stored in special notes. Individually, they don’t make sense. I want to display a tooltip when hovering over them. Hovering is a pure GUI aspect. The event can be related to a widget but I must then associate it to a Gramps object. This Gramps object allows me to access to the DB. And from there I can issue queries to retrieve details about the other fragments. A full valid URL is built and presented in the tool tip.
User can check the URL is correct or right-click, control-click, … to open a browser on the URL.
I’d rather not. StyledTextEditor is a Gtk.TextView. It belongs in the GUI domain and is (relatively?) independent from Gramps. Adding a link to a Note would break this independence.
In addition, StyledTextEditor is indeed invoked by the Note management but by many other windows not related to notes at all. This would mean checking gramplets code and Glade descriptions. I want to only minimally modify Gramps to avoid introducing problems.
There is also another issue. In case my modification remains a private venture, I want it to be ported easily across GRAMPS evolution. Once again, changing as few things as possible is imperative.
My problem is inverse: I start from a Note and I create a context menu from a lot of non-trivially related Gramps objects. But perhaps, I am tackling the problem from the wrong side.