0

Hot key doesn't work when floating?

Hi,

I'm new with RV Python, and just have been experimenting with adding and removing UI from the main window.
I want to do something like the "Session Manager" where you have a hot key, "x", to display and remove. I got that much to work except when the widget is floating.

Here's my "Hello RV" code:

from PyQt4 import QtGui, QtCore
from rv import rvtypes

class HelloRV(rvtypes.MinorMode):

    def __init__(self):
        rvtypes.MinorMode.__init__(self)
        self.init("HelloRV", None, [("key-down--X", self.toggleWidget, "X Key")])

        top_level_widgets = QtGui.QApplication.topLevelWidgets()
        self.main_window = None
        for widget in top_level_widgets:
            if isinstance(widget, QtGui.QMainWindow):
                self.main_window = widget

        self.my_dock_widget = QtGui.QDockWidget()
        label = QtGui.QLabel("This is the only thing inside the dock widget")
        self.my_dock_widget.setWidget(label)
        self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.my_dock_widget)
        self.my_dock_widget.close()

    def toggleWidget(self, event):
        if self.my_dock_widget.isHidden():
            self.my_dock_widget.show()
        else:
            self.my_dock_widget.close()

def createMode():
    return HelloRV()

 

It works just fine when the widget is docked, but when it's floating, it gives me this error:

ERROR: event = menu
ERROR: function = __lambda859 (void; Event ignored)
ERROR: Exception Value: exception: "invalid property name #RVTransform2D.transform.flop" 

Can somebody tell me what I'm doing wrong? Thanks!

1 条评论

  • 0
    Avatar
    Alan Trombla

    Hi Andry,

    I think the issue is not so much that the widget is floating, but that it has keyboard focus.  The event bindings described in the mode's init() function are managed by the GLView, so if some other widget has focus then the event will not get to the your handler.  The error you see is because the default binding for 'X' is to flip the media, and you are probably testing with an empty session (no media).  If you want the 'x' key to work when your widget has focus as well as when the GLView has focus, you'll need to manage that in the usual Qt way for your widget.

    Hope that clarifies,

    Alan

请先登录再写评论。