Ejemplo n.º 1
0
def consumeKey( ctxt, pressed ):
    """
    build the proper QKeyEvent from Softimage key event and send the it along to the focused widget
    """
    kcode = ctxt.GetAttribute( 'KeyCode' )
    mask = ctxt.GetAttribute( 'ShiftMask' )

    # Build the modifiers
    modifier = Qt.NoModifier
    if ( mask & C.siShiftMask ):
        if ( kcode + 300 in KEY_MAPPING ):
            kcode += 300
            
        modifier |= Qt.ShiftModifier
        
    if ( mask & C.siCtrlMask ):
        modifier |= Qt.ControlModifier

    if ( mask & C.siAltMask ):
        modifier    |= Qt.AltModifier

    # Generate a Qt Key Event to be processed
    result  = KEY_MAPPING.get( kcode )
    if ( result ):
        from PySide.QtGui import QApplication, QKeyEvent

        if ( pressed ):
            event = QKeyEvent.KeyPress
        else:
            event = QKeyEvent.KeyRelease
        
        if ( result[2] ):
            modifier |= result[2]
        
        # Send the event along to the focused widget
        QApplication.sendEvent( QApplication.instance().focusWidget(), QKeyEvent( event, result[0], modifier, result[1] ) )