GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 27, 2016 9:53 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Trouble with keybindings in GtkTextView (gtk3 and PyGO)
PostPosted: Sun Sep 23, 2012 8:32 pm 

Joined: Thu Aug 30, 2012 1:40 pm
Posts: 1
[edited with code examples and a bit more explanation]

Hi. I've been able to set several keybord shortcuts for a GtkTextView and a GtkTextEntry using the new css provider system. I'm finding, though, that I only seem to be able to establish keybindings for combinations including a modifier key. The widget doesn't respond to any bindings I set up that use:

- the delete key
- the escape key
- individual letter or punctuation keys alone

Here's the code where I set up the css provider for the keybindings (it's Python, using PyGO, but it should be readable based on the C docs -- I figured out the Python mostly from the C docs anyhow, since there isn't much PyGO documentation yet!)

       #set up style context
        keys = Gtk.CssProvider()
        keys.load_from_path(os.path.join(data_path, 'keybindings.css'))

        #set up style contexts and css providers
        widgets = {'window': self.window, 'vbox': self.vbox,
                    'toolbar': self.toolbar, 'search_entry': self.search_entry,
                    'paned': self.paned,
                    'notelist_treeview': self.notelist_treeview,
                    'notelist_window': self.notelist_window,
                    'notetext_window': self.notetext_window,
                    'editor': self.editor,
                    'statusbar': self.statusbar
        for l, w in widgets.iteritems():

Then in keybindings.css this is an example of what works:

@binding-set gtk-vi-text-view
    bind "<ctrl>b" { "move-cursor" (display-lines, -5, 0) };     /* 5 lines up */
    bind "<ctrl>k" { "move-cursor" (display-lines, -1, 0) };     /* down */
    bind "<ctrl>j" { "move-cursor" (display-lines, 1, 0) };      /* up */

Part of what I'm trying to do is just add proper delete-key function to the text widgets (right now the delete key does nothing at all). So if I add a binding like one of these, nothing happens:

    bind "Delete" { "delete-selection" () };
    bind "Delete" { "delete-from-cursor" (chars, 1) };

The other part of what I want to do is more elaborate. I want to set up something like Vim's command and visual modes. So at the moment I'm just playing around with (a) setting the widget to editable=false by hitting the esc key; and (b) using homerow letters to move the cursor (as a proof-of-concept exercise). So far there's no response from the escape key or from the letter keys, even though the bindings work when I apply them to modifier-key combinations.

For example, I do this in the css for the text-widget:

    bind "j" { "move-cursor" (display-lines, 1, 0) };            /* down */
    bind "k" { "move-cursor" (display-lines, -1, 0) };           /* up */
    bind "l" { "move-cursor" (logical-positions, 1, 0) };        /* right */
    bind "h" { "move-cursor" (logical-positions, -1, 0) };       /* left */

but none of these bindings does anything, even if other bindings in the same set are respected.

What's especially odd is that the vim-like movement bindings above *are* respected when I attach them to a GtkTreeView widget for navigating the tree-view options:

@binding-set gtk-vi-tree-view
    bind "j" { "move-cursor" (display-lines, 1) };               /* selection down */
    bind "k" { "move-cursor" (display-lines, -1) };              /* selection up */

So it seems like there are limitations or overrides of some kind on keybindings for the TextView widget (and for the del key?), but I can't find documentation of anything like that. Are these just things that can't be done with the css providers? If so, what are my alternatives for non-modified keybindings?



Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Google Adsense [Bot] and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group