I believe that the reason none of your options have worked is that you need
to unbind the Ctrl+Tab and Ctrl+Shift+Tab accelerators as well as adding
their use. I think if you  adapted your (B) attempt and added unbinding of
the default handling, it may well work. I've attached something that I
tried on current master that appeared to work, but this *will not* work on
3.18.x.

cheers,
Kai

On Sat, 22 Aug 2020 at 19:01, Donjan Rodic <dro...@phys.ethz.ch> wrote:

> 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
>
diff --git a/meld/accelerators.py b/meld/accelerators.py
index ad116e06..d3030250 100644
--- a/meld/accelerators.py
+++ b/meld/accelerators.py
@@ -12,10 +12,10 @@ VIEW_ACCELERATORS: Dict[str, Union[str, Sequence[str]]] = {
     'view.go-to-line': '<Primary>I',
     # Overridden in CSS
     'view.next-change': ('<Alt>Down', '<Alt>KP_Down', '<Primary>D'),
-    'view.next-pane': '<Alt>Page_Down',
+    'view.next-pane': ('<Alt>Page_Down', '<Primary>Tab'),
     # Overridden in CSS
     'view.previous-change': ('<Alt>Up', '<Alt>KP_Up', '<Primary>E'),
-    'view.previous-pane': '<Alt>Page_Up',
+    'view.previous-pane': ('<Alt>Page_Up', '<Shift><Primary>Tab'),
     'view.redo': '<Primary><Shift>Z',
     'view.refresh': ('<control>R', 'F5'),
     'view.save': '<Primary>S',
diff --git a/meld/resources/meld.css b/meld/resources/meld.css
index 7ec8e70a..04e1f81a 100644
--- a/meld/resources/meld.css
+++ b/meld/resources/meld.css
@@ -34,6 +34,15 @@ action-gutter {
     background-color: @theme_bg_color;
 }
 
+@binding-set UnbindFocusBindings {
+    unbind "<Ctrl>Tab";
+    unbind "<Ctrl><Shift>Tab";
+}
+
+* {
+    -gtk-key-bindings: UnbindFocusBindings;
+}
+
 @binding-set ChunkMovementBindings {
     /* Gdk.ScrollDirection.UP */
     bind "<Alt>Up" { "move-diff" (0) };
_______________________________________________
meld-list mailing list
meld-list@gnome.org
https://mail.gnome.org/mailman/listinfo/meld-list

Reply via email to