Re: ctrl+tab switching



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 <drodic 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

Attachment: tab-binding.patch
Description: Text Data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]