Clipboard context menus for "ref" objects and exploding place hierarchies

Gramps Clipboard & Gramplet Enhancements — Installation Guide

Status: Unofficial, experimental patch that needs field testing. This is not (yet?) part of the official Gramps or addons-source codebase. It changes two files inside your Gramps program installation (not just an addon), so please read the whole guide before installing, and keep a backup as described below.

Please PM me if you would like to try out the hacks. If there is interest, I will initially share the patches there and add anyone who PMs to the thread. Discourse forums do not give enough feedback about whether anyone is actually trying a presented hack. Given sufficient interest, the hacks will be added here. And submit it as a 6.2 PR. I will not battle through the PR process for a hack that only I want.


Two separate enhancements, not one

This patch is actually two independent sets of changes that happen to live in this one guide together. Neither is specific to the “Collections Clipboard” gramplet — that gramplet just happens to be the one place in Gramps where both sets are visible at once, which makes it a convenient example to demonstrate them, but it isn’t what either change targets or is limited to.

Set A — Clipboard reference & hierarchy copying (in clipboard.py)
Changes how right-clicking an item on the clipboard behaves. This affects every clipboard in Gramps that shares the same underlying code: the standard Edit ▸ Clipboard window, the Collections Clipboard gramplet, and any other tool built on the same clipboard widget.

Set B — Gramplet “Dock” button (in grampletbar.py)
Changes what happens when a gramplet is popped out of a category view’s sidebar or bottombar into its own floating window. This affects every gramplet capable of being undocked from those two locations — Fan Chart, Statistics, Filters, Collections Clipboard, all of them — regardless of which clipboard, if any, it involves.

This does not reach the Dashboard. Gramplets placed on the Dashboard view use a separate, unrelated detach mechanism (GrampletWindow in grampletpane.py) rather than the sidebar/bottombar’s DetachedWindow (in grampletbar.py) that this patch changes. A gramplet undocked from the Dashboard still shows the old plain Close button; only gramplets undocked from a sidebar or bottombar show the new Dock button. Porting this to the Dashboard’s detach window would be a separate, third change — say the word if you want that scoped out.

The Collections Clipboard is the ideal demo, because it’s both a clipboard (so it shows Set A) and a gramplet (so it shows Set B) at the same time — but it is not the target of either change, and installing this patch affects both areas everywhere in Gramps, not just that one gramplet.


What each set changes

Set A: Clipboard reference & hierarchy clipping

  1. Clip the actual item behind a reference.
    Some things you can put on the clipboard aren’t the record itself, but a link to one — for example, a child listed inside a family, or a repository listed inside a source. Right-clicking one of those ‘ref’ links now offers a “Clip [Person / Place / Event / …]” option that adds the real record it points to onto the clipboard, the same as if you’d
    dragged that record there directly. Previously, right-clicking these linked items did nothing at all — anywhere in Gramps, not only in the Collections Clipboard gramplet.

  2. Clip Enclosing Places.
    Right-clicking a Place that’s already on a clipboard now offers “Clip Enclosing Places” when that place has a parent place set up (city inside a county inside a state, etc.). Choosing it walks all the way up the hierarchy and adds every parent place to that clipboard in one step, instead of finding and dragging each one by hand.

Set B: gramplet “Dock” button

  1. A clearer button on undocked (floating) gramplets — sidebar/bottombar
    only.

    When you pop a gramplet out of a category view’s sidebar or bottombar into its own window, the old Close button has been replaced with a Dock button that shows a small icon for the view it came from and whether it will return to the sidebar or the bottombar — so it’s clear that closing the window puts the gramplet back where it came from, rather than discarding it. This applies to every gramplet undocked from those two locations, clipboard or otherwise — but not to gramplets undocked from the Dashboard, which still show the plain Close button (see above).

None of this changes your family tree data. It only changes clipboard and gramplet behavior inside the program.

Known rough edges:

  • The view-type icon on the Dock button sometimes falls back to the broader category icon instead of the more specific one, depending on your icon theme.
  • You may see a harmless Gtk-WARNING: Drawing a gadget with negative dimensions message in the terminal when docking/undocking any gramplet.
    This is a pre-existing GTK3 quirk in how the sidebar/bottombar draws its
    tab-overflow arrows, not something this patch introduces, and it doesn’t
    affect functionality.
  • Menu wording (e.g. “Clip” vs “Copy”) can be freely edited to taste in
    the patched clipboard.py — it’s just a label string.

The general “hack” process

Because these changes live inside Gramps’s own program files rather than
in an addon, applying them means replacing two files inside your Gramps
installation:

  • gramps/gui/clipboard.py — Set A
  • gramps/gui/widgets/grampletbar.py — Set B

You can install either set independently of the other — they don’t depend
on each other. Do this, in order, for whichever version section below
matches your Gramps:

  1. Find the real file first. Locate the installed copy of each file.
    On Linux with a user-installed Gramps this is typically somewhere like:
    ~/.local/lib/python3.11/site-packages/gramps/gui/clipboard.py
    ~/.local/lib/python3.11/site-packages/gramps/gui/widgets/grampletbar.py
    The exact path depends on your OS, Python version, and whether Gramps was installed system-wide or per-user. If you’re not sure, search your system for clipboard.py inside a folder named gramps.

  2. Rename the original — don’t delete or overwrite it directly.
    Before copying in the patched version, rename the file that’s already
    there, e.g.:
    clipboard.pyclipboard.py.stock-5.2
    grampletbar.pygrampletbar.py.stock-5.2
    This keeps a working, unmodified copy sitting right next to the patched
    one, so reverting is a simple rename back — no reinstalling Gramps, no
    hunting for a backup.

  3. Copy in the patched file and give it the original name.
    The patched file you download must be renamed to exactly clipboard.py or grampletbar.py — Gramps imports files by module name, so a different filename (or a stray extra suffix) will fail to load or, worse, silently not load at all.

  4. Fully restart Gramps — don’t just close and reopen a view or a gramplet. Gramps loads its own program modules once at startup, so a file swapped in while Gramps is already running won’t take effect until the next full restart.

  5. If anything looks wrong, quit Gramps, delete the patched file, and rename your .stock-* copy back to its original name. You’re back to an unmodified Gramps.

The Collections Clipboard gramplet addon file itself (ClipboardGramplet.py, which lives under your Gramps profile folder — e.g. ~/.gramps/gramps52/plugins/ClipboardGramplet/ — rather than inside the program installation) is only included below as a convenient, visible demonstration of Set A. You do not need it to get either enhancement working elsewhere in Gramps.


A separate, unrelated note for the addon author

While comparing versions, it came up that addons-source’s master branch for ClipboardGramplet.py still uses the pre-6.0 import pattern (MultiTreeView with a lambda title) that matches the old maintenance/gramps50gramps52 branches, rather than the ClipboardMultiTreeView pattern already adopted in the gramps60 and gramps61 maintenance branches. That’s worth flagging independently of anything in this guide, since it means an addon release cut from current master would fail to import under current Gramps master core.

The use (if any) of the Master branch in the gramps-project/addons-source repository is still a bit obtuse.