I'm using Meld a lot recently and my productivity would be increased if
Ctrl+Tab and Ctrl+Shift+Tab were available for switching to the next,
respectively previous, tab (notebook page). I'm aware that GNOME doesn't
like this particular shortcut, but I've set it up in every other GNOME
application I use (Gedit, gnome-terminal, Nautilus) and find it to be
highly efficient.
I've tried to hack it unsuccessfully and would like to request some
help. This was done on Meld 3.18.0 (default Ubuntu 18.04 repo version).
If newer versions help with this particular issue, I'll sideload...
updates will eventually catch up.
Attempt A)
In meldwindow.py:MeldWindow:__init__() write these built-in Gtk methods:
from meld.meldapp import app
app.set_accels_for_action("win.tab-previous",
["<shift><control>Tab", "<control>Page_Up"])
app.set_accels_for_action("win.tab-next", ["<control>Tab",
"<control>Page_Down"])
print(app.get_accels_for_action("win.tab-next"))
The keybindings get stored (printed) correctly, but apparently Meld
ignores this feature.
Attempt B)
In meldwindow.py:MeldWindow:__init__(), there is a block "# Add
alternate keybindings ..." setting F5 etc. Just below, write:
(keyval, mask) = Gtk.accelerator_parse("<Primary>J")
accels.connect(keyval, mask, 0, lambda *_:
self.notebook.set_current_page(1))
(keyval, mask) = Gtk.accelerator_parse("<Primary>Tab")
accels.connect(keyval, mask, 0, lambda *_:
self.notebook.set_current_page(1))
(keyval, mask) = Gtk.accelerator_parse("<Primary>KP_Tab")
accels.connect(keyval, mask, 0, lambda *_: print("foo"))
(keyval, mask) = Gtk.accelerator_parse("<Primary>ISO_Left_Tab")
accels.connect(keyval, mask, 0, lambda *_: print("bar"))
Now Ctrl+J correctly switches to the second tab from the left, but
Ctrl+Tab and Ctrl+Shift+Tab get ignored (no terminal output either).
They do iterate through Meld's icon list at the top, for what that's worth.
Attempt C)
In filediff.py:FileDiff:on_key_event(), write:
if event.state & Gdk.ModifierType.CONTROL_MASK and
Gdk.keyval_name(event.keyval) == 'Tab':
print("switch to tab right")
This correctly prints to the terminal when Ctrl+Tab is pressed. But I'm
at a loss on how to hook it up to notebook.set_current_page() here.
app = Gtk.Application.get_default() is empty and I can't get a higher
parent than self.widget.
Attempt D)
In meldwindow.py:MeldWindow:__init__(), register the signal:
self.connect("key-press-event",self.on_key_press_event)
#...
def on_key_press_event(self, window, event):
print("key press event")
crashes with "AttributeError: connect", unless I let MeldWindow
additionally inherit from
melddoc.MeldDoc
or
GObject.GObject
and call
melddoc.MeldDoc.__init__(self)
respectively
GObject.Object.__init__(self)
, in which case it simply doesn't know the signal name. Also, inheriting
from Gtk.Window yields
File "/usr/lib/python3/dist-packages/meld/ui/gnomeglade.py", line 47,
in __init__
self.widget = getattr(self, root)
RuntimeError: field is not writable
Attempt E)
Using an external library pretty much anywhere:
from pynput.keyboard import Listener
with Listener(on_press=self.my_press,
on_release=self.my_release) as listener:
listener.join()
def my_press(key, *_):
print("Key pressed: {0}".format(key))
def my_release(key, *_):
print("Key released: {0}".format(key))
Works in principle by printing any pressed keys. But it's blocking
w.r.t. Meld's loops, so the GUI doesn't show.
Help?
Best
Donjan
_______________________________________________
meld-list mailing list
meld-list@gnome.org
https://mail.gnome.org/mailman/listinfo/meld-list