Glade Panel in Axis blocks arrow keys

More
30 Jan 2018 02:16 #105185 by cmorley
First try this, replace the def forward function etc with this code:
    def forward_press(w, e, fw):
        if e.keyval in ignore:
            return

        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    def forward_release(w, e, fw):
        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    window.connect_after("key-press-event", forward_press, fw)
    window.connect("key-release-event", forward_release, fw)

Now that will only ignore press events not release events.

Chris M

Please Log in or Create an account to join the conversation.

More
30 Jan 2018 02:26 #105186 by cmorley
hmm i see press events use 'connect_after' and release uses 'connect'
changing those commands could make a difference too.

Chris M

Please Log in or Create an account to join the conversation.

More
30 Jan 2018 23:02 #105219 by +Jan+
Hey Chris,
I tested your code today, my xembed file:
#!/usr/bin/env python
# vim: sts=4 sw=4 et
"""
XEmbed helper functions to allow correct embeding inside Axis
"""

import gtk

def reparent(window, parent):
    """ Forced reparent. When reparenting Gtk applications into Tk
    some extra protocol calls are needed.
    """
    from Xlib import display
    from Xlib.xobject import drawable

    if not parent:
        return window

    plug = gtk.Plug(long(parent))
    plug.show()

    d = display.Display()
    w = drawable.Window(d.display, plug.window.xid, 0)
    # Honor XEmbed spec
    atom = d.get_atom('_XEMBED_INFO')
    w.change_property(atom, atom, 32, [0, 1])
    w.reparent(parent, 0, 0)
    w.map()
    d.sync()

    for c in window.get_children():
        window.remove(c)
        plug.add(c)

    # Hide window if it's displayed
    window.unmap()

    return plug

def keyboard_forward(window, forward):
    """ XXX: Keyboard events forwardind
        This is kind of hack needed to properly function inside Tk windows.
        Gtk app will receive _all_ events, even not needed. So we have to forward
        back things that left over after our widgets. Connect handlers _after_
        all others and listen for key-presss and key-release events. If key is not
        in ignore list - forward it to window id found in evironment.
    """
    if not forward:
        return
    try:
        forward = int(forward, 0)
    except:
        return

    from Xlib.protocol import event
    from Xlib import display, X
    from Xlib.xobject import drawable

    d = display.Display()
    fw = drawable.Window(d.display, forward, 0)

    ks = gtk.keysyms
    ignore = [ ks.Tab, ks.Page_Up, ks.Page_Down
             , ks.KP_Page_Up, ks.KP_Page_Down
             , ks.Left, ks.Right, ks.Up, ks.Down
             , ks.KP_Left, ks.KP_Right, ks.KP_Up, ks.KP_Down
             , ks.bracketleft, ks.bracketright
             ]
    def gtk2xlib(e, fw, g, type=None):
        if type is None: type = e.type
        if type == gtk.gdk.KEY_PRESS:
            klass = event.KeyPress
        elif type == gtk.gdk.KEY_RELEASE:
            klass = event.KeyRelease
        else:
            return
        kw = dict(window=fw, detail=e.hardware_keycode,
                  state=e.state & 0xff,
                  child=X.NONE, root=g._data['root'],
                  root_x=g._data['x'], root_y=g._data['y'],
                  event_x=0, event_y=0, same_screen=1)
        return klass(time=e.time, **kw)

    
    def forward_press(w, e, fw):
        if e.keyval in ignore:
            return

        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    def forward_release(w, e, fw):
        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return
        fw.send_event(fe)

    window.connect_after("key-press-event", forward_press, fw)
    window.connect("key-release-event", forward_release, fw)
    window.add_events(gtk.gdk.KEY_PRESS_MASK)
    window.add_events(gtk.gdk.KEY_RELEASE_MASK)

Now xyz behave the same way (no oszillating on z anymore), but they still do not stop on the FIRST button release after moving the mouse into the panel.

hmm i see press events use 'connect_after' and release uses 'connect'
changing those commands could make a difference too.


No difference :huh:

Thanks in advance

Jan

Please Log in or Create an account to join the conversation.

More
31 Jan 2018 07:18 - 31 Jan 2018 07:19 #105225 by cmorley
Starting with my last code
Change the one function to this:
    def forward_release(w, e, fw):
        CMD.jog(self.emc.JOG_STOP, 0)
        CMD.jog(self.emc.JOG_STOP, 1)
        CMD.jog(self.emc.JOG_STOP, 2)
        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

add this to the top of the file:

import linuxcnc
CMD = linuxcnc.cmmand()

This will only work in 2.7.X
It's a brute force way to do it but will be interesting if it actually works as expected.

Chris M
Last edit: 31 Jan 2018 07:19 by cmorley.

Please Log in or Create an account to join the conversation.

More
31 Jan 2018 16:39 - 31 Jan 2018 16:40 #105236 by +Jan+
Hello Chris,
I tried to use your on code on a 2.7 machine and got on the terminal the message:

CMD.jog(self.emc.JOG_STOP, 0)
NameError: global name 'self' is not defined



I suppose I have to do something additional?

I corrected

CMD = linuxcnc.cmmand()

to

CMD = linuxcnc.command()


Is that correct?
Last edit: 31 Jan 2018 16:40 by +Jan+.

Please Log in or Create an account to join the conversation.

More
31 Jan 2018 17:28 #105239 by cmorley
change them to like this:
CMD.jog(linuxcnc.JOG_STOP, 0)

and yes i misspelled command

Chris M

Please Log in or Create an account to join the conversation.

More
31 Jan 2018 20:41 - 31 Jan 2018 20:45 #105249 by +Jan+
Hey Chris,
thanks for your comments, It works now under 2.7. :)
I did my very first python programmning approach with some changes, so that this brute force event only takes place when I release on of the keys mentioned in the ignore section:
def forward_press(w, e, fw):
        if e.keyval in ignore:
            return

        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    def forward_release(w, e, fw):
        if e.keyval in ignore:
            CMD.jog(linuxcnc.JOG_STOP, 0)
            print 'stop0'
            CMD.jog(linuxcnc.JOG_STOP, 1)
            print 'stop1'
            CMD.jog(linuxcnc.JOG_STOP, 2)
            print 'stop2'
            g = fw.get_geometry()
            fe = gtk2xlib(e, fw, g)
            if not fe: return

        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    window.connect_after("key-press-event", forward_press, fw)
    window.connect("key-release-event", forward_release, fw)

This avoids error messages after hitting for example the esc key.
I`m still interested in a "clean" way which works also in 2.8. How should I go on?

Best wishes

Jan
Last edit: 31 Jan 2018 20:45 by +Jan+.

Please Log in or Create an account to join the conversation.

More
01 Feb 2018 00:59 #105257 by cmorley
Excellent !
Nice on the editing too - that is one reason why I like python it is pretty easy to figure out and test changes.

The CMD.jog function has changed in master requiring another bit of data.
It is part of the upgrade for axis to joints.
I will look at whats required soon for you.

I would prefer to see the code send out release events rather then assume they are jogging keys.
If someone changed the jogging key is AXIS it could mess things up - but thats a problem if we pushed this fix to linuxcnc.
At this point I am just glade we have made a positive step...

Chris M

Please Log in or Create an account to join the conversation.

More
01 Feb 2018 04:55 #105263 by cmorley
looks likethis should do it for master:
CMD.jog(self.emc.JOG_STOP, 0,0)
CMD.jog(self.emc.JOG_STOP, 0,1)
CMD.jog(self.emc.JOG_STOP, 0,2)

Chris M

Please Log in or Create an account to join the conversation.

More
02 Feb 2018 22:34 - 02 Feb 2018 22:35 #105342 by +Jan+
Hey Chris,

At this point I am just glade we have made a positive step...


Me too...


I upgraded again to Master, and did some tests, until now I was not able to fix the problem in Master. I had to change again "self.emc" to "linuxcnc". Now I do not get any error message on the Terminal (the print messages are displayed).
Here is my actual xembed code (the interesting parts) I use for Master 2.8.
#!/usr/bin/env python
# vim: sts=4 sw=4 et
"""
XEmbed helper functions to allow correct embeding inside Axis
"""

import gtk
import linuxcnc
CMD = linuxcnc.command()

...
    def forward_press(w, e, fw):
        if e.keyval in ignore:
            return

        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    def forward_release(w, e, fw):
        if e.keyval in ignore:
            CMD.jog(linuxcnc.JOG_STOP, 0,0)
            print 'stop0'
            CMD.jog(linuxcnc.JOG_STOP, 0,1)
            print 'stop1'
            CMD.jog(linuxcnc.JOG_STOP, 0,2)
            print 'stop2'
            g = fw.get_geometry()
            fe = gtk2xlib(e, fw, g)
            if not fe: return

        g = fw.get_geometry()
        fe = gtk2xlib(e, fw, g)
        if not fe: return

        fw.send_event(fe)

    window.connect_after("key-press-event", forward_press, fw)
    window.connect("key-release-event", forward_release, fw)
    window.add_events(gtk.gdk.KEY_PRESS_MASK)
    window.add_events(gtk.gdk.KEY_RELEASE_MASK)
Last edit: 02 Feb 2018 22:35 by +Jan+.

Please Log in or Create an account to join the conversation.

Time to create page: 0.161 seconds
Powered by Kunena Forum